From jcarlson at uci.edu Thu Aug 18 15:57:20 2005 From: jcarlson at uci.edu (jcarlson at uci.edu) Date: 18 Aug 2005 12:57:20 -0700 Subject: PyPE 2.1 run problem In-Reply-To: <1124358546.523320.58590@g14g2000cwa.googlegroups.com> References: <_HCMe.39$ea.3751@ns2.gip.net> <1124358546.523320.58590@g14g2000cwa.googlegroups.com> Message-ID: <1124395040.774656.179260@g49g2000cwa.googlegroups.com> > Once I done the replacement as suggested above, PyPE2.1 can run from > the source now. Thanks Josiah ! No problem. > > I have downloaded the PyPE2.1-win-unicode.zip, after unzip it with winzip > > into PyPE2.1-win-unicode dierctory on window XP. I try to run "pype.exe" > > by double > > click on it, but nothing has happen, then when I run it with "run as..." > > using the right click button. > > I have the following Message in the pype.exe.log > > > > Traceback (most recent call last): > > File "pype.py", line 30, in ? > > File "configuration.pyc", line 129, in ? > > WindowsError: [Errno 267] The directory name is invalid: > > 'E:\\Downloads\\Python\\PyPE\\PyPE2.1-win-unicode\\library.zip/*.*' > > > > I also copy the "PyPE2.1-win-unicode" directory into > > "C:\Python24\Lib\site-packages" and run it, but it behaves the same !! I have a solution to that one too...turns out that it was a problem with PyPE trying to use a home directory inside of the library.zip file if it couldn't find your platform's home directory. I have fixed it to be aware of being py2exe'd. Try PyPE 2.1.1, available via sourceforge.net (remember to verify those hashes!) - Josiah From gdamjan at gmail.com Mon Aug 29 16:16:02 2005 From: gdamjan at gmail.com (Damjan) Date: Mon, 29 Aug 2005 22:16:02 +0200 Subject: python image thumbnail generator? References: Message-ID: Chris Dewin wrote: > Hi. I run a website for my band, and the other guys want an image gallery. > > I'm thinking it would be nice and easy, if we could just upload a jpg into > a dir called "gallery/". When the client clicks the "gallery" link, a > cgi script could search the gallery/ dir, and create thumbnails of any > jpeg images that don't already have a thumbnail associated with them. The > script could then generate a page of clickable thumbnails. Once I made an example mod_python handler, that resized images on the fly. For example: http://server/folder/image.jpg - would give you the original image, served directly by apache without any performance hit. http://server/folder/image.jpg?thumbnail - would resize the picture (and cache the result on disk) and return that, on a second request it would return the cached image very fast by calling an apache.send_file function. see http://www.modpython.org/pipermail/mod_python/2004-September/016471.html -- damjan From rkern at ucsd.edu Fri Aug 5 14:30:16 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 05 Aug 2005 11:30:16 -0700 Subject: Suggestions for optimizing my code In-Reply-To: <1123263231.010703.88990@z14g2000cwz.googlegroups.com> References: <1123263231.010703.88990@z14g2000cwz.googlegroups.com> Message-ID: drife wrote: > Hello, > > I am looking for suggestions for how I might optimize my > code (make it execute faster), and make it more streamlined/ > elegent. But before describing my code, I want to state that > I am not a computer scientist (I am an atmospheric scientist), > and have but a rudimentary understanding of OO principles. > > My problem is this: I want to find the maximum off-diagonal > element of a correlation matrix, and the -position- of that > element within the matrix. In case you are unfamiliar with > correlation matrices they are square and symmetric, and contain > the mutual correlations among data collected at different > points in space or time. import MLab import Numeric as N def find_max(R): U = MLab.triu(R) n = U.shape[0] # set the diagonal elements to 0.0, too U.flat[::n+1] = 0.0 k = N.argmax(U.flat) i, j = divmod(k, n) return i, j, R[i,j] -- 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 sybrenUSE at YOURthirdtower.com.imagination Wed Aug 31 09:41:20 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 31 Aug 2005 15:41:20 +0200 Subject: Python doc problems example: gzip module References: <1125477977.072146.298670@g47g2000cwa.googlegroups.com> Message-ID: Xah Lee enlightened us with: > but after a minute of scanning, please someone tell me what the fuck > is it talking about? How difficult is it? The first line of the Gzip class explains it all to me: "Constructor for the GzipFile class, which simulates most of the methods of a file object" Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From djanvk at gmail..com Fri Aug 12 16:42:37 2005 From: djanvk at gmail..com (djanvk at gmail..com) Date: Fri, 12 Aug 2005 20:42:37 GMT Subject: Text/IDE Python Editor? References: Message-ID: THanks for the information and the review.. On Fri, 12 Aug 2005 16:57:04 GMT, Peter A. Schott wrote: >Also, it depends on what you're trying to do. GUI, Web, Service-type apps, etc. > >I have started using Stan's Python Editor (www.stani.be) because I like the >general features it offers. It does require wxpython to run, though. I've also >used Boa Constructor and DrPython - both pretty good environments. I believe >that they are both dependent on wxpython as well. > >Some people like Eric - now available for XP using PyQt under the Qt GPL'd >version. I had a little trouble with it running correctly - probably due to a >config issue on my part. I will admit to not spending a lot of time with it, >though. > >If you don't need the GUI IDE, there are a whole bunch of options available. >More than I'm able to delve into properly. > >Best answer is to play around a little with the different IDE's and find the one >that works for your coding style. Also, check the archives for this group. This >topic has come up quite a bit recently. > >-Pete > >Simon Brunning wrote: > >> On 8/12/05, djanvk at gmail..com wrote: >> > Any recommendations on a editior/IDE for programming in python? >> >> http://wiki.python.org/moin/PythonEditors From p at ulmcnett.com Wed Aug 24 12:01:18 2005 From: p at ulmcnett.com (Paul McNett) Date: Wed, 24 Aug 2005 09:01:18 -0700 Subject: Default function arguments behaving badly In-Reply-To: <1124898044.569156.217700@g49g2000cwa.googlegroups.com> References: <1124898044.569156.217700@g49g2000cwa.googlegroups.com> Message-ID: <430C99CE.2000900@ulmcnett.com> jonny.longrigg at gmail.com wrote: > I'm having some trouble with a function I've written in Python: > def myFunction(l1,l2,result=[]): [snipped rest of function and explanation of what it does] > Does anyone know what is going on here? Is there an easy solution? It shined out like a supernova. It has to do with mutability of certain Python objects (e.g. dicts and lists) and the fact that Python binds the default arguments only once. So, when your function is defined, python binds the name "result" to the value []. Then, your function runs the first time using that original binding. The second time, it still uses the original binding which, because lists are mutable, still contains the prior list. Etcetera. The solution is to never assign mutable objects to default arguments. Instead, assign to None, like: def myFunction(l1, l2, result=None): if result is None: result = [] Others will certainly post links to the python docs that explain this. -- Paul McNett http://paulmcnett.com From leszczynscyATnospam.yahoo.com.nospam Fri Aug 5 02:02:48 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Fri, 05 Aug 2005 01:02:48 -0500 Subject: >time.strftime %T missing in 2.3 In-Reply-To: References: Message-ID: Robert Kern wrote: > Andy Leszczynski wrote: > >> Python 2.2/Unix >> >> >>time.strftime("%T") >> '22:12:15' >> >>time.strftime("%X") >> '22:12:17' >> >> Python 2.3/Windows >> >> >>time.strftime("%X") >> '22:12:47' >> >> time.strftime("%T") >> '' > > > From http://docs.python.org/lib/node252.html > > """The full set of format codes supported varies across platforms, > because Python calls the platform C library's strftime() function, and > platform variations are common.""" > > So I suggest that it's a platform issue, not a Python version issue. FWIW: > > Python 2.4.1 (#2, Mar 31 2005, 00:05:10) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import time > >>> time.strftime("%T") > '22:50:49' > >>> time.strftime("%X") > '22:50:59' > I accept that, but still pain. Took me a while to filter out the problem in the code running on the Unix and not on M$. A. From sybrenUSE at YOURthirdtower.com.imagination Mon Aug 22 08:22:38 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 22 Aug 2005 14:22:38 +0200 Subject: Python dutch References: Message-ID: Sybren Stuvel enlightened us with: > I'd suggest learning English. The programming language is based on > English anyway. Besides, everybody in The Netherlands learns English > at school. Sorry, not a really helpful answer. There is plenty of docs in Dutch, which is of no surprise since Python's daddy is Dutch himself! Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From alanmk at hotmail.com Wed Aug 31 14:48:57 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Wed, 31 Aug 2005 19:48:57 +0100 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. In-Reply-To: <1125502430.504110.134500@f14g2000cwb.googlegroups.com> References: <1125502430.504110.134500@f14g2000cwb.googlegroups.com> Message-ID: [Alan Kennedy] >> (PCW, for those who don't know it, is sort of the UK's equivalent >> of Byte Magazine,except that it's still publishing after almost 25 >> years). [Paul Boddie] > Hmmm. Even Byte at its lowest point was far better than PCW ever was. Well, I mostly disagree, but you've got your opinion. I personally preferred Byte, particularly because of their orientation towards what the PC market would become, not just how it currently was, e.g. they would run articles on RISC vs. CISC, for example, when the "battle" was just starting. But Byte went out of business: obviously not enough people cared about what it had to say. PCW is, and always has been, focussed on the state of the market as is, which means they're always testing and reviewing the stuff you can get off the shelves right now. Whenever I buy a peripheral, e.g. scanner/fax, optical writer, digital camera, etc, I always check if PCW has anything to say about it, or about the class of peripherals: chances are they've done a reasonably thorough review quite recently. And they are still around, after all these decades, because they provide information that people want. [Alan Kennedy] >>The only problem was they listed the "manufacturer" of the software as >>SourceForge, so the product was known as "SourceForge SpamBayes". [Paul Boddie] > PCW may still be publishing after 25 years (half the magazine being > adverts probably keeps it just about economically viable), but they > clearly haven't yet managed to shake off that classic 1980s mindset > where "everything is a product by a company" (and, given the > superficial understanding of software licensing still likely to be > pervasive in the mainstream UK IT press, "everything else is public > domain"). Don't forget that the comprehension of IT journalists is generally a good indicator of the comprehension of the general computer-using public. But I generally find that the journos at PCW are a little more enlightened than average: rather than copying and pasting corporate product announcements, they actually use the stuff they comment on. I personally put great store in the fact that PCW awarded the Editors Choice award to SpamBayes, because it's based on actually *using* the software, rather than doing a simple feature comparison. 95% of the people who read the review and download/install SpamBayes won't give a monkeys what language it's written in. But they'll still have a modern python interpreter installed on their system as a consequence. IMHO, there is a great opportunity here for the python community: SpamBayes is a "best-of-breed" product in a very important market, anti-SPAM: it even beat commercial competitors. SPAM has become an enormous logistical, financial, commercial and legal problem across the world, purportedly costing billions of dollars(virus distribution, phishing, scams, etc). If the community ever wanted to prove python to be a serious language, here's a fine opportunity. Surely that's worth a simple team name, for mnemonic purposes if nothing else. Something different or unusual, like one of my favourites, "Legion of the Bouncy Castle", who are a group of Java cryptography dudes http://www.bouncycastle.org (Also, I've often seen PCW refer to open source apps as "manufactured" by individuals or teams: it's just that in this case the SpamBayes team have made no name available). > As for URLs and other things, last time I looked at the PCW Web site, > it was all time-limited (or page-view-limited) viewing for > non-subscribers. If British print distribution wasn't such a lock-in, > I'd imagine PCW would have taken its place alongside Byte, staring at > us from the print media fossil record. I didn't notice any complaints when PCW ran a story this time last year about Michael Sparks, python and python's use in the BBC's future distribution plans for digital TV. old-fashioned-ly'yrs, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From markmcintyre at spamcop.net Tue Aug 30 11:09:22 2005 From: markmcintyre at spamcop.net (Mark McIntyre) Date: Tue, 30 Aug 2005 16:09:22 +0100 Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: On Tue, 30 Aug 2005 11:30:19 GMT, in comp.lang.c , axel at white-eagle.invalid.uk wrote: >Why do I think of a Dutch expression 'mieren neuker' with regards to >Balmer's posts? Its a complete mystery. Just as is the reason why you are x-posting complete garbage to comp.lang.c... -- Mark McIntyre CLC FAQ CLC readme: ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From paolo_veronelli at tiscali.it Tue Aug 16 10:38:47 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 16 Aug 2005 16:38:47 +0200 Subject: A (unpythonic) pythonable mixin recipe. Message-ID: <4301FA77.6060707@tiscali.it> I had always been negative on the boldeness of python on insisting that unbound methods should have been applied only to its im_class instances. Anyway this time I mixed in rightly, so I post this for comments. ###### looking for a discovery .Start ################# class _Mixin(object): def __init__(self,main,instance,*args,**kwargs): # do mixin businnes main.__reinit__(self,instance) # the caveated interface # probably missing __reinit__ in main # one could assume main.__init__ should do def mixinMethod(self): print 'mixinMethod on',repr(self) def Mixin(instance,*args,**kwargs): klass=instance.__class__ return type('Mix+%s'%klass.__name__,(_Mixin,klass),{})(klass,instance) ############ end of hot water discovery ########## class Base(object): def __reinit__(self,another): # do something so that self is like another (painful in general) # easy for mutables, impossible for other pass b=Base() b=Mixin(b) assert isinstance(b,Base) b.mixinMethod() # doesn't fail with absurds #### The next doesn't work #### # l=[1,2,3] # l.__reinit__=l.__init__ # exception IMAConservativeLanguage class L(list): __reinit__=lambda self,other:list.__init__(self,other) l=L([1,2,3]) l=Mixin(l) l.mixinMethod() Regards Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From onurb at xiludom.gro Wed Aug 24 08:45:13 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 24 Aug 2005 14:45:13 +0200 Subject: What's the matter with this code section? In-Reply-To: <1124867880.762717.83780@o13g2000cwo.googlegroups.com> References: <1124867880.762717.83780@o13g2000cwo.googlegroups.com> Message-ID: <430c6bda$0$24729$636a15ce@news.free.fr> Johnny Lee wrote: > Here is the source: > (snip) > class TestCaseTest(TestCase): > def testRunning(self): > print "testRunning in TestCaseTest" > test = WasRun("testMethod") > assert(not test.wasRun) > test.run() > assert(test.wasRun) > def testSetUp(self): > print "testSetUp in TestCaseTest" > test = WasRun("testMethod") > test.run() Shouldn't it be test.setUp() instead ? Unless the problem is here: ### TestCase.run() calls self.setUp() class TestCase: (snip) def run(self): print "run in TestCase" self.setUp() method = getattr(self, self.name) method() ### WasRun.run() doesn't call self.setUp() class WasRun(TestCase): (snip) def run(self): print "run in WasRun" method = getattr(self, self.name) method() def setUp(self): print "in setUp of WasRun" self.wasSetUp = 1 BTW, if the only reason for overloading WasRun.run() is to print "run in WasRun", you can also modify parent's class run() method so it display the effective class name, not an hard-coded one: class TestCase: (snip) def run(self): print "run in %s" % self.__class__.__name__ self.setUp() method = getattr(self, self.name) method() and then remove run() from WasRun. There should be a simple solution to 'aspect' the debug/trace stuff with a decorator, like: def traced(func): def _wrapper(self, *args, **kwargs): print "%s method in %s class" % (func.func_name, self.__class__.__name) return func(self, *args, **kwargs) return _wrapper(func) class TestCase: @traced def run(self): self.setUp() method = getattr(self, self.name) method() (not tested, and I don't have much experience with decorators...) -- bruno desthuilliers ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@')" python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From tjreedy at udel.edu Wed Aug 31 17:39:18 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2005 17:39:18 -0400 Subject: Arguement error References: <6829832e050831133030a012f9@mail.gmail.com> Message-ID: "Jeffrey Maitland" wrote in message news:6829832e050831133030a012f9 at mail.gmail.com... Hello folks, >I am wondering why I am getting this error. when I try to run a script. >TypeError: translate() takes at most 3 arguments (10 given) Because you apparently gave it more than 3 args. >>> str.translate.__doc__ 'S.translate(table [,deletechars]) -> string\n\nReturn a copy of the string S, where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256.' >but the thing is the method translate actually accepts 10 arguements. Why do you think that? Terry J. Reedy From gene.tani at gmail.com Sun Aug 7 01:32:22 2005 From: gene.tani at gmail.com (gene tani) Date: 6 Aug 2005 22:32:22 -0700 Subject: Decline and fall of scripting languages ? In-Reply-To: <1123390288.402485.171020@o13g2000cwo.googlegroups.com> References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> Message-ID: <1123392742.576632.59400@z14g2000cwz.googlegroups.com> (copied from "Fat/Lazy" thread http://martinfowler.com/bliki/CollectionClosureMethod.html http://onestepback.org/index.cgi/Tech/Ruby/PythonAndRuby.rdoc From bokr at oz.net Wed Aug 31 11:13:50 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 31 Aug 2005 15:13:50 GMT Subject: Infinity syntax. Re: Bug in string.find; was... References: <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> <43156165.219034725@news.oz.net> <1125497606.359002.131900@g14g2000cwa.googlegroups.com> Message-ID: <4315c414.244297871@news.oz.net> On 31 Aug 2005 07:13:26 -0700, "Kay Schluehr" wrote: >Bengt Richter wrote: > >> How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ? >> That would give a consitent interpretation of seq[-1] and no errors >> for any value ;-) > >Cool, indexing becomes cyclic by default ;) > >But maybe it's better to define it explicitely: > > seq[!i] = seq[i%len(seq)] > >Well, I don't like the latter definition very much because it >introduces special syntax for __getitem__. A better solution may be the >introduction of new syntax and arithmetics for positive and negative >infinite values. Sequencing has to be adapted to handle them. > >The semantics follows that creating of limits of divergent sequences: > > !0 = lim n > n->infinity > >That enables consistent arithmetics: > > !0+k = lim n+k -> !0 > n->infinity > > !0/k = lim n/k -> !0 for k>0, > n->infinity -!0 for k<0 > ZeroDevisionError for k==0 > > >etc. > >In Python notation: > >>>> !0 >!0 >>>> !0+1 >!0 >>>> !0>n # if n is int >True >>>> !0/!0 >Traceback (...) >... >UndefinedValue >>>> !0 - !0 >Traceback (...) >... >UndefinedValue >>>> -!0 >-!0 >>>> range(9)[4:!0] == range(9)[4:] >True >>>> range(9)[4:-!0:-1] == range(5) >True Interesting, but wouldn't that last line be >>> range(9)[4:-!0:-1] == range(5)[::-1] >Life can be simpler with unbound limits. Hm, is "!0" a di-graph symbol for infinity? What if we get full unicode on our screens? Should it be rendered with unichr(0x221e) ? And how should symbols be keyed in? Is there a standard mnemonic way of using an ascii keyboard, something like typing Japanese hiragana in some word processing programs? I'm not sure about '!' since it already has some semantic ties to negation and factorial and execution (not to mention exclamation ;-) If !0 means infinity, what does !2 mean? Just rambling ... ;-) Regards, Bengt Richter From cam.ac.uk at mh391.invalid Wed Aug 24 11:12:56 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Wed, 24 Aug 2005 16:12:56 +0100 Subject: py-serial + CSV In-Reply-To: <1124820032.854336.278790@f14g2000cwb.googlegroups.com> References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> <1124820032.854336.278790@f14g2000cwb.googlegroups.com> Message-ID: McBooCzech wrote: > This (according to your suggestions) is my code which works for me > > import serial > s = serial.Serial(port=0,baudrate=4800, timeout=20) > while 1: > line = s.readline() > words = line.split(',') > if words[0]=="$GPRMC": > print words[1], words[3], words[5] > > I just wonder if there is some beter (or as you are saying "more > pythonic":) aproach how to write such a piece of code. import csv from serial import Serial port = Serial(port=0, baudrate=4800, timeout=20) for row in csv.reader(iter(port.readline, None)): if row[0] == "$GPMRC": print row[1], row[3], row[5] -- Michael Hoffman From a_geek at web.de Sat Aug 13 15:48:48 2005 From: a_geek at web.de (a_geek at web.de) Date: Sat, 13 Aug 2005 21:48:48 +0200 Subject: catching all exceptions [SOLVED] In-Reply-To: <42fe48d2$1@news.home.net.pl> References: <42fe48d2$1@news.home.net.pl> Message-ID: Hello, Tomasz Lisowski wrote: >> Well, actually the second statement doesn't even compile... any ideas >> why I shouldn't be able to catch "anonymous" exceptions like this, or >> whether and how I can (and only overlooked it)? [ one of three suggestions: ] > Try this: Ok, so the answer simply was that I didn't see "it", although the solution is in the manual. Thank you! Kind Regards, Toni From cam.ac.uk at mh391.invalid Mon Aug 1 08:46:36 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Mon, 01 Aug 2005 13:46:36 +0100 Subject: [path-PEP] Path inherits from basestring again In-Reply-To: References: Message-ID: Delaney, Timothy (Tim) wrote: > Hey - paths are special enough to warrant additional syntax, aren't they? I hope this is a joke :) -- Michael Hoffman From roccomoretti at hotpop.com Tue Aug 16 09:46:04 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Tue, 16 Aug 2005 08:46:04 -0500 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: <8c7f10c6050815075443fc446a@mail.gmail.com> <200508151316.34512.hancock@anansispaceworks.com> Message-ID: Simon Brunning wrote: > On 8/15/05, Terry Hancock wrote: > >>On Monday 15 August 2005 09:54 am, Simon Brunning wrote: >> >>>If you call its code, it's a library. If it calls yours, it's a framework. >> >>Such concision deserves applause. ;-) > > > Thank you. ;-) > > As others have pointed out, this is a *drastic* simplification, > perhaps an oversimplification. You will inevitably need to call a > framework's code in addition to it calling yours, and a callback > argument or two won't turn a library into a framework. But I think it > captures the essence of the difference. The point that passed me by the first time, and which Magnus et al. helped me realize, is that it's referring not to an instantaneous, mechanical view of calling, but to a more general, philosophical view of calling. With a library, the user's code is "in charge" of the program structure, and calls the library to fill in the details and help out. With a framework, the framework is "in charge", and the user code is filling in with a supporting role. With this in mind, it's easy to see why Andy Smith feels frameworks are restricting - after all, it's the framework, not the user, who is "in charge" of program structure. But I'm not sure if library vs. framework a fair comparison - the two are doing different things. With a framework, you're not really writing your own program, you're customizing someone else's. Sort of a vastly more flexible version of command line options. Saying you can't reuse code written for a framework is kind of like saying that it's difficult to use an Apache config file with the Gimp. From alessandro.bottoni at infinito.it Mon Aug 8 11:31:13 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Mon, 08 Aug 2005 15:31:13 GMT Subject: Is there a better/simpler logging module? Message-ID: <5VKJe.9469$HM1.273456@twister1.libero.it> I just tried to use the python standard logging module in a small program and I found myself lost among all those features, all those configuration options and so on. Is there any better/simpler logging module around? What do you use for logging in your programs? Thanks in advance. ----------------------------------- Alessandro Bottoni From spammers-go-here at spam.invalid Sat Aug 6 00:28:34 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sat, 06 Aug 2005 00:28:34 -0400 Subject: GUI programming, embedding, real time plots, etc. References: <42f4157f$0$18643$14726298@news.sunsite.dk> <1123296691.424699.172460@g14g2000cwa.googlegroups.com> Message-ID: <42f43c73$0$18642$14726298@news.sunsite.dk> nephish at xit.net wrote: > apt-get install python-pwm > this will get you python mega widgets > one of the dependencies that apt will take care of for you is the > python2.whatever-tk. > depending on which version of debian you are using. > i run sarge with python 2.3 Thanks for the help. I tried to write a piece of code to plot some simulated data from a measurement : from Tkinter import * import Pmw steps=(0,) voltages=(0,) master=Tk() plot=Pmw.Blt.Graph(master) plot.pack(expand=1,fill='both') for i in range(1,10): steps=steps+(i,) setvolt=1.0*i/100 voltages=voltages+(setvolt,) plot.line_create("Plot",xdata=steps,ydata=voltages) master.mainloop() This quits with : Traceback (most recent call last): File "", line 15, in ? File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwBlt.py", line 266, in line_create self.tk.call((self._w, 'line', 'create', name) + self._options(kw)) _tkinter.TclError: element "Plot" already exists in ".-1222950836" Now, if I try to plot from outside the loop (move the last statement in the loop out of it), it plots ok. I need to plot this in realtime. So, what would be the best approach ? From randy at psg.com Fri Aug 19 00:25:38 2005 From: randy at psg.com (Randy Bush) Date: Fri, 19 Aug 2005 04:25:38 +0000 Subject: dict duplicity References: <43052863$1@news.eftel.com> Message-ID: <17157.24386.878511.374626@roam.psg.com> > Firstly, to remove one possible source of confusion, change the name of > your dictionary ... "mydict" or "fred" ... anything but "dict" > > Next, after you have created the dictionary and added items to it, do this: > print len(fred) > print len(fred.items()) > nitems = 0 > for k, v in fred.iteritems(): > nitems += 1 > print nitems > > If by this stage you haven't worked out what you are doing wrong, post > an exact copy/paste of the MINIMAL code that exhibits the "multiple > instances of same key in .iteritems()" problem i did not work out what i was doing wrongly. but now it works. i hate ing magic! but thanks for making me permute. randy From aurora00 at gmail.com Thu Aug 11 17:44:08 2005 From: aurora00 at gmail.com (aurora) Date: Thu, 11 Aug 2005 14:44:08 -0700 Subject: performance of recursive generator References: <3uqdnVTPRY8yM2bfRVn-pQ@comcast.com> Message-ID: > You seem to be assuming that a yield statement and a function call are > equivalent. I'm not sure that's a valid assumption. I don't know. I was hoping the compiler can optimize away the chain of yields. > Anyway, here's some data to consider: > > -------------------- test.py -------------------- > def gen(n): > if n: > for i in gen(n/2): > yield i > yield n > for i in gen(n/2): > yield i > > def gen_wrapper(n): > return list(gen(n)) > > def nongen(n, func): > if n: > nongen(n/2, func) > func(n) > nongen(n/2, func) > > def nongen_wrapper(n): > result = [] > nongen(n, result.append) > return result > ------------------------------------------------- This test somehow water down the n^2 issue. The problem is in the depth of recursion, in this case it is only log(n). It is probably more interesting to test: def gen(n): if n: yield n for i in gen(n-1): yield i From luismgz at gmail.com Tue Aug 2 16:00:01 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 2 Aug 2005 13:00:01 -0700 Subject: Newer than a Newbe In-Reply-To: <1122958406.623954.117430@f14g2000cwb.googlegroups.com> References: <1122958406.623954.117430@f14g2000cwb.googlegroups.com> Message-ID: <1123012801.603826.253940@f14g2000cwb.googlegroups.com> linuxfreak wrote: > Look at Karrigell. Its a web framework for Python > > http://karrigell.sourceforge.net I second this suggestion. Karrigell is a pleasure to work with and I'm sure it will appeal any python fun who dare to play with it. I also hope Pierre (its developer) lose some of his modesty and start to show off this beatifull framework :-) because so far, he's been reluctant to promote it until he is 100% sure it's mature and stable (it's been ready for a long time though). From aahz at pythoncraft.com Tue Aug 9 15:20:41 2005 From: aahz at pythoncraft.com (Aahz) Date: 9 Aug 2005 12:20:41 -0700 Subject: namespaces References: Message-ID: In article , Paolino wrote: > >Why descriptor mechanism doesn't apply to modules? The real answer: Because Guido doesn't want it to -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From steve at holdenweb.com Thu Aug 25 07:54:27 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Aug 2005 07:54:27 -0400 Subject: MySQLdb module, method executemany with anything other than strings? In-Reply-To: <1124962000.842751.125710@g49g2000cwa.googlegroups.com> References: <1124962000.842751.125710@g49g2000cwa.googlegroups.com> Message-ID: olekristianvillabo at gmail.com wrote: > The method cursor.executemany is there in order to avoid multiple calls > to cursor.execute(). > > I have tried, with success, to do like every single example (that I > have found on the www) on the subject shows, to use a insert statement > on the form: > statement = INSERT INTO table (colA,colB,colC) values (%s,%s,%s) > > and pass in a list containing tuples > list = [('bla','bla','bla'),('bla','bla','bla'),('bla','bla','bla')] > > on the form > > cursor.executemany(statement,list) > > This works fine for all strings, but I have never been able to insert a > single integer or a float using this method. I get an error message > reporting that float (or an int) is required. > > Statement is then of course changed to something like > statement = INSERT INTO table (colA,colB,colC) values (%s,%i,%f) > list = [('bla',1,0.65),('bla',3,3.7),('bla',3,0.9)] > > Havee anybody experienced similar problems? > Am I doing something wrong? > Any feedback is greatly appreciated. > > > Here is som real output from the interpreter: > >>>>statement = 'insert into testtable3 (url,probability) values (%s,%f)' ^^ That's your problem, right there. >>>>l > > [('url1', 0.98999999999999999), ('url2', 0.89000000000000001)] > >>>>cursor.executemany(statement,l) > > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 181, in > execu > any > self.errorhandler(self, TypeError, msg) > File "C:\Python24\Lib\site-packages\MySQLdb\connections.py", line 33, > in de > lterrorhandler > raise errorclass, errorvalue > TypeError: float argument required > It's just that you should use "%s" for *all* parameters, no matter what their type: >>> conn = db.connect() >>> curs = conn.cursor() >>> curs.execute(""" ... create table thingy( ... f1 char(10) primary key, ... f2 float)""") 0L >>> l = [('url1', 0.98999999999999999), ('url2', 0.89000000000000001)] >>> curs.executemany(""" ... insert into thingy (f1, f2) values (%s, %s)""", l) 2L >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From dwelch91 at gmail.com Fri Aug 12 18:21:49 2005 From: dwelch91 at gmail.com (dwelch91 at gmail.com) Date: 12 Aug 2005 15:21:49 -0700 Subject: Running one Python program from another as a different user Message-ID: <1123885309.455560.220670@z14g2000cwz.googlegroups.com> Greetings- This is on Linux... I have a daemon running as root and I want to execute another Python program as another user (a regular user). I have the name of the user and can use the 'pwd' and 'grp' modules to get that user's user and group ids. What I don't understand is how to then go about launching that new program. I had considered having the launched program switch itself back to the target user (somehow), but the launched program is graphical in nature (PyQt), and I am afraid of X11 locking out the display to user root (many distros seem to ship with server access for user root turned off). That might prevent the launched program from even starting? Any ideas? My Google searching was not successful in figuring this out... Thanks, Don From bronger at physik.rwth-aachen.de Mon Aug 1 02:13:15 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Mon, 01 Aug 2005 08:13:15 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <861x5ehk4g.fsf@bhuda.mired.org> <87iryqzm1d.fsf@wilson.rwth-aachen.de> Message-ID: <87y87mxk04.fsf@wilson.rwth-aachen.de> Hall?chen! Cliff Wells writes: > On Sun, 2005-07-31 at 23:46 +0200, Torsten Bronger wrote: > >> Cliff Wells writes: >> >>> [...] >>> >>> Well, I think this exposes one of the more interesting sides of >>> open source software in general. For better or worse, you get >>> choices. If you don't like choice, you won't like open source. >> >> On the other hand, the GUI package bundled with Python is a >> regular decision of some sort of committee. > > No, it's a decision made by Guido some years ago that remains in > place because it's more pain to remove than to simple leave there. http://wiki.python.org/moin/TkInter suggests that it's a more or less regular decision. > Besides, define "bundled with". Described in the standard library documentation. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From sp1d3rx at gmail.com Thu Aug 4 13:17:34 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 4 Aug 2005 10:17:34 -0700 Subject: Windows command line problem In-Reply-To: <1123096085.320143.268140@g14g2000cwa.googlegroups.com> References: <1121699051.059188.55640@g43g2000cwa.googlegroups.com> <1121726398.861595.31350@g43g2000cwa.googlegroups.com> <1121759914.689112.272530@z14g2000cwz.googlegroups.com> <1121762108.120184.201340@g47g2000cwa.googlegroups.com> <1121812275.374283.224000@g47g2000cwa.googlegroups.com> <1123096085.320143.268140@g14g2000cwa.googlegroups.com> Message-ID: <1123175854.867335.35470@g44g2000cwa.googlegroups.com> Here's an example... ---- BEGIN TEST.PY ---- import sys print "Original:", sys.argv for arg in sys.argv: arg = arg.strip('-\x93\x96') # add chars here you want to strip print "Stripped:", arg ---- END TEST.PY ---- From could.net at gmail.com Sun Aug 14 08:45:09 2005 From: could.net at gmail.com (could ildg) Date: Sun, 14 Aug 2005 20:45:09 +0800 Subject: What does the word "quiet" mean in this paragraph? Message-ID: <311b5ce105081405453299b71b@mail.gmail.com> The paragraph is as below, I mark the word quiet with *** ***. ___________________________________ One problem with distributed applications is that if no data arrives over a long period of time, you need to wonder why. On one hand, it could be that the other program just hasn't had any information to send recently. On the other hand, the other program could have crashed. TCP handles this problem by allowing you to send an "Are you still alive?" message every so often to ***quiet*** connections. The way is to call setKeepAlive() with a value of true. ___________________________________ Please tell me what does the word "quiet" mean, Thank you~ From pwatson at redlinepy.com Mon Aug 15 13:06:37 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 15 Aug 2005 12:06:37 -0500 Subject: Using for in one-liner In-Reply-To: <1124124590.563497.241560@g43g2000cwa.googlegroups.com> References: <3mbu82F15h18oU1@individual.net> <1124124590.563497.241560@g43g2000cwa.googlegroups.com> Message-ID: <4300CB9D.2020809@redlinepy.com> BranoZ wrote: > Paul Watson wrote: > >>Can a for loop be used in a one-liner? What am I missing? >> >>$ python -c "import sys;for i in range(5): print i," >> File "", line 1 >> import sys;for i in range(5): print i, >> ^ >>SyntaxError: invalid syntax > > > This was tricky.. > > python -c $'import sys;\nfor i in range(5): print i,' > > Separate statements with and enclose it in $'string'. > > BranoZ I did try '\n' a few ways. But, I never thought to add a '$' before the string? What made you think of that? I cannot find any shell documentation about it either. Can you provide a reference? Thanks. From mynews44 at yahoo.com Sun Aug 7 20:14:10 2005 From: mynews44 at yahoo.com (googleboy) Date: 7 Aug 2005 17:14:10 -0700 Subject: Some newbie cgi form questions... In-Reply-To: References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> <1123429640.905460.140210@o13g2000cwo.googlegroups.com> Message-ID: <1123460050.807204.326680@o13g2000cwo.googlegroups.com> Robert Kern wrote: > Diez B.Roggisch wrote: > >>Traceback (most recent call last): > >> File "/var/www/users/senta/html/gobooks/cgi/form.py", line 35, in ? > >> if not form.keys()[key]: > >>TypeError: list indices must be integers > >> > >>As you can see, I am using python 2.3 (my web service provider is > >>responsible for this - I'd use 2.4.1 if I could) > > > > That code above can't work - you want something like > > > > if not form.keys() in key: > > This thread has to rank somewhere in the top ten threads with respect to > the density of obviously wrong code samples. LoL! Yeah, I am guessing I started out not too far from something that was doing what I wanted until now, I have gradually moved further and further away from stuff that looks to me like it should work as python code. I've even managed to turn code that was working into code that is broken somehow... At the moment this bit of code is about validating that stuff was entered into the form properly, and about doing something with some types of form inputs and not others. I try all sorts of things and they just give me exception errors. And I just don't know what use to make of advice that says stuff like "The form is not a dictionary." :( I have spent the whole weekend doing searches and reading tutorials on this before I posted, I have a form that I get working and doing most of what I want. It is just the last bits that I can't figure out, and the tutes don't seem to cover the stuff I am trying to do. O well, I guess I will go bang my head against it or a few more days and then hopefully an answer will show up in my brain somewhere. Thanks for your help. Googleboy. From michaels at rd.bbc.co.uk Tue Aug 2 06:05:16 2005 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Tue, 02 Aug 2005 11:05:16 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: Phil Hunt wrote: > Kamaelia seems it might be an interesting project. However, I don't > think the project is well served by this announcement -- which I > find vague and hard to understand. Which is a shame, because it > means that other people probably don't understand it very well > either, which means less people will use it. It is a shame, and thanks for mentioning this. Let me have another go :-) (ripping to shreds welcome :) OK, here's a better go. (It's always difficult to think where to pitch this sort of thing) ---START--- The project aims to make it simple to build networked multimedia systems (eg audio, video, interactive systems), which are naturally componentised and naturally concurrent allowing quick and fast reuse in the same way as Unix pipelines do. It is designed as a practical toolkit, such that you can build systems such as: * Ogg Vorbis streaming server/client systems (via vorbissimple) * Simple network aware games (via pygame) * Quickly build TCP based network servers and clients * Quickly build Multicast based network servers and clients It runs on Linux, Window, Mac OS X with a subset running on Series 60 phones. The basic underlying metaphor of a component us like an office worker with inboxes and outboxes, with deliveries occuring between desks, offices, and depts. The component can thus do work anyway it likes but only communicates with these inboxes and outboxes. Like office workers, components run in parallel, and to achieve this are generally implemented using python generators, but can also used threads. The rationale behind the project is to provide a toolkit enabling the development of new protocols, including streaming, for large scale media delivery. The license essentially allows use in proprietary systems without change, but all changes to the system itself must be shared. ---END--- Is that clearer ? A short summary of all that could be: """Kamaelia is a networking/communications infrastructure for innovative multimedia systems. Kamaelia uses a component architecture designed to simplify creation and testing of new protocols and large scale media delivery systems.""" Hopefully that's clearer than: >>Kamaelia is a collection of Axon components designed for network >>protocol experimentation in a single threaded, select based >>environment. Axon components are python generators are augmented by >>inbox and outbox queues (lists) for communication in a communicating >>sequential processes (CSP) like fashion. [ which you noted "I really have very little idea what this means." ] > The information I can guess out of this is: "Kamaelia is a library > for creating network protocols that sit on top of tcp and/or udp". > Given that it's a BBC project, I imagine we're talking about > protocols for transferring large amount of data, e.g. sound or > motion pictures. Indeed. However, if you're having to guess I'm not doing the best job (despite trying!) at explaining this. >>More background on the motivations behind Kamaelia >>can be found here: http://kamaelia.sourceforge.net/Challenges/ > > There's something interesting here: > > In Building Public Value, the BBC has committed to the delivery of > BBC content to the British Public over this multitude of systems, > in a way that is enjoyable, accessible and **repurposable** by the > British Public in the way they choose. > > (my emphasis) > > This is a laudable aim, but if the BBC want to do this, the first > step they could make is to open up their content under a Creative > Commons licence. I would suggest that you forward this comment directly to the team involved in working on the Creative Archive. You can do this via this URL: * http://creativearchive.bbc.co.uk/ This is unfortunately not as simple as "just putting stuff up", and any comments you have, I'm sure would be welcome. However, the Creative Archive hasn't yet been put to a Public Value Test (including impact on industry), and rights is a much more problematic issue than you might expect. (eg background music on the radio in eastenders, posters on people's walls...) There's also http://www.bbc.co.uk/info/contactus/form.shtml which might be more appropriate. On a positive note, the Creative Archive has more organisations involved than just the BBC, it inlucde the BFI , Channel 4, Open University & Teachers'TV, so even if these things take longer than some people might like they do seem to be moving. Public organisations are weighed down whether the should do something, as well as whether they can. BBC R&D's role in this is to make these decisions possible. > They could start with their news, current affairs > and documentaries. BBC Backstage is a start here - at least with some of the online content. (http://backstage.bbc.co.uk) > But the download only staryed up for a week, and they didn't put the > files under a CC license, so they could be redistributed. Why not? It > would have cost them no more to do so than what they did, and > would've provided better value for downloaders and music lovers. I can pass on that request if you're interested in an answer - I'm not personally aware of the rationale behind it only being up for a week. > BTW, the html is broken in that it's very poorly written, It's written using a PyQT based WYSIWYG editor (written on my time, not the BBC's) that has the limitation that preformatted text gets squished (since the editor doesn't support the pre tag - or indeed a lot of other tags). At some point I'll fix the editor to handle pre-formatted text, but it's not a priority right now. (Should it be?) The HTML isn't really *that* bad as far as generated code is concerned IMHO, and is directly what the PyQT QTextEdit widget creates. (It's not that great either - you may notice it doesn't have proper headings either) > doesn't use CSS, This isn't a problem IMHO, YMMV. The site's been tested on a variety of browsers/platforms and looks pretty much the same on all. > I guess the main question that needs to be answered is "Why would I, > as a programmer, use Kamaelia?" Probably the most interesting response I've had back from people who've picked it up is that it's FUN. You can write small sketches (throwaway code fragments), rewrite their inputs/outputs to take data from inboxes & outboxes, and then it's usable in a much wider system. It encourages reuse of code, and assimilating existing systems can be relatively trivial. For example, trivial sketches: * A program to display an image using pygame * A program that can understand when an area of space has been clicked. (call it a button) * A program that can print a list of filenames, pausing waiting for a user to press return. (call it a chooser) Trivial changes: * Take the filename of the image from an inbox * Rather than print the filenames to send the filename to an outbox. * Rather than wait for a user to press a key, wait for a message on an inbox. A useful composition linking some of these together: Graphline( CHOOSER = Chooser(items = files), IMAGE = Image(size=(800,600), position=(8,48)), NEXT = Button(caption="Next", msg="NEXT", position=(72,8)), PREVIOUS = Button(caption="Previous", msg="PREV",position=(8,8)), linkages = { ("NEXT","outbox") : ("CHOOSER","inbox"), ("PREVIOUS","outbox") : ("CHOOSER","inbox"), ("CHOOSER","outbox") : ("IMAGE","inbox"), } ).run() And you have a simple presentation tool ! Another example. The visualisation framework was originally a stand alone piece of code and was essentially just a piece of eye candy. I threw in a few yields into certain locations. File reading & static graph construction was replaced with recieving data from inboxes, and then it was available for use (and networked after creating trivial protocol components). A piece of eye candy is now a useful tool. It's likely to gain the ability to send to an outbox a message saying "this blob is clicked" meaning we can have 'WYSIWYG' GUI based construction of pipelines easily. It's designed literally as a tool for making it simple to bolt things together with minimal change. (Which means you choose what you use, not the framework.) The system also lends itself to test driven and network independent development, something not that simple normally with network protocols. Why wouldn't you use it? When Twisted is appropriate (Twisted is a more mature framework). Michael. -- Michael.Sparks at rd.bbc.co.uk, http://kamaelia.sourceforge.net/ British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) contains personal views which are not the views of the BBC unless specifically stated. (THIS IS NORMALLY AT THE BOTTON OF MY EMAILS, BUT IT'S REALLY, REALLY, REALLY THE CASE THIS TIME!!!) From zarnovican at gmail.com Fri Aug 19 11:38:56 2005 From: zarnovican at gmail.com (BranoZ) Date: 19 Aug 2005 08:38:56 -0700 Subject: Newbie Question In-Reply-To: References: Message-ID: <1124465936.220597.140290@g47g2000cwa.googlegroups.com> Michael.Coll-Barth at VerizonWireless.com wrote: > >>> x = '22,44,66,88,"asd,asd","23,43,55"' > >>> y = eval(x) > >>> y > (22, 44, 66, 88, 'asd,asd', '23,43,55') > > And now, a question for the experts. I'm no expert, just experienced. > Does anyone have a pointer as to why my code might be > dangerous? Well, the smallest problem you have here is that you will get an SyntaxError exception on badly formated input. x = 'z,22,44,66,88,"asd,asd","23,43,55"' eval(x) NameError: name 'z' is not defined In worse case, somebody will send you a carefuly formated input that you will run blindy (just like in case of buffer overflows). CSV is easy with the module.. import csv cr = csv.reader((x,)) print cr.next() ['z', '22', '44', '66', '88', 'asd,asd', '23,43,55'] Usually, you will use the csv module, like this: import csv, sys for line in csv.reader(sys.stdin): # print line[3] BranoZ From wouter at voti.nl Tue Aug 23 15:06:47 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Tue, 23 Aug 2005 19:06:47 GMT Subject: Doubt C and Python References: Message-ID: <430b7335.1489472047@news.xs4all.nl> > I want to know the link between c and python. Apart from the fact that the inner part of Python is written in C I know no link? > Some people with C background use Python instead >of programming in C.why? I use Python when my time is most valuable (in most cases it is), in the very few cases the computer's time is more valuable I write in C/C++. Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From n00m at narod.ru Wed Aug 31 09:03:00 2005 From: n00m at narod.ru (n00m) Date: 31 Aug 2005 06:03:00 -0700 Subject: Sockets: code works locally but fails over LAN Message-ID: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433)) s1.bind((host, port)) s1.listen(1) cn, addr = s1.accept() def VB_SCRIPT(): while 1: data = cn.recv(4096) if not data: return s2.send(data) print 'VB_SCRIPT:' + data + '\n\n' def SQL_SERVER(): while 1: data = s2.recv(4096) if not data: return cn.send(data) print 'SQL_SERVER:' + data + '\n\n' thread.start_new_thread(VB_SCRIPT,()) thread.start_new_thread(SQL_SERVER,()) ============================================= The above code acts as an intermediator between a very simple VB script and SQL Server. Like follows: the vbs sends its requests to "fake" port 1434 and the python code catches and re-sends them to sql server which listens to its DEFAULT port = 1433... And vice versa. ========================================================= VB script: ========================================================= Set cn = CreateObject("ADODB.Connection") cn.Open _ "Provider=sqloledb;Data Source=192.168.0.3,1434;" & _ "Network Library=DBMSSOCN;Initial Catalog=pubs;" & _ "User ID=qwe;Password=asdasd;" cn.Execute "select * from authors;" cn.Close Set cn = Nothing ========================================================= It works fine (I see all client/server data printed in IDLE window)but only locally. I.e. if vbs, python and sql server run on the same machine. If I run the vbs from some other machine in my LAN then it fails to work out properly. Below is all that vbs and sql server are able to say to each other: =========================================================== VB_SCRIPT:    SERVER qwe asdasd 000000a5 ???Ut  Microsoft (r) W 192.168.0.3,1434  asdasd  OLEDB   SQL_SERVER:  ? 3 ? pubsmaster?0 E  # Changed database context to 'pubs'.W ?  us_english ?4 G  ' Changed language setting to us_english.W ? cp1251 ?  Microsoft SQL Server _ ?? 40964096? VB_SCRIPT:  G   4096  ========================================================== In abt 30 seconds OLE DB Provider (on the vbs side) reports "General Network Error". PEOPLE, WHY ON THE EARTH IT DOES NOT WORK OVER LAN ??? PS: Of course, without involving Python into the process vbs and sql server communicate with each other just fine - no matter locally or over LAN; on win2k machines or on/from NT 4.0 machine. From peter at engcorp.com Mon Aug 29 17:19:19 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 29 Aug 2005 17:19:19 -0400 Subject: Exploring outlook contents In-Reply-To: <1125336375.499390.276520@g44g2000cwa.googlegroups.com> References: <1125336375.499390.276520@g44g2000cwa.googlegroups.com> Message-ID: Subir wrote: > I am trying to build an application to explore the contents of an > outlook .pst files. All the reference that I have seen uses the > registry to do so. Does any one know any other way of doing this. Also, > is anyone has any code which does something related to this, please let > me know. Are you trying to do this without Outlook installed? Last time I checked, the format was proprietary and rather undocumented, and all approaches that I found relied on having Outlook actually installed on the machine. -Peter From tjreedy at udel.edu Sun Aug 7 21:32:04 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 7 Aug 2005 21:32:04 -0400 Subject: Proposed new collection methods References: <86d5oqvfqf.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86d5oqvfqf.fsf at bhuda.mired.org... > Another thread pointed out a couple of methods that would be nice to > have on Python collections: find and inject. Since Python does not have a collections superclass, I am puzzled as to what you are really proposing. > find with no arguments is identical to the any function, > except it's [find is] a method. Again, a method of what? The virtue of functions of iterables is that once written, the functionality immediately becomes available to *EVERY* iterable -- for free. Moreover, anybody can write one of the infinite number of such functions and use it *without* begging Guido (or Mats) to please add it to a perhaps already overly long list of methods of the collection superclass. > An alternative to adding a new method to collections would be adding a > new keyword argument - test - to the list index method. This would > remove the overlap of functionality with any. However, it would also > mean you couldn't use it on anything but lists (and presumably > strings). I'm not sure how serious a restriction that is. Compared to the infinite universe of possible iterables, the restriction is pretty severe. Index should perhaps be turned into a universal iterable function. You could suggest that any() get an optional keyword or 2nd param. In Python, generic functions are functions. Methods are functions properly restricted to one or a few classes and perhaps subclasses. > def inject(self, op, init = None): > return reduce(op, self, init) You aren't seriously suggesting that reduce be renamed to something more obscure, even contradictory, are you? Inject means to add something into, while reduce usually means to pull a summary out of. Perhaps I missed something. Terry J. Reedy From rkern at ucsd.edu Wed Aug 17 14:10:42 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 17 Aug 2005 11:10:42 -0700 Subject: Testing for presence of arguments In-Reply-To: <43036087$0$18639$14726298@news.sunsite.dk> References: <430353e1$0$18641$14726298@news.sunsite.dk> <1124293800.587084.302130@g43g2000cwa.googlegroups.com> <43036087$0$18639$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > Unrelated question, how does one call a fortran 95 subroutine from python ? > I need really high speed of execution for that call (needed for each > measurement point, and is used to calculate some parameters for the > excitation for the next measurement point) and a scripting language would > not cut it. http://cens.ioc.ee/projects/f2py2e/ -- 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 Tue Aug 23 06:25:23 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 12:25:23 +0200 Subject: Library and real path name References: <430af2d2$0$8495$5fc30a8@news.tiscali.it> Message-ID: Michele Petrazzo wrote: > I want to redistribute the library that I create. > I create a project, its setup.py that when launched copy all files into > the "site-packages/library" directory. And here it's all ok. > When I call my library with: > > import library > library.class() > > I want that my library know where are its real path > (site-packages/library/) you can use the __file__ or __path__ variables to determine this. e.g. # get this module's directory import os prefix = os.path.dirname(__file__) or, inside a package __init__.py file: # get package's main directory prefix = __path__[0] From randy at psg.com Sat Aug 27 23:48:31 2005 From: randy at psg.com (Randy Bush) Date: Sat, 27 Aug 2005 17:48:31 -1000 Subject: list insertion References: <431116b4.2601142154@news.oz.net> Message-ID: <17169.13327.52494.277304@roam.psg.com> >> hold = self.next >> self.next = DaClass(value) >> self.next.next = hold >> >> but i suspect (from print statement insertions) that the result >> is not as i expect. as the concept and code should be very >> common, as i am too old for pride, i thought i would ask. > I think you're fine. indeed. the bug was elsewhere. i got confused and tried to look-ahead too far when i could have just recursed. i threw away the too-clever code and replaced it with one line. i love it when that happens. randy From wouter at voti.nl Sun Aug 28 15:38:15 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Sun, 28 Aug 2005 19:38:15 GMT Subject: Doubt C and Python References: <430b7335.1489472047@news.xs4all.nl> Message-ID: <43121175.86355773@news.xs4all.nl> >> I use Python when my time is most valuable (in most cases it is), in >> the very few cases the computer's time is more valuable I write in >> C/C++. > >In cases when the computer's time is more valuable, why not use CPython >with C/C++ API? Only most time consuming parts can be replaced to C/C++ >codes so as to increase the speed up to native C/C++ programs). That assumes that one knows which are the most time-consuming parts, that they are few (which is typically, but not always, the case) and that they are 'fit' to be transferred to the C/C++ domain. The one application I have written the last few years that probably would not be fit to this approach is a compiler (Jal). It spends most of its time walking the annotated syntax tree, with a lot of code contributing rather evenly to the CPU time. Don't take me wrong, IIRC that is the *only* PC program I have written the last few years for which I selected the language and the language was not Python :) But I mainly program PICs. Where is the 10F200 Python interpreter when you need one? Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From rmanx at gmx.de Mon Aug 22 11:05:46 2005 From: rmanx at gmx.de (Robert) Date: Mon, 22 Aug 2005 17:05:46 +0200 Subject: Error with Python Message-ID: Hello I have created a tool in Python 2.3 under WinXP Now I extended this tool and now my tool makes Python crash. I see Dr Watson showing a stacktrace. This tool also uses wxPython. Dr Watson says: AppName: python.exe AppVer: 0.0.0.0 ModName: python23.dll ModVer: 2.3.5150.1012 Offset: 0003736a The stacktrace is very long and I don't know how to copy and paste it, because it cannot be selected. (I have made some screenshots) Python crashes as I can see from my tools log file, when the tool is handling messages on the Queue object. My tool is multi threaded and unsing Queue to send messages between threads and the main GUI thread. My questions now are: - can I get some help from somebody on this problem (is Python 2.3 supported)? - how do I find out if this is Python or wxPython related problem? - which information or tool could help me to search for the problem myself? - do I have to be the absolute Python guru to find the problem or is it enough to know programming a little bit? - where to start? I would change to Python 2.4 but then I have also to change to new wxPython and this is a big migration effort (I have tried already). Hope someone can give me some hints... Regards Robert From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 1 12:02:20 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 01 Aug 2005 18:02:20 +0200 Subject: Getting not derived members of a class In-Reply-To: References: <1122907402.650512.213470@g47g2000cwa.googlegroups.com> Message-ID: <3l6v2gF115ttuU1@individual.net> Franz Steinhaeusler wrote: > The background: > I want to create a code completition for an editor component. > It should distinguish between inherited and non inherited members. > Reason is, that on wxPython, most classes are derived from wxWindow. > For example if I want Code completition for wx.Frame, > I always get the 200 or so suggestions, > whereby most times, I'm only interested in the possible completions of > wx.Frame and maybe wx.TopLevelWindow. You can, of course, always search the base classes and subtract the two sets (all members)-(members of baseclasses). For example: cls = wx.Frame set(dir(cls)) - reduce(set.union, [set(dir(base)) for base in cls.__bases__]) Reinhold From eric.paquet at isrec.ch Tue Aug 30 04:57:49 2005 From: eric.paquet at isrec.ch (Meo) Date: 30 Aug 2005 01:57:49 -0700 Subject: array of arrays question Message-ID: <1125392269.199866.64910@f14g2000cwb.googlegroups.com> Hi, Here is what I'm doing in python 2.4.1 : >>> aOfa=[[[]]*3]*4 >>> aOfa [[[], [], []], [[], [], []], [[], [], []], [[], [], []]] >>> aOfa[3][2].append(1) >>> aOfa [[[1], [1], [1]], [[1], [1], [1]], [[1], [1], [1]], [[1], [1], [1]]] Ok, so there is something I didn't understand about python's arrays. The result I was expecting was : [[[], [], []], [[], [], []], [[], [], []], [[], [], [1]]] Somebody understand what's going on here? Thank From mohammed at aims.ac.za Mon Aug 22 15:44:49 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Mon, 22 Aug 2005 21:44:49 +0200 Subject: split function Message-ID: <430A2B31.90104@aims.ac.za> Dear All What i want to do is , my input is like 0 2 0 3 0 4 1 2 1 4 2 3 3 4 I am comparing and put the number in group , like ,the first three lines , all has zero as first input for each line, so the out put should look like 0 2 3 4 and so on 1 2 4 2 3 3 4 I managed to do what i need , but i did in this case , there is no space between numbers , like 02 03 04 12 14 23 34 so , how can i do this with spaces between numbers This is my code def belong_to(x,a): c=-1 for i in range(len(a)-1): if x==int(a[i]): c=i return c def list_belong(x,a): # This function to check if this line c=-1 # line has been searched before or not for i in range(len(a)): if a[i]==x: c=1 break return c x=0 occur=[] in_file=open('data.dat','r') out_file=open('result.dat','w') fileList = in_file.readlines() for k in fileList: v=k occur.append(k) n=len(v)-1 for i in range(n): temp=int(v[i]) print temp, out_file.write(str(temp)) for line in fileList: if v!=line: if list_belong(line,occur)!=1: if belong_to(temp,line) != -1: j=belong_to(temp,line) for i in range(len(line)-1): if i!=j: print line[i], out_file.write(line[i]) print out_file.write("\n") out_file.close() in_file.close() From tomi.kyostila at gmail.com Mon Aug 22 15:42:51 2005 From: tomi.kyostila at gmail.com (=?ISO-8859-1?Q?Tomi_Ky=F6stil=E4?=) Date: Mon, 22 Aug 2005 22:42:51 +0300 Subject: How to print the name of a list? In-Reply-To: <1124727846.909693.129750@g43g2000cwa.googlegroups.com> References: <1124727846.909693.129750@g43g2000cwa.googlegroups.com> Message-ID: oriana.falco at thalesesec.com wrote: > Hi! > > I was wondering what can I do to print the name of a list that is > inside a list. For example: > > > exported = ['123','456'] > imported = ['789','012'] > > client1 = ['cl1b','cl1a'] > client2 = ['cl2a','cl2b'] > > host = ['imported','exported'] > client = ['client1','client2'] > > list = ['host', 'client'] > > My goal is to print a string that reads: > 'host imported 789' > ...and subsequently print more strings that read: > 'host imported 012' > 'host exported 123' > 'host exported 456' > ..... > > > Thanks in advance for the help.... > Oriana > def printContents(seq, output=""): for itemname in seq: item = globals().get(itemname, None) if isinstance(item, (list, tuple)): printContents(item, "%s%s " % (output, itemname)) else: print "%s%s" % (output, itemname) exported = ['123','456'] imported = ['789','012'] client1 = ['cl1b','cl1a'] client2 = ['cl2a','cl2b'] host = ['imported','exported'] client = ['client1','client2'] # you shouldn't reassing 'list', so let's call it something else namelist = ['host', 'client'] printContents(namelist) Output: host imported 789 host imported 012 host exported 123 host exported 456 client client1 cl1b client client1 cl1a client client2 cl2a client client2 cl2b Let me know if this wasn't what you wanted :) -- dOb From rlb at hoekstra-uitgeverij.nl Wed Aug 24 02:09:57 2005 From: rlb at hoekstra-uitgeverij.nl (Richard Bos) Date: Wed, 24 Aug 2005 06:09:57 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <1124816780_7123@spool6-east.superfeed.net> Message-ID: <430c0eed.59907997@news.xs4all.nl> l v wrote: > Mike Schilling wrote: > > A formatting-only subset of HTML would be useful for both e-mail and Usenet > > posts. > > I would *agree* (your news reader may bold that last word) It had bloody better not. You're cross-posting this to a C newsgroup, where *ptr* 4 is a legal (albeit inadvisably spaced) expression. Richard From sklass at pointcircle.com Thu Aug 25 14:28:09 2005 From: sklass at pointcircle.com (rh0dium) Date: 25 Aug 2005 11:28:09 -0700 Subject: Superclass files and order - oh my!! Questioning the experts!! Message-ID: <1124994489.853664.188260@f14g2000cwb.googlegroups.com> Hi all, Still a newbie but making some headway. So I have a file structure like this.. top/ --modules/ ----metrics.py --metrix/ ----uptime.py Now metrics.py is my superclass, and uptime.py inherits the superclass metrics.py. So for arguments sake metrics.py ---------------- class metrics(): def __init__(self, foo=bar): self.foo=foo def run(): pass ---------------- uptime.py ---------------- class metrics(metrics): def run(): print "hello" if __name__ == '__main__': if os.path.exists("../modules"): print "importing modules" sys.path.insert( 0, "../modules") import metrics else: print "Unable to bring in main metric instance - path not correct" sys.exit(1) ---------------- Now if simply try to run ./uptime.py it complains about not having the metrics module? Huh but I brought it in? File "./uptime.py", line 19, in ? class uptime(metrics): NameError: name 'metrics' is not defined BUT... If I do this then it it imports.. ( NOTE the order is different.. ) uptime.py ---------------- if os.path.exists("../modules"): print "importing modules" sys.path.insert( 0, "../modules") import metrics else: print "Unable to bring in main metric instance - path not correct" sys.exit(1) class metrics(metrics): def run(): print "hello" if __name__ == '__main__': pass ---------------- But I get the next erorr: Path exists importing modules Traceback (most recent call last): File "./uptime.py", line 34, in ? class uptime(metrics): TypeError: Error when calling the metaclass bases module.__init__() takes at most 2 arguments (3 given) So the question is.. Why is it not looking at the "if __name__ == '__main__':" statement and starting there? I thought it was supposed to do that? Why can't I just put a class statement in a file and if you put nothing (like if __name__....) the class is just "registered" so later if (like __main__) I use it then it's available. I want to not have to put that ugly code at the top but it seems as though that's the only way? Someone must have figured this out and can you explain why it workst this way? I must be missing something cause that's how modules work. How is this different than a module? From http Sun Aug 7 04:44:23 2005 From: http (Paul Rubin) Date: 07 Aug 2005 01:44:23 -0700 Subject: Python -- (just) a successful experiment? References: Message-ID: <7xslxmxhjs.fsf@ruckus.brouhaha.com> "Eric Pederson" writes: > Maybe: > -- Automatic dependency handling > -- Tightly coupled GUI package ("tightly coupled" ~= "Pythonic") > -- High level IDE (i.e. intuitive drag and drop GUI builder) > -- High level database framework (perhaps a mature, killer Dabo) > -- Powerful web framework as good as the language (and simple enough for the PHP guys to use) > -- Etc. Are you saying Ruby on Rails has all that in the quick-install? From peter at engcorp.com Wed Aug 3 15:19:53 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 03 Aug 2005 15:19:53 -0400 Subject: socket and os.system In-Reply-To: References: Message-ID: mfaujour wrote: > I HAVE THIS PYTHON PROGRAMM: [snip] > socket.error: (98, 'Address already in use') > > DOES SOMEONE HAS AN IDEA ? PLEASE learn to format your questions more appropriately! Your post is simply _awful_ to read. At the very least, ALL CAPS is considered to be "shouting", though I can see why you had to use them since it would have been impossible to see the questions amongst all the code. In any case, assuming I've been able to guess at the specific problem based on the above lines, which isn't certain, you need to use a line something like this in your code to allow your server socket to bind to an address that was previously in use: server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) For more background, I suggest a Google search on "python so_reuseaddr". -Peter From philippe.dalet at voila.fr Sat Aug 13 08:55:03 2005 From: philippe.dalet at voila.fr (pdalet) Date: 13 Aug 2005 05:55:03 -0700 Subject: Parallel port programming on windows XP / 2000 In-Reply-To: References: Message-ID: <1123937703.604211.296170@g14g2000cwa.googlegroups.com> I have written a python script with pyparallel pyDS1267 (W2K, pyparallel 0.1, giveio_setup.exe, pythoncard), with no problems on this OS. I have not tested with pyparallel 0.2 pyDS1267, pyUltraISR http://sourceforge.net/projects/gpib82357a/ philippe.dalet at voila.fr lyp champollion av pezet 46100 FIGEAC FRANCE Novice Experl a ?crit : > I'm still stuck... my script is finished and works just fine on win98 using pyparallel, but I still haven't seen any sample code to do access the port in XP / 2000. > > If I don't make progress soon, I'll need to find a solution in another language, which I don't really want to do. > > > --------------= Posted using GrabIt =---------------- > ------= Binary Usenet downloading made easy =--------- > -= Get GrabIt for free from http://www.shemes.com/ =- From gregpinero at gmail.com Tue Aug 23 13:05:04 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 23 Aug 2005 13:05:04 -0400 Subject: High Level FTP library In-Reply-To: <1124816180.938426.258200@g49g2000cwa.googlegroups.com> References: <7NGOe.6737$Nb2.115820@news1.nokia.com> <1124816180.938426.258200@g49g2000cwa.googlegroups.com> Message-ID: <312cfe2b050823100551e56c84@mail.gmail.com> I reccomend ftputil (http://www.sschwarzer.net/python/python_software.html) also. I went through the same thing you did about 2 months ago and ftputil was the best I found. Here's a short script I wrote using ftputil: http://www.blendedtechnologies.com/instant-gratification-for-a-home-web-developer/15 -Greg On 23 Aug 2005 09:56:20 -0700, billuseslinux at gmail.com < billuseslinux at gmail.com> wrote: > > Paulo Pinto wrote: > > Hello, > > > > Is there any Python library similar to NET::FTP from Perl? > > ftplib seems too lowlevel. > > > > I already found a few, but would like to get one that is > > endorsed by the community. > > > > Thanks, > > Paulo > > > Have you looked at ftputil? > > http://www.sschwarzer.net/python/python_software.html > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnb at itga.com.au Wed Aug 10 03:26:21 2005 From: gnb at itga.com.au (Gregory Bond) Date: Wed, 10 Aug 2005 17:26:21 +1000 Subject: Adding and attribute to an instance In-Reply-To: <1123623524.732496.79460@g49g2000cwa.googlegroups.com> References: <1123623524.732496.79460@g49g2000cwa.googlegroups.com> Message-ID: <42F9AC1D.8020702@itga.com.au> J wrote: > I have looked at some of the source code in PyObject_GenericGetAttr and > it turns out that the object has no dictionary. It seens that the > address of the dictionary is computed somehow via tp_dictoffset in the > type object. I asked this a few months ago...... Basically, you need a PyObject * in your object record: struct PyStruct { PY_OBJECT_HEAD // ... PyObject *dict; // .... } then add the offset to the tp_dictoffset member in the type struct: PyTypeObject PyType { // .... offsetof(PyStruct, dict), /* tp_dictoffset */ // ... Make sure you init this member to 0 (tp_init), and make sure you PyXDECREF() it when the object is deleted (tp_dealloc). Optionally: add a __dict__ entry to the PyMemberDefs so that obj.__dict__ works (tho this is not necessary): {"__dict__", T_OBJECT, offsetof(PyStruct, dict), READONLY }, The ROOOOOOLY cool bit: You don't need to add the dictionary with PyDict_New() etc, because the python runtime will create this dict the first time a new attrribute is added. So the cost of this feature for object instances that don't have extra attributes is just 4 unused bytes in the instance record! This is just sooooooo cool. Greg. From rkern at ucsd.edu Mon Aug 8 06:53:11 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 08 Aug 2005 03:53:11 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <20050808005104.862503556.EP@zomething.com> References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <20050808005104.862503556.EP@zomething.com> Message-ID: EP wrote: > Robert Kern wrote: > >>Which is exactly why I said at the beginning that people shouldn't >>bother with this thread and should instead just get to work. > > Robert, you are probably right, but I think how we get to work is important as well. > > What I posted was a little intellectually thin, but it would be nice to stir the collective energy toward some common (and useful) objectives. What I'm trying to say is that posting to c.l.py is absolutely ineffective in achieving that goal. Code attracts people that like to code. Tedious, repetitive c.l.py threads attract people that like to write tedious, repetitive c.l.py threads. In the open source world, you can't tell people what to do. It's often a waste of time even to try to get them to *agree* on what they should do particularly when the group ("Python programmers") is so large and the goals ("create a powerful web framework as good as the language") are so amorphous. Ruby on Rails isn't the phenomenon that it is today because a bunch of Ruby programmers got together on c.l.ruby and all decided to work on one web app framework and bless it as the One True Way to write Ruby web apps. Instead, they wrote good code that solved their problems, code that would solve other people's problems, too. They released it in such a way that got people talking about their code and people talking about people talking about their code (and me talking about people talking about ... yeah). I'm not sure that this phenomenon is particularly repeatable. It was the result of a large number of uncontrollable factors and relied very heavily on network effects. Plone has, for a long time, made all-in-one distributions of itself+Zope+Python+et al. for Windows and Mac just like the one you tried for Ruby on Rails. When Zope was first released as open source, it got the same kind of "people talking about people talking ..." that Ruby on Rails is now getting; Zope was widely purported to be *the* Killer App for Python that would draw users of other languages in droves. Django is getting the right kind of attention, and is simple enough to get started with a small project, but it's in the unfortunate position of having come out *after* Ruby on Rails. You can do everything right and still not get what you want. There's a better question that you should have asked instead: "What can I do to help make Python a more attractive language to program?" And I would suggest that far and away, Python will get the largest payoff for your effort if you hammer hammer hammer on setuptools/PythonEggs/EasyInstall. Distribution affects *everyone* from the hobbiest, to the Java guy who just wants to try out one of the funky "dynamic languages," to the enterprise programmer. And there are a large number of diverse, small projects that don't need a whole lot of coordination with anybody else; you can do them without needing to forge much consensus. You can make your own packages distributable via eggs. You can sumbit patches for your favorite 3rd party packages to work well as eggs. You can build and donate binary eggs for the platforms you care about. You can build a GUI interface for managing the installation of eggs via EasyInstall. You can work out a way for eggs to work well with dpkg/rpm/whatever package manager your system uses. You can add signatures for eggs. You can work out a way to easy associate documentation packages associated with the runtime eggs. The more you improve this technology, even incrementally, the more people will buy into it and thus improve it for you, too. Or we can keep posting here. Your choice. -- 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 matthewharrison at gmail.com Tue Aug 30 18:48:12 2005 From: matthewharrison at gmail.com (matt) Date: 30 Aug 2005 15:48:12 -0700 Subject: Bicycle Repair Man usability In-Reply-To: <1125440834.163913.49830@g44g2000cwa.googlegroups.com> References: <1125440834.163913.49830@g44g2000cwa.googlegroups.com> Message-ID: <1125442092.912504.86760@g47g2000cwa.googlegroups.com> Eclipse's java refactoring tool puts BRM to shame. This probably has a lot to do with the static typing of Java and the JDTs nice built in compiler. When doing Java development the refactoring support is really nice (and using a nice ide make's java development almost as easy as python, since the ide can do the typing for you;) ). I'd like to hear other's experiences with refactoring in python. Most of the projects I work on are quite small relative to some of the Java projects I've worked on. Are people using BRM? Or is refactoring in python just as easy by hand? Or is refactoring just a java based activity.... matt From kay.schluehr at gmx.net Wed Aug 31 10:13:09 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 Aug 2005 07:13:09 -0700 Subject: Infinity syntax. Re: Bug in string.find; was... References: <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> <43156165.219034725@news.oz.net> Message-ID: <1125497589.683894.226100@o13g2000cwo.googlegroups.com> Bengt Richter wrote: > How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ? > That would give a consitent interpretation of seq[-1] and no errors > for any value ;-) Cool, indexing becomes cyclic by default ;) But maybe it's better to define it explicitely: seq[!i] = seq[i%len(seq)] Well, I don't like the latter definition very much because it introduces special syntax for __getitem__. A better solution may be the introduction of new syntax and arithmetics for positive and negative infinite values. Sequencing has to be adapted to handle them. The semantics follows that creating of limits of divergent sequences: !0 = lim n n->infinity That enables consistent arithmetics: !0+k = lim n+k -> !0 n->infinity !0/k = lim n/k -> !0 for k>0, n->infinity -!0 for k<0 ZeroDevisionError for k==0 etc. In Python notation: >>> !0 !0 >>> !0+1 !0 >>> !0>n # if n is int True >>> !0/!0 Traceback (...) ... UndefinedValue >>> !0 - !0 Traceback (...) ... UndefinedValue >>> -!0 -!0 >>> range(9)[4:!0] == range(9)[4:] True >>> range(9)[4:-!0:-1] == range(5) True Life can be simpler with unbound limits. Kay From bill.mill at gmail.com Thu Aug 11 15:38:19 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 11 Aug 2005 15:38:19 -0400 Subject: help in algorithm In-Reply-To: <1123703167.979083.280490@z14g2000cwz.googlegroups.com> References: <1123703167.979083.280490@z14g2000cwz.googlegroups.com> Message-ID: <797fe3d4050811123877f4625b@mail.gmail.com> On 10 Aug 2005 12:46:08 -0700, gene tani wrote: > this sounds like LSI / singular value decomposition (?) Why do you think so? I don't see it, but you might see something I don't. LSI can be used to cluster things, but I see no reason to believe that he's using LSI for his clustering. I ask because I've done some LSI [1], and could help him out with that if he is doing it. While I'm on the subject, is there any general interest in my python LSI code? [1] http://llimllib.f2o.org/files/lsi_paper.pdf Peace Bill Mill From bokr at oz.net Wed Aug 31 03:01:50 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 31 Aug 2005 07:01:50 GMT Subject: Yielding a chain of values References: <4314bf65.177562962@news.oz.net> <3nk0e4F1snjcU2@individual.net> <4314e9fe.188467011@news.oz.net> Message-ID: <431553db.215568641@news.oz.net> On Tue, 30 Aug 2005 21:23:39 -0400, Peter Hansen wrote: >Bengt Richter wrote: >> On Tue, 30 Aug 2005 23:12:35 +0200, Reinhold Birkenfeld wrote: >>>Bengt Richter wrote: >>>>Maybe >>>> yield in inner() >>>> >>>>could be sugar for the above and become something optimized? >>> >>>The problem here is that yield isn't a statement any more. It's now an >>>expression, so it is not easy to find new syntax around it. >> >> No, the idea was that it's still a statement, but what it >> yields is "in inner()" which UIAM is illegal now, and would >> signify "whatever sequence of elements is in inner()" -- >> really yield in seq -- I don't know what inner() was, but I assumed >> an iterable. > >I believe he was referring indirectly to >http://www.python.org/peps/pep-0342.html (see item #1 in the >"Specification Summary" section), where yield will become an expression. > This PEP has been accepted, thus his use of present tense, confusing >though it is when it's not in the released version of Python yet. > >Or I might be wrong. ;-) Well, maybe it's right both ways ;-) I.e., even though yield "is" now an expression, it is valid to use it as an expression-statement which evaluates the expression and discards the value. So I think you could still use the currently illegal "yield in" token sequence to mean that what follows is to be taken as an iterable whose full sequence is to be yielded sequentially as if yield in iterable were sugar for for _ in iterable: yield _ Regards, Bengt Richter From steven.bethard at gmail.com Fri Aug 19 11:57:50 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 19 Aug 2005 09:57:50 -0600 Subject: stdin -> stdout In-Reply-To: References: Message-ID: max(01)* wrote: > i was wondering, what's the simplest way to echo the standard input to > the standard output, with no modification. import sys for line in iter(sys.stdin.readline, ''): sys.stdout.write(line) Note that this uses the second form of iter(), which calls its first argument repeatedly until it returns the sentinel value (its second argument). STeVe From bryanjugglercryptographer at yahoo.com Tue Aug 16 13:12:32 2005 From: bryanjugglercryptographer at yahoo.com (bryanjugglercryptographer at yahoo.com) Date: 16 Aug 2005 10:12:32 -0700 Subject: __del__ pattern? In-Reply-To: References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: <1124212352.823286.92200@o13g2000cwo.googlegroups.com> Tom Anderson wrote: > On Mon, 15 Aug 2005, Chris Curvey wrote: > > > Is there a better pattern to follow than using a __del__ method? I just > > need to be absolutely, positively sure of two things: > > An old hack i've seen before is to create a server socket - ie, make a > socket and bind it to a port: > > import socket > > class SpecialClass: > def __init__(self): > self.sock = socket.socket() > self.sock.bind(("", 4242)) > def __del__(self): > self.sock.close() > > Something like that, anyway. > > Only one socket can be bound to a given port at any time, so the second > instance of SpecialClass will get an exception from the bind call, and > will be stillborn. This is a bit of a crufty hack, though - you end up > with an open port on your machine for no good reason. Much worse, it's a bug. That pattern is for programs that need to respond at a well-known port. In this case it doesn't work; the fact that *someone* has a certain socket open does not mean that this particular program is running. -- --Bryan From francois.perche at gmail.com Wed Aug 10 10:15:23 2005 From: francois.perche at gmail.com (perchef) Date: 10 Aug 2005 07:15:23 -0700 Subject: wxPython and threads again Message-ID: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> Hi, I have several files to download and a GUI to update. I know this is a frequently asked question but i can't find an appropriate solution. My Downloader extends threading.Thread and update a wx.Gauge in GUI during the process. for src in urls: downloader = Downloader( src, destination, GUI ) downloader.start() #work with the downloaded files... If i don't use a downloader.join() in this for loop, I launch several threads at the same time and so my wx.Gauge is bouncing up and down. If i do add the downloader.join() my GUI is no more updated ( in fact, nothing appears, it's frozen ) How can I wait the end of the thread and also be able to update the GUI ? ( I have to wait, otherwise I will work uncompleted files ) Any way to work around it? Thanks. From cfbolz at gmx.de Tue Aug 30 20:53:53 2005 From: cfbolz at gmx.de (Carl Friedrich Bolz) Date: Wed, 31 Aug 2005 02:53:53 +0200 Subject: Release of PyPy 0.7.0 In-Reply-To: References: <4311ea97$0$1276$ed2619ec@ptn-nntp-reader02.plus.net> <1h20uj1.y52kzk1che9j9N%dial#####$$NOSPAM##$#$##tone@gmail.com> <43121002$0$97118$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: <4314FFA1.1020709@gmx.de> Michael Hudson wrote: [snip >>Obviously therefore anyone seeking to translate their existing code from >>python to an executable directly using pypy would not be doing it for >>performance reasons (again, something I'm aware of watching the >>updates come out and having run svn checkouts at previous times). > > No, you're still operating at the wrong level here (very easily done). > This is the _translated PyPy_ interpreting pystone. If you run a > _translated pystone_ you'll (hopefully) get a different, faster > answer. > > In expected order of execution speed: > > interpreted pypy interpreting pystone > translated pypy interpreting pystone > cpython interpreting pystone > translated pystone Hey, wait, that's not enough! There are even more options since we (the PyPy Project) also have the LLInterpreter. This is an interpreter for low level flow graphs, the intermediate representation that our translator produces (very useful for debugging). Therefore you also have: CPython interpreting the LLInterpreter interpreting PyPy interpreting pystone (verrrrrry slow, nobody ever waited for even the end of the parsing of pystone on the llinterpreted PyPy) and CPython interpreting LLInterpreter interpreting pystone :-) Cheers, Carl Friedrich From zen19725 at zen.co.uk Mon Aug 1 12:05:09 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 1 Aug 2005 17:05:09 +0100 Subject: Is this Pythonic? Message-ID: Suppose I'm writing an abstract superclass which will have some concrete subclasses. I want to signal in my code that the subclasses will implement certan methods. Is this a Pythonic way of doing what I have in mind: class Foo: # abstract superclass def bar(self): raise Exception, "Implemented by subclass" def baz(self): raise Exception, "Implemented by subclass" class Concrete(Foo): def bar(self): #...actual implemtation... def baz(self): #...actual implemtation... -- Email: zen19725 at zen dot co dot uk From ray_usenet at yahoo.com Thu Aug 11 23:39:05 2005 From: ray_usenet at yahoo.com (Ray) Date: 11 Aug 2005 20:39:05 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123817414.665062.282500@g49g2000cwa.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123817414.665062.282500@g49g2000cwa.googlegroups.com> Message-ID: <1123817945.783409.158810@g47g2000cwa.googlegroups.com> Devan L wrote: > Fausto Arinos Barbuto wrote: > > Ray wrote: > > > > > 1. Where are the access specifiers? (public, protected, private) > > > > AFAIK, there is not such a thing in Python. > > > > ---Fausto > > Well, technically you can use _attribute to mangle it, but technically > speaking, there are no public, protected, or private things. OK, thanks. How about static members and instance members? Seems that in Python everything is class-wide? Thanks Ray From paolo_veronelli at tiscali.it Sat Aug 6 15:16:13 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Sat, 06 Aug 2005 21:16:13 +0200 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <42F50C7D.8030604@tiscali.it> Peter Hansen wrote: > Paolino wrote: > >>seberino at spawar.navy.mil wrote: >>def enclosing(): >> var=[] >> var[0]=2 >> def enclosed(): >> var[0]=4 >>which is like saying python is not working >> >>It's ok to mark non locals,but why var=4 is not searched outside and >>var[0]=4 yes? > > > Because "var=4" rebinds the name "var", while "var[0]=4" does not. It's > exactly the same issue with using "global", where you don't need it if > you aren't rebinding the name. > > (Those who don't understand the difference between "rebinding a name" > and "modifying an object" will need to figure out that distinction > before they can participate much in a discussion about Python scopes, I > think.) The point is not to understand obvious technical things, but having a coherent programming framework.If I can modify an out of scope object (ie var list) without saying it's an 'outer' no problem as python looks for it, in fact I should put 'outer' to rebind var to 4 if I refer to 'var' as an outer binding, python can find it if it exists, if it doesn't it can raise an error. Many other ways to identify the scope layer of a binding can be thought about:having only 'global' and pretending that is the only useful namspace layer to be identify for changing its bindings is just a piece of sense. Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From programmer.py at gmail.com Mon Aug 1 15:53:34 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Mon, 1 Aug 2005 14:53:34 -0500 Subject: Dabo in 30 seconds? In-Reply-To: <200508011240.58566.jstroud@mbi.ucla.edu> References: <200508011200.35374.jstroud@mbi.ucla.edu> <200508011517.41240.ed@leafe.com> <200508011240.58566.jstroud@mbi.ucla.edu> Message-ID: It is usually referred to as STC. This is from my BUILD.txt instructions for "unix" builds: 2. To build and install wxWidgets you could just use the "make" command but there are other libraries besides the main wxWidgets libs that also need to be built so again I make a script to do it all for me so I don't forget anything. This time it is called ".make" (I use the leading "." so when I do ``rm -r *`` in my build dir I don't lose my scripts too.) This is what it looks like:: make $* \ && make -C contrib/src/animate $* \ && make -C contrib/src/gizmos $* \ && make -C contrib/src/stc $* So you just use .make as if it where make, but don't forget to set the execute bit on .make first!:: jw On 8/1/05, James Stroud wrote: > On Monday 01 August 2005 12:17 pm, Ed Leafe wrote: > > So in a way, I *do* expect someone > > who has foregone the binary route and chosen the source route to at least > > read the build instructions. > > There is no mention of stylized text controls in either the wxPython build or > install pages of the www documentation. It is probably there, hidden in a > very obvious place that someone would be expected to read if they wanted to > use it enough to dig for something they don't know there looking for. > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ > -- > http://mail.python.org/mailman/listinfo/python-list > From pydecker at gmail.com Tue Aug 16 12:19:39 2005 From: pydecker at gmail.com (Peter Decker) Date: Tue, 16 Aug 2005 12:19:39 -0400 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: <200508161031.26507.hancock@anansispaceworks.com> References: <200508161031.26507.hancock@anansispaceworks.com> Message-ID: On 8/16/05, Terry Hancock wrote: > Where a framework shines is when you don't really want to program > it much at all -- you just need a tweak here and there beyond what > it already does. Gimp plugins are a great example of that. I'd put it slightly differently. Where a framework really shines is when you need to do the same thing over an over again; instead of recoding that multiple times, the framework codes it once, and you don't have to worry about it. I've written several apps that need to update a database, and each one had to do the same things: connect, grab data, create controls to display/edit that data, validate any changes and then stuff the edited data back into the database. I started playing with the Dabo framework a few months ago, and it does all of that for me. I just set the connection info, and then set a couple of properties on controls, and the rest just works. I'm sure others who don't like using frameworks will chime in that they've done similar things; that they've created reusable classes that make writing such appsmuch easier than having to rewrite the same code time and time again. In that case, I'd contend that you've simply created your own framework as you've gone along. -- # p.d. From fakeaddress at nowhere.org Sat Aug 13 18:45:13 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 13 Aug 2005 22:45:13 GMT Subject: Catching stderr output from graphical apps In-Reply-To: References: <1123697339.925135.161200@g47g2000cwa.googlegroups.com> <1123856626.852626.236030@g43g2000cwa.googlegroups.com> Message-ID: Robert Kern wrote: > Christopher Subich wrote: >> If you can get a cross-platform solution, please re-annoucne it; this >> sounds like a really neat module to have handy for graphical programs. > > > Look at py.io[1]. It seems to have implemented a probably-cross-platform > solution. Please check it out and let c.l.py and the py mailing list > know if it works on Windows. > > [1] http://codespeak.net/py/current/doc/home.html Thanks guys. I found I had a bootable Linux system. With some stuff from py.io, and *without* the fsync(), this one worked on Windows and Linux in my not-so-extensive testing. -- --Bryan """ Import this module into graphical Python apps to provide a sys.stderr. No functions to call, just import it. It uses only facilities in the Python standard distribution. If nothing is ever written to stderr, then the module just sits there and stays out of your face. Upon write to stderr, it launches a new process, piping it error stream. The new process throws up a window showing the error messages. """ import sys import os import thread import time if __name__ == '__main__': from Tkinter import * import Queue queue = Queue.Queue(99) def read_stdin(app): fd = os.dup(sys.stdin.fileno()) infile = os.fdopen(fd, 'r', 0) while 1: data = os.read(infile.fileno(), 2048) queue.put(data) if not data: break class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master.title("Error Stream from run of %s" % sys.argv[-1]) self.pack(fill=BOTH, expand=YES) self.logwidget = Text(self) self.logwidget.pack(side=TOP, fill=BOTH, expand=YES) # Disallow key entry, but allow copy with self.logwidget.bind('', lambda x: 'break') self.logwidget.bind('', lambda x: None) self.after(200, self.start_thread, ()) def start_thread(self, _): thread.start_new_thread(read_stdin, (self,)) self.after(200, self.check_q, ()) def check_q(self, _): go = True while go: try: data = queue.get_nowait() if not data: self.logwidget.configure(foreground ='#0000AA') data = "\n==== File Closed ====\n" go = False self.logwidget.insert(END, data) self.logwidget.see(END) except Queue.Empty: self.after(200, self.check_q, ()) go = False app = Application() app.mainloop() else: class ErrorPipe(object): def __init__(self): self.lock = thread.allocate_lock() self.pipe = None def on_first_write(self): command = "%s %s %s" % (sys.executable, __file__, sys.argv[0]) self.rawpipe = os.popen(command, 'w') fd = os.dup(self.rawpipe.fileno()) self.pipe = os.fdopen(fd, 'w', 0) def write(self, data): self.lock.acquire() try: if not self.pipe: self.on_first_write() self.pipe.write(data) finally: self.lock.release() sys.stderr = ErrorPipe() # sys.stdout = ErrorPipe() From SSchukat at dspace.de Wed Aug 3 02:44:40 2005 From: SSchukat at dspace.de (Stefan Schukat) Date: Wed, 3 Aug 2005 07:44:40 +0100 Subject: Pythoncom scripting Windows Media Player & visible Message-ID: Hello, you have to put the ocx in a container window (e.g. a dialog or the IE). Without this the media player just acts like a normal COM object. Example for the dialog you can find in [Pythonroot]\Lib\site-packages\pythonwin\pywin\Demos\ocx Bye Stefan > -----Original Message----- > From: python-list-bounces+sschukat=dspace.de at python.org > [mailto:python-list-bounces+sschukat=dspace.de at python.org] On > Behalf Of Bill Eldridge > Sent: Tuesday, August 02, 2005 6:15 PM > To: python-list at python.org > Subject: Pythoncom scripting Windows Media Player & visible > > > I'm trying to make Windows Media Player visible and control > it from Python. It seems when I call it below, I get only the > console version, and there's no Visible method like with > Internet Explorer. > I do catch events, but I need it visible. > Should it be put into a panel instead? > Should a different type dispatch be called or a different > method? it seems that there are a console and a windows > classes in the COM browser, but I can't seem to access any > useful windows classes. > I get "fullScreen" as False, but can't set it. > openPlayer(address) will launch a visible window, but with no > control of the the window after that. > > Ideas? > > from win32com.client import Dispatch,DispatchWithEvents > > class WMPEvents: > def OnVisible(self,evt): > print "OnVisible changed:",evt > def OnError(self,evt=None): > print "OnError",evt > def OnMediaError(self,evt=None): > print "OnMediaError",evt > def OnDisconnect(self,evt): > print "OnDisconnect",evt > def OnStatusChange(self): > print "OnStatusChange" > def OnDisconnect(self,evt): > print "Disconnect",evt > def OnBuffering(self,evt): > print "OnBuffering changed:",evt > def OnOpenStateChange(self,evt=None): > print "OnOpenStateChange" ,evt > > mp = DispatchWithEvents("WMPlayer.OCX.7",WMPEvents) > mp.Visible = True # Does nothing > tune = mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma") > mp.currentPlaylist.appendItem(tune) > mp.controls.playItem(tune) > mp.controls.play() > raw_input("Press enter to stop playing") > mp.controls.stop() > > -- > http://mail.python.org/mailman/listinfo/python-list > The "Leading Manufacturing Test Company of the Year 2005" http://www.dspace.de/goto?f_s_award From Scott.Daniels at Acm.Org Tue Aug 9 18:46:08 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 09 Aug 2005 15:46:08 -0700 Subject: How to determine that if a folder is empty? In-Reply-To: References: Message-ID: <42f92976$1@nntp0.pdx.net> could ildg wrote: > I want to know this because I want to zip a directory and all of its > sub-files and sub-directories to a zip file. zipfile module of python > will not automatically include the empty directories, so I have to > check if a dir is empty and do this manually.... Can you make work some variant of: wanted, stack = {}, () for root,dirs,files in os.walk('.'): if files: # Don't worry about parent dictionaries for name in reversed(stack): if name in wanted and (root.startswith(name) and root[len(name)] == os.path.sep): del wanted[name] stack.pop() else: break else: wanted[root] = True print root, dirs, len(files) while len(stack) and not (root.startswith(stack[-1]) and root[len(stack[-1])] == os.path.sep): stack.pop() stack.append(root) --Scott David Daniels Scott.Daniels at Acm.Org From deets at nospam.web.de Mon Aug 22 13:48:38 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Aug 2005 19:48:38 +0200 Subject: Sanitizing untrusted code for eval() In-Reply-To: References: Message-ID: <3muhfnF18o689U1@uni-berlin.de> > Does anyone know of any other "gotchas" with eval() I have not found? Or > is eval() simply too evil? Yes - and from what I can see on the JSON-Page, it should be _way_ easier to simply write a parser your own - that ensures that only you decide what python code gets called. Diez _ From bj_666 at gmx.net Wed Aug 10 16:06:17 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 10 Aug 2005 22:06:17 +0200 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: In <1123689195.840622.158870 at z14g2000cwz.googlegroups.com>, Qopit wrote: > Hi there, > > I'm pretty new to Python and am trying to figure out how to get "will > this code compile?"-like code checking. To me this is a pretty basic > language/environment requirement, especially when working with large > projects. It is *much* better to catch errors at "compile-time" rather > than at run-time. Might sound harsh, but then python ist the wrong language for you. > One thing I've "found" is the PyChecker module (conveniently embedded > in SPE), but it doesn't seem to do that great of a job. For example, > the following simple program checks out perfectly as far as PyChecker > is concerned: > > #---- > def tester(a,b,c): > print "bogus test function",a,b,c > tester(1,2,3) #this runs fine > tester(1,2) #this obviously causes a run-time TypeError exception > #---- > > It seems to me that this should be an obvious catch for PyChecker. It's just obviuos because you know that the first call to `tester()` doesn't change the name binding for `tester` to a callable object that also accepts just two parameters. You, as a human, can see easily the error here, but a program has to follow all possible control flows to be sure about that. And that's most of the time very complex and sometimes impossible. It's not enough to look just at the signature of the function. Simple (?) test:: def tester(a, b, c): global tester print "bogus test function", a, b, c def tester(a, b): print "other test function", a, b tester(1, 2, 3) # This runs fine. tester(1, 2) # This too. > Any other comments appreciated (aside from things like "just right good > code that doesn't have bugs like that" :) ). Compile it by running it and write unit tests. Ciao, Marc 'BlackJack' Rintsch From gregpinero at gmail.com Wed Aug 31 11:03:27 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Wed, 31 Aug 2005 11:03:27 -0400 Subject: Bicycle Repair Man usability In-Reply-To: References: <1125439673.688666.264820@z14g2000cwz.googlegroups.com> Message-ID: <312cfe2b05083108035612d712@mail.gmail.com> > > How would you setup BRM in VIM? And bonus points for explaining it for > Windows users ;-) > I recently got PyDev for Eclipse, which comes with BRM. > > I use it from VIM. > > > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From homeusenet1 at brianhv.org Sat Aug 20 10:48:03 2005 From: homeusenet1 at brianhv.org (Brian Victor) Date: Sat, 20 Aug 2005 14:48:03 GMT Subject: [newbie]search string in tuples References: Message-ID: Viper Jack wrote: > but i want check on several object inside the tuple so i'm trying this: > > list=["airplane","car","boat"] Note that this is actually a list, not a tuple as your subject suggests. For the difference, take a look at this: http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types Also, it's generally considered bad form to shadow built-in type names like list. This prevents you from using methods in the list scope and makes for potentially confusing bugs. > while select != list[0] or list[1] or list[2]: This actually behaves as though you wrote this: while (select != list[0]) or list[1] or list[2]: The since list[1] always evaluates to a true value (non-empty strings are true), the while loop body will always execute. Fortunately, python has a very simple way of doing what you want: vehicles = ("airplane", "car", "boat") select = vars while select not in vehicles: select=raw_input("Wich vehicle?") -- Brian From kent37 at tds.net Thu Aug 4 16:32:51 2005 From: kent37 at tds.net (Kent Johnson) Date: Thu, 04 Aug 2005 16:32:51 -0400 Subject: sample code for parsing html file to get contents of td fields In-Reply-To: <1123181678.144557.93100@g49g2000cwa.googlegroups.com> References: <1123181678.144557.93100@g49g2000cwa.googlegroups.com> Message-ID: <42f27afc$1_1@newspeer2.tds.net> yaffa wrote: > does anyone have sample code for parsting an html file to get contents > of a td field to write to a mysql db? even if you have everything but > the mysql db part ill take it. http://www.crummy.com/software/BeautifulSoup/examples.html From fredrik at pythonware.com Thu Aug 25 09:41:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 25 Aug 2005 15:41:06 +0200 Subject: variable hell References: <430dc538@127.0.0.1> Message-ID: "Nx" wrote: > I am unpacking a list into variables, for some reason they need to be > unpacked into variable names like a0,a1,a2....upto aN whatever is > in the list. why? From ptmcg at austin.rr.com Fri Aug 5 13:50:38 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 5 Aug 2005 10:50:38 -0700 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <1123256939.119967.280500@z14g2000cwz.googlegroups.com> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <1123256939.119967.280500@z14g2000cwz.googlegroups.com> Message-ID: <1123264238.812930.315720@g47g2000cwa.googlegroups.com> Just because a hosting service doesn't list Python on their web page doesn't mean that it's not available. My company's service (LunarPages) supports Python, and only recently has it started appearing on their online literature. Once you find your service based on price/support/etc., send them an e-mail asking for Python support. The worst they can say is "no, and we never will," but just as likely they might respond "yes, it's already there" or "yes, we can add that". -- Paul From paolo_veronelli at yahoo.it Thu Aug 11 11:09:55 2005 From: paolo_veronelli at yahoo.it (Paolo Veronelli) Date: Thu, 11 Aug 2005 17:09:55 +0200 Subject: set of sets In-Reply-To: <42FB2CDA.2040106@tiscali.it> References: <42FB2CDA.2040106@tiscali.it> Message-ID: <42FB6A43.1060401@yahoo.it> Paolino wrote: > I thought rewriting __hash__ should be enough to avoid mutables problem but: > > class H(set): > def __hash__(self) > return id(self) > > s=H() > > f=set() > > f.add(s) > f.remove(s) > > the add succeeds > the remove fails eventually not calling hash(s). > Yes this is really strange. from sets import Set class H(Set): def __hash__(self): return id(self) s=H() f=set() #or f=Set() f.add(s) f.remove(s) No errors. So we had a working implementation of sets in the library an put a broken one in the __builtins__ :( Should I consider it a bug ? Regards Paolino ___________________________________ Aggiungi la toolbar di Yahoo! Search sul tuo Browser, e'gratis! http://it.toolbar.yahoo.com From nospam at nospam.nospam Wed Aug 3 22:51:53 2005 From: nospam at nospam.nospam (Steve Jorgensen) Date: Wed, 03 Aug 2005 19:51:53 -0700 Subject: pyunit and Eclipse Message-ID: <3d03f1pqvhggm0lafpglc9bom33dfm8cc5@4ax.com> I was working with a friend on a project Monday night, and tried to run a pyunit test from Eclipse, and nothing seemed to happen. We finally figured out that the test is doing exactly what it's supposed to do, but the pyunit output isn't making it to the Eclipse console window. We get the same result if I run the module as a pyunit test using Eclipse, or if we simply have the program call unittest.main, and run that. As a workaround, we just ran the tests from a command prompt which worked well enough, but it would be nice to fix the problem. From peter at engcorp.com Tue Aug 2 08:45:33 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 02 Aug 2005 08:45:33 -0400 Subject: Newer than a Newbe In-Reply-To: <1122980591.835483.276830@g43g2000cwa.googlegroups.com> References: <42ef4563$0$7841$626a14ce@news.free.fr> <1122980591.835483.276830@g43g2000cwa.googlegroups.com> Message-ID: gene tani wrote: > Truthfully, the number of frameworks is staggering, tho some are > specialized for blogs/wiki, search engine, PIM, etc. [snip massive yet even so incomplete list] It's called biodiversity and, while generally this is a good thing, I think it's high time for some of these Python web frameworks to start mating and having nice little baby web frameworks which keep all the good genes and dispense with the bad. :-) Actually, I strongly suspect this is already happening, as there are clear signs the latest generation of frameworks is quite a bit more sophisticated than the earlier ones. So... does anyone have a nice framework with TLS and sessions support, which they'd like to rent out for stud? ;-) -Peter From hamstu at gmail.com Fri Aug 5 12:45:21 2005 From: hamstu at gmail.com (Hamish Macpherson) Date: 5 Aug 2005 09:45:21 -0700 Subject: Oreilly CodeZoo In-Reply-To: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> References: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> Message-ID: <1123260321.356560.36700@g47g2000cwa.googlegroups.com> A sexy design? But yes, there are quite a few out there. From leo.uaz at gmail.com Wed Aug 10 12:06:38 2005 From: leo.uaz at gmail.com (Leo) Date: 10 Aug 2005 09:06:38 -0700 Subject: interpreter frame Message-ID: <1123689998.800361.278370@g43g2000cwa.googlegroups.com> Why is it not possible to get the frame from the interpreter using the inspect library? IOW, why does this code: >>> from inspect import * >>> stack() produce: [(, '', 1, '?', None, None)] instead of: [(, '', 1, '?', '\tstack()', 0)] ? I must be missing something. The motivating question is: How can I get the interpreter line that triggered the current actions? TIA, Leo. From chris2k01 at hotmail.com Fri Aug 26 12:47:10 2005 From: chris2k01 at hotmail.com (Chris Head) Date: Fri, 26 Aug 2005 16:47:10 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Bokma wrote: > Chris Head wrote: > > >>John Bokma wrote: > > >>>>Additionally, a user interface operating inside an HTML >>>>renderer can NEVER be as fast as a native-code user interface with >>>>only the e-mail message itself passed through the renderer. >>> >>>Nowadays, more then futile. >> >>Sorry, I don't understand what you mean. Even on my 2.8GHz Pentium 4, >>using Thunderbird to juggle messages is noticeably faster than >>wandering around Hotmail. Complex HTML rendering still isn't >>absolutely instantaneous. > > > It can be made much faster. There will always be a delay since messages > have to be downloaded, but with a fast connection and a good design, the > delay will be very very small and the advantages are big. What advantages would those be (other than access from 'net cafes, but see below)? [snip] >>... and purpose-built client applications (e.g. Thunderbird) don't? > > > if A -> B, it doesn't say that B -> A :-) I.e. that it works via HTML > doesn't mean it doesn't with a dedicated client ;-). > > I live in Mexico, most people here rely on so called Internet cafes for > their connection, and even the use of a computer. For them Thunderbird > *doesn't work*. This point I agree with. There are some situations - 'net cafes included - - where thick e-mail clients don't work. Even so, see below. > > >>Maybe I'm old-fashioned but I still very much prefer thick clients. >>They simply feel much more solid. Perhaps part of it is that thin >>clients have to communicate with the server at least a little bit for >>just about everything they do, while thick clients can do a lot of >>work without ANY Internet round-trip delay at all. > > > Each has it's place. A bug in a thick client means each and everyone has > to be fixed. With a thin one, just one has to be fixed :-D. True. However, if people are annoyed by a Thunderbird bug, once it's fixed, most people will probably go and download the fix (the Thunderbird developers really only need to fix the bug once too). > > >>Hotmail has to talk to the server to >>move a message from one mailbox to another. Thunderbird doesn't. > > > Depends on where your mailbox resides. Isn't there something called > MAPI? (I haven't used it myself, but I recall something like that). IMAP. It stores the messages on the server. Even so, it only has to transfer the messages, not the bloated UI. I concede that Webmail might be just as fast when using a perfectly-designed Javascript/frames-driven interface. In the real world, Webmail isn't (unfortunately) that perfect. As I said above regarding 'net cafes: If the Internet cafe has an e-mail client installed on their computers, you could use IMAP to access your messages. You'd have to do a bit more configuration than for Webmail, so it depends on the user I guess. Personally I doubt my ISP would like me saving a few hundred megs of e-mail on their server, while Thunderbird is quite happy to have 1504 messages in my Inbox on my local machine. If I had to use an Internet cafe, I would rather use IMAP than Webmail. > > >>Ergo, >>Thunderbird is faster as soon as the Internet gets congested. > > > Ah, yeah, wasn't that predicted to happen in like 2001? Wasn't what predicted to happen? Congestion? It happens even today (maybe it's the Internet, maybe it's the server, whatever...). Hotmail is often pretty slow. > > Also, unless you have some program that kills spam on the server, you > have to download all with Thunderbird. I remember a funny day when I got > 2000 messages/hour due to a virus outbreak :-( With hotmail, if you have > 100 new messages you download them when you read them. Or kill them when > you don't want to read. > Fortunately I'm not plagued by spam. I get around 150 messages per day. Of those, about 140 are from a mailing list, 5 are personal, and 5 are spam. I used to get about 100 messages per day of which 90 or so were spam, but it suddenly stopped. To this day, I have not figured out why. Nevertheless, I agree that not having to download all those messages is one place where Webmail blows POP out of the water (but IMAP, which could be a sort of "middle ground", doesn't suffer from this). Chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (MingW32) iD8DBQFDD0eM6ZGQ8LKA8nwRArpyAJwJ+W2Q2H2wZLrcNcj8Z70sCoBIswCfZZUV DaaHKbqfADYKOWAE9APey7w= =6Mmv -----END PGP SIGNATURE----- From leo.uaz at gmail.com Mon Aug 29 14:01:35 2005 From: leo.uaz at gmail.com (Leo) Date: 29 Aug 2005 11:01:35 -0700 Subject: command history behavior in windows and linux Message-ID: <1125338495.826742.29210@g49g2000cwa.googlegroups.com> Does someone know if there is a setting in the python Unix world to make the command history behave as it does in the Windows intepreter? Specifically, I like the fact that the command history remembers which of a sequence of commands is the one that I last issued. For example, suppose that I typed the following lines into the interpreter: import foo for e in foo.container: print e In Unix, I would have to tap up arrow 3 times for each line: up up up gives me "import foo". I press enter. up up up gives me "for...". I press enter. up up up gives me " print...". I press enter. In Windows, I get this behavior I like better: up up up gives me "import foo". I press enter. down gives me "for...". I press enter. down gives me " print...". I press enter. How do I get the second behavior to take place in all the platforms I use? Also, the windows version remembers my commands across sections. How do I enable that in the python version? I tried editing the inputrc file that controls the readline library by adding the following lines: $if python set history-preserve-point on $endif but this did not seem to work. TIA, Leo. From sjmachin at lexicon.net Thu Aug 11 08:24:38 2005 From: sjmachin at lexicon.net (John Machin) Date: Thu, 11 Aug 2005 22:24:38 +1000 Subject: Regular expression to match a # In-Reply-To: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> Message-ID: <42fb4386@news.eftel.com> Tom Deco wrote: > Hi, > > I'm trying to use a regular expression to match a string containing a # > (basically i'm looking for #include ...) > > I don't seem to manage to write a regular expression that matches this. > > My (probably to naive) approach is: p = re.compile(r'\b#include\b) > I also tried p = re.compile(r'\b\#include\b) in a futile attempt to use > a backslash as escape character before the # > None of the above return a match for a string like "#include ". > > I know a # is used for comments, hence my attempt to escape it... > > Any suggestion on how to get a regular expression to find a #? > > Thanks > You definitely shouldn't have the first \b -- match() works only at the beginning of the target string, so it is impossible for there to be a word boundary just before the "#". You probably shouldn't have the second \b. You probably should read section A12 of K&R2. You probably should be using a parser, but if you persist in using regular expressions: (a) read the manual. (b) try something like this: >>> pat1 = re.compile(r'\s*#\s*include\s*<\s*([^>\s]+)\s*>\s*$') >>> pat1.match(" # include < fubar.h > ").group(1) 'fubar.h' N.B. this is based the assumption that sane programmers don't have whitespace embedded in the names of source files ;-) HTH, John From nothingcanfulfill at gmail.com Tue Aug 9 21:52:55 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 9 Aug 2005 18:52:55 -0700 Subject: Import question In-Reply-To: References: <1123614152.482652.72900@g44g2000cwa.googlegroups.com> <1123634807.617032.271850@g14g2000cwa.googlegroups.com> Message-ID: <1123638775.381309.110940@o13g2000cwo.googlegroups.com> I've got multiple instances I want globally available in the secondary modules, which can't easily be passed around with every function call without driving me nuts, so I wish to have all variables from the Main module passed to each of the other modules it creates. One such example would be in Main, we call the SettingsParse() function or whatever, which creates a Settings class storing all settings. This class needs to be readily accessible by extensions (dynamically loaded) and almost all other modules in the project. -Wes From fakeaddress at nowhere.org Tue Aug 30 01:15:34 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 30 Aug 2005 05:15:34 GMT Subject: global interpreter lock In-Reply-To: <864q98b7k0.fsf@bhuda.mired.org> References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> <864q98b7k0.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Bryan Olson writes: >> > Bryan Olson writes: >> > Trivially, an 'if' statement that depends upon input >> >>data is statically predictable. Use of async I/O means makes the >> >>programs execution dependent upon external timing. >>Mike Meyer wrote: >> > Yes, but that depenency is tied to a single point - the select >> > call. The paths after that are statically predictable. This makes the >> > code very managable. >>Wow -- I could not disagree more. Returning back to some single >>point for every possibly-blocking operation is painful to manage >>even for simple GUIs, and humanly intractable for sophisticated >>services. > > I'd be interested in what you're trying to do that winds up as > unmanagable. I'd like to call a utility in someone else's code, but it might do something that could block. I find re-writing everyone's code into a state-machine that can trap back to the central I/O loop and later resume where it left off, to be hard to manage. When I'm writing my own base classes, I find it hard to support the back-to-the-I/O-loop-and-resume thing so that method over-rides can call blocking operations when they need to. > There are clearly things select+async IO is unsuitable > for. You may be running into problems because you're trying to use it > in such an environment. For instance, it's not clear to me that it > will work well for any kind of GUI programming, though I've had good > look with it for command line interfaces. Uh, not sure where you're coming from there. Are you unaware of the 'event loop' in the GUI's, or unaware that it's async I/O. >>Select is certainly useful, but it scales badly and isn't as >>general as better tools. > > It can't take advantage of multiple CPUs. I've not run into scaling > problems on single-CPU systems. Select() is linear-time in the number of sockets to be checked (not just the number found to be ready). There's a good write-up of the problem and solutions Google-able as "The C10K problem". >> > [...] I'm calling the tools available in most programming >> > languages for dealing with it primitive. >> > We need better tools. >>Agreed, but if 'select' is someone's idea of the state of the >>art, they have little clue as to the tools already available. > > Well, share! Uh, where have you been? I keep explaining that concurrency systems have improved vastly in recent years. For a long time, the most sophisticated software services generally have used multiple lines of execution, and now that's mostly in the form of threads. No one actually disagrees, but they go right on knocking the modern methods. -- --Bryan From hancock at anansispaceworks.com Wed Aug 31 17:34:03 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 31 Aug 2005 16:34:03 -0500 Subject: OpenSource documentation problems In-Reply-To: <4314DA67.6030101@benjiyork.com> References: <200508301700.36140.hancock@anansispaceworks.com> <4314DA67.6030101@benjiyork.com> Message-ID: <200508311634.03402.hancock@anansispaceworks.com> On Tuesday 30 August 2005 05:15 pm, Benji York wrote: > Terry Hancock wrote: > > OTOH, there are lots of poorly-documented third-party Python > > modules (as in any language). Zope is a particularly nasty > > example -- though I think I understand some of the reasons > > behind that (rapidly changing API, poor interaction with doc > > tools, etc). > > Are you referring to Zope 2 or 3 here? I ask because I consider the > Zope 3 code (at least the parts written in the last couple years) to be > some of the best (externally) documented code I've worked with. I'm talking about Zope 2. I haven't had a chance to fully explore Zope 3, yet, but what little I have learned has all been good. I suspect they are probably using an automatic documentation approach now? That certainly seemed to be the way they've been leaning. The biggest problem would seem to be the discontinuity between 2 & 3, but that's also probably the biggest asset, so there you go. ;-) Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From __peter__ at web.de Tue Aug 16 16:07:23 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2005 22:07:23 +0200 Subject: 'import copy' too slow?, was Re: [Python-Dev] implementation of copy standard lib References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: [Martijn Brouwer] > Importing copy takes 5-10 times more time that > import os, string and re together! Are you sure you aren't seeing the effects of caching? My little ad hoc test (which fails on the os module) doesn't confirm your numbers: $ python2.4 -m timeit -n1 -r1 -s"import sys; assert 're' not in sys.modules" "import re" 1 loops, best of 1: 1.69 msec per loop $ python2.4 -m timeit -n1 -r1 -s"import sys; assert 'copy' not in sys.modules" "import copy" 1 loops, best of 1: 542 usec per loop That's roughly one third of the time it takes to import re which I think is vastly more popular. $ python2.4 -m timeit -n1 -r1 -s"import sys; assert 'os' not in sys.modules" "import os" Traceback (most recent call last): File "/usr/local/lib/python2.4/timeit.py", line 264, in main r = t.repeat(repeat, number) File "/usr/local/lib/python2.4/timeit.py", line 188, in repeat t = self.timeit(number) File "/usr/local/lib/python2.4/timeit.py", line 161, in timeit timing = self.inner(it, self.timer) File "", line 3, in inner AssertionError Therefore the following number is meaningless: $ python2.4 -m timeit -n1 -r1 "import os" 1 loops, best of 1: 9.06 usec per loop Peter From jforcier at strozllc.com Sun Aug 21 23:00:40 2005 From: jforcier at strozllc.com (Jeffrey E. Forcier) Date: 21 Aug 2005 20:00:40 -0700 Subject: Decorator and Metaclasses Documentation In-Reply-To: References: <1124668873.380249.119630@f14g2000cwb.googlegroups.com> Message-ID: <1124679640.711717.311870@o13g2000cwo.googlegroups.com> Sorry about that, I misread the original question. However, the python.org link is still valid as it concerns metaclasses as well as a handful of other topics. From rex.eastbourne at gmail.com Thu Aug 11 22:46:36 2005 From: rex.eastbourne at gmail.com (Rex Eastbourne) Date: 11 Aug 2005 19:46:36 -0700 Subject: Printing literal text of an argument In-Reply-To: References: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> Message-ID: <1123814796.130867.204530@o13g2000cwo.googlegroups.com> Thanks. I adapted it a bit: def debug(foo): print foo, 'is:' exec('pprint.pprint(' + foo + ')') But I'm getting "NameError: name 'foo' is not defined," since foo is not defined in this scope. (The function works beautifully when I'm dealing with global variables, which is very rarely). Any way around this? Rex From nicolas.riesch at genevoise.ch Tue Aug 23 12:16:53 2005 From: nicolas.riesch at genevoise.ch (nicolas_riesch) Date: 23 Aug 2005 09:16:53 -0700 Subject: python asp page keeps state across queries !?!? Message-ID: <1124813813.038076.184620@z14g2000cwz.googlegroups.com> I am writing asp pages in python, running on IIS 5 on Windows. I notice that variables outside functions keep their value across queries. I don't know if it is normal. Here is a little script that demonstrates it: ------------------ problem.asp --------------------- <%@LANGUAGE=Python%> <% try: if x == 0: # if x is not defined, an exception is raised here and code goes to the except clause pass else: x = x + 1 # if x exists, increment x except: x = 10 # if x not defined, initialize x to 10 Response.write('Hello, the value of x is ' + str(x) ) # write value of x %> ----------------------------------------------------- The first time I fetch this asp page from the web browser, I get: Hello, the value of x is 10 So far, it works. But then, when I click on the refresh button to query the asp page again, I get: Hello, the value of x is 11 and then Hello, the value of x is 12 and so on ... Each time I reload this asp page, the x variable is incremented !!! It seems that IIS loads this asp page like a module and keep it in memory. That's why all variables at the module level act as global variables that survives to multiple queries. To be sure, I tried a similar asp script written in VB script, and I can see that in VBscript, variables at this same level ARE NOT kept across different queries !!! So, the behavior of Python asp page is different from the same page written in VBscript. I don't know if it is a normal thing or if it is a bug, of if I have missed something. Someone has an explanation ? From peter at engcorp.com Sun Aug 21 19:26:16 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 21 Aug 2005 19:26:16 -0400 Subject: Best way to 'touch' a file? In-Reply-To: References: Message-ID: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Kenneth McDonald wrote: > I could've sworn python had such a command, but now I can't find it... > > I'm looking for an easy way to perform a UNIX-style "touch", to update > the modification time of a file without actually modifying it. I could > do something (I imagine) like opening the file for appending and then > immediately closing it, but that doesn't seem like a good idea--what if > the file is already open for reading or writing? Anyone know of a nice, > elegant solution? from path import path path('myfile').touch() (That relies on Jason Orendorff's path.py module, which does this and much more very elegantly, not to mention practically.) -Peter From luismgz at gmail.com Thu Aug 25 16:50:39 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 25 Aug 2005 13:50:39 -0700 Subject: New Arrival to Python In-Reply-To: <1BkPe.304848$5V4.169335@pd7tw3no> References: <1BkPe.304848$5V4.169335@pd7tw3no> Message-ID: <1125003039.232718.304100@g47g2000cwa.googlegroups.com> Windows Apps: Since you said "professional looking" applications, I assume you mean graphical interfaces (windows - GUI): If so, I recomend PythonCard ( http://pythoncard.sourceforge. net/ ). It is very easy to use, very similar to Visual Basic or Delphi (drag and drop widgets on a form...). Web Development: An excellent choice for simple (and complex, but easy) web development in Python is Karrigell ( http://karrigell.sourceforge. net/ ). It is not an IDE, but a web framework. The coding can de made with the standard IDLE or simply notepad. Books: Learning Python 2nd Edition. Very good and complete introduction to python. Online resources: A byte of Python (google this) Dive into Python (for more experienced programmers) Hope this helps... Luis From ggg at zzz.it Mon Aug 1 16:19:54 2005 From: ggg at zzz.it (deelan) Date: Mon, 01 Aug 2005 22:19:54 +0200 Subject: MySQL help In-Reply-To: <1122922717.658701.29410@g14g2000cwa.googlegroups.com> References: <1122922717.658701.29410@g14g2000cwa.googlegroups.com> Message-ID: <%qvHe.29361$TR5.2357@news.edisontel.com> supercomputer at gmail.com wrote: > So i'm writing this program to check if a row exists in a table. If it > doesn't it inserts it if it does it will update that row with the > current info. (...) quick tip: are you aware of the mysql's REPLACE command? -- deelan, #1 fan of adriana lima! From tjreedy at udel.edu Sun Aug 7 23:52:40 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 7 Aug 2005 23:52:40 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement forkeyword'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com><11f84j8elj07271@news.supernews.com><861x57wrui.fsf@bhuda.mired.org><11f9f9u2enfsi58@news.supernews.com><11f9u843r0fts5b@news.supernews.com><86br4avf5t.fsf@bhuda.mired.org><11fakjctean9u8a@news.supernews.com> <42f6b12e.871276739@news.oz.net> Message-ID: "Bengt Richter" wrote in message news:42f6b12e.871276739 at news.oz.net... > I think the relationship of abstract entities and their concrete > representations > is very interesting. ditto > BTW, maybe this is a place to mention the concept of an AST decorator, > that works like > a function decorator except that it is prefixed with @@ instead of @ and > it operates > at compile time when the AST becomes available, but before it gets > translated to code, > and what gets passed to the decorator is the AST One can do this much today: import compiler new_ast = ast_transformer(compiler.parse('''\ ''') However, I can't see any way in the docs to get a code object from the AST. I believe the AST-to-code compilet is currently being worked on. When it is, @@ would be nice syntactic sugar but not really necessary. > The idea is that this form of decoration could transform the > AST arbitrarily before code generation, and be a very flexible tool > for mischief of course, but also useful tricky things. At the moment, we are limited to manipulating concrete text before compiling it. Terry J. Reedy From me at jonbowlas.com Tue Aug 16 08:33:05 2005 From: me at jonbowlas.com (Jon Bowlas) Date: Tue, 16 Aug 2005 13:33:05 +0100 Subject: looping list problem Message-ID: HI all, I'm fairly new to python and programming in general so I was hoping someone here may be able to help me. Let me explain what the problem I'm having is: I am trying to parse the XML of an attributes object I created, this object has the structure outlined below. Everything is ok on the parsing front until I try to get the values in ucl_navhide (StringField); these are basically the id's of objects I wish to hide in a website navigation menu separated by a space: root atts tb-black UCL Web Services section_header_white section_subheader_white cms-assets/images/ucl0001 ucl0001 normal yes 3_columns test1 test2 I have a script 'normalmenu' that I will eventually be using to generate a navigation menu for a website here it is in its present development state: attobject = context.get_attobject() navstring = context.get_uclattribute(attobject, 'ucl_navhide') hiddennavelements = navstring.split(' ') for hiddennavelement in hiddennavelements: return hiddennavelement So the script 'get_attobject' basically looks for an instance of the attributes object in the current folder, if it doesn't locate one then it uses acquisition to find one in a parent folder. The script 'get_uclattribute' then gets the nodeValues of the requested node. In this instance its ucl_navhide, then I split the 'navstring' string at the spaces and attempt the for-loop to output each of the values. Unfortunately it appears I am unable to loop through each of the list items in hiddennavelements, as it only returns the first value & will not repeat. Strangely if I test to output the value of hiddennavelements it looks like this: [u'test1', u'test2'] which I believe the u refers to Unicode, although I could be wrong. Even more bizarrely if I test the len(hiddennavelements) it returns the correct result (2), so why wont my for-loop work? Hope someone can help, or point out my schoolboy error. Jon From zen19725 at zen.co.uk Sun Aug 28 19:42:58 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 29 Aug 2005 00:42:58 +0100 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> Message-ID: On Sun, 28 Aug 2005 19:25:55 -0400, Mike Meyer wrote: >Bryan Olson writes: >> phil hunt wrote: >> > Yes, find solutions. Don't find dangerous dead-ends that look like >> > solutions but which will give you lots of trouble. >> If concurrency is a dead end, why do the programs that provide >> the most sophisticated services of any in the world rely on it >> so heavily? > >I don't know what Phil is saying, but I'm not calling concurrency a >dead end. In general it isn't. However, in many programs, it might be, in that by using it you might end up with a very complex program that fails unpredictably and if hard to debug: if you get in that situation, you may have to start again, in which case your previous work will have been a dead end. (Actually I would suggest that knowing when to throw something away and start again is something that differentiates between good and bad programmers). >I'm calling the tools available in most programming >languages for dealing with it primitive. > >We need better tools. I agree. -- Email: zen19725 at zen dot co dot uk From ken at lampsacos.demon.co.uk Sun Aug 28 14:48:10 2005 From: ken at lampsacos.demon.co.uk (Ken Starks) Date: Sun, 28 Aug 2005 19:48:10 +0100 Subject: ideas for university project ?? References: Message-ID: Jon Hewer wrote: > Hi > > I'm about to start my third, and final, year in computer science at > cambridge uni, and i need to come up with an idea for a software > project, but i'm really struggling for ideas, and i was wondering > whether anyone here had any suggestions. > > I'd say i'm probably most experienced in Java, but I have started > learning Python, and although i haven't got very far yet, I plan on > doing some more in the next few weeks. > > Areas of interested include AI, distributed systems. Most of all i > want something that is interesting, and actually useful (thats > probably stating the obvious!) > > Cheers > Jon I'd like you to write a Python-SOAP-based interface to data-loggers and interface boxes used in the UK at school level. For example, those produced by Phillip Harris, which are normally connected by way of a serial cable. The idea is to keep an old computer with the data-logger attached, and the SOAP server installed, in the field or lab. Am I correct in saying that Java is too security-bound for this role? Personally, I would feed the resulting XML into Cocoon, which already has SOAP input, and from there into dataframes in 'R' among other places. Once it has entered a Cocoon pipeline, it is already in a very flexible form, and Data analysis can be done anywhere that can reach the Cocoon server. You may wish to develop that end of the pipeline either using your Java skills, or by using XSLT to create Prolog facts or whatever. From tdelaney at avaya.com Mon Aug 22 18:35:50 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Tue, 23 Aug 2005 08:35:50 +1000 Subject: while c = f.read(1) Message-ID: <2773CAC687FD5F4689F526998C7E4E5F05CC5E@au3010avexu1.global.avaya.com> Donn Cave wrote: > Before leaving this topic, I wanted to make a rare visit > to the ruins of Google's USENET archive and pull out this > giant post on the subject of True and False, when they were > being considered for adoption into Python. There is some > stuff to ignore, where she addresses questions that didn't > go anywhere, but she goes on to write a well articulated > case that makes very interesting reading, and possibly has > had some effect on how people think about it around here. How did I guess, before I even looked at the post, that it was going to be Laura Creighton? :) Tim Delaney From nospam at nospam.com Mon Aug 22 17:57:06 2005 From: nospam at nospam.com (42) Date: Mon, 22 Aug 2005 21:57:06 GMT Subject: Sandboxes References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: In article , peter at engcorp.com says... > 42 wrote: > > I was planning on "sanitizing" the language instead of relying on rexec > > and bastion so issues with them shouldn't be relevant. > > I think in dealing with security, deciding what might be relevant before > you fully understand the problem is somewhat premature... True enough, but I don't think in this case it applies. Its ok to rule as irrelevant the various security problems with various locking solutions for your front door when the proposed solution is to simply brick the door over, removing it entirely. > > I'm curious about the 'other' stuff that was alluded to, that could > > still occur in a python with all its __import__, import, exec, eval, and > > various reflection/metadata builtins prohibited (e.g. getattr)... > > Okay, but are you saying that combining those keywords with "security" > when searching comp.lang.python in Google Groups produced no useful > results? I couldn't say that. I will say that none of the links I clicked on revealed an attack that could bootsrap without the functions I proposed 'removing'. > When I do it, I generally get to threads where somebody rushes > in with suggestions about how to add security where the core Python > people fear to tread (so to speak), and after a short period of back and > forth where each idea is quickly shot down, the thread sort of dies out > as (I suspect) the OP realizes the problems are fundamental and probably > can't be fixed without changes to the Python core itself, or at least > can't be fixed *with confidence* without a thorough security audit which > so far nobody has valued enough to actually do. Difference being that all the threads I read are trying to 'put full python in sandbox' whereas I'd proposed literally hacking out chunks of the language. FWIW I've already given up on making python secure. I agree that odds are extremely high that I've missed something. I'm just curious to see what one of the holes I left is, preferably without wading through hundreds of pages :) From peter at somewhere.com Wed Aug 31 08:33:20 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 14:33:20 +0200 Subject: module not found in IIS virtual dir Message-ID: I'm trying to call python scripts from IIS in the following tree: upgrade/ util/ __init__.py logonUser.py select/ selectFiles.py - select/ is referred from IIS as a virtual dir vselect. - upgrade/ is inserted into the Python path via .pth file in .../site-packages. - selectFiles.py has a line "from util import logonUser". If I run selectFiles.py from the command line everything is ok. But if I call it via IIS (http://localhost/vselect/selectFiles.py) there is an error "No module named util" due the fact that selectFiles.py still sees upgrade/ in the Python Path but upgrade/util/logonUser.py can no longer be found by selectfiles.py (os.path.exists returns false). This is strange because other modules, e.g. odbc.py are still importable. Hope you can help me. Thanks. -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From randy at psg.com Thu Aug 18 16:59:29 2005 From: randy at psg.com (Randy Bush) Date: Thu, 18 Aug 2005 20:59:29 +0000 Subject: dict duplicity Message-ID: <17156.63153.533919.507070@roam.psg.com> a dict written as pKey = (prefix, pLen, origin) val = dict.get(pKey) if val == None: dict[pKey] = (timeB, timeB) else: if val[0] > timeB: val[0] = timeB if val[1] < timeB: val[1] = timeB dict[pKey] = val and read back as for pKey, pVal in dict.iteritems(): print \ pKey[0], hash(pKey[0]), \ pKey[1], hash(pKey[1]), \ pKey[2], hash(pKey[2]), \ "hash=", hash(pKey), \ pVal[0], hash(pVal[0]), \ pVal[1], hash(pVal[1]) when run with | sort, produces 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 not that there are two entries with the same hash= i am utterly confused randy From n00m at narod.ru Tue Aug 30 14:19:05 2005 From: n00m at narod.ru (n00m) Date: 30 Aug 2005 11:19:05 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> Message-ID: <1125425945.667967.181000@g49g2000cwa.googlegroups.com> Oops.. not everything so super as I thought. Incredible but from command line it results as: D:\>python23\python d:\python23\00\socket6.py Traceback (most recent call last): File "d:\python23\00\socket6.py", line 1, in ? import socket, thread File "D:\Python23\00\socket.py", line 3, in ? s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) AttributeError: 'module' object has no attribute 'AF_INET' D:\> FROM IDLE 1.0.3 THE SAME SCRIPT WORKS PERFECTLY !!! WHY ON THE EARTH <'module' object has no attribute 'AF_INET'> ??? From listsub at wickedgrey.com Wed Aug 24 13:54:16 2005 From: listsub at wickedgrey.com (Eli Stevens (WG.c)) Date: Wed, 24 Aug 2005 10:54:16 -0700 Subject: Inline::Python, pyperl, etc. In-Reply-To: References: Message-ID: <430CB448.7080702@wickedgrey.com> Sybren Stuvel wrote: > Eli Stevens (WG.c) enlightened us with: > >>I've bumped into some snags with pyperl (can't import perl2.so? But >>it's right there in site-packages/ !), and I'm wondering if it's bitrot >>or a config error on my end. > > > If the .so file is as old as you described, it's probably linked to an > old version of python. Try recompiling it. The perl2.so is not old though; it was built as part of the pyperl install I just did. Since the file ended up at (without needing any prompting from me): /usr/local/lib/python2.4/site-packages I'm fairly confident that it's linked against python 2.4. But still: $$$ ll /usr/local/lib/python2.4/site-packages total 1968 drwxr-sr-x 2 root staff 4096 Aug 24 00:36 . drwxr-sr-x 19 root staff 12288 Aug 20 00:42 .. -rw-r--r-- 1 root staff 119 Aug 20 00:42 README -rw-r--r-- 1 root staff 1672 Mar 6 2001 dbi.py -rw-r--r-- 1 root staff 2248 Aug 24 00:36 dbi.pyc -rw-r--r-- 1 root staff 8289 Mar 6 2001 dbi2.py -rw-r--r-- 1 root staff 10292 Aug 24 00:36 dbi2.pyc -rwxr-xr-x 1 root staff 40249 Aug 24 00:36 perl.so -rwxr-xr-x 1 root staff 1895597 Aug 24 00:36 perl2.so -rw-r--r-- 1 root staff 3566 Mar 6 2001 perlmod.py -rw-r--r-- 1 root staff 4236 Aug 24 00:36 perlmod.pyc -rw-r--r-- 1 root staff 1310 Mar 6 2001 perlpickle.py -rw-r--r-- 1 root staff 1358 Aug 24 00:36 perlpickle.pyc $$$ python Python 2.4.1 (#1, Aug 20 2005, 00:41:20) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import perl Traceback (most recent call last): File "", line 1, in ? ImportError: perl2.so not found >>> import sys >>> for line in sys.path: print line ... /home/elis/edit/external/pyperl-1.0.1 /usr/local/lib/python24.zip /usr/local/lib/python2.4 /usr/local/lib/python2.4/plat-linux2 /usr/local/lib/python2.4/lib-tk /usr/local/lib/python2.4/lib-dynload /usr/local/lib/python2.4/site-packages >>> But again, I'm not so much interested in fixing this specific problem; I'm wanting to know if anyone is actually using Inline::Python or PyPerl in any real sense. If they are dead projects that will have to factor into our decision to use them or something else. Thanks for the input, Eli From joe at invalid.address Fri Aug 12 15:55:17 2005 From: joe at invalid.address (joe at invalid.address) Date: 12 Aug 2005 14:55:17 -0500 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: "Mike Schilling" writes: > "J?rgen Exner" wrote in message > news:BATKe.19727$0d.11740 at trnddc07... > > Xah Lee wrote: > >> Jargons of Info Tech industry > >> > >> (A Love of Jargons) > >> > >> Xah Lee, 2002 Feb > >> > >> People in the computing field like to spur the use of spurious > >> jargons. The less educated they are, the more they like extraneous > > [...] > > > > Just for the records at Google et.al. in case someone stumbles across > > Xah's > > masterpieces in the future: > > Xah is very well known as the resident troll in many NGs and his > > 'contributions' are less then useless. > > He sent a lovely one to some of the language groups the other day, > explaining why Jonathan Swift was a poor writer. That's remarkable, considering he doesn't realize "jargon" is a collective noun. Joe From exarkun at divmod.com Mon Aug 29 22:25:21 2005 From: exarkun at divmod.com (Jp Calderone) Date: Mon, 29 Aug 2005 22:25:21 -0400 Subject: Using select on a unix command in lieu of signal In-Reply-To: <1125363454.816578.73260@g47g2000cwa.googlegroups.com> Message-ID: <20050830022521.3914.1102017452.divmod.quotient.10018@ohm> On 29 Aug 2005 17:57:34 -0700, rh0dium wrote: >So here's how I solved this.. It's seems crude - but hey it works. >select not needed.. > > def runCmd( self, cmd, timeout=None ): > self.logger.debug("Initializing function %s - %s" % >(sys._getframe().f_code.co_name,cmd) ) > command = cmd + "\n" > > child = popen2.Popen3(command) > t0 = time.time() > > out = None > while time.time() - t0 < timeout: > if child.poll() != -1: > self.logger.debug("Command %s completed succesfully" % >cmd ) > out = child.poll() > results = "".join(child.fromchild.readlines()) > results = results.rstrip() > break > print "Still waiting..", child.poll(), time.time() - >t0, t0 > time.sleep(.5) > > if out == None: > self.logger.warning( "Command: %s failed!" % cmd) > kill = os.kill(child.pid,9) > self.logger.debug( "Killing command %s - Result: %s" % >(cmd, kill)) > out = results = None > > else: > > self.logger.debug("Exit: %s Reullts: %s" % (out,results)) > > child.tochild.close() > child.fromchild.close() > return out,results > >Comments.. > Here's how I'd do it... from twisted.internet import reactor, protocol, error class PrematureTermination(Exception): """Indicates the process exited abnormally, either by receiving an unhandled signal or with a non-zero exit code. """ class TimeoutOutputProcessProtocol(protocol.ProcessProtocol): timeoutCall = None onCompletion = None def __init__(self, onCompletion, timeout=None): # Take a Deferred which we will use to signal completion (successful # or otherwise), as well as an optional timeout, which is the maximum # number of seconds (may include a fractional part) for which we will # await the process' completion. self.onCompletion = onCompletion self.timeout = timeout def connectionMade(self): # The child process has been created. Set up a buffer for its output, # as well as a timer if we were given a timeout. self.output = [] if self.timeout is not None: self.timeoutCall = reactor.callLater( self.timeout, self._terminate) def outReceived(self, data): # Record some data from the child process. This will be called # repeatedly, possibly with a large amount of data, so we use a list # to accumulate the results to avoid quadratic string-concatenation # behavior. If desired, this method could also extend the timeout: # since it is producing output, the child process is clearly not hung; # for some applications it may make sense to give it some leeway in # this case. If we wanted to do this, we'd add lines to this effect: # if self.timeoutCall is not None: # self.timeoutCall.delay(someNumberOfSeconds) self.output.append(data) def _terminate(self): # Callback set up in connectionMade - if we get here, we've run out of # time. Error-back the waiting Deferred with a TimeoutError including # the output we've received so far (in case the application can still # make use of it somehow) and kill the child process (rather # forcefully - a nicer implementation might want to start with a # gentler signal and set up another timeout to try again with KILL). self.timeoutCall = None self.onCompletion.errback(error.TimeoutError(''.join(self.output))) self.onCompletion = None self.output = None self.transport.signalProcess('KILL') def processEnded(self, reason): # Callback indicating the child process has exited. If the timeout # has not expired and the process exited normally, callback the # waiting Deferred with all our results. If we did time out, nothing # more needs to be done here since the Deferred has already been # errored-back. If we exited abnormally, error-back the Deferred in a # different way indicating this. if self.onCompletion is not None: # We didn't time out self.timeoutCall.cancel() self.timeoutCall = None if reason.check(error.ProcessTerminated): # The child exited abnormally self.onCompletion.errback( PrematureTermination(reason, ''.join(self.output))) else: # Success! Pass on our output. self.onCompletion.callback(''.join(self.output))) # Misc. cleanup self.onCompletion = None self.output = None def runCmd(executable, args, timeout=None, **kw): d = defer.Deferred() p = TimeoutOutputProcessProtocol(d, timeout) reactor.spawnProcess(p, executable, args, **kw) return d And there you have it. It's a bit longer, but that's mostly due to the comments. The runCmd function has a slightly different signature too, since spawnProcess can control a few more things than Popen3, so it makes sense to make those features available (these include setting up the child's environment variables, the UID and GID it will run as, whether or not to allocate a PTY for it, and the working directory it is given). The return value differs too, of course: it's a Deferred instead of a two-tuple, but it will eventually fire with roughly the same information. Hope this helps, Jp From peter at engcorp.com Thu Aug 25 10:18:37 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 25 Aug 2005 10:18:37 -0400 Subject: Fighting Spam with Python In-Reply-To: References: Message-ID: David MacQuigg wrote: > Are you as mad about spam as I am? Are you frustrated with the > pessimism and lack of progress these last two years? Do you have > faith that an open-source project can do better than the big companies > competing for a lock-in solution? If so, you might be interested in > the Open-Mail project. > > I'm writing some scripts to check incoming mail against a registry of > reputable senders, using the new authentication methods. Python is > ideal for this because it will give mail-system admins the ability to > experiment with the different methods, and provide some real-world > feedback sorely needed by the advocates of each method. So far, we > have SPF and CSV. See http://purl.net/macquigg/email/python for the > latest project status. You might find www.spambayes.org of interest, in several ways. -Peter From michele.simionato at gmail.com Thu Aug 25 04:15:55 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 25 Aug 2005 01:15:55 -0700 Subject: Setting the encoding in pysqlite2 Message-ID: <1124957755.392563.197910@z14g2000cwz.googlegroups.com> An easy question, but I don't find the answer in the docs :-( I have a sqlite3 database containing accented characters (latin-1). How do I set the right encoding? For instance if I do this: #-*- encoding: latin-1 -*- from pysqlite2 import dbapi2 as sqlite import os DBFILE="/tmp/example.db" def writedb(conn): c = conn.cursor() c.executescript(""" create table example (word char(20)); insert into example values ("cos?"); """) c.close() def readdb(conn): c = conn.cursor() c.execute("select * from example;") #print c.fetchall() c.close() if __name__ == "__main__": conn = sqlite.connect(DBFILE) writedb(conn) readdb(conn) conn.close() os.remove(DBFILE) I get UnicodeDecodeError: 'utf8' codec can't decode byte 0xec in position 3: unexpected end of data (notice, even if the 'print' statement is commented. Michele Simionato From sybrenUSE at YOURthirdtower.com.imagination Fri Aug 26 06:20:27 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Fri, 26 Aug 2005 12:20:27 +0200 Subject: Should I move to Amsterdam? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> <430ee832$0$11069$e4fe514c@news.xs4all.nl> Message-ID: Martin P. Hellwig enlightened us with: > Yes it is, and it sucks too In Amsterdam, it's the best way to go. > or do you find it amusing to ride 15 clicks through rain and wind to > get to your clients? Makes a man out of you ;-) Of course, rain sucks, but as long as it's not raining too hard it's not really an issue for me. > By the way did you notice the "travel across the Randstad" part? Sure. I wouldn't want to bike from Amsterdam to Rotterdam either. > Yes that reminds me that I had 2 quite expensive abus locks on my > rather cheap bike, the day after a hack was published on the > Internet how to open this lock without damaging, the locks where > stolen but my bike was further untouched, that pretty badly hurt my > bikes ego I guess. LOL :) >> if you have a serious delay, you even get part of your money back. > > They don't do it because they like the customer they do it because > it's a law. I don't mind for what reason they do it. Fact is that they do it. > Comparing it to Belgium, France, Luxembourg, Germany, Spain, Norway, > Swizz etc.etc. okay, but comparing it with a former Communistic > country? Hey, I just had a three week holiday in Croatia with transportation mostly by train. It made me a lot more positive about the NS. > Yeah that sucks, but this is the work of fanatics and in no way by > the average, anyone searching for a reason for murder, rape or > opression can find them in any religious context that doesn't matter > if it's one of various christian incarnations, islam or whatever > mono/multi/none-god(s) believes people believe in. Oh I agree to that. The problem IMHO is that currently the name of Allah and/or the Islam are used a lot when people are killed, and we don't see a massive counter-move from other (not mentally insane like those fanatics) Islamitic people. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From billiejoex at fastwebnet.it Sat Aug 27 15:40:38 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Sat, 27 Aug 2005 21:40:38 +0200 Subject: pcapy - print the DATA field of a packet References: Message-ID: <2l3Qe.19905$zs.9494@tornado.fastwebnet.it> I'm really sorry. I was talking about this source: http://oss.coresecurity.com/impacket/sniff.py ...but nevermind. I discovered the get_data_as_string() function that resolved my problem > Sorry, but *which* source are you talking about? The link you provided > appears to be merely a page of Google search results. > > Was there a specific page in there which you meant to point us to instead? > > -Peter From and-google at doxdesk.com Mon Aug 22 07:12:49 2005 From: and-google at doxdesk.com (and-google at doxdesk.com) Date: 22 Aug 2005 04:12:49 -0700 Subject: PIL: retreive image resolution (dpi) References: Message-ID: <1124709169.824131.49120@g44g2000cwa.googlegroups.com> AlexGreif.2609394 at bloglines.com wrote: > I looked at the PIL Image class but cannot see a posibility to retreive > the image resolution dots per inch (or pixels per inch) Not all formats provide a DPI value; since PIL doesn't do anything with DPI it's not part of the main interface. For PNG and JPEG at least the value may be retrievable from the extra info dictionary (image.info['dpi']) when loaded from a file that sets it. Expect an (x, y) tuple (not necessarily square-pixel). -- And Clover mailto:and at doxdesk.com http://www.doxdesk.com/ From ray_usenet at yahoo.com Fri Aug 12 12:41:18 2005 From: ray_usenet at yahoo.com (Ray) Date: 12 Aug 2005 09:41:18 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: <42fccc42$0$32450$626a14ce@news.free.fr> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123857710.987790.285330@o13g2000cwo.googlegroups.com> <42fccc42$0$32450$626a14ce@news.free.fr> Message-ID: <1123864878.820070.232350@g14g2000cwa.googlegroups.com> bruno modulix wrote: > Then wait until you discover what one can do with __magic_methods__, > functions-as-objects, closures, callable objects, descriptors > (properties on steroids), decorators, generators, and metaclasses... > *Then* you'll know what power means !-) > > And more is to come... ... I've got a feeling that this Pythonic journey will expand my brain so much ;) > > -- > bruno desthuilliers > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > p in 'onurb at xiludom.gro'.split('@')])" From EP at zomething.com Sat Aug 6 01:22:20 2005 From: EP at zomething.com (EP) Date: Fri, 5 Aug 2005 21:22:20 -0800 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <86br4byfpz.fsf@bhuda.mired.org> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <1123256939.119967.280500@z14g2000cwz.googlegroups.com> <1123264238.812930.315720@g47g2000cwa.googlegroups.com> <86br4byfpz.fsf@bhuda.mired.org> Message-ID: <20050805212220.2054839105.EP@zomething.com> Mike Meyer writes: > > The only way ISPs will find out that Python is popular is if potential > customers tell them they need it. So if they say no, be *sure* and > tell them you won't be using them because of that. I think this is an issue of critical mass, but I know minds the like of this group will immediate see that something as general as critical mass can be further reduced. Point being, all one needs is critical mass at a given point to overcome the inertia at that point. By overcoming inertia, and getting change at that point, if that point is visible to other major points, you can change thought on the larger scale. Personally, my current needs are sub collocation or dedicated server. In respect of a good ISP (though I may be breaking all usenet etiquette by mentioning a specific hosting company), I have been treated well by Zettai.net (Zope, Plone, Python + the usual other languages) -- and I get a lot of value there. I have no desire to move. Good people, and nice hosting if you like Unix. However, I would really like to see Python hosting part of the normal competitive hosting landscape, at least for the reasons mentioned --- sometimes we do not get to pick the host. What percent of the commercial hosting servers will my (Python) code run on? It is a small number, I think. So, if this issue were going to get some attention from some Pythonistas, what are the 2,3 or 5 hosting companies we would most like to see Python hosting offered by? And what are their e-mail addresses? I would certainly nominate GoDaddy.com (sales at goDaddy.com), who haves done a tremendous job on domain name registration, and may end up with a very large footprint in the (recently launched) hosting business. Python should definitely run on their servers (filers?). For the betterment of mankind. Anyway, just a thought. EP From usenet.20.evilspam at spamgourmet.com Sun Aug 28 03:12:16 2005 From: usenet.20.evilspam at spamgourmet.com (Chris Spencer) Date: Sun, 28 Aug 2005 07:12:16 GMT Subject: Socket Troubles In-Reply-To: <0ndQe.259$DV.23@trndny07> References: <0ndQe.259$DV.23@trndny07> Message-ID: Chris Spencer wrote: > I've written a simple class to manage P2P socket connections. However, > whenever I try to receive data, the socket raises an exception with the > error message (11, 'Resource temporarily unavailable'). > > My code's fairly straight-forward, with much of it right out of the > Python docs, so I'm not sure what I'm doing wrong. You can see it all at > http://deadbeefbabe.org/paste/1525/0 > > Any help is immensely appreciated. > > Thanks, > Chris One more thing. The code I posted is also a complete demo of my problem. Run the script in two different terminals simultaneously, like script.py 8000 8001 and script.py 8001 8000 They should then try talking to each other, reproducing the problem. Chris From bokr at oz.net Tue Aug 16 15:18:23 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 16 Aug 2005 19:18:23 GMT Subject: How to obtain GMT offset? References: Message-ID: <43023bdf.1627616969@news.oz.net> On Mon, 15 Aug 2005 20:57:16 -0700, Erik Max Francis wrote: >new pip wrote: > >> I'm using Windows os. If the current system date time is '28 Jun 2001 >> 14:17:15 +0700', how can I obtain the value '+0700' using python? > >time.timezone gives you the timezone offset in minutes. > ITYM seconds? Regards, Bengt Richter From googlenews at tooper.org Wed Aug 24 06:52:45 2005 From: googlenews at tooper.org (tooper) Date: 24 Aug 2005 03:52:45 -0700 Subject: execfile in global scope In-Reply-To: <1124873425.620610.170970@g47g2000cwa.googlegroups.com> References: <1124873425.620610.170970@g47g2000cwa.googlegroups.com> Message-ID: <1124880765.635997.39780@o13g2000cwo.googlegroups.com> What about : globdict= globals() def changevar(): global globdict execfile("changevar.py",globdict) x = 111 # global var changevar() print x # returns 111 instead of 555 From mwm at mired.org Mon Aug 15 22:52:36 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 15 Aug 2005 22:52:36 -0400 Subject: Invoking GUI for app running in background with a keypress References: Message-ID: <86fyta4mq3.fsf@bhuda.mired.org> Mathias Dahl writes: > How does one go about doing this? I found a small program written in C > (xbindkeys) that can do this and understand that it probably involves > a lot of "low-level" stuff in X which feels a bit "scary" :). Any > clues of doing this "easily" in Python + some module? Check out the python xlib implementation . It's a python library that speaks native X - no C required. That lets you do those low-level things in Python in a straightforward manner. It's not getting a lot of work lately - because it's largely a finished product. I use it heavily on a daily basis. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From ksenia.marasanova at gmail.com Wed Aug 10 06:44:09 2005 From: ksenia.marasanova at gmail.com (Ksenia Marasanova) Date: Wed, 10 Aug 2005 12:44:09 +0200 Subject: sorting question In-Reply-To: <130df1930508100315522b369f@mail.gmail.com> References: <1123662644.955191.93570@g47g2000cwa.googlegroups.com> <130df1930508100315522b369f@mail.gmail.com> Message-ID: <130df19305081003442308e534@mail.gmail.com> Example of the wrong sort: class Node: def __init__(self, name, url, order, pid, id): self.name = name self.url = url self.order = order self.pid = pid self.id = id def __repr__(self): return '%s [order: %s]' % (self.url, self.order) def mycmp(x,y): print "COMPARING", x, y if x.pid == y.pid: if x.order != y.order: return cmp(x.order,y.order) return cmp(x.url,y.url) #return cmp(x.pid,y.pid) return cmp(x.url,y.url) list = [ Node('top','/', order=1, pid=0, id=1000), Node('ham','/test/ham/', order=1, pid=400, id=21), Node('ham','/test2/spam/', order=1, pid=300, id=32), Node('ham','/test2/spam/spam/', order=1, pid=32, id=320), Node('ham','/test2/ham/', order=2, pid=300, id=31), Node('eggs','/test/ham/eggs/', order=1, pid=21, id=121), Node('eggs','/test2/ham/eggs/', order=1, pid=21, id=1210), Node('spam','/test2/', order=10, pid=1000, id=300), Node('spam','/test/', order=1, pid=1000, id=400) ] print "++++++++++++++ BEFORE SORTING +++++++++++++" for item in list: print item list.sort(mycmp) print "++++++++++++++ AFTER SORTING +++++++++++++" for item in list: print item ~ -- Ksenia From steve at holdenweb.com Mon Aug 22 16:12:40 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 16:12:40 -0400 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: Rich Teer wrote: > On Mon, 22 Aug 2005, jan V wrote: > > >>Please don't use ASCII art... not everyone uses a fixed-width font for his >>newsreader............... > > > Then I humbly submit thet they are using broken and/or badly > configured readers. ;-) > Not to mention the fact that if they are unix morons they probably have no idea what length the lines are anyway :-). If only everyone would do things Xah Lee's way we wouldn't have to see all his twaddle. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jason at tishler.net Fri Aug 26 14:36:34 2005 From: jason at tishler.net (Jason Tishler) Date: Fri, 26 Aug 2005 14:36:34 -0400 Subject: Socket Support When Compiling Python 2.3.5 On Cygwin In-Reply-To: <47801.159.53.78.143.1124984387.squirrel@mail.zoper.com> References: <47801.159.53.78.143.1124984387.squirrel@mail.zoper.com> Message-ID: <20050826183634.GA2040@tishler.net> Tom, On Thu, Aug 25, 2005 at 10:39:47AM -0500, tom at tompurl.com wrote: > What do I need to do to make sure that this file will be created with > I compile Python 2.3.5? Are there any error messages when the socket module is built during the Python build? If so, then post them to the list. 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 kay.schluehr at gmx.net Sun Aug 21 04:20:53 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 21 Aug 2005 01:20:53 -0700 Subject: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: <1124612453.206314.39330@g43g2000cwa.googlegroups.com> Steven Bethard wrote: > "The slice of s from i to j with step k is defined as the sequence of > items with index x = i + n*k such that 0 <= n < (j-i)/k." > > This seems to contradict list behavior though. > range(10)[9:-1:-2] == [] No, both is correct. But we don't have to interpret the second slice argument m as the limit j of the above definition. For positive values of m the identity m==j holds. For negative values of m we have j = max(0,i+m). This is consistent with the convenient negative indexing: >>> range(9)[-1] == range(9)[8] If we remember how -1 is interpreted as an index not as some limit the behaviour makes perfect sense. Kay From spammers-go-here at spam.invalid Sun Aug 7 13:31:25 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sun, 07 Aug 2005 13:31:25 -0400 Subject: Optional assignments ? Message-ID: <42f6456a$0$18641$14726298@news.sunsite.dk> Hi Is it possible to have something like : a,b,c,d=fn(that returns 10 return values) ? From jpopl at interia.pl Wed Aug 31 03:20:15 2005 From: jpopl at interia.pl (Jacek =?iso-8859-2?Q?Pop=B3awski?=) Date: Wed, 31 Aug 2005 07:20:15 +0000 (UTC) Subject: telnet.read_until() from telnetlib References: <1125075800.736986.28480@g43g2000cwa.googlegroups.com> <1125434258.386506.125620@f14g2000cwb.googlegroups.com> Message-ID: my newsreader told me that sp1d3rx at gmail.com wrote: > "If end of file is found and no text was read, raise EOFError. > Otherwise, when nothing matches, return (-1, None, text) where text is > the text received so far (may be the empty string if a timeout > happened). " What if: - exception has not been raised and: - time passed is smaller than timeout? How to interpret such behaviour? -- Free Software - find interesting programs and change them NetHack - meet interesting creatures, kill them and eat their bodies Usenet - meet interesting people from all over the world and flame them Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net From saint.infidel at gmail.com Tue Aug 23 13:57:05 2005 From: saint.infidel at gmail.com (infidel) Date: 23 Aug 2005 10:57:05 -0700 Subject: pipes like perl In-Reply-To: References: Message-ID: <1124819825.156716.72400@z14g2000cwz.googlegroups.com> Here's one technique I use to run an external command in a particular module: stdin, stdout, stderr = os.popen3(cmd) stdin.close() results = stdout.readlines() stdout.close() errors = stderr.readlines() stderr.close() if errors: raise Exception(''.join(errors)) Maybe this will get you going in a better direction? From me at privacy.net Fri Aug 19 11:40:53 2005 From: me at privacy.net (Dan Sommers) Date: Fri, 19 Aug 2005 11:40:53 -0400 Subject: stdin -> stdout References: Message-ID: On Fri, 19 Aug 2005 15:26:27 GMT, "max(01)*" wrote: > ps: in perl you ca do this: > ... > while ($line = ) > { > print STDOUT ("$line"); > } > ... import fileinput import sys for line in fileinput.input(): sys.stdout.write(line) Regards, Dan -- Dan Sommers From kenneth.m.mcdonald at sbcglobal.net Thu Aug 25 19:07:05 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Thu, 25 Aug 2005 18:07:05 -0500 Subject: pre-PEP: Object-oriented file module In-Reply-To: <430e4621$0$16867$9b622d9e@news.freenet.de> References: <430e4621$0$16867$9b622d9e@news.freenet.de> Message-ID: Why would any of the issues below be any more difficult than they are with the current file functions? I'm not proposing a C replacement for current functions, merely a Python module that wraps all of those functions (and adds some additional ones) in an appropriate class. On Aug 25, 2005, at 5:28 PM, Martin v. L?wis wrote: > I'd be personally curious as to how you would be dealing with > Unicode file names. How to access file attributes is also > an interesting question (e.g. how to find out whether it is > a symlink, whether it is a hidden file, what the POSIX ACL > is, and what the 8.3 short name is) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dimitri.pater at gmail.com Wed Aug 31 10:43:43 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Wed, 31 Aug 2005 16:43:43 +0200 Subject: change date format In-Reply-To: References: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> <200508311236.49648.lars@gustaebel.de> Message-ID: On 8/31/05, Fredrik Lundh wrote: > > Lars Gust?bel wrote: > > > Not a single occurrence of the f**k word. You're making progress. > > perhaps, but why is he posting apache questions to the python list? because we know all, we see all, we are "Python programing (sic) morons" dimitri -------------- next part -------------- An HTML attachment was scrubbed... URL: From rebound1618 at yahoo.com Sat Aug 6 19:57:03 2005 From: rebound1618 at yahoo.com (Jerry He) Date: Sat, 6 Aug 2005 16:57:03 -0700 (PDT) Subject: SWIG again Message-ID: <20050806235703.63983.qmail@web51509.mail.yahoo.com> > Robert Kern >Please don't make a new thread every time you post. sorry, I chose the digest mode when I signed up, and I have no idea how to reply, nor any idea how to change to the normal mode where I get individual emails so I can actually just hit the reply button instead of copying your name and part of your message every time I post... If you know how, please let me know. On the other hand, I discovered that had the command prompt, cmd.exe was trying to use the my cygwin python executable instead of the Windows python executable. Since I didn't have the patience to wait for .NET Framework SDK to download, (why does python need .NET framework SDK anyway??). I tried building it on cygwin, ... And it WORKED!!! I was really exited that I can do import example example.gcd(5, 10) and get the right answer... However, then I realized I just installed a completely useless module. Can you tell me how to completely remove that module? thanks in advance, -Jerry __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From http Mon Aug 22 12:16:41 2005 From: http (Paul Rubin) Date: 22 Aug 2005 09:16:41 -0700 Subject: Python for Webscripting (like PHP) References: Message-ID: <7xslx2kkuu.fsf@ruckus.brouhaha.com> "Fredrik Lundh" writes: > > (Python has even been told to be used by Yahoo! and Google, among others, > > but nobody was able to demonstrate this, so far) > hint: > http://mail.google.com/support/bin/answer.py?answer=6554 I don't see anything about Python at that url. I've heard Gmail is written in Java. Google is well known to use Python for many internal purposes, and perhaps for some low traffic administrative web pages. The main search application is written in C++ and is enormous. I haven't heard that any high traffic pages are handled in Python. From onurb at xiludom.gro Fri Aug 12 12:20:17 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 12 Aug 2005 18:20:17 +0200 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123857710.987790.285330@o13g2000cwo.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123857710.987790.285330@o13g2000cwo.googlegroups.com> Message-ID: <42fccc42$0$32450$626a14ce@news.free.fr> Ray wrote: > Roy Smith wrote: > >>Quick answer; there are none, all attributes are public. >> (snip) > > Well yeah... if you really want it, in Java you can do that too via > reflection. Just that I'm not used to it yet so I feel a bit jittery > with so much power on my hands! Then wait until you discover what one can do with __magic_methods__, functions-as-objects, closures, callable objects, descriptors (properties on steroids), decorators, generators, and metaclasses... *Then* you'll know what power means !-) And more is to come... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From bra_mik at invalid.invalid Mon Aug 15 18:33:48 2005 From: bra_mik at invalid.invalid (BRA_MIK) Date: Mon, 15 Aug 2005 22:33:48 GMT Subject: robust html parser Message-ID: I'm looking for a good and robust html parser that could parse complex html/xhtml document without crashing (possibly free) Could you help me please ? TIA MB From justin.vanwinkle at gmail.com Fri Aug 26 12:05:29 2005 From: justin.vanwinkle at gmail.com (justin.vanwinkle at gmail.com) Date: 26 Aug 2005 09:05:29 -0700 Subject: problems with tarfile.open and tar.bz2 Message-ID: <1125072329.310958.20650@g43g2000cwa.googlegroups.com> Hello everyone, I need some tar functionality for my program. Currently the following code properly displays tar archives, and tar.gz archives. However, it chokes on tar.bz2 archives with the following error: File "mail_filter.py", line 262, in extract_archive tar_archive = tarfile.open('', 'r', fileobj) File "/usr/lib/python2.3/tarfile.py", line 900, in open return func(name, "r", fileobj) File "/usr/lib/python2.3/tarfile.py", line 980, in bz2open raise ValueError, "no support for external file objects" ValueError: no support for external file objects The code snippet is: fileobj = StringIO(attach) if attach_type == 'application/x-tgz' or attach_type == 'application/x-tbz' or attach_type == 'application/x-tar': print '%s file detected, attempting to decompress' % (attach_type) tar_archive = tarfile.open('', 'r', fileobj) print tar_archive.getnames() for archive_file in tar_archive.getmembers(): print archive_file print tar_archive.extractfile(archive_file).read() #except: # print 'Error while extracting %s.' % (attach_type) # return '' I'm at my wits end with this error, it doesn't make any sense that it would treat bzip2'd tar archives very differently than gz'd tar archives. Justin From maxerickson at gmail.com Fri Aug 26 09:44:19 2005 From: maxerickson at gmail.com (Max Erickson) Date: Fri, 26 Aug 2005 13:44:19 -0000 Subject: Excel Character object through COM References: <1125057043.800968.180180@g47g2000cwa.googlegroups.com> Message-ID: "Krisz" wrote in news:1125057043.800968.180180 at g47g2000cwa.googlegroups.com: >>>> A.book.Worksheets(1).Range("a1").Characters(1,1) > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: Characters instance has no __call__ method > > So my question is that am I doing something wrong or there is a > different way to modify the color of a charater through COM. > try GetCharacters(1,1) max From peter.havens at gmail.com Tue Aug 9 12:51:23 2005 From: peter.havens at gmail.com (peter.havens at gmail.com) Date: 9 Aug 2005 09:51:23 -0700 Subject: Build errors for Objects/complexobject.c Message-ID: <1123606282.872534.214330@g47g2000cwa.googlegroups.com> Hi all, I'm attempting to build Python 2.4.1 on Solaris 10 using gcc 3.4.3. I get the following build error: gcc -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -o Objects/complexobject.o Objects/complexobject.c Objects/complexobject.c: In function `complex_pow': Objects/complexobject.c:479: error: invalid operands to binary == Objects/complexobject.c:479: error: wrong type argument to unary minus Objects/complexobject.c:479: error: invalid operands to binary == Objects/complexobject.c:479: error: wrong type argument to unary minus make: *** [Objects/complexobject.o] Error 1 I've poked around a bit, and it looks like there is a macro called Py_ADJUST_ERANGE2 which is being called at that point in the code. It uses a defined value for Py_HUGE_VAL. I'm guessing that the definition of Py_HUGE_VAL is the problem. The comments above the define for Py_HUGE_VAL, and the notes in the Misc/NEWS file lead me to believe that I need to correct the defined value of Py_HUGE_VAL (which is set to HUGE_VAL now, and I'm assuming that comes from a C standard). However, I'm not sure what to set that value to. I found two files in Solaris that seem to define HUGE_VAL in some way. /usr/include/iso/math_c99.h /usr/include/iso/math_iso.h ...and math_iso.h looks like the best choice. Here is the relevant sections of the header: #if !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && !defined(__C99FEATURES__) typedef union _h_val { unsigned long _i[sizeof (double) / sizeof (unsigned long)]; double _d; } _h_val; #ifdef __STDC__ extern const _h_val __huge_val; #else extern _h_val __huge_val; #endif #undef HUGE_VAL #define HUGE_VAL __huge_val._d #endif /* !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && ... */ ...my C isn't very strong, so that doesn't make sense to me -- is HUGE_VAL set to a type rather than a value? Anyway, I set Py_HUGE_VAL to LONG_MAX. It compiled and 'make test' seems to work out. Will this cause problems? Should I report this as a Python bug? Thanks, Pete From tprimke at interia.pl Sun Aug 14 06:49:08 2005 From: tprimke at interia.pl (TPJ) Date: 14 Aug 2005 03:49:08 -0700 Subject: Standalone applications ? In-Reply-To: <42feca21$0$18650$14726298@news.sunsite.dk> References: <42feba84$0$18644$14726298@news.sunsite.dk> <42feca21$0$18650$14726298@news.sunsite.dk> Message-ID: <1124016548.909588.77090@g47g2000cwa.googlegroups.com> > I should have added that my platform is Linux. In this case you shouldn't bother yourself with executables. Python is available on any major distribution. My Python apps are available as pyc files for Linux (and for those Windows users, who have Python installed) and as executables for Win (for those Windows users, who have no Python installed). From zen19725 at zen.co.uk Wed Aug 3 08:25:36 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 13:25:36 +0100 Subject: Art of Unit Testing References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> Message-ID: On Tue, 02 Aug 2005 21:11:52 +0200, Christoph Zwerschke wrote: >Thanks for the link, Grig. I wasn't aware of the py lib so far. The >possibility to create fixtures at the three different scopes is exactly >what I was looking for. > >Anyway, I think it would be nice to have that feature in the standard >lib unittest as well. It should not be too hard to add setUpOnce and >tearDownOnce methods in addition to setUp and tearDown. Actually, I am >wondering that there doesn't seem to be any development progress since >unittest was included in the standard lib of Python 2.1 in August 2001. >I had expected that such an important module would be continually >improved and maintained. How come? So few people using unit tests? Or do >most people write their own testing code or use py.test? I can answer this question, at least for myself. I use regression testing a lot, and have done so since before Python's unittest was written. Originally I just used my own code, which didn't use classes just functions that called other functions. later on I decided to have a look at unittest. I found two problems with it. Firstly it didn't stop when it reached an error, it continued doing the rewsr of the tests. This wasn't what i wanted: most of the time when a test fails, I want to look at what's happening. I don't want unnecessary information about other tests, I want to concentrate on that one thing. Also, the log of information sent to stdout about each test was less informative than I wanted (and which my old system provided). So I had a look at unittest to see if I could modify it to fix these problems. However, I found the code to be rather complex and hard to understand so I decided it would be quicker to write my own testing framework. Which I did. -- Email: zen19725 at zen dot co dot uk From donn at drizzle.com Sun Aug 7 00:23:01 2005 From: donn at drizzle.com (Donn Cave) Date: Sun, 07 Aug 2005 04:23:01 -0000 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> <86br4avf5t.fsf@bhuda.mired.org> <11fakjctean9u8a@news.supernews.com> <863bpmv85p.fsf@bhuda.mired.org> Message-ID: <1123388581.613567@yasure> Quoth Mike Meyer : | "John Roth" writes: ... |> It seems to be the concensus on this group anyway: declarative typing |> does not give enough improvement in program correctness to override |> more concise programs and TDD. That may, of course, be wishful |> thinking on the Python community's part. | | "The concensus of this group" is a *long* way from "the debate has | moved on". I agree that it's the concensus of this group - but this is | a group devoted to a dynamic programming language. If you go to a | group devoted to a statically typed language, you'll find a different | concensus. Which means the debate is still very much alive. Also an OOP group, which tends to mean that experience with static typing will have been with C++ or Java, or similar languages. The ideas I've read for P3000 fortunately show some influence from the type inference systems popular in FP. What people in this group think is frankly irrelevant if they're thinking in terms of Java. | So we have one (count him, 1) user who complains that it's changing to | fast. I suspect most readers here would disagree with him. True, but another statistic that's compromised by self-selecting population. Earlier in this thread our attention was directed to an article announcing a fairly radical drop in popularity of Python (and other interpreted languages) for new projects outside of North America, citing failure to penetrate the "enterprise" market as a reason. Ask the enterprise world if they think Python is changing fast enough. Maybe they're giving up on Python because they decided they'd never get code blocks. (Ha ha.) Donn Cave, donn at drizzle.com From siona at chiark.greenend.org.uk Wed Aug 10 09:07:30 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 10 Aug 2005 14:07:30 +0100 (BST) Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> Message-ID: <6It*e8NVq@news.chiark.greenend.org.uk> infidel wrote: >> [ somebody else wrote: ] >> To my mind, although one CAN put many classes in a file, it is better to >> put one class per file, for readability and maintainability. >Personally I find it easier to maintain a set of related classes when >they're all in the same file. Real world example: I have here an API I'm one of the maintainers of which is available in C++, Java and Python versions. Part of the nature of this beast is that it has about 20 exception classes derived from the same base class. So that's one .py for the Python interface, a .h and a .cxx for the C++ (there is some logic in the base class which counter-indicates stuffing it all in one .h), and 21 .java files (plus their corresponding .classes). Take a guess which ones[*] are easiest to maintain. ([*] hint) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From fredrik at pythonware.com Tue Aug 16 09:35:08 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 16 Aug 2005 15:35:08 +0200 Subject: looping list problem References: Message-ID: Jon Bowlas wrote: > Ok so I changed it to this: > > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > hiddennavelements = navstring.split(' ') > for hiddennavelement in hiddennavelements: > yield hiddennavelements > > But I get the following error- Line 5: Yield statements are not allowed. umm. I might be missing something, but I cannot find any trace of that error message in the Python interpreter source code. it doesn't even look like a Python traceback. did you perhaps forget to tell us that you're using some fancy web framework that uses Python in its own idiosyncratic way? From simon.brunning at gmail.com Fri Aug 12 08:19:15 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Fri, 12 Aug 2005 13:19:15 +0100 Subject: bug in property? In-Reply-To: <42FC8FF7.4080202@agg.astranet.ru> References: <42FC8FF7.4080202@agg.astranet.ru> Message-ID: <8c7f10c605081205191dc88c70@mail.gmail.com> On 8/12/05, Damir Hakimov wrote: > #!/usr/bin/python2.4 > class test_property: > def __init__(self): > self._x="Zero" > pass > def setx(self,x): > print "set x" #this is not work > self._x=x > def getx(self): return self._x > def delx(self): del(self._x) > x=property(getx,setx,delx,"XXX") > t=test_property() > t.x=1 > print t.x Properties only work with new style classes, so try: class test_property(object): -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From bignose+hates-spam at benfinney.id.au Wed Aug 10 23:52:09 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2005 13:52:09 +1000 (EST) Subject: what's the exactly newsgroup url of python-list? References: Message-ID: He, Aspk wrote: > My thunderbir cant connect to comp.lang.python as the python.org page > saying. You may be confused. is a URL to a Usenet newsgroup, as evidenced by the 'news:' schema part. If your web browser is configured properly to invoke a newsreader (such as Thunderbird) for 'news:' URLs, your newsrreader will then attempt to get the comp.lang.newsgroup from your default NNTP server. python-list is a mailing list. -- \ "When I was a baby I kept a diary. Recently I was re-reading | `\ it, it said 'Day 1: Still tired from the move. Day 2: Everybody | _o__) talks to me like I'm an idiot.'" -- Steven Wright | Ben Finney From benn at cenix-bioscience.com Tue Aug 9 10:14:21 2005 From: benn at cenix-bioscience.com (Neil Benn) Date: Tue, 09 Aug 2005 16:14:21 +0200 Subject: Recommendations for CVS systems In-Reply-To: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> Message-ID: <42F8BA3D.40304@cenix-bioscience.com> geskerrett at hotmail.com wrote: >I was wondering if anyone could make recomendations/comments about CVS >systems, their experiences and what perhaps the strengths of each. > >Currently we have 2 developers but expect to grow to perhaps 5. > >Most of the developement is Python, but some C, Javascript, HTML, etc. > >The IDE what have been using/experimenting with are drPython and >eclipse with PyDev. > > >TIA > > > I use SVN which is excellent (http://subversion.tigris.org/), on a windows box as a client I use TortoiseSVN which is also excellent. I have the server running in Apache. To work in SVN with eclipse you will need an eclipse plugin : http://subclipse.tigris.org/#subclipse Neil -- 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 bsharitt at gmail.com Tue Aug 30 19:00:41 2005 From: bsharitt at gmail.com (bsharitt at gmail.com) Date: 30 Aug 2005 16:00:41 -0700 Subject: py2app and Bittornado Message-ID: <1125442841.042912.197950@g14g2000cwa.googlegroups.com> I'm trying to get Bittornado to run on Mac OS X (10.4 with Python 2.3.5) but I've only ever dealt with Python at lower lever scripting stuff, never wxPython or another GUI stuff. py2app is supposed to be the tool to create Mac friendly Python applications(like py2exe on Windows), but the documentation for py2app doesn't seem to be much help. The setup.py script that comes with BitTornado doesn't run when I type python setup.py py2app and produces the following error: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: invalid command 'py2app' (no module named 'distutils.command.py2app') When I drag the script to PackageInstaller, it creates a Mac installer package, but all that does is mostly copy the the sane stuff stuff to /usr/local/bin and when I try to run btdownloadgui.py all I get is: Traceback (most recent call last): File "btdownloadgui.py", line 29, in ? from BitTornado.ConfigReader import configReader File "/Library/Python/2.3/site-packages/BitTornado/ConfigReader.py", line 40, in ? _CHECKINGCOLOR = ColorToHex(wxSystemSettings_GetColour(wxSYS_COLOUR_3DSHADOW)) File "/BinaryCache/wxWidgets/wxWidgets-2.root~174/System/Library/Frameworks/Python.framework/Versions/2.3/Extras/lib/python/wx-2.5.3-mac-unicode/wx/_misc.py", line 145, in SystemSettings_GetColour wx._core.PyNoAppError: The wx.App object must be created first! Any help would be appreciated. Either reply to this or email me. From pecoraREMOVE at THISanvil.nrl.navy.mil Mon Aug 8 12:24:11 2005 From: pecoraREMOVE at THISanvil.nrl.navy.mil (Lou Pecora) Date: Mon, 08 Aug 2005 12:24:11 -0400 Subject: GUI programming, embedding, real time plots, etc. References: <42f4157f$0$18643$14726298@news.sunsite.dk> Message-ID: In article <42f4157f$0$18643$14726298 at news.sunsite.dk>, Madhusudan Singh wrote: > 1. In using matplotlib (my code essentially involved creating a plot and > show()'ing it inside a loop), the color of the plot changed. Is there a way > to tell matplotlib to not treat each new invocation as a new plot, but to > really overwrite the old one ? You were able to get matplotlib to open a new plot each time (assuming you closed the old one, too)? Can you show a simple example of this? Thanks. -- Lou Pecora (my views are my own) REMOVE THIS to email me. From dial#####$$NOSPAM##$#$##tone at gmail.com Sun Aug 28 14:46:15 2005 From: dial#####$$NOSPAM##$#$##tone at gmail.com (Valentino Volonghi aka Dialtone) Date: Sun, 28 Aug 2005 20:46:15 +0200 Subject: Release of PyPy 0.7.0 References: <4311ea97$0$1276$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1h20uj1.y52kzk1che9j9N%dial#####$$NOSPAM##$#$##tone@gmail.com> Michael Sparks wrote: > Would it be useful for people to start trying out their modules/code to see > if they work with this release, and whether they can likewise be translated > using the C/LLVM backends, or would you say this is too early? (I'm more > thinking in terms of it providing real world usecases in the hope of > finding things that don't work - rather than anything else) This is not how it works. Pypy doesn't translate your code to C/LLVM. Currently PyPy can only translate a pretty simple subset of python called RPython which has a very C-like syntax (but without memory management code). This is needed to allow type inference inside the interpreter code. The code in your application is application code and can be whatever you want, you may try to translate it to C/LLVM but it won't be that good of course because the annotator is not that intelligent. Just In Time compilation a-la-psyco is planned before the 1.0 release of pypy. Right now also the compiler/parser run in application level which means it is rather slow because it is not translated like the rest of pypy (which accounts for quite a bit of the slowness of the translated pypy) [this is of course only true if they didn't manage to rewrite the parser/compiler in RPython, which I admit I'm not sure] More information is available on codespeak.net website :). What's really cool in PyPy is how easily you can implement a new object space and change semantics of operations done in python. Writing a Python interpreter that can share data structures across many computers will be hard but possible. There are already 4 different object spaces implemented, the standard one, the thunk one (which is a lazy evaluation object space), the flowgraph object space and the trace object space that traces each operation done. > Either way, this looks like a great milestone - congratulations to the > entire team. (I remember PyPy being met with skepticism as to whether > it could even be done! :-) Indeed. -- Valentino Volonghi aka Dialtone Now Running MacOSX 10.4 Blog: http://vvolonghi.blogspot.com http://weever.berlios.de From phillip.watts at anvilcom.com Sun Aug 7 15:11:25 2005 From: phillip.watts at anvilcom.com (phil) Date: Sun, 07 Aug 2005 14:11:25 -0500 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> Message-ID: <42F65CDD.4070005@anvilcom.com> > Kay Schluehr (kay.schluehr at gmx.net) wrote: > : No good news for scripting-language fans: > > : http://www.phpmag.net/itr/news/psecom,id,23284,nodeid,113.html > What incredible horse dooey. The only thing that NEVER "penetrates the enterprise space" is good sense. Does anyone read history books? There is no such thing as a large corporation that is not doomed. There are a few names which are older than 1/2 a century but the companies and players are unrecognizable. We have barbeque joints in Texas older than IBM. And noone from 1970 would recognize IBM. The "enterprise" is good for one thing. Devouring each other. The "enterprise"'s opinion about what is good for the future is like this broker I knew in Dallas. All you had to do was find out which stock he was recommending, then short it. From cowie.rob at gmail.com Wed Aug 31 13:12:07 2005 From: cowie.rob at gmail.com (Rob Cowie) Date: 31 Aug 2005 10:12:07 -0700 Subject: Retrieving Filename from Path Message-ID: <1125508327.616838.55630@g44g2000cwa.googlegroups.com> Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string using '/' as delimiters and get the last 'word'. The reason I'm not entirely happy with that method is that it is platform specific. I would prefer to use a built in method if possible. Cheers, Rob Cowie From john at castleamber.com Tue Aug 30 14:09:30 2005 From: john at castleamber.com (John Bokma) Date: 30 Aug 2005 18:09:30 GMT Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: Alan Balmer wrote: > Another obnoxious cross-poster identified. Thank you. You mean Alan clueless n00b Balmer? At least you got the follow up doesn't work the first time. Try to get the other message I wrote as well: ignore this thread, it will stop in 1-2 days out of itself. If you keep feeding it, it will last much and much longer. Or did we just met Alan the clueless n00b troll Balmer? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From aahz at pythoncraft.com Wed Aug 10 11:32:48 2005 From: aahz at pythoncraft.com (Aahz) Date: 10 Aug 2005 08:32:48 -0700 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> Message-ID: In article , Neal Becker wrote: > >For a python newsgroup, you are required to consider mercurial. It's not >ready for production use yet, but is making rapid progress, and many >(including myself) are using it. Why do you say "required" when the next sentence you say it's not ready for production? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From googlenews at tooper.org Tue Aug 30 05:23:47 2005 From: googlenews at tooper.org (tooper) Date: 30 Aug 2005 02:23:47 -0700 Subject: Python port on Palm Treo? In-Reply-To: <3ngpgqF1fdulU1@individual.net> References: <3ngpgqF1fdulU1@individual.net> Message-ID: <1125393827.028218.204470@f14g2000cwb.googlegroups.com> I'm not aware of any Treo dedicated port, but as Treo is running Palm, the Palm port of Python should be OK (if I remember well it's pypi or pipy, standing for PYthon for palm PIlot) Hope it helps... From thomas at thomas-lotze.de Mon Aug 1 20:31:12 2005 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Tue, 02 Aug 2005 02:31:12 +0200 Subject: Using gnu readline in my own python program? References: <1122938196.818416.234960@g44g2000cwa.googlegroups.com> <1122941307.523726.190200@g47g2000cwa.googlegroups.com> Message-ID: sboyle55 wrote: > raw_input is an excellent suggestion, and almost exactly what I want. > > But, I want to give the user a string to edit, not have them start from > scratch inputting a string. Take a look at the fancy_input function. -- Thomas From fredrik at pythonware.com Mon Aug 22 19:18:15 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 01:18:15 +0200 Subject: Can I send files through xmlrpc connections? References: <1124742818.840010.59710@g44g2000cwa.googlegroups.com> <1124749305.244308.154430@g49g2000cwa.googlegroups.com> Message-ID: "dcrespo" wrote: > I'm sorry, I didn't the right question... Of course that I can break > the file and rewrite it on an xmlrpc protocol for transmition, or send > a byte each time through the socket lib. I meant is there a program > already developed that sends and receives files based on xmlrpc calls? I'm not sure I understand what you're trying to do, really, but here's a program to send files based on xmlrpc calls: import sys, xmlrpclib xmlrpclib.ServerProxy(sys.argv[1]).store(open(sys.argv[2], "rb").read()) to receive files based on xmlrpc calls, see: http://www.python.org/doc/2.4/lib/module-SimpleXMLRPCServer.html From gene.tani at gmail.com Wed Aug 10 15:19:02 2005 From: gene.tani at gmail.com (gene tani) Date: 10 Aug 2005 12:19:02 -0700 Subject: "Ordered" dicts In-Reply-To: <1123684654.638017.25390@g43g2000cwa.googlegroups.com> References: <1123684654.638017.25390@g43g2000cwa.googlegroups.com> Message-ID: <1123701542.520442.181670@g44g2000cwa.googlegroups.com> More ways to do it, from the FAQ http://www.python.org/doc/faq/programming.html#how-can-i-get-a-dictionary-to-display-its-keys-in-a-consistent-order Also look at the recipe, page 222 of Cookbook2, that allows you to rank key values by their associated values, and demonstrate the power of mixins. From rtconner at gmail.com Tue Aug 9 11:29:46 2005 From: rtconner at gmail.com (Rob Conner) Date: 9 Aug 2005 08:29:46 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123536834.629449.154790@g44g2000cwa.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> Message-ID: <1123601386.567072.111240@o13g2000cwo.googlegroups.com> Ah ok, thats interesting I hadn't even tried a valid date yet. Now how do I get this thing to call __init__ when I pass in an invalid date and the ValueError is thrown and caught within __new__. dt = DateTime(2005, 02, 30) From claird at lairds.us Tue Aug 30 08:08:03 2005 From: claird at lairds.us (Cameron Laird) Date: Tue, 30 Aug 2005 12:08:03 GMT Subject: Perl books (was: Experience regarding Python tutorials?) References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <3n688aF2fp4U1@uni-berlin.de> <1124986050.757959.307630@o13g2000cwo.googlegroups.com> Message-ID: In article <1124986050.757959.307630 at o13g2000cwo.googlegroups.com>, SamFeltus wrote: . . . >with (google TMTOWTDI), so Perl will teach you to BE CAREFUL. The >O'Reilly Perl books are excellent. > Well, no. I understand you writing that, and recognize it's a widespread impression. O'Reilly's Perl catalogue is indeed a notable achievement, with many high spots. HOWEVER, there are over three dozen ORA Perl titles still in print. It's simply not true that they're all of uniformly superior quality. Even among those which are unarguably stylish, several are too idiosyncratic and even self-indulgent to be "excellent" for a beginner at the level the original poster described as his. From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 26 14:07:31 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 26 Aug 2005 20:07:31 +0200 Subject: reportlab and custom fonts In-Reply-To: <3n93a4Ffo89U1@individual.net> References: <3n93a4Ffo89U1@individual.net> Message-ID: <3n9433FelusU1@individual.net> Reinhold Birkenfeld wrote: > Hi, > > I'm trying to get reportlab working together with the Tahoma font > (by Microsoft ;) > > So far it's up and running (converted the ttf with ttf2pt1), but the > Euro sign (which is in position 0x80 in the WinAnsiEncoding) fails to > show up in the final PDF. > > I investigated a bit and saw that in the afm (and pfb) the code point > 128 is called "uni20AC". That's okay in principle, since that Unicode > character is the Euro sign, but it seems that reportlab likes the > character to be named "Euro". Okay, renamed it in both files, still no > luck. > > Has anyone experience with this problem? Never mind, I overlooked one occurence of "uni20AC" in my .t1a file. Reinhold From duncan.booth at invalid.invalid Thu Aug 11 08:11:40 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Aug 2005 12:11:40 GMT Subject: Regular expression to match a # References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> Message-ID: Dan wrote: >> My (probably to naive) approach is: p = re.compile(r'\b#include\b) > > I think your problem is the \b at the beginning. \b matches a word break > (defined as \w\W or \W\w). There would only be a word break before the # > if the preceding character were a \w (that is, [A-Za-z0-9_], and maybe > some other characters depending on your locale). > > However, the \b after the "include" is exactly what you want. > So the OP probably wanted '\B' the exact opposite of '\b' for the start of the string, i.e. only match the # if it is NOT preceded by a wordbreak. Alternatively for C style #includes search for r'^\s*#\s*include\b'. From dimitri.pater at gmail.com Thu Aug 25 06:42:48 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Thu, 25 Aug 2005 12:42:48 +0200 Subject: Should I move to Amsterdam? In-Reply-To: References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> Message-ID: > > > The problem with the world is stupidity. Not saying there should be a > capital punishment for stupidity, but why don't we just take the > safety labels off of everything and let the problem solve itself? > Frank Zappa Geef mij wat vloerbedekking onder deze vette zwevende sofa sorry, very off-topic, couldn't resist dimitri * * -------------- next part -------------- An HTML attachment was scrubbed... URL: From sybrenUSE at YOURthirdtower.com.imagination Thu Aug 25 06:33:22 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Thu, 25 Aug 2005 12:33:22 +0200 Subject: loop in python References: <1124964483.645753.190460@g47g2000cwa.googlegroups.com> Message-ID: James enlightened us with: > One does not compare speed when they use Perl/Python/Ruby/Tcl. They > are all more or less in the same performance ball park. I don't want to offend you or anything, but doesn't the second sentence mean that someone DID do a speed comparison? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From daniel.dittmar at sap.corp Mon Aug 22 11:26:06 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Mon, 22 Aug 2005 17:26:06 +0200 Subject: loop in python In-Reply-To: References: Message-ID: km wrote: > Why is it that the implementation of empty loop so slow in python when compared to perl ? [...] > Is python runtime slow at all aspects when compared to perl ? No > I really wonder what makes python slower than perl ? It could be that the Perl compiler recognizes such a for loop and emits special code (e.g. an integer loop variable that gets incremented). Python creates an xrange object and then has the overhead of 1000 next() calls. You should benchmark other features before jumping to conclusions: calls to functions, calls to methods, calls to inherited methods. Others will probably chime in with arguments whether such micro benchmarks are a useful indication of the speed a complete program at all. > Is there any proposal to make python faster in future versions ? Yes in the general case, probably no in this specific case. Daniel From lshuai at kaneva.com Mon Aug 1 16:29:22 2005 From: lshuai at kaneva.com (Liu Shuai) Date: Mon, 1 Aug 2005 16:29:22 -0400 Subject: Terminate a thread that doesn't check for events Message-ID: <9CA58FB7E095F146AD3E7FE1E5855929042F9A@brain.klausatlanta.local> Hi all, I am aware that similar and probably same questions have been posted many times, but I was unable to find a solution after reading a dozen threads in the archive. So here it goes again. I have a thread that does some heavy task (hash calculation, for instance). I need a mechanism that works *across platforms* to stop that calculation if user decides to exit. How can I do that? I can not do the standard "periodical checking" way since there is only one function/step call in my thread. Here is a snippet of my thread classes to help illustrate the problem: class Dispatcher(): def __init__(self): self.__worker = Worker() def start(self): self.__worker.start() def stop(): #how do i stop the worker? class Worker(threading.Thread): def __init__(self): def run(self): oneTimeConsumingCall() Thank you in advance for any suggestions/pointers. LS -------------- next part -------------- An HTML attachment was scrubbed... URL: From zarnovican at gmail.com Mon Aug 15 12:32:56 2005 From: zarnovican at gmail.com (BranoZ) Date: 15 Aug 2005 09:32:56 -0700 Subject: seeking Python developers In-Reply-To: <1124121180.796627.105810@g44g2000cwa.googlegroups.com> References: <1124121180.796627.105810@g44g2000cwa.googlegroups.com> Message-ID: <1124123576.433095.120370@f14g2000cwb.googlegroups.com> > If anyone has ideas for how to find such people within > this geographic area, I'd much appreciate suggestions.. Try to post it at http://www.python.org/Jobs.html BranoZ From john at castleamber.com Thu Aug 25 17:38:24 2005 From: john at castleamber.com (John Bokma) Date: 25 Aug 2005 21:38:24 GMT Subject: Usenet, HTML (was Re: Jargons of Info Tech industry) References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> Message-ID: Ulrich Hobelmann wrote: > On the information side (in contrast to the discussion side) RSS is > replacing Usenet, LOL, how? I can't post to RSS feeds. Or do you mean for lurkers? > There is no real reason why NNTP couldn't be used like RSS (i.e. > contain a small description and a web link as message text), It has been used like that for ages (or as long as I can remember). > or why a > newsgroup shouldn't we written in HTML and contain a (default, or > user-provided) CSS sheet. It's called www. It's already here (or there) > If things were that way, suddenly people > *would* use Outlook and Thunderbird for news-reading, But why do you want that? (Oh, and you can't read news with Outlook). Why do you want more people on Usenet? > while today > everything is just Browser+HTTP. And what's wrong with that? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From hongqn at gmail.com Fri Aug 12 13:16:25 2005 From: hongqn at gmail.com (Qiangning Hong) Date: Sat, 13 Aug 2005 01:16:25 +0800 Subject: need help with my append syntax In-Reply-To: References: <1123864268.248317.23940@g44g2000cwa.googlegroups.com> <42FCD2BE.3030405@gmail.com> Message-ID: <42FCD969.9090705@gmail.com> Do not discuss off-list, maybe others will have better solutions to your question. And also please do not top-posting, it makes me difficult to trim the irrelevant text. yaffa wrote: > sorry addr is a variable. how to i append to that? I know addr is a variable (or better a name). But what object do you assign to it? I mean, does incident.findNextSibling('td') return a string or an object of another type? If your code "addr.append('%s;')" doesn't raise an exception, it is pretty sure what assigned to addr is not a string (maybe a list, which has an "append" method). You can use "print addr" or "print repr(addr)" to determine that. > ----- Original Message ----- From: "Qiangning Hong" > To: "yaffa" > Cc: > Sent: Friday, August 12, 2005 12:47 PM > Subject: Re: need help with my append syntax > > >> yaffa wrote: >> >>> dear folks, >>> >>> i'm trying to append a semicolon to my addr string and am using the >>> syntax below. for some reason the added on of the ; doesn't work. >>> when i print it out later on it only shows the original value of addr. >>> >>> addr = incident.findNextSibling('td') >>> addr.append('%s;') >> >> >> Is addr is really a string? AFAIK, strings havn't an append methond. >> >> use += to extend strings: >> >> .>>> addr = 'abc' >> .>>> addr += '%s;' >> .>>> addr >> 'abc%s;' >> >> -- >> Qiangning Hong >> >> I'm usually annoyed by IDEs because, for instance, they don't use VIM >> as an editor. Since I'm hooked to that, all IDEs I've used so far have >> failed to impress me. >> -- Sybren Stuvel @ c.l.python >> >> Get Firefox! >> >> > -- Qiangning Hong I'm usually annoyed by IDEs because, for instance, they don't use VIM as an editor. Since I'm hooked to that, all IDEs I've used so far have failed to impress me. -- Sybren Stuvel @ c.l.python Get Firefox! From grante at visi.com Thu Aug 11 10:22:43 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 11 Aug 2005 14:22:43 -0000 Subject: what's the exactly newsgroup url of python-list? References: Message-ID: <11fmnpj6571j1ae@corp.supernews.com> On 2005-08-11, Fredrik Lundh wrote: > Ben Finney wrote: > >> is a URL to a Usenet newsgroup, as >> evidenced by the 'news:' schema part. If your web browser is >> configured properly to invoke a newsreader (such as Thunderbird) for >> 'news:' URLs, your newsrreader will then attempt to get the >> comp.lang.newsgroup from your default NNTP server. > > footnote: if you have no such server, things won't work. > > for an excellent way to read the python mailing list via a news- > reader even if you don't have access to a "real" NNTP server, > see http://gmane.org/ Using an NNTP gateway to a mailing list that's gatewayed to a Usenet group. That's about like running Cygwin under Windows under Linux: there are valid reasons to do it, but it always feels surreal. -- Grant Edwards grante Yow! My Aunt MAUREEN was at a military advisor to IKE & visi.com TINA TURNER!! From mritty at gmail.com Fri Aug 26 12:25:52 2005 From: mritty at gmail.com (Paul Lalli) Date: 26 Aug 2005 09:25:52 -0700 Subject: minimalist regular expression In-Reply-To: References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> <1125050745.833419.120910@o13g2000cwo.googlegroups.com> Message-ID: <1125073552.716818.198610@g14g2000cwa.googlegroups.com> Brian McCauley wrote: > Paul Lalli wrote: > > > > m//; > > > > it matches everything. > > Not in Perl it doesn't. :-) Sure it does.... provided you haven't tried matching anything else beforehand... Paul Lalli From jeff.millstein at comcast.net Fri Aug 26 23:52:06 2005 From: jeff.millstein at comcast.net (Jeff) Date: 26 Aug 2005 20:52:06 -0700 Subject: SAS Transport FIle Message-ID: <1125114726.509035.126560@f14g2000cwb.googlegroups.com> Does anyone know of a python module to read a SAS Transport (XPORT) file? From russandheather at gmail.com Wed Aug 10 17:12:59 2005 From: russandheather at gmail.com (Qopit) Date: 10 Aug 2005 14:12:59 -0700 Subject: "Compile time" checking? In-Reply-To: References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: <1123708379.036298.134210@g43g2000cwa.googlegroups.com> > def tester(a, b, c): > global tester > print "bogus test function", a, b, c > def tester(a, b): > print "other test function", a, b > > tester(1, 2, 3) # This runs fine. > tester(1, 2) # This too. Interesting example. In that case, pychecker does spit out a warning since it has trouble deciphering the redefinition. I have no problem whatsoever with a compiler/code-checker getting confused in such an oddball situation. As you say, it is difficult for an automated process to follow such flows. A warning is fine here (as I got with the "proper" pychecker on my initial example - it did easily catch what I thought should have been, and was, obvious). With your example, I was curious how pychecker would deal with it if you altered the flow a bit so that all calls would/should make sense in what seems to me to be logical locals order, and tried this: #--- def tester(a, b, c): global tester print "bogus test function", a, b, c def tester(a, b): print "other test function", a, b tester(1, 2) #no pychecker complaint since local tester(1, 2, 3) # pychecker complains here (?) #--- I'm a bit confused why pychecker complained where it did - I don't get how it got the 2 arg version at that point, but I actually don't really care that much due to the weirdness level of this code. A compiler (or code-checker) warning on this code is perfectly acceptable to me. I'm a big fan of Python's ability to easily rebind everything in sight, but this particular usage seems like a strange abuse I wouldn't expect a code-checker to be able to figure out. I'll just avoid writing confusing code like that... it's not only confusing to a program, but to a human as well! Dynamically massacring a function definition (as opposed to just rebinding a new implementation) like that seems odd to me. > Compile it by running it and write unit tests. ... sure, that works, I'm just used to the integrated tools I've had available to me for the last 15 years to help me write more robust code waaaay faster than having to unit test a zillion blocks of code when you change a single definition somewhere. PyChecker seems like it may fit the bill right now... just need to try it some more and figure out how to get around that weird raw_input thing. The basis for my first post was a jerk what-the-heck reaction to the fact that it seemed that pychecker didn't get the simple arg count mismatch error, but jk showed that that was wrong and I just have to sort out something with SPE. Cheers, Russ From pink at odahoda.de Fri Aug 5 05:02:48 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Fri, 05 Aug 2005 11:02:48 +0200 Subject: Py: a very dangerous language References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> <1123209659.123369.286840@f14g2000cwb.googlegroups.com> Message-ID: Luis M. Gonzalez wrote: > This is great! > It's absolutely useless, like a real therapist, but it's free! Never heard of Eliza? Even Emacs has it built in (Menu Help -> Emacs Psychiatrist). -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From yoav_artzi at il.vio.com Mon Aug 22 03:30:43 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Mon, 22 Aug 2005 10:30:43 +0300 Subject: Running multiple console processes and watching their output Message-ID: <43097ddf$1@news.bezeqint.net> I need to run multiple console apps in the background and to watch their output. I have no idea if this is possible, and I don't even know where to start looking. The processes are watchers, meaning that they watch folders and mail boxes and do operations on items in them . Essentially these are Java command line programs. What I need is to have them running and to take a glance at their console output once in a while to parse it. Is it possible? How? Any idea will help. Thanks. From rafi at free.fr Sun Aug 28 17:18:50 2005 From: rafi at free.fr (rafi) Date: Sun, 28 Aug 2005 23:18:50 +0200 Subject: aproximate a number In-Reply-To: References: Message-ID: <43122a2f$0$23053$636a15ce@news.free.fr> billiejoex wrote: > Hi all. I'd need to aproximate a given float number into the next (int) > bigger one. Because of my bad english I try to explain it with some example: > > 5.7 --> 6 > 52.987 --> 53 > 3.34 --> 4 > 2.1 --> 3 > > Regards > > math.ceil returns what you need but as a float, then create an int >>> import math >>> math.ceil (12.3) 13.0 >>> int (math.ceil (12.3)) 13 hth -- rafi "Imagination is more important than knowledge." (Albert Einstein) From denis.kasak at gmail.com Fri Aug 26 10:43:59 2005 From: denis.kasak at gmail.com (Denis Kasak) Date: Fri, 26 Aug 2005 16:43:59 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <1125064956.863140.32270@g14g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <1125064956.863140.32270@g14g2000cwa.googlegroups.com> Message-ID: T Beck wrote: > > Wasn't the point... I never said they were. HTML is at version 4.0(I > think?) now, AND we've added extra layers of stuff you can use > alongside of it. The internet is a free-flowing evolving place... to > try to protect one little segment like usenet from ever evolving is > just ensuring it's slow death, IMHO. > > That's all... HTML is at version 4.01 to be precise, but that is precisely off-topic. This discussion has being going on for long enough. It is held in a large crosspost to newsgroups that have nothing to do with HTML or the evolution of Usenet. The bottom line is that most Usenet users like it the way it is now, and it certainly serves it's purpose. The Web and Usenet should not mix as they are two distinct entities and merging them would lose some of their distinctive qualities, making the Internet a poorer place. I suggest letting the matter rest or taking it to a more appropriate newsgroup. -- Denis From xah at xahlee.org Wed Aug 31 04:46:17 2005 From: xah at xahlee.org (Xah Lee) Date: 31 Aug 2005 01:46:17 -0700 Subject: Python doc problems example: gzip module Message-ID: <1125477977.072146.298670@g47g2000cwa.googlegroups.com> today i need to use Python to decompress gzip files. since i'm familiar with Python doc and have 10 years of computing experience with 4 years in unix admin and perl, i have quickly located the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html but after a minute of scanning, please someone tell me what the fuck is it talking about? Fuck the Python programing morons. Thanks. I just need to decompress files. Is it: import gzip; gzip.GzipFile("/Users/xah/access_log.1.gz"); can someone put a example into that fucking doc so that people don't have to wade thru whatever fuck it is trying to sound big? For more about Python doc, please see: http://xahlee.org/perl-python/re-write_notes.html Xah xah at xahlee.org ? http://xahlee.org/ From godoy at ieee.org Tue Aug 2 07:09:09 2005 From: godoy at ieee.org (Jorge Godoy) Date: Tue, 02 Aug 2005 08:09:09 -0300 Subject: Dabo in 30 seconds? References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <8ur1s2-r5t.ln1@strongwill.g2ctech> <3l7dl2F111tulU1@uni-berlin.de> Message-ID: Daniel Dittmar wrote: > Because you put different probabilities on different outcomes. One easy > 'risk markup' would be to assume that parts of the standard Python > distribution like TkInter have a higher chance of working with the next > release than external libraries like wxPython. Of course, there are lots I think it will be true only if there's no package for the considered toolkit on my Linux distribution, *BSD, Windows or Mac. I don't see it as a risk because having the toolkit available on the destination platform is a pre-requisite and comes before coding. If I already have the code working on some version, backwards compatibility handles a little of the problem and besides, I can create one new package for the lacking environment. I just need to do this work once. > of other possible criteria: > - which has been under more active development in the last releases > - which source code is easier to understand so that I don't have to rely > on external help - Which takes less time - Which needs less hand written code - Which provides more functionality - Which has data aware controls - ... There are lots of other things that are considered, independently of the toolkit. None gets a "100% OK" grade, and some things have a higher weight to me or to the client. -- Jorge Godoy From deets at nospam.web.de Mon Aug 22 13:51:18 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Aug 2005 19:51:18 +0200 Subject: Running multiple console processes and watching their output In-Reply-To: <43097ddf$1@news.bezeqint.net> References: <43097ddf$1@news.bezeqint.net> Message-ID: <3muhkmF18o689U2@uni-berlin.de> Yoav wrote: > I need to run multiple console apps in the background and to watch their > output. I have no idea if this is possible, and I don't even know where > to start looking. The processes are watchers, meaning that they watch > folders and mail boxes and do operations on items in them . Essentially > these are Java command line programs. What I need is to have them > running and to take a glance at their console output once in a while to > parse it. Is it possible? How? Pyexpect may help - and telling us what platform you are on, too. Diez From lshuai at kaneva.com Mon Aug 8 11:26:59 2005 From: lshuai at kaneva.com (Liu Shuai) Date: Mon, 8 Aug 2005 11:26:59 -0400 Subject: Terminate a thread that doesn't check for events Message-ID: <9CA58FB7E095F146AD3E7FE1E5855929043040@brain.klausatlanta.local> Thank you for the help Chris and Jp. Just wanted to let you know that I re-wrote a "stoppable" version of the function I was calling in the thread instead of forcing the thread to terminate. I think it worth the effort as the solution is now clean and portable. Thanks again for all your input. LS > -----Original Message----- > From: python-list-bounces+sliu=kaneva.com at python.org [mailto:python-list- > bounces+sliu=kaneva.com at python.org] On Behalf Of Chris Lambacher > Sent: Tuesday, August 02, 2005 12:16 PM > To: python-list at python.org > Subject: Re: Terminate a thread that doesn't check for events > > No. On Linux a separate thread is a separate process with shared memory. > You > can send a signal to a particular process and catch that signal as an > indication that you need to terminate (perhapse something that is set up > before running your long running process so that it is generic). In > windows > threads are separate beasts from processes(almost) and there are functions > for > terminating them (though I don't think gracefully). Unfortunately I can't > comment on other platforms. > > -Chris > > On Tue, Aug 02, 2005 at 11:54:57AM -0400, Liu Shuai wrote: > > Thanks for the reply Chris. > > > > Are you suggesting running the task in a *separate* process instead of a > > separate *thread*? Because if that's the case, I will have to share data > > (and possible memory) between that new process and my "master" process > > since they depend on one other. > > > > Yeah I will sure post it if I can find an elegant solution. > > > > Thank you, > > LS > > > > > -----Original Message----- > > > From: Chris Lambacher [mailto:lambacck at computer.org] > > > Sent: Tuesday, August 02, 2005 11:50 AM > > > To: Liu Shuai > > > Subject: Re: Terminate a thread that doesn't check for events > > > > > > Hi, > > > > > > There is no cross platform way to do this. You need to periodically > > check > > > a > > > quit flag, or perform a platform specific action to terminate it. On > > > Linux > > > you can send the process a signal. On windows you will need to use > > the > > > win32all package. If you decide to go the later route, maybe you > > could > > > encapsulate the thread termination code in a module and share it with > > the > > > Python community. > > > > > > -Chris > > > > > > On Tue, Aug 02, 2005 at 09:51:31AM -0400, Liu Shuai wrote: > > > > Can someone please comment on this? > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > ----- > > > > > > > > From: python-list-bounces+sliu=kaneva.com at python.org > > > > [mailto:python-list-bounces+sliu=kaneva.com at python.org] On Behalf > > Of > > > Liu > > > > Shuai > > > > Sent: Monday, August 01, 2005 4:29 PM > > > > To: python-list at python.org > > > > Subject: Terminate a thread that doesn't check for events > > > > > > > > > > > > > > > > Hi all, > > > > > > > > > > > > > > > > I am aware that similar and probably same questions have been > > posted > > > many > > > > times, but I was unable to find a solution after reading a dozen > > > threads > > > > in the archive. So here it goes again. > > > > > > > > > > > > > > > > I have a thread that does some heavy task (hash calculation, for > > > > instance). I need a mechanism that works *across platforms* to > > stop > > > that > > > > calculation if user decides to exit. How can I do that? > > > > > > > > I can not do the standard "periodical checking" way since there > > is > > > only > > > > one function/step call in my thread. > > > > > > > > > > > > > > > > Here is a snippet of my thread classes to help illustrate the > > > problem: > > > > > > > > > > > > > > > > class Dispatcher(): > > > > > > > > def __init__(self): > > > > > > > > self.__worker = Worker() > > > > > > > > > > > > > > > > def start(self): > > > > > > > > self.__worker.start() > > > > > > > > > > > > > > > > def stop(): > > > > > > > > #how do i stop the worker? > > > > > > > > > > > > > > > > class Worker(threading.Thread): > > > > > > > > def __init__(self): > > > > > > > > > > > > > > > > def run(self): > > > > > > > > oneTimeConsumingCall() > > > > > > > > > > > > > > > > > > > > > > > > Thank you in advance for any suggestions/pointers. > > > > > > > > > > > > > > > > LS > > > > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list From look-on at mindprod.com.invalid Thu Aug 11 23:16:37 2005 From: look-on at mindprod.com.invalid (Roedy Green) Date: Fri, 12 Aug 2005 03:16:37 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <8j4of1t3h7cvuc6s0svvreu971peeh9qc7@4ax.com> On 11 Aug 2005 18:23:42 -0700, "Xah Lee" wrote or quoted : >The Jargons of >marketing came from business practice, and they can be excusable >because they are kinda a necessity or can be considered as a naturally >evolved strategy for attracting attention in a laissez-faire economy >system. Jargon is a name that hides what it does. The idea is those in the know can sound much more intelligent than they really are. In Java you have the JDK -- Java Development Kit. That is a pretty clear name for what it is. You have the JRE the Java Runtime Environment. I might have shortened it to Java Base. Oak, Tiger, Dragonfly etc are internal codenames. They are really nobody's business but Sun's. You have JAF -- Java Activation Framework. Now that's jargon. You have no idea knowing its name what it is for. JMF Java Media Framework could have been shortened to Java Media. JavaMail is pretty clear. Java Web Start is self-explanatory. Perhaps Java Web Launch would be a tiny bit clearer. J2EE Java 2 Enterprise Edition. The 2 is a lot of Bullshit. Sun marketing people keep trying to screw with the logical progression of version numbers. The edition says nothing, and the Enterprise gives you a hint this is not for hobbyist programmers. J2SE Java 2 Standard Edition. This is needlessly wordy. they could have called it Standard Java. If you use short names then you don't need acronyms. Without acronyms, names can be self-explanatory. I think your beef is not with Jargon, but with so many acronyms. From bill.pursell at gmail.com Thu Aug 11 02:39:38 2005 From: bill.pursell at gmail.com (bill) Date: 10 Aug 2005 23:39:38 -0700 Subject: signals (again) In-Reply-To: <7x8xz9s1nl.fsf@ruckus.brouhaha.com> References: <1123713622.727375.206270@f14g2000cwb.googlegroups.com> <7x8xz9s1nl.fsf@ruckus.brouhaha.com> Message-ID: <1123742378.503574.51240@g49g2000cwa.googlegroups.com> How does that help? I interpret "use asynchronous calls" to mean "use fcntl to set an FN_NOTIFY on the directory in order to be alerted when something needs to be done." But the method of doing that which I outlined above has a critical section in which the incoming signal will not be noticed. All of the solutions I can think of for getting around it involve a lot of acrobatics that I'm fairly certain aren't necessary, and more to the point I don't think they actually solve the problem. There is always a section in which the signal arrives just before the pause, so it doesn't wake us up out of the pause as it is intended to. We can set globals in the signal handler, and then check them right before the pause, but if they get set after we check, then we're hosed. I was hoping that perhaps the following code might be atomic: if notify_occurred or signal.pause(): but I'm almost certain that it's not. The problem is localized, so I don't see how invoking a seperate thread is useful. Could you elaborate on how you think that will help? From martin at v.loewis.de Thu Aug 25 18:28:49 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 26 Aug 2005 00:28:49 +0200 Subject: pre-PEP: Object-oriented file module In-Reply-To: References: Message-ID: <430e4621$0$16867$9b622d9e@news.freenet.de> Kenneth McDonald wrote: > I'd like to propose a new PEP [no, that isn't a redundant 'process' in > there :-)--pre-PEP is a different process than PEP], for a standard > library module that deals with files and file paths in an object > oriented manner. I believe this module should be included as part of > the standard Python distribution. See the discussions at http://python.org/sf/1226256 http://mail.python.org/pipermail/python-dev/2005-June/054439.html http://mail.python.org/pipermail/python-dev/2005-July/054535.html I'd be personally curious as to how you would be dealing with Unicode file names. How to access file attributes is also an interesting question (e.g. how to find out whether it is a symlink, whether it is a hidden file, what the POSIX ACL is, and what the 8.3 short name is) Regards, Martin From u.hobelmann at web.de Mon Aug 29 04:09:09 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Mon, 29 Aug 2005 10:09:09 +0200 Subject: Writing portable applications In-Reply-To: <86acj1y8mr.fsf@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> <3ndociF11gd3U1@individual.net> <86acj1y8mr.fsf@bhuda.mired.org> Message-ID: <3nfu55F19ui5U1@individual.net> Mike Meyer wrote: > I'm still waiting for an answer to that one - where's the Java toolkit > that handles full-featured GUIs as well as character cell > interfaces. Without that, you aren't doing the job that the web > technologies do. Where is the text-mode browser that would even run part of the web apps I use, like home-banking, all web forums, server configuration interfaces, etc.? I think we should leave both these questions open. (In fact, as to UIs using Java, blech! Haven't seen a really good one...) >>>> I just wonder who wrote fully standards compliant web browsers for >>>> those 90 platforms. >>> Nobody. I doubt there's a fully standards compliant web browser >> Nobody, huh? Then how could you run just ANY web application on those >> platforms? > > The same way you write POSIX applications in the face of buggy > implementations - by working around the bugs in the working part of > the implementation, and using conditional code where that makes a > serious difference. But as soon as some user of platform 54 tries your website, she'll encounter some weird behavior without even knowing why. And maybe so will you, especially if you don't have that platform there for testing. I don't understand how this web thing changes anything... With POSIX at least you have a real bug-report for the guy responsible for it. If a platform keeps being buggy, with no fixes coming, screw them. Every user will see that sooner or later, and these platforms die. Even Windows is quite stable/reliable after 10+ years NT! >>> available for *any* platform, much less any non-trivial collection of >>> them. You write portable web applications to the standards, and design >>> them to degrade gracefully. Then you go back and work around any new >> Oh right, they degrade gracefully. So without Javascript or cookies >> (the former is often not implemented) you get a HTML page with an >> error notice -- if you're lucky. > > You left off the important part of what I had to say - that the > application be written by a moderately competent web author. But if you can cater for all kinds of sub-platforms, then why not just provide a CLI as well as those GUI interfaces, when we're duplicating work to begin with? ;) If it doesn't run without JS, then you lock out 90% of all alive platforms (and maybe 1% of all alive users :D) anyway. >> A server AND client for a simple protocol designed for its task >> (i.e. not FTP for instance) can be implemented in much less work than >> even designing even part of a web application backend that does that >> kind of stuff. > > Well, if it that easy (and web applications are dead simple), it > should be done fairly frequently. Care to provide an example? We have all the web standards, with various extensions over the years. Some FTP clients even don't crash if they see that some server doesn't yet support the extension from RFC XY1234$!@. Then there's tons of inter-application traffic in XML already, growing fast. Then there are s-expressions (Lisp XML if you want). Then probably thousands of ad-hoc line-based text protocols, but I don't know how well they can be extended. There's CORBA. Most web standards are simple, at least if you would subtract the weird stuff (and IMHO there should be new versions of everything with the crap removed). XML is somewhat simple, just hook libxml. There's NNTP. There's RSS. There's Atom. The latter two emerged quite painlessly, even though you could maybe use some website for what they provide. But this way you have lots of clients for lots of platforms already. >>> You think you're done. A lot of developers think you can stop with >>> the >>> first one or two. You're all right for some applications. For others, >>> you're not. Personally, I like applications that run on all the >>> platforms I use - and your set doesn't cover all three of those >>> systems. >> Ok, I'd be interested to hear what those are. VMS, RiscOS, Mac OS 9...? > > FreeBSD, OS X and a Palm Vx. Didn't I say, a GUI for the Mac, for X11, and Windows? That only leaves out the Palm. I heard they aren't too hard to program for, either. But I haven't heard of a really decent browser for pre-OS5 PalmOS (not sure about OS5). >> If a system's scheduler, or select implementation sucks, though, I'd >> complain to the vendor or simply abandon the platform for >> another. Competition is good :) > > Complaining to the vendor doesn't always get the bug fixed. And > refusing to support a platform isn't always an option. Sometimes, you > have to byte the bullet and work around the bug on that platform. Sure, but you can tell your customers that unfortunately their system vendor refuses to fix a bug and ask THEM to ask that vendor. Boy, will they consider another platform in the future, where bugs do get fixed ;) >>> same thing applies to threads, except such code typically includes a >>> third option of not using threads at all. And so on. >> Well, who doesn't do threads after several years of POSIX IMHO can't >> be taken seriously. Ok, the BSDs didn't until recently, but those are >> volunteer projects. > > Not all platforms are POSIX. If you're ok limiting your application to > a small subset of the total number of platforms available, then > there's no advantage to using web technologies. Some of us aren't > satisifed with that, though. Sure. You have to look where your users are. Chances are that with obscure systems they can't use most web-apps either. >>> And we haven't even started talking about the build process... >> If the libraries are installed, just build and link it (if you use >> standard C, POSIX + 3rd party libs that do the same). If not, then >> tough luck -- it couldn't even run in theory then. > > You have to have the right build tool installed. Since you use BSD, > you've surely run into typing "make" only to have it blow up because > it expects gmake. With 3rd party-stuff, yes. The little that I've written yet compiled immediately (with pmake and gmake), except for C99 (the FreeBSD I tried had gcc 2.95 installed). But now I write all C as pre-99 anyway, looks cleaner, IMHO. > Well, marking up text is a pretty poor way to describe a UI - but > anything that is going to replace web technologies has to have a > media-independent way to describe the UI. One of the things that made > the web take off early was that anyone with a text editor could create > web pages. I think that's an important property to keep - you want the > tools that people use to create applications be as portable/flexible > as the applications. Since most GUI's are written in some programming > language or another, and most programming langauges are still flat > text, a GUI description as flat text exists for most GUIs, so this > requirement isn't a handicap. That's true, though I think the future of development lies in overcoming that program-code-as-text thing (NOT visual programming, just tool-based, structured). Smalltalk did it decades ago. > You don't have to guess - finding examples of XUL isn't hard at all. I > think XML gets used in a lot of places where it isn't appropriate. One > of the few places where it is appropriate is where you want a file > format that lots of independent implementations are going to be > reading. This could well be one of those times. Maybe, but for applications that aren't predominantly concerned about text, I'd really rather use a structured data type (like s-expressions), not text markup like XML. For hypertext, XHTML is fine, though, if a bit verbose. [follow-up set to comp.unix.programmer] (I just noticed I replaced my sig with something web-related yesterday. This is pure coincidence :D) -- My ideal for the future is to develop a filesystem remote interface (a la Plan 9) and then have it implemented across the Internet as the standard rather than HTML. That would be ultimate cool. Ken Thompson From benn at cenix-bioscience.com Tue Aug 23 12:02:40 2005 From: benn at cenix-bioscience.com (Neil Benn) Date: Tue, 23 Aug 2005 18:02:40 +0200 Subject: pythonXX.dll size: please split CJK codecs out In-Reply-To: References: Message-ID: <430B48A0.2070707@cenix-bioscience.com> Giovanni Bajo wrote: >Hello, > >python24.dll is much bigger than python23.dll. This was discussed already on >the newsgroup, see the thread starting here: >http://mail.python.org/pipermail/python-list/2004-July/229096.html > >I don't think I fully understand the reason why additional .pyd modules were >built into the .dll. OTOH, this does not help anyone, since: > >- Normal users don't care about the size of the pythonXX.dll, or the number of >dependencies, nor if a given module is shipped as .py or .pyd. They just import >modules of the standard library, ignoring where each module resides. So, >putting more modules (or less modules) within pythonXX.dll makes absolutely no >differences for them. >- Users which freeze applications instead are *worse* served by this, because >they end up with larger programs. For them, it is better to have the highest >granularity wrt external modules, so that the resulting freezed application is >as small as possible. > > > 1.8Mb - life's too short what gain would you get from removing 1Mb from that? So it can get on a floppy? ;-). That would be more effort than is needed, IMHO, even my handy/mobile phone/cell phone can easily cope with 1.8Mb! Neil -- 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 max2 at fisso.casa Tue Aug 23 13:26:38 2005 From: max2 at fisso.casa (max(01)*) Date: Tue, 23 Aug 2005 17:26:38 GMT Subject: pipes like perl Message-ID: hi. in perl i can do this: ... if (open (MYPIPE, "*some_system_command* |")) { ... *do_something* ... while ($answer = ) { print $answer; } ... *do_something_more* ... } else { ... *do_something_else* ... } ... but i do not know how to do it in python, because "if *command*:" gives syntax error. moreover, if i use ... import os ... try: MYPIPE = os.popen("*some_system_command*, "r") ... *do_something* ... for answer in MYPIPE: print answer, MYPIPE.close() ... *do_something_more* ... except: ... *do_something_else* ... ... it doesn't work, since "*do_something*" and *do_something_more* are always executed (it seems like MYPIPE = os.popen("*some_system_command*", "r") does not raise any exception even if *some_system_command* does not exist/work... any help? thanks a lot max From Scott.Daniels at Acm.Org Fri Aug 12 20:06:50 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 12 Aug 2005 17:06:50 -0700 Subject: UCALC equivalent In-Reply-To: References: <42FCDCA7.7030107@syscononline.com> <42fcea4a$1@nntp0.pdx.net> Message-ID: <42fd2def$1@nntp0.pdx.net> Max Erickson wrote: > Scott David Daniels wrote in > news:42fcea4a$1 at nntp0.pdx.net: > > >>max wrote: >> From the web page referenced: >> ... >> cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)") >> << endl; >>The python equivalent: >> ... >> print eval("abc(5) - abc(3,4) * shl(0x0E, 1)") > > Ouch, I sure was wrong. You did such a good job making me look > foolish that it was mentioned in Python-URL!. Sorry, I wasn't trying to make you look foolish. I was trying to nip a misconception in the bud. I also forgot how to convert binary to an integer (the #b01101 above) when I was writing it, so that last line should read: print eval("abc(5) - abc(3,4) * shl(int('01101', 2), 1)") --Scott David Daniels Scott.Daniels at Acm.Org From __peter__ at web.de Thu Aug 4 04:21:26 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Aug 2005 10:21:26 +0200 Subject: Py: a very dangerous language References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> Message-ID: Tom Anderson wrote: > On Mon, 1 Aug 2005, Peter Otten wrote: > >> Harald Massa wrote: >> >>> Always go to bed exactly when you want to write the first lambda. >> >> Eureka. The Twentieth Pythonic Thesis has finally surfaced. > > So what does it mean that i do much of my programming in bed? You may want to discuss the implications with your therapist. Ain't got one? Look here: http://www.jezuk.co.uk/cgi-bin/view/eliza :-) Peter From belred at gmail.com Mon Aug 22 21:50:57 2005 From: belred at gmail.com (Bryan) Date: Mon, 22 Aug 2005 18:50:57 -0700 Subject: Python Light Revisted? In-Reply-To: References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: > Someone recently produced a distribution capable of running from a CD > and designed to make it easy to use Python on machines where it wasn't > actually installed. That might be a useful starting point too, but I > can't find the right incantation to get Google to bring it up. > > regards > Steve steve, are you thinking about moveable python? http://www.voidspace.org.uk/python/movpy/ bryan From mwh at python.net Mon Aug 15 11:58:09 2005 From: mwh at python.net (Michael Hudson) Date: Mon, 15 Aug 2005 15:58:09 GMT Subject: __del__ pattern? References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: "Chris Curvey" writes: > I need to ensure that there is only one instance of my python class on > my machine at a given time. I recommend modifying your requirements such that you ensure that there is only one "active" instance of your class at any one time (or something like that), and then use try:finally: blocks to ensure your locks get removed. > Is there a better pattern to follow than using a __del__ method? I > just need to be absolutely, positively sure of two things: > > 1) There is only one instance of my special class on the machine at a > time. > 2) If my special class is destroyed for any reason, I need to be able > to create another instance of the class. As another poster mentioned, you also need to work out what you're going to do if your process gets killed in a way that doesn't allow finally blocks to run (this doesn't have much to do with Python). Cheers, mwh -- The above comment may be extremely inflamatory. For your protection, it has been rot13'd twice. -- the signature of "JWhitlock" on slashdot From polytechnique at gmail.com Tue Aug 30 11:16:14 2005 From: polytechnique at gmail.com (DENG) Date: 30 Aug 2005 08:16:14 -0700 Subject: how to join two Dictionary together? In-Reply-To: References: Message-ID: <1125414974.636879.251180@g43g2000cwa.googlegroups.com> thanks all!! update is very useful! From gperetti at abqjournal.com Mon Aug 15 17:03:56 2005 From: gperetti at abqjournal.com (Greg Peretti) Date: Mon, 15 Aug 2005 15:03:56 -0600 Subject: Resetting modification time Message-ID: <17D802AA-0DD0-11DA-A612-000D93C45AAA@abqjournal.com> I'm new to Python and would appreciate being pointed in the right direction. I'm trying to create a simple script that would note the modification time of a file, perform some changes to the file and then reset the modification time to the pre-change time. The area I'm having difficulty with is the resetting the modification time. According to the O'Reilly book I have, using utime in this way - os.utime(testfile, (1124137226, 1124137227)) (those are just sample numbers) - would do so, but I'm generating an OSError. Any Ideas? Greg Peretti web developer www.abqjournal.com (505) 823-3888 ----------------------------------------------------------------- ----------------------------------------------------------------- "Enjoy every sandwich." ?Warren Zevon "If you ever drop your keys into a river of molten lava, let 'em go, because, man, they're gone." ?Jack Handey -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 958 bytes Desc: not available URL: From ironfroggy at gmail.com Wed Aug 10 13:05:32 2005 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 10 Aug 2005 13:05:32 -0400 Subject: Does any one recognize this binary data storage format In-Reply-To: <11fk0kg65rtfn72@corp.supernews.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> <42f98255@news.eftel.com> <11fk0kg65rtfn72@corp.supernews.com> Message-ID: <76fd5acf05081010059711b8e@mail.gmail.com> On 8/10/05, Grant Edwards wrote: > On 2005-08-10, John Machin wrote: > > >>>>Perhaps the one bit is an exponent -- some kind of floating point > >>>>based format? That matches the doubling of all digits. > >>> > >>>That would just be sick. I can't imagine anybody on an 8-bit > >>>CPU using FP for a phone number. > > >> >>> double_binary_lehex_to_double('000000806a6e4941') > >> 3333333.0 > >> >>> double_binary_lehex_to_double('000000806a6e5941') > >> 6666666.0 > >> >>> double_binary_lehex_to_double('0000108777F9Fc41') > >> 7777777777.0 > >> > >> ;-) > > > > Well done, Scott & Bengt!! > > I've just verified that this works with all 12 corrected examples posted > > by the OP. > > > > Grant, MS-DOS implies 16 bits at least; > > You're right. For some reason I was thinking you had said CP/M. > > > and yes there was an FPU (the 8087). > > I never met an MS-DOS box that had an 8087 (though I did write > firmware for an 8086+8087 fire-control computer once upon a > time). > > > And yes there are a lot of sick people who store things as > > numbers (whether integer or FP) when the only arithmetic > > operations that can be applied to them stuff them up mightily > > (like losing leading zeroes off post-codes, having NEGATIVE > > tax file numbers, etc) and it's still happening on the best > > OSes and 64-bit CPUS. Welcome to the real world :-) > > I've been in the real world for a long time, and the dumb > things people (including myself) do still surprise me. > > -- > Grant Edwards grante Yow! Hello, GORRY-O!! I'm > at a GENIUS from HARVARD!! > visi.com > -- > http://mail.python.org/mailman/listinfo/python-list > Original Poster should send this off to thedailywtf.com From MrJean1 at gmail.com Thu Aug 25 16:38:24 2005 From: MrJean1 at gmail.com (MrJean1) Date: 25 Aug 2005 13:38:24 -0700 Subject: Suppressing checking of modules with pychecker In-Reply-To: <1124996320.482701.26660@o13g2000cwo.googlegroups.com> References: <1124996320.482701.26660@o13g2000cwo.googlegroups.com> Message-ID: <1125002303.986168.184380@z14g2000cwz.googlegroups.com> FWIIW, We use PyChecker all the time with Python files using importing wx plus wx.grid or wx.stc, etc. and the run times vary between 5 and 15 seconds. This is Python 2.4 with wxPython 2.4.2.4 and RedHat Fedora Core 2 Linux running on a 1.2 GHz Pentium 4 M laptop. /Jean Brouwers From rkern at ucsd.edu Fri Aug 5 11:50:11 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 05 Aug 2005 08:50:11 -0700 Subject: Passing a variable number of arguments to a wrapped function. In-Reply-To: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> References: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> Message-ID: stephen at theboulets.net wrote: > Is there a better way of doing this so that I don't have to go through > every permutation of possible arguments (the example here from the > matplotlib 'plot' function): Usually, you would just make the defaults for linecolor and linewidth the same as the defaults for the underlying function. matplotlib.pylab functions, however, have too much intelligence coded in them for this to be easy. -- 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 steve at holdenweb.com Sat Aug 27 23:37:43 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Aug 2005 23:37:43 -0400 Subject: Experience regarding Python tutorials? In-Reply-To: <17169.12062.87650.520472@roam.psg.com> References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <1125072815.753219.62420@g47g2000cwa.googlegroups.com> <17169.12062.87650.520472@roam.psg.com> Message-ID: Randy Bush wrote: >>There is also a python tutor newsgroup at gmane >>(gmane.comp.python.tutor). > > > is there a mailing list to which it is gated? > > randy > It's actually primarily a mailing list (tutor-list at python.org, IIRC). See http://mail.python.org/mailman/listinfo/tutor regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From fperez.net at gmail.com Tue Aug 30 18:30:32 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Tue, 30 Aug 2005 16:30:32 -0600 Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk> <4314ce74$0$18648$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > Madhusudan Singh wrote: > >> Hi >> >> I am using time.clock() to get the current time of the processor in >> seconds. For my application, I need really high resolution but currently >> seem to be limited to 0.01 second. Is there a way to specify the >> resolution (say 1-10 microseconds) ? My processor is a 1.4 MHz Intel >> processor. Surely, it should be able to report times a few (or at least >> 10) microseconds apart. >> >> Thanks. > > Correcting a typo (1.4GHz, not 1.4 MHz). > > And I am using Linux. Then, this may be handy to give you an idea of the resolution you can expect at the python level (i.e., without writing extension code). Feel free to add fancier statistics if you actually need them: planck[python]> cat tdelta.py #!/usr/bin/env python """quick and dirty test for time deltas. Under Linux, this is best done using time.time() instead of time.clock()""" import commands from time import time npts = 50 times = [-(time()-time()) for i in xrange(npts)] print commands.getoutput('egrep "MHz|model name" /proc/cpuinfo') print 'Min. time delta :',min(times),'s' print 'Max. time delta :',max(times),'s' print 'Avg. time delta :',sum(times)/float(npts),'s' print 'Num. of timings :',npts # For example, on my system: planck[python]> ./tdelta.py model name : Intel(R) Pentium(R) 4 CPU 2.80GHz cpu MHz : 2794.365 Min. time delta : 2.86102294922e-06 s Max. time delta : 9.05990600586e-06 s Avg. time delta : 3.38554382324e-06 s Num. of timings : 50 Cheers, f From fakeaddress at nowhere.org Thu Aug 11 12:08:28 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 11 Aug 2005 16:08:28 GMT Subject: zipfile library - problem.. In-Reply-To: References: Message-ID: <0KKKe.1762$dk5.188@newssvr21.news.prodigy.com> Renzo wrote: > Renzo ha scritto: > > I've seen that the error is a known bug: > > "zipfile still has 2GB boundary bug" > > > so I've used the module TarFile instead ZipFile, and now the script > works perfectly. Thanks; good to know. Looks like people are working on this Python library bug. Next after that, we'll need to fix the zip format. The 4GB limit on contained files and 256TB limit on archives both looked astronomical at the time they were defined. Sorry to sound like an old guy, but wow, how times change. Incidentally, since your files are jpegs, they're already compressed, and thus TarFile should be just as good as ZipFile anyway. -- --Bryan From stevena at neosynapse.net Mon Aug 1 21:18:30 2005 From: stevena at neosynapse.net (Steven Arnold) Date: Mon, 1 Aug 2005 21:18:30 -0400 Subject: JOB: Python/web developer/network contract Message-ID: Neosynapse Inc is seeking an experienced Python developer for a short- term engagement with a new Neosynapse government customer. The task will require 5-7 years of overall programming experience; at least two years of Python experience; experience writing web applications; and a good basic knowledge of networks, including routers, IP blocks, firewalls, etc. Knowledge of and experience with protocols such as SNMP will be a big plus. Many of the hosts to be monitored will run on Windows; hence an understanding of Windows and Perfmon will also be helpful. The right candidate will be someone who is comfortable learning new things on the fly, using resources such as google, books and occasional customer contacts. Among other things, you will use and modify a tool provided by Neosynapse, written in Python, that will test a web application for correctness and load; and you will author a web-based dashboard that will indicate the health and welfare of the application. This position is contract-only and is located in Washington, DC. All work for this engagement is performed on-site. This position could lead to further work with our customer, or to other contract work with Neosynapse; we value skilled programmers and usually have plenty to do. Please send resumes directly to me at stevena at neosynapse.net. I can read PDF, text, web/html, or, yes, Word format. Thanks, steve From wolfgang.keller.nospam at gmx.de Wed Aug 17 04:57:24 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Wed, 17 Aug 2005 10:57:24 +0200 Subject: Python as VBA replacement under Windows? Message-ID: Hello, this is a potentially veeery dumb question, but: - If an application supports VBA as a macro language, - and if you can execute Python code from within a VBA script (how?) - and if the application exposes its VBA scripting interface through COM then it should be perfectly possible to entirely replace VBA in nearly all Windows applications with Python, right? TIA, sincerely, Wolfgang Keller From greg at puyo.cjb.net Mon Aug 22 05:43:25 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 22 Aug 2005 02:43:25 -0700 Subject: while c = f.read(1) In-Reply-To: <1124431651.152721@yasure> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: <1124703805.178363.145870@g49g2000cwa.googlegroups.com> Donn Cave wrote: > Actually I'd make it a little less compact -- put the "break" > on its own line -- but in any case this is fine. It's a natural > and ordinary way to express this in Python. > > ... > | But I get a syntax error. > | > | while c = f.read(1): > | ^ > | SyntaxError: invalid syntax > | > | And read() doesn't work that way anyway because it returns '' on EOF > | and '' != False. If I try: > > This is the part I really wanted to respond to. Python managed > without a False for years (and of course without a True), and if > the introduction of this superfluous boolean type really has led > to much of this kind of confusion, then it was a bad idea for sure. Sorry that was patently untrue - as far as the while loop is concerned '' and False both cause the loop to exit so for all intents and purposes, in that context, '' may as well equal False. I think True and False constants are a good idea. And I like the way it worked. The reason I got confused though was because I cannot do this: while c = f.read(1): # ... > The condition that we're looking at here, and this is often the > way to look at conditional expressions in Python, is basically > something vs. nothing. In this and most IO reads, the return > value will be something, until at end of file it's nothing. > Any type of nothing -- '', {}, [], 0, None - will test "false", > and everything else is "true". Of course True is true too, and > False is false, but as far as I know they're never really needed. I'm all in favour of logic that looks like: if '' or 0 or {} or None: # never gets done else: # always gets done My confusion stems from the syntax error not from Python's boolean logic. Sorry, my statement at the end regarding '' != False was a bit of a red herring. :\ I'm also in the habit of doing things like this: def f(dict=None): dict = dict or {} # ... > You are no doubt wondering when I'm going to get to the part where > you can exploit this to save you those 3 lines of code. Sorry, > it won't help with that. Ah but if it helps me to understand why Python forces me to do it then although it won't save 3 lines it will stop me from complaining and posting naff newbie questions. ;) > | Is this related to Python's expression vs. statement syntactic > | separation? How can I be write this code more nicely? > > Yes, exactly. Don't worry, it's nice as can be. If this is > the worst problem in your code, you're far better off than most > of us. Okay well that is reassuring but a little disappointing. Are there any plans (PEPs?) in the distant future to unify statements and expressions in the Python syntax so I can generally do things like this: x = if aboolean: else: and while c = f.read(1): # ... I couldn't find any general PEPs along these lines, only specific ones (e.g. 308 re. an if-then-else expression). It does seem quirky given Python's indentation syntax. :( However I notice I can already do some things I wouldn't expect given a strict statement/expression separation, such as: x = y = z = 0 I suppose I have to learn these as special cases. (?) From aahz at pythoncraft.com Mon Aug 8 11:53:30 2005 From: aahz at pythoncraft.com (Aahz) Date: Mon, 8 Aug 2005 08:53:30 -0700 Subject: BayPIGgies: August 11, 7:30pm (Ironport) Message-ID: <20050808155330.GA8821@panix.com> The next meeting of BayPIGgies will be Thurs, August 11 at 7:30pm at Ironport. Hasan Diwan will present RRsR, a web-based RSS reader written using feedparser and python CGI. This is expected to be a short presentation; afterward, anyone who was at OSCON is invited to summarize what they saw/heard. BayPIGgies meetings alternate between IronPort (San Bruno, California) and Google (Mountain View, California). For more information and directions, see http://www.baypiggies.net/ Before the meeting, we plan to meet at 6pm for dinner. Discussion of dinner plans is handled on the BayPIGgies mailing list. This week will probably be at Creperie du Monde, six long blocks from IronPort (i.e., walking distance). Advance notice: The September 8 meeting agenda has not been set. Please send e-mail to baypiggies at baypiggies.net if you want to suggest an agenda (or volunteer to give a presentation). We already have a speaker for October. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From steve at holdenweb.com Mon Aug 22 21:18:28 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 21:18:28 -0400 Subject: Best way to 'touch' a file? In-Reply-To: References: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Message-ID: Peter Hansen wrote: > Fredrik Lundh wrote: > >>Peter Hansen wrote: >> >>>I guess it depends on whether "touch" implies creation-when-missing, as >>>with the command line version, or just updating the time. >> >>the OP wanted "to update the modification time of a file without actually >>modifying it". os.utime does exactly that; no more, no less, and no extra >>dependencies. > > > You've quoted selectively. He also said "Unix-style 'touch'", from > which one could quite legitimately infer he wants the other features of > the Unix touch command, including the automatic creation of missing files. > > Unless you know something more about the OP's needs than he's posted > publicly, you're just guessing too... even if we both agree yours is the > more likely interpretation. > Which we probably all can. It's a right bugger when you actually have to listen to what the customer wants, innit? ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From martin.witte at gmail.com Fri Aug 12 11:05:11 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 12 Aug 2005 08:05:11 -0700 Subject: Python's Exception, and Capitalization In-Reply-To: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> References: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> Message-ID: <1123859111.669622.259010@z14g2000cwz.googlegroups.com> For youtr try, except, finally: you can construct something like this: try: try: print 'egg' + 1 except ValueError, e: print e finally: print 'spam' It results in: py> spam Traceback (most recent call last): File "C:/Martin/test.py", line 3, in -toplevel- print 'egg' + 1 TypeError: cannot concatenate 'str' and 'int' objects py> If you catch the TypeError you get: try: try: print 'egg' + 1 except TypeError, e: print e finally: print 'spam' py> cannot concatenate 'str' and 'int' objects spam py> From gry at ll.mit.edu Fri Aug 19 11:45:57 2005 From: gry at ll.mit.edu (gry at ll.mit.edu) Date: 19 Aug 2005 08:45:57 -0700 Subject: Newbie Question In-Reply-To: References: Message-ID: <1124466357.866401.243000@z14g2000cwz.googlegroups.com> Yes, "eval" of data from a file is rather risky. Suppose someone gave you a file containing somewhere in the middle: ... 22,44,66,88,"asd,asd","23,43,55" os.system('rm -rf *') 33,47,66,88,"bsd,bsd","23,99,88" ... This would delete all the files in your directory! The csv module mentioned above is the tool of choice for this task, especially if there are strings that could contain quotes or commas. Doing this right is not at all easy. If you really want to roll your own, and the data is KNOWN to be fixed and very restricted, you can do something like: "myfile" contains: 13,2,'the rain',2.33 14,2,'in spain',2.34 for l in open('myfile'): x,y,comment,height = l.split(',') x=int(x) y=int(y) height=int(height) comment=comment.strip("' ") # strip spaces and quotes from front and back but beware this will break if the comment contains commas. -- George From fredrik at pythonware.com Tue Aug 16 08:43:50 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 16 Aug 2005 14:43:50 +0200 Subject: looping list problem References: Message-ID: Jon Bowlas wrote: > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > hiddennavelements = navstring.split(' ') > for hiddennavelement in hiddennavelements: > return hiddennavelement > > So the script 'get_attobject' basically looks for an instance of the > attributes object in the current folder, if it doesn't locate one then it > uses acquisition to find one in a parent folder. The script > 'get_uclattribute' then gets the nodeValues of the requested node. In this > instance its ucl_navhide, then I split the 'navstring' string at the spaces > and attempt the for-loop to output each of the values. > > Unfortunately it appears I am unable to loop through each of the list items > in hiddennavelements, as it only returns the first value & will not repeat. did you perhaps mean to use "yield" instead of "return" ? From eqcank at yahoo.co.id Sun Aug 21 22:16:14 2005 From: eqcank at yahoo.co.id (Trian Diarsa) Date: Mon, 22 Aug 2005 09:16:14 +0700 (ICT) Subject: Problem with wxPython 2.6.1 Message-ID: <20050822021614.52575.qmail@web33903.mail.mud.yahoo.com> can you explain about your problem ? > --- Mario Lacunza menulis: > > > Hello! > > > > Im newbie in Linux, I have instaled Ubuntu 5.04, > but > > I couldt install > > the wxPython 2.6.1, anybody help me?? > > > > For this reason I dont do my Job , because I use > > SpeIde and Boa > > Constructor, and both dont run with the old v > > wxPython 2.5.3 > > > > Thanks in advance!! > > > > -- > > Saludos / Best regards > > > > Mario Lacunza > > Desarrollador de Sistemas - Webmaster > > Email: mario.lacunza at gmail.com > > Email: mario_lacunza at yahoo.es > > Messenger MSN: mario_lacunza at hotmail.com > > Website: http://www.lacunza.tk > > Lima - Peru > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > ________________________________________________________ > > Apakah Anda Yahoo!? > Sekarang dengan penyimpanan 1GB > http://id.mail.yahoo.com/ > ________________________________________________________ Apakah Anda Yahoo!? Sekarang dengan penyimpanan 1GB http://id.mail.yahoo.com/ From lbates at syscononline.com Tue Aug 16 12:56:41 2005 From: lbates at syscononline.com (Larry Bates) Date: Tue, 16 Aug 2005 11:56:41 -0500 Subject: class-call a function in a function -problem In-Reply-To: References: Message-ID: <43021AC9.5000103@syscononline.com> Try something like: class ludzik: # # Define an __init__ method that gets called when # you instantiate the class. Notice also that I've # allowed you to set x, and y parameters if you like. # If you don't pass them they default to 1 and 2 as # in your example. # def __init__(self, x=1, y=2) # # Create 3 attributes (x, y, a). Note that I changed # your attribute named 'l' to 'a' because it conflicts # with your method named 'l'. # self.x=x self.y=y self.a=0 return def l(self): # # Class attributes are referred to by self. # self.a=self.x+self.y print "In ludzik.l a=',self.a return def ala(self): print "In ludzik.ala x=",self.x print "In ludzik.ala y=",self.y # # To refer to one of my own methods you use self. # self.l() return wierus wrote: > Hello, i have a problem. I write my first class in python so i'm not a > experience user. I want to call a function in another function, i tried to > do it in many ways, but i always failed:( > I supposed it's sth very simple but i can't figure what it is: > ================================== > class ludzik: > x=1 > y=2 > l=0 > def l(self): > ludzik.l=ludzik.x+ludzik.y > print ludzik.l > > def ala(self): > print ludzik.x > print ludzik.y > ludzik.l() > > > z=ludzik() > z.ala() > ==================================== > > > k.py > 1 > 2 > Traceback (most recent call last): > File "k.py", line 17, in ? > z.ala() > File "k.py", line 14, in ala > ludzik.l() > TypeError: unbound method l() must be called with ludzik instance as > first argument (got nothing instead) > > > i would be gratefull for resolving this problem for me.... > > > From max at alcyone.com Tue Aug 9 21:57:39 2005 From: max at alcyone.com (Erik Max Francis) Date: Tue, 09 Aug 2005 18:57:39 -0700 Subject: Recommendations for CVS systems In-Reply-To: <861x52lg10.fsf@bhuda.mired.org> References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Perforce. it costs money, but it's worth it. My current client uses > subversion, and I generally wind up cursing at it at least once a > day. Perforce is much smarter about merges and dealing with > branches. Also, if you like using Unix tools to do things like search > your sources or build tags files, Perforce doesn't leave turds in your > development tree. It also is free for personal use (up to 2 clients, 2 users) and open soruce projects can get free licenses. Or at least it was so the last I checked. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis The only way to get rid of a temptation is to yield to it. -- Oscar Wilde From nicolas.riesch at genevoise.ch Tue Aug 23 02:22:50 2005 From: nicolas.riesch at genevoise.ch (nicolas_riesch) Date: 22 Aug 2005 23:22:50 -0700 Subject: COM access sooo slow !? In-Reply-To: <4301834a$0$15576$8fcfb975@news.wanadoo.fr> References: <1123956653.745700.220980@g49g2000cwa.googlegroups.com> <4301834a$0$15576$8fcfb975@news.wanadoo.fr> Message-ID: <1124778170.262592.290450@z14g2000cwz.googlegroups.com> I also use Python to access database on Windows. You can speed up your program by doing that: Open PythonWin, then click on the "Tools" menu and the item "COM Makepy Utility". It will display all libraries available. Then, select "Microsoft ActiveX Data Objects 2.7 Library" or whatever last version of ADO you have. You just need to do it once, as it registers the objects of the library in the registry ( I think. I don't completely understand the mechanism. ) If you use another library, do the same thing with the library you use. From bryanjugglercryptographer at yahoo.com Tue Aug 16 18:51:27 2005 From: bryanjugglercryptographer at yahoo.com (bryanjugglercryptographer at yahoo.com) Date: 16 Aug 2005 15:51:27 -0700 Subject: __del__ pattern? In-Reply-To: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: <1124232686.973363.317640@z14g2000cwz.googlegroups.com> Chris Curvey wrote: > I need to ensure that there is only one instance of my python class on > my machine at a given time. (Not within an interpreter -- that would > just be a singleton -- but on the machine.) These instances are > created and destroyed, but there can be only one at a time. > > So when my class is instantiated, I create a little lock file, and I > have a __del__ method that deletes the lock file. Unfortunately, there > seem to be some circumstances where my lock file is not getting > deleted. Then all the jobs that need that "special" class start > queueing up requests, and I get phone calls in the middle of the night. For a reasonably portable solution, leave the lock file open. On most systems, you cannot delete an open file, and if the program terminates, normally or abnormally, the file will be closed. When the program starts, it looks for the lock file, and if it's there, tries to delete it; if the delete fails, another instance is probably running. It then tries to create the lock file, leaving it open; if the create fails, you probably lost a race with another instance. When exiting cleanly, the program closes the file and deletes it. If the program crashes without cleaning up, the file will still be there, but a new instance can delete it, assuming permissions are right. There are neater solutions that are Unix-only or Windows-only. See BranzoZ's post for a Unix method. -- --Bryan From ajartaknev at gmail.com Tue Aug 16 10:52:05 2005 From: ajartaknev at gmail.com (Ajar) Date: 16 Aug 2005 07:52:05 -0700 Subject: open links in a html page Message-ID: <1124203925.920385.209450@f14g2000cwb.googlegroups.com> Hi, Using urllib2,ClinetForm and ClinetCookie modules I have logged into my ISPs web site and managed to fetch the first page. Now, on this page there is this link: Service Records I need to click this link from python code. How do I do it? check(4) is the following javascript function: ------------------------------------------------------------------------------- function check(parameter){ if(parameter==1){ parent.frames(0).location.href="userinfo.jsp" + "?" + new Date().toString(); }else if(parameter==2){ parent.frames(0).location.href="modipswd.jsp" + "?" + new Date().toString(); }else if(parameter==3){ parent.frames(0).location.href="cardrecharge.jsp" + "?" + new Date().toString(); }else if(parameter==4){ parent.frames(0).location.href="serviceRecords.jsp" + "?" + new Date().toString(); }else if(parameter==5){ parent.frames(0).location.href="rateSelectResult.jsp" + "?" + new Date().toString(); } else if(parameter==6){ parent.frames(0).location.href="stopService.jsp" + "?" + new Date().toString(); } else if(parameter==7){ if (confirm("Are you sure to exit?")){ window.location="../logout.jsp"; return true; }else{ return false; } }else if(parameter==8){ parent.frames(0).location.href="cancelService.jsp" + "?" + new Date().toString(); }else{ return false; } From davefickbohm at yahoo.com Wed Aug 31 18:28:22 2005 From: davefickbohm at yahoo.com (David Fickbohm) Date: Wed, 31 Aug 2005 15:28:22 -0700 (PDT) Subject: To Python List Moderator Message-ID: <20050831222822.85607.qmail@web80012.mail.yahoo.com> Can you please remove me from the list starting tomorrow I am going an a weeks vacation. I do not want people to get the "Dave Fickbohm is out of the office" message over and over If I could be reinstated as of 9/12/05 it would be appreciated. Thanks Dave Dave Fickbohm Use Technology to the Fullest 1250 45th st suite 200 Emeryville, CA, 94608 510 594 4151 voice -------------- next part -------------- An HTML attachment was scrubbed... URL: From kenneth.m.mcdonald at sbcglobal.net Sun Aug 21 12:56:59 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Sun, 21 Aug 2005 11:56:59 -0500 Subject: Best way to 'touch' a file? Message-ID: <1378C457-DCBF-4C3B-B33E-0FAC6439DF25@sbcglobal.net> I could've sworn python had such a command, but now I can't find it... I'm looking for an easy way to perform a UNIX-style "touch", to update the modification time of a file without actually modifying it. I could do something (I imagine) like opening the file for appending and then immediately closing it, but that doesn't seem like a good idea--what if the file is already open for reading or writing? Anyone know of a nice, elegant solution? Thanks, Ken From hancock at anansispaceworks.com Tue Aug 23 23:49:24 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 23 Aug 2005 22:49:24 -0500 Subject: Doubt C and Python In-Reply-To: <430b0872$0$21931$db0fefd9@news.zen.co.uk> References: <430b0872$0$21931$db0fefd9@news.zen.co.uk> Message-ID: <200508232249.25164.hancock@anansispaceworks.com> On Tuesday 23 August 2005 06:28 am, Will McGugan wrote: > praba kar wrote: > > I want to know the link between c and python. > > Some people with C background use Python instead > > of programming in C.why? For the same reason that people acquainted with assembly language nevertheless chose to write software in C. It is a higher level language. That generally translates to: 1) Gettng much more done in much less time. 2) Being able to think about the problem at a more abstract level, and not getting befuddled with trivia. 3) Fewer bugs (there is a claim that bugs are directly proportional to lines of code, so that any language that allows you to get the job done with fewer LOC will also allow you to do it with fewer bugs). 4) The result is usually slower and bulkier, being less hand optimized. 1,2, & 3 are definitely advantages. 4 is a disadvantage, but there are reasons not to worry about it: * CPU time and memory progress rapidly enough that wasting expensive programmer time on reducing them is often a poor trade. * The claim that a Human can optimize code better than the compiler assumes a very smart and talented Human, and/or a very dumb compiler. Compilers are getting smarter, and since a lot more people find the need to program, the average programmer is not that talented. I'm pretty I'm not, for example -- I'll take my chances with the compiler. ;-) Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From vivek7006 at gmail.com Tue Aug 16 14:10:43 2005 From: vivek7006 at gmail.com (vivek7006 at gmail.com) Date: 16 Aug 2005 11:10:43 -0700 Subject: random seed Message-ID: <1124215843.369517.197900@z14g2000cwz.googlegroups.com> By default, randomm module uses the timestamp to generate the seed value. Is it possible to know what that seed value is? import random random.random() # How do I print the current value of the seed? Thanks Vivek From tim.peters at gmail.com Tue Aug 16 12:54:28 2005 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 16 Aug 2005 12:54:28 -0400 Subject: String functions deprication In-Reply-To: References: Message-ID: <1f7befae05081609542df2e175@mail.gmail.com> [steve morin] > http://www.python.org/doc/2.4.1/lib/node110.html > > These methods are being deprecated. What are they being replaced > with? Does anyone know? As it says at the top of that page, The following list of functions are also defined as methods of string and Unicode objects; see ``String Methods'' (section 2.3.6) for more information on those. You should consider these functions as deprecated, although they will not be removed until Python 3.0. The methods of string and Unicode objects are not deprecated. It's just the redundant _functions_ in the string module that are deprecated. Historically, the functions in the string module existed long before strings and Unicode objects had any methods. Now that string and Unicode objects do have methods, the functions in the string module are no longer needed. From spam.csubich+block at block.subich.spam.com Sat Aug 6 21:59:03 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Sat, 06 Aug 2005 21:59:03 -0400 Subject: Proposed new collection methods In-Reply-To: <86d5oqvfqf.fsf@bhuda.mired.org> References: <86d5oqvfqf.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Another thread pointed out a couple of methods that would be nice to > have on Python collections: find and inject. These are taken from > . > > find can be defined as: > > def find(self, test = None): > for item in self: > if test: > if test(item): > return item > elif item: > return item > return ValueError, '%s.index(): no matching items in list' \ > % self.__class__.__name__ Dear Zeus no. Find can be defined as: def find(self, test=lambda x:1): try: item = (s for s in iter(self) if test(s)).next() except StopIteration: raise ValueError('No matching items in list') Let's use generators, people. And given the simplicity of writing this, I'm not sure we need it in the standard library -- especially since the default test is arbitrary. This recipe can also be useful for dictionaries, where the syntax would be slightly different, and lists-of-immutables, in which case returning the index in the list might be better. Too much customization. > inject is basically an OO version of reduce. You can define it in > terms of reduce: Except that if it's exactly reduce, we don't need to call it inject. The problem with reduce in python isn't that it's functional rather than OO, it's that it's limited to a function call or lambda -- one expression rather than an anonymous block. From grante at visi.com Tue Aug 30 00:48:03 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 30 Aug 2005 04:48:03 -0000 Subject: aproximate a number References: <1125369077.295227.8540@g14g2000cwa.googlegroups.com> <11h7i0s2lr5a8e8@corp.supernews.com> <1125374065.138657.66410@o13g2000cwo.googlegroups.com> Message-ID: <11h7p83qbjeilad@corp.supernews.com> On 2005-08-30, Devan L wrote: > Grant Edwards wrote: >> On 2005-08-30, Devan L wrote: >> > >> > RoundToInt(2.0) will give you 3. >> >> That's what the OP said he wanted. The next bigger integer >> after 2.0 is 3. > > It's not really clear whether he wanted it to round up or to go to the > next biggest integer because he says he has bad english. I can't think > of a particular use of returning the next bigger integer. You're probably right. I suspect what he really wants is i = int(math.ceil(x)) -- Grant Edwards grante Yow! Is it FUN to be at a MIDGET? visi.com From spam.csubich+block at block.subich.spam.com Tue Aug 9 16:04:14 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 16:04:14 -0400 Subject: Does any one recognize this binary data storage format In-Reply-To: References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> Message-ID: Dejan Rodiger wrote: > 8003346488(10)=1DD096038(16) > 1D D0 96 03 8 > 80 03 96 D0 1D 00 > 80 03 96 d0 fd 41 Add E041 I'm pretty sure that the last full byte is a parity check of some sort. I still thing that Phone2 (..F1) is a typo and should be 41. Even if it's not, it could be a more detailed parity (crc-like?) check. If the F1/41 is a typo, the last byte is ..41 if the parity of the other 40 bits is odd, and ..42 if the parity is even. (Since ..41 and ..42 each have two 1s, it does not change the parity of the entire string). If not, Lucy has some 'splaining to do. Taking the last byte out of ther equation entirely, 40 bytes for 10 decimal numbers is 4 bytes / number, meaning there is some redundancy still in the remainder (the full 10-digit number can be expressed with room to spare in 36 bits). Thinking like an 80s Mess-Dos programmer, 32-bit math is out of the question since the CPU doesn't support it. Five decimal digits already pushes the 16-bit boundary, so thinking of using the full phone number or any computation is insane. #1/#2 and #4/#5 share both the first five digits of the real phone number and the last 16 bits of the remaining expression. Both pairs *also* share bits 5-8 (the second hex digit). Therefore, we may possibly conclude that digits 5-10 are stored in bits 5-8 and 21-36. This is an even 20 of the 40 data-bits. In fact, bits 6-8 of all expamples given were all 0, but since I can't find an equivalent always-x set for the other 5 digits I'm not sure that this is significant. Therefore: 95442 = 8c701 = 1 + c701 (?) 56168 = 0ECF4 = 0 + ecf4 (?) I'm not coming up with a terribly useful algorithm from this, though. :/ My guess is that somewhere, there's a boolean check based on whether a digit is >= 6 [maybe 3?] (to prevent running afoul of 16-bitness). I'm also 90% sure that the first and second halves of the phone number are processed separately, at mostly, for the same reason. From brian at sweetapp.com Tue Aug 2 04:56:13 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Tue, 02 Aug 2005 10:56:13 +0200 Subject: Python Programming Contest: First results In-Reply-To: References: <1121838061.749455.44630@g14g2000cwa.googlegroups.com> <42DE18B2.903@sweetapp.com> Message-ID: <42EF352D.2060702@sweetapp.com> Tomi Ky?stil? wrote: > Why don't I see my solution (__author__ = "dOb") in the results? I'm > sure that you got it as you replied to my mail. Ahhh...sorry. I have your solution and I timed it but I don't have the results here so I can't add it to the website. I'll do it tomorrow. > Where do the timing results come from? Is it the number that > fly_test.main(['fly']) outputs? I don't think it is that because with my > solution that would be ~0.06 seconds. This is the time required to do several thousand trials. Cheers, Brian From cliff at develix.com Tue Aug 2 22:10:44 2005 From: cliff at develix.com (Cliff Wells) Date: Tue, 02 Aug 2005 19:10:44 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <86r7dbeuvq.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <8664uqhkfj.fsf@bhuda.mired.org> <86hde9f172.fsf@bhuda.mired.org> <86r7dbeuvq.fsf@bhuda.mired.org> Message-ID: <1123035044.3202.41.camel@localhost.localdomain> On Tue, 2005-08-02 at 20:17 -0400, Mike Meyer wrote: > Um - you're not answering the question I asked. I asked "What app do I > use to bundle my applications for Unix, ala py2exe (or whatever it is) > for Windows?" You're telling me how to install wxPython on those > platforms. > I know how to install wxPython. What I want to know is how to build an > application bundle for all those Unix systems for a Python app I use > that includes wxPython - or any other third party libraries I may be > using. Sorry, I assumed you'd know about distutils: http://www.python.org/doc/current/dist/ http://www.python.org/doc/current/dist/built-dist.html distutils can go so far as to build an rpm for you, but you'll need to package things like .debs yourself. Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From cam.ac.uk at mh391.invalid Wed Aug 31 16:05:56 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Wed, 31 Aug 2005 21:05:56 +0100 Subject: command line arguments In-Reply-To: <1125512004.352928.103620@g47g2000cwa.googlegroups.com> References: <1125512004.352928.103620@g47g2000cwa.googlegroups.com> Message-ID: wittempj at hotmail.com wrote: > py> parser.add_option("-n", "--name", dest="name", action="store", > py> help="enter a name") > py> parser.add_option("-u", "--url", action="store", dest="url", > help = "enter an url") It's worth noting that this will have the same effect and involves less repetitive typing: parser.add_option("-n", "--name", help="enter a name") parser.add_option("-u", "--url", help="enter a url") Discovering this has made optparse usage much more painless for me, and also reduces the incidence of those nasty multiple line option additions. Although I should note for the record that I agree with Peter Hansen that if the arguments are not *optional* then they should not be made options in this manner. -- Michael Hoffman From danieldsmith at gmail.com Fri Aug 12 11:06:36 2005 From: danieldsmith at gmail.com (danieldsmith at gmail.com) Date: 12 Aug 2005 08:06:36 -0700 Subject: thread limit in python In-Reply-To: <9jTKe.85$k92.8@newssvr19.news.prodigy.com> References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> Message-ID: <1123859196.289006.200380@g44g2000cwa.googlegroups.com> i modified my C test program (included below) to explicitly set the default thread stack size, and i'm still running into the same problem. can you think of any other thing that would possibly be limiting me? and sorry to continue to post here. since this is occurring in both c and python, i think there's no question i'm running into an os limit. #include #include #include #include void * run (void *arg) { sleep(1000); } int main(int argc, char *argv[]) { int j; int ret; pthread_t tid; int num_threads = atoi(argv[1]); pthread_attr_t attr; int stacksize; pthread_attr_init(&attr); pthread_attr_getstacksize (&attr, &stacksize); printf("Default stack size = %d\n", stacksize); // set stack size to 64K pthread_attr_setstacksize (&attr, 0x10000); pthread_attr_getstacksize (&attr, &stacksize); printf("New stack size = %d\n", stacksize); for (j=0; j < num_threads; j++) { ret = pthread_create (&tid, NULL, run, NULL); if (ret != 0) { printf("thread create failed\n",j); fflush(stdout); exit(0); } printf("created thread %d\n",j); fflush(stdout); } sleep(1000); } From martin.witte at gmail.com Fri Aug 12 10:54:23 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 12 Aug 2005 07:54:23 -0700 Subject: simpli int/str problem In-Reply-To: References: Message-ID: <1123858463.740417.226470@g14g2000cwa.googlegroups.com> Use substitution like below. Hope this helps py> d = {'str_name': 'etc' , 'int_name' : 112 } py> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + d['str_name'] + "', '" + d['int_name'] + "')" Traceback (most recent call last): File "", line 1, in -toplevel- SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + d['str_name'] + "', '" + d['int_name'] + "')" TypeError: cannot concatenate 'str' and 'int' objects py> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('%s', %d)" % (d['str_name'], d['int_name']) py> print SQL INSERT INTO (`AH`, `BH` ) VALUES ('etc', 112) py> From peter at engcorp.com Mon Aug 8 08:19:22 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 08 Aug 2005 08:19:22 -0400 Subject: zipped socket In-Reply-To: <1123474441.944938.165170@g49g2000cwa.googlegroups.com> References: <1123474441.944938.165170@g49g2000cwa.googlegroups.com> Message-ID: John wrote: > > Is there anyway open a socket so that every send/listen/recv > goes thru a zipping/unzipping process automatically? You ought to be able to do this easily by wrapping a bz2 compressor around the socket (maybe using socket.makefile() to return a file object first) and probably using a generator as well: http://effbot.org/librarybook/bz2.htm includes relevant examples (not specifically with sockets though). Googling for "python incremental compression" ought to turn up any other alternatives. -Peter From u.hobelmann at web.de Fri Aug 26 04:45:57 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Fri, 26 Aug 2005 10:45:57 +0200 Subject: Usenet, HTML (was Re: Jargons of Info Tech industry) In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> Message-ID: <3n8366F9vvsU1@individual.net> John Bokma wrote: > Ulrich Hobelmann wrote: > >> On the information side (in contrast to the discussion side) RSS is >> replacing Usenet, > > LOL, how? I can't post to RSS feeds. Or do you mean for lurkers? I said "information side", meaning stuff like RSS is used for. >> There is no real reason why NNTP couldn't be used like RSS (i.e. >> contain a small description and a web link as message text), > > It has been used like that for ages (or as long as I can remember). Yes, but for some reason people jumped onto the RSS hype. I wonder why. Heck, even I am subscribed to a bunch of RSSes, because those institutions don't offer NNTP ;) >> or why a >> newsgroup shouldn't we written in HTML and contain a (default, or >> user-provided) CSS sheet. > > It's called www. It's already here (or there) Well, but forums only emulate the posting/reply structure. It would make more sense to use NNTP for that, and use $WHATEVER, e.g. HTML, for markup inside the posts. WWW is something else; a bunch of pages with hyperlinks to each other. Maybe we shouldn't call web forums and other dynamic websites www, as they don't really follow that purpose. They are just abuses of HTTP/HTML/JS for thin clienting. ;) >> If things were that way, suddenly people >> *would* use Outlook and Thunderbird for news-reading, > > But why do you want that? (Oh, and you can't read news with Outlook). Why > do you want more people on Usenet? No, I'm not talking about usenet. I'm glad if the SNR keeps as high (haha) as it is, and messages in plain text. I'm talking about using the technology for communication, instead of reinventing the wheel with crappy web forums. Oh, and I've heard there are people reading our in-house newsgroup with Outlook. >> while today >> everything is just Browser+HTTP. > > And what's wrong with that? It's slow and pointless. All interaction that's more than clicking a link has to be emulated with Javascript (heard of Ajax already?) to make it more smooth. NNTP has advantages like giving you only the headlines first, so you can choose what to check out. Then you can get the article if you like (in the communication case) or the news description (in the RSSoid case) and maybe click on a link inside. Saves bandwidth and is quite faster than waiting for some overloaded PHP server to send you a bunch of HTML tables. Responding doesn't involve *any* HTTP requests, just a keypress and you're typing. Web forums are stone-age, as are most web-pages. -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From mwm at mired.org Fri Aug 12 22:21:27 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 12 Aug 2005 22:21:27 -0400 Subject: Running one Python program from another as a different user References: <1123885309.455560.220670@z14g2000cwz.googlegroups.com> Message-ID: <86vf2a4lw8.fsf@bhuda.mired.org> "dwelch91 at gmail.com" writes: > Greetings- > This is on Linux... I have a daemon running as root and I want to > execute another Python program as another user (a regular user). I have > the name of the user and can use the 'pwd' and 'grp' modules to get > that user's user and group ids. What I don't understand is how to then > go about launching that new program. I had considered having the > launched program switch itself back to the target user (somehow), but > the launched program is graphical in nature (PyQt), and I am afraid of > X11 locking out the display to user root (many distros seem to ship > with server access for user root turned off). That might prevent the > launched program from even starting? > > Any ideas? My Google searching was not successful in figuring this > out... Well, Jeff already pointed out running su. You might also check the os.setuid docs, and the setuid man page. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mknoth at earthlink.net Fri Aug 5 10:31:30 2005 From: mknoth at earthlink.net (kman3048) Date: 5 Aug 2005 07:31:30 -0700 Subject: API class creation In-Reply-To: References: Message-ID: <1123252290.142694.313030@g14g2000cwa.googlegroups.com> Thanks, that helped a lot. Anybody who wants to attempt the same might find the source code tree of Python i.e. file src/Modules/cdmodule.c helpful. --Matt Daniel Dittmar wrote: > kman3048 wrote: > > Hello, > > > > as a relative newcomer to Python API programming I've got a problem: > > > > To extend Python: > > - there is an API C call to create a module > > - there is also a API C call to create a method > > - there is an API C call to create a Class instance > > > > Now, I need to create a Class and fill it with Methods and Variables. > > There are means to create (and attache) methods and variables. > > However, I have not found how to create a Class within a Module. Or do > > I have to use a low level API function to allocate an Object from Heap? > > static PyMethodDef moduleMethods [] = { > ... > }; > > statichere PyTypeObject MyClassType = { > PyObject_HEAD_INIT (NULL) > ... > }; > > initmymodule () > { > PyObject* module; > PyObject* dict; > > module = Py_InitModule4 ("mymodule", moduleMethods, > "doc string", NULL, PYTHON_API_VERSION); > if (module == NULL) { > return; > } > dict = PyModule_GetDict (module); > PyDict_SetItemString (dict, "MyClass"), > (PyObject*) &MyClassType)); > } > > Daniel From sebastien.martini at gmail.com Sun Aug 28 07:52:57 2005 From: sebastien.martini at gmail.com (ookoi) Date: 28 Aug 2005 04:52:57 -0700 Subject: Can I send files through xmlrpc connections? In-Reply-To: <1124742818.840010.59710@g44g2000cwa.googlegroups.com> References: <1124742818.840010.59710@g44g2000cwa.googlegroups.com> Message-ID: <1125229977.184070.232520@g43g2000cwa.googlegroups.com> hi, You can try this recipe, it should provides what you need. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413404 The key is: xmlrpclib.Binary(my_file_object.read()) -- s?bastien http://yadp.sourceforge.net From bokr at oz.net Fri Aug 19 20:52:44 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 20 Aug 2005 00:52:44 GMT Subject: How to get a unique id for bound methods? References: Message-ID: <43067d0e.1906448017@news.oz.net> On Fri, 19 Aug 2005 16:33:22 -0700, "Russell E. Owen" wrote: [...] > >The current issue is associated with Tkinter. I'm trying to create a tk >callback function that calls a python "function" (any python callable >entity). > >To do that, I have to create a name for tk that is unique to my python >"function". A hash-like name would be perfect, meaning a name that is >always the same for a particular python "function" and always different >for a different python "function". That would save a lot of housekeeping. > Why do you need a name? Can you post an example snippet that shows a callback function being used with Tkinter as you would wish? I have a feeling there is a much simpler solution than you are imagining ;-) Regards, Bengt Richter From gordon at hammy.burditt.org Fri Aug 26 12:08:53 2005 From: gordon at hammy.burditt.org (Gordon Burditt) Date: Fri, 26 Aug 2005 16:08:53 -0000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3n8di6Fbhg7U2@individual.net> <3n8sqaFch6kU1@individual.net> Message-ID: <11gufkl279pk646@corp.supernews.com> >The only thing I hate is when I am directed to some website that needs >cookies, but doesn't tell me. A couple times I did a survey, wasting >maybe 10 minutes of my life for a good cause, and then there was an >error. Great! I guess that page needed cookies, but didn't bother to >tell me. Back button didn't work, either, so I just left that website. Some sites do much worse than that. If you have cookies off, they cause an infinite redirect loop. Sometimes my browser manages to detect this after a few minutes and shut it off, and sometimes it doesn't (usually on different sites). I think I can manually get out of this with the STOP button, but until I do, it likely causes a lot of useless load on the web site. Gordon L. Burditt From roy at panix.com Wed Aug 10 21:30:37 2005 From: roy at panix.com (Roy Smith) Date: Wed, 10 Aug 2005 21:30:37 -0400 Subject: PEP 328, absolute/relative import (was: Re: Bizarre error from help()) References: Message-ID: Ben Finney wrote: > Once PEP 328 is fully implemented, all bare 'import foo' statements > specify absolute imports (i.e. from sys.path only). To perform a > relative import (e.g. from current directory) will require different > syntax. It seems like this will break lots of existing code. From mknhln002 at sneakemail.com Tue Aug 9 22:35:23 2005 From: mknhln002 at sneakemail.com (Jules Dubois) Date: Tue, 09 Aug 2005 20:35:23 -0600 Subject: Python supports LSP, does it? References: Message-ID: <9773629.2qrFMi47Q9@knode.kde> On Tuesday 09 August 2005 17:36, Andy Leszczynski <> () wrote: > wikipedia > (http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming) > says: > """ > Python's support for object oriented programming paradigm is vast. It > supports polymorphism [...] fully in the Liskov substitution > principle-sense for all objects. > """ > > Just wondering if it is true statement. It's true if not particularly insightful. "What is wanted here is something like the following substitution property [6]: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T." > Is not LSP more a quality of the desing of class hierachy rather then > language itslef? In a statically-typed language, polymorphism is based on the class hierarchy (through inheritance). Because Python uses dynamically-checked typing, its polymorphism is structural rather than nominative. > Comments? Discussions like these might be more appropriate for the comp.object newsgroup. From michele.petrazzo at TOGLIunipex.it Tue Aug 23 05:56:33 2005 From: michele.petrazzo at TOGLIunipex.it (Michele Petrazzo) Date: Tue, 23 Aug 2005 11:56:33 +0200 Subject: Library and real path name Message-ID: <430af2d2$0$8495$5fc30a8@news.tiscali.it> I want to redistribute the library that I create. I create a project, its setup.py that when launched copy all files into the "site-packages/library" directory. And here it's all ok. When I call my library with: import library library.class() I want that my library know where are its real path (site-packages/library/), because it has to load a data file present into a subpackage directory (like site-package/library/data/file.dat), but if, inside the library code, I try to load the file with: f = open("./data/file.dat") python raise me an exception because it not found the file. I see that the current path are the path where I execute python. I think that I can solve this problem with something like: if sys.platform == 'win32': prefix = os.path.join(sys.prefix, "Lib/site-packages/library/data/") else: prefix = os.path.join(sys.prefix, "site-packages/library/data/") it work, but I think that is not a good solution (a real pythonic solution). Can someone help me? Thanks Michele From lycka at carmen.se Fri Aug 12 05:24:30 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 12 Aug 2005 11:24:30 +0200 Subject: What are modules really for? In-Reply-To: <42fb5a47$0$27714$626a14ce@news.free.fr> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> <42fb5a47$0$27714$626a14ce@news.free.fr> Message-ID: bruno modulix wrote: > Magnus Lycka wrote: > >>N.Davis wrote: >> >> >>>Functions existing in a module? Surely if "everything is an object" >>>(OK thats Java-talk but supposedly Python will eventually follow this >>>too) >> >> >>int too? ;) > > > Yes, int too. I was talking about everything being an object in Java... Java has an Integer class which is OO and an int type which is usable from a performance point of view. At least that distinction existed when I was looking at Java. From gslee at daisy.kw.ac.kr Fri Aug 5 18:26:09 2005 From: gslee at daisy.kw.ac.kr (Gang Seong Lee) Date: Sat, 6 Aug 2005 07:26:09 +0900 Subject: ANN : dxPython 0.3.0 Message-ID: <20050805222232.M12811@mail.kw.ac.kr> Just opened simple webpage. dxPython ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dxPython is a set of interface modules to use DirectX C++ libraries from standard Python programming language. http://dxpython.pythonworld.net/ Comments, suggestions are welcome. Gang Seong LEE gslee at mail.kw.ac.kr From http Sun Aug 7 10:28:53 2005 From: http (Paul Rubin) Date: 07 Aug 2005 07:28:53 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> Message-ID: <7xpsspq0re.fsf@ruckus.brouhaha.com> bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: > > That would imply that it included the Ruby language. Nothing stops the > > Ruby on Rails packagers from making the Ruby on Rails distro a > > superset of the Ruby distro, after all. > > So you agree with me then? That _was_ exactly my point, after all. Not > that you read it. After all, you might have been replying to some > completely different posting - who could know? I don't understand what you're getting at. Either the RoR distribution includes the Ruby language or else it doesn't. From that other post, I have the impression that it does, but I don't care enough about Ruby to want to go check into it. Or is your point that some third party could make a moby Python distro that includes more runtime stuff than the python.org distro includes? Yes, they could; that it's happened with Ruby and not with Python suggests that Ruby is doing a better job attracting people to do stuff like that. I don't think the Ruby language is as nice as Python, so the difference must be in the culture surrounding the language, rather than the language itself. Python culture often strikes me as seriously dysfunctional. See the "reinventing the wheel" thread of the previous week or so, which was full of gnashers arguing that a convenient unified distro isn't necessary since users should have enough tenacity to download and configure umpteen separate components themselves. From weekender_ny at yahoo.com Mon Aug 8 00:13:05 2005 From: weekender_ny at yahoo.com (John) Date: 7 Aug 2005 21:13:05 -0700 Subject: socket + file i/o question References: <1123430926.790390.195590@f14g2000cwb.googlegroups.com> <1123431324.640997.7240@g44g2000cwa.googlegroups.com> Message-ID: <1123474385.063096.271860@g49g2000cwa.googlegroups.com> I found the problem. There was a recv that was not from an open socket... Sorry abt the trouble, --j From jgrahn-nntq at algonet.se Sat Aug 20 06:05:39 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 20 Aug 2005 10:05:39 GMT Subject: As Simple As Possible? References: <1124338318.133726.304370@g49g2000cwa.googlegroups.com> <7677804.UTi409LUyN@knode.kde> Message-ID: On Thu, 18 Aug 2005 15:05:02 +0100, Tom Anderson wrote: > On Thu, 18 Aug 2005, Jules Dubois wrote: > >> On Wednesday 17 August 2005 22:11, jitya >> (<1124338318.133726.304370 at g49g2000cwa.googlegroups.com>) wrote: ... >> Smalltalk is or would be my first choice if everything else were equal. >> Python is what I actually use. > > The showstopping problem with smalltalk, IMHO, is the intertwining of the > language and the environment. Smalltalk weenies hold this up as one of its > greatest strengths, but to me, it just looks like there's twice as much to > learn to begin with. More importantly, I think: it's not polite for a programming language to make it hard to communicate with the rest of your environment. Java pissed me off when I looked at it back in the 1990s, because I was on Unix, and the language would barely give me access to the command line options, had no getopt-style parser, etc. "No, you're supposed to write the kinds of programs that /we/ want you to write!" Python, in contrast, happily provides all that (and enough, it seems, to make Windows and web server people reasonably happy too). The ideological stuff ends at the source code level. > A good command-line smalltalk plus a python-style > simple interactive environment would be a winning combination. I thought that it existed and was called Python ;-) Although I'm not very familiar with the details of Smalltalk. But I agree. If the earlier generations of programming languages (Smalltalk, Eiffel, Oberon, SML, ...) had had more "open-minded" implementations, I think they could have won the battle as early as fifteen years ago. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From martin at v.loewis.de Thu Aug 11 02:47:37 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 11 Aug 2005 08:47:37 +0200 Subject: Pre-PEP Proposal: Codetags In-Reply-To: References: Message-ID: <42FAF489.3010306@v.loewis.de> Micah Elliott wrote: > I also have this living as a wiki > if people would like to add comments there. I might try to capture there > feedback from this group anyway. First try at a PEP -- thanks for any > feedback! I think you somewhat misunderstood the purpose of the PEP process. This is meant primarily for enhancements to Python (the language and its library), and it is meant to save the PEP author from implementing unagreeable functionality - if the PEP is accepted, the PEP author is typically expected to implement the proposed functionality (in many cases, having a draft implementation is prerequisite to accepting it). Both elements seem to be missing your document: it does not propose changes to the Python language; instead, it proposes a specific way of writing comments (ie. something that is not relevant to the Python interpreter or libraries, only to the Python developer). Also, there is no indication that you would like to implement something for the PEP: what tool would you like to change in what specific way? If you want this as a PEP so that Python somehow "endorses" code tags (which appear to be independent from the programming language), I'm -1: Python has traditionally abstained from pushing unrelated technologies. Instead, it integrates with the technologies people find useful; in this spirit, I would rather like to see code tags become popular on their own merits, and *then* perhaps integrating support for it into IDLE could be considered. Regards, Martin From apadovan at gmail.com Thu Aug 18 04:25:35 2005 From: apadovan at gmail.com (apa) Date: 18 Aug 2005 01:25:35 -0700 Subject: how do i add a new path into sys.path? In-Reply-To: References: Message-ID: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> You can do it this way: sys.path.append("C:\Temp") Alejandro From usenet at isbd.co.uk Fri Aug 26 04:50:34 2005 From: usenet at isbd.co.uk (usenet at isbd.co.uk) Date: 26 Aug 2005 08:50:34 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: <3n83eqF6ogbU2@individual.net> In comp.lang.perl.misc John Bokma wrote: > usenet at isbd.co.uk wrote: > > > In comp.lang.perl.misc John Bokma wrote: > >> > >> > the argument that usenet should never change seems a little > >> > heavy-handed and anachronistic. > >> > >> No, simple since there *are* alternatives: web based message boards. > >> Those alternatives *do* support HTML formatting (often the subset > >> mentioned > > > > ... and generally these "web based message boards" (i.e. forums I > > assume you mean) have none of the useful tools that Usenet offers and > > are much, much slower. > > Yup, Slow because of all the HTML and avatars. And you suggest to introduce > such a thing to Usenet? > No, quite the opposite, I like Usenet News as it is. > And which useful tools do you require? > A choice of news readers to suit different people with different interfaces, filtering, kill files, etc. etc. A forum provides a single, usually rather limited, interface for the user with no way for the user to change it radically. -- Chris Green From maksim.kasimov at gmail.com Mon Aug 8 03:34:54 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Mon, 08 Aug 2005 10:34:54 +0300 Subject: Splitting a string into groups of three characters In-Reply-To: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: import re str = '123456789983qw' re.findall("(.{3})", str)+[str[-(len(str) % 3):]] lemon97 at gmail.com wrote: > Hi, > > Is there a function that split a string into groups, containing an "x" > amount of characters? > > Ex. > TheFunction("Hello World",3) > > Returns: > > ['Hell','o W','orl','d'] > > > Any reply would be truly appreciated. > > Thank You, > -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From bdesth.quelquechose at free.quelquepart.fr Thu Aug 11 17:23:55 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 11 Aug 2005 23:23:55 +0200 Subject: Python interpreter error: unsupported operand type(s) for |: In-Reply-To: <1123790610.264861.112280@g47g2000cwa.googlegroups.com> References: <1123790610.264861.112280@g47g2000cwa.googlegroups.com> Message-ID: <42fbba5e$0$7795$626a14ce@news.free.fr> Szabolcs Nagy a ?crit : > you cannot use | with two dict (dict has no .__or__ method) > > what are you trying to do? > read the post: "need help with python syntax"... (posted one hour sooner) From florent.newsgroups at kynesthesy.org Wed Aug 3 06:12:01 2005 From: florent.newsgroups at kynesthesy.org (florent) Date: Wed, 03 Aug 2005 12:12:01 +0200 Subject: trying to parse non valid html documents with HTMLParser In-Reply-To: References: <42efc9ae$0$12924$636a15ce@news.free.fr> Message-ID: <42f09837$0$4042$636a15ce@news.free.fr> > From http://www.crummy.com/software/BeautifulSoup/: > > You didn't write that awful page. You're just trying to get > some data out of it. Right now, you don't really care what > HTML is supposed to look like. > > Neither does this parser. True, I just want to extract some data from html documents. But the problem is the same. The parser looses the position he was in the string when he encounters a bad tag. From mwh at python.net Wed Aug 17 12:24:07 2005 From: mwh at python.net (Michael Hudson) Date: Wed, 17 Aug 2005 16:24:07 GMT Subject: Urgent: Embedding Python problems - advice sought References: <1124236492.970194.270970@g47g2000cwa.googlegroups.com> <1124281396.055192.66840@o13g2000cwo.googlegroups.com> Message-ID: adsheehan at eircom.net writes: > Does anyone have advice on other groups, sites etc that has knowledge > of this subject ? I've just replied to your original post, having not seen it the first time around. Cheers, mwh -- w00t w00t w00t w00t! I don't understand all of the code, but it works! I guess I should check it in. -- from Twisted.Quotes From mwm at mired.org Sun Aug 7 15:15:37 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 07 Aug 2005 15:15:37 -0400 Subject: Wheel-reinvention with Python References: <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <87wtn245qo.fsf@wilson.rwth-aachen.de> <86slxpyxp2.fsf@bhuda.mired.org> <873bporhgm.fsf@wilson.rwth-aachen.de> <86mznvyge7.fsf@bhuda.mired.org> <7xhde2twui.fsf@ruckus.brouhaha.com> Message-ID: <86hde1ftie.fsf@bhuda.mired.org> Dennis Lee Bieber writes: > On 06 Aug 2005 17:27:33 -0700, Paul Rubin > declaimed the following in comp.lang.python: > >> Mike Meyer writes: >> > Is there a free language you consider successful? I can't think of any >> > that are a lot more (i.e. - an order of magnitude) successful than >> > Python that aren't derived from C. >> >> SQL >> > Now /I'm/ getting confused... > > As far as I'm concerned neither Python, SQL, REXX, that OTHER P > language, and lots of can be said to be "derived from C"... The original question was asked of an OP who doesn't consider those languages successful. I don't agree with him, and was asking *his* opinion. He didnt' answer the first time, and I gave up the conversation after that. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jdhunter at ace.bsd.uchicago.edu Thu Aug 11 16:52:14 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 11 Aug 2005 15:52:14 -0500 Subject: Gotchas in user-space matplotlib install? References: <626hf1lp7k492cbcq4o1mqhe3hnaqpbhf5@4ax.com> Message-ID: <87d5okurgh.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "Matt" == Matt Feinstein writes: Matt> Hi all-- I'm planning to try to do a completely local Matt> install of matplotlib (in Fedora Core 1)-- the system Matt> administrator isn't going to stop me-- but he isn't going to Matt> cooperate either. I've got the tarballs for python, numeric, Matt> numarray, matplotlib, ipython, wxpython and freetype-- which Matt> I think covers the various pre-requisites and Matt> post-requisites. One semi-obvious question is where to put Matt> the freetype library (the system version in FC1 is not up to Matt> the required level)-- but I can only wonder what other Matt> trouble I'm going to get into. Any advice before I take the Matt> plunge would be appreciated. TIA... If you do a --prefix=~/usr for all 'configure' and 'python setup.py install' commands, and set your PATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, LIBRARY_PATH, and LD_LIBRARY_PATH variables accordingly, and set the MATPLOTLIBDATA environment variable to point to ~/usr/share/matplotlib, it should work. When debugging your setup, you might want to run your test matplotlib/pylab script with > python myscript.py --verbose-helpful OR > python myscript.py --verbose-debug to get extra information about where matplotlib is looking for things. JDH From garabik-news-2005-05 at kassiopeia.juls.savba.sk Mon Aug 15 10:54:58 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Mon, 15 Aug 2005 14:54:58 +0000 (UTC) Subject: get a list of mounted filesystems under MacOSX Message-ID: Hi all, I am trying to port my (linux) program to MacOSX, and I need to get a list of mounted filesystems. Under linux, it was easy, I was parsing /etc/mtab (or /proc/mounts), this works also on some other unices. But I have no idea how to do it on MacOSX, apart from calling "mount" as an external program and parsing the output - but I prefer "cleaner" solutions. Is there one? And when we are at this, how to find out a list of mounted filesystems under MS Windows? (yes, I know, there is a difference between cygwin python and native port, and the term "mounted" is not used in MS Windows world much) -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From johnjsal at NOSPAMgmail.com Thu Aug 18 00:30:07 2005 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Thu, 18 Aug 2005 00:30:07 -0400 Subject: up to date books? Message-ID: hi all. are there any recommendations for an intro book to python that is up-to-date for the latest version? would reading a book from a year or two ago cause me to miss much? thanks! From benn at cenix-bioscience.com Mon Aug 8 08:28:50 2005 From: benn at cenix-bioscience.com (Neil Benn) Date: Mon, 08 Aug 2005 14:28:50 +0200 Subject: Decline and fall of scripting languages ? In-Reply-To: <42F65CDD.4070005@anvilcom.com> References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <42F65CDD.4070005@anvilcom.com> Message-ID: <42F75002.5070209@cenix-bioscience.com> phil wrote: >>Kay Schluehr (kay.schluehr at gmx.net) wrote: >>: No good news for scripting-language fans: >> >>: http://www.phpmag.net/itr/news/psecom,id,23284,nodeid,113.html >> >> >> > >What incredible horse dooey. > >The only thing that NEVER "penetrates the enterprise space" >is good sense. > >Does anyone read history books? There is no such thing as a large >corporation that is not doomed. There are a few names which are >older than 1/2 a century but the companies and players are >unrecognizable. We have barbeque joints in Texas older than IBM. >And noone from 1970 would recognize IBM. >The "enterprise" is good for one thing. Devouring each other. > >The "enterprise"'s opinion about what is good for the future >is like this broker I knew in Dallas. All you had to do was >find out which stock he was recommending, then short it. > > > Err, that's not what is meant by enterprise, it's a catch all term for large distributed systems, take a look at the link below for an idea of this: http://java.sun.com/j2ee/faq.html Obviously there are other variations on this than the Sun stuff but enterprise dosn't mean 'very large companies' in this case. Cheers, Neil -- 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 tjreedy at udel.edu Thu Aug 11 14:11:12 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Aug 2005 14:11:12 -0400 Subject: performance of recursive generator References: Message-ID: "aurora" wrote in message news:op.svbscwmx6yt6e7 at news.cisco.com... >I love generator and I use it a lot. Lately I've been writing some > recursive generator to traverse tree structures. After taking closer look > I have some concern on its performance. When the stacked yields become a measureable problem over the anticipated future use of the code, then you can rewrite the obviously correct recursive generator as a less-obviously correct iterative generator, using the first to generate test results to check the second. Terry J. Reedy From billiejoex at fastwebnet.it Tue Aug 16 05:52:46 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Tue, 16 Aug 2005 11:52:46 +0200 Subject: sniffer in python References: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> <0KmdncVnD80_Hp3eRVn-rw@powergate.ca> Message-ID: Thanks for your help. Like you suggested I converted the integer value in a string one by using the repr() funtion applied on the print: print '%d \n %s' %(count, repr(iface)) The program now permit me to select the interface. The output is in a strange hex-similar form: C:\Python24>test.py 0 u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e\u6972\u4e63\u6964\u5773\u6e61\u6441\u7061\u6574r\u445c\u7665\u6369\u5c65\u504e\u5f46\u317b\u4534\u3544\u3642\u2d31\u3030\u3942\u342d\u4441\u2d39\u3341\u4345\u382d\u3033\u3246\u3938\u3241\u4531\u7d44\u5c00\u6544\u6976\u6563\u4e5c\u4650\u7b5f\u3541\u3630\u3934\u3434\u452d\u4230\u2d37\u3634\u3239\u382d\u4237\u2d35\u4630\u3133\u4244\u3933\u3532\u3943}\u445c\u7665\u6369\u5c65\u504e\u5f46\u377b\u4337\u3644\u3034\u2d31\u3841\u3143\u342d\u3743\u2d43\u3241\u4633\u432d\u3731\u3037\u3538\u3234\u4538\u7d34'1 u'\u6547\u656e\u6972\u2063\u644e\u7369\u6157\u206e\u6461\u7061\u6574r\u4d56\u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u4d56\u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u564e\u4449\u4149\u6e20\u6f46\u6372\u2065\u434d\u2050\u654e\u7774\u726f\u696b\u676e\u4120\u6164\u7470\u7265\u4420\u6972\u6576\u2072\u4d28\u6369\u6f72\u6f73\u7466\u7327\u5020\u6361\u656b\u2074\u6353\u6568\u7564\u656c\u2972 'Please select an interface: 0When I select the interface (0 or 1) I encounter an encoding error:Traceback (most recent call last): File "C:\Python24\test.py", line 108, in ? main(filter) File "C:\Python24\test.py", line 92, in main p = open_live(dev, 1500, 0, 100)UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15:ordinal not in range(128)- How con I resolve this encoding problem?- How can I display the interface names in a 'human' form?Best regardsbillie> Helping you learn to troubleshoot from tracebacks: look at the linepreceding the failing call. Can you guess anything about what in that linemight be causing an encode() call? The count variable is, presumably, justan integer, so %i wouldn't like have to do more than convert it to a string.%s, however, asks for "iface" to be turned into a string... if it were notalready a string (i.e. it's a unicode?) it would have to be encoded. Whatdoes iface contain and where did it come from? Can you make it be just astring? Does that change or fix anything?>> -Peter From sjmachin at lexicon.net Thu Aug 11 17:58:36 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 07:58:36 +1000 Subject: about coding In-Reply-To: <42FB94CC.6040205@redlinepy.com> References: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> <42FB94CC.6040205@redlinepy.com> Message-ID: <42fbca0b$1@news.eftel.com> Paul Watson wrote: > cantabile wrote: > >> Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : >> -*-' directive. >> >> I'm using an accented characters language. Some of them are correctly >> displayed while one doesn't. I've written : >> -*- coding: utf-8 -*- >> >> Is this wrong ? >> >> Where can I find a pratical explanation about these encodings ? >> >> Thanks. > > > You must know the encoding produced by your editor. > > If you want to experiment, you could save a small file and run > > od -Ax -tx1 thefile.py > > to see exactly what codepoints appear. Compare those with the > charts at http://www.unicode.org/ and you can probably surmize > a good guess. Perhaps faster, and certainly available on all platforms (unlike "od"): Fire up Idle, then do this: >>> import sys >>> sys.stdout.encoding 'cp1252' >>> Why Idle, and not from the command line? Well because if you are on Windows, you'll get a different answer, which is very unlikely to be the one you want [unless you are using a legacy editor]. C:\junk>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.stdout.encoding 'cp850' >>> From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 26 13:54:11 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 26 Aug 2005 19:54:11 +0200 Subject: reportlab and custom fonts Message-ID: <3n93a4Ffo89U1@individual.net> Hi, I'm trying to get reportlab working together with the Tahoma font (by Microsoft ;) So far it's up and running (converted the ttf with ttf2pt1), but the Euro sign (which is in position 0x80 in the WinAnsiEncoding) fails to show up in the final PDF. I investigated a bit and saw that in the afm (and pfb) the code point 128 is called "uni20AC". That's okay in principle, since that Unicode character is the Euro sign, but it seems that reportlab likes the character to be named "Euro". Okay, renamed it in both files, still no luck. Has anyone experience with this problem? Reinhold From hancock at anansispaceworks.com Wed Aug 24 02:15:03 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 24 Aug 2005 01:15:03 -0500 Subject: Externally-defined properties? Message-ID: <200508240115.03337.hancock@anansispaceworks.com> Frankly, I was surprised this worked at all, but I tried creating a property outside of a class (i.e. at the module level), and it seems to behave as a property: >>> def get_x(ob): ... global x ... return str(x) ... >>> def set_x(ob, value): ... global x ... x = int(value) ... >>> def del_x(ob): ... global x ... del x ... >>> def x_access(): ... return property(get_x, set_x, del_x, "X defined externally?") ... >>> >>> class Accessor(object): ... s_x = x_access() ... def __str__(self): ... print "Accessor has x = %s" % self.s_X ... >>> a = Accessor() >>> a.s_x = 3 >>> a.s_x '3' >>> dir() ['Accessor', '__builtins__', '__doc__', '__name__', 'a', 'del_x', 'get_x', 'p', 'set_x', 'x', 'x_access'] >>> x 3 (of course in the real example, x will probably be in an entirely different module, used as a library -- the client code just calls a function to get a property that is automatically managed for it). So far, the only problem I see is that it only works if the property is assigned to a new-type class attribute (otherwise, the first assignment simply replaces the property). I'm thinking of using this to tie a property of a class to an external data source (a joystick axis, in fact -- or at least its last-polled value). There is a more convential way to do this, of course -- I could just use a "get_value" function, but there is something attractive about have a variable that is simply bound to the external data source like this. It seems like a good way to encapsulate functionality that I don't really want the high level class to have to "think" about. I mention it here, because I've never seen a property used this way. So I'm either being very clever, or very dumb, and I would be interested in opinions on which applies. ;-) Am I about to shoot myself in the foot? Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From nomail at nomail.com Tue Aug 9 10:10:30 2005 From: nomail at nomail.com (Nx) Date: Tue, 09 Aug 2005 22:10:30 +0800 Subject: Python 32 and Python 64 bit Message-ID: <42f8b868@127.0.0.1> Suse Linux 9.2 64 Python 2.3 64 bit Python 2.4 32 bit My question is : I have a python prog which is installed for python 2.3 but I need some variables filled with data, which I only can get with running a python prog via python 2.4 (data is comming from a firebird database server via kinterbase ? all needs to be 32 bit). How do I call python 2.4 from within python 2.3 and load my variables with the data from the python 2.4 run ? Nx From bj_666 at gmx.net Wed Aug 10 16:42:50 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 10 Aug 2005 22:42:50 +0200 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123703058.378299.133980@g47g2000cwa.googlegroups.com> Message-ID: In <1123703058.378299.133980 at g47g2000cwa.googlegroups.com>, Qopit wrote: > Now I'm running into another snag when checking some other code I have. > Pychecker gets hung up on raw_input... it actually executes code > rather than just checking it, it seems. For example, the snippet below > hangs pychecker:: > > #--- > while 1: > x = raw_input("meh:") > #--- > > Curious. AFAIK `pylint` tries to avoid running the code. A common idiom to protect code from being executed, if the module is just imported opposed to executed as main module, is to write:: def foo(): # some code if __name__ == '__main__': foo() `__name__` is set to the module name if the module will be imported but to '__main__' if the module is directly executed. Ciao, Marc 'BlackJack' Rintsch From ashok.rajasingh at tegel.co.nz Mon Aug 8 00:15:03 2005 From: ashok.rajasingh at tegel.co.nz (Ashok Rajasingh) Date: Mon, 8 Aug 2005 16:15:03 +1200 Subject: OT: World's largest Python caught!:) Message-ID: <87EFF7FC7B6D46479AF451B4326EF876361599@newplymth.tegel.co.nz> Hi Can I please get some information on this python? I saw a brief news clip last year & am very keen to know more. Thanks Ashok Rajasingh 21 Cumberland street New Plymouth New Zealand +646 7575698 (home) 7599592 (work) ###################################################################### Attention: The information contained in this message and or attachments is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any system and destroy any copies. Please note that the views or opinions expressed in this message may be those of the individual and not necessarily those of Tegel Foods Ltd. This email was scanned and cleared by NetIQ MailMarshal. ###################################################################### -------------- next part -------------- An HTML attachment was scrubbed... URL: From fakeaddress at nowhere.org Fri Aug 12 15:23:35 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 19:23:35 GMT Subject: thread limit in python In-Reply-To: References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> <1123859196.289006.200380@g44g2000cwa.googlegroups.com> Message-ID: Peter Hansen wrote: > Probably, but I haven't yet seen anyone ask the real important question. > What possible use could you have for more than 1000 *simultaneously > active* threads? There are very likely several alternative approaches > that will fit your use case and have better characteristics (e.g. higher > performance, simpler code, safer architecture, etc). Threading systems have come a long way in the last decade or so, and they're still advancing. 64-bit, multi-core processors make mega-threading even more attractive. To read why zillions of threads are good, see: http://www.usenix.org/events/hotos03/tech/vonbehren.html For an example of a high-performance server that uses massive threading, I'd nominate MySQL. Prediction: Ten years from now, someone will ask that same "What possible use..." question, except the number of threads will be a million. -- --Bryan From richardlewis at fastmail.co.uk Fri Aug 26 12:13:56 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Fri, 26 Aug 2005 17:13:56 +0100 Subject: problems with tarfile.open and tar.bz2 In-Reply-To: <1125072329.310958.20650@g43g2000cwa.googlegroups.com> References: <1125072329.310958.20650@g43g2000cwa.googlegroups.com> Message-ID: <1125072836.2382.241558457@webmail.messagingengine.com> On 26 Aug 2005 09:05:29 -0700, justin.vanwinkle at gmail.com said: > Hello everyone, > > I need some tar functionality for my program. Currently the following > code properly displays tar archives, and tar.gz archives. However, it > chokes on tar.bz2 archives with the following error: > > File "mail_filter.py", line 262, in extract_archive > tar_archive = tarfile.open('', 'r', fileobj) > File "/usr/lib/python2.3/tarfile.py", line 900, in open > return func(name, "r", fileobj) > File "/usr/lib/python2.3/tarfile.py", line 980, in bz2open > raise ValueError, "no support for external file objects" > ValueError: no support for external file objects > > > The code snippet is: > > fileobj = StringIO(attach) > > if attach_type == 'application/x-tgz' or attach_type == > 'application/x-tbz' or attach_type == 'application/x-tar': > print '%s file detected, attempting to decompress' % > (attach_type) > > tar_archive = tarfile.open('', 'r', fileobj) > > print tar_archive.getnames() > for archive_file in tar_archive.getmembers(): > print archive_file > print tar_archive.extractfile(archive_file).read() > #except: > # print 'Error while extracting %s.' % (attach_type) > # return '' > Try opening with the 'r:bz2' mode instead of just 'r'. Cheers, Richard From deets at web.de Mon Aug 29 08:16:08 2005 From: deets at web.de (Diez B. Roggisch) Date: 29 Aug 2005 05:16:08 -0700 Subject: Python built email message doesn't support OutLook Express In-Reply-To: References: Message-ID: <1125317768.854518.134140@g44g2000cwa.googlegroups.com> That is not what Sybren requested - we need the message text. If you send html, make sure your paragraphs are html paragraphs (enclosed in

-tags) and not pure whitespace, as html ignores these. Diez From spam.csubich+block at block.subich.spam.com Wed Aug 10 14:50:38 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 10 Aug 2005 14:50:38 -0400 Subject: Help with Regular Expressions In-Reply-To: <1123680438.327709.171480@z14g2000cwz.googlegroups.com> References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> <1123680438.327709.171480@z14g2000cwz.googlegroups.com> Message-ID: Paul McGuire wrote: > If your re demands get more complicated, you could take a look at > pyparsing. The code is a bit more verbose, but many find it easier to > compose their expressions using pyparsing's classes, such as Literal, > OneOrMore, Optional, etc., plus a number of built-in helper functions > and expressions, including delimitedList, quotedString, and > cStyleComment. Pyparsing is intended for writing recursive-descent > parsers, but can also be used (and is best learned) with simple > applications such as this one. As a slightly unrelated pyparsing question, is there a good set of API documentation around for pyparsing? I've looked into it for my mud client, but for now have gone with DParser because I need (desire) custom token generation sometimes. Pyparsing looks easier to internationalize, though. From tomi.kyostila at gmail.com Thu Aug 18 08:29:14 2005 From: tomi.kyostila at gmail.com (=?ISO-8859-1?Q?Tomi_Ky=F6stil=E4?=) Date: Thu, 18 Aug 2005 15:29:14 +0300 Subject: List of strings In-Reply-To: <3mibqiF16it0lU1@individual.net> References: <3mibqiF16it0lU1@individual.net> Message-ID: Paul Watson wrote: > Mohammed Altaj wrote: > >> Hi All >> >> Thanks for your reply , what i am doing is , i am reading from file , >> using readlines() , I would like to check in these lines , if there is >> line belong to another one or not , if it is , then i would like to >> delete it >> >> ['0132442\n', '13\n', '24\n'] >> '13' is already in '0132442' >> '24' is already in '0132442' >> Thanks > > > $ python > Python 2.4.1 (#1, Jul 19 2005, 14:16:43) > [GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> line = '0132442\n' > >>> line > '0132442\n' > >>> line.find("13") > 1 > >>> line.find("03") > -1 > >>> line.find("24") > 3 > >>> print line.find.__doc__ > S.find(sub [,start [,end]]) -> int > > Return the lowest index in S where substring sub is found, > such that sub is contained within s[start,end]. Optional > arguments start and end are interpreted as in slice notation. > > Return -1 on failure. Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> line = '0132442\n' >>> line '0132442\n' >>> "13" in line True >>> "03" in line False >>> "24" in line True -- dOb From mwm at mired.org Thu Aug 25 21:47:37 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 25 Aug 2005 21:47:37 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: <86acj5mpty.fsf@bhuda.mired.org> "Mike Schilling" writes: > Another advantage is that evewry internet-enabled computer today already > comes with an HTML renderer (AKA browser) No, they don't. Minimalist Unix distributions don't include a browser by default. I know the BSD's don't, and suspect that gentoo Linux doesn't. HTML is designed to degrade gracefully (never mind that most web authors and many browser developers don't seem to comprehend this), so you don't really need a "subset" html to get the safety features you want. All you need to do is disable the appropriate features in the HTML renderer in your news and mail readers. JavaScript, Java, and any form of object embedding. Oh yeah, and frames. No problem. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From paolo_veronelli at tiscali.it Tue Aug 2 02:06:19 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 02 Aug 2005 08:06:19 +0200 Subject: doctest bug with nested triple quotes In-Reply-To: <1122957696.085082.293440@o13g2000cwo.googlegroups.com> References: <1122957696.085082.293440@o13g2000cwo.googlegroups.com> Message-ID: <42EF0D5B.8010904@tiscali.it> I can't reproduce the error. Freebsd,python 2.4 runs it. > cat x.py """ dummy = ''' something here ''' """ import doctest; doctest.testmod() > python x.py > maybe the file is different. > python -c "print open('x.py').read().encode('base64')" IiIiCmR1bW15ID0gJycnCgpzb21ldGhpbmcKaGVyZQonJycKIiIiCmltcG9ydCBkb2N0ZXN0OyBk b2N0ZXN0LnRlc3Rtb2QoKQo= Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From wuwei23 at gmail.com Mon Aug 15 19:36:27 2005 From: wuwei23 at gmail.com (alex23) Date: 15 Aug 2005 16:36:27 -0700 Subject: EasyDialogs - select multiple files? In-Reply-To: <1124127204.566082.309300@g14g2000cwa.googlegroups.com> References: <1124127204.566082.309300@g14g2000cwa.googlegroups.com> Message-ID: <1124148987.718610.294120@z14g2000cwz.googlegroups.com> I haven't used EasyDialogs myself but a quick scan of both the Mac & Windows docs doesn't show any explicit support for multiple file selection. EasyGUI is similar to EasyDialogs but uses Tkinter instead of native OS calls: http://www.ferg.org/easygui/index.html While it provides simple functions for selecting files, these are limited to a single file as well. However, you should be able to use the multchoicebox function along with your own compiled list of files to select multiple files at once. Hope this helps. -alex23 From hancock at anansispaceworks.com Sat Aug 13 01:25:16 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sat, 13 Aug 2005 00:25:16 -0500 Subject: Why is this? In-Reply-To: <42fd206b$0$38038$bed64819@news.gradwell.net> References: <42fd206b$0$38038$bed64819@news.gradwell.net> Message-ID: <200508130025.17022.hancock@anansispaceworks.com> On Friday 12 August 2005 05:19 pm, Peter Mott wrote: > Duncan Booth wrote: > > So would you expect: > > > > random.seed(0) > > random.random() + random.random() > > > > and: > > > > random.seed(0) > > random.random() * 2 > > > > to be the same? The first call to random() in each case returns the same > > result, but even though the source text is identical the second call > > in the addition returns something different. It is just the same with the > > lists. > > I don't see that this bears on what I said at all. It may be true that you don't see it, but it is also true that it is exactly the same phenomenon. In both cases you add '+' two distinct objects created by identical python expressions, and are surprised that the result is not the same as creating a single object from the same expression and doubling it with '*'. a = [] is calling a list constructor, so it's basically a function call (to a factory function that makes empty list objects). a = [] + [] calls that function twice, creating two objects, then concatenating them into a list. b = [] * 2 calls the function only once, and then makes two references to it. Which is just exactly what random is doing in the example above, except that it's easier to see that that is a function call, which is presumably the value of mentioning it. ;-) Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From daniel.dittmar at sap.corp Wed Aug 10 09:46:45 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Wed, 10 Aug 2005 15:46:45 +0200 Subject: how to write thread-safe module ? and pytz In-Reply-To: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> References: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> Message-ID: nicolas_riesch wrote: > Does someone know if the module pytz > (http://sourceforge.net/projects/pytz/) is thread-safe ? > I have not seen it explicitely stated, and just wanted to be sure, as I > want to use it. > > That's because in the file pytz/tzinfo.py, I see global variables > _timedelta_cache, _datetime_cache, _ttinfo_cache, which are > dictionnaries and are used as cache. > I always thought that you must protect shared data with locks when > multithreading, but I don't see any lock anywhere in pytz. Dictionaries (and probably most other Python types that are implemented in C) are inherently thread safe. This applies only to the individual methods of dictionaries. The following code would still require a lock: if mydict.has_key (keyval): variable = mydict [keyval] because a second thread could delete the entry between the calls to has_key and __getvalue__. mydict [keyval] = mydict.get (keyval, 0) + 1 is also an candidate for problems. > However, pytz seems to work well with multiple threads creating various > timezone objects at the same time. 'Seems to work' is never a good argument with regard to threads. Especially if you're testing on a single CPU machine. Daniel From gregpinero at gmail.com Fri Aug 19 11:27:34 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 19 Aug 2005 11:27:34 -0400 Subject: global interpreter lock In-Reply-To: <20050820014732.GA7647@mrna.tn.nic.in> References: <20050820014732.GA7647@mrna.tn.nic.in> Message-ID: <312cfe2b05081908272734c56d@mail.gmail.com> KM, I eagerly await the answer to this question as well. I'd love to see this explained in laymen's terms. From what I understand of this issue, your best bet for getting parrelism is to use whatever the OS provides and just have multiple python instances running... but then I didn't understand the articles I've read about this so don't listen to me. -Greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffrey.schwab at rcn.com Tue Aug 9 22:25:28 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Tue, 09 Aug 2005 22:25:28 -0400 Subject: Creating a virtual file system In-Reply-To: References: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> Message-ID: Bryan Olson wrote: > > Atila Olah wrote: > > My question is: How do I implement a virtual partition that acts like a > > real file-system and is compleatly transparent to other programs? > > Should I make a virtual file allocation table for a FAT32 partition or > > simulate an NTFS? Or even further: How do I create a junction (or a > > hard link) to it in "My network places" or in "Entire Network"? > > Hmmm... I seem to rememeber ... Ah, here... > > On: > > http://ask.slashdot.org/article.pl?sid=04/06/01/1810201 > > 'Petard' and 'Foolhard' note that the Microsoft Windows IFS > (Installable File System) Developer's Kit costs like $900. Doing > it well would be a large and expensive project. Read their posts > for more discouragement. > > > > Thanks forward for help. > > Not exactly helpful was I? Sorry. You don't have to pay Microsoft to develop a Windows-compatible filesystem. See http://ubiqx.org/cifs/. From zen19725 at zen.co.uk Mon Aug 1 17:21:58 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 1 Aug 2005 22:21:58 +0100 Subject: Is this Pythonic? References: <74SdnekYvd-_EnPfRVn-2A@speakeasy.net> Message-ID: On Mon, 01 Aug 2005 14:07:46 -0700, Erik Max Francis wrote: > >Yes, but raise NotImplementedError instead of Exception. Another trick >you can use is to prevent people from instantiating the abstract class: > > class Foo: > def __init__(self): > if self.__class__ is Foo: > raise NotImplementedError > ... > > def bar(self): > raise NotImplementedError That's a clever trick, but it's obvious from the code that the class is intended to be abstract, so if people are stupid enough to shoot themselves in the foot by creating an instance, I don't feel like adding extra code to protect themselves from their stupidity. -- Email: zen19725 at zen dot co dot uk From leo.uaz at gmail.com Wed Aug 10 18:08:21 2005 From: leo.uaz at gmail.com (Leo) Date: 10 Aug 2005 15:08:21 -0700 Subject: interpreter frame In-Reply-To: References: <1123689998.800361.278370@g43g2000cwa.googlegroups.com> Message-ID: <1123711701.529320.85880@g14g2000cwa.googlegroups.com> Good try, but that doesn't seem to work either. Maybe I should have emphasized that what I really want is the line of code, as opposed to the entire frame. Here is the output of sys._getframe() on my system: Python 2.3.4 (#1, Feb 2 2005, 12:11:53) [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._getframe() >>> from inspect import * >>> getframeinfo(sys._getframe()) ('', 1, '?', None, None) Is it different in 2.4? Maybe there is something else in sys.* that I am having trouble finding? TIA, Leo. From alan at alankemp.com Sun Aug 21 14:25:23 2005 From: alan at alankemp.com (Alan Kemp) Date: Sun, 21 Aug 2005 14:25:23 -0400 Subject: last line chopped from input file In-Reply-To: <1124646074.295575.292490@g47g2000cwa.googlegroups.com> References: <1124603622.204380.256560@g47g2000cwa.googlegroups.com> <1124646074.295575.292490@g47g2000cwa.googlegroups.com> Message-ID: On Sun, 21 Aug 2005 13:41:14 -0400, Eric Lavigne wrote: >> A shorter python program would be: >> >> os.command("debug\\curve-fit output.txt") > > I tried this program: > import os > os.command("debug\\curve-fit output.txt") > > My error message is: > AttributeError: 'module' object has no attribute 'command' > > I also could not find os.command in the help files. My Python version > is 2.4 (latest is 2.4.1, just a bug-fix release). > I imagine thats was a typo for: >>> os.system("debug\\curve-fit output.txt") Alan From newsgroups at jhrothjr.com Sat Aug 6 09:37:59 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 6 Aug 2005 07:37:59 -0600 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> Message-ID: <11f9f9u2enfsi58@news.supernews.com> "Mike Meyer" wrote in message news:861x57wrui.fsf at bhuda.mired.org... > "John Roth" writes: >> wrote in message >> news:1123270841.195692.21470 at g47g2000cwa.googlegroups.com... >> A much better idea would be to fix the underlying >> situation that makes the global statement necessary. > > You can't "fix" this. This code (in some python-like langauge that > isn't python): > > x = 23 > > def fun(): > x = 25 > # Rest of code > > has two possible interpretations. > > Either the occurrence of x in fun references the global, or it > references a local that shadows the global. There are reasons for > wanting both behaviors. So you have to have some way to distinguish > between the two, and you want it to happen per variable, not per > function. The method with the fewest keywords is to have one be the > default, and some keyword that triggers the other. > > So the only way to remove the global statement would be to have some > way to mark the other interpretation, with say a "local" > decleration. I thik that would be much worse than "global". For one > thing, most variables would be local whether or not they are > declared. Second, having an indication that you need to check module > globals in the function is a better than not having that clue there. You've got half of the answer. The other half is to have the editor/ide translate the lexical cues into color coding and hide the lexical cues. It's not going to happen because the Python community is fat and happy, and is not seeing the competition moving up on the outside. Characteristics that make a great language one day make a mediocre one a few years later, and make a has-been a few years after that. John Roth > > -- > Mike Meyer http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more > information. From onurb at xiludom.gro Thu Aug 11 11:53:58 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 11 Aug 2005 17:53:58 +0200 Subject: len(sys.argv) in (3,4) In-Reply-To: References: Message-ID: <42fb7498$0$11771$626a14ce@news.free.fr> Daniel Sch?le wrote: > Hello > > I wrote a simple module, which is also supposed to be used as standalone > program > after considering how to avoid multiple if's I came up with this idea > > if __name__ == "__main__": > if len(sys.argv) not in (3,4): > print "usage: prog arg1 argv2 [-x]" > # etc ... > > while develeoping I had my interpeter running and reloaded module > now since I am ready, I wanted to run it from cmd windows shell > but it always prints "usage ..." > I added print len(sys.arg) and it prints 1 though I am provinding more > than 1 value > > > C:\pool\vhd2h\python>vhd2h.py vhd.vhd vhd.h -o > 1 > usage: vhd2h.py vhdlFile hFile [-o] > > Someone got an idea what may be wrong? Nope. But since you're running this on a very peculiar OS, I just can guess that this very peculiar OS consider all args to be one same string... Try this: if __name__ == "__main__": for num, arg in enumerate(sys.argv): print "arg %d is %s" % (num, arg) This should art least give you some hints... BTW, isn't the DOS syntax for command line args something like : > myprog /arg1 /arg2 ??? -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From onurb at xiludom.gro Tue Aug 23 13:42:32 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 23 Aug 2005 19:42:32 +0200 Subject: split function In-Reply-To: References: Message-ID: <430b600a$0$14505$636a15ce@news.free.fr> Mohammed Altaj wrote: > Dear all > > Sorry , I confused between two things , what i said in the last e-mail i > already managed to do using C code , But what i need to do using python > is : my input data : > > 0 2 3 4 > 1 2 4 > 2 3 > 3 4 > > what i suppose to do is , using the first line and start searching > number by number ,first i have 0 search in the rest of lines if there is > 0 print out the all numbers except 0 , after that , start searching > using the 2ed element in the first line which is 2 , in the 2ed line we > have 1 , 4 . in the 3rd line we have 3 , in the 4th line we do not have > 2. And so on for 3 and 4 , and also for the 2nd , 3rd lines , so the > output should be > > 0 2 1 4 3 3 2 4 4 1 2 3 > 1 2 3 4 3 > 2 3 > 3 4 > > And i managed to do this , but i did in the case of no space between > numbers,when i am reading from file , like > 0234 > 124 > 23 > 34 > > I want my code be able to deal with the space between numbers , "0 2 1 3\n".strip().replace(' ', '') => "0213" > and this > is my code again (snip unreadable and overcomplicated implementation) in_file = open('result.dat','r') lines = [line.strip().replace(' ', '') for line in in_file] in_file.close() def find_relateds(target, lines): relateds = [target] for line in lines: if target in line: relateds.extend(list(line.replace(target, ''))) return relateds out_file=open('result2.dat','w') for numline, line in enumerate(lines): buf = [] for target in line: relateds = find_relateds(target, lines[numline+1:]) buf.append(" ".join(relateds)) buf = " ".join(buf) print buf out_file.write("%s\n" % buf) out_file.close() BTW, note that this won't work with numbers > 9. If you need to deal with such a case, you can use str.split() to turn "10 21 32 43" into ["10", "21", "32", "43"]. Adapting the above code snippet to use this scheme should be pretty straightforward. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From mwh at python.net Fri Aug 5 08:42:08 2005 From: mwh at python.net (Michael Hudson) Date: Fri, 05 Aug 2005 12:42:08 GMT Subject: Py: a very dangerous language References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> <1123209659.123369.286840@f14g2000cwb.googlegroups.com> Message-ID: Benjamin Niemann writes: > Luis M. Gonzalez wrote: > >> This is great! >> It's absolutely useless, like a real therapist, but it's free! > > Never heard of Eliza? Even Emacs has it built in (Menu Help -> Emacs > Psychiatrist). M-x psy return Cheers, mwh -- Gullible editorial staff continues to post links to any and all articles that vaguely criticize Linux in any way. -- Reason #4 for quitting slashdot today, from http://www.cs.washington.edu/homes/klee/misc/slashdot.html From mwm at mired.org Fri Aug 26 20:40:49 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 26 Aug 2005 20:40:49 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <11gt0d8bjanaabe@corp.supernews.com> Message-ID: <86irxsw6su.fsf@bhuda.mired.org> gordonb.vu2n4 at burditt.org (Gordon Burditt) writes: >>HTML is designed to degrade gracefully (never mind that most web >>authors and many browser developers don't seem to comprehend this), so >>you don't really need a "subset" html to get the safety features you >>want. All you need to do is disable the appropriate features in the >>HTML renderer in your news and mail readers. JavaScript, Java, and any >>form of object embedding. Oh yeah, and frames. > > And links. And cookies. And any kind of external site or local > file access. And browser history. That depends on whether you're trying to keep an HTML message from doing anything nasty (like revealing that you read it) when you render it, or to make sure it *never* does anything nasty, no matter what you do with the message. If all you want is the former - which is what the OP asked for, and I was replying to - then nothing on the list you gave is required. Some of the things you list are a danger even without HTML; most modern news/mail readers will follow links in flat ascii. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fakeaddress at nowhere.org Wed Aug 24 23:33:10 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 25 Aug 2005 03:33:10 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: The doc for the find() method of string objects, which is essentially the same as the string.find() function, states: find(sub[, start[, end]]) Return the lowest index in the string where substring sub is found, such that sub is contained in the range [start, end). Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found. Consider: print 'Hello'.find('o') or: import string print string.find('Hello', 'o') The substring 'o' is found in 'Hello' at the index -1, and at the index 4, and it is not found at any other index. Both the locations found are in the range [start, end), and obviously -1 is less than 4, so according to the documentation, find() should return -1. What the either of the above actually prints is: 4 which shows yet another bug resulting from Python's handling of negative indexes. This one is clearly a documentation error, but the real fix is to cure the wart so that Python's behavior is consistent enough that we'll be able to describe it correctly. -- --Bryan From kuljo at freemail.hu Wed Aug 31 09:58:54 2005 From: kuljo at freemail.hu (Kuljo) Date: Wed, 31 Aug 2005 15:58:54 +0200 Subject: new line References: Message-ID: Kuljo wrote: > Kuljo wrote: > >> Dear friends >> I'm so sorry to bore you with this trivial problem. Allthou: I have >> string having 0x0a as new line, but I should have \n instead. >> How should I solve it? >> I've tried >>>>>text_new=tex_old.replace(str(0x0a), '\n') >> and other things, but none of them worked. >> Thanks in advance > > > I have found this in the meantime: > >>>>nl="\\"+"n" >>>>text_new=replace(text_old, chr(10), nl) > > It works. Thanks Peter, you are right, even >>>text_new=replace(text_old, chr(10), "\\n") works. Yes, it was exactly what I needed. The problem actually was: I'm using Pilot V for years and a part of my "knowledge base" is stored in den memo files. On the PC side I'm using jpilot (Linux Kubuntu 5.04) which works perfectly. Now I wanted to try out kontact (groupware). The shortcoming is that kontact (actually kpilot in the background) does not import the memos. But it store them in a folder as a file per memo. In this file are the cr/lf indicated by hex 0a. The notes in kontact uses char \n instead. For this translation I made a python script which works now. Kind regards Kuljo From steven.bethard at gmail.com Thu Aug 18 22:37:45 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 18 Aug 2005 20:37:45 -0600 Subject: Really virtual properties In-Reply-To: References: <87slx7c4g5.fsf@wilson.rwth-aachen.de> Message-ID: <9MKdnXUVNe1q2JjeRVn-sg@comcast.com> Ben Finney wrote: > Not using the built-in property type. Here is a recipe for a > LateBindingProperty that does what you ask: > > Steven Bethard: > "This recipe provides a LateBindingProperty callable which allows > the getter and setter methods associated with the property to be > overridden in subclasses." > Also see Tim Delaney's comment at the bottom, which provides similar functionality by subclassing property. STeVe From SeeMySites at www.invalid Fri Aug 26 23:49:47 2005 From: SeeMySites at www.invalid (Andrew Thompson) Date: Sat, 27 Aug 2005 03:49:47 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: On Fri, 26 Aug 2005 22:33:22 GMT, Rich Teer wrote: > On Fri, 26 Aug 2005, John Bokma wrote: > >> ..My partner can check her email when I had her over the computer. ... > ...The idea of my wife checking her > email while I'm "doing her" over my computer is most amusing! :-) It does raise the question though. Is it mundane sex, ..or riveting email, that causes this phenomenon? ;-) [ F'Ups set to c.l.j.p. only ] -- Andrew Thompson physci.org 1point1c.org javasaver.com lensescapes.com athompson.info "You live with apes, man, it's hard to be clean." Marilyn Manson 'The Beautiful People' From grante at visi.com Tue Aug 9 16:33:54 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 09 Aug 2005 20:33:54 -0000 Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> Message-ID: <11fi4piovsrgoe1@corp.supernews.com> On 2005-08-09, geskerrett at hotmail.com wrote: > I can posted records as it will take up to much space. But all > three phone numbers are stored in 8 bytes with null bytes (ie. > 00) stored in the leading positions (ie. the left hand side) > > I do have some more examples; > > I have inserted the leading null bytes and seperated with spaces for > clarity. > > Ex #1) 333-3333 > Hex On disk: 00 00 00 80 6a 6e 49 41 > > Ex #2) 666-6666 > Hex On disk: 00 00 00 80 6a 6e 59 41 So there's only a 1-bit different between the on-disk representation of 333-3333 and 666-6666. That sounds pretty unlikely. Are you 100% sure you're looking at the correct bytes? -- Grant From gene.tani at gmail.com Tue Aug 23 09:55:53 2005 From: gene.tani at gmail.com (gene tani) Date: 23 Aug 2005 06:55:53 -0700 Subject: Reg python nature. In-Reply-To: References: Message-ID: <1124805353.664218.295520@o13g2000cwo.googlegroups.com> Do some reading, and stop hijacking threads http://www.python.org/doc/faq/general.html From rkern at ucsd.edu Sun Aug 7 07:24:05 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 04:24:05 -0700 Subject: Abstract methods in python - is this a good way ?) In-Reply-To: References: Message-ID: Philipp H. Mohr wrote: > Hello, > > I would like to use abstract methods in python to force some of the > classes to implement common methods. > > I found this web page and wonder if it is a good way of implementing them: > > http://www.lychnis.net/blosxom/programming/python-abstract-methods-3.lychnis It's okay. I prefer interfaces, though. http://peak.telecommunity.com/PyProtocols.html http://www.zope.org/Wikis/Interfaces/FrontPage > Also could some one please tell me what the type class is which > > class Metaclass (type): > > is inheriting from. It's the builtin type object. Metaclasses inherit from it. http://www.python.org/2.2/descrintro.html -- 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 bryanjugglercryptographer at yahoo.com Mon Aug 15 16:49:28 2005 From: bryanjugglercryptographer at yahoo.com (bryanjugglercryptographer at yahoo.com) Date: 15 Aug 2005 13:49:28 -0700 Subject: socket setdefaulttimeout In-Reply-To: References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> <8122246.VFEYWSAU@news.verizon.net> Message-ID: <1124138968.532691.294420@g43g2000cwa.googlegroups.com> Michael P. Soulier wrote: > On 13/08/05 Bryan Olson said: > > > The seperate thread-or-process trick should work. Start a deamon > > thread to do the gethostbyname, and have the main thread give up > > on the check if the deamon thread doesn't report (via a lock or > > another socket) within, say, 8 seconds. > > Wouldn't an alarm be much simpler than a whole thread just for this? You mean a Unix-specific signal? If so that would be much less portable. As for simpler, I'd have to see your code. -- --Bryan From rkern at ucsd.edu Sat Aug 20 15:06:39 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 20 Aug 2005 12:06:39 -0700 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> Message-ID: James Kim wrote: > Robert Kern wrote: > >>http://www.catb.org/~esr/faqs/smart-questions.html > > Is it a *smart* way or *necessary* way? It's the polite way. And probably the only way you're going to get your questions actually answered. Read the documentation. If you still don't understand something, come back and ask a specific question about what you didn't understand. Then we will respond to your politeness with our own polite answer. Until then, your rudeness gets my rudeness in response. > Plus, my question was not for the detail description but for the > intuitive guide leading the beginner's further study. > > I understand that too many repeated talks make cyberian tired. However, > over and over discussions of basic concepts is also very important for > technology enhancements. Thus, Commands 'iter' and 'lambda' should be > discussed over and over about their necessity and convenience in the > news-group as long as they are the principle keywords distinguished from > the conventional languages like c/c++, pascal, etc. Then use Google Groups to see that they have been, in great detail, and at a higher level than giving a newbie an "intuitive" rundown of the features. Now go read the documentation. -- 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 http Tue Aug 30 04:37:49 2005 From: http (Paul Rubin) Date: 30 Aug 2005 01:37:49 -0700 Subject: Writing Multithreaded Client-Server in Python. References: <1125376325.572881.163770@g44g2000cwa.googlegroups.com> <7x3bos55vb.fsf@ruckus.brouhaha.com> <1125389989.030999.172080@g47g2000cwa.googlegroups.com> Message-ID: <7xll2jhlb6.fsf@ruckus.brouhaha.com> google at phaedro.com writes: > What it does do, is handle each request (from the same client too) in a > new separate thread. Convenient if your processing intensive handle may > otherwise slow down the main server process becoming less responsive to > other requests. > What it doesn't do (and what Sidd seems to search as is suggested by > his 'select()' remark) is handle each client in a separate thread. I don't know what you mean by that. It launches a new thread for each client connection. The connection is two-way and can last as long as desired. If you're imagining something like a web server handling http requests, using http 1.1 keepalive, you could handle any number of requests in that connection. > If you want to apply SocketServer such that each client corresponds to > one thread that handles its' requests (and maintains its state), don't > use ThreadingMixIn - only the thread-selection will be executed in a > separate thread. What do you mean by "each client"? If a client connects, does some stuff, disconnects, and later reconnects, how do you know that it's the same client that's come back? From mwm at mired.org Thu Aug 4 01:05:36 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 04 Aug 2005 01:05:36 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <86zms0ex85.fsf@bhuda.mired.org> <86acjzetfw.fsf@bhuda.mired.org> Message-ID: <86ek9a1ecf.fsf@bhuda.mired.org> Mike Meyer writes: >> I think you'll find that wxPython installs perfectly on Tiger using >> the package provided. Indeed, the only really painful platform to >> install wxPython on is Linux, where you pretty much need to build from >> source if you want the latest and greatest. FWIW, Tiger ships with wxPython pre-installed. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From pink at odahoda.de Wed Aug 3 15:51:08 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 03 Aug 2005 21:51:08 +0200 Subject: Py: a very dangerous language References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> Message-ID: yoda wrote: > It was 2a.m.... I was writing my first enterprise scale application in > Python.... the logic just flowed from my mind onto the keyboard and was > congealed into the most beautiful terse lines of code I had ever > seen... > > It was 3a.m.... I knew I had to sleep.... work the next day or rather, > in a few hours.... but Python somehow brought out all the logic. All > the verbosity of my thought was purified into clean beautiful logic... > > The Python was wringing the cruft out of my thought and letting me > generate wonderfully clean code.... I have to sleep... this is the last > line of code i'm writing... > > It was 4a.m.... just one more def... then I'll sleep.. > > It was 5 a.m.... just one more class...I'll sleep now.. I've got to go > to work in a few hours.... > > It was 6 a.m.... just one more lambda...I'll really sleep > now...seriously... I've got to go to work in a few hours.... > > Python is a very dangerous language... It is addictive.. Once you start > coding, you simply can't stop.... No language has every made(allowed?) > me to think so clearly before.... This is madness.. I hardly every > sleep... I simply can't stop coding when I use Python.... > > This is scary... maybe I should switch back to Java: a language so > unwieldy that I'm driven away from the keyboard in disgusted > frustration.... > > I need to sleep.. but Python won't let me... Python is a dangerous > language.... Well, Python does not cause sleeping problems for me. In fact it lets me sleep pretty well, because it enables me to write HQ software - in contrast to other languages that just cause ugly nightmare after reaching a certain degree of complexity. But Python is the only software in general that - after years of using it - still makes me want to shout 'Python ist einfach nur geil!' (german, loosly translated: 'Python simply kicks ass!') almost every time I dive into something new. The only thing that comes close to it is TDD (test driven development) - and that's not a software product. Since I'm applying it, it greatly improved the confidence in my code and generally increased the fun in programming. And TDD also has its downsides: because you are dividing your work into much smaller steps, each step finalized with a 'all tests passed - your code works *exactly* as specified' (if you treat the testsuite as the formal specification, which I do), then you are tempted to celebrate all these small successes with a small reward. Baaad thing, if you smoke like I do... -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From rafi at free.fr Sun Aug 21 14:41:57 2005 From: rafi at free.fr (rafi) Date: Sun, 21 Aug 2005 20:41:57 +0200 Subject: tkinter text widget question In-Reply-To: References: Message-ID: <4308cb26$0$12107$636a15ce@news.free.fr> William Gill wrote: > The tkinter text widget uses indexes to identify row:column offsets > within the text, but it seems counter intuitive to have to convert row > and column integers to a string like "0.1'. It's great that index can > take a string, but what about looping through rows and columns? Am I > missing a way to use integers directly, or should I create a class that > takes the two integers and returns them formatted as the proper string? tkinter relies on tk that is for tcl at first, and in tcl every thing is a string (more or less). "%s.%s" % (row, column) should answer your problem easily my 2 cents -- rafi "Imagination is more important than knowledge." (Albert Einstein) From bokr at oz.net Tue Aug 16 21:47:14 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 17 Aug 2005 01:47:14 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <4302228e.1621136831@news.oz.net> Message-ID: <43028fd5.1649111246@news.oz.net> On Tue, 16 Aug 2005 19:24:04 -0400, "Terry Reedy" wrote: > >"Bengt Richter" wrote in message >news:4302228e.1621136831 at news.oz.net... >> IOW, "...open the box and find the i'th item /in/ the box..." is not >> really >> finding the i'th item _itself_ "/in/" the box. It is finding one end of a >> string >> tied to some point /in/ the box, but the actual item/object is at the >> other end >> of the string, not /in/ the box, and many other strings may potentially >> also >> be leading to the same object, whether originating from anonymous >> structural >> binding points in other objects, or named binding points in >> name-tag-containing >> objects/namespaces. > >The way I think of it is that Python's collective objects are like club >rosters: one person (object) can be on many rosters. A container would be >like a room, and a person could only be in one room at a time. > Yes, the roster model works for me too, but I'm not sure I understand your concept of "container/room" ;-) I.e., at the Python object level, object representations themselves don't contain each other in the sense of the memory layout of nested C structs, UIAM? Obviously there are C structs for basic object representation information layout, but object-level parts are aggregated by reference via pointers rather than by memory adjacency (again UIAM). E.g., a list of floats is not an array of doubles in memory. It's not even a list of pointers to doubles in cpython, I believe, even though one could conceive of a form of object reference handle/pointers with type clues in the LSBs that could make pointing to a float object be represented exactly identically to a C pointer to double. (Since ints are much more commonly used that would be a waste though, I think, since you would want to use LSB bits to encode differentiation between the most common primitive types for special handling, and it would probably be nice to do simple integer arithmetic without needing to mask, but this is getting to other topics ;-) Regards, Bengt Richter From roccomoretti at hotpop.com Mon Aug 15 13:40:20 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Mon, 15 Aug 2005 12:40:20 -0500 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: Simon Brunning wrote: > On 8/15/05, Rocco Moretti wrote: > >>Which lead me to the question - what's the difference between a library >>and a framework? > > > If you call its code, it's a library. If it calls yours, it's a framework. Although that definition probably makes sense from a pure C perspective, where practically everything you deal with is a primitive, I'm not sure how much use the distinction is with a OO/duck typing language like Python. Say you have a "library" of objects - you (as a user) subclass one and change one of it's functions subtly (say to add logging). Now when the library code runs, it'll call into your code. Voila! Framework. Or say you have a library function which takes a file object as a parameter. Instead of feeding it a Python file, you feed it your own file-like object. Now it'll call your code whenever you do a read/write/seek etc. In fact, since the parameter was probably documented just as "takes a file", you're never quite sure which functions in your objects will get called, short of reading the source of the library - excuse me, it's a framework now. In fact, since Python works with duck typing, and even basic operations like addition and element access can be customized for any parameter, there is no guarantee that users' code won't get called when they use your "library." So is the library/framework distinction useful in Python, especially w/r/t Andy Smith's remarks? From onurb at xiludom.gro Wed Aug 10 13:25:40 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 10 Aug 2005 19:25:40 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> <42fa2189$0$4880$626a14ce@news.free.fr> Message-ID: <42fa389b$0$5469$636a15ce@news.free.fr> Tito wrote: >> [1] 'aName' => public, '_aName' => protected, '__aName' => private > > > I didn't know this one, as I am quite new to Python. Is it really > general use? Yes, it's the convention. Well, to be more exact, this is: name => interface (intended for public use) _name => implementation (not intented for public use) __name => mangled (should not be hidden or overriden) [1] __name__ => magic (has special meaning for the Python interpreter) [2] BTW, from module import * tends to only import 'public' symbols, so you can use _name to prevent _name being imported by accident. [1] The purpose here is not to enforce privacy, but to protect the symbolf from being accidentaly overriden or hidden. given: class Foo(object): def __init__(self, name): self.__name = name f = Foo('foo') You'll have to use : f._Foo__name to access foo.__name from outside the class (this hold for derived classes too). [2] __name__ attributes (variables and functions) usually have special behaviours attached to them. For exemple, - obj.__init__(self, ...) is called on object initialisation - seq.__len__() is called by len(seq), - obj.__str__() is called by str(obj) - obj.__add__ is the '+' operator called by obj1 + obj2 -> obj1.__add__(self, obj2), - obj.__getattr__(self, name) is called when you lookup an inexistant attribute of obj, etc... You'll find all this (and much more) in the doc. HTH -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From jwashin at vt.edu Mon Aug 22 19:53:46 2005 From: jwashin at vt.edu (Jim Washington) Date: Mon, 22 Aug 2005 23:53:46 GMT Subject: Sanitizing untrusted code for eval() References: Message-ID: On Mon, 22 Aug 2005 22:12:25 +0200, Fredrik Lundh wrote: > however, running a tokenizer over the source string and rejecting any string > that contains unknown tokens (i.e. anything that's not a literal, comma, > colon, > or square or curly bracket) before evaluation might be good enough. > > (you can use Python's standard tokenizer module, or rip out the relevant > parts > from it and use the RE engine directly) This seems like the right compromise, and not too difficult. OOTB, tokenize burns a couple of additional milliseconds per read, but maybe I can start there and optimize, as you say, and be a bit more sure that python's parser is not abused into submission. BTW, this afternoon I sent a couple of hours of random junk to eval() just to see what would be accepted. I did not know before that 5|3 = 7 6^3 = 5 ~6 = -7 ()and aslfsdf = () Amusing stuff. Thanks! -Jim Washington From denis.kasak at gmail.com Fri Aug 26 05:49:36 2005 From: denis.kasak at gmail.com (Denis Kasak) Date: Fri, 26 Aug 2005 11:49:36 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: Mike Schilling wrote: > > Threaded mail-readers too, screen-based editors , spell-checkers, all > useless frills. Interestingly enough, I have explained my opinion in the part of the post you have trimmed. On the other hand, things you mentioned are far from being useless. They introduce no intrinsical slowdown due to increased bandwidth consumation, nor potential security problems. They have no downsides I can possibly think of and have many advantages. They are useful. HTML on Usenet is not. -- Denis From nidoizo at yahoo.com Wed Aug 17 23:02:29 2005 From: nidoizo at yahoo.com (Nicolas Fleury) Date: Wed, 17 Aug 2005 23:02:29 -0400 Subject: win32pipe.popen3 In-Reply-To: <1124301101.559487.283280@o13g2000cwo.googlegroups.com> References: <1124301101.559487.283280@o13g2000cwo.googlegroups.com> Message-ID: Jakob Simon-Gaarde wrote: > Follow-up on a thread from 1999 (see below) > > Well now it is 2005 and the operating system I'm using is Windows > Server 2003, and I can still see that the same problem persists with: > > win32pipe.popen2() > win32pipe.popen3() > win32pipe.popen4() > > while win32pipe.popen() does almost what you want. Have you tried subprocess? Regards, Nicolas From c.gillespie at ncl.ac.uk Thu Aug 18 12:01:16 2005 From: c.gillespie at ncl.ac.uk (Colin Gillespie) Date: Thu, 18 Aug 2005 17:01:16 +0100 Subject: Put a url in a browsers address bar Message-ID: Dear All, I would like to place a url in my browsers address bar, then execute. How can do this? e.g. def goToGoogle(): url = "www.google.com" b = openBrowser() b.goToUrl(url) return True Thanks for any help Colin From blr at drizzle.com Fri Aug 26 18:42:02 2005 From: blr at drizzle.com (Brian Raiter) Date: Fri, 26 Aug 2005 22:42:02 +0000 (UTC) Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: > I know this is entirely inappropriate and OT, [...] Yeah -- unlike the rest of this misbegotten thread, which is right bang on-topic for all five newsgroups and is not suffering at all from topic drift, no not in the least. b From mhellwig at xs4all.nl Fri Aug 26 05:57:30 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Fri, 26 Aug 2005 11:57:30 +0200 Subject: Should I move to Amsterdam? In-Reply-To: References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> Message-ID: <430ee832$0$11069$e4fe514c@news.xs4all.nl> Sybren Stuvel wrote: > Martin P. Hellwig enlightened us with: > >>Personal transportation sucks in the Netherlands, if you live in the >>Randstad (the area of the above mentioned cities) and you have to >>travel across the Randstad, you go with the bike and/or >>bus/tram/metro/train because that is the fastest way of >>transportation. > > > And a bike isn't "personal transportation"? Yes it is, and it sucks too, or do you find it amusing to ride 15 clicks through rain and wind to get to your clients? Of course you go by car but then it will take you longer. Byt the way did you notice the "travel across the Randstad" part? > >>By the way, the big cities are notorious for losing your bike fast. > > > True. Unless you have two proper locks. In that case your bike will > last a very long time. Yes that reminds me that I had 2 quite expensive abus locks on my rather cheap bike, the day after a hack was published on the Internet how to open this lock without damaging, the locks where stolen but my bike was further untouched, that pretty badly hurt my bikes ego I guess. > >>That doesn't mean that public transportation is good, no actual >>since the public transportation is commercialized it sucks too. > > > It's quite good actually. The Dutch Railways (Nationale Spoorwegen, NS > for short) have a reputation of being late, but it isn't that bad. > Trains run frequently, and if you have a serious delay, you even get > part of your money back. They don't do it because they like the customer they do it because it's a law. > > My GF and I just got back from a holiday in Croatia. There, there is > only a train every four hours, and then you're lucky. The track is so Croatia is hardley comparible to western europe. > bad, going by bus is just as fast, except you can buy a ticket on the > bus instead of having to buy a ticket + reservation in advance. > > On the way back, we used the ICE (intercity express) through Germany. > It got delayed, so we missed our train to Amsterdam by 15 minutes. The Aah yes, ICE, always put in a extra half hour if you need to change trains, you don't wat to miss reserved trains, no realy you don't want to. It is just the same as with airplanes. > delay was in K?ln, because the pope paid a visit - well known to the > Deutsche Bahn, but still they didn't do anything about it. We had to > use another train which left two hours later. And we didn't get any > compensation for this - not even for the reservation for the train we > missed. Same as with airplanes. > > We had a delay of two hours. In The Netherlands you would at least get > a significant percentage of your money back. Not in Germany. Strange, I very frequently go with rail like transportation across western europe and the only place where it sucks more then in the Netherlands is the UK or France when they doing another strike. I do not account major accidents like flooding, storm or earthquakes. > > After all, I think with the frequent trains (compared to Croatia) and > reasonable refunds (compared to Germany), the NS isn't that bad after > all. Comparing it to Belgium, France, Luxembourg, Germany, Spain, Norway, Swizz etc.etc. okay, but comparing it with a former Communistic country? They still have about 45 years of catching up to do and to there credits they develop much faster then the "old" western countries. I heard that in Swizz public transportation tend to leave on time and even arrive on time! Compare that with 12% delayed leaving and 27% delayed arrivals of trains in the Netherlands. A rule of thumb is that as soon as the weathere changes (it doesn't matter what from what and where too) you have at least a 15 minute delay between the major stations. > > >>Just don't plan to get anywhere special with public transportation >>after 2300h. > > > There are night trains between the big cities in the Randstad. At > least in Amsterdam busses go through the city all the night, every > night. I don't know about other cities - I live in Amsterdam. There still alot of people living in cities like Gouda or surrounding villages in "Het Groene Hart", and most of them can only get home after 23.00h when they go by car (or motorbike). >>Most people in here are non-believers or so lightly believers that >>you won't know the difference between them and the non-believers. >>The biggest part of the remaining believers are realistic and value >>life, moral and norms without compromising public safety, of course >>fanatics are every where in the world including the Netherlands. > > > Here in Amsterdam, things are getting more nasty. A > writer/critic/actor was killed "in the name of Allah", just because he > excercised his freedom of speech. > > Another man was seriously messed up while standing in his own front > door opening, just because he's homosexual. In his street, sometimes > people are shouting "Go away you homo, you're not welcome here. This > is a Macoccan street!. I'm not discriminating, but Maroccans telling > Dutch people they aren't welcome in their own captial? I wish _those_ > people would just go back to Marocco. Yeah that sucks, but this is the work of fanatics and in no way by the average, anyone searching for a reason for murder, rape or opression can find them in any religious context that doesn't matter if it's one of various christian incarnations, islam or whatever mono/multi/none-god(s) believes people believe in. > > >>The only serious downsize is that in the Randstad the house prices >>are too high > > > Very true. My girlfriend and I are renting a house in the northern > part of Amsterdam, just above Central Station. We had to search quite > hard to find that, though! > > Sybren -- mph From cliff at develix.com Tue Aug 2 00:30:04 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 21:30:04 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <86d5oxf0u8.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <861x5ehk4g.fsf@bhuda.mired.org> <86d5oxf0u8.fsf@bhuda.mired.org> Message-ID: <1122957004.19618.472.camel@localhost.localdomain> On Mon, 2005-08-01 at 23:56 -0400, Mike Meyer wrote: > I think you have me confused with someone else. I was responding to > someone who was claiming that the lack of a standard enterprise > strength GUI toolkit was a serious problem for Python - I disagree. I > won't recap the thread, but other languages have been *very* > successful without having a GUI as part of the language, all they had > was one development environment distributed with a GUI. I think there's a lot of confusion in this thread. > BTW, in answer to your rhetorical question about GUI's for Linux, the > answer is plwm. Technically, a toolkit for building a window manager, not a GUI. But funny anyway ;) Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From finite.automaton at gmail.com Tue Aug 9 16:08:30 2005 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 9 Aug 2005 13:08:30 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123601386.567072.111240@o13g2000cwo.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> Message-ID: <1123618110.763724.304990@g44g2000cwa.googlegroups.com> What kinds of illegal date values are you trying to represent? The reason I ask is that it's not going to be as easy as subclassing datetime... datetime is implemented in C. and so enforcement of legal values is going to be in the C code. For the time.h functions, you're also going to be constrained by the size of the time_t struct, which is probably a long int on your platform. See Modules/datetimemodule.c in the Python source. One thing you could do would be to copy datetimemodule.c and build your own C extension type based on it... things like MAXYEAR 9999 could be changed that way. The other thing would be to write a pure-python datetime class without trying to inherit datetime.datetime. From rubbishemail at web.de Mon Aug 29 10:22:31 2005 From: rubbishemail at web.de (rubbishemail at web.de) Date: 29 Aug 2005 07:22:31 -0700 Subject: Pointers and ctypes In-Reply-To: <43131645$0$27016$626a14ce@news.free.fr> References: <1125321557.883310.41490@g43g2000cwa.googlegroups.com> <43131645$0$27016$626a14ce@news.free.fr> Message-ID: <1125325351.933944.158330@f14g2000cwb.googlegroups.com> thanks a bunch, i just got the answer myself. next time i think about it a little longer. thanks again carlo From jepler at unpythonic.net Thu Aug 4 22:50:56 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 4 Aug 2005 21:50:56 -0500 Subject: Euclid's Algorithm in Python? In-Reply-To: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> Message-ID: <20050805025056.GD19009@unpythonic.net> Well, this article http://pythonjournal.cognizor.com/pyj1/AMKuchling_algorithms-V1.html was the first hit on google for '"euclid's algorithm" python'. It contains this function: def GCD(a,b): assert a >= b # a must be the larger number while (b != 0): remainder = a % b a, b = b, remainder return a Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From gene.tani at gmail.com Wed Aug 31 15:45:10 2005 From: gene.tani at gmail.com (gene tani) Date: 31 Aug 2005 12:45:10 -0700 Subject: graphical or flow charting design aid for python class development? In-Reply-To: <8ckRe.3276$v83.327@newssvr33.news.prodigy.com> References: <8ckRe.3276$v83.327@newssvr33.news.prodigy.com> Message-ID: <1125517510.138456.175480@z14g2000cwz.googlegroups.com> Have you looked at class browser module? Not the graphical tool you're looking for, but maybe a good start http://www.python.org/doc/2.0.1/lib/module-pyclbr.html William Gill wrote: > Being somewhat new to Python, and having a tendency to over complicate > things in my class design, I was wondering if anyone can suggest a > simple graphical or flowcharting tool that they use to organize their > class and program design? Because of a 55 mph head-on accident a few > years back, I have short term memory problems, so flipping back and > forth between pages of code is next to impossible for me to keep > straight. A simple graphical model would allow me to 'see' everything > in one view, and better organize my resulting code. I have had limited > success using pydoc to view my classes, but it's not really much help in > development, just review, and sometimes there is too much info. > > I have used editors for other languages that allow the view to expand > and collapse functions/methods (like message threads here on the board), > which help, but I haven't seen anything like this for python. > > Thanks for any suggestions. > > Bill From rkern at ucsd.edu Tue Aug 30 19:17:00 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 30 Aug 2005 16:17:00 -0700 Subject: py2app and Bittornado In-Reply-To: <1125442841.042912.197950@g14g2000cwa.googlegroups.com> References: <1125442841.042912.197950@g14g2000cwa.googlegroups.com> Message-ID: bsharitt at gmail.com wrote: > I'm trying to get Bittornado to run on Mac OS X (10.4 with Python > 2.3.5) but I've only ever dealt with Python at lower lever scripting > stuff, never wxPython or another GUI stuff. py2app is supposed to be > the tool to create Mac friendly Python applications(like py2exe on > Windows), but the documentation for py2app doesn't seem to be much > help. The setup.py script that comes with BitTornado doesn't run when I > type python setup.py py2app and produces the following error: > > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] > or: setup.py --help [cmd1 cmd2 ...] > or: setup.py --help-commands > or: setup.py cmd --help > > error: invalid command 'py2app' (no module named > 'distutils.command.py2app') You need to write a setup.py (actually, probably you should name it something else like "setup-app.py") that specifies the appropriate information. From the py2app documentation, the simplest example would be from distutils.core import setup import py2app setup( app=['MyApplication.py'], ) Then you can do python setup-app.py py2app If you need more help, I suggest asking on the PythonMac-SIG mailing list. -- 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 aurora00 at gmail.com Thu Aug 11 17:37:36 2005 From: aurora00 at gmail.com (aurora) Date: Thu, 11 Aug 2005 14:37:36 -0700 Subject: performance of recursive generator References: Message-ID: On Thu, 11 Aug 2005 01:18:11 -0700, Matt Hammond wrote: > >> Is it an inherent issue in the use of recursive generator? Is there any >> compiler optimization possible? > > Hi, I could be misunderstanding it myself, but I think the short answer > to your question is that its an inherent limitation. ... > Perhaps if there existed some kind of syntax to hint this to python it > could optimise it away, eg: > > yield *inorder(t.left) > > ... but AFAIK there isn't :-( so I guess you'll have to avoid recursive > generators for this app! That would be unfortunately. I think generator is most elegant in traversing recursive structure. It is non-trivial to use most other methods. But the O(n^2) price tag is a big caveat to keep in mind. Of course I agree we should not optimize prematurely. I'm not about to rewrite my recursive generators just yet. But O(n^2) complexity is something important to bear in mind. It doesn't necessary cause problems in practice. But it might. From duncan.booth at invalid.invalid Thu Aug 11 11:46:40 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Aug 2005 15:46:40 GMT Subject: Regular expression to match a # References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> Message-ID: John Machin wrote: >> Alternatively for C style #includes search for r'^\s*#\s*include\b'. > > Search for r'^something' can never be better/faster than match for > r'something', and with a dopey implementation of search [which > Python's re is NOT] it could be much worse. So please don't tell > newbies to search for r'^something'. > Search for r'^something' is always better than searching for r'something' when the spec requires the search to match only at the start of a line (on the principle that code that works is better than code which doesn't). It appears that this may be something the original poster wanted, so I stand by my suggestion. From fakeaddress at nowhere.org Tue Aug 9 19:08:23 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 09 Aug 2005 23:08:23 GMT Subject: MainThread blocks all others In-Reply-To: References: Message-ID: Nodir Gulyamov wrote: > Hello All! > I met some strange situation. In MainThread my program wating changes of > some variable. This variable should be changed in another thread, but loop, > which wait changing variable blocks all other threads. > Code below: > > class class1: > def __init__(self): > self.counter = 0 > result = doSomeJob() > > def increaseCounter(self): > self.counter += 1 > > doSomeJob(self): > ##### BLOCKING HERE ### > while counter != 1: Should that be self.counter? > pass > # ... continue... > > # this class subscribed to some observer which implements thread > class monitor: > def __init__(self, klass): > #do some init > self.c = klass > def update(self): > self.c.increaseCounter() > > if __name__ == "__main__": > cl1 = class1() > m = monitor(cl1) > mo = MonitorObserver(m) > > > I am very confused how to resolve this problem. Any help will be > appreciated. Make self.counter a semaphore. Untested code: import threading class class1: def __init__(self): self.counter = threading.semaphore(0) result = doSomeJob() def increaseCounter(self): self.counter.release() doSomeJob(self): # Busy-waiting sucks. # while counter != 1: # pass self.counter.acquire() # ... continue... -- --Bryan From phm4 at kent.ac.uk Sun Aug 7 07:15:15 2005 From: phm4 at kent.ac.uk (Philipp H. Mohr) Date: Sun, 7 Aug 2005 12:15:15 +0100 (BST) Subject: Abstract methods in python - is this a good way ?) Message-ID: Hello, I would like to use abstract methods in python to force some of the classes to implement common methods. I found this web page and wonder if it is a good way of implementing them: http://www.lychnis.net/blosxom/programming/python-abstract-methods-3.lychnis Also could some one please tell me what the type class is which class Metaclass (type): is inheriting from. Thank you, Phil From grante at visi.com Thu Aug 18 12:05:50 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 18 Aug 2005 16:05:50 -0000 Subject: gnuplot-py: plotoutput in string? References: Message-ID: <11g9ceuht92ve85@corp.supernews.com> On 2005-08-18, Nicola Kaiser wrote: > I?m using Gnuplot via gnuplot.py and I?m looking for a way to get the > plotting output (terminal set to png in my case) piped in a string > instead of to stdout or a file. Plotting to a file and then reading the file is pretty trivial: import Gnuplot,time filename = 'foo.png' p = Gnuplot.Gnuplot() p('set term png') p('set out "%s"' % filename) p.plot('sin(x)') p('set out') time.sleep(0.1) # wait for gnuplot to process all the commands s = open(filename,'rb').read() Since gnuplot is running asycnronously and reading commands from a pipe, you've got to give it some time to finish executing the commands before you attempt to read the file. > Is there any method in gnuplot.py that does this for me? I don't think so. > If not, I tried something like: > > p=Gnuplot.Gnuplot(debug=1) > p('set terminal png') > oldstdout=sys.stdout > output=cStringIO.StringIO() > sys.stdout=output > p.plot([[1,0],[2,50],[3,0],[4,20],[5,0],[6,30],[7,70], [8,70], [9, 75], > [10, 50], [11, 30], [12, 50]]) > sys.stdout=oldstdout > print output.getvalue() That's not going to work. The gnuplot engine isn't a Python program. It's not writing to sys.stdout, it's writing to Unix file descriptor 1. In order to do things the way you're attempting to, you'd have to redirect file descriptor 1 to a pipe before you start the gnuplot engine, then read the plot data from the pipe. The Gnuplot module may already be redirecting the gnuplot processes output file descriptors, so attempting to do it yourself might not work anyway. > But unfortunately I also get other stuff like: > > "gnuplot: unable to open display '' > "gnuplot: X11 aborted" > > in the same string > > Can anyone help me on this? You shouldn't have gotten messages about the X11 terminal driver if you really had set the terminal type to png. -- Grant Edwards grante Yow! Are you selling NYLON at OIL WELLS?? If so, we can visi.com use TWO DOZEN!! From mwm at mired.org Wed Aug 3 09:47:26 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 03 Aug 2005 09:47:26 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <8664uqhkfj.fsf@bhuda.mired.org> <86hde9f172.fsf@bhuda.mired.org> <86r7dbeuvq.fsf@bhuda.mired.org> Message-ID: <86r7db16a9.fsf@bhuda.mired.org> Cliff Wells writes: > On Tue, 2005-08-02 at 20:17 -0400, Mike Meyer wrote: > >> Um - you're not answering the question I asked. I asked "What app do I >> use to bundle my applications for Unix, ala py2exe (or whatever it is) >> for Windows?" You're telling me how to install wxPython on those >> platforms. >> I know how to install wxPython. What I want to know is how to build an >> application bundle for all those Unix systems for a Python app I use >> that includes wxPython - or any other third party libraries I may be >> using. > > Sorry, I assumed you'd know about distutils: Cliff, please quit being an ass. You keep assuming that because some tool isn't the answer to my question that I don't know about it. That's simply rude. It would be *much* more polite to ask "What's wrong with distutils" rather than saying "So you don't know about distutils." > http://www.python.org/doc/current/dist/ > http://www.python.org/doc/current/dist/built-dist.html > > distutils can go so far as to build an rpm for you, but you'll need to > package things like .debs yourself. I've very familiar with distutils. It doesn't do what I asked for, in that it only bundles up *my* code. It doesn't bundle the things I depend on the way py2exe does. It's patently *not* the answer to the question I asked. For those who want .deb's out of distutils, there's a PR on sourceforge that includes a patch to make it generate .debs that works quite well. Of course, anyone who built a .deb (or an RPM, or a port, or whatever) that bundled up everything it needed would be doing *the wrong thing*. Those formats are designed for packaging single distributions, not applications. They include dependency information that is used to fetch the dependencies and install them. From my standpoint, the problem here is that you then have to get the dependencies into the repository before you can put your application there and have it work. For instance, my port of bicyclerepairman is stuck at an old version because I haven't gotten a port PyMac accepted yet (it also has to do with bugs in the xemacs port, but that's another story). I'm surprised you haven't mentioned eggs yet. Those work across all the platforms I named. Of course, they aren't the answer to my question either, because, like PRMs et al, they only reference external dependencies, they don't include them. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From donn at drizzle.com Tue Aug 9 02:41:01 2005 From: donn at drizzle.com (Donn Cave) Date: Tue, 09 Aug 2005 06:41:01 -0000 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <7x8xzcck9d.fsf@ruckus.brouhaha.com> <86wtmvlti7.fsf_-_@bhuda.mired.org> <7xoe87vl0i.fsf@ruckus.brouhaha.com> Message-ID: <1123569660.464123@yasure> Quoth Paul Rubin : | Right now I'm mainly interested in OCaml, Haskell, Erlang, and maybe | Occam. Haskell seems to have the happiest users, which is always a | good thing. Erlang has been used for real-world systems and has | built-in concurrency support. OCaml seems to crush Haskell and Erlang | (and even Java) in performance. I'm sure you're aware that these are all arguable. In particular, shootout figures aren't a really reliable way to find out about performance. | The idea is to use one of those languages for a personal project after | my current work project wraps up pretty soon. This would be both a | learning effort and an attempt to write something useful. I'm | thinking of a web application like a discussion board or wiki, | intended to outperform the existing ones, i.e. able to handle a | Slashdot or Wikipedia sized load (millions of hits/day) on a single | fast PC instead of a rack full. "Single fast PC" will probably soon | come to mean a two-cpu-chip motherboard in a 1U rack box, where each | cpu chip is a dual core P4 or Athlon, so the application should be | able to take advantage of at least 4-way multiprocessing, thus the | interest in concurrency. Oh. Note that the FP world has been historically attracted to the "green" thread model, where threads are implemented in the runtime like (old) Stackless micro-threads, much faster and more tractable for runtime data structures ... but runs on only one CPU at a time. Ocaml & I believe current ghc support native OS threads, Erlang I would guess not but wouldn't know for sure. Don't know about ghc internals, the way I remember it ocaml's native thread system has something like Python's global lock, instead of locks around each memory management function etc. Donn Cave, donn at drizzle.com From berlin.brown at gmail.com Wed Aug 17 20:59:44 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Wed, 17 Aug 2005 20:59:44 -0400 Subject: Lightweight Python distribute it in under 2MBs for Win32 In-Reply-To: <1123888740.907184.38670@f14g2000cwb.googlegroups.com> References: <1123888740.907184.38670@f14g2000cwb.googlegroups.com> Message-ID: <7tednYxNzPYfQJ7eRVn-iA@comcast.com> fred.dixon wrote: > 30meg for wx ? > mine is under 3meg, compressed > Can I have a copy of that? Windows version? -- Ramza from Atlanta http://www.newspiritcompany.com From spam.csubich+block at block.subich.spam.com Thu Aug 4 20:36:53 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Thu, 04 Aug 2005 20:36:53 -0400 Subject: cut & paste text between tkinter widgets In-Reply-To: <1123198583.339591.283890@g47g2000cwa.googlegroups.com> References: <1123198583.339591.283890@g47g2000cwa.googlegroups.com> Message-ID: <6wyIe.13166$jq.10303@bignews3.bellsouth.net> Repton wrote: >>This poses a small problem. I'm not sure whether this is a >>Win32-related issue, or it's because the PRIMARY selection isn't fully >>configured. > > > You need to select something first :-) > That doesn't work for inter-process communication, though, at least not with win32 native programs. From bokr at oz.net Sun Aug 7 17:46:32 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 07 Aug 2005 21:46:32 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <42F4F2D3.80804@tiscali.it> Message-ID: <42f659a4.848866235@news.oz.net> On Sat, 6 Aug 2005 19:28:13 -0400, "Terry Reedy" wrote: > >"Paolino" wrote in message >news:42F4F2D3.80804 at tiscali.it... >> seberino at spawar.navy.mil wrote: >> I don't think the global keyword is useful actually. >> What's so special in a module nemespace to be priviledged like that. > >The specialness of globals and locals was part of Python's original simple >namespace design, and is still reflected in exec statements and eval >functions, as well as in nested functions. > Ok ;-) But that's historical, and tells us something about how we got to the status quo. ISTM someone wants to discuss possibilities for the future (unless they are just complaining ;-) >> The point IMO is accessing names defined somewhere in the enclosing >> namespaces. > >Accessing such names is already possible, even *after* the outer function >returns and the rest of its execution context is deleted. > >> def enclosing(): >> var=2 >> def enclosed(): >> outer var=4 > >This is rebinding, rather than merely accessing. Similar, but even more >problematical would be initial binding in outer from inner: > >def enclosing(): > def enclosed(): > outer var = 4 > >> this is the base of something useful. > >Actually, it is the reinvention of classes: > >class enclosing(object): > def __init__(self): > self.var = 2 > def enclosed(self): > self.var = 4 > >There was a long discussion on the pydev list a couple of years ago re >adding rebinding in addition to access (of outer variables). I think, in >the end, Guido concluded that there was no compelling reason, as of then, >to add another general mechanism for private, sharable, rebindable >variables. > >> I think there is only one or none possible solution to an outer statement > >There were lots of proposals for both the exact syntax and semantics of >outer binding/rebinding. > No doubt ;-) It might be interesting to compare attribute names with bare names. For attributes we also have a legacy from the historical evolution of current functionaly. E.g., classic vs new classes, descriptors, and most relevenat to the current discussion, mro and super. Bare names do not (yet ;-) have an explicit "nro" (name resolution order), and there is no "super" for names (though someone recently proposed an "unshadow" operator here on c.l.p, so the subject is alive ;-) Nor do we have any correspondence for bare names analogous to setattr(obj, "name", value) <=> obj.name = value e.g., setname(, "name", value) There is nowhere near the kind of control the programmer has over attribute namespace use for bare-name use, even though by various means we are able to select from a limited set of namespaces. (BTW, if were a call to a suitable builtin function that could return objects whose attribute namespace were the desired name space, then setname could be effected with setattr, e.g., setattr(get_ns_obj(), "name", value) # name = value (defaulting to local, same as get_ns_obj(0)) setattr(get_ns_obj(1), "name", value) # name = value (in lexically immediately (1) enclosing scope) setattr(get_ns_obj(-1), "name", value) # name = value (in global module scope) ) I am thinking that there is a subliminal discussion under a layer of red herrings ;-) I refer to the subject of unification/generalizing/orthogonalizing by removing special legacy restrictions (or not introducing special restrictions in a new feature). E.g., recently decorators were introduced, and part of the discussion (which became explicit ;-) was whether to allow the expression following the '@' to be a fully general expression, or whether to restrict it to names, dotted names, and function calls. The latter won out. Some regard this kind of restriction as paternalistic, and protest that "we are adults here" (even though we are not all, and we others not all the time ;-) The BDFL has introduced many new ideas, yet has retained or introduced restrictions on fully orthogonal functionality that might otherwise be allowed if e.g. names in certain contexts were allowed to be full expressions. It goes the other way too. IIRC the list of bases for a class will be allowed to be an empty "()" soon. Bottom line, I think Python is eminently usable and very pleasant to use, but I think bare name mechanisms could be improved. What about more namespace control in the definition of functions, along the lines of "nro" for bare name lookup in the function body? This could be in the form of a sequence of ordinary objects whose attribute name spaces should be searched before looking in globals(). Also using := rather than = to override local namespace binding with extended name space lookup, e.g., (discuss **= syntax later ;-) def fun(a, b=2, *args, **kw, **=(nso, nso2, etc)): print x # looks for local x, nso.x, nso2.x, etc.x, and then globals()['x'] # i.e., not a used-before-bound error if **= spec exists x = 123 # binds local x in any case print x # finds the local x first del x # unshadow **= namespace sequence x := 456 # not local binding unless pre-existing, but if so rebind. # Also rebind if found in enclosing closure scope, BTW. # Otherwise find the first object nsofound with x attr in **= object attribute name space sequence, # and then do nsofound.x=456 -- where x could be a normal property defined by type(nsofound) The property possibility should be interesting ;-) Be kind, I've suggested := for find-and-rebind before, but I haven't thought very far about this combination with extended function namespace ;-) Regards, Bengt Richter From rtomek at ceti.pl Thu Aug 18 20:52:52 2005 From: rtomek at ceti.pl (Tomasz Rola) Date: Fri, 19 Aug 2005 02:52:52 +0200 (CEST) Subject: up to date books? In-Reply-To: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 18 Aug 2005, John Salerno wrote: > hi all. are there any recommendations for an intro book to python that > is up-to-date for the latest version? > > would reading a book from a year or two ago cause me to miss much? Well, well - and nobody mentioned an online tutorial (if I'm not wrong). What a shame :-). If you feel new to all this, then first go to this page: http://www.python.org/doc/2.4.1/ then locate the Tutorial and give it a try. Maybe it is not very complete and leaves some subjects in the dark, but after reading it you should improve your ability to choose the right printed book from your local store (or wherever you look for new books). After reading the Tutorial, I would start a decent text editor, and pointed it to my local Python install files, like /usr/local/lib/python2.4/ and checked if any *.py file made any sense to me. This would give me some hints about how much I need to learn and on what level. Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQwUtaxETUsyL9vbiEQIoEwCfZQm9IHu5wUFrdu7vUqbDAi6APkQAoOOc b7v4+ZFWEyh9nnOfDbJ/BbX0 =Fs7D -----END PGP SIGNATURE----- From u.hobelmann at web.de Fri Aug 26 18:13:44 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Sat, 27 Aug 2005 00:13:44 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> <3n8di6Fbhg7U2@individual.net> <3n8sqaFch6kU1@individual.net> Message-ID: <3n9igoFhsomU1@individual.net> John Bokma wrote: [cookies] > Delete them after each session automatically, except the ones on the > exception list. But why? I simply don't even take them, except my exception list ;) Some people have all cookies turned off. > You are clearly not an average user, so your usage pattern > probably only messes up the stats they obtain via cookies anyway. > > I have long ago given up on manually accepting each and every cookie, and > trying to guess it's purpose. Exactly. That's why I don't do that. I just block them all, except some good sites where I want to be auto-logged in. -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From harlinseritt at yahoo.com Wed Aug 31 07:04:29 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: 31 Aug 2005 04:04:29 -0700 Subject: use threading without classes References: Message-ID: <1125486269.706118.58350@g47g2000cwa.googlegroups.com> Is there any reason why you wouldn't want to do this using the the threading class? To each his own I suppose. You can try the following though you'll at least need to use functions: import time import thread def myfunction(string,sleeptime,*args): while 1: print string time.sleep(sleeptime) #sleep for a specified amount of time. if __name__=="__main__": thread.start_new_thread(myfunction,("Thread No:1",2)) while 1:pass From twic at urchin.earth.li Thu Aug 11 11:24:44 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Thu, 11 Aug 2005 16:24:44 +0100 Subject: help in algorithm In-Reply-To: References: Message-ID: On Wed, 10 Aug 2005, Paolino wrote: > I have a self organizing net which aim is clustering words. Let's think > the clustering is about their 2-grams set. Words then are instances of > this class. > > class clusterable(str): > def __abs__(self):# the set of q-grams (to be calculated only once) > return set([(self+self[0])[n:n+2] for n in range(len(self))]) > def __sub__(self,other): # the q-grams distance between 2 words > set1=abs(self) > set2=abs(other) > return len(set1|set2)-len(set1&set2) Firstly: - What do you mean by "to be calculated only once"? The code in __abs__ will run every time anyone calls abs() on the object. Do you mean that clients should avoid calling abs more than once? If so, how about memoising the function, or computing the 2-gram set up front, so clients don't need to worry about it? - Could i suggest frozenset instead of set, since the 2-gram set of a string can't change? - How about making the last line "return len(set1 ^ set2)"? > I'm looking for the medium of a set of words, as the word which > minimizes the sum of the distances from those words. I think i understand. Does the word have to be drawn from the set of words you're looking at? You can do that straightforwardly like this: def distance(w, ws): return sum([w - x for x in ws]) def medium(ws): return min([(distance(w, ws), w) for w in ws])[1] However, this is not terribly efficient - it's O(N**2) if you're counting calls to __sub__. If you want a more efficient algorithm, well, that's tricky. Luckily, i am one of the most brilliant hackers alive, so here is an O(N) solution: def distance_(w, counts, h, n): "Returns the total distance from the word to the words in the set; the set is specified by its digram counts, horizon and size." return h + sum([(n - (2 * counts[digram])) for digram in abs(w)]) def horizon(counts): return sum(counts.itervalues()) def countdigrams(ws): "Returns a map from digram to the number of words in which that digram appears." counts = {} for w in ws: for digram in abs(w): counts[digram] = counts.get(digram, 0) + 1 return counts def distance(w, ws): "Returns the total distance from the word to the words in the set." counts = countdigrams(ws) return distance_(w, counts, horizon(counts), len(ws)) def medium(ws): "Returns the word in the set with the least total distance to the other words." counts = countdigrams(ws) h = horizon(counts) n = len(ws) return min([(distance_(w, counts, h, n), w) for w in ws])[1] Note that this code calls abs a lot, so you'll want to memoise it. Also, all of those list comprehensions could be replaced by generator expressions, which would probably be faster - they certainly wouldn't allocate as much memory; i'm on 2.3 at the moment, so i don't have genexps. I am ashamed to admit that i don't really understand how this code works. I had a flash of insight into how the problem could be solved, wrote the skeleton, then set to the details; by the time i'd finished with the details, i'd forgotten the fundamental idea! I think it's something like using the counts to represent the ensemble properties of the population of words, which means measuring the total distance for each word is O(1). > Aka:sum([medium-word for word in words]) I have no idea what you're trying to do here! tom -- I sometimes think that the IETF is one of the crown jewels in all of western civilization. -- Tim O'Reilly From yoav_artzi at il.vio.com Wed Aug 24 05:59:08 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Wed, 24 Aug 2005 12:59:08 +0300 Subject: Variables in REs Message-ID: <430c43cd$1@news.bezeqint.net> Anyway to set variables in REs. Meaning: I have the RE re.compile(r'/[^/]*') for example and I want to use it on both Win32 machines and Unix machnes. Meaning tha tI need to be able to control the '/' before compiling. I want to create and if and decide what the system is and then put the right char in a variable and compile the RE using that varialbe. I am quite a noob, so I know the question might sound stupid, but any help will be appreciated. Thanks. From krisztian.sinka at ericsson.com Fri Aug 26 11:28:07 2005 From: krisztian.sinka at ericsson.com (Krisz) Date: 26 Aug 2005 08:28:07 -0700 Subject: Excel Character object through COM In-Reply-To: References: <1125057043.800968.180180@g47g2000cwa.googlegroups.com> Message-ID: <1125070087.218313.105470@f14g2000cwb.googlegroups.com> Thanks, it works... Krisz From peter at engcorp.com Thu Aug 18 10:34:50 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 18 Aug 2005 10:34:50 -0400 Subject: Python for Webscripting (like PHP) In-Reply-To: References: Message-ID: Alessandro Bottoni wrote: > (Python has even been told to be used by Yahoo! and Google, among others, > but nobody was able to demonstrate this, so far) Nobody, except Google's founders? http://www-db.stanford.edu/~backrub/google.html (Among many other references.) -Peter From zarnovican at gmail.com Thu Aug 18 12:47:31 2005 From: zarnovican at gmail.com (BranoZ) Date: 18 Aug 2005 09:47:31 -0700 Subject: List of string In-Reply-To: References: Message-ID: <1124383651.776037.123950@z14g2000cwz.googlegroups.com> Dennis Lee Bieber wrote: > On Thu, 18 Aug 2005 13:30:45 +0200, Mohammed Altaj > declaimed the following in comp.lang.python: > > > > Thanks , but , this work for an ordered substrings , just like what we > > had ['0132442\n', '13\n', '24\n'] , I would like to remove all > > substrings from the list , example > > > > ['0134314244133', '132443', '234'] > > > > > > 2nd and 3rd strings are also substrings from the 1st one , so it should > > be removed > > > > One of us must be using a non-standard definition of "substring" as > "234" does not appear anywhere within either "132443" or > "0134314244133". I don't understand "234" either, but I can see some pattern in "132443". "132443" is a 'subsubstring' "0134314244133" because: 0134314244133 -##----###-#- Maybe "234" is just a typo, and it should be "243". def subsubstr(a, b): if b == '': return True if a == '': return False else: if a[0] == b[0]: return subsubstr(a[1:], b[1:]) else: return subsubstr(a[1:], b) I can give you more efficient, index-based sulution, but this one looks nicer. BranoZ From uval at rz.uni-karlsruhe.de Fri Aug 5 16:34:58 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-15?Q?Daniel_Sch=FCle?=) Date: Fri, 05 Aug 2005 22:34:58 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: [...] > Derive your own subclass of complex and define those methods. I think something as basic as an angle/arg of complex number definetly belongs to the interface, and it would not even require a great effort to put it there most complex formulas out there use Euler representation it's a waste of code lines (and programmers time) to write 3 liner functions for the transformion between a+bj <-> (r,angle) Python makes things covenient so we have complex numbers in the core language the calculations where perfectly possible without them using (re, im) tupels and many many sin/cos in the code but imagine how ugly it would be .. I would like see Python as a competitor to Matlab etc Regards -- Daniel From lycka at carmen.se Tue Aug 30 09:55:02 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 30 Aug 2005 15:55:02 +0200 Subject: Problem with select.poll and popen2 Message-ID: I'm trying to read standard out in a process started with popen2 in a non-blocking way. (Other good ways of doing this than the one I tried are appreciated.) I've tried to dumb down my code to see what happens, and socket.poll seems to behave very strangely. I've tried to use the .poll method for the poll object with and without a timeout, but in either case, the output randomly switches between on of the versions below. It runs fast, there is certainly no 1000 ms delay between printed full stops. I suspect Python does things in the background with the pipes that confuse select/poll. import sys import select import popen2 import os CMD = 'date' #fi, fo = os.popen2(CMD) # Same result with this... fo, fi = popen2.popen2(CMD) p = select.poll() p.register(fo, select.POLLOUT) while 1: print '.', sys.stdout.flush() l = p.poll(1000) for (o, evt) in l: if o == fo.fileno() and evt == select.POLLOUT: print 'Reading', fo c = fo.read(1) print c, $ python clpy.py . Reading T . Reading u . Reading e . Reading . Reading A . Reading u . Reading g . Reading . Reading 3 . Reading 0 . Reading . Reading 1 . Reading 5 . Reading : . Reading 4 . Reading 5 . Reading : . Reading 3 . Reading 8 . Reading . Reading C . Reading E . Reading S . Reading T . Reading . Reading 2 . Reading 0 . Reading 0 . Reading 5 . Reading . Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [etc] $ python clpy.py . Reading T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [etc] $ python clpy.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [etc] From mekstran at scl.ameslab.gov Wed Aug 10 08:52:30 2005 From: mekstran at scl.ameslab.gov (mekstran at scl.ameslab.gov) Date: Wed, 10 Aug 2005 07:52:30 -0500 (CDT) Subject: "Ordered" dicts In-Reply-To: References: Message-ID: <57603.129.186.99.221.1123678350.squirrel@mail.scl.ameslab.gov> > Lots and lots of people want ordered dicts it seems. Or at least, they > want > to be able to access their dictionary keys in order. > [snipped lots of examples, nice pro-con lists, etc.] > What do y'all think? I'll second the need for this. Although, what can also be useful as a further extension (at least I needed this capability for a project I worked on) is the ability to not only have the keys sorted, but have them arranged in an arbitrary order (I had parsed some XML data, and each "object" represented in the XML had certain fields, which I was storing in a dictionary, but I needed each object to iterate that dictionary in the same order, preferably the order they occured in the file). I accomplished this through subclassing dict to create a SpecialSortedDict, overriding keys(), values(), the iterxxx() functions, and any others relevant so that it had an associated key order list. It would return keys in the specified order (ignoring any in the order list that weren't in the dictionary), an then any remaing keys were sorted at the end. I don't know if that'd be a useful enhancement to Chris's idea, or if it's a really obscure corner case. But I thought I'd throw it out there. From uomart at ihug.co.nz Thu Aug 18 11:15:03 2005 From: uomart at ihug.co.nz (Jon Monteleone) Date: Fri, 19 Aug 2005 03:15:03 +1200 Subject: Coin-operated kiosk written in python -- need some help... Message-ID: <003001c5a407$9cd68d00$5700a8c0@rmse> Greetings, I posted a few days back and didnt get much of a response, so I figured I would post again with more detail. I am running gnome under fedora core 4. I want a kid to be able to drop a quarter into a coin slot and get 15 minutes of time on an account that has "restricted" Internet access via the firefox web browser. We are experimenting with different ways to allow kids to safely surf the web during school hours while recovering some of the cost for bandwidth. I have written a python program that detects the coin drop and adds 15 minutes to a gui written in tkinter. The gui contains 2 buttons and the usage time. I need a way for my gui to display from machine bootup until shutdown and through multiple logins and logouts of the web browsing account. I am familiar with kiosk setups but I dont know how to code my python program to display its gui at the login screen and continue running through multiple sessions of users logging into and out of the internet acct. I thought making my kiosk program a daemon would work, but I cant get the gui to display at the login screen and then there is the problem of having the press of a button on my gui enter username and password information. Basically, I envision the following sequence of events... 1) Machine is turned on and boots up 2) My kiosk is started (maybe as a daemon) 3) The daemon uses Tkinter to display its gui with the buttons and time 4) User drops coins and time on gui is incremented 5) User presses the start button 6) My program logs the user into the Internet account 7) Secure firefox is started 8) My program starts counting down the time on the gui 9) When the time reaches 0, the user is logged out When the user presses stop on my gui, they are logged out The user can drop more coins at any time during the session to prolong the session 10) Timer resets to 0 awaiting the next customer to drop coins Any help on how to display my gui and log into an account using python would be much appreciated. Cheers -Jon From saddle at gmail.com Fri Aug 12 00:02:44 2005 From: saddle at gmail.com (saddle at gmail.com) Date: 11 Aug 2005 21:02:44 -0700 Subject: any multi-pattern mathching for python Message-ID: <1123819364.485544.252130@g49g2000cwa.googlegroups.com> as I know , agrep can handle this , at least the newer version from http://www.tgries.de/agrep/index.html with a -f property. here is a agrep port to python http://www.bio.cam.ac.uk/~mw263/pyagrep.html, but it is some out of date, and in it's discription "matching of multiple input patterns is deferred to another day", after three years passed..., could anybody give me an advice where has a implement of this multi pattern matching style. thanks in advance From saint.infidel at gmail.com Tue Aug 9 15:31:07 2005 From: saint.infidel at gmail.com (infidel) Date: 9 Aug 2005 12:31:07 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123613673.097932.265430@g47g2000cwa.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> <1123613673.097932.265430@g47g2000cwa.googlegroups.com> Message-ID: <1123615867.763409.138150@z14g2000cwz.googlegroups.com> This doesn't work. I'm out of my league here. From paschott at no.yahoo.spamm.com Thu Aug 11 20:06:17 2005 From: paschott at no.yahoo.spamm.com (Peter A. Schott) Date: Fri, 12 Aug 2005 00:06:17 GMT Subject: Help sorting a list by file extension Message-ID: Trying to operate on a list of files similar to this: test.1 test.2 test.3 test.4 test.10 test.15 test.20 etc. I want to sort them in numeric order instead of string order. I'm starting with this code: import os for filename in [filename for filename in os.listdir(os.getcwd())]: print filename #Write to file, but with filenames sorted by extension Desired result is a file containing something like: C:\MyFolder\test.1,test.001 C:\MyFolder\test.2,test.002 C:\MyFolder\test.3,test.003 C:\MyFolder\test.4,test.004 C:\MyFolder\test.10,test.010 C:\MyFolder\test.15,test.015 C:\MyFolder\test.20,test.020 I need to order by that extension for the file output. I know I've got to be missing something pretty simple, but am not sure what. Does anyone have any ideas on what I'm missing? Thanks. -Pete Schott From Pierre-Eric.Melchy at uni-konstanz.de Fri Aug 5 04:09:10 2005 From: Pierre-Eric.Melchy at uni-konstanz.de (Pierre-Eric.Melchy at uni-konstanz.de) Date: 5 Aug 2005 01:09:10 -0700 Subject: Reliable destruction In-Reply-To: References: <1123153847.649321.235450@z14g2000cwz.googlegroups.com> <1123157779.191750.178300@g43g2000cwa.googlegroups.com> Message-ID: <1123229350.098754.327450@z14g2000cwz.googlegroups.com> Hello, your idea sounds good and handles the exception on teardown as well. (I did not think about the if XXX!=None check in teardown()) I will now provide each of the instruments with an explicit shutdown() method which frees the interface card as well. These methods will be called in a finally clause after run. I think this is much better than to wait for or rely on garbage collection. Of course there is a hardware protection of the setup as well. I am amazed how well Python handles lab instrumentation, it is really fun to develop with Py. Many thanks for your help From tjreedy at udel.edu Sun Aug 28 23:31:59 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2005 23:31:59 -0400 Subject: Release of PyPy 0.7.0 References: <4311ea97$0$1276$ed2619ec@ptn-nntp-reader02.plus.net><1h20uj1.y52kzk1che9j9N%dial#####$$NOSPAM##$#$##tone@gmail.com> <43121002$0$97118$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: "Michael Sparks" wrote in message news:43121002$0$97118$ed2619ec at ptn-nntp-reader03.plus.net... > (Factor of ~450 though is pretty d*^%n cool though :) I think the ratio was 10 or 100 times higher when first measureable. I have long expected success but am still impressed. TJR From smitty_one_each at bigfoot.com Tue Aug 2 18:24:37 2005 From: smitty_one_each at bigfoot.com (Chris Smith) Date: Tue, 02 Aug 2005 18:24:37 -0400 Subject: Using win32com for web automation References: <1122399814.174328.63980@g43g2000cwa.googlegroups.com> <1122409338.810583.97610@z14g2000cwz.googlegroups.com> <1122928162.157140.183090@f14g2000cwb.googlegroups.com> Message-ID: <873bpsnfiy.fsf@bigfoot.com> >>>>> "calfdog" == calfdog writes: calfdog> ina wrote: >> Look up pamie it should do all the work you need. If it dosn't >> I can send you ishyBrowser but pamie has more comunity support. calfdog> # wait for the document to fully load calfdog> while ie.ReadyState calfdog> != 4: sleep(1) calfdog> doc = ie.Document calfdog> while doc.readyState != "complete": sleep(1) I was trying to make this work several months ago, and tried to open the windows event to trap the OnDocumentComplete from IE. It was all beat. I went with the ?ber-hack: a sentinel file in a certain spot writing the word 'Done'. COM programming recalls the Steven Write joke: "Went to the hardware store to buy some batteries, but they weren't included; so I had to buy them again." Grr, Chris From martindemello at yahoo.com Tue Aug 23 04:11:44 2005 From: martindemello at yahoo.com (Martin DeMello) Date: Tue, 23 Aug 2005 08:11:44 GMT Subject: gtkmozembed in fedora core 3 Message-ID: <4TAOe.90515$vj.4835@pd7tw1no> Could someone help me get gtkmozembed working under fc3? The only available rpms need gnome-python2 >= 2.9 and fc3 ships with 2.6. I can't find any fc3 rpms to upgrade gnome-python2 and I can't quite figure out what I'd need to compile just to install gtkmozembed and the python bindings (I need to deploy this at work, so I'm trying to make the minimal possible change to a stock fc3 install). Upgrading to fc4 is sadly not an option :-/ martin From adam at atommic.com Tue Aug 23 21:05:43 2005 From: adam at atommic.com (Adam Atlas) Date: 23 Aug 2005 18:05:43 -0700 Subject: Multiple (threaded?) connections to BaseHTTPServer In-Reply-To: <1124844344.609477.32060@g47g2000cwa.googlegroups.com> References: <1124844344.609477.32060@g47g2000cwa.googlegroups.com> Message-ID: <1124845543.409001.83770@g44g2000cwa.googlegroups.com> Never mind... I've found a workable solution: http://mail.python.org/pipermail/python-list/2001-August/062214.html Robert, thanks, I'll still check that out for any future projects; but for my current purpose, it seems overkill. But I don't know for sure; assuming BaseHTTPServer is good enough for my current needs aside from its lack of threading, does PooledThreadedServer have any advantages over the method I linked above? - Adam From http Sat Aug 20 15:23:16 2005 From: http (Paul Rubin) Date: 20 Aug 2005 12:23:16 -0700 Subject: Well, another try Re: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> Message-ID: <7x8xyw2z17.fsf@ruckus.brouhaha.com> Robert Kern writes: > >>http://www.catb.org/~esr/faqs/smart-questions.html > > Is it a *smart* way or *necessary* way? > > It's the polite way. And probably the only way you're going to get > your questions actually answered. I wonder if there's a way to killfile posts that contain that url. They are cluttering up the newsgroup much more than repeated newbie questions do. Sheesh people, if you see a question that you don't feel like answering, then don't answer. From mandus at gmail.com Tue Aug 2 07:20:25 2005 From: mandus at gmail.com (Mandus) Date: Tue, 2 Aug 2005 11:20:25 +0000 (UTC) Subject: C++, Swig, and pyMPI References: <1122979622.636448.200960@g47g2000cwa.googlegroups.com> Message-ID: 2 Aug 2005 03:47:02 -0700 skrev stringy: > I would like to be able to write a C++ function, to be wrapped into > some python, to be able to communicate over pyMPI. As pyMPI is based on > C++ I figure that this should be possible, although I'm not sure of > where to start. I know the basics of swig and pyMPI, but not how I > would do this. > > Does anyone know if this is possible and where to start? > Are you sure that pyMPI are C++-based? I think it is based on pure C? Besides that, it is not clear (at least to me) what you try to achive. Do you want to use MPI also in your extension module? mvh, -- Mandus - the only mandus around. From pink at odahoda.de Sat Aug 6 07:36:35 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Sat, 06 Aug 2005 13:36:35 +0200 Subject: about coding References: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> Message-ID: cantabile wrote: > Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-' > directive. > > I'm using an accented characters language. Some of them are correctly > displayed while one doesn't. I've written : > -*- coding: utf-8 -*- > > Is this wrong ? > > Where can I find a pratical explanation about these encodings ? The coding line tell the interpreter to assume that the file is encoded as utf-8. It's the job of the editor that you are using, to actually encode the file as utf-8. The coding directive uses a format that is automatically recognized by the emacs editor. If you are using another editor, you'll have to search its menus for the proper way to save files as utf-8. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From http Fri Aug 26 16:04:26 2005 From: http (Paul Rubin) Date: 26 Aug 2005 13:04:26 -0700 Subject: Any projects to provide Javascript-style client-side browser access via Python? References: Message-ID: <7xacj4o46t.fsf@ruckus.brouhaha.com> Kenneth McDonald writes: > I'm curious about this because, quite aside their function as web > browsers, it is now possible to build some very useable interfaces > using browsers with HTML, CSS, and JavaScript. (The biggest problem > is still the lack of a decent text widget.) However, JavaScript isn't > really a good language for building complex applications, and it > would be very cool if there were some way to use Python to replace > client-side JavaScript, in order to gain access the DOM. > > So anyone know if there are projects underway on this? Python isn't a good choice as a browser language because it doesn't have enough security. Hostile scripts can take over the interpreter too easily. There was a Python-based browser effort called Grail which I don't think got very far. Personally I think there are very few good uses for complex client side browser scripts. Most sites that use Javascript don't really need to. From lycka at carmen.se Fri Aug 19 11:28:19 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 19 Aug 2005 17:28:19 +0200 Subject: determine variable type In-Reply-To: References: Message-ID: MCollins at seminolecountyfl.gov wrote: > trying to determine a variable type, specifically that a variable is an > integer. > > i tried using type(var) but that only seemed to produce a response in the > command line. You mean that if you do "type(var)" at the Python prompt, it gives you a reply, but if you have a line with just that in a script, it doesn't? That has nothing to do with type checks. All Python expressions in Python work like that. In interactive use, unused results are echoed to the screen, but in scripts, they are not. How would you expect the echoed value to be useful in your program? In a script, you need to take care of the output of an expression to get any use from it. A standalone expression on a line of its own is legal Python code, but the result is thrown away... E.g. var = 6 type(var) # Works, but meaningless, noone will know what happened print type(var) # Like the interactive use (more or less) var_type = type(var) # Now you have a variable containing the result # of the expression. You can use that later if type(var) == int: # You can use the result in another construct... print "%i is an integer!" % var But don't worry so much about type checking. That's typically not so important in Python as is is in most other languages, in fact, if you try to handle types too strictly in Python, you are throwing away a lot of the benefits of Python's dynamic features. Perhaps your code is useful with other types than integers, such as the new decimal type or some upcoming money type. That typecheck might just make it impossible to use your code in some completely meaningful way. If you just did nothing, your code would probably throw an exception if 'var' had a type that didn't make sense, and handling that exception is probably not more difficult than to handle whatever action you planned to take if var wasn't an int... Python is much stricter in its type handling than e.g. C++, so don't worry so much. Trying to add a string to an int etc, will raise a sensible exception. It won't lead to any program crash or give any bizarre result to your calculations. If you're sanitizing user input, that's a good thing of course, but then the safe thing would be to read strings (e.g. via raw_input) and then inspect the string before you evaluate it or cast it to something else. Actually, int() does this pretty well, so you could just do: .while 1: # Loop until broken out of... . response = raw_input('Number please: ') . try: . var = int(response) . break . except ValueError: . print response, 'isn't a number!' From rkern at ucsd.edu Thu Aug 25 09:35:04 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 06:35:04 -0700 Subject: variable hell In-Reply-To: <430dc538@127.0.0.1> References: <430dc538@127.0.0.1> Message-ID: Nx wrote: > Hi > > I am unpacking a list into variables, for some reason they need to be > unpacked into variable names like a0,a1,a2....upto aN whatever is > in the list. Really? Why? -- 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 ray_usenet at yahoo.com Fri Aug 12 01:53:33 2005 From: ray_usenet at yahoo.com (Ray) Date: 11 Aug 2005 22:53:33 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <1123826013.339147.154530@g14g2000cwa.googlegroups.com> Thanks guys! Your explanations have cleared up things significantly. My transition from C++ to Java to C# was quite painless because they were so similar, but Python is particularly challenging because the concepts are quite different. (I always have this paranoid feeling: "Am I using Python to write Java, or using Python to write Python?") Regards, Ray Ray wrote: From lutz.horn at gmx.de Tue Aug 2 07:38:51 2005 From: lutz.horn at gmx.de (Lutz Horn) Date: 2 Aug 2005 11:38:51 GMT Subject: SOAPpy and http authentication References: Message-ID: <3l94aaF11la6sU1@individual.net> On 2005-08-02, Odd-R. wrote: > from SOAPpy import WSDL > from SOAPpy import URLopener > url= ' http://someserver/somewebservice > url1 = URLopener.URLopener(username='user',passwd='pass') > server=WSDL.Proxy(url1.open(url)) Is it possible to call WSDL.Proxy with a String? Then you could build the URL als http://user:pass at someserver/somewebservice. This works with SOAPpy.SOAPProxy. Lutz From berlin.brown at gmail.com Mon Aug 8 23:22:32 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Mon, 08 Aug 2005 23:22:32 -0400 Subject: Python Project (sigh with Java) In-Reply-To: References: Message-ID: could ildg wrote: > Good job~ > I also like both java and py so I always focus on jython, > but now it's being moved forward kinda slow. > I'm looking forward to jython 2.4. > > You're right, swing is great. wxpy is also wonderfu but it's so lack > of docs. I mainly work on windows so I use p4d(python for delphi), I > use delphi for UI and use py for some other works. p4d is magic, I > like it. And I recommend it to everyone who is familiar with both py > and delphi. > > On 8/9/05, Ramza Brown wrote: > >>I know you may frown at my use at java, but this is a pretty simple way >>to create GUIs quickly, using Java's swing. I have some code for an >>approach for integrating the swing GUI components and python. I threw >>the project together in a couple of days, so it is not some massive >>application. And, I have some little models(hehe). Anyway, if you want >>to check out an approach for working with Jython, here it is. >> >>Some questions, I do get asked, how do you us python code in java. I >>normally don't like using my python objects in the java code. >>Basically, there is never the *.java files. You can do everything in >>python, it is a lot simpler, short of language constructs you can only >>do in java. >> >>This is a HTML code generator, you only need a java runtime. >> >>http://www.newspiritcompany.com/phoenixproj.html >> >>-- >>Ramza from Atlanta >>http://www.newspiritcompany.com >>-- >>http://mail.python.org/mailman/listinfo/python-list >> And I normally don't take the entire python library with me. I just take 'jython.jar' so I can distribute it easier. -- Ramza from Atlanta http://www.newspiritcompany.com From alessandro.bottoni at infinito.it Fri Aug 26 09:29:56 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Fri, 26 Aug 2005 13:29:56 GMT Subject: Embedding Python in other programs References: Message-ID: Thomas Bartkus wrote: > Name: lib64python2.4-devel > Summary: The libraries and header files needed for Python development > > Description: The Python programming language's interpreter can be extended > with dynamically loaded extensions and can be embedded in other programs. > This package contains the header files and libraries needed to do these > types of tasks. > ------------------------------------------------------ > > > *** The Python programming language's interpreter ... can be embedded in > other programs. *** > > That's very intriguing! > But I can't seem to locate much information about this. > > Can anyone direct me to greater enlightenment? > Thomas Bartkus There is a section of the official documentation devoted to extending and embedding python: http://docs.python.org/ext/ext.html There are a few articles on this topics on the web, as well. Search "embedding python" with Google. ----------------------------------- Alessandro Bottoni From shantanoo at gmail.com Thu Aug 11 17:14:54 2005 From: shantanoo at gmail.com (????? ????? =?ISO-8859-1?Q?=28Shantanoo_Mahajan=29?=) Date: Fri, 12 Aug 2005 02:44:54 +0530 Subject: regex help References: <42fb345a$1@news.eftel.com> Message-ID: John Machin wrote: > jeff sacksteder wrote: >> Regex questions seem to be rather resistant to googling. >> >> My regex currently looks like - 'FOO:.*\n\n' >> >> The chunk of text I am attempting to locate is a line beginning with >> "FOO:", followed by an unknown number of lines, terminating with a >> blank line. Clearly the ".*" phrase does not match the single newlines >> occuring inside the block. >> >> Suggestions are warmly welcomed. > > I suggest you read the manual first: > """ > "." > (Dot.) In the default mode, this matches any character except a newline. > If the DOTALL flag has been specified, this matches any character > including a newline. > """ I think you need to write you own function. Something like: for x in open('_file_name'): if x == 'Foo:\n': flag=1 if x == '\n': flag=0 if flag == 1: print x if the line is 'FOO: _some_more_data_' you may try, if x.startswith('Foo:'): instead of if x == 'Foo:\n': Hope this help. Shantanoo From grflanagan at yahoo.co.uk Tue Aug 30 14:51:42 2005 From: grflanagan at yahoo.co.uk (Gerard Flanagan) Date: 30 Aug 2005 11:51:42 -0700 Subject: Python2Html regex question References: <1125422888.376223.19970@z14g2000cwz.googlegroups.com> Message-ID: <1125427902.697619.230170@g44g2000cwa.googlegroups.com> Perfect. Thanks Trent. Gerard From dominant500 at comcast.net Wed Aug 17 17:07:05 2005 From: dominant500 at comcast.net (Mark) Date: 17 Aug 2005 14:07:05 -0700 Subject: Moinmoin config Message-ID: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> Hi, I have Moinmoin 1.3.4 installed and working on Linux RHEL3.0. However, all screen elements are lined up on the left hand side. How can I get it displayed like the wiki at: http://moinmoin.wikiwikiweb.de/HelpOnConfiguration instead of this ? -> LANShieldOS Release Notes Search: * MarkRuedy * UserPreferences * HelpOnEditing * HelpContents * HelpForBeginners * UserPreferences * FrontPage * RecentChanges * FindPage * HelpContents * Edit * Show Changes * Get Info * Subscribe * FrontPage From tim.golden at viacom-outdoor.co.uk Tue Aug 23 12:08:07 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue, 23 Aug 2005 17:08:07 +0100 Subject: How to execute python script in Windows Message-ID: <9A28C052FF32734DACB0A288A3533991044D21E5@vogbs009.gb.vo.local> [David Fickbohm] > People, > Can someone please tell me how to execute a python script in windows? > Thanks > Dave Have a look at this: http://www.python.org/doc/faq/windows.html#how-do-i-run-a-python-program-under-windows 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 tjreedy at udel.edu Wed Aug 31 13:04:56 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2005 13:04:56 -0400 Subject: can't start new thread References: <1125506166.505956.144570@f14g2000cwb.googlegroups.com> Message-ID: "jdonnell" wrote in message news:1125506166.505956.144570 at f14g2000cwb.googlegroups.com... > I'm using Python 2.2.3 on a custom vps version of FC1. I am pretty sure there have been thread-related bug fixes since then. Trying the latest release (even if you can't use it for production) might give you some idea of the source of the failure (Python versus your OS). Terry J. Reedy From bokr at oz.net Tue Aug 9 14:18:38 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 09 Aug 2005 18:18:38 GMT Subject: namespaces References: <42f8c492$1@nntp0.pdx.net> Message-ID: <42f8e67a.1015992700@news.oz.net> On Tue, 09 Aug 2005 08:35:38 -0700, Scott David Daniels wrote: >Paolino wrote: >> Peter Otten wrote: >>> Paolino wrote: >>>> Why descriptor mechanism doesn't apply to modules? >>> Because modules are instances of the module class and the descriptor >>> has to be defined in the class in order to work with the instance.... >> Then there is no way of having descriptors at module level,as 'module' >> class is not updatable. > >Well, an entry in the dictionary "sys.modules" is what is returned by >imports, so you could either pre-replace or post-replace a module by >an object which uses the descriptor technique to get to some (but not >necessarily all) of the attributes. Think of this technique as a >hack to get to a goal, rather than a good technique to use; good for >debugging, not so nice for production work. If you still don't know >how to do this from this admittedly sketchy description, I'd suggest >you avoid trying it altogether. > I had the thought a while ago that it might be interesting to have an import variant that could produce a subclassed module, where you indicate the import name as usual (for __import__) and also supply the subclass source text as an argument (string or file). E.g., something like subclass_source = """\ class MyModule(math): twopi = property(lambda: math.pi*2.0') """ module_with_property = subclassing_import('math', subclass=subclass_source) Another thought/bf would be a way to extend the attribute namespace of an arbitrary object by chaining the attribute name spaces of a sequence of objects (this would be a language mod) e.g., (sort of a dynamic instance attribute mixin) obj ..= a, b, c # a sequence of objects then obj.x # looks for obj.x, then a.x then b.x then c.x before giving up with attribute error obj ..=() # clears chained attribute name space ? Then you could add a property to the namespace of a module by adding an object whose class defines the property, like mod ..= objhavingproperty # same tuple ambiguity as with 'somestr' % x something analogous to += on immutables would have to be done for builtin objects I suppose. Just adding more mulch/worms to the idea garden ;-) Regards, Bengt Richter From nas at arctrix.com Sat Aug 6 06:23:42 2005 From: nas at arctrix.com (Neil Schemenauer) Date: Sat, 6 Aug 2005 04:23:42 -0600 Subject: PEP: Generalised String Coercion Message-ID: <20050806102342.GA11309@mems-exchange.org> The title is perhaps a little too grandiose but it's the best I could think of. The change is really not large. Personally, I would be happy enough if only %s was changed and the built-in was not added. Please comment. Neil PEP: 349 Title: Generalised String Coercion Version: $Revision: 1.2 $ Last-Modified: $Date: 2005/08/06 04:05:48 $ Author: Neil Schemenauer Status: Draft Type: Standards Track Content-Type: text/plain Created: 02-Aug-2005 Post-History: 06-Aug-2005 Python-Version: 2.5 Abstract This PEP proposes the introduction of a new built-in function, text(), that provides a way of generating a string representation of an object without forcing the result to be a particular string type. In addition, the behavior %s format specifier would be changed to call text() on the argument. These two changes would make it easier to write library code that can be used by applications that use only the str type and by others that also use the unicode type. Rationale Python has had a Unicode string type for some time now but use of it is not yet widespread. There is a large amount of Python code that assumes that string data is represented as str instances. The long term plan for Python is to phase out the str type and use unicode for all string data. Clearly, a smooth migration path must be provided. We need to upgrade existing libraries, written for str instances, to be made capable of operating in an all-unicode string world. We can't change to an all-unicode world until all essential libraries are made capable for it. Upgrading the libraries in one shot does not seem feasible. A more realistic strategy is to individually make the libraries capable of operating on unicode strings while preserving their current all-str environment behaviour. First, we need to be able to write code that can accept unicode instances without attempting to coerce them to str instances. Let us label such code as Unicode-safe. Unicode-safe libraries can be used in an all-unicode world. Second, we need to be able to write code that, when provided only str instances, will not create unicode results. Let us label such code as str-stable. Libraries that are str-stable can be used by libraries and applications that are not yet Unicode-safe. Sometimes it is simple to write code that is both str-stable and Unicode-safe. For example, the following function just works: def appendx(s): return s + 'x' That's not too surprising since the unicode type is designed to make the task easier. The principle is that when str and unicode instances meet, the result is a unicode instance. One notable difficulty arises when code requires a string representation of an object; an operation traditionally accomplished by using the str() built-in function. Using str() makes the code not Unicode-safe. Replacing a str() call with a unicode() call makes the code not str-stable. Using a string format almost accomplishes the goal but not quite. Consider the following code: def text(obj): return '%s' % obj It behaves as desired except if 'obj' is not a basestring instance and needs to return a Unicode representation of itself. In that case, the string format will attempt to coerce the result of __str__ to a str instance. Defining a __unicode__ method does not help since it will only be called if the right-hand operand is a unicode instance. Using a unicode instance for the right-hand operand does not work because the function is no longer str-stable (i.e. it will coerce everything to unicode). Specification A Python implementation of the text() built-in follows: def text(s): """Return a nice string representation of the object. The return value is a basestring instance. """ if isinstance(s, basestring): return s r = s.__str__() if not isinstance(r, basestring): raise TypeError('__str__ returned non-string') return r Note that it is currently possible, although not very useful, to write __str__ methods that return unicode instances. The %s format specifier for str objects would be changed to call text() on the argument. Currently it calls str() unless the argument is a unicode instance (in which case the object is substituted as is and the % operation returns a unicode instance). The following function would be added to the C API and would be the equivalent of the text() function: PyObject *PyObject_Text(PyObject *o); A reference implementation is available on Sourceforge [1] as a patch. Backwards Compatibility The change to the %s format specifier would result in some % operations returning a unicode instance rather than raising a UnicodeDecodeError exception. It seems unlikely that the change would break currently working code. Alternative Solutions Rather than adding the text() built-in, if PEP 246 were implemented then adapt(s, basestring) could be equivalent to text(s). The advantage would be one less built-in function. The problem is that PEP 246 is not implemented. Fredrik Lundh has suggested [2] that perhaps a new slot should be added (e.g. __text__), that could return any kind of string that's compatible with Python's text model. That seems like an attractive idea but many details would still need to be worked out. Instead of providing the text() built-in, the %s format specifier could be changed and a string format could be used instead of calling text(). However, it seems like the operation is important enough to justify a built-in. Instead of providing the text() built-in, the basestring type could be changed to provide the same functionality. That would possibly be confusing behaviour for an abstract base type. Some people have suggested [3] that an easier migration path would be to change the default encoding to be UTF-8. Code that is not Unicode safe would then encode Unicode strings as UTF-8 and operate on them as str instances, rather than raising a UnicodeDecodeError exception. Other code would assume that str instances were encoded using UTF-8 and decode them if necessary. While that solution may work for some applications, it seems unsuitable as a general solution. For example, some applications get string data from many different sources and assuming that all str instances were encoded using UTF-8 could easily introduce subtle bugs. References [1] http://www.python.org/sf/1159501 [2] http://mail.python.org/pipermail/python-dev/2004-September/048755.html [3] http://blog.ianbicking.org/illusive-setdefaultencoding.html Copyright This document has been placed in the public domain. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 End: From foo at bar.org Sun Aug 7 16:44:09 2005 From: foo at bar.org (stasz) Date: Sun, 07 Aug 2005 22:44:09 +0200 Subject: gettext again References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> Message-ID: On Sun, 07 Aug 2005 21:33:21 +0200, cantabile wrote: > stasz a ?crit : >> On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote: >> >> >>>Hi, >>>I'm failing to make it work but can't find out what's wrong. Here's what >>>I do : >> >> [....] >> >>>How come ? What's wrong with what I am doing ? >> >> Start with this little howto about gettext. >> http://childsplay.sourceforge.net/translate-howto.html >> >> And then do this in your test.py: >> http://www.python.org/doc/2.4.1/lib/node330.html >> >> You should read the part about gettext in the Python Library Reference >> it's really good :-) >> >> Good luck, >> Stas Z >> >> > > Well, I must be dumb, because I did exactly that and it still doesn't > work... > > BTW, I have no pygettext module. I asked here and somebody said it was > deprecated and now included in xgettext. > And I've read the Python doc about gettext about ten times, but it seems > quite outdated since it calls pygettext (as staded above)... > > I've read the info pages of gettext too (quite a long work). Ok, you should use xgettext to create a .po file from your test1.py. Translate that file and use msgfmt to compile it into a .mo file. Copy this .mo file to /usr/share/locale/fr/LC_MESSAGES/ > Here's my test1.py file again : > > =========================== > import gettext, os, locale > > locale.setlocale(locale.LC_ALL) > gettext.install('test1.py', '/usr/share/locale') test1.py is wrong, you must give the name of the .mo file. It must be: gettext.install('test1.mo', '/usr/share/locale') Assuming you have called the mo file like that. Stas Z From spammers-go-here at spam.invalid Tue Aug 9 16:45:31 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Tue, 09 Aug 2005 16:45:31 -0400 Subject: pyuic and Qt Designer plugins Message-ID: <42f915e2$0$18641$14726298@news.sunsite.dk> Hi I managed to compile and install the FileChooser plugin (.so file) in /usr/share/qt3/plugins/designer and use it in my form in Designer. Then I tried to use pyuic which generated the .py code from the ui file. An attempt to execute the python file quits with : Traceback (most recent call last): File "measure.py", line 16, in ? f = MEASURE() File "/home/m_singh/measure.py", line 422, in __init__ self.fileChooser1 = FileChooser(self.groupBox4,"fileChooser1") NameError: global name 'FileChooser' is not defined The wrapper in my .py file : from qt import * from measure import * import sys if __name__ == "__main__": app = QApplication(sys.argv) f = MEASURE() f.show() app.setMainWidget(f) app.exec_loop() What do I need to do to include the FileChooser plugin ? Thanks. From donn at u.washington.edu Fri Aug 19 13:26:10 2005 From: donn at u.washington.edu (Donn Cave) Date: Fri, 19 Aug 2005 10:26:10 -0700 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> Message-ID: In article <91nNe.620$zD3.198 at newssvr29.news.prodigy.net>, Bryan Olson wrote: > km wrote: > > Hi all, > > > > is true parallelism possible in python ? or atleast in the > > coming versions ? is global interpreter lock a bane in this > > context ? > > No; maybe; and currently, not usually. > > On a uniprocessor system, the GIL is no problem. On multi- > processor/core systems, it's a big loser. I rather suspect it's a bigger winner there. Someone who needs to execute Python instructions in parallel is out of luck, of course, but that has to be a small crowd. I would have to assume that in most applications that need the kind of computational support that implies, are doing most of the actual computation in C, in functions that run with the lock released. Rrunnable threads is 1 interpreter, plus N "allow threads" C functions, where N is whatever the OS will bear. Meanwhile, the interpreter's serial concurrency limits the damage. The unfortunate reality is that concurrency is a bane, so to speak -- programming for concurrency takes skill and discipline and a supportive environment, and Python's interpreter provides a cheap and moderately effective support that compensates for most programmers' unrealistic assessment of their skill and discipline. Not that you can't go wrong, but the chances you'll get nailed for it are greatly reduced - especially in an SMP environment. Donn Cave, donn at u.washington.edu From could.net at gmail.com Mon Aug 8 01:13:32 2005 From: could.net at gmail.com (could ildg) Date: Mon, 8 Aug 2005 13:13:32 +0800 Subject: How to determine that if a folder is empty? Message-ID: <311b5ce1050807221323f7436e@mail.gmail.com> I want to check if a folder named "foldername" is empty. I use os.listdir(foldername)==[] to do this, but it will be very slow if the folder has a lot of sub-files. Is there any efficient ways to do this? Thanks~ From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 11 12:11:33 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 11 Aug 2005 18:11:33 +0200 Subject: What is Python?! In-Reply-To: <42faccb9$1@news.orcon.net.nz> References: <42fa51db$0$7802$626a14ce@news.free.fr> <42faccb9$1@news.orcon.net.nz> Message-ID: <3m1bllF14k27oU3@individual.net> Evil Bastard wrote: > bruno modulix wrote: >> You can tell buy the most common use. bash is a scripting language, >> javascript is a scripting language, perl is a scripting language, php is >> a scripting language, Python is *not* a scripting language !-) > > Perhaps a better definition - the term 'scripting language' is > increasingly being used by CTOs as a justification for saving money by > putting large chunks of their workforces on lower pay scales - an > attitude of 'scripters aren't as skilled as real programmers, so don't > deserve the same pay'. > > To me, the term is archic. What 'scripting language' means to me is: > 1. insufficient facilities for general purpose or 'serious' programming > 2. ability to get simple useful programs up and working quickly > 3. absence of a hack/compile/link/test cycle. My view too. > What makes 1 and 3 redundant is that linkage mechanisms have diversified > over the years. For instance, java and python's 'import' statements, > java's CLASSPATH and python's 'sys.path'. > > I guess a language could be called a 'scripting language' if: > - the source code can be executed directly, and/or > - source need not be converted to a separate file in a > non-human-readable format before it can be executed, and/or > - a change to the source file automatically causes a change in > runtime behaviour > > By these, Python is most definitely a scripting language, and joins Perl > and PHP. Whereas changes to java source files don't change runtime > behaviour. Though they prefer to be called "agile languages" nowadays. Reinhold From kristian.zoerhoff at gmail.com Tue Aug 30 13:50:55 2005 From: kristian.zoerhoff at gmail.com (Kristian Zoerhoff) Date: Tue, 30 Aug 2005 12:50:55 -0500 Subject: trouble with time --again In-Reply-To: <1125423761.517155.162710@g44g2000cwa.googlegroups.com> References: <1125423761.517155.162710@g44g2000cwa.googlegroups.com> Message-ID: <3511dc75050830105013460263@mail.gmail.com> On 30 Aug 2005 10:42:41 -0700, nephish at xit.net wrote: > Hey there, > could someone show me where i am going wrong here? > > >>> date1 = '2005-01-01 8:20:00' > >>> date1 = strptime('%Y-%m-%d %H:%M:%S',date1) > > raise ValueError("time data did not match format: data=%s fmt=%s" % > ValueError: time data did not match format: data=%Y-%m-%d%H:%M:%S > fmt=2005-01-01 8:20:00 Try: >>> date1 = strptime(date1, '%Y-%m-%d %H:%M:%S') I think you have the data and format strings swapped. -- Kristian kristian.zoerhoff(AT)gmail.com zoerhoff(AT)freeshell.org From roy at panix.com Tue Aug 9 23:06:42 2005 From: roy at panix.com (Roy Smith) Date: Tue, 09 Aug 2005 23:06:42 -0400 Subject: Python supports LSP, does it? References: <86wtmuk0c5.fsf@bhuda.mired.org> Message-ID: Andy Leszczynski writes: > Is not LSP more a quality of the desing of class hierachy rather then > language itslef? Comments? I do agree that LSP is more a class hierarchy thing than a language thing. For example, it's easy in Python to write a LSP-violating set of classes: class base: def f(self): print "I am base" class child (base): f = "not a function" Since you can call base.f(), LSP says you should also be able to call child.f(). Well, I suppose you can, but most people would not consider throwing a TypeError to satisfy the LSP :-). Mike Meyer wrote: > It's not a true statement. Nothing in the language enforces LSP. In > fact, there's not even a [way?] when a function/method is invoked to make > sure the type passed in is a subtype of the type you expect Well, that's not entirely true. I could write: def func (self, obj): assert (isinstance (obj, baseClass)) It's sort of un-pythonic, but the language certainly lets you do it if you really want to. From bokr at oz.net Thu Aug 11 17:15:40 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 11 Aug 2005 21:15:40 GMT Subject: need help with python syntax References: <1123786609.621111.324390@g49g2000cwa.googlegroups.com> Message-ID: <42fbb8c4.1200898821@news.oz.net> On 11 Aug 2005 11:56:49 -0700, "yaffa" wrote: >dear python gurus, > >quick question on syntax. > >i have a line of code like this > >for incident in bs('tr', {'bgcolor' : '#eeeeee'}): > > >what i want it to do is look for 'bgcolor' : '#eeeeee' or 'bgcolor' : >'white' and then do a whole bunch of stuff. > >i've tried this: > >for incident in bs('tr', {'bgcolor' : '#eeeeee'} or {'bgcolor' : >'white'} ): but it only seems to pick up the stuff from the >{'bgcolor' : '#eeeeee'} > > >any ideas folks? > First, what is bs (LOL, sorry ;-) ? Is it a function or class constructor that returns an iterator? What do you expect incident successively to be bound to as you iterate? Note that {'bgcolor':'#eeeeee'} or {'bgcolor' :'white'} is an expression that is guaranteed never to evaluate to the 'or' part, (and always to the first part) since bool({'bgcolor':'#eeeeee'}) is always True. BTW, if you have a dict d which might define 'bgcolor' as '#eeeeee' or 'white' you could check for either white something like (untested) if d['bgcolor'] in ('#eeeeee', 'white'): # put most common white code first for better speed print 'white' else: print 'not my idea of white' or if you had a LOT of codes to check (for white or whatever) you could check them faster using a set, e.g., whites = set('#eeeeee white #dddddd'.split()) # not a LOT ;-) if d['bgcolor'] in whites: print 'white, sort of' ... Regards, Bengt Richter From spammers-go-here at spam.invalid Tue Aug 30 17:25:14 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Tue, 30 Aug 2005 17:25:14 -0400 Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk> Message-ID: <4314ce74$0$18648$14726298@news.sunsite.dk> Madhusudan Singh wrote: > Hi > > I am using time.clock() to get the current time of the processor in > seconds. For my application, I need really high resolution but currently > seem to be limited to 0.01 second. Is there a way to specify the > resolution (say 1-10 microseconds) ? My processor is a 1.4 MHz Intel > processor. Surely, it should be able to report times a few (or at least > 10) microseconds apart. > > Thanks. Correcting a typo (1.4GHz, not 1.4 MHz). And I am using Linux. From konrad at my-rho.de Tue Aug 23 10:44:54 2005 From: konrad at my-rho.de (=?ISO-8859-1?Q?Konrad_M=FChler?=) Date: Tue, 23 Aug 2005 16:44:54 +0200 Subject: Convert float to string ... Message-ID: Hi, a simple question but i found no solution: How can i convert a float value into a string value? string_value1 = string(float_value) + ' abc' doesn't work ... Thanks Konrad From dmqatpobox.com Fri Aug 26 21:26:15 2005 From: dmqatpobox.com (David MacQuigg) Date: Fri, 26 Aug 2005 18:26:15 -0700 Subject: Licensing and Other Questions References: Message-ID: <4ufvg1hnlgu16lcnaduk9d3eto3nk2jflv@4ax.com> On Sat, 27 Aug 2005 01:35:58 +0300, Christos Georgiou wrote: >Your method is/will_not be free (as in beer), as hinted in >http://www.ece.arizona.edu/~edatools/home/email/registry/Form-Sender01.htm >. *That* is a drawback similar to the licensing of the Microsoft's >Sender/Caller-ID scheme. Why not support open, free standards? These are fees for services, not license fees. I don't know how you could miss that. The code is offered under the Python licence, which is the most unrestrictive of any license I know about. One of my goals is to provide an open-source version of what big companies are now paying millions for - spam appliances with proprietary methods. On Fri, 26 Aug 2005 23:20:05 GMT, jjl at pobox.com (John J. Lee) wrote: >[David, in an earlier email] >> reject. 15% will get an immediate accept without filtering, because >> the sender is authenticated and has a good reputation. Eventually, >> all reputable senders will join the 15%, and the 5% will shrink to >> where we can ignore it. > >Two questions you seem to be implicitly assuming particular answers >to: Is widespread authentication a good thing? Does it solve any >problem not solved by Bayesian filtering plus good mail client >support? My first reaction is to answer "no" to both questions, so to >regard your effort as harmful. Might be interesting to hear why you >think it's a good thing, though. I really didn't intend for this to be a discussion of the merits of filtering vs authentication. I worry this will be a long discussion, with no satisfactory conclusion, so I suggest we move these topics to one of the email security forums. My conclusion, after participating in many such discussions, is that both filtering and authentication are necessary tools, and a complete system should have both. -- Dave From berlin.brown at gmail.com Sat Aug 20 17:15:55 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Sat, 20 Aug 2005 17:15:55 -0400 Subject: Python Light Revisted? In-Reply-To: <1124568446.496146.247180@g47g2000cwa.googlegroups.com> References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: Steve M wrote: > I agree with you in part and disagree in part. > > I don't see the point to making the distribution any smaller. 10MB for > the installer from python.org, 16MB for ActiveState .exe installer. How > is 5MB "lightweight" while 10MB isn't? The Windows XP version of Java > at java.com is 16+ MB, and the .NET framework is, well, I don't know > how big, but I doubt it's much less than 10MB. > > Also I think it's a terrible idea to distribute without pieces of the > standard library if the distribution is meant to be developed against > for arbitrary applications. (If you just want a slimmed down Python for > one specific application, use py2exe - I think it only includes > whatever gets imported for your program to run.) And excluding zip > while including Twisted? I don't get it. Besides, how do you know > Twisted doesn't import XML-RPC? I could see an enlarged Python that > includes Twisted along with the standard library, and in fact > ActiveState's includes win32 stuff. There's another such > mega-distribution around, the name of which escapes me at the moment. > But removing zip from the standard library so you can save 20kb seems > foolish. (Again, unless it is for one specific application, in which > case py2exe should do the trick, although I could be wrong about that > since I've never used it.) > > Now, what I do agree with is a Python that can be run from a folder > without having to be installed on the system. That could have lots of > benefits, if the details with pythonpath and whatever could be sorted > out. For example I haven't upgraded to 2.4 yet because I have 20 > different packages (e.g. SOAPpy, ZODB, whatever) installed on WinXP, > many of which required me selecting my 2.3 installation when I > installed them. I have no idea what will happen to all those if I run > the ActiveState installer for 2.4. I seem even to remember reading that > I have to un-install 2.3 before installing 2.4. I don't want to > re-install those 20 packages. Anyway I haven't had time to research it > and it isn't pressing, even though I'd like to start trying decorators > and generator expressions. > Also, py2exe will work '100%' without a host python install. I have never used it. I have my doubts though? -- Ramza from Atlanta http://www.newspiritcompany.com From zen19725 at zen.co.uk Mon Aug 1 17:18:36 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 1 Aug 2005 22:18:36 +0100 Subject: Is this Pythonic? References: Message-ID: On Mon, 01 Aug 2005 22:01:06 +0200, Caleb Hattingh wrote: >Peter > >To my mind, this kind of setup (interface class, or abstact class) is more >usually used in static languages to benefit polymorphism - but python is >dynamically typed, so in which situations would this setup be useful in a >python program? You see, I expected your post to say that it wouldn't >even be necessary, but you didn't :) I realise it's not necessary. I just thought it would be nice to document the interfaces my concrete classes will be using. >I have spent a little effort training myself not to bother setting up >class hierarchies like this in python, due to the fact that I use Delphi a >lot at work (I do pretty much the code below to let myself know when an >inherited/abstract class method is being called in error). I started doing OO stuff with Smalltalk, where it isn't necessary, then moved to C++, where it is, and liked it. -- Email: zen19725 at zen dot co dot uk From daniel.einstein at pnl.gov Sat Aug 20 22:39:22 2005 From: daniel.einstein at pnl.gov (Einstein, Daniel R) Date: Sat, 20 Aug 2005 19:39:22 -0700 Subject: incorect version Message-ID: <0DF798CBF125BF4AA1227F26431C29BDD73686@pnlmse27.pnl.gov> Hello, I am working with a code that has python embedded in it. The embedded python points to my local python. Outside of the embedding application, I can import a third part module (wrapped ITK). When, I attempt to import the same module from within the embedding application, it fails with the message 'possible version mismatch'. Also, this module was built against my local python. In short, there can be no version mismatch because it is all the same pyhton. Can anyone shed some light on this? I do not know much about the embedding of python. In my case, I do know that the libpython23.a and libnumeric.a libraries are somehow involved. These may be the culprits as I need to include particular version in my build. Again, any light to be shed? Thanks so much Dan Daniel R Einstein, PhD Biological Monitoring and Modeling Pacific Northwest National Laboratory P.O. Box 999; MSIN P7-59 Richland, WA 99352 Tel: 509/ 376-2924 Fax: 509/376-9064 daniel.einstein at pnl.gov From cam.ac.uk at mh391.invalid Fri Aug 12 20:06:04 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sat, 13 Aug 2005 01:06:04 +0100 Subject: Python Challenge on BBC In-Reply-To: References: Message-ID: Python Challenge also got mentioned on MetaFilter. But as "Python Challange" [sic]. -- Michael Hoffman From ray_usenet at yahoo.com Fri Aug 12 21:58:08 2005 From: ray_usenet at yahoo.com (Ray) Date: 12 Aug 2005 18:58:08 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123879800.675531.319370@g47g2000cwa.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123857710.987790.285330@o13g2000cwo.googlegroups.com> <42fccc42$0$32450$626a14ce@news.free.fr> <1123864878.820070.232350@g14g2000cwa.googlegroups.com> <1123879800.675531.319370@g47g2000cwa.googlegroups.com> Message-ID: <1123898288.052685.50520@g44g2000cwa.googlegroups.com> gene tani wrote: > I think you'll like python. > > http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing > http://dirtsimple.org/2004/12/java-is-not-python-either.html > > (and python-is-not-java) Thanks gene, these are exactly the stuff I wanna know more about. Ray From mhellwig at xs4all.nl Fri Aug 5 13:49:13 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Fri, 05 Aug 2005 19:49:13 +0200 Subject: The ONLY thing that prevents me from using Python In-Reply-To: References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <42f37b5a$0$11075$e4fe514c@news.xs4all.nl> Message-ID: <42f3a6a6$0$11070$e4fe514c@news.xs4all.nl> Magnus Lycka wrote: > Martin P. Hellwig wrote: > >> Kevin wrote: >> >> >> Well, for some strange reason I have never found that to be a problem. > > > If you develop software for an external customer, and they have > an existing web site run by some ISP that you have no control over, > this might well be a problem. Yes indeed there are a *load of companies not interested in technology they just want a fancier web page then their rivals, for them this is definitely a problem well actually it's a problem for the developer. Do you tell the client to do it your way or do you do it their way. It all depends, I work in and for non-profit organization so I mostly I can do what I think is the best solution. I'll explain that and what the advantage or dis-advantage is of all different possibilities. > > Even if the customer is in control of their web servers, it might be > difficult to convince them to install and maintain something like > Python on them. > > I find it a bit surprising that so many people on comp.lang.python > don't realize what kind of practical complications most commercial > software developers have to struggle with if they don't just follow > the mainstream and use PHP or Java for all web apps. Yeah well, I remember that I had a hard time getting java support instead of cgi alone, then somewhat later I've had that with perl and PHP and whatever, it always feels like playing catch up. I really had it with all that begging to get this or that supported. I've been bitten so many times over support issues that it isn't even funny anymore, so in the end I realized that the only way to get it down in a acceptable way is to do it myself or source it to a small company that needs the customer. > > My ISP (FS Data in Sweden) has Python installed, and always upgraded > it when I asked them (but only then, so I suspect I'm the only user-- > and this is one of the biggest ISPs in Sweden). As I said above, I found it more likely to get support from smaller companies then the bigger ones. > > Even if I have access to Python, they don't allow me to have my own > long running processes, so I'm stuck with CGI, which wouldn't work > very well with a much higher load than my moin has. (Actually, I > didn't really need more, so I haven't asked for mod_python support > etc.) > > Colocation is certainly getting much cheaper, my ISP charges much less > than 95EUR/month.(295 SEK). Still, it would certainly be great if > mod_python, twisted and zope support etc would be as common as mod_perl > or PHP support. We can only get that if we actively ask for it, and if > we really favour vendors that provide this support when we can. But overall I must say the I agree with you, and that this chicken/egg problem can only be resolved by further popularity of python. -- mph From francois.perche at gmail.com Sun Aug 14 17:17:04 2005 From: francois.perche at gmail.com (perchef) Date: 14 Aug 2005 14:17:04 -0700 Subject: wx.MessageDialog displayed without components inside In-Reply-To: References: <1123951035.856439.173160@g44g2000cwa.googlegroups.com> <1123976057.103585.237410@z14g2000cwz.googlegroups.com> <1124030710.688098.299040@o13g2000cwo.googlegroups.com> Message-ID: <1124054224.426825.308300@z14g2000cwz.googlegroups.com> yes, it did work. From iamsidd at gmail.com Tue Aug 30 00:32:05 2005 From: iamsidd at gmail.com (Sidd) Date: 29 Aug 2005 21:32:05 -0700 Subject: Writing Multithreaded Client-Server in Python. Message-ID: <1125376325.572881.163770@g44g2000cwa.googlegroups.com> Hi, I tried finding and example of multithreaded client-serve program in python. Can any one please tell me how to write a multithreaded client-server programn in python such that 1.It can handle multiple connections 2.It uses actual threads and not select() or some other function From simon.brunning at gmail.com Wed Aug 10 10:23:49 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Wed, 10 Aug 2005 15:23:49 +0100 Subject: "Ordered" dicts In-Reply-To: References: <8c7f10c605081006489f9ea3a@mail.gmail.com> Message-ID: <8c7f10c6050810072363446624@mail.gmail.com> On 8/10/05, Chris Cioffi wrote: > While the sorted() built in addressed (yet another) community desire, I > don't think this addresses the underlying expectation of getting dictionary > keys in some order. You do get them in *some* order. ;-) > It works, but it feel like a kludge to me. To me, it's elegant. Want the keys? Call .keys(). Want them sorted? Call sorted(). Each tool does one job well. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From bokr at oz.net Thu Aug 18 19:25:11 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 18 Aug 2005 23:25:11 GMT Subject: question about binary and serial info References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <1124386952.353027.93050@g47g2000cwa.googlegroups.com> Message-ID: <430510da.1813212441@news.oz.net> On 18 Aug 2005 10:42:32 -0700, nephish at xit.net wrote: >>>> import serial >>>> ser =3D serial.Serial('/dev/ttyS0', 2400, timeout=3D 10, bytesize=3D8, = >stopbits=3D1) >>>> a =3D ser.read(1) >>>> print a >^ In general, print a is not a good way to investigate what a is, because print uses str(a) as a conversion, and when the original a is type str, that doesn't change the data being fed to the presentation process (which BTW will encode the characters depending on the coding scheme for your display output, or other destination encoding info). print repr(a) will get you a string representation of a that is guaranteed to be printable, so that if a is a str type containing unprintable characters, you will see them all represented, e.g., >>> a = '\x01\x02\x20\x41\x42\x43\x20\x30\x31\x32' >>> print a ?? ABC 012 >>> print repr(a) '\x01\x02 ABC 012' or, interactively, just >>> a '\x01\x02 ABC 012' although for convenience None is not printed when evaluated interactively: >>> b = None >>> b >>> print repr(b) None (interactively, it would be a nuisance when invoking functions that don't return results, since they in actuality do return None by default). Sometime it is hard to see the separate characters with printables and \-escaped characters all joined together. list(a) is an easy way to separate them: >>> a '\x01\x02 ABC 012' >>> print list(a) ['\x01', '\x02', ' ', 'A', 'B', 'C', ' ', '0', '1', '2'] or just >>> list(a) ['\x01', '\x02', ' ', 'A', 'B', 'C', ' ', '0', '1', '2'] The trick is to keep in mind that there is some abstraction that is being represented in various ways, and make allowances for people's saying "hex" when they mean the binary that the hex (characters matching [0-9A-Fa-f]) representation is representing, and similarly with other abstractions (e.g. binary ;-) and their representations (e.g., string representations of binary, or DRAM state representations of binary, etc.) HTH Regards, Bengt Richter From alanmk at hotmail.com Mon Aug 29 13:32:13 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Mon, 29 Aug 2005 18:32:13 +0100 Subject: python xml DOM? pulldom? SAX? In-Reply-To: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> References: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> Message-ID: [jog] > I want to get text out of some nodes of a huge xml file (1,5 GB). The > architecture of the xml file is something like this [snip] > I want to combine the text out of page:title and page:revision:text > for every single page element. One by one I want to index these > combined texts (so for each page one index) > What is the most efficient API for that?: > SAX ( I don?t thonk so) SAX is perfect for the job. See code below. > DOM If your XML file is 1.5G, you'll need *lots* of RAM and virtual memory to load it into a DOM. > or pulldom? Not sure how pulldom does it's pull "optimizations", but I think it still builds an in-memory object structure for your document, which will still take buckets of memory for such a big document. I could be wrong though. > Or should I just use Xpath somehow. Using xpath normally requires building a (D)OM, which will consume *lots* of memory for your document, regardless of how efficient the OM is. Best to use SAX and XPATH-style expressions. You can get a limited subset of xpath using a SAX handler and a stack. Your problem is particularly well suited to that kind of solution. Code that does a basic job of this for your specific problem is given below. Note that there are a number of caveats with this code 1. characterdata handlers may get called multiple times for a single xml text() node. This is permitted in the SAX spec, and is basically a consequence of using buffered IO to read the contents of the xml file, e.g. the start of a text node is at the end of the last buffer read, and the rest of the text node is at the beginning of the next buffer. 2. This code assumes that your "revision/text" nodes do not contain mixed content, i.e. a mixture of elements and text, e.g. "This is a piece of revision text. The below code will fail to extract all character data in that case. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= import xml.sax class Page: def append(self, field_name, new_value): old_value = "" if hasattr(self, field_name): old_value = getattr(self, field_name) setattr(self, field_name, "%s%s" % (old_value, new_value)) class page_matcher(xml.sax.handler.ContentHandler): def __init__(self, page_handler=None): xml.sax.handler.ContentHandler.__init__(self) self.page_handler = page_handler self.stack = [] def check_stack(self): stack_expr = "/" + "/".join(self.stack) if '/parent/page' == stack_expr: self.page = Page() elif '/parent/page/title/text()' == stack_expr: self.page.append('title', self.chardata) elif '/parent/page/revision/id/text()' == stack_expr: self.page.append('revision_id', self.chardata) elif '/parent/page/revision/text/text()' == stack_expr: self.page.append('revision_text', self.chardata) else: pass def startElement(self, elemname, attrs): self.stack.append(elemname) self.check_stack() def endElement(self, elemname): if elemname == 'page' and self.page_handler: self.page_handler(self.page) self.page = None self.stack.pop() def characters(self, data): self.chardata = data self.stack.append('text()') self.check_stack() self.stack.pop() testdoc = """ Page number 1 p1 r1 revision one Page number 2 p2 r2 revision two """ def page_handler(new_page): print "New page" print "title\t\t%s" % new_page.title print "revision_id\t%s" % new_page.revision_id print "revision_text\t%s" % new_page.revision_text print if __name__ == "__main__": parser = xml.sax.make_parser() parser.setContentHandler(page_matcher(page_handler)) parser.setFeature(xml.sax.handler.feature_namespaces, 0) parser.feed(testdoc) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= HTH, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From lemon97 at gmail.com Sun Aug 7 21:58:24 2005 From: lemon97 at gmail.com (lemon97 at gmail.com) Date: 7 Aug 2005 18:58:24 -0700 Subject: Splitting a string into groups of three characters Message-ID: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Hi, Is there a function that split a string into groups, containing an "x" amount of characters? Ex. TheFunction("Hello World",3) Returns: ['Hell','o W','orl','d'] Any reply would be truly appreciated. Thank You, From paolo_veronelli at tiscali.it Tue Aug 9 10:03:07 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 09 Aug 2005 16:03:07 +0200 Subject: namespaces Message-ID: <42F8B79B.8070609@tiscali.it> Why descriptor mechanism doesn't apply to modules? I suspect another anomaly in the namespaces implementations. class Mosse(object): def __get__(self,*_): print 'HERE' m=Mosse() m # doesn't work import new mod=new.module('hopeless') mod.m=Mosse() assert 'm' in mod.__dict__ # this is said to be the key for descriptors # to be called mod.m # doesn't work Thanks Paolino ___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com From apardon at forel.vub.ac.be Tue Aug 16 05:54:53 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 16 Aug 2005 09:54:53 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: Op 2005-08-06, Peter Hansen schreef : > Paolino wrote: >> seberino at spawar.navy.mil wrote: >> def enclosing(): >> var=[] >> var[0]=2 >> def enclosed(): >> var[0]=4 >> which is like saying python is not working >> >> It's ok to mark non locals,but why var=4 is not searched outside and >> var[0]=4 yes? > > Because "var=4" rebinds the name "var", while "var[0]=4" does not. It's > exactly the same issue with using "global", where you don't need it if > you aren't rebinding the name. This doesn't answer the question at the appropiate level IMO. Why has one made a difference in search policy for finding a variable based on whether the variable is rebound or not in the first place. -- Antoon Pardon From nospam at nospam.com Mon Aug 22 14:32:52 2005 From: nospam at nospam.com (42) Date: Mon, 22 Aug 2005 18:32:52 GMT Subject: Sandboxes References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: In article , peter at engcorp.com says... > 42 wrote: > > But for what its worth, I *am* curious what sorts of holes persist. I > > did try googling the archives, but with no idea what I'm looking for -- > > python security brings up a mess of unrelated issues... Python in > > Apache, rexec/bastion stuff, xss, issues with infinite loops and many > > other 'security' issues that might be relevant to someone running python > > on a web server where you have to be concerned about DOS but not of any > > concern to me... and so on and so forth. > > > > Can you, or someone, at least give me a few keywords I should be looking > > for that will bring matches for the sorts of attachs you've hinted at? > > "security" plus just about anything involved, such as rexec, bastion, > eval, and exec, appear to bring forth reams of relevant info. Try > sorting by date instead of Google's questionable "relevance" to make > sure you're getting some of the more recent discussions too. I was planning on "sanitizing" the language instead of relying on rexec and bastion so issues with them shouldn't be relevant. And I'd already covered that the sanitized language would not have eval and exec along with a dozen or so other builtin keywords/commands (which I listed in a previous post) would not be allowed in scripts... the pre- parser will simply reject any script containing them before running it. If eval and exec (and others) simply aren't allowed in the scripts; then the 'sneaky' things they might do aren't an issue. I'm curious about the 'other' stuff that was alluded to, that could still occur in a python with all its __import__, import, exec, eval, and various reflection/metadata builtins prohibited (e.g. getattr)... regards -Dave From tjreedy at udel.edu Thu Aug 11 15:02:08 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Aug 2005 15:02:08 -0400 Subject: Python supports LSP, does it? References: <20050811105151.736450c8.jk@ospaz.ru> Message-ID: wrote in message news:20050811105151.736450c8.jk at ospaz.ru... > On Thu, 11 Aug 2005 01:19:19 +0100 > phil hunt wrote: > >> According to Wikipedia, the Liskov substitution principle is: >> >> Let q(x) be a property provable about objects x of type T. Then >> q(y) should be true for objects y of type S where S is a subtype of T >> >> To me, this is nonsense. Under this definition any subtype must >> behave the same as its parent type, becausde if it doesn't there >> will be some q(y) that are different to q(x). >> >> But if it behaves the same, what's the point of having a subtype? > > It does not behave the same, it has the same properties. > > In other words, if there is some true assertion about _any_ object of > type > x, then it's true about any object of type y, if y is derived from x. > > Quick-and-dirty example: any object of type "list" is iterable, and it is > true > as well for any object of some type derived from list. I remember discussion of the LSP on comp.object some years ago when I was reading it. (I presume there still are, just don't read it anymore.). One of the problems is that biology and evolution do not obey it. Birds (in general) can fly, but those in the ratite family, evolved later than order aves, cannot. Nor can some birds in zoos after their wings have been (un)fixed. In a quite literal sense, the 'fly' method got disabled. The list goes on. In some cave-dwelling taxa, the 'see' method gets genetically disabled. Bones breaks. Artifacts also get disabled by accident or intention. So LSP conflicts with both scientific and everyday classification. Python lets one choose which hierarchy principle to adhere to. Terry J. Reedy From fakeaddress at nowhere.org Sat Aug 13 18:58:55 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 13 Aug 2005 22:58:55 GMT Subject: thread limit in python In-Reply-To: References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> <1123859196.289006.200380@g44g2000cwa.googlegroups.com> Message-ID: Peter Hansen wrote: > Bryan Olson wrote: > >> Peter Hansen wrote: >> > My question was in the context of the OP's situation. What >> possible use >> > for 1000 OS threads could he have? >> >> Is this a language thing? Surely you realize that "what possible >> use could be" carries an insinuation that is not >> such a good idea. > > Obviously. Is it no longer permissible to question someone's approach > to doing something? > > You're questioning my approach to inquiring after the OP's requirements, > and clearly you believe there is a better way to do it. Wonderful. You > may even be right. It's also off-topic. I'm just arguing against the notion that a couple thousands threads is generally a bad idea; if you didn't mean to suggest that, then I misread you. There are a lot of neat ways to do things that use one-or-two threads per thing-they-can-support. In days past such methods did not scale well, but on modern systems that is no longer true. -- --Bryan From asbjs at stud.ntnu.no Tue Aug 9 08:19:33 2005 From: asbjs at stud.ntnu.no (=?iso-8859-1?q?Asbj=F8rn_S=E6b=F8?=) Date: 09 Aug 2005 14:19:33 +0200 Subject: Point and click GUI builder for Python References: <42f430ea$0$18643$14726298@news.sunsite.dk> Message-ID: <87slxjmhey.fsf@ansatt20.q2s.ntnu.no> Madhusudan Singh writes: > Is there such a thing for python ? Like Qt Designer for instance ? Glade? >From http://glade.gnome.org/ : ----------------------------------------- Glade is a free user interface builder for GTK+ and GNOME, released under the GNU GPL License. The user interfaces designed in Glade are saved as XML, and by using the libglade library these can be loaded by applications dynamically as needed. (Glade can also generate C code, though this isn't recommended for large applications.) By using libglade, Glade XML files can be used in numerous programming languages including C, C++, Java, Perl, Python, C#, Pike, Ruby, Haskell, Objective Caml and Scheme. Adding support for other languages is easy too. ---------------------------------------- Asbj.S. From cgusenetmail at hotmail.com Sat Aug 13 17:01:41 2005 From: cgusenetmail at hotmail.com (CG) Date: 13 Aug 2005 14:01:41 -0700 Subject: Parsing a log file Message-ID: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> I am looking for a way to parse a simple log file to get the information in a format that I can use. I would like to use python, but I am just beginning to learn how to use it. I am not a programmer, but have done some simple modifications and revisions of scripts. I am willing to attempt this on my own, if someone can point me in the right direction (any example scripts that do similar things would be helpful). This doesn't have to be Python, but I need a cross-platform solution (i.e. Perl or some other kind of script). I just wanted to try Python because I like the concept of it. Here is my scenario: I have a program that connects and disconnects to a server. It writes a simple log file like this: 08-13-2005 13:19:37:564 Program: CONNECTED to 'Server' 08-13-2005 15:40:08:313 Program: DISCONNECTED from 'Server' 08-13-2005 15:45:39:234 Program: CONNECTED to 'Server' 08-13-2005 15:55:18:113 Program: DISCONNECTED from 'Server' 08-13-2005 16:30:57:264 Program: CONNECTED to 'Server' 08-13-2005 16:59:46:417 Program: DISCONNECTED from 'Server' 08-13-2005 17:10:33:264 Program: CONNECTED to 'Server' 08-13-2005 18:25:26:316 Program: DISCONNECTED from 'Server' 08-13-2005 18:58:13:564 Program: CONNECTED to 'Server' 08-13-2005 19:29:10:715 Program: DISCONNECTED from 'Server' What I basically want to do is end up with a text file that can be easily imported into a database with a format like this (or I guess it could be written in a SQL script form that could write directly to a database like Mysql): Connect_Date Connect_Time Disconnect_date Disconnect_time User ------------ ------------ --------------- --------------- ------- 08-13-2005 13:19:37 08-13-2005 15:40:08 John 08-13-2005 15:45:39 08-13-2005 15:55:18 John 08-13-2005 16:30:57 08-13-2005 16:59:46 John 08-13-2005 17:10:33 08-13-2005 18:25:26 John 08-13-2005 18:58:13 08-13-2005 19:29:10 John Here are some notes about this: * the username would come from the log file name (i.e. John_Connect.log) * I don't need the fractions of seconds in the timestamps * I only need date, time, and connect or disconnect, the other info is not important * If it is possible to calculate the elapsed time between Connect and Disconnect and create a new field with that data, that would help (but I can easily do that with SQL queries) * This log file layout seems to be consistent * There may not be a "disconnect" statement if the log file is read while connected, so the next time it would have to insert the disconnect information. The file will be read quite regularly, so this is very likely. * This would eventually need to be done without intervention (maybe every 5 minutes). I am open to other ideas or existing programs and am flexible about the final solution. Thanks, Clint From nid_oizo at yahoo.com_removethe_ Sun Aug 7 21:41:33 2005 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Sun, 07 Aug 2005 21:41:33 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <42f695f8.864310192@news.oz.net> References: <42f695f8.864310192@news.oz.net> Message-ID: Bengt Richter wrote: >>__specialize__ Special Member Function. > > By "Member Function" do you mean anything different from "method"? No, I should have written method. C++ habit. >> The first element of this proposal is the addition of the >> __specialize__ special member function. The __specialize__ >> function can have the same signatures as __call__. When > > Any function can have any legal signature, so I'm not sure what you are saying. You're right, I should focus on the syntax change, to call __getitem__ (or __specialize__) automatically. >> defined, the definition of __getitem__ has no effect, and >> __specialize__ will be called instead. > > What about subclassing and overriding __getitem__ ? I have no problem with that. I even suggest it at the end of the PEP. But don't you think the name "__getitem__" is not appropriate then? > here you can currently write > __getitem__ = __specialize__ > although you have to remember that obj[:] and related slicing expressions > become legal and that obj[] does not, without a language sysntax change. Yes, the PEP is about that syntax change. >> class Specializer: >> def __init__(self, callableObj): >> self.callableObj > > ^^?? = callableObj ? Yes, "= callableObj" is missing. >> A common pattern in Python is to use a function to create >> another function: >> >> def makeGetMemberFunc(memberName): >> def getMember(object): >> return getattr(object, memberName) >> return getMember >> >> foo(makeGetMemberFunc('xyz')) > > > Either closures like the above or bound methods work for this, > so you just want more concise spelling? In the case of functions, yes. For functions, I guess the syntax is much more useful is static typing is added, or planned to be added, in the language. However, there's still use cases where it is useful. > Have you looked at currying? E.g., > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549 And partial will be in Python 2.5 (PEP 309). Yes, I've look at it, but in my use cases the created function correspond to a specific function signature, so, for example, you always only want to specify the "memberName" argument. Currying is nice, but since any argument can supplied, the code is less self-documenting. But I used these in day-to-day programming. >> class MyList[ElementType=object](List[ElementType]): >> ... > > Before I'd want to extend class syntax this way, I think I'd want to > explore some other aspects of class syntax as well, with more (and > more persuasive) use cases in view. Also more thought to what is done > when and whether the issue is to supply information into existing control > contexts or to modify control flow as well, to extend possibilities for > customized processing. What do you think of the example I post in a reply to Martin v.Lowis? >> Instead of adding a __specialize__ method, the __getitem__ > > When you say "the" __getitem__ method, what do you mean? AFAIK the > method itself is an unrestricted function. It just happens that > binding it as a class attribute __getitem__ makes it get called > from code with square bracket access spellings. I think that's where > your changes to allow "additional signatures" would have to go. I.e., > in generation of code from the "calling" syntax. To illustrate: > > >>> class C(object): > ... def __getitem__(self, *args, **kwargs): > ... return self, args, kwargs > ... > >>> c=C() > >>> c[1] > (<__main__.C object at 0x02EF498C>, (1,), {}) > >>> c[1,2] > (<__main__.C object at 0x02EF498C>, ((1, 2),), {}) > >>> c[:] > (<__main__.C object at 0x02EF498C>, (slice(None, None, None),), {}) > >>> c[kw='key word arg'] > File "", line 1 > c[kw='key word arg'] > ^ > SyntaxError: invalid syntax > > But here the problem is not in the __getitem__ method: > > >>> c.__getitem__(kw='key word arg') > (<__main__.C object at 0x02EF498C>, (), {'kw': 'key word arg'}) > > It's just that square bracket expression trailer syntax does not > allow the same arg list syntax as parenthesis calling trailer syntax. I totally agree and that's what I mean. The formulation of the PEP is wrong, I should almost not talk about __getitem__ since as you said it can have any signature. The PEP is about extending [] syntax to call automtically __getitem__ function with more complex signatures. >> Should other operators that square brackets be used for >> specialization? > > Didn't quite parse that ;-) You mean list comprehensions? Or ?? I mean should angle brackets <> like in C++, or another operator, be used instead? Regards and thx for your feedback, Nicolas From http Mon Aug 1 17:13:49 2005 From: http (Paul Rubin) Date: 01 Aug 2005 14:13:49 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <7xd5ozv1ng.fsf@ruckus.brouhaha.com> <7xek9e5ywq.fsf@ruckus.brouhaha.com> Message-ID: <7xek9djr76.fsf@ruckus.brouhaha.com> Cliff Wells writes: > Still, that leaves Linux and Mac out in the cold. But I'll admit you > met my challenge. Most likely you can actually do most of the things > with Tk you can with Wx, it's simply a matter of how much effort is > going to be (for instance, it's certainly quite possible to embed Gecko > in Tk, but I for one am not likely to be up to the task). I actually misunderstood your question about embedding a browser and thought for a while about what it would take to write or port a serious browser to use tkinter as its graphics layer. The resulting picture wasn't pretty. I wonder whether it's feasible in wxpython. I like the idea of a browser-like portable gui toolkit. Instead of merely wrapping some other widget set, you'd write your interface as an XML file using HTML-like interface elements. You'd have callbacks on the form submit buttons and optionally on the other input elements, and you could get at the elements through the XML DOM if you were so inclined (sort of like the HTML DOM that browsers expose through Javascript). Implementations could run on top of Tk, GTK, native Windows widgets, or whatever. The language probably shouldn't be exactly HTML (e.g. it should have some additional widgets), but maybe it could be close enough that people wanting to do so could use the various wysiwyg web-layout programs that are out there, to put interfaces together. From peter at engcorp.com Mon Aug 29 08:59:01 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 29 Aug 2005 08:59:01 -0400 Subject: aproximate a number In-Reply-To: References: <43122d6d$0$97103$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: Mikael Olofsson wrote: > Michael Sparks wrote: > >> def approx(x): >> return int(x+1.0) > > I doubt this is what the OP is looking for. ... > Others have pointed to math.ceil, which is most likely what the OP wants. I agree that's "likely" but, as Michael pointed out in the text you removed, his version does do what the OP's spec states, when interpreted literally. Very likely there's a language issue involved, and Michael was aware of that as well, I'm sure. Still, others had already posted on math.ceil(), so Michael was just trying to make sure that the OP realized his specification was inadequate and -- just in case he wanted something other than math.ceil -- he provided a valid alternative. -Peter From michael at stroeder.com Thu Aug 4 06:37:46 2005 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 04 Aug 2005 12:37:46 +0200 Subject: Secure email In-Reply-To: <42f1ecd3$0$11079$e4fe514c@news.xs4all.nl> References: <42f1ecd3$0$11079$e4fe514c@news.xs4all.nl> Message-ID: Martin P. Hellwig wrote: > > I think you want this more common approach for mail encryption: > > server: > https CGI form --> mail wrapper --> PGP encryption/signing --> send > > client: > recieve mail --> pgp decryption/verification --> read This would require an additional PGP-plugin for Outlook. Outlook can decrypt S/MIME messages out-of-the-box. Ciao, Michael. From bokr at oz.net Tue Aug 30 13:50:33 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 30 Aug 2005 17:50:33 GMT Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> <864q98b7k0.fsf@bhuda.mired.org> Message-ID: <43149abd.168178447@news.oz.net> On Tue, 30 Aug 2005 05:15:34 GMT, Bryan Olson wrote: >Mike Meyer wrote: > > Bryan Olson writes: > >> > Bryan Olson writes: > >> > Trivially, an 'if' statement that depends upon input > >> >>data is statically predictable. Use of async I/O means makes the > >> >>programs execution dependent upon external timing. > >>Mike Meyer wrote: [...] > > >> > [...] I'm calling the tools available in most programming > >> > languages for dealing with it primitive. > >> > We need better tools. > >>Agreed, but if 'select' is someone's idea of the state of the > >>art, they have little clue as to the tools already available. > > > > Well, share! > >Uh, where have you been? I keep explaining that concurrency >systems have improved vastly in recent years. For a long time, >the most sophisticated software services generally have used >multiple lines of execution, and now that's mostly in the form >of threads. No one actually disagrees, but they go right on >knocking the modern methods. I think Mike is asking for references/citations/links to the "concurrency systems" and "modern methods" you are talking about ;-) (I'd be interested too ;-) Regards, Bengt Richter From bkhl at stp.lingfil.uu.se Sun Aug 7 06:47:05 2005 From: bkhl at stp.lingfil.uu.se (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) Date: Sun, 07 Aug 2005 12:47:05 +0200 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> Message-ID: <8764uiyqfq.fsf@lucien.dreaming> Paul Rubin writes: > bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: >> I don't see why the things you talk about would have to be part of the >> main Python distribution. Ruby on Rails seems to do pretty well without >> being included with the core language. > > I haven't used Ruby on Rails but from the description I saw, its distro > includes everything needed, which I assume includes Ruby itself. Hm... did you read my posting before you answered? That's exactly the kind of distro I suggested that you would make. Ruby on Rails is not Ruby itself, you know. >> There's already a pretty successful programming framework for Python >> (Zope), and I don't see why people wouldn't be able to put something >> like that together to compete on more equal terms with Ruby on Rails, or >> Delphi, &c. > > I have the impression that Zope is ungodly complex, and revolves around > a weird and nonstandard database instead of having an SQL interface. That's why you would put something together "to compete on more equal terms with Ruby on Rails". > Anyway, I'm a Python user, not an evangelist. As a user I'm happy to > have Python and am thankful to its authors, even though (like anything > else) it's a long way from being perfect. But I do get annoyed by > evangelists who make unsupportable claims that the product doesn't > live up to. I made no such claims. Again, did you actually read my posting? -- Bj?rn Lindstr?m Student of computational linguistics, Uppsala University, Sweden From renting at astron.nl Wed Aug 31 03:28:16 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 31 Aug 2005 09:28:16 +0200 Subject: Precise timings ? Message-ID: One of the limits of at least IBM compatible PC's is that in general they are not more accurate as about 1/64 th of a second if I recall correctly. I think this is the default tick size of the BIOS clock. Next to that the BIOS clock itself doesn't need to be very accurate, I can easily drift like an hour a year. Oh, and on top of that: If you are in a multi taksing operating system this complicates matters even further. Finally there's interrupts, as other posters pointed out. This explains it very well: http://www.beaglesoft.com/mainfaqclock.htm There was a thread with the same question 'time.clock() problem under linux (precision=0.01s)' about a month ago. I think it had some suggestion of using a soundcard sampling rate to get an accurate clock. I think that without an external calibrated device, you're not going to get any real accurate timing, precission isn't the same as accuracy. Adriaan. Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 200 (217 direct) P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ From oddr at home.no.no Tue Aug 2 07:11:04 2005 From: oddr at home.no.no (Odd-R.) Date: 2 Aug 2005 11:11:04 GMT Subject: SOAPpy and http authentication Message-ID: I use the following piece of code to contact a webservice, and read a wsdl file. from SOAPpy import WSDL from SOAPpy import URLopener url= ' http://someserver/somewebservice url1 = URLopener.URLopener(username='user',passwd='pass') server=WSDL.Proxy(url1.open(url)) This yields no errors, and everyting is fine. However, when I start calling the actual methods of this webservice, I get this error SOAPpy.Errors.HTTPError: How can I avoid this? Thanks in advance for all help! -- Har du et kj?leskap, har du en TV s? har du alt du trenger for ? leve -Jokke & Valentinerne From steve at REMOVETHIScyber.com.au Mon Aug 1 12:37:41 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 02 Aug 2005 02:37:41 +1000 Subject: namespaces References: <42EC9690.2040301@tiscali.it> <42ED9175.1050006@REMOVEMEcyber.com.au> <7xzms29ucn.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 31 Jul 2005 21:03:36 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Most languages can create self-modifying code. That's not the >> question. The question is whether developers should write >> self-modifying code, not whether language designers should prohibit it. > > There was no self-modifying code in that closure example. > Self-modifying code means something entirely different. The example was a function that modified itself to do something different from what it was doing. Calling it a "closure" is just jargon. As for closure being "tried and true" in Lisp... well, there is a reason why Lisp is a niche language, with very little if any use in the commercial world. -- Steven. From bokr at oz.net Tue Aug 16 15:37:26 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 16 Aug 2005 19:37:26 GMT Subject: How to obtain GMT offset? References: Message-ID: <43023cb1.1627827502@news.oz.net> On Mon, 15 Aug 2005 20:57:16 -0700, Erik Max Francis wrote: >new pip wrote: > >> I'm using Windows os. If the current system date time is '28 Jun 2001 >> 14:17:15 +0700', how can I obtain the value '+0700' using python? > >time.timezone gives you the timezone offset in minutes. > Hm, ... >From help(time): Variables: timezone -- difference in seconds between UTC and local standard time altzone -- difference in seconds between UTC and local DST time daylight -- whether local time should reflect DST tzname -- tuple of (standard time zone name, DST time zone name) I learned something: there is an altzone variable. But is that a constant, or is it zero during the standard-time part of the local year? (and since we do not have module-level properties, what happens if you start python during standard time and retrieve altzone after 1AM (or whenever the official switchover happens)? Lack of property would seem to make constants for both altzone and timezone safer. But then daylight should probably be an accessor function, if it can't be a property ;-) Regards, Bengt Richter From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Aug 2 02:30:09 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 2 Aug 2005 06:30:09 +0000 (UTC) Subject: using Pyro for network games References: Message-ID: Michael Rybak wrote: > Hi, everyone. > In topic "2-player game, client and server at localhost", I've asked > about subj, and Peter Hansen suggested to switch to Twisted, Pyro or > the like. > > I've tried using Pyro. > > I've written a very very simple test-game, in which you have 2 balls > controlled by 2 players. Each player moves his mouse somewhere at > his window, and his ball starts moving towards the pointer. No > objectives, just to test how it works. The code is very small, so I > can put it all here, skipping obvious stuff. > > I've tried playing this test-game via local-host - all is ok. > Then I've tested via Internet connection with my friend. I have a > 33.6 Kbps modem, he has a 2 MBps dedicated line (if this is the term), > and we ran a server at his pc and both connected to it. His ball ran as > a child, smoothly and quickly, while I had about 5 fps :(, and for him > it looked like my ball is simply very slow. I realise that client at > my pc *has* to work slower than the client at server's pc, but hey, > I've played Quake2 and WarCraft 2 via 33.6 modem, and those should have > much more stuff to transfer per second :( > > Please help me in any way you can think of. I'd welcome links to > Python games written with Pyro, tips on what I am doing wrong, on not > Pythonically enough - anything. Do not use pyro, use simple UDP protocol. I've written networked tetris in python, communicating via UDP protocol, and used it successfully on very congested lines. If all you need is to transfer pointer coordinates, UDP is perfect since you do not need feedback. use something like this for server: import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(('', port)) while 1: data, addr = s.recvfrom(1024) print `data` and for client: import socket outsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) outsock.bind(('', 0)) outsock.sendto('message', ('server-hostname', server_port)) -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From berlin.brown at gmail.com Sat Aug 20 17:14:20 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Sat, 20 Aug 2005 17:14:20 -0400 Subject: Python Light Revisted? In-Reply-To: <1124568446.496146.247180@g47g2000cwa.googlegroups.com> References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: Steve M wrote: > I agree with you in part and disagree in part. > > I don't see the point to making the distribution any smaller. 10MB for > the installer from python.org, 16MB for ActiveState .exe installer. How > is 5MB "lightweight" while 10MB isn't? The Windows XP version of Java > at java.com is 16+ MB, and the .NET framework is, well, I don't know > how big, but I doubt it's much less than 10MB. > > Also I think it's a terrible idea to distribute without pieces of the > standard library if the distribution is meant to be developed against > for arbitrary applications. (If you just want a slimmed down Python for > one specific application, use py2exe - I think it only includes > whatever gets imported for your program to run.) And excluding zip > while including Twisted? I don't get it. Besides, how do you know > Twisted doesn't import XML-RPC? I could see an enlarged Python that > includes Twisted along with the standard library, and in fact > ActiveState's includes win32 stuff. There's another such > mega-distribution around, the name of which escapes me at the moment. > But removing zip from the standard library so you can save 20kb seems > foolish. (Again, unless it is for one specific application, in which > case py2exe should do the trick, although I could be wrong about that > since I've never used it.) > > Now, what I do agree with is a Python that can be run from a folder > without having to be installed on the system. That could have lots of > benefits, if the details with pythonpath and whatever could be sorted > out. For example I haven't upgraded to 2.4 yet because I have 20 > different packages (e.g. SOAPpy, ZODB, whatever) installed on WinXP, > many of which required me selecting my 2.3 installation when I > installed them. I have no idea what will happen to all those if I run > the ActiveState installer for 2.4. I seem even to remember reading that > I have to un-install 2.3 before installing 2.4. I don't want to > re-install those 20 packages. Anyway I haven't had time to research it > and it isn't pressing, even though I'd like to start trying decorators > and generator expressions. > I see your concern. But, I am talking about, for example I have 70MB in my Python directory. I don't remember what the download size was. I know that can be reduced. 5MB completely unzipped. Plus, If the python setup is light enough, have a complete environment away from the 'main' 90MB environment, one that doesnt manipulate registry settings and whatnot. -- Ramza from Atlanta http://www.newspiritcompany.com From jeffrey.schwab at rcn.com Sun Aug 7 17:03:32 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sun, 07 Aug 2005 17:03:32 -0400 Subject: Creating a virtual file system In-Reply-To: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> References: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> Message-ID: Atila Olah wrote: > I'm working on a project to implement a simple cross-platform file > sharing protocol (using Python) that is similar to HTTP, and I have to > write a GUI for Windows and Linux. But let's start with the harder one: > Windows. > > My question is: How do I implement a virtual partition that acts like a > real file-system and is compleatly transparent to other programs? > Should I make a virtual file allocation table for a FAT32 partition or > simulate an NTFS? Or even further: How do I create a junction (or a > hard link) to it in "My network places" or in "Entire Network"? > > If there are tools that could help me but written in C or C++, please > let me know, I'll compile them to Python modules. > > Thanks forward for help. http://www.samba.org/samba/what_is_samba.html From exarkun at divmod.com Mon Aug 29 18:16:37 2005 From: exarkun at divmod.com (Jp Calderone) Date: Mon, 29 Aug 2005 18:16:37 -0400 Subject: python and ajax In-Reply-To: <20050829190446.60169.qmail@web40421.mail.yahoo.com> Message-ID: <20050829221637.3914.616083772.divmod.quotient.9914@ohm> On Mon, 29 Aug 2005 12:04:46 -0700 (PDT), Steve Young wrote: >Hi, I was wondering if anybody knew of any good >tutorial/example of AJAX/xmlhttprequest in python. >Thanks. > There's a short example of Nevow's LivePage online here: http://divmod.org/svn/Nevow/trunk/examples/livepage/livepage.py It's not a tutorial by itself, but if you poke around some of the other examples and read http://divmod.org/projects/nevow and some of the documents it references, you should be able to figure things out. Jp From grante at visi.com Wed Aug 31 16:31:57 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 31 Aug 2005 20:31:57 -0000 Subject: Sockets: code works locally but fails over LAN References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> <11hbcu1guovme72@corp.supernews.com> Message-ID: <11hc4ttbmcgdkbd@corp.supernews.com> On 2005-08-31, Bryan Olson wrote: >>>2. I'm not at all sure that accessing the same socket object >>>simultaneously from two threads is safe. >> >> It's OK under Unix. Having one thread handle rx and a >> different one handle tx is a pretty widely used method. >> >> Don't know about Win32... > > A thread for send and one for recv is also frequently used > with Winsock. Can anyone vouch for the Python wrapping? The last time I looked, it was a pretty thin wrapper, and shouldn't cause a problem. I just looked at 2.3.5 sources. [I think the timeout feature is new since I hacked on socketmodule.c last.] I don't really see anything troublesome. Basically, socket.recv() just calls recv() and socket.send() just calls send(). -- Grant Edwards grante Yow! MY income is ALL at disposable! visi.com From cgusenetmail at hotmail.com Sun Aug 14 10:38:31 2005 From: cgusenetmail at hotmail.com (CG) Date: 14 Aug 2005 07:38:31 -0700 Subject: Parsing a log file In-Reply-To: <42ff409b$1@news.eftel.com> References: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> <42ff409b$1@news.eftel.com> Message-ID: <1124030311.912414.110300@g49g2000cwa.googlegroups.com> John, Your comments are very helpful. I will take the datetime stamp as the way to go. I don't have a need to throw away the time info, it is You said: >What do you do if servers are in different >timezones? This is all inhouse in a non-daylight savings country and would not be an issue You also said: >Any chance of your using ISO standard format >for representing dates? I think I have very little control over the actual logfile data. I seem to be able to control what info it collects, but I don't think I can change the formatting. Thanks, Clint From saint.infidel at gmail.com Tue Aug 9 14:54:33 2005 From: saint.infidel at gmail.com (infidel) Date: 9 Aug 2005 11:54:33 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123601386.567072.111240@o13g2000cwo.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> Message-ID: <1123613673.097932.265430@g47g2000cwa.googlegroups.com> I think you have to call type.__new__ like this: def __new__(cls, year, month, day, *args, **kw): print "new called" try: return _datetime.__new__(cls, year, month, day, *args, **kw) except ValueError: return type.__new__(cls, ...) Are you sure you can specify arbitrary arguments to the __new__ method? I thought they had to be the class object, the tuple of bases, and the dictionary of names. From uomart at ihug.co.nz Thu Aug 25 08:40:08 2005 From: uomart at ihug.co.nz (Jon Monteleone) Date: Fri, 26 Aug 2005 00:40:08 +1200 Subject: Language translation possible in python? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> Message-ID: <003301c5a972$21bd30e0$5700a8c0@rmse> I have a program that currently displays all of its messages and instructions in only English. My boss wants me to change it all to Korean. Is there a python module that will automatically translate my English to Korean? -Jon From yoav_artzi at il.vio.com Thu Aug 25 05:04:39 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Thu, 25 Aug 2005 12:04:39 +0300 Subject: RE Despair - help required Message-ID: <430d8883@news.bezeqint.net> I am trying the following: re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") and I get a return of NoneType, and I have no idea why. I know that I missing something here, but I really can't figure out why (I bet it's something obvious). I also tried this RE on KODOS and it works fine there, so I am really puzzled. Any ideas? Thanks. From jeremy at emperorlinux.com Mon Aug 15 14:20:42 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Mon, 15 Aug 2005 14:20:42 -0400 Subject: Invoking GUI for app running in background with a keypress In-Reply-To: References: Message-ID: <1124130042.3819.37.camel@localhost.localdomain> If you want to get crazy you can poll() on one of the evdev nodes (/dev/input/event*) and behave accordingly. I do this in a C application we use to do the exact same thing you're talking about. Each successful read from the device returns a 16-byte input_event struct (or similar, I'm going from memory here) that represents a key action. A google search returned this: http://svn.navi.cx/misc/trunk/python/evdev/evdev.py On Mon, 2005-08-15 at 12:22 +0200, Mathias Dahl wrote: > I am creating a small app called PyQe > (http://klibb.com/cgi-bin/wiki.pl/PyQe) to launch commands and > programs quickly. I works more or less as I want it now and I have > managed to make my window manager (Metacity) under Mandrake GNU/Linux > start my program so that it can be started easily with just a > keypress. > > Now, the only annoyance I have is that when I have not started the > program for a while, the OS seems to not have Python or the program in > "the cache" (or whatever, what I mean is that if I have started the > program "recently" it starts fast the next time) anymore, which means > that the program, even though quite small, takes about a second to > start. This is too slow to feel good given the nature of the program > (a quick launcher). > > I have tried making it start faster by calling python with the -S > switch and by compiling my program to a .pyc file. It has not helped > much. > > So, I was wondering if I could have my program running in the > background and instead capture a certain keystroke (the same one I > have my window manager to capture now) to make the GUI appear. > > How does one go about doing this? I found a small program written in C > (xbindkeys) that can do this and understand that it probably involves > a lot of "low-level" stuff in X which feels a bit "scary" :). Any > clues of doing this "easily" in Python + some module? > > /Mathias > From sonicsmooth at gmail.com Wed Aug 24 06:47:56 2005 From: sonicsmooth at gmail.com (sonicSpammersGoToHellSmooth) Date: 24 Aug 2005 03:47:56 -0700 Subject: Eric3 for Windows not firing up. Message-ID: <1124880476.871046.4690@f14g2000cwb.googlegroups.com> Hi, I downloaded Python 2.4.1 for Windows and PyQtGPL10.exe and Eric3snapshot2005-04-10.exe from http://pythonqt.vanrietpaap.nl/ They seemed to install fine. Python 2.4.1 works. I tried Linguist and Designer, but there was some entrypoint error in qt-mt3.dll. I copied this file into the c:\windows directory, and then QT at least fired up, with Linguist and Designer now working. Then I tried Eric3, but I get the following: The procedure entry point ?wheelEvent at QWidget@@MAEXPAVQWheelEvent@@@Z could not be located in the dynamic link library qt-mt3.dll. Any clues how to fix this one? thanks Michael From could.net at gmail.com Tue Aug 16 21:05:39 2005 From: could.net at gmail.com (could ildg) Date: Wed, 17 Aug 2005 09:05:39 +0800 Subject: How can I exclude a word by using re? In-Reply-To: <1124217228.600911.132070@z14g2000cwz.googlegroups.com> References: <430085e8$1@news.eftel.com> <1124165702.590364.107410@o13g2000cwo.googlegroups.com> <1124198308.584668.69390@g14g2000cwa.googlegroups.com> <1124198822.785871.143970@o13g2000cwo.googlegroups.com> <1124217228.600911.132070@z14g2000cwz.googlegroups.com> Message-ID: <311b5ce10508161805f615f1@mail.gmail.com> Thanks for all of you~ I made it. Pyparsing is really nice. On 16 Aug 2005 11:33:48 -0700, Paul McGuire wrote: > I just reviewed what the re "\s" signifies: whitespace. This is easy, > pyparsing ignores all intervening whitespace by default. So mp3Entry > simplfies to: > > mp3entry = valign + number.setResultsName("number"?? + tdEnd + \ > tdStart + aStart + \ > SkipTo(tdEnd).setResultsName("??me") + tdEnd > > which leads me to another question - isn't there a closing in > there somewhere, probably at the end of the name? If so, then you > might be better off with: > > mp3entry = valign + number.setResultsName("number"?? + tdEnd + \ > tdStart + aStart + \ > SkipTo(aEnd).setResultsName("??me") + aEnd + tdEnd > > -- Paul > > -- > http://mail.python.org/mailman/listinfo/python-list > From levicc00123 at gmail.com Mon Aug 29 12:17:33 2005 From: levicc00123 at gmail.com (levicc00123 at gmail.com) Date: 29 Aug 2005 09:17:33 -0700 Subject: using common lisp with python. In-Reply-To: <43130f30$0$17711$626a14ce@news.free.fr> References: <1125264907.656465.106900@g44g2000cwa.googlegroups.com> <43130f30$0$17711$626a14ce@news.free.fr> Message-ID: <1125332253.886031.256950@g49g2000cwa.googlegroups.com> basically, what I'm looking to do is use python as a bridge between C and Common Lisp to create a virtual city that contains Artificial life. From cam.ac.uk at mh391.invalid Thu Aug 11 14:53:18 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Thu, 11 Aug 2005 19:53:18 +0100 Subject: python2.4/site-packages In-Reply-To: References: Message-ID: Srinivasan TK wrote: > Now ,Is it mandatory that I build the third-party > packages ( python2.4/site-packages) . Only if you want to use them. Really, no. > If so is there a > list that needs to be built and installed . There is a list of them packages which you MAY install but may also choose not to here: http://www.python.org/pypi This used to be called the Python Package index but is now the Python Cheese Shop? Huh??? -- Michael Hoffman From me at privacy.net Sat Aug 13 21:39:45 2005 From: me at privacy.net (Dan Sommers) Date: Sat, 13 Aug 2005 21:39:45 -0400 Subject: Spaces and tabs again References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> <6spsf1hr7i0ho9fa0ptauhst1s61jkig13@4ax.com> Message-ID: On Sun, 14 Aug 2005 01:04:04 GMT, Dennis Lee Bieber wrote: > On 13 Aug 2005 13:18:21 -0700, sigzero at gmail.com declaimed the following > in comp.lang.python: >> >> Are you kidding? You are going to MANDATE spaces? >> > After the backlash, Python 4.0 will ban leading spaces and require > tabs Why not petition the unicode people to include PYTHON INDENT and PYTHON DEDENT code points, and leave the display up to the text editors? ;-) Regards, Dan -- Dan Sommers From mwm at mired.org Wed Aug 31 22:44:06 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 31 Aug 2005 22:44:06 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> <864q98b7k0.fsf@bhuda.mired.org> <43149abd.168178447@news.oz.net> Message-ID: <86ek897bih.fsf@bhuda.mired.org> Bryan Olson writes: > Bengt Richter wrote: > > Bryan Olson wrote: > >>For a long time, > >>the most sophisticated software services generally have used > >>multiple lines of execution, and now that's mostly in the form > >>of threads. No one actually disagrees, but they go right on > >>knocking the modern methods. > > I think Mike is asking for references/citations/links to the > > "concurrency systems" and "modern methods" you are talking about ;-) > > (I'd be interested too ;-) > Sure. I tried to be helpful there, but maybe I need to be more > specific. The ref from my previous post, Google-able as "The > C10K problem" is good but now a little dated. That appears to be a discussion on squeezing the most out of a network server, touching on threading models only so far as to mention what's available for popular languages on some popular server OS's. > System support for threads has advanced far beyond what Mr. Meyer > dealt with in programming the Amiga. I don't think it has - but see below. > In industry, the two major camps are Posix threads, and Microsoft's > Win32 threads (on NT or better). Some commercial Unix vendors have > mature support for Posix threads; on Linux, the NPTL is young but > clearly the way to move forward. I haven't looked at Win32 threading. Maybe it's better than Posix threads. Sure, Posix threads is better than what I dealt with 10 years ago, but there's no way I'd call it "advanced beyond" that model. They aren't even as good as the Python Threading/Queue model. > Java and Ada will wrap the native thread package, which > C(++) offers it directly. Obviously, any good solution will wrap the native threads package. Just like it wraps the I/O package. That doesn't make the native threads package good. You also have to deal with the cost the compiler pays when you implement threading primitives as library calls. I'm surprised the paper didn't mention that problem, as it effects performance so directly. I don't know what Ada offers. Java gives you pseudo-monitors. I'm almost willing to call them "advanced", but they are still don't really help much. There are some good threading models available. Posix threads isn't one of them, nor is Java's "synchronized". http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From alanmk at hotmail.com Wed Aug 3 06:47:16 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Wed, 03 Aug 2005 11:47:16 +0100 Subject: JBUS and Python which way In-Reply-To: <1122990414.662555.116450@g43g2000cwa.googlegroups.com> References: <1122990414.662555.116450@g43g2000cwa.googlegroups.com> Message-ID: [mjekl] > My aim is to have an idea of the alternatives technologies for > accessing information produced by a machine with a JBUS interface > (RS232) and how to access this information realtime in Python > (connecting a PC locally via serial port). > > I'm aware of pyserial but I wonder if there is a library/module that > takes care of accessing/interpreting JBUS protocol. I've searched for > this without results. A possibility you may not have considered is to use a Java library for Modbus/JBus, and then use jython to control that. The following looks like a likely candidate. http://sourceforge.net/projects/jamod/ I imagine that writing your own cpython implementation wouldn't be that difficult. I did some modbus work in C back in the 90s, and it was pretty straightforward, but requiring a lot of finicky bit-twiddling. I'm pretty certain that writing a python implementation would be a snap. > I also searched the net looking for some information so that I could > have a birds-eye-view on this subject and got the impression that a > possibility is to have the communication (JBUS protocol / buffering) > managed by some hardware component. Is this so? Can some-one give me > some pointers/resources on this subject. Would it still be possible > to work with Python. Well, if you do find some hardware component that manages the JBus interface, you've then turned your problem into "How to talk between the PC and the JBus instrument-manager" rather than "How to talk between the PC and JBus instruments". Depending on the protocol used by the "instrument-manager", you may be able to use python to control that. HTH, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From CantankerousOldGit at gmail.com Thu Aug 18 13:44:30 2005 From: CantankerousOldGit at gmail.com (Cantankerous Old Git) Date: Thu, 18 Aug 2005 18:44:30 +0100 Subject: Windows message pump problems In-Reply-To: <3avMe.873$FA3.106@news-server.bigpond.net.au> References: <3avMe.873$FA3.106@news-server.bigpond.net.au> Message-ID: Neil Hodgson wrote: > Cantankerous Old Git: > >> Problem 1: >> If I have another thread call DestroyWindow after a delay, it gets an >> error "permission denied". I really can't see why. > > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/destroywindow.asp > > > """A thread cannot use DestroyWindow to destroy a window created by a > different thread.""" > > Posting WM_CLOSE to the window will probably work. If not, then send > an application defined message to the window and handle it by calling > DestroyWindow. > > Neil Sorry for the delay in answering. That put me on the right track, thanks. I post a custom message, and the handler calls DestroyWindow. The Cog From DoubleMPi at Netscape.com Wed Aug 3 22:22:53 2005 From: DoubleMPi at Netscape.com (Mike Moum) Date: Thu, 04 Aug 2005 02:22:53 +0000 Subject: Getting a dictionary from an object In-Reply-To: References: Message-ID: <42F17BFD.4050401@Netscape.com> Thanos Tsouanas wrote: I'm not sure what you're getting at, but have you tried this: class A(object): def __getitem__(self, ky): return self.__dict__[ky] for example: >>> class A(object): def __init__(self,a,b,c): self.a = a self.b = b self.c = c def __getitem__(self, ky): return self.__dict__[ky] >>> a = A(1,2,3) >>> a['a'] 1 >>> a['b'] 2 >>> > Hello. > > I would like to have a quick way to create dicts from object, so that a > call to foo['bar'] would return obj.bar. > > The following works, but I would prefer to use a built-in way if one > exists. Is there one? > > Thanks in advance. > > class dictobj(dict): > """ > class dictobj(dict): > A dictionary d with an object attached to it, > which treats d['foo'] as d.obj.foo. > """ > def __init__(self, obj): > self.obj = obj > def __getitem__(self, key): > return self.obj.__getattribute__(key) > From rkern at ucsd.edu Sat Aug 6 19:01:24 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 16:01:24 -0700 Subject: SWIG again In-Reply-To: <20050806225333.26874.qmail@web51503.mail.yahoo.com> References: <20050806225333.26874.qmail@web51503.mail.yahoo.com> Message-ID: Please don't make a new thread every time you post. Jerry He wrote: > Robert Kern > >>Write a distutils setup.py script to do all of the >>compiling and linking. > > Ok, I wrote the following distutils setup.py script > from distutils.core import setup, Extension > > setup (name = 'example', > version = '2.4', > ext_modules = [Extension('example', \ ['example.c', > 'example_wrap.c'])] ) > > > I put it in the same directory as the extension files > and I ran from the command line > > python setup.py install, > > and nothing happened... No output? -- 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 xah at xahlee.org Mon Aug 22 14:43:09 2005 From: xah at xahlee.org (Xah Lee) Date: 22 Aug 2005 11:43:09 -0700 Subject: Jargons of Info Tech industry In-Reply-To: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Unix, RFC, and Line Truncation [Note: unix tradition requires that a return be inserted at every 70 characters in email messages or so so that each line are less than 80 characters. Unixers made this as a requirement into an RFC document.] Xah Lee, 20020511 This truncation of lines business is a hatred of mine, from email formatting to formatting of program codes. I have been fighting with the unix slew of morons about the line cut for years. The unix morons are the number one excuse expert, that whenever in an argument they'll mention some RFC ?specifications?. (RFC = Really Fucking Common, invented by mostly unix folks in the 70s.) the unix morons, think that the world should truncate lines just like their incompetent operating system silently truncate lines (and it still DOES, folks! e.g. ps, tar, tcsh.) Around 1998 when i was using Outlook Express or Eudora before that, i remember i can set lines to not hard-wrap, and i did. Boy that always pissed the unix blockheads. In their diddly eyes and lousy email software, i'm breaking standards, making things hard to read, and being a stupid ass. Their brain fail to see what unix ways are not capable of. These guys are the same slew of morons who cry in pain about how the web should not commercialize (circa 1996), and email should be text only (anti-MIME, circa 1995), and lynx is the best browser (circa 1995), and GUI is for sissys and mouse is for pussies and Apple computer is for kids (circa 1987). There is no reason for a paragraph encoding to be splattered with end of line characters, nor the human labor expended. There is reason for paragraphs to be displayed not too wide, and that is readability. What the unixer could not get clear of is a distinction of concepts. Because their fantastically hacked-up operating system operate by the principle that lines should not be some 80 chars or else it will be truncated and *silently* too, thus it became _necessarily_ their _habit_ and thought that line truncation business is natural and a human duty. Unknown of these setups, the unix geeks go by their presumption that all text should be hard wrapped, as if parameters should be hard-coded. I recall, two particular unix hotshots who bugged me about the line truncations business is the Perl priest Tom Christiansen, who used to reside over comp.lang.perl.*, and another unix jockey Chris Nandor, who was a MacPerl proponent now the main maintainer. It is not a coincidence that the people who go out of their way to complain about any ?format=flowed? or softwrapped or logically-formatted lines in emails are always the unixers. The unix twits will start a flame war over a petty formatting issue, because it's unix's training to bent over pettiness, not to mention they are the ones who are retarded on the issue of line truncation. As i have alluded to above, there are serious problems with the line-truncation ways of thinking. The gist is that it is a form of physical formatting as opposed to logical. (think softwrap vs hardwrap, parameter vs hard-code) Those who are familiar with the history or reason for SGML and HTML should understand the problem. Many of you familiar with drive of evolution of HTML from 1995 days to today's CSS & XML should also understand the issue. We wish to encode information, and be flexible about representation, not botching info into one particular representation. The harm done by the unixers to society is of a long lasting and pervasive nature. First is the RFC, which serves as the mob's standard, which requires that every emailer should be broken like unix, so that unix can process them without problems. Fuck unix and fuck unix geeks. Secondly, it drains human labor. Right this second there are hundreds of people pressing returns or fixing jagged lines unnecessarily. Thinking and computer could have done that for us, if not for fucking stupid unix and its people. Thirdly, a generation of programs and programer's times are wasted over tools that mutilate paragraphs into pieces. (in emacs, there's fill-paragraph etc, and in BBEdit it's just called ?Hard Wrap?) Fourthly, physical formatting ultimately multiply the process required on the data, as we can see in emails, especially in combination with the stupid quote convention: ?>? (that's another unix invention.). But most importantly is that the hard-liners instilled a bad notion, a confusion, that generated a entire generation of utterly stupid programing languages and monkey coders, starting with unix's C language. As of 200506, the following two sites shows that as late as 2001, unix tool tar (BSD) still truncate long file names. ? http://www.sourcekeg.co.uk/www.mysql.com/doc/mysql/en/mac-os-x.html (local copy) http://nrg.cs.usm.my/~tcwan/macosx_essentials.htm (local copy) -------------------- This post is archived at: http://xahlee.org/UnixResource_dir/writ/truncate_line.html Xah xah at xahlee.org ? http://xahlee.org/ From steve at holdenweb.com Wed Aug 31 00:28:19 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Aug 2005 23:28:19 -0500 Subject: reg email packages work In-Reply-To: <20050831042039.25690.qmail@web8409.mail.in.yahoo.com> References: <20050831042039.25690.qmail@web8409.mail.in.yahoo.com> Message-ID: praba kar wrote: > --- Sybren Stuvel > wrote: > > >>Steve Holden enlightened us with: >> >>>It's obvious you aren't using that EXACT code, >> >>because it doesn't >> >>>formulate a three-paragraph message. So the bit we >> >>really need to >> >>>see is how you capture and formulate the argument >> >>to set_payload(). >> >>I'd rather see what I asked for, which is the output >>of >>msg.as_string(). That contains all that's sent to >>the client. > > > msg.as_string() have all the client data(which include > headers and body of the message > Does this mean you can't let us see it, or that you still don't understand what we want to see? Without knowing what you are passing to the sendmail process we can't tell what's wrong, not being psychic :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From tiang_ono at yahoo.com Wed Aug 17 20:47:50 2005 From: tiang_ono at yahoo.com (Titi Anggono) Date: Wed, 17 Aug 2005 17:47:50 -0700 (PDT) Subject: Some questions Message-ID: <20050818004750.91423.qmail@web30709.mail.mud.yahoo.com> Hi all, I have some questions: 1. Can we use Tkinter for web application such as Java ? 2. I use gnuplot.py module for interfacing with gnuplot in linux. Can we make the plot result shown in web ? I tried using cgi, and it didn't work. Thanks ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From lemon97 at gmail.com Sun Aug 7 23:50:54 2005 From: lemon97 at gmail.com (lemon97 at gmail.com) Date: 7 Aug 2005 20:50:54 -0700 Subject: Splitting a string into groups of three characters In-Reply-To: <1123470331.579657.28080@g47g2000cwa.googlegroups.com> References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> <1123470331.579657.28080@g47g2000cwa.googlegroups.com> Message-ID: <1123473054.950660.101630@g14g2000cwa.googlegroups.com> Thank You, For your help, I guess I will just make a couple of these functions and find out which one is that fastest. From petr at tpc.cz Tue Aug 30 08:10:06 2005 From: petr at tpc.cz (McBooCzech) Date: 30 Aug 2005 05:10:06 -0700 Subject: time.mktime problem In-Reply-To: <87ek8bmyrb.fsf@majakari.net> References: <1125397106.854442.227120@g44g2000cwa.googlegroups.com> <87ek8bmyrb.fsf@majakari.net> Message-ID: <1125403806.561645.145160@f14g2000cwb.googlegroups.com> according to the Python documentation: http://docs.python.org/lib/module-time.html ===snip=== Values 100-1899 are always illegal. . . strptime(string[, format]) . . The default values used to fill in any missing data are: (1900, 1, 1, 0, 0, 0, 0, 1, -1) ===snip=== BTW, check the following code: >>import datetime, time >>print time.gmtime(time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1))) (1901, 12, 13, 20, 45, 52, 4, 347, 0) but (1900, 1, 1, 0, 0, 0, 0, 1, -1) is (IMHO) expected.... Hmmm. But I am just a newbie!!! :) Anyway, maybe I am just using a wrong way how to calculate time delta between two time values given in the format "HHMMSS". Does Python provide some other ways how to calculate it? Petr Jakes From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 25 10:13:59 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 25 Aug 2005 16:13:59 +0200 Subject: RE Despair - help required In-Reply-To: <430dcea0$1@news.bezeqint.net> References: <430d8883@news.bezeqint.net> <430dcea0$1@news.bezeqint.net> Message-ID: <3n6217F1fg2U2@individual.net> Yoav wrote: > Don't think it will do much good. I need to get them from a file and > extract the last folder in the path. For example: > if I get "c:\dos\util" > I want to extract the string "\util" Then os.path.basename should be for you. Reinhold From fredrik at pythonware.com Tue Aug 23 06:33:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 12:33:54 +0200 Subject: Import Error ('mutual inclusion of modules'?) References: <1124792581.450156.214960@g44g2000cwa.googlegroups.com> Message-ID: wrote: >I have the following code: > > A.py > ==== > > from B import B > B.py > ==== > > from A import R > I think python does not support this kind of 'mutual inclusion'. Am I > right? Thanks. Cesar. this page http://effbot.org/zone/import-confusion.htm might help you figure out what's going on here. From jcarlson at uci.edu Thu Aug 18 01:01:06 2005 From: jcarlson at uci.edu (jcarlson at uci.edu) Date: 17 Aug 2005 22:01:06 -0700 Subject: Read from stdouton Popen on WinXP? References: Message-ID: <1124340296.489236.249680@g43g2000cwa.googlegroups.com> > >>> "mhenry1384" 08/16/05 11:48 PM >>> > I am trying to run a program and filter the output on Windows XP. > Since I want to filter the output, I'd like to read it a line at a time > and only print the lines I care about. > > p = subprocess.Popen(["doxygen.exe", r"Doxyfile.cfg"], > stdout=subprocess.PIPE, stderr=subprocess.STDOUT) Install pywin32 . Use: read(p.stdout, SIZE) read(p.stderr, SIZE) Having defined read() as the below. The subprocess generally still needs to flush stdout and stderr. - Josiah import msvcrt import pywintypes from win32file import ReadFile from win32pipe import PeekNamedPipe def read(stdout_or_stderr, maxsize): try: x = msvcrt.get_osfhandle(stdout_or_stderr.fileno()) (read, nAvail, nMessage) = PeekNamedPipe(x, 0) if maxsize < nAvail: nAvail = maxsize if nAvail > 0: (errCode, read) = ReadFile(x, nAvail, None) except pywintypes.error, e: errno = e.args[0] if errno == 109: # other end disconnected stdout_or_stderr.close() else: raise return read From steve at holdenweb.com Tue Aug 23 14:24:08 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 23 Aug 2005 14:24:08 -0400 Subject: py-serial + CSV In-Reply-To: <1124820032.854336.278790@f14g2000cwb.googlegroups.com> References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> <1124820032.854336.278790@f14g2000cwb.googlegroups.com> Message-ID: McBooCzech wrote: > Sorry, I did not mentioned the data flow from the serial port is > permanent/continuous (as long as the GPS receiver is connected to the > serial port). The input data are commning every second, they are comma > separated and they are looking like: > > $GPGGA,174525.617,5026.1080,N,01521.6724,E,1,05,1.8,306.5,M,,,,0000*0B > $GPGSA,A,3,02,09,05,06,14,,,,,,,,3.6,1.8,3.1*31 > $GPGSV,3,1,09,30,74,294,,05,65,093,49,06,40,223,32,02,39,089,49*78 > $GPRMC,174525.617,A,5026.1080,N,01521.6724,E,0.0,005.8,230805,,*0A > etc.... > >>From the rows they are begining with $GPRMC I want to get following > data only (positions 2,4,6) > 174525.617 > 5026.1080 > 01521.672 > > This (according to your suggestions) is my code which works for me > > import serial > s = serial.Serial(port=0,baudrate=4800, timeout=20) > while 1: > line = s.readline() > words = line.split(',') > if words[0]=="$GPRMC": > print words[1], words[3], words[5] > > I just wonder if there is some beter (or as you are saying "more > pythonic":) aproach how to write such a piece of code. That code is quite tidy. You could save yourself the split on lines that weren't of interest, though frankly this isn't essential - this task won't use 1% of CPU on almost any computer built in the last five years. But, if you are interested in seeing other solutions you might consider it, and it does avoid the split when it's not necessary. while 1: line = s.readline() if line.startswith("$GPRMC"): words = line.split(",") print words[1], words[3], words[5] regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Sat Aug 20 13:16:41 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 20 Aug 2005 10:16:41 -0700 Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? In-Reply-To: References: Message-ID: <43075998$1@nntp0.pdx.net> Miernik wrote: > On my Debian GNU/Linux system I have Python 2.3 installed in > /usr/lib/python2.3/ where most Python system files like > > /usr/lib/python2.3/gzip.py > /usr/lib/python2.3/gzip.pyc > /usr/lib/python2.3/gzip.pyo > > live, besides of course /usr/bin/python2.3 > > I noticed that all those files come in three "flavours": > *.py *.pyc *.pyo > > Is it possible that only one "flavour" of these files is needed, and I can > delete the remaining two, any my Python installation will still work? > > The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting > two "flavours" would save about 10 MB on my system, and that would help > me much as I am trying to fit my system on a 256 MB SD card, to make it > quiet (hard disks are noisy). > > Can I just do > cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc > for example, and everything will still work as before? > You can put them all in a .zip (repeating the structure), named python23.zip, and put that zip file where the search path looks for it. Having built python23.zip, you can delete all the .py, .pyc, .pyo files you put in the zip. Compress them using "DEFLATE", since Python's zipfile module doesn't do BZIP2 compression (yet). --Scott David Daniels Scott.Daniels at Acm.Org From roy at panix.com Sun Aug 28 22:31:47 2005 From: roy at panix.com (Roy Smith) Date: Sun, 28 Aug 2005 22:31:47 -0400 Subject: trictionary? References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> Message-ID: Steven Bethard wrote: > In Python, pairs are usually handled with tuples[2], but tuples would be > inconvenient in this case, since the first value must be modified. Instead of modifying the tuple (which you can't do), you can create a new one: a, b = myDict[key] myDict[key] = (a+1, b) It's a bit inefficient, but get it working first, with clear, easy to understand code, then worry about how efficient it is. > Declaring a class with two attributes as > you suggested is often a good substitute, but if the OP's code is really > what it looks like, I get another code smell because declaring a class > to be used by only 10 lines of code seems like overkill. But, classes are so lightweight in Python. You can get away with nothing more than: class Data: pass and then you can do things like: myData = Data myData.a = a myData.b = b More likely, I would want to write: class Data: def __init__ (self, a, b): self.a = a self.b = b but I've done the minimilist Data class more than once. It doesn't cost much, and it's often more self-documenting than just a tuple. From randy at psg.com Sun Aug 28 23:17:58 2005 From: randy at psg.com (Randy Bush) Date: Sun, 28 Aug 2005 17:17:58 -1000 Subject: trictionary? References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> Message-ID: <17170.32358.268677.962644@roam.psg.com> >> bin = {} >> for whatever: >> for [a, b] in foo: >> x = 42 - a >> if bin.has_key(x): >> bin[x.b] += 1 >> else: >> bin[x.b] = 1 >> bin[x.not b] = 0 >> for x, y, z in bin.iteritems(): >> print x, y, z >> >> should the dict value become a two element list, or is there a >> cleaner way to do this? > It would probably help if you explained what the real problem is > you're trying to solve. actually, that code fragment was meant to do that. it's pretty much what i needed to do at that point, just the variable names made simple. > Using a two element list to store a pair of counts has a bad code > smell to me. exactly. which is why i was asking. > That said, you could write your code something like: > bin = {} > for whatever: > # NOTE: brackets are unnecessary > for a, b in foo: > x = 42 - a > # NOTE: 'in' is generally faster than has_key() > if x in bin > bin[x][0] += 1 > else: > bin[x] = [1, 0] > # NOTE: extra parens necessary to unpack count list > for x, (y, z) in bin.iteritems(): > print x, y, z so, to do this using the real names, it looks like for [start, end, AS, full] in heard: week = int((start-startDate)/aWeek) if week in bin: if full: bin[week][0] += 1 else: bin[week][1] += 1 else: if full: bin[week] = [1, 0] else: bin[week] = [0, 1] ... for i, (j, k) in bin.iteritems(): if j == 0: print str(i) + ",," + str(k) elif k == 0: print str(i) + "," + str(j) else: print str(i) + "," + str(j) + "," + str(k) which is still pretty darned grotty and unexpressive. of course, i could be a bit more obscure and do if week in bin: bin[week][not full] += 1 else: bin[week] = [ full, not full ] except i probably have to coerce the types or something. less code but less obvious. randy From martin.witte at gmail.com Thu Aug 11 16:22:31 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 11 Aug 2005 13:22:31 -0700 Subject: breaking a loop In-Reply-To: References: Message-ID: <1123791750.995297.24380@g47g2000cwa.googlegroups.com> What you do is asking for a string, and then embed the result in '%' characters, as this is what you do in the sql statement (btw: where is the cursor defined?) It is probably a better idea to construct the sql statement with the direct result of raw_input, instead of format it straight away - see below for the idea martin at ubuntu:~ $ python Python 2.4.1 (#2, Mar 30 2005, 21:51:10) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. py> s = raw_input('Prompt: ') Prompt: exit py> print s exit py> if s == 'exit': ... print 'yes' ... yes py> t = '%%%s%%' %s py> print t %exit% py> sql = "select * from TABLE where FIELD like %s", (s) py> print sql ('select * from TABLE where FIELD like %s', 'exit') py> sql = "select * from TABLE where FIELD like '%%%s%%" % s py> print sql select * from TABLE where FIELD like '%exit% py> From femlikeapitbullinbed at yahoo.com Fri Aug 19 19:24:52 2005 From: femlikeapitbullinbed at yahoo.com (Steph) Date: Fri, 19 Aug 2005 23:24:52 -0000 Subject: wanna stop by my homemade glory hole? Message-ID: my husband is installing an extra bathroom poolside. there is a perfect size hole (unless you have a huge cock) to stick your dick through into the adjoing room. come around the side of my house(perfect if you look like a repair man) enter into the unfisnished bathroom and I'll service you from the other side. you can leave when your done, no talking or small talk. i want to do this before the hole gets patched up. its been a huge fantasy of mine ever since I've seen a glory hole online. you can email me for a time convienient for you. im home all-day most days so my schedule is open. do you prefer a certain color of lipstick? check out my pic and email here under kallegirl26 www.no-strings-fun.net/kallegirl26 ready and waiting, me ;o) From http Wed Aug 10 21:27:58 2005 From: http (Paul Rubin) Date: 10 Aug 2005 18:27:58 -0700 Subject: signals (again) References: <1123713622.727375.206270@f14g2000cwb.googlegroups.com> Message-ID: <7x8xz9s1nl.fsf@ruckus.brouhaha.com> "bill" writes: > What's the pythonic thing to do here? How can I > guarantee timely response to the creation of a file in the directory > referenced by fd? Use asynchronous calls and/or a separate thread. From lahxee at bellsouth.net Tue Aug 23 08:59:13 2005 From: lahxee at bellsouth.net (Lah Xee) Date: Tue, 23 Aug 2005 08:59:13 -0400 Subject: Jargons of Info Tech industry In-Reply-To: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: <430B1DA1.4090406@bellsouth.net> Xah Lee wrote: You stupid UNIX donkey! Why you wrap your email? You wasted time formatting email that you could have used to read Python documentation and critique it! How you expect to change world if you spend time formatting email??? And I no want hear you let Google groups format it! If you use stupid UNIX-using, text monkey service like Google to format your email, then you no longer worthy to be our prince!! I, Lah Xee, master of wit and expert grammarian must rise to occasion and become pre-eminent troll for common good of all mankind! Down with UNIX!! Down with Mac!! Down with Perl!! Down with Xah Lee!! You will all bow before my astonishing wisdom and knowledge!! Now, why do this so-called "print" statement in Python f*ck up my text by splattering it with end of line characters? Lah Xee Master Grammarian Pre-Eminent Troll >Unix, RFC, and Line Truncation > >[Note: unix tradition requires that a return be inserted at every 70 >characters in email messages or so so that each line are less than 80 >characters. Unixers made this as a requirement into an RFC document.] > >Xah Lee, 20020511 > >This truncation of lines business is a hatred of mine, from email >formatting to formatting of program codes. I have been fighting with >the unix slew of morons about the line cut for years. The unix morons >are the number one excuse expert, that whenever in an argument they'll >mention some RFC ?specifications?. (RFC = Really Fucking Common, >invented by mostly unix folks in the 70s.) > >the unix morons, think that the world should truncate lines just like >their incompetent operating system silently truncate lines (and it >still DOES, folks! e.g. ps, tar, tcsh.) Around 1998 when i was using >Outlook Express or Eudora before that, i remember i can set lines to >not hard-wrap, and i did. Boy that always pissed the unix blockheads. >In their diddly eyes and lousy email software, i'm breaking standards, >making things hard to read, and being a stupid ass. Their brain fail to >see what unix ways are not capable of. These guys are the same slew of >morons who cry in pain about how the web should not commercialize >(circa 1996), and email should be text only (anti-MIME, circa 1995), >and lynx is the best browser (circa 1995), and GUI is for sissys and >mouse is for pussies and Apple computer is for kids (circa 1987). > >There is no reason for a paragraph encoding to be splattered with end >of line characters, nor the human labor expended. There is reason for >paragraphs to be displayed not too wide, and that is readability. What >the unixer could not get clear of is a distinction of concepts. Because >their fantastically hacked-up operating system operate by the principle >that lines should not be some 80 chars or else it will be truncated and >*silently* too, thus it became _necessarily_ their _habit_ and thought >that line truncation business is natural and a human duty. Unknown of >these setups, the unix geeks go by their presumption that all text >should be hard wrapped, as if parameters should be hard-coded. > >I recall, two particular unix hotshots who bugged me about the line >truncations business is the Perl priest Tom Christiansen, who used to >reside over comp.lang.perl.*, and another unix jockey Chris Nandor, who >was a MacPerl proponent now the main maintainer. It is not a >coincidence that the people who go out of their way to complain about >any ?format=flowed? or softwrapped or logically-formatted lines in >emails are always the unixers. The unix twits will start a flame war >over a petty formatting issue, because it's unix's training to bent >over pettiness, not to mention they are the ones who are retarded on >the issue of line truncation. > >As i have alluded to above, there are serious problems with the >line-truncation ways of thinking. The gist is that it is a form of >physical formatting as opposed to logical. (think softwrap vs hardwrap, >parameter vs hard-code) Those who are familiar with the history or >reason for SGML and HTML should understand the problem. Many of you >familiar with drive of evolution of HTML from 1995 days to today's CSS >& XML should also understand the issue. We wish to encode information, >and be flexible about representation, not botching info into one >particular representation. > >The harm done by the unixers to society is of a long lasting and >pervasive nature. First is the RFC, which serves as the mob's standard, >which requires that every emailer should be broken like unix, so that >unix can process them without problems. Fuck unix and fuck unix geeks. >Secondly, it drains human labor. Right this second there are hundreds >of people pressing returns or fixing jagged lines unnecessarily. >Thinking and computer could have done that for us, if not for fucking >stupid unix and its people. Thirdly, a generation of programs and >programer's times are wasted over tools that mutilate paragraphs into >pieces. (in emacs, there's fill-paragraph etc, and in BBEdit it's just >called ?Hard Wrap?) Fourthly, physical formatting ultimately >multiply the process required on the data, as we can see in emails, >especially in combination with the stupid quote convention: ?>? >(that's another unix invention.). But most importantly is that the >hard-liners instilled a bad notion, a confusion, that generated a >entire generation of utterly stupid programing languages and monkey >coders, starting with unix's C language. > >As of 200506, the following two sites shows that >as late as 2001, unix tool tar (BSD) still truncate long file names. >? http://www.sourcekeg.co.uk/www.mysql.com/doc/mysql/en/mac-os-x.html >(local copy) >http://nrg.cs.usm.my/~tcwan/macosx_essentials.htm >(local copy) > >-------------------- >This post is archived at: >http://xahlee.org/UnixResource_dir/writ/truncate_line.html > > Xah > xah at xahlee.org >? http://xahlee.org/ > > > From peter at somewhere.com Wed Aug 31 10:22:29 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 16:22:29 +0200 Subject: Bicycle Repair Man usability In-Reply-To: References: <1125439673.688666.264820@z14g2000cwz.googlegroups.com> Message-ID: Sybren Stuvel schrieb: > I use BRM if I need to rename a function or variable, and that's about > it. I do the rest by hand faster than I can figure out how to use > additional software. Sounds like "I can walk from Aachen to Cologne faster than figure out how to drive a car" ;) I don't know BRM nor any other refactoring tool but for a thorough decision one would have to know the ratio time(learningTool)/time(doingByHand) to calculate the break even point in terms of number(doingByHand). -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From provato at gmail.com Wed Aug 17 09:20:46 2005 From: provato at gmail.com (DK) Date: 17 Aug 2005 06:20:46 -0700 Subject: stopping a python windows service References: <1124230320.593335.288650@g44g2000cwa.googlegroups.com> Message-ID: <1124284846.064888.276430@g43g2000cwa.googlegroups.com> I may have taken your code example too literally. I tried putting in the check for 'shutdownEvent.isset()' but it's failing at run time. It's looking for a global variable, I guess. Do I have to register these threads somehow in the beginning? I'm somewhat new to Python so please be patient... From http Fri Aug 19 05:40:08 2005 From: http (Paul Rubin) Date: 19 Aug 2005 02:40:08 -0700 Subject: global interpreter lock References: <7xwtmi70c6.fsf@ruckus.brouhaha.com> Message-ID: <7x8xyyqn7r.fsf@ruckus.brouhaha.com> Robin Becker writes: > > http://poshmodule.sf.net > Is posh maintained? The page mentions 2003 as the last date. Dunno, and I suspect not. I've been wondering about it myself. From mwm at mired.org Thu Aug 18 23:01:29 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 18 Aug 2005 23:01:29 -0400 Subject: python html References: Message-ID: <86oe7ud3zq.fsf@bhuda.mired.org> Steve Young writes: > Hi, I am looking for something where I can go through > a html page and make change the url's for all the > links, images, href's, etc... easily. If anyone knows > of something, please let me know. Thanks. I've been doing a lot of that today. But the tool I'm using is sh and sed, because what I'm doing is captured nicely by regular expressions on the URLs. You might consider that option. If you have well-formed HTML, you can use the HTMLParser module, and write out the mangled data as it passed through your sublcass of the HTMLParser class. If the HTML isn't well-formed (which is probably true for most of the stuff on the web), you need a more understanding parser. I'd look into using BeatifulSoup for this, though Iv'e only used it to extract information from web pages, not to modify them. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From meng at are.berkeley.edu Tue Aug 2 13:32:29 2005 From: meng at are.berkeley.edu (meng at are.berkeley.edu) Date: Tue, 02 Aug 2005 10:32:29 -0700 Subject: bug in python/numarray Message-ID: <5.1.1.5.2.20050802103138.04c79d50@are.berkeley.edu> Hi, there, I got different results by running the same lines of code on windows and debian. Here is the code: a = kroneckerproduct(ones((4195,1)), identity(12)) print a.mean() This works perfectly well in windows but it gave the following error while running it in debian: Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line 1137, in mean return self.sum()/(self.nelements()*1.0) File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line 1133, in sum return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat, type=type) IndexError: too many indices. But if I reduce the number 4195 to 419, it works. Is it a bug in Python or Numarray? Can someone help me figure it out? BTW, the python version is 2.4.1 Many thanks! Xiangyi From saint.infidel at gmail.com Thu Aug 11 16:32:28 2005 From: saint.infidel at gmail.com (infidel) Date: 11 Aug 2005 13:32:28 -0700 Subject: breaking a loop In-Reply-To: References: Message-ID: <1123792348.010755.193820@g44g2000cwa.googlegroups.com> > Desired behavior: when I type 'exit' the program should quit. def search(): user_input = '' while True: user_input = raw_input('Search for: ') if user_input == 'exit': break print 'processing', user_input Note that putting user input directly into SQL statements leaves your database open to SQL-injection attacks :-) From jgrahn-nntq at algonet.se Sun Aug 7 06:34:28 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 7 Aug 2005 10:34:28 GMT Subject: Creating a virtual file system References: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> Message-ID: On 5 Aug 2005 16:47:08 -0700, Atila Olah wrote: > I'm working on a project to implement a simple cross-platform file > sharing protocol (using Python) that is similar to HTTP, and I have to Like WebDAV, then? > My question is: How do I implement a virtual partition that acts like a > real file-system and is compleatly transparent to other programs? > Should I make a virtual file allocation table for a FAT32 partition or > simulate an NTFS? Or even further: How do I create a junction (or a > hard link) to it in "My network places" or in "Entire Network"? You're asking in the wrong group completely. What you are trying to do is to extend the Windows kernel. This is almost certainly a difficult and dangerous task, and it will require C or C++ programming against Windows APIs that may or may not be available to mere mortals. On the other hand, if you can get such a thing to work, it would be very fun and useful. It's easier on Linux, but probably not /easy/. Google for "user space file system" and "webdav file system". Also note that this has nothing to do with FAT32 or NTFS. Those describe two different physical layouts of bits on a disk, and there's a driver for each that expose them to the kernel as a set of read/write/list directory calls. Your file system driver will have to expose the same calls, but implement them in a completely different way that has nothing to do with bits on a disk. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From cantabile.03 at wanadoo.fr Wed Aug 3 11:02:37 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Wed, 03 Aug 2005 17:02:37 +0200 Subject: pygettext ? In-Reply-To: References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: <42f0dc8d$0$894$8fcfb975@news.wanadoo.fr> Jon Hewer a ?crit : > Hi > > I'm pretty new to Python, and recently been working my way through > Dive Into Python, and I'm currently writing a really simple rss reader > purely to get familiarised with the language. I want to move onto > something a little more challenging, but I'm stuck for ideas on what > to do. > > I'm after a project that can start quite simple, but has lots of room > for expansion when I get more confident with Python. Ideally > something which would start as a command line program, and then when I > feel adventurous I could build a GUI for it. > > I have just bought the Foundations of Python Network Programming book, > so maybe something network related would be good? > > Cheers > Jon Excuse me but what has this answer to do with my question ? From rkern at ucsd.edu Fri Aug 26 04:24:40 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 26 Aug 2005 01:24:40 -0700 Subject: variable hell In-Reply-To: References: Message-ID: Adriaan Renting wrote: > Not in my Python. > > >>>>for count in range(0, 10): > > ... value = count > ... exec("'a%s=%s' % (count, value)") But that's not what rafi suggested. rafi: > why using the eval? > > exec ('a%s=%s' % (count, value)) See the difference? -- 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 mynews44 at yahoo.com Thu Aug 18 10:58:32 2005 From: mynews44 at yahoo.com (googleboy) Date: 18 Aug 2005 07:58:32 -0700 Subject: Confused newbie needs help with "__init__() takes exactly 11 arguments (1 given)" Message-ID: <1124377112.427700.177790@g47g2000cwa.googlegroups.com> I've written a little script to parse a csv file then use seach/replace over a template to create a file for each line in the file. It pikes out when I call the function that parses the csv (read_revs). If I have inadvertantly left an extra comma or two in the comma field, it gives an error that says: Traceback (most recent call last): File "C:\dev\python\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "d:\dev\python\projects\books\revgen3.py", line 177, in ? gen_html() File "d:\dev\python\projects\books\revgen3.py", line 92, in gen_html revlist = read_revs(r'D:\library\work\websites\gobooks\cgi\reviews.csv') File "d:\dev\python\projects\books\revgen3.py", line 38, in read_revs reviews = [Review(*[field.strip() for field in row]) for row in reader] TypeError: __init__() takes exactly 11 arguments (13 given) Which I understand totally, because I can see the two extra fields in the csv. Problem is, if I correct that problem it gives me confusing output that is identical except for the final line which says: TypeError: __init__() takes exactly 11 arguments (1 given) I don't get how it goes from 13 arguments to 1! I now have 10 fields and can understand that it is passing self as the 11th argument. Particularly confusing to me was that when I translated this from a windows box running Python 2.4 to an OpenBSD box running python 2.3, it just worked on the unix box. Find below an the code and an example of the csv file in question. TIA googleboy ----- param1,param2,param3,param4,param5,param6,param7,param8,param9,comments data1,data2,data3,data4,data5,data6,data7,data8,data9,Comments on the item reviewed go here. Sometime, but not all the time, there might be extra commas in this text. data1,data2,data3,data4,data5,data6,data7,data8,data9,Comments on the item reviewed go here. ------ import string, os, re, sys, operator, csv class Review(object): def __init__(self, param1, param2, param3, param4, param5, param6, param7, param8, param9, comments): params = locals() del params['self'] self.__dict__.update(params) def __repr__(self): all_items = self.__dict__.items() return '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % (self.param1, self.param2, self.param3, self.param4, self.param5, self.param6, self.param7, self.param8, self.param9, self.comments) def read_revs(filename): csv_file = open(filename, "rb") reader = csv.reader(csv_file) reviews = [Review(*[field.strip() for field in row]) for row in reader] csv_file.close() return reviews def gen_revs(): revlist = read_revs(r'd:\dev\python\projects\books\reviews.csv') revheader = revlist[0] all_reviews = revlist[1:] template = open(r'd:\dev\python\projects\books\template.txt', 'r') sTemplate = template.read() for review in all_reviews: param1 = getattr(review, 'param1') param2 = getattr(review, 'param2') param3 = getattr(review, 'param3') param4 = getattr(review, 'param4') param5 = getattr(review, 'param5') param6 = getattr(review, 'param6') param7 = getattr(review, 'param7') param9 = getattr(review, 'param8') param9 = getattr(review, 'param9') comments = getattr(review, 'comments') output = template % (param1, param2, param3, param4, param5, param6, param7, param8, param9, comments) f=open(r"d:\dev\python\projects\books\%s.html" % param1, 'w') f.write(output) f.close() From theller at python.net Sat Aug 6 07:20:49 2005 From: theller at python.net (Thomas Heller) Date: Sat, 06 Aug 2005 13:20:49 +0200 Subject: Do I need to have site.py available or not ? References: <1123257409.099201.114960@g49g2000cwa.googlegroups.com> <3li24kF11appjU1@individual.net> Message-ID: Reinhold Birkenfeld writes: > Terry Reedy wrote: >> wrote in message >> news:1123257409.099201.114960 at g49g2000cwa.googlegroups.com... >>> Hi, >>> on startup my embedded python comes up with "import site failed use >>> -v". Later python crashes on Pyrun_file(). This is the first time I >>> have used python and I would like to know does it require site.py to be >>> read in, and has anyone got an idea how to pass in the -v without using >>> the python -v command, ie the embedded way. Thanks very much. >> >> If by embedded you mean embedded in a C/C++ program, I would look to the >> doc for the C API function that you use to start it up to see whether there >> is a way to pass in argv flags or to have the same effect. > > Also note that '-v' doesn't do what you want here, it merely activates verbose > mode so that you can find the cause for above error. You want '-S'. I would say that "import site failed" means that something is wrong. The '-v' flag helps to find out what and why. The PYTHONVERBOSE environment variable does the same. Thomas From tow21 at cam.ac.uk Tue Aug 23 12:44:50 2005 From: tow21 at cam.ac.uk (Toby White) Date: Tue, 23 Aug 2005 17:44:50 +0100 Subject: Limited XML tidy Message-ID: I have a program which produces well-formed XML documents, but takes several hours if not days to do so. It would be useful to be able to take the incomplete output and manipulate it as XML. Clearly, however, the incomplete output will not be well- formed, so before being able to manipulate it I need to make it wellformed. This is essentially fairly simple. I know it's well-formed up to now - all I need to do is close unclosed tags. So, I 've made a short function that will do this: #!/usr/bin/python import sys import xml.sax tagStack = [] closingTags = "" class DodgyHandler(xml.sax.ContentHandler): def startElement(self, tag, attributes): tagStack.append(tag) def endElement(self, tag): tagStack.pop() class DodgyErrorHandler(xml.sax.ErrorHandler): def fatalError(self,exception): global closingTags tagStack.reverse() for tag in tagStack: closingTags += "" % tag return closingTags def finishXML(text): p = xml.sax.make_parser() p.setContentHandler(DodgyHandler()) p.setErrorHandler(DodgyErrorHandler()) for line in text: p.feed(line) p.close() text.append(closingTags) However - while this works for 90% of the cases I need, it fails in the case where my incomplete output stops in the middle of a tag (not to mention some other more arcane places I don't really care about). The problem is that when the sax handler raises an exception, I can't see how to find out why. What I want to do is for DodgyErrorHandler to do something different depending on where we are in the course of parsing. Is there anyway to get that information back from xml.sax (or indeed from any other sax handler?) Toby -- Dr. Toby White Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK Email: From steve at holdenweb.com Mon Aug 29 16:22:20 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Aug 2005 16:22:20 -0400 Subject: reg email packages work In-Reply-To: <20050829073514.12323.qmail@web8405.mail.in.yahoo.com> References: <20050829073514.12323.qmail@web8405.mail.in.yahoo.com> Message-ID: praba kar wrote: > Dear All, > > I am working in web based email system project. > Here I try to build email message > from scratch. I used below code to build email > message > > msg = email.MIMEBase('text','html') > msg['Return-Path'] = user+'@'+domain > msg['Date'] = formatdate(localtime=1) > msg['Subject'] = subject > msg['From'] = from_name > msg['To'] = to > msg['Cc'] = cc > msg.set_payload("Body of the email messagge") > fh = os.popen('/bin/sendmail %s'% (eachid),'w') > fh.write(msg.as_string()) > fh.close() > > This code will build plain email message properly. > But after building the message. If a email user > download this mail through out look express then > this email message will display without any alignment. > If a user type 3 paragraph message > outlook express display as a single line. What > could be problem?. Kindly let me know ASAP > It's obvious you aren't using that EXACT code, because it doesn't formulate a three-paragraph message. So the bit we really need to see is how you capture and formulate the argument to set_payload(). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mhenry1384 at gmail.com Wed Aug 17 09:25:38 2005 From: mhenry1384 at gmail.com (mhenry1384) Date: 17 Aug 2005 06:25:38 -0700 Subject: get the return code when piping something to a python script? In-Reply-To: References: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> Message-ID: <1124285138.352319.298070@g47g2000cwa.googlegroups.com> Now that I know it's not possible to do what I wanted, I can work around this without a problem. I'll just scan the output of the .exe to determine whether it appears to have failed or not. Thanks to everyone for the info. From steve at myplace.com Fri Aug 12 17:58:11 2005 From: steve at myplace.com (Steve M) Date: Fri, 12 Aug 2005 16:58:11 -0500 Subject: Printing to printer References: Message-ID: Kristian Zoerhoff wrote: > On 8/11/05, Steve M wrote: >> Kristian Zoerhoff wrote: >> >> > On 8/11/05, Steve M wrote: >> >> Hello, >> >> >> >> I'm having problems sending information from a python >> >> script to a printer. I was wondering if someone might send me >> >> in the right direction. I wasn't able to find much by Google >> > >> > Which platform? Directions will vary wildly. >> > >> Ooops, sorry forgot to mention I'm using Suse 9.0 and Python 2.3x > > Assuming a local printer, you could just open the appropriate > device file (e.g. /dev/lp0) in write mode and write the text to it. > Another option would be to create a temp file, and then feed that > to the lpr or enscript commands via the subprocess module. > Thank you for your help. I try and work it out now that I have a direction. Steve From merkosh at hadiko.de Fri Aug 12 16:40:08 2005 From: merkosh at hadiko.de (Uwe Mayer) Date: Fri, 12 Aug 2005 22:40:08 +0200 Subject: Bug on Python2.3.4 [FreeBSD]? References: Message-ID: Friday 12 August 2005 22:12 pm David Bolen wrote: > Which version of FreeBSD are you running? I thought it might be a > dependency on needing to seek between reads and writes on a duplex > stream (which is ANSI), but FreeBSD doesn't require that, at least > back as far as a 4.7 system I have, and I assume much earlier than > that. > > One dumb question - are you absolutely sure it wasn't appending? As > written, there's no trailing newline on the file, so your final "cat > test" would produce output where the "testing" was on the same line as > your next command prompt, and can sometimes be missed visually. > >> Can anyone confirm that? Is there any other way of opening a file for >> appending instead of a+? > > Well, if you really just want appending, I'd just use "a". It creates > the file if necessary but always appends to the end. Of course, it's > not set up for reading, but you wouldn't need that for appending. I was debugging an application I released, on a forreign FreeBSD system: $ uname -a FreeBSD hephaistos 4.11-RELEASE FreeBSD 4.11-RELEASE #0: Sun Feb 27 21:09:39 CET 2005 root at olympus.tfp:/storage/obj-4.11/usr/src/sys/OLYMPUS i386 The application as able to create and write to files, but not to open and read them. It seems the file poitner is positioned at the end of a file when using: >>> f = open('', 'a+') on FreeBSD, but at the beginning of the file on Linux (at least on my Debian unstable, Python 2.3.4 and 2.3.5; its running on Gentoo Linux and Suse, too, though I don't know the Python version numbers). I was assuming the fp was set to 0 in this mode, thus the app was not working on above FreeBSD and the owner set up a login for me to debug the situation. The problem is easyly fixed by appending a f.seek(0) after opening the file, but the position of the fp is strange. Thanks, Ciao Uwe From jmdeschamps at cvm.qc.ca Mon Aug 15 11:57:48 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 15 Aug 2005 08:57:48 -0700 Subject: seeking Python developers In-Reply-To: <1124121180.796627.105810@g44g2000cwa.googlegroups.com> References: <1124121180.796627.105810@g44g2000cwa.googlegroups.com> Message-ID: <1124121468.195490.323180@g43g2000cwa.googlegroups.com> What level? and is geography important? JM From giampiero19601 at yahoo.it Tue Aug 2 09:56:54 2005 From: giampiero19601 at yahoo.it (giampiero mu) Date: 2 Aug 2005 06:56:54 -0700 Subject: finding sublist Message-ID: <1122991014.595476.5740@g47g2000cwa.googlegroups.com> hi everyone my target is implement a function controlla(string - a binary string-) that check if there is in a string two equal not overlapping subsequences at least of length limitem: my code: def controlla(test): # print test limitem=4 lunghezz=len(test) l1=lunghezz-limitem+1 l2=lunghezz-limitem+1 f=0 for ii in range(l1): for kk in range(l2): t1=test[ii:ii+limitem] t2=test[kk:kk+limitem] if abs(ii-kk)>=limitem : if t1==t2 : f=1 if f==1 : break break break if f==0 : return test else: return 'no' the question is: Is there a faster way doing that? I don't know, changing string into list or array, using map, or module, using different loop, regular expression,funcional programming , list comprehensions , sets, different looping techniques, i dont know.......(!) From mwm at mired.org Fri Aug 12 20:55:30 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 12 Aug 2005 20:55:30 -0400 Subject: Writing a small battleship game server in Python References: <200508111746.15668.mail@tuxipuxi.org> <1123778097.6562.35.camel@localhost.localdomain> Message-ID: <86zmrm64fx.fsf@bhuda.mired.org> Michael Goettsche writes: > On Thursday 11 August 2005 18:34, Dan wrote: >> > The server should accept connections from new players and be able to >> > handle multiple games concurrently. >> >> Multiple threads would be the way to go for a real application. But if >> you want to avoid the complexity involved in threading and >> synchronization in this exercize, you can avoid threads by using >> "select" instead: >> http://www.python.org/doc/2.3.5/lib/module-select.html >> >> The "select" function allows you to determine (without blocking) which >> sockets have input available. >> >> Python's "select" is a wrapper for the C function with the same name. On >> Unix you can learn more about it using "man select". >> > > Thanks Dan. > Assuming the server accepts connections in an endless loop, how would I handle > communication without additional threads and create new games in that loop? > Could you give me pseudo-code for this? I recommended threads even more strongly than Dan did, so I'll answer as well. The pseudocode is: while 1: (rd, wr, xl) = select(rl, wl, xl) for sock in rd: socketdict(sock).do_read() for sock in wr: socketdict(sock).do_write() for sock in xl: socketdict(sock).do_except() Basically, you have objects that handle doing reads, writes, and "other things". You create a new object every time you get a new connection from your listennig socket, and store the object in socketdict indexed by the socket. You may have different types of objects in the dictionary, depending on what the socket is doing. In particular, the socket that is doing an accept() will have an object that creates new objects and stores them in the dictionary, whereas other sockets aren't likely to need that capability. When the objects socket has data ready to be read, it's do_read method will be called. When the socket is ready for a write, it's do_write method is called. When other conditions happen, it's do_except method is called. Those methods are pretty much the same whether you're using theads os asynchronious IO. Two critical differences: the I/O to the sockets must be done non-blocking, and you rally want to avoid operations that soak up lots of real time. There are frameworks around that already deal with all of this stuff for you. Twisted comes to mind, but I've never used it, and it may no be what I think it is. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From sjmachin at lexicon.net Fri Aug 19 18:55:46 2005 From: sjmachin at lexicon.net (John Machin) Date: Sat, 20 Aug 2005 08:55:46 +1000 Subject: stdin -> stdout In-Reply-To: References: Message-ID: <43066371@news.eftel.com> limodou wrote: > 2005/8/19, max(01)* : > >>hi. >> >>i was wondering, what's the simplest way to echo the standard input to >>the standard output, with no modification. >> >>i came up with: >> >>... >>while True: >> try: >> raw_input() >> except EOFError: >> break >>... >> >>but i guess there must be a simpler way. >> >>using bash i simply do 'cat', *sigh*! >> >>bye >> >>max >> >>ps: in perl you ca do this: >> >>... >>while ($line = ) >> { >> print STDOUT ("$line"); >> } >>... > > > Try this. > > import sys > > line = sys.stdin.readline() > while line: > sys.stdout.write(line) > line = sys.stdin.readline() > Try this: import sys for line in sys.stdin: sys.stdout.write(line) From tvmaly at gmail.com Thu Aug 18 11:07:03 2005 From: tvmaly at gmail.com (tvmaly at gmail.com) Date: 18 Aug 2005 08:07:03 -0700 Subject: Creating watermark with transparency on jpeg using PIL? Message-ID: <1124377623.599745.17750@g44g2000cwa.googlegroups.com> I have been trying to add a watermark to a jpeg using PIL, but the watermark has a black box around it. I looked at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879 and http://mail.python.org/pipermail/python-list/1999-May/003369.html but I think these only refer to gif or png. I know jpegs really do not support transparency, but is there some way to take a watermark in a non jpeg format and add it to a jpeg without that box appearing around it? Best Regards Ty From ed at leafe.com Mon Aug 1 12:20:41 2005 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Aug 2005 12:20:41 -0400 Subject: Dabo in 30 seconds? In-Reply-To: References: <200508010830.27322.ed@leafe.com> Message-ID: <200508011220.41469.ed@leafe.com> On Monday 01 August 2005 11:56, Terry Reedy wrote: > That is an impossibility. ?However, there is a middle path between that and > no defensive code. ?In the present case, you appear to acknowledge a known > easy way to mis-compile wxWidgets from Dabo's viewpoint. ?If there is a > known easy way to detect that misconfiguration (which I suspect there is), > and it is known that someone has tripped over that problem (which it now > is), then a nice error message ?like 'Sorry, Dabo need wxWidgets compiled > with the --include_stylized_text option' would certainly be friendlier than > a stack trace. OK, that's more of what I had in mind. Truth be told, this is the first time we've run into this, and as a result I'll make the change to that import statement today. We've taken the attitude that when a bug/shortcoming is pointed out, we address it. But one problem with that is when you only have a handful of people actively using and testing it, you limit your potential for discovering problems. If nothing else, this thread has helped by pointing out one such shortcoming. ;-) -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From alessandro.bottoni at infinito.it Sat Aug 27 05:15:55 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Sat, 27 Aug 2005 09:15:55 GMT Subject: Python library/module for MSAccess References: <430fc532$1@nntp0.pdx.net> Message-ID: Christos Georgiou wrote: > I think the OP wants to *use* .mdb files on a linux system without using > any msjet*.dll libraries. Looks like you need a .mdb driver for the Python DB-API. Have a look here: http://www.python.org/topics/database/ http://www.mayukhbose.com/python/ado/ado-connection.php (ADO) http://www.vex.net/parnassus/ (Python Vaults of Parnassus) Have a look at Kexi, as well (KDE based, no Python involved): http://www.koffice.org/kexi/ http://www.kexi-project.org/ HTH ----------------------------------- Alessandro Bottoni From bj_666 at gmx.net Thu Aug 11 15:52:11 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Thu, 11 Aug 2005 21:52:11 +0200 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123708379.036298.134210@g43g2000cwa.googlegroups.com> Message-ID: In <1123708379.036298.134210 at g43g2000cwa.googlegroups.com>, Qopit wrote: > I'm > a big fan of Python's ability to easily rebind everything in sight, but > this particular usage seems like a strange abuse I wouldn't expect a > code-checker to be able to figure out. I'll just avoid writing > confusing code like that... it's not only confusing to a program, but > to a human as well! Dynamically massacring a function definition (as > opposed to just rebinding a new implementation) like that seems odd to > me. Well it's a contrived example. But taking a function or method and wrap it with some other function or method isn't that uncommon. For methods there is even syntactic sugar: decorator syntax. Here's a more useful dynamic function wrapping:: def debug_trace(func): def wrapper(*args, **kwargs): print 'Calling %s' % func.__name__ print 'args: %r' % (args,) print 'kwargs: %r' % kwargs func(*args, **kwargs) return wrapper def test(a, b, c): print 'just a test', a, b, b test = debug_trace(test) test(1, 2, 3) test(1, 2) Here it's quite clear to a human reader that the wrapping doesn't change the number of arguments. But it's harder to let a program figure this out. Ciao, Marc 'BlackJack' Rintsch From steve at holdenweb.com Mon Aug 29 17:28:22 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Aug 2005 17:28:22 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: Antoon Pardon wrote: > Op 2005-08-27, Steve Holden schreef : > >>> >>If you want an exception from your code when 'w' isn't in the string you >>should consider using index() rather than find. > > > Sometimes it is convenient to have the exception thrown at a later > time. > > >>Otherwise, whatever find() returns you will have to have an "if" in >>there to handle the not-found case. > > > And maybe the more convenient place for this "if" is in a whole different > part of your program, a part where using -1 as an invalid index isn't > at all obvious. > > >>This just sounds like whining to me. If you want to catch errors, use a >>function that will raise an exception rather than relying on the >>invalidity of the result. > > > You always seem to look at such things in a very narrow scope. You never > seem to consider that various parts of a program have to work together. > Or perhaps it's just that I try not to mix parts inappropriately. > So what happens if you have a module that is collecting string-index > pair, colleted from various other parts. In one part you > want to select the last letter, so you pythonically choose -1 as > index. In an other part you get a result of find and are happy > with -1 as an indictation for an invalid index. Then these > data meet. > That's when debugging has to start. Mixing data of such types is somewhat inadvisable, don't you agree? I suppose I can't deny that people do things like that, myself included, but mixing data sets where -1 is variously an error flag and a valid index is only going to lead to trouble when the combined data is used. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From nochiel at gmail.com Mon Aug 1 03:50:07 2005 From: nochiel at gmail.com (yoda) Date: 1 Aug 2005 00:50:07 -0700 Subject: Py: a very dangerous language Message-ID: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> It was 2a.m.... I was writing my first enterprise scale application in Python.... the logic just flowed from my mind onto the keyboard and was congealed into the most beautiful terse lines of code I had ever seen... It was 3a.m.... I knew I had to sleep.... work the next day or rather, in a few hours.... but Python somehow brought out all the logic. All the verbosity of my thought was purified into clean beautiful logic... The Python was wringing the cruft out of my thought and letting me generate wonderfully clean code.... I have to sleep... this is the last line of code i'm writing... It was 4a.m.... just one more def... then I'll sleep.. It was 5 a.m.... just one more class...I'll sleep now.. I've got to go to work in a few hours.... It was 6 a.m.... just one more lambda...I'll really sleep now...seriously... I've got to go to work in a few hours.... Python is a very dangerous language... It is addictive.. Once you start coding, you simply can't stop.... No language has every made(allowed?) me to think so clearly before.... This is madness.. I hardly every sleep... I simply can't stop coding when I use Python.... This is scary... maybe I should switch back to Java: a language so unwieldy that I'm driven away from the keyboard in disgusted frustration.... I need to sleep.. but Python won't let me... Python is a dangerous language.... From nicolas.riesch at genevoise.ch Wed Aug 10 08:18:49 2005 From: nicolas.riesch at genevoise.ch (nicolas_riesch) Date: 10 Aug 2005 05:18:49 -0700 Subject: Syntax error after upgrading to Python 2.4 References: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> Message-ID: <1123676329.723972.302420@g44g2000cwa.googlegroups.com> frr at easyjob.net wrote: > additive = self.additive, > ^ > SyntaxError: invalid syntax > I'm using Windows XP and Python 2.4.1 > > Any ideas? O:-) I had a similar problem with python 2.4.1. When I imported some module, I got a SyntaxError like you. But if I run the module directly, and not importing it, it works and dos not trigger any SyntaxError. As a workaround, I put a comment ( just a # can do ) at the end of the offending line, and I could then import the module without any problem. It is certainly a bug, and I think it is perhaps this one ( bug 1211639 ): http://sourceforge.net/tracker/index.php?func=detail&aid=1211639&group_id=5470&atid=105470 or this one ( bug 1200686 ): http://sourceforge.net/tracker/index.php?func=detail&aid=1200686&group_id=5470&atid=105470 From simon.brunning at gmail.com Tue Aug 16 04:05:27 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Tue, 16 Aug 2005 09:05:27 +0100 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: <200508151316.34512.hancock@anansispaceworks.com> References: <8c7f10c6050815075443fc446a@mail.gmail.com> <200508151316.34512.hancock@anansispaceworks.com> Message-ID: <8c7f10c605081601053693f374@mail.gmail.com> On 8/15/05, Terry Hancock wrote: > On Monday 15 August 2005 09:54 am, Simon Brunning wrote: > > If you call its code, it's a library. If it calls yours, it's a framework. > > Such concision deserves applause. ;-) Thank you. ;-) As others have pointed out, this is a *drastic* simplification, perhaps an oversimplification. You will inevitably need to call a framework's code in addition to it calling yours, and a callback argument or two won't turn a library into a framework. But I think it captures the essence of the difference. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From cliff at develix.com Thu Aug 4 16:41:02 2005 From: cliff at develix.com (Cliff Wells) Date: Thu, 04 Aug 2005 13:41:02 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <86irym1ee5.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <8664uqhkfj.fsf@bhuda.mired.org> <86hde9f172.fsf@bhuda.mired.org> <86r7dbeuvq.fsf@bhuda.mired.org> <86r7db16a9.fsf@bhuda.mired.org> <86irym1ee5.fsf@bhuda.mired.org> Message-ID: <1123188062.7189.28.camel@localhost.localdomain> On Thu, 2005-08-04 at 01:04 -0400, Mike Meyer wrote: > Right. Let's go back to the original question: What's the app I use on > Unix that acts like py2exe on Windows and py2app on Unix? > > Any archiving system can be coerced into collecting all the parts > together. None of them do it automatically. That automatically makes > them *not* an answer to the question. Nothing. Since it isn't all written for you it can't be done. Have a nice day. -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From cmedcoff at hotmail.com Tue Aug 2 13:03:26 2005 From: cmedcoff at hotmail.com (chuck) Date: 2 Aug 2005 10:03:26 -0700 Subject: pre subprocess module help Message-ID: <1123002206.772923.174120@g44g2000cwa.googlegroups.com> I need to execute a command shell process obtain the return code and capture stdout from that shell process. I've done this with 2.4 using subprocess. How do I do it with 2.3? From Florian.Lindner at xgm.de Fri Aug 19 11:56:57 2005 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Fri, 19 Aug 2005 17:56:57 +0200 Subject: Python for Webscripting (like PHP) References: Message-ID: Florian Lindner wrote: > Hello, > I've been using Python a lot for scripting (mainly scripts for server > administration / DB access). All these scripts were shell based. > > Now I'm considering using Python (with mod_python on Apache 2) for a web > project, just how I've used PHP in some smaller Projects before ( print "foo" ?>).. > > How suitable is Python for these kind of projects? What do think? Does the > stdlib offers all basic functions for this kind of requirements? An email I got from Dan Richter. Since he has problems with his news/mail gateway I forward it with his permission for the benefit of others. Florian - - - Python is great for "heavy lifting": when most of the work is done behind the scenes and outputting the HTML is relatively trivial. An example would be a program that searches archives or computes derivatives. But PHP is designed for web pages and is quite powerful. If you can reasonably do a job in PHP, you probably should. Web sites written in Python usually involve lots of statements like these: uri = os.environ['HTTP_URI'] print '' + theTitle + '' print '''

The answer to your question

After lots of computing, here's what we discovered.

''' And so on. As you can see, PHP allows you to embed HTML much more gracefully, as well do other web-like things such as retrieve URL query string parameters more easily. So PHP is preferable for most web sites. Depending on what you want to do, you might also consider Perl and Java Servlets. - - - From oddr at home.no.no Wed Aug 10 05:54:26 2005 From: oddr at home.no.no (Odd-R.) Date: 10 Aug 2005 09:54:26 GMT Subject: searching a list of dictionaries for an element in a list. Message-ID: If input is ['red','blue'], list1 is [ {'primarycolor':'red', 'secondarycolor':'burgundee'}, {'primarycolor':'red', 'secondarycolor':'wine'}, {'primarycolor':'yellow','secondarycolor':'plain'}, {'primarycolor':'blue','secondarycolor':'ocean'}] I want to search list1, and the result should be all dictionaries where primarycolor is in input. I can do this using a double for-loop, but is there a more efficent way? -- Har du et kj?leskap, har du en TV s? har du alt du trenger for ? leve -Jokke & Valentinerne From Peter.Vandersteegen at gmail.com Wed Aug 3 06:55:03 2005 From: Peter.Vandersteegen at gmail.com (peter) Date: 3 Aug 2005 03:55:03 -0700 Subject: distutils package_dir newbie In-Reply-To: References: <1123055950.708133.66580@g49g2000cwa.googlegroups.com> <1123057785.888610.204630@g44g2000cwa.googlegroups.com> Message-ID: <1123066503.872412.79700@f14g2000cwb.googlegroups.com> hello Robert I've tried your setup.py file and now it seems to work... I've made the following fault in the setup: I did use: setup(..., packages = ['project_dev'], ...) instead of the correct one: setup(..., packages = ['project_user'], ...) you have been a great help Peter From paolo_veronelli at tiscali.it Mon Aug 8 06:51:25 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Mon, 08 Aug 2005 12:51:25 +0200 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) In-Reply-To: <42f659a4.848866235@news.oz.net> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <42F4F2D3.80804@tiscali.it> <42f659a4.848866235@news.oz.net> Message-ID: <42F7392D.6030209@tiscali.it> Bengt Richter wrote: > Nor do we have any correspondence for bare names analogous to > > setattr(obj, "name", value) <=> obj.name = value > > e.g., > > setname(, "name", value) Probably this parallelism is a better approach to what I commented before.Thanks for clarity. > There is nowhere near the kind of control the programmer has over attribute namespace > use for bare-name use, even though by various means we are able to select from a limited > set of namespaces. (BTW, if were a call to a suitable builtin function > that could return objects whose attribute namespace were the desired name space, then setname > could be effected with setattr, e.g., > > setattr(get_ns_obj(), "name", value) # name = value (defaulting to local, same as get_ns_obj(0)) > setattr(get_ns_obj(1), "name", value) # name = value (in lexically immediately (1) enclosing scope) > setattr(get_ns_obj(-1), "name", value) # name = value (in global module scope) > ) > Yes namespaces should be unified in their base behaviour. > I am thinking that there is a subliminal discussion under a layer of red herrings ;-) > I refer to the subject of unification/generalizing/orthogonalizing by removing special > legacy restrictions (or not introducing special restrictions in a new feature). > > E.g., recently decorators were introduced, and part of the discussion (which became explicit ;-) > was whether to allow the expression following the '@' to be a fully general expression, or > whether to restrict it to names, dotted names, and function calls. The latter won out. > > Some regard this kind of restriction as paternalistic, and protest that "we are adults here" > (even though we are not all, and we others not all the time ;-) > Uhmpf, adults==theorists and childrens==experimentals ? > The BDFL has introduced many new ideas, yet has retained or introduced restrictions on fully > orthogonal functionality that might otherwise be allowed if e.g. names in certain contexts > were allowed to be full expressions. It goes the other way too. IIRC the list of bases for > a class will be allowed to be an empty "()" soon. > > Bottom line, I think Python is eminently usable and very pleasant to use, but I think bare name > mechanisms could be improved. > A good dose of humility could be good for reingeneering something ,if necessary.Python is very usable,and has an almost perfect surface layer. But this is not enough.It needs to be strong and elegant in the insides to survive.More, isn't the "Namespaces do more of them" a Python Zen Law ? Thanks again for putting things in a saner and more open way then I did. Regards Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From oren.tirosh at gmail.com Fri Aug 26 02:28:33 2005 From: oren.tirosh at gmail.com (Oren Tirosh) Date: 25 Aug 2005 23:28:33 -0700 Subject: Email client in Pyhton In-Reply-To: References: Message-ID: <1125037713.267177.96100@g14g2000cwa.googlegroups.com> > IIRC, many of the mailbox modules (such as mailbox and > mhlib) are read-only, but they should provide a good starting point. The mailbox module has recently been upgraded for full read-write access by a student participating in google's Summer of Code. It is currently under review for inclusion in the standard library. From ray_usenet at yahoo.com Thu Aug 11 23:31:27 2005 From: ray_usenet at yahoo.com (Ray) Date: 11 Aug 2005 20:31:27 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <1123817487.901244.272700@z14g2000cwz.googlegroups.com> Fausto Arinos Barbuto wrote: > Ray wrote: > > > 1. Where are the access specifiers? (public, protected, private) > > AFAIK, there is not such a thing in Python. So everything is public? I know that you can prefix a member with underscores to make something private, but how about protected, for example? > > ---Fausto From could.net at gmail.com Mon Aug 8 23:41:23 2005 From: could.net at gmail.com (could ildg) Date: Tue, 9 Aug 2005 11:41:23 +0800 Subject: Python Project (sigh with Java) In-Reply-To: References: Message-ID: <311b5ce10508082041496c5fc9@mail.gmail.com> But the function is also too limited. What I want to do is to run much of my py scripts in jython as good as possible. On 8/9/05, Ramza Brown wrote: > could ildg wrote: > > Good job~ > > I also like both java and py so I always focus on jython, > > but now it's being moved forward kinda slow. > > I'm looking forward to jython 2.4. > > > > You're right, swing is great. wxpy is also wonderfu but it's so lack > > of docs. I mainly work on windows so I use p4d(python for delphi), I > > use delphi for UI and use py for some other works. p4d is magic, I > > like it. And I recommend it to everyone who is familiar with both py > > and delphi. > > > > On 8/9/05, Ramza Brown wrote: > > > >>I know you may frown at my use at java, but this is a pretty simple way > >>to create GUIs quickly, using Java's swing. I have some code for an > >>approach for integrating the swing GUI components and python. I threw > >>the project together in a couple of days, so it is not some massive > >>application. And, I have some little models(hehe). Anyway, if you want > >>to check out an approach for working with Jython, here it is. > >> > >>Some questions, I do get asked, how do you us python code in java. I > >>normally don't like using my python objects in the java code. > >>Basically, there is never the *.java files. You can do everything in > >>python, it is a lot simpler, short of language constructs you can only > >>do in java. > >> > >>This is a HTML code generator, you only need a java runtime. > >> > >>http://www.newspiritcompany.com/phoenixproj.html > >> > >>-- > >>Ramza from Atlanta > >>http://www.newspiritcompany.com > >>-- > >>http://mail.python.org/mailman/listinfo/python-list > >> > > And I normally don't take the entire python library with me. I just > take 'jython.jar' so I can distribute it easier. > > > > -- > Ramza from Atlanta > http://www.newspiritcompany.com > -- > http://mail.python.org/mailman/listinfo/python-list > From kent37 at tds.net Sat Aug 6 16:45:55 2005 From: kent37 at tds.net (Kent Johnson) Date: Sat, 06 Aug 2005 16:45:55 -0400 Subject: Get directory from http web site In-Reply-To: <1122029473.532056.215900@z14g2000cwz.googlegroups.com> References: <1122029473.532056.215900@z14g2000cwz.googlegroups.com> Message-ID: <42f52102$1_3@newspeer2.tds.net> rock69 wrote: > Hi all :) > > I was wondering if there's some neat and easy way to get the entire > contents of a directory at a specific web url address. > > I have the following link: > > http://www.infomedia.it/immagini/riviste/covers/cp > > and as you can see it's just a list containing all the files (images) > that I need. Is it possible to retrieve this list (not the physical > files) and have it stored in a variable of type list or something? BeautifulSoup and urllib do this easily: >>> from BeautifulSoup import BeautifulSoup >>> import urllib >>> data = urllib.urlopen('http://www.infomedia.it/immagini/riviste/covers/cp/').read() >>> soup = BeautifulSoup(data) >>> anchors = soup.fetch('a') >>> len(anchors) 164 >>> for a in anchors[:10]: ... print a['href'], a.string ... ?N=D Name ?M=A Last modified ?S=A Size ?D=A Description /immagini/riviste/covers/ Parent Directory cp100.jpg cp100.jpg cp100sm.jpg cp100sm.jpg cp101.jpg cp101.jpg cp101sm.jpg cp101sm.jpg cp102.jpg cp102.jpg http://www.crummy.com/software/BeautifulSoup/ Kent From somebody at nowhere.com Thu Aug 11 21:28:38 2005 From: somebody at nowhere.com (Sean Richards) Date: Fri, 12 Aug 2005 13:28:38 +1200 Subject: keywords for optional args in extension modules Message-ID: <87irycj649.fsf@MB5085.valhalla.net> Python 2.3.4 (#1, May 29 2004, 17:05:23) [GCC 3.3.3] on linux2 Getting some strange behaviour with keyword arguments for optional arguments in extension modules. See the simple test case below --------8<-------------------------------------------------- #include "Python.h" static PyObject * keywdarg_test(PyObject *self, PyObject *args, PyObject *keywds) { int one; unsigned int two = 2; int three = 3; static char *kwlist[] = {"one", "two", "three", NULL}; if (!PyArg_ParseTupleAndKeywords(args, keywds, "i|Ii", kwlist, &one, &two, &three)) return NULL; Py_INCREF(Py_None); return Py_None; } static PyMethodDef keywdarg_methods[] = { {"test", (PyCFunction)keywdarg_test, METH_VARARGS | METH_KEYWORDS}, {NULL, NULL, 0, NULL} }; void initkeywdarg(void) { Py_InitModule("keywdarg", keywdarg_methods); } --------8<-------------------------------------------------- Compile the module $ cc -g -c keywdarg.c -I/usr/include/python2.3 $ ld -shared -o keywdarg.so keywdarg.o Test it In [1]: from keywdarg import * In [2]: test(1) In [3]: test(1,two=2) In [4]: test(1,two=2,three=3) In [5]: test(1,three=3,two=2) In [6]: test(1,three=3) --------------------------------------------------------------------------- exceptions.TypeError Traceback (most recent call last) /home/sean/research/code/framework/wiener/ TypeError: argument 2, item 1074941247, item 1079307903 impossible However if I change the order of the optional arguments so the unsigned int is last as below then it works fine. if (!PyArg_ParseTupleAndKeywords(args, keywds, "i|iI", kwlist, &one, &three, &two)) This seems buggy. Python 2.3 is getting a bit old now but do later later versions still exhibit this behaviour? Cheers, Sean -- ~/.signature From jstroud at mbi.ucla.edu Fri Aug 12 01:13:37 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 11 Aug 2005 22:13:37 -0700 Subject: list to tuple In-Reply-To: <1123819543.351623.324870@f14g2000cwb.googlegroups.com> References: <1123819543.351623.324870@f14g2000cwb.googlegroups.com> Message-ID: <200508112213.37563.jstroud@mbi.ucla.edu> Try the zip funciton: py> a = [11,12,13,14] py> b = [2,3,4,5] py> c = [20,21,22,23,24,25] py> zip(a,b,c) [(11, 2, 20), (12, 3, 21), (13, 4, 22), (14, 5, 23)] On Thursday 11 August 2005 09:05 pm, zxo102 wrote: > Hi, > I got several dynamic lists a1, b1, c1, .... from a python > application such as > a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, .... > > With python, I would like to reorganize them into a tuple like > > t1 = ((a1[0],b1[0],c1[0],...),(a1[1],b1[1],c1[1],...),...) > > Anybody knows how to do that. Thanks for your help. > > Ouyang -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From spam at me.please Sat Aug 6 22:49:36 2005 From: spam at me.please (Evil Bastard) Date: Sun, 07 Aug 2005 14:49:36 +1200 Subject: seek python parser Message-ID: <42f57826@news.orcon.net.nz> Hi, Does anyone know of a python source parser program which can return the parsed source file as a coherent dom-like data structure? I'm playing around with ast, and the output of ast.tolist(), but it's got a lot of chaff, and would need a lot of hacking to break it down to simple data structures All recommendations appreciated -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From savvyside at aol.com Wed Aug 24 20:53:18 2005 From: savvyside at aol.com (michael) Date: Thu, 25 Aug 2005 00:53:18 GMT Subject: Command Line arguments Message-ID: I have a question about Windows based python (2.4 and later). For example, if I make a script called test.py like so: import sys print sys.argv then run it: python test.py this is a test I see a list with ['test.py', 'this', 'is', 'a', 'test'] All is good! BUT... If i make .py extensions be run as exes (by setting the .py extension to be executable with PATHEXT setting in environment variables, the Python program will run, but NO arguments are passed! For example, after setting .py extension to be executable, i get this: test this is a test I get ['test.py]. NO arguments are passed. NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and earlier works FINE. Any one have an idea? Thank you! Michael From steven.bethard at gmail.com Fri Aug 12 13:27:54 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 12 Aug 2005 11:27:54 -0600 Subject: __getattribute__ for class object In-Reply-To: References: <42FC87D7.3080807@libero.it> Message-ID: <_aGdneJZYpKIQWHfRVn-qQ@comcast.com> Dan wrote: > Depending on what you want to do, it might be better to use properties > instead: > > class Meta(type): > x = property(lambda klass: 'Called for '+str(klass)) > > class Foo(object): > __metaclass__=Meta Also worth noting that you can inline the metaclass if you don't need it anywhere else, e.g.: class Foo(object): class __metaclass__(type): x = property(lambda klass: 'Called for '+str(klass)) STeVe From pythonmailing at web.de Mon Aug 1 08:31:54 2005 From: pythonmailing at web.de (Marek Kubica) Date: Mon, 1 Aug 2005 14:31:54 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <873bpvqu9g.fsf@wilson.rwth-aachen.de> <7xhdebv1t0.fsf@ruckus.brouhaha.com> <87vf2rpc0i.fsf@wilson.rwth-aachen.de> <7xy87nw75w.fsf@ruckus.brouhaha.com> <87r7dfp58w.fsf@wilson.rwth-aachen.de> Message-ID: Hello! On Sun, 31 Jul 2005 13:46:55 +0200 Torsten Bronger wrote: > Be that as it may, some Google postings suggest that it works at > least with wxPython. Yes, it does. I hadn't done this a long time, but it is possible. In fact, afaik there are less problems with py2exe and wxPython than with PyGTK (writing the setup.py was easier). greets, Marek From xzhvasqt at vxhuarpr.com Thu Aug 25 18:07:56 2005 From: xzhvasqt at vxhuarpr.com (Jeff Hanson) Date: Thu, 25 Aug 2005 15:07:56 -0700 Subject: Ud_lG play for free Ud_lG Message-ID: <1TbPe.10680$A1.7571@news.uswest.net> Dear Casino Player, YOU HAVE BEEN PREAPPROVED. Receive $100 FREE at the Online Casino Of The Year 2002 when you open a new account. DOWNLOAD AWARD WINNING CASINO GAMES or VISIT THEIR WEBSITE FOR MORE INFORMATION. http://webmaster.windowscasino.com/SmartDownload.asp?affid=14409 WINDOWS CASINO FEATURES OVER * 127 GAMES * PROMPT PAYOUTS * GENEROUS COMPS * FREE CHIPS Experience the diference in online gaming today! js&cTKXW\K=UYClNCu9rkG8LY)gB?# From timothy at open-networks.net Tue Aug 2 03:35:27 2005 From: timothy at open-networks.net (Timothy Smith) Date: Tue, 02 Aug 2005 17:35:27 +1000 Subject: startfile problems In-Reply-To: References: Message-ID: <42EF223F.9000108@open-networks.net> Dennis Lee Bieber wrote: >On Tue, 02 Aug 2005 15:10:23 +1000, Timothy Smith > declaimed the following in comp.lang.python: > > > >>i'm very curious as to what everyone thinks >> >> > > I suspect most of us think: Where's the code? > followed by: Where's the traceback? > > As for your statement of verifying the path and filename... We >haven't seen it so can't guess... (part of the "where's the code") > > Does the path contain \n, \t, \r, \f, etc. If it does, and you >are not using a raw string, you are looking for a file with newline, >tab, carriage return, formfeed, etc. respectively in the name. > > >fid = "c:\temp\something.pdf" #bad, this is ># c:emp\something.pdf ># assuming \s isn't some special character > >fid = r"c:\temp\something.pdf" #good >fid = "c:\\temp\\something.pds" #okay > > > it's iterally just PDFname = 'tmp.pdf' os.startfile(PDFname) thats the code. so obviously it contains no errnous characters. see my update btw. it actually DOES open the report, but throws up the exception as well. From nospam at nospam.com Mon Aug 22 05:04:21 2005 From: nospam at nospam.com (42) Date: Mon, 22 Aug 2005 09:04:21 GMT Subject: Sandboxes References: Message-ID: In article , nospam at nospam.nospam says... > Clearly, Pyton does not directly offer any kind of useful security sandbox > capability, but since Java does, I suppose JPython is an option. I know there > are a lot of downsides to JPython, but it should be a genuine solution to the > sandbox problem. Except that linking from the .net framework to jpython doesn't seem to be as transparent. :/ -dave From jepler at unpythonic.net Thu Aug 4 10:51:16 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 4 Aug 2005 09:51:16 -0500 Subject: Fail codecs.lookup() on 'mbcs' and 'tactis' In-Reply-To: <3lelp7F12526dU1@individual.net> References: <3lelp7F12526dU1@individual.net> Message-ID: <20050804145112.GA19009@unpythonic.net> I don't know what 'tactis' is, but 'mbcs' is not a portable character set name. It's a special character set name on win32, which refers to some system-specific multibyte character set. I don't think these "failures" are a Python bug. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From jsacksteder at gmail.com Wed Aug 10 22:49:51 2005 From: jsacksteder at gmail.com (jeff sacksteder) Date: Wed, 10 Aug 2005 22:49:51 -0400 Subject: regex help Message-ID: <51c8a7be050810194943f0469f@mail.gmail.com> Regex questions seem to be rather resistant to googling. My regex currently looks like - 'FOO:.*\n\n' The chunk of text I am attempting to locate is a line beginning with "FOO:", followed by an unknown number of lines, terminating with a blank line. Clearly the ".*" phrase does not match the single newlines occuring inside the block. Suggestions are warmly welcomed. From paschott at no.yahoo.spamm.com Fri Aug 12 12:15:40 2005 From: paschott at no.yahoo.spamm.com (Peter A. Schott) Date: Fri, 12 Aug 2005 16:15:40 GMT Subject: Help sorting a list by file extension References: Message-ID: OK - I actually got something working last night with a list that is then converted into a dictionary (dealing with small sets of data - < 200 files per run). However, I like the sorted list option - I didn't realize that was even an option within the definition and wasn't quite sure how to get there. I realized I could use os.path.splitext and cast that to an int, but was having trouble with the sort. My files only have a single "." in them so this will work well for me. (from Tom's code) [name for dec,name in sorted((int(os.path.splitext(nm)[1][1:]),nm) for nm in namelist)] I'll give that a try - it would eliminate the dictionary part of my code and be a little more efficient. Thanks to all for the quick responses. -Pete Peter A. Schott wrote: > Trying to operate on a list of files similar to this: > > test.1 > test.2 > test.3 > test.4 > test.10 > test.15 > test.20 > > etc. > > I want to sort them in numeric order instead of string order. I'm starting with > this code: > > import os > > for filename in [filename for filename in os.listdir(os.getcwd())]: > print filename > #Write to file, but with filenames sorted by extension > > > Desired result is a file containing something like: > C:\MyFolder\test.1,test.001 > C:\MyFolder\test.2,test.002 > C:\MyFolder\test.3,test.003 > C:\MyFolder\test.4,test.004 > C:\MyFolder\test.10,test.010 > C:\MyFolder\test.15,test.015 > C:\MyFolder\test.20,test.020 > > I need to order by that extension for the file output. > > I know I've got to be missing something pretty simple, but am not sure what. > Does anyone have any ideas on what I'm missing? > > Thanks. > > -Pete Schott From usenet at isbd.co.uk Fri Aug 26 04:47:29 2005 From: usenet at isbd.co.uk (usenet at isbd.co.uk) Date: 26 Aug 2005 08:47:29 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> Message-ID: <3n8391F6ogbU1@individual.net> In comp.lang.perl.misc Ulrich Hobelmann wrote: > usenet at isbd.co.uk wrote: > > In comp.lang.perl.misc John Bokma wrote: > >>> the argument that usenet should never change seems a little > >>> heavy-handed and anachronistic. > >> No, simple since there *are* alternatives: web based message boards. Those > >> alternatives *do* support HTML formatting (often the subset mentioned > > > > ... and generally these "web based message boards" (i.e. forums I > > assume you mean) have none of the useful tools that Usenet offers and > > are much, much slower. > > That is because NNTP and its applications didn't evolve to feed the > glitzy need lots of users have. > I don't think they have "glitzy need", they are just fed glitzy (but slow) forums as the way to get support etc. If they were told about the alternatives as well and told how to use them then I thiink those alternatives would be used. "NNTP and its applications" have evolved to provide a set of much more sophisticated means of accessing and giving information than any forum I've ever seen. > Sadly web forums (esp. the ugly, sloooow PHPBB, and the unspeakable > Google groups) are increasingly replacing usenet, but there are > exceptions (DragonflyBSD). > One good solution is a furum which is also accessible by NNTP. > On the information side (in contrast to the discussion side) RSS is > replacing Usenet, with some obvious disadvantages: go on vacation, > return after a week, and -- yahoo! -- all your RSS feeds only turn of > the, say, most recent 30 articles, while your newsgroups all show > everything you missed. > Same applies to most newsfeeds, depending on retention. If you want to look a long way back in a thread, use Google Groups. -- Chris Green From nmichaud at jhu.edu Thu Aug 18 12:09:46 2005 From: nmichaud at jhu.edu (nmichaud at jhu.edu) Date: Thu, 18 Aug 2005 12:09:46 -0400 (EDT) Subject: Implementing class methods in C Message-ID: I am having a problem implementing some methods of a python class in C. The class is defined in python, but I would like to rewrite some methods in c. Here is an example of what I want to do: file _test.c: #include static PyObject * func2(PyObject *self, PyObject *args) { if (self == NULL) { PyErr_SetString(PyExc_SystemError, "self is NULL"); return NULL; } // Parse arguments if (!PyArg_ParseTuple(args, "")) { return NULL; } Py_INCREF(Py_None); return Py_None; } static PyMethodDef TestMethods[] = { {"func2", func2, METH_VARARGS, "func2."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC init_test(void) { (void) Py_InitModule("_test", TestMethods); } ---------------------------------------------------- test.py: class Test: def func1(self): print "I am in func 1" import _test import new Test.func2 = new.instancemethod(_test.func2, None, Test) del(new) t = Test() t.func2() When I run test.py, I get a SystemError exception (which is what I raise if self is NULL). I think my confusion lies in the use of PyObject* self in the function declaration. Shouldn't this be set to point to the instance of class Test that I am calling it from? Am I misunderstanding the purpose of PyObject* self? Thanks. Naveen --------------------------------------------------------------------- Naveen Michaud-Agrawal Program in Molecular Biophysics Johns Hopkins University (410) 614 4435 From mwm at mired.org Thu Aug 11 21:53:36 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 11 Aug 2005 21:53:36 -0400 Subject: Writing a small battleship game server in Python References: <200508111746.15668.mail@tuxipuxi.org> Message-ID: <86ll377wf3.fsf@bhuda.mired.org> Dan writes: >> The server should accept connections from new players and be able to handle >> multiple games concurrently. > > Multiple threads would be the way to go for a real application. But if > you want to avoid the complexity involved in threading and > synchronization in this exercize, you can avoid threads by using > "select" instead: Select works quite well for real applications, without nearly the headaches that come from using threads. The downside is that you can't do anything that takes long amounts of real time while dealing with the traffic. If you can live with that restriction, select is to be preferred to multiple threads even for "real applications". http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From tiissa at nonfree.fr Tue Aug 16 15:56:03 2005 From: tiissa at nonfree.fr (tiissa) Date: Tue, 16 Aug 2005 21:56:03 +0200 Subject: random seed In-Reply-To: <1124215843.369517.197900@z14g2000cwz.googlegroups.com> References: <1124215843.369517.197900@z14g2000cwz.googlegroups.com> Message-ID: <430244d1$0$14955$626a14ce@news.free.fr> vivek7006 at gmail.com wrote: > By default, randomm module uses the timestamp to generate the seed > value. Is it possible to know what that seed value is? From a (very) quick glance at the doc [1], I'm not sure you can get it. But if you want to reuse it later (for a deterministic behaviour), you can get and set the internal state of the generator (using getstate and setstate). [1] http://docs.python.org/lib/module-random.html From rkern at ucsd.edu Sun Aug 28 00:20:27 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 27 Aug 2005 21:20:27 -0700 Subject: formal math ? In-Reply-To: <1125186266.843702.254220@f14g2000cwb.googlegroups.com> References: <1125186266.843702.254220@f14g2000cwb.googlegroups.com> Message-ID: mehdi.rabah at gmail.com wrote: > Hi, > > I have just discovered python and it seems so easy ans so powerful to > me that it remind me matlab or maple programming language (sorry free > software purists ears). > > So I was wondering if there a sort of formal math library, that can do > a thing like: > > lib.solve("x+1=0") > -> x=-1 There are some old ones laying about in various states of usefulness. Nothing really full-featured, though. http://www.tildesoft.com/Pythonica.html http://cens.ioc.ee/cgi-bin/viewcvs.cgi/python/ginac/ It's easier to integrate with a full-featured CAS than it is to write one yourself. http://home.arcor.de/mulk/projects/mascyma/index.xhtml.en http://library.wolfram.com/infocenter/MathSource/585/ > I have checked numarray and I think it can not do this. No, it cannot. -- 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 john at hazen.net Wed Aug 31 15:51:02 2005 From: john at hazen.net (John Hazen) Date: Wed, 31 Aug 2005 12:51:02 -0700 Subject: Sockets: code works locally but fails over LAN In-Reply-To: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> Message-ID: <20050831195102.GA17862@gate2.hazen.net> * n00m [2005-08-31 05:45]: > import socket, thread > host, port = '192.168.0.3', 1434 > s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s2.connect((host, 1433)) > s1.bind((host, port)) I think the problem is that you're using the same host for both the send and recieve sockets. Wouldn't you want one host to be the localhost, and one to be sql server? If it doesn't work even when only the VBscript is on a different box, are you running an OS with a firewall that you have to disable? -John From http Sat Aug 27 22:20:31 2005 From: http (Paul Rubin) Date: 27 Aug 2005 19:20:31 -0700 Subject: python image thumbnail generator? References: Message-ID: <7x8xymby4w.fsf@ruckus.brouhaha.com> "Chris Dewin" writes: > (1) Can this be done with python? If so, what module do I need to look up? You could do it with PIL, or run jpegtran in an external process. jpegtran may be easier. From spam.csubich+block at block.subich.spam.com Wed Aug 3 11:25:45 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 03 Aug 2005 11:25:45 -0400 Subject: 2-player game, client and server at localhost In-Reply-To: References: Message-ID: Michael Rybak wrote: > As stated above, that's how I'm trying it right now. Still, if doing > it turn-base, I would have to create a new thread every time. > I have some other questions though - please see below. No, you should never need to create a new thread upon receiving input. What you want is inter-thread communication, a synchronous queue. A synchronous queue is a thread-safe queue. You'd push event updates to it from the communication thread, and in the update thread, WHICH IS ALWAYS RUNNING, you'd check the queue each loop to see if there was anything new. > Now, few questions. Do I need to time.sleep(0.xxx) in any of these > while True: loops, not to overwhelm CPU? I can measure the time at > beginning and end of each iteration to make things happen fixed number > of times per second, but should I? And another: do I get it right that > instead of "lock global" you mean: > while global.locked: > time.sleep(0.001) > lock global > And I also wonder how do I make sure that 2 threads don't pass this > "while" loop simultaneously and both try locking global. There is a > probability, not? You have the right idea, that locking's important, but when the grandparent poster said "lock global," he meant "lock global." Locks are low-level primitives in any threading system, they can also be called mutexes. Attempting to acquire a lock returns immediate if the lock can be acquired; if it can't (and it's set to block, which is the default) the thread will wait until it -can- acquire the lock -- the entire thrust of your 'time.sleep' loop, only good. See thread.acquire and threading.Lock for python built-in locks. > In my yesterday experiment, I have a separate thread for each of 2 > clients, and what I do there is: > > def thr_send_status(player_sock): > while 1: > t, sub_addr = player_sock.recvfrom(128) #player ready to accept > player_sock.sendto(encode_status(g.get_status()), sub_addr) > > I'm reading 1 byte from client every time before sending new update to > him. OK, Ok, I know that's not good, ok. Now, I like your idea much > more, where you say we first measure the processing speed of each > client, and send data to every client as often as he can process it: Just how much data are you sending in each second? Testing client speed and managing updates that way is relatively advanced, and I'd argue that it's only necessary when your data has the potential to swamp a network connection. > While thinking about this, I've decided to go the wrong way, and to > wait for confirmation from client before sending next pack. No, you definitely don't need to do this. TCP is a reliable protocol, and so long as the connection stays up your client will receive data in-order with guaranteed arrival. If you were using UDP, then yes you'd need (possibly) to send confirmation, but you'd probably need a more advanced version to handle missing / out-of-order packets. > I'm also almost sure it's wrong to have separate sockets and threads > for each player, you say I should select()/dispatch instead, but I'm > afraid of that some *thing* being wrong with select() for Windows. > Somehow, I'm doing a lot of thins the wrong way :( Just use the Twisted library. It abstracts that away, and not touching sockets is really much nicer. > Before describing another problem I've encountered, I thought I'd > remind you of what my test game is: each player controls it's ball by > moving mouse pointer, towards which his ball starts moving; that's it. What's the nature of your evend update? Do you say "mouse moved N" or "mouse moved to (123,456)?" If it's the latter, then without motion prediction there's no way that either simulation should have the ball overshoot the mouse. Synchronization, however, will still be an issue. From shmem at netspace.net.au Thu Aug 25 04:37:36 2005 From: shmem at netspace.net.au (Shaun) Date: Thu, 25 Aug 2005 18:37:36 +1000 Subject: overload builtin operator Message-ID: Hi, I'm trying to overload the divide operator in python for basic arithmetic. eg. 10/2 ... no classes involved. I am attempting to redefine operator.__div__ as follows: # my divide function def safediv(a,b): return ... # reassign buildin __div__ import operator operator.__div__ = safediv The operator.__dict__ seems to be updated OK but the '/' operator still calls buildin __div__ Does anyone know if this is possible and if I'm going along the correct path with my attempts above? Is it possible to do this using a C extention? Regards, Shaun. From onurb at xiludom.gro Wed Aug 24 05:38:42 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 24 Aug 2005 11:38:42 +0200 Subject: loop in python In-Reply-To: References: <20050823065501.GA24558@mrna.tn.nic.in> <430afc09$0$30445$636a15ce@news.free.fr> Message-ID: <430c4025$0$30687$626a14ce@news.free.fr> Terry Hancock wrote: > On Tuesday 23 August 2005 05:35 am, bruno modulix wrote: > (snip) >> >>If you hope to be taken seriously, please abandon the sms-talk style here. >> > > > I think it's reasonably clear that neither poster hoped "to be taken > seriously". :-D > Err... I guess that "to be taken seriously" (in french: "?tre pris au s?rieux") has some other meaning in english :-/ -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From lycka at carmen.se Fri Aug 12 07:22:18 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 12 Aug 2005 13:22:18 +0200 Subject: len(sys.argv) in (3,4) In-Reply-To: References: Message-ID: Daniel Sch?le wrote: > I just tried the same code at home and it worked fine > it has to do with windows .. some settings or whatever > (python 2.4.1 installed on both) > > maybe someone have experienced the same problem > and had more luck in solving the puzzle First of all: "Windows" is a whole family of OSes, and not all members have any blood relations. The NT family is probably more related to VMS than to MS DOS. Secondly: There is an association mechanism (I don't have access to Windows at work, but you can find it in some Explorer menu) where you define what the OS does when you try to fire off a file with a certain extension. That mechanism defines if and how the OS passes command line arguments. It might we work better if you run "python x.py y z" instead of just "x.py y z". This might give a hint... http://www.robvanderwoude.com/call.html From donn at u.washington.edu Mon Aug 8 17:52:55 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 08 Aug 2005 14:52:55 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <7x8xzcck9d.fsf@ruckus.brouhaha.com> Message-ID: In article <7x8xzcck9d.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: ... > I notice that Haskell strings are character lists, i.e. at least > conceptually, "hello" takes the equivalent of five cons cells. Do > real implementations (i.e. GHC) actually work like that? If so, that's > enough to kill the whole thing right there. Yep. There is a separate packed string type. > > Objective CAML is indeed not a pure functional language. > > Should that bother me? I should say, my interest in Ocaml or Haskell > is not just to try out something new, but also as a step up from both > Python and C/C++ for writing practical code. That is, I'm looking for > something with good abstraction (unlike Java) and type safety (unlike > C/C++), but for the goal of writing high performance code (like > C/C++). I'm even (gasp) thinking of checking out Ada. It's up to you, I'm just saying. Speaking of C++, would you start someone with Python or Java for their first OOPL? Kind of the same idea. Donn Cave, donn at u.washington.edu From john at castleamber.com Wed Aug 31 00:19:33 2005 From: john at castleamber.com (John Bokma) Date: 31 Aug 2005 04:19:33 GMT Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: Mark McIntyre wrote: > On 30 Aug 2005 18:06:48 GMT, in comp.lang.c , John Bokma > wrote: > >>Mark McIntyre wrote: >> >>>Its a complete mystery. Just as is the reason why you are x-posting >>>complete garbage to comp.lang.c... >> >>A similar mystery as in why Mark clueless n00b II McIntyre thinks it's >>a good idea to cross post to all other groups except comp.lang.c? > > I see you felt it appropriate to RE-post this offtopic garbage back > into clc. > > You sir, are a troll, No clueless n00b, you are a troll, or either too stupid to have a Usenet account. > and I'd claim my fiver if I could be arsed. > > Exactly, you and your clueless buddy think you can make smart ass statements. Either add something not brain dead to this thread, or let it go. As I already explained to that other n00b, threads like this *can't* be stopped, moved, controlled or what. The harder you try the longer it takes for it to stop. Either ignore the whole thing, or make a useful contribution which might make setting the FollowUp-To: header work (but don't get angry if it's ignored). Now lets hope that the rest gets the point. Thanks. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From reinhold-birkenfeld-nospam at wolke7.net Tue Aug 30 17:12:35 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Tue, 30 Aug 2005 23:12:35 +0200 Subject: Yielding a chain of values In-Reply-To: <4314bf65.177562962@news.oz.net> References: <4314bf65.177562962@news.oz.net> Message-ID: <3nk0e4F1snjcU2@individual.net> Bengt Richter wrote: > On Tue, 30 Aug 2005 12:18:59 GMT, Michael Hudson wrote: > >>Talin writes: >> >>> I'm finding that a lot of places within my code, I want to return the >>> output of a generator from another generator. Currently the only >>> method I know of to do this is to explicitly loop over the results >>> from the inner generator, and yield each one: >>> >>> for x in inner(): >>> yield x >>> >>> I was wondering if there was a more efficient and concise way to do >>> this. And if there isn't, >> >>Greenlets, perhaps? (for which, see google). >> > Maybe > > yield in inner() > > could be sugar for the above and become something optimized? The problem here is that yield isn't a statement any more. It's now an expression, so it is not easy to find new syntax around it. Reinhold From grante at visi.com Thu Aug 18 12:48:49 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 18 Aug 2005 16:48:49 -0000 Subject: question about binary and serial info References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> Message-ID: <11g9evhkjbanncb@corp.supernews.com> On 2005-08-18, nephish at xit.net wrote: > i got the bitwise part, i just cant seem to convert the > incomming ascii into hex, binary, integer, or decimal. So you've got an ASCII string in one format and you want to convert into an ASCII string in a different format? For example you want to convert the string "FF" into the string "255"? > how do i do this, my serial port bytes just come in all weird > looking ascii characters -- Grant Edwards grante Yow! It's OKAY -- I'm an at INTELLECTUAL, too. visi.com From saint.infidel at gmail.com Fri Aug 26 10:18:14 2005 From: saint.infidel at gmail.com (infidel) Date: 26 Aug 2005 07:18:14 -0700 Subject: a dummy python question In-Reply-To: References: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> <1125006812.641866.125150@g44g2000cwa.googlegroups.com> Message-ID: <1125065894.741165.119990@g14g2000cwa.googlegroups.com> > > If that were so, Pythonistas could never write a recursive function! > > No, presumably at the writing of the edition of _Learning Python_ that > he is reading, Python did not have nested scopes in the language, yet. > One could always write a recursive function provided it was at the > top-level of the module. One could not write a recursive function inside > another function because inside inner(), it could only access two > namespaces, the one local to inner() and the module's namespace, not the > namespace of outer() where inner() is defined. Ah, that makes sense. Thanks for the clarification. From esleben at gmail.com Wed Aug 10 08:35:42 2005 From: esleben at gmail.com (Jan-Ole Esleben) Date: Wed, 10 Aug 2005 14:35:42 +0200 Subject: Why is this? In-Reply-To: References: Message-ID: <3756d97505081005351c66ff08@mail.gmail.com> For the sake of completeness (I didn't copy this message to the list): > I have a problem with initialization. > >>> a, b = [[]]*2 > >>> a.append(1) > >>> b > [1] > > Why is this? Why does not this behave like the below: You create a single list (inside your brachets) and duplicate a reference to it. a and b are two references to the same list; this is just a problem for mutable objects, but I think it's safe to say that it bites everyone at some point. > >>> [[], []] == [[]]*2 > True Obviously, this is not a test for referential identity. Hope this helps to clear the matter up! Ole 2005/8/10, Jiri Barton : > Yes, now it is clear! > > As always, I should have RTFM, the operator* is not just a syntactic sugar > and thus does not make copies. You know, my actual scenario was with four > variables at the time: > > a, b, c, d = [], [], [], [] > > so I was even more tempted to use the previous and wrong approach:-) > > Thank you for your explanation. No more errors in my code from now on (oh > well,...) > > jbar > -- > http://mail.python.org/mailman/listinfo/python-list > From lycka at carmen.se Fri Aug 12 05:40:15 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 12 Aug 2005 11:40:15 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com><42F9BC7D.1050300@le.ac.uk> <42FB55BC.70608@sweetapp.com> Message-ID: Terry Reedy wrote: > However, everything is an instance of a class or type. Except whitespace, comments, operators and statements! (Did I miss anything?) You can obviously argue whether a "variable" (or name if you like) is an object, or just refers to an object, but then we're getting philosophical I guess. C.f. http://www.comviz.com.ulaval.ca/module1/Images/MagrittePipe.jpg or http://www.fredosaurus.com/notes-cpp/arrayptr/60song.html From rkern at ucsd.edu Sun Aug 7 14:46:27 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 11:46:27 -0700 Subject: SWIG again In-Reply-To: <20050807183241.26544.qmail@web51503.mail.yahoo.com> References: <20050807183241.26544.qmail@web51503.mail.yahoo.com> Message-ID: Jerry He wrote: > > Can you tell me how to completely remove that > >>module? >> >>For cygwin, it should be in whatever corresponds to >>/usr/lib/python2.4/site-packages . >> >>-- >>Robert Kern >>rkern at ucsd.edu >> > > Hi, > Do you mean to say that all I have to do is delete > "example.py" and the "build" folder? > > (note: I didn't do "python setup install", I did > "python setup build", so all I have is the above two > things in the sourcefile folder. ) Yes, although since you didn't actually install it, it's not going to adversely affect anything except taking up a miniscule bit of your diskspace. -- 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 http Mon Aug 8 18:01:24 2005 From: http (Paul Rubin) Date: 08 Aug 2005 15:01:24 -0700 Subject: python for microcontrollers References: <42f7c8d4$1@news.orcon.net.nz> Message-ID: <7xd5oof5qj.fsf@ruckus.brouhaha.com> Evil Bastard writes: > Yes, this approach sucks. But can anyone offer any suggestions which > suck less? I don't think you want to do this. Runtime type tags and the overhead of checking them on every operation will kill you all by themselves. Processors like that haven't been used much as Lisp targets either, for the same reasons. Pick a different language. From eric.nieuwland at xs4all.nl Sat Aug 13 05:03:16 2005 From: eric.nieuwland at xs4all.nl (Eric Nieuwland) Date: Sat, 13 Aug 2005 11:03:16 +0200 Subject: Python Wireless Extension Module (pyiw) In-Reply-To: <1123794171.4559.15.camel@localhost.localdomain> References: <1123794171.4559.15.camel@localhost.localdomain> Message-ID: <0ff08ab1822dcdc11fb08a6e51795767@xs4all.nl> Jeremy Moles wrote: > I am mostly done with writing an extension module in C that wraps (and > makes easier) interfacing with libiw (the library that powers iwconfig, > iwlist, and friends on Linux). We're using this internally for a tool > to > manage wireless connectivity. This is a million times better than > hundreds of invocations of the iw* suite of tools. :) > > Would anyone else find something like this useful? I know a few distros > maintain their own suite of config tools, but I don't think there is > yet > an actual binding for python. > > Anyway, I am just curious... we plan on using it, at any rate. It's > already made the code easier to read, faster, and more reliable. > > # example usage --------------------------------- > > wlan = pyiw.WirelessInfo("wlan0") > > nets = wlan.Scan() > > for net in nets: > print net.signal_quality > > wlan.essid > wlan.key > wlan.protocol > > wlan.essid = "LV-426" > > wlan.Reconfigure() So cool! YES, I'd like to have that. Preferably as source code since I have quite a number of different Un*xes. --eric From jgrahn-nntq at algonet.se Thu Aug 4 05:00:56 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 4 Aug 2005 09:00:56 GMT Subject: Emacs skeletons References: Message-ID: On Tue, 26 Jul 2005 22:08:25 +0200, Caleb Hattingh wrote: >> Since you are on this topic, do you (or anyone else) have any type of >> "code-completion" mode for python in emacs? >> >> Thanks >> -george > > For what its worth, Vim has a generic type of "code-completion" that uses > the file being edited to check for completion options within a word. It's > not true completion (using valid completions for class hierarchies, a la > Delphi/VB), but I get a lot of mileage out of it with my python coding. > > I fully expect Emacs has something similar, though I can't tell you how (I > hardly know emacs at all). It's dabbrev-expand, bound to C-TAB by default. I wouldn't dream of typing any kind of text (source code or otherwise) into an editor without this feature. It saves a lot of time, typos and wrist pain. So, it's not surprising that both vim and emacs has it. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From nomail at nomail.com Thu Aug 25 21:50:54 2005 From: nomail at nomail.com (Nx) Date: Fri, 26 Aug 2005 09:50:54 +0800 Subject: variable hell In-Reply-To: References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> Message-ID: Thanks for all the responses and animated discussion, which is still the best way to learn something new. Most of the time it is not that you want to do something in a certain way , it rather is one cannot think of a better , faster more efficient way . Nx From daiwei at gmail.com Fri Aug 26 19:57:18 2005 From: daiwei at gmail.com (daiwei at gmail.com) Date: 26 Aug 2005 16:57:18 -0700 Subject: MySQLdb install Message-ID: <1125100638.767395.151940@g47g2000cwa.googlegroups.com> Hi, I installed the MySQLdb on my BSD, but when I import it I got following errors. Any idea how to fix it? import MySQLdb Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py", line 27, in ? import _mysql ImportError: /usr/local/lib/liblthread.so.2: Undefined symbol "_sched_yield" Thanks, Wei, From agentriot at gmail.com Mon Aug 22 03:36:19 2005 From: agentriot at gmail.com (Ricardo Sanchez) Date: 22 Aug 2005 00:36:19 -0700 Subject: Uploading images to imageshack.us with Python In-Reply-To: <1124688349.177133.170420@o13g2000cwo.googlegroups.com> References: <1124688164.318336.55370@z14g2000cwz.googlegroups.com> <1124688349.177133.170420@o13g2000cwo.googlegroups.com> Message-ID: <1124696179.042921.71300@g47g2000cwa.googlegroups.com> Ok, I solved it with the unvaluable help of a nice guy in the #python channel. It is a studid as it gets, replaced files = [('fileupload', 'b.jpg', open('b.jpg').read())] by files = [('fileupload', 'b.jpg', open('b.jpg', 'rb').read())] because binary files are not opened correctly in Windows XP unless you specify that they are so. From sigzero at gmail.com Sat Aug 13 16:18:21 2005 From: sigzero at gmail.com (sigzero at gmail.com) Date: 13 Aug 2005 13:18:21 -0700 Subject: Spaces and tabs again In-Reply-To: References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> Message-ID: <1123964301.854778.172680@g49g2000cwa.googlegroups.com> Aahz wrote: > Python 3.0 will prohibit tabs. > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > The way to build large Python applications is to componentize and > loosely-couple the hell out of everything. Are you kidding? You are going to MANDATE spaces? Robert From zen19725 at zen.co.uk Tue Aug 2 03:37:05 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Tue, 2 Aug 2005 08:37:05 +0100 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> <861x5deype.fsf@bhuda.mired.org> Message-ID: On Tue, 02 Aug 2005 00:42:53 -0400, Mike Meyer wrote: >zen19725 at zen.co.uk (phil hunt) writes: >> In practise any Python GUI is going to contain code from otyher >> languages since if it was coded all the way down in python it would >> be too slow. > >Not necessarily. My window manger is Python all the way down Your X server is written in Python? :-) > - it uses >the Python Xlib implementation - and is plenty fast. > >Of course, it doesn't do a lot of graphics work, even for a window >manager. That's what I mean: painting the individual pixels on the screen. -- Email: zen19725 at zen dot co dot uk From mwm at mired.org Tue Aug 2 01:42:36 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 01:42:36 -0400 Subject: Standards not standard References: Message-ID: <86vf2oevxv.fsf@bhuda.mired.org> Dark Cowherd writes: > Being able to write a usable GUI is key task for all programmers today No, it isn't. I'm a programmer. I never get paid to write usable GUIs. Most of my programs don't have a GUI at all. For those that do, I get paid to write a functional GUI. Clients that want a usable GUI are told up front they'll have to pay someone else - who may not be a programmer - to provide that. If you said "most" - well, I still don't think I'd agree with you, but at I wouldn't have so directly disagreed. The team I'm currently working on has about a half dozen programmers, only one of whom needs to be able to write a usable GUI. Now, when it comes to writing tools for me, I've written some things that have what I consider to be *very* usable GUIs - much more usable than anything I've ever seen on a Mac or Windows box. But gods forbid end users should ever have to deal with them. > You can for example tie a dataset with a chart and grid on the same > screen. Type in the grid and see the chart change. All this with zero > code. Made my eyes bug out the first time I saw this. PyQt has this kind of functionality. I first saw it in boopsie, back in the late 80s. It is pretty cool. > I really think that the community needs a lot more of STANDARDS not > a STANDARD GUI Standards happen in one of two ways. Either an 800-lb gorrilla establishes them by fiat, or a group of people interested in having their code play well together hashes out something after they've all taken a crack at implementing it. The latter is slowly happening in the Python community. But it's a slow process. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From eurleif at ecritters.biz Mon Aug 22 22:55:40 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Tue, 23 Aug 2005 02:55:40 GMT Subject: Sandboxes In-Reply-To: References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: 42 wrote: > FWIW I've already given up on making python secure. I agree that odds > are extremely high that I've missed something. I'm just curious to see > what one of the holes I left is, preferably without wading through > hundreds of pages :) f = [x for x in [].__class__.__bases__[0].__subclasses__() if x.__name__=='file'][0] f('/path/to/important/file', 'w').close() From spammers-go-here at spam.invalid Wed Aug 31 10:05:06 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 31 Aug 2005 10:05:06 -0400 Subject: Problem with string -> int conversion ? References: <4314dbd0$0$18648$14726298@news.sunsite.dk> Message-ID: <4315b8cc$0$18647$14726298@news.sunsite.dk> Fredrik Lundh wrote: >> The code is : >> >> void Form3::getNPrange() >> { > > what language is this? Its python embedded in the designer workflow. pyuic extracts stuff from it, and generates a python script from the ui.h file. > > if the callback code is Python, you should be able to add a print > statement to the line just before the failing "int" call: > > print repr(signalrangestr), type(signalrangestr) > signalrange = int(signalrangestr) > > that print statement should be all you need to figure out what > signalrangestr really is. Thanks for the hint. I get : <__main__.qt.QString object at 0xb7c1a3ec> The question is : How do I convert a QString to a plain string ? From googlenews at tooper.org Wed Aug 31 10:34:42 2005 From: googlenews at tooper.org (tooper) Date: 31 Aug 2005 07:34:42 -0700 Subject: using python_ldap for authentication Message-ID: <1125498882.711348.216060@g47g2000cwa.googlegroups.com> Hello all, I'd like to use an ldap server just for authentication, but I'm a complete beginner with all the ldap stuff... I've tried this from the python_ldap Demo examples : ---------- import ldap, getpass ldap_url="... validation ldap server URL & port ..." l = ldap.initialize(ldap_url) login_dn = "cn=thierry" login_pw = getpass.getpass("Password for %s: " % login_dn) l.simple_bind(login_dn, login_pw) ---------- but it seems to succeed whatever the password I'm providing :-( How to simply assess the binding really occured ? Do I need to start doing stuff with the "l" object to catch an error and realize I'm not in fact connected : that's my current workaround but I'm not very proud of it... Thanks in advance ! From hongyuan1306 at gmail.com Sat Aug 13 11:07:11 2005 From: hongyuan1306 at gmail.com (Yuan HOng) Date: Sat, 13 Aug 2005 23:07:11 +0800 Subject: Archetype Permission Errors with CMFBoard 2.2 In-Reply-To: <91320d220508130801126f7@mail.gmail.com> References: <91320d220508130801126f7@mail.gmail.com> Message-ID: <91320d22050813080716ca3177@mail.gmail.com> Ops. Sorry for posting the wrong list. On 8/13/05, Yuan HOng wrote: > Hi, > > I am trying to integrate the latest CMFBoard 2.2 with my Plone site > (2.0.5 with Archetypes 1.3.3-final). I'd like to have my users to post > anonymously with CMFBoard, so I added a forumNB of type 'open'. > > However, when an anonymous user tries to added a new Topic to the > board, a bunch of error messages were seen in the event.log as shown > below. > > As a result, I find the topic of a new forum topic can not be > displayed in several locations. > > Can someone explain what the various errors mean and how shall I set > up my permission so CMFBoard will work correctly for anonymous users? > > By the way, is CMFBoard 2.2 known to work stably with Archetype 1.3.3? > So many warning/errors for just adding a simple topic make me really > worry. > > Below is the event.log transcript: > -- Hong Yuan ????????? ??????????? http://www.homemaster.cn From john at castleamber.com Thu Aug 25 13:37:41 2005 From: john at castleamber.com (John Bokma) Date: 25 Aug 2005 17:37:41 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: Rich Teer wrote: > On Thu, 25 Aug 2005, Mike Schilling wrote: > >> Another advantage is that evewry internet-enabled computer today >> already comes with an HTML renderer (AKA browser), so that a message >> saved to a file can be read very easily. > > I think you're missing the point: email and Usenet are, historically > have been, and should always be, plain text mediums. If I wanted to > look at prettily formatted HTML, I'd use a web browser to look at the > web. Just have a look at some web based message boards, and you might see why it would be another disaster on Usenet. Moreoever, why keep people insisting on making Usenet "better"? If you want HTML and fancy mark up, start a message board. You probably can get even more people. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From steve at myplace.com Thu Aug 11 20:09:05 2005 From: steve at myplace.com (Steve M) Date: Thu, 11 Aug 2005 19:09:05 -0500 Subject: Printing to printer Message-ID: Hello, I'm having problems sending information from a python script to a printer. I was wondering if someone might send me in the right direction. I wasn't able to find much by Google TIA Steve From neuruss at gmail.com Sat Aug 6 13:07:24 2005 From: neuruss at gmail.com (neuruss neuruss) Date: 6 Aug 2005 10:07:24 -0700 Subject: Point and click GUI builder for Python In-Reply-To: <42f430ea$0$18643$14726298@news.sunsite.dk> References: <42f430ea$0$18643$14726298@news.sunsite.dk> Message-ID: <1123348044.677983.211380@g47g2000cwa.googlegroups.com> Madhusudan Singh wrote: > Is there such a thing for python ? Like Qt Designer for instance ? The easiest way to create Python GUI apps: PythonCard. It is based on wxPython by it has a higher level of abstraction. You just drag and drop widgets on a form and code the events like you woud in Visual Basic or Delphi. IMHO, it's easier, simpler, more intuitive and stable than Boa Constructor. From pink at odahoda.de Tue Aug 2 16:14:13 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Tue, 02 Aug 2005 22:14:13 +0200 Subject: trying to parse non valid html documents with HTMLParser References: <42efc9ae$0$12924$636a15ce@news.free.fr> Message-ID: florent wrote: > I'm trying to parse html documents from the web, using the HTMLParser > class of the HTMLParser module (python 2.3), but some web documents are > not fully valids. Some?? Most of them :( > When the parser finds an invalid tag, he raises an > exception. Then it seems impossible to resume the parsing just after > where the exception was raised. I'd like to continue parsing an html > document even if an invalid tag was found. Is it possible to do this ? AFAIK not with HTMLParser or htmllib. You might try (if you haven't done yet) htmllib and see, which parser is more forgiving. You might pipe the document through an external tool like HTML Tidy before you feed it into HTMLParser. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From tjreedy at udel.edu Tue Aug 23 18:07:30 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2005 18:07:30 -0400 Subject: how to deal with space between numbers References: <430B5ACF.6070509@aims.ac.za> Message-ID: Your input data file must be formatted in such a way that the program, knowing the format, can separate one number from another. There are two basic ways to do this. 1. Separate the numbers with non-digit characters, such as spaces. (Other characters such as commas are also used, but are more trouble when your data is just numbers.) 2. Put each number in a particular set of columns. The columns make a *field*. If the numbers in a field will be greater than 9, then your field needs more than one column. For input to Python, numbers that do not require all the columns in the field should be padded with leading spaces rather than leading zeros. Example with 3 fields, with the second needing 2 columns. xyyz 1102 # 1 10 2 4 53 # 4 5 3 etc This usually requires an editor with fixed-pitch fonts. And you have to tell the program the position of each field. Unless you have enough fields or enough lines that you actually need to save display or disk space, I would stick with the first option. Terry J. Reedy From yoav_artzi at il.vio.com Mon Aug 29 04:22:52 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Mon, 29 Aug 2005 11:22:52 +0300 Subject: close failed: [Errno 0] No error goes to stdout In-Reply-To: References: <4311b9bf@news.bezeqint.net> Message-ID: <4312c4bc$1@news.bezeqint.net> I run a Java command line program. The point is, that it's not the program that output this error message for sure. And I don't expect popen3() to catch and report errors. I just want to keep my screen output clean, and I expect popen3() to run the program and not let anything slip to the screen, after all as I understood it is supposed to capture STDERR and STDOUT, but maybe I didn' t understand it right (it's quite probable). Anyway anyway I can do such a thing? Thanks. Peter Hansen wrote: > Yoav wrote: > >> I use the following code to the console output: >> >> def get_console(cmd): >> try: >> p_in, p_out, p_err = os.popen3(cmd) >> except: >> pass >> out_str = '' >> for obj in p_out: >> out_str = out_str + obj >> for obj in p_err: >> out_str = out_str + obj >> return out_str >> >> >> for some reason some exceptions (stderr outputs) are not captured by >> the try method, and slip to the screen. Any one has any idea on how >> can prevent from any output that I don't want to? >> The output I get on these exceptions is: >> close failed: [Errno 0] No error > > > What makes you think the errors are getting past the try/except? Could > they be printed by the program you are invoking with popen3() instead? > What does "cmd" equal when you get this failure? > > Maybe you are expecting that popen3() will somehow raise exceptions when > the called program fails, exceptions which the except statement would > catch. That's not the case. > > -Peter From martin at v.loewis.de Mon Aug 22 03:18:49 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 22 Aug 2005 09:18:49 +0200 Subject: pythonXX.dll size: please split CJK codecs out In-Reply-To: <64tybhr2.fsf@python.net> References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <4308e632$0$31533$9b622d9e@news.freenet.de> <64tybhr2.fsf@python.net> Message-ID: <43097c59$0$4862$9b622d9e@news.freenet.de> Thomas Heller wrote: > That seems to be true. But it will need zlib.pyd as soon if you try to > import from compressed zips. So, zlib can be thought as part of the > modules required for bootstrap. Right. OTOH, linking zlib to pythonXY means that you cannot build Python at all anymore unless you also have zlib available. Regards, Martin From sybrenUSE at YOURthirdtower.com.imagination Sun Aug 28 18:54:28 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 29 Aug 2005 00:54:28 +0200 Subject: NooB Question References: Message-ID: APCass enlightened us with: > How do you execute a .py in Linux with KDE? If I double click on my > program it opens Kwrite, for editing. Make it executable (properties, permissions, executable). Make sure it has #!/usr/bin/python as the first line. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From fredrik at pythonware.com Tue Aug 23 10:56:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 16:56:05 +0200 Subject: Convert float to string ... References: Message-ID: Konrad M?hler wrote: > a simple question but i found no solution: > > How can i convert a float value into a string value? > > > string_value1 = string(float_value) + ' abc' str(float_value) + 'abc' repr(float_value) + "abc" '%fabc' % float_value '%gabc' % float_value (etc) the tutorial has more information: http://docs.python.org/tut/node9.html From stuart at stuartbishop.net Sun Aug 14 02:01:05 2005 From: stuart at stuartbishop.net (Stuart Bishop) Date: Sun, 14 Aug 2005 16:01:05 +1000 Subject: how to write thread-safe module ? and pytz In-Reply-To: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> References: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> Message-ID: <42FEDE21.7020802@stuartbishop.net> nicolas_riesch wrote: > Does someone know if the module pytz > (http://sourceforge.net/projects/pytz/) is thread-safe ? > I have not seen it explicitely stated, and just wanted to be sure, as I > want to use it. pytz is thread safe. > That's because in the file pytz/tzinfo.py, I see global variables > _timedelta_cache, _datetime_cache, _ttinfo_cache, which are > dictionnaries and are used as cache. > I always thought that you must protect shared data with locks when > multithreading, but I don't see any lock anywhere in pytz. > However, pytz seems to work well with multiple threads creating various > timezone objects at the same time. > I don't understand where the trick is, that allows multiple threads to > access this module without any locking and that all this seems to work > without any problem... Thanks to the global interpreter lock, with the Python builtin types you only need to maintain a lock if there is a race condition, or if you care about the race condition. For example, the following is thread safe code: >>> from threading import Thread >>> import time >>> stack = [] >>> stack2 = [] >>> def doit(i): ... stack.append(i) ... time.sleep(0.1) ... stack2.append(stack.pop()) ... >>> threads = [Thread(target=doit, args=(i,)) for i in range(0,100)] >>> for t in threads: t.start() ... >>> for t in threads: t.join() ... >>> len(stack2) 100 >>> stack2 [99, 95, 98, 94, 93, 97, 92, 91, 96, 88, 87, 86, 85, 84, 83, 90, 79, 78, 77, 76, 74, 73, 72, 71, 70, 75, 82, 81, 80, 89, 69, 67, 66, 65, 64, 68, 60, 59, 58, 57, 56, 55, 63, 62, 61, 49, 54, 53, 52, 51, 46, 45, 44, 50, 48, 47, 29, 28, 35, 34, 33, 43, 42, 41, 40, 39, 38, 32, 37, 31, 30, 36, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 12, 16, 15, 14, 13, 11, 10, 9, 8, 7, 6, 4, 3, 2, 1, 0, 5] Note that the value being appended to 'stack2' might not be the value that was appended to 'stack' in any particular thread - in this case, we don't care (but is the sort of thing you might need to watch out for). In the code you mention in pytz, there *is* a race condition. However, if this condition occurs the side effects are so trivial as to not worry about locking. ie. if a number of threads call memorized_timedelta(seconds=60) simultaneously, there is a slight chance that each thread will get a different timedelta instance. This is extremely unlikely, and the rest of the code doesn't care at all. If pytz compared the timedeltas using 'is' instead of '==' at any point, it would be a bug (but it doesn't, so it isn't). So you can write thread safe Python code without locks provided you are using the builtin types, and keep a close eye out for race conditions. This might sound error prone, but it is quite doable provided the critical areas that are accessing shared objects are kept isolated, short and simple. Here is an thread unsafe example. Here the mistake is made that the length of stack will not change after checking it. Also because we don't use the atomic stack.pop(), two threads might add the same value to stack2: >>> from threading import Thread >>> import time >>> stack = range(0, 50) >>> stack2 = [] >>> def doit(): ... if len(stack) > 0: ... stack2.append(stack[-1]) ... time.sleep(0.1) ... del stack[-1] ... >>> threads = [Thread(target=doit) for i in range(0, 100)] >>> for t in threads: t.start() ... Exception in thread Thread-249: Traceback (most recent call last): File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap self.run() File "/usr/lib/python2.4/threading.py", line 422, in run self.__target(*self.__args, **self.__kwargs) File "", line 5, in doit IndexError: list assignment index out of range -- Stuart Bishop http://www.stuartbishop.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: OpenPGP digital signature URL: From velocity.travlr at gmail.com Fri Aug 26 02:20:03 2005 From: velocity.travlr at gmail.com (travlr) Date: 25 Aug 2005 23:20:03 -0700 Subject: loop in python In-Reply-To: References: <20050823065501.GA24558@mrna.tn.nic.in> <430afc09$0$30445$636a15ce@news.free.fr> Message-ID: <1125037203.235456.281300@g43g2000cwa.googlegroups.com> I gotta say that as number cruncher, iteration in python is my biggest nightmare. I do what is possible with numpy, but element by element processing is a hassle. My programming experience is still pretty fresh at a year, so "exotics" as such are not in play yet. I also wish python looping/iterative features could be improved as best possible (what ever extent that may be). Generators are a friend, but not as performance friendly as when I am able to do all the needed work in numpy. I dunno I guess I got spoiled :) From groups at matthammond.org Thu Aug 4 05:15:51 2005 From: groups at matthammond.org (Matt Hammond) Date: 4 Aug 2005 02:15:51 -0700 Subject: Advanced concurrancy References: <42ea98a2$0$1185$ed2619ec@ptn-nntp-reader01.plus.net> <42f154fd$0$14656$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1123146951.295678.82770@g14g2000cwa.googlegroups.com> Hi Stefan, > It seems as though all components basically have to do busy waiting now. You are right - components are, for the most part, busy-waiting. Which is not a good thing! > So do you plan on including a kind of scheduler-aware blocking > communication (like the `channels` of the `tasklets` in stackless)? > > (as you have a postman already - not a bad idea i think if you compare > with multi-agent-systems theory (see jade) - it could be responsible for > alerting the scheduler of box.has_data) There is basic support for components to block, by calling the self.pause() method. From the next yield, this blocks further execution until data arrives on any inbox. The un-pausing action is actually performed by code within the component itself, though this is in effect, as you suggested it might be, instigated by the postman microprocess. A simple example would be an improved 'consoleEcho' component: class consoleEchoer(Axon.Component.component): .... def main(self): while 1: yield 1 while self.dataReady("inbox"): print self.recv("inbox") self.pause() That said, if you look at the code, you'll see that probably the majority of components do not make good use of this yet! There are quite probably better mechanisms around - hence the distinction, in the code, between microprocesses and components. We'd be very interested if yourself or other people want to play with alternative communication & blocking mechanisms. I'd hope that even if the components and postboxes model doesn't work out in the long run, the underlying generator based microprocesses code could still be of some value to others! regards Matt From jwkenne at attglobal.net Fri Aug 26 12:25:50 2005 From: jwkenne at attglobal.net (John W. Kennedy) Date: Fri, 26 Aug 2005 12:25:50 -0400 Subject: Jargons of Info Tech industry In-Reply-To: <430E8E1E.92071F5A@yahoo.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <430E8E1E.92071F5A@yahoo.com> Message-ID: CBFalconer wrote: > Chris Head wrote: > > .... snip ... > >>Why can't we use the Web for what it was meant for: viewing >>hypertext pages? Why must we turn it into a wrapper around every >>application imaginable? > > > Because the Lord High PoohBah (Bill) has so decreed. He has > replaced General bullMoose. Not particularly his doing. SGI was using a Netscape plugin to distribute and install operating-system patches when Billionaire "Intelligent Design" Billy was still denying that TCP/IP had a future. And there are places for web forums: public feedback pages, for example. (Add RSS and/or e-mail and/or NNTP feeds for more advanced users.) -- John W. Kennedy "The grand art mastered the thudding hammer of Thor And the heart of our lord Taliessin determined the war." -- Charles Williams. "Mount Badon" From fakeaddress at nowhere.org Sun Aug 28 16:34:07 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sun, 28 Aug 2005 20:34:07 GMT Subject: global interpreter lock In-Reply-To: References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> Message-ID: <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> phil hunt wrote: > It's not the number of paths that's important. Absolutely right. Non-trivial software always has too many paths to consider them individually, so we have to reason generally. > What's important is *predictability*, e.g. which instruction will > the computer execute next? > > If you only have one thread, you can tell by looking at the code > what gets executed next. It's very simple. Not really. Trivially, an 'if' statement that depends upon input data is statically predictable. Use of async I/O means makes the programs execution dependent upon external timing. > If you have 2 threads you can easily have a timing-based situation > that occurs rarely but which causes your program to behave wierdly. > This sort of bug is very hard to reproduce and therefore to fix. So we need to learn to avoid it. [...] > Yes, find solutions. Don't find dangerous dead-ends that look like > solutions but which will give you lots of trouble. If concurrency is a dead end, why do the programs that provide the most sophisticated services of any in the world rely on it so heavily? -- --Bryan From __peter__ at web.de Wed Aug 17 02:39:51 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Aug 2005 08:39:51 +0200 Subject: Making programs work together. References: <1124256651.450266.90580@g47g2000cwa.googlegroups.com> <4302d48e.1666704914@news.oz.net> <1124259853.264169.157750@g44g2000cwa.googlegroups.com> Message-ID: ChuckDubya at gmail.com wrote: > Example: I'm driving a car in a game and I hit an oil slick so instead > of me having to lift off the throttle button on the keyboard, I want to > make a program to disengage the throttle as long as I'm on that oil > slick. Does that clear anything up? Yes. Here's how to do it: import random import time class Car: def throttle(self, on): if on: print "full throttle" else: print "on that oil slick again" class ThatOilSlick: def __contains__(self, item): return random.random() < .7 class Game: def __init__(self): self.car = Car() self.thatOilSlick = ThatOilSlick() def play(self): while True: self.car.throttle(self.car in self.thatOilSlick) time.sleep(.2) if __name__ == "__main__": Game().play() :-) Look here for further information: www.catb.org/~esr/faqs/smart-questions.html Peter From john at castleamber.com Fri Aug 26 07:16:43 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 11:16:43 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> Message-ID: usenet at isbd.co.uk wrote: > In comp.lang.perl.misc John Bokma wrote: [ web based boards ] >> And which useful tools do you require? >> > A choice of news readers to suit different people with different > interfaces, - different browsers, different stylesheets, different board styles (themes). > filtering, There is often a search function, which filters away everything that doesn't match. There are also things like word filters, etc. > kill files, > etc. etc. http://www.phpbb.com/mods/ > A forum provides a > single, usually rather limited, interface for the user with no way for > the user to change it radically. Does the user want this? And with a user stylesheet you can change it quite radically :-) And in return the user gets: colors, fonts, font sizes, embedding of images, flash, you name it. Moving avatars, even sounds. Oh, yes, I would love to see an XML interface on the board I use. Maybe I can just install a mod, or write one myself. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From steven.bethard at gmail.com Fri Aug 12 00:36:07 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 11 Aug 2005 22:36:07 -0600 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: Ray wrote: > 1. Where are the access specifiers? (public, protected, private) There's no enforceable way of doing these. The convention is that names that begin with a single underscore are private to the class/module/function/etc. Hence why sys._getframe() is considered a hack -- it's not officially part of the sys module. > 2. How does Python know whether a class is new style or old style? > E.g.: > > class A: > pass That's an old-style class. All new-style classes inherit from object (or another new-style class). So write it like: class A(object): pass If you're just learning Python now, there's really no reason to use old-style classes. They're only there for backwards compatibility. > 3. In Java we have static (class) method and instance members. But this > difference seems to blur in Python. I mean, when you bind a member > variable in Python, is it static, or instance? It seems that everything > is static (in the Java sense) in Python. Am I correct? No, there's a difference, but things can get a little tricky. We'll start with the easy one: py> class A(object): ... x = 0 # "static", class-level ... def __init__(self): ... self.y = 1 # "non-static", instance-level ... The difference between a "static", class-level attribute and a "non-static", instance-level attribute is whether it's set on the class object (e.g. in the class definition), or on the instance object (e.g. by writing self.XXX = YYY). Playing with this a bit: py> a = A() py> A.x # read the class-level "x" 0 py> a.x # read the *class*-level "x" (but search through the instance) 0 py> A.y # try to read a class-level "y" Traceback (most recent call last): File "", line 1, in ? AttributeError: type object 'A' has no attribute 'y' py> a.y # read the instance-level "y" 1 Note that you can read "static" attributes from both the class and the instance, and you can only read "non-static" attributes from the instance, just like Java (IIRC). Where you're likely to get confused is that instance level attributes can shadow the class level attributes. That is, if you set an instance attribute with the same name as a class attribute, you can't find the class attribute through that instance anymore: py> a.x = 2 # set the *instance*-level "x" py> A.x # read the *unchanged* class-level "x" 0 py> a.x # read the *changed* instance-level "x" 2 HTH, STeVe From pythonmailing at web.de Mon Aug 1 08:20:56 2005 From: pythonmailing at web.de (Marek Kubica) Date: Mon, 1 Aug 2005 14:20:56 +0200 Subject: The state of OO wrappers on top of wxPython (was Re: Wheel-reinvention with Python) References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87slxwqp32.fsf@wilson.rwth-aachen.de> <7xmzo4nmf0.fsf@ruckus.brouhaha.com> Message-ID: <8r4w9olxni3k.141eg8nfvy7s0$.dlg@40tude.net> On Sat, 30 Jul 2005 14:13:14 -0700 Cliff Wells wrote: > But how stable is GTK on systems such as Windows and OS/X? That has > been what has kept me from using it. Most GTK apps I've used on Windows > (including the venerable GIMP) are nowhere near as stable as their Linux > counterparts (although this may not be entirely the fault of GTK). > Also, GTK on OS/X requires Fink, which is a pretty hefty requirement to > place on an end user. I cannot speak for Mac OS X, but I like GTK on Windows, it's better than Tkinter :D GTK unter Windows has been discussed not so long ago: http://groups.google.de/group/comp.lang.python/browse_frm/thread/308b08adce4b9794/7ca38c3d89933ce9?tvc=1#7ca38c3d89933ce9 If you already tried GIMP on Windows, better try Inkscape on Windows.. that piece of GTK software is really good. greets, Marek From steve at holdenweb.com Thu Aug 25 16:29:11 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Aug 2005 16:29:11 -0400 Subject: variable hell In-Reply-To: <430e26c6$0$2092$626a14ce@news.free.fr> References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> Message-ID: rafi wrote: > Reinhold Birkenfeld wrote: > > >>>> exec(eval("'a%s=%s' % (count, value)")) >>> >>>why using the eval? >>> >>>exec ('a%s=%s' % (count, value)) >>> >>>should be fine >> >>And this demonstrates why exec as a statement was a mistake ;) >> >>It actually is >> >>exec 'a%s=%s' % (count, value) > > > Noted. > > In the meantime another question I cannot find an answer to: any idea > why does eval() consider '=' as a syntax error? > > >>> eval ('a=1') > Traceback (most recent call last): > File "", line 1, in ? > File "", line 1 > a=1 > ^ > SyntaxError: invalid syntax > > Thanks > Because eval() takes an expression as an argument, and assignment is a statement. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From max at alcyone.com Thu Aug 25 13:39:15 2005 From: max at alcyone.com (Erik Max Francis) Date: Thu, 25 Aug 2005 10:39:15 -0700 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: <5ZudndXd2JTen5PeRVn-2A@speakeasy.net> Bill Mill wrote: > Unlikely; 2 people have confirmed these results already. > > I did find, though, that if I remove all print statements from the > program, the dummy and non-dummy variable versions take indentical > time. Can others reproduce this? Yes, it's obviously a real effect given the other sightings. I don't see any speed difference, myself (Pentium IV 3.0 GHz running Slackware Linux). -- 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 never was a good war or a bad peace. -- Benjamin Franklin From fredrik at pythonware.com Thu Aug 11 08:26:12 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 11 Aug 2005 14:26:12 +0200 Subject: read function in python serial References: <8c05f79c05081102343e9827db@mail.gmail.com> Message-ID: "sinan ." wrote: > hi i`m developing a program that reads the serial device. i like the > readline() function, but readline() depends on \n character, i want a > similar function that waits for a specific character or string that i > gave like [ETX] (hex03) how can i do this ? call read(1) repeatedly until you see chr(3). From fuzzyman at gmail.com Fri Aug 19 10:31:23 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 19 Aug 2005 07:31:23 -0700 Subject: python html In-Reply-To: References: Message-ID: <1124461883.116486.44570@o13g2000cwo.googlegroups.com> I do exactly that in my Python CGI proxy (approx). I wrote a very simple parser called scraper.py that makes it easy. It won't choke on bad html either. http://www.voidspace.org.uk/python/recipes.shtml All the best, Fuzzyman http://www.voidspace.org.uk/python From rkern at ucsd.edu Sun Aug 7 15:46:21 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 12:46:21 -0700 Subject: Some newbie cgi form questions... In-Reply-To: References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> <1123429640.905460.140210@o13g2000cwo.googlegroups.com> Message-ID: Diez B.Roggisch wrote: >>Traceback (most recent call last): >> File "/var/www/users/senta/html/gobooks/cgi/form.py", line 35, in ? >> if not form.keys()[key]: >>TypeError: list indices must be integers >> >>As you can see, I am using python 2.3 (my web service provider is >>responsible for this - I'd use 2.4.1 if I could) > > That code above can't work - you want something like > > if not form.keys() in key: This thread has to rank somewhere in the top ten threads with respect to the density of obviously wrong code samples. -- 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 weekender_ny at yahoo.com Sun Aug 14 23:07:57 2005 From: weekender_ny at yahoo.com (John) Date: 14 Aug 2005 20:07:57 -0700 Subject: client server question References: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> <1123767743.583123.50710@o13g2000cwo.googlegroups.com> Message-ID: <1124075277.107036.11170@z14g2000cwz.googlegroups.com> Thanks a lot, I think I could modify this to get my work done. --j Chris Curvey wrote: > import threading > import logging > > ###################################################################### > class Reader(threading.Thread): > def __init__(self, clientsock): > threading.Thread.__init__(self) > self.logger = logging.getLogger("Reader") > > #----------------------------------------------------------------- > def run(self): > self.logger.info("New child %s" % > (threading.currentThread().getName())) > self.logger.info("Got connection from %s" % > (clientsock.getpeername())) > > #################################################################### > # set up a socket to listen for incoming connections from our clients > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > s.bind((host, port)) > s.listen(1) > > while True: > try: > clientsock, clientaddr = s.accept() > except KeyboardInterrupt: > raise > except: > traceback.print_exc() > continue > > client = Reader(clientsock) > client.setDaemon(1) > client.start() From steve at holdenweb.com Thu Aug 18 13:00:06 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Aug 2005 18:00:06 +0100 Subject: Put a url in a browsers address bar In-Reply-To: <4304B66B.6030706@ncl.ac.uk> References: <4304B66B.6030706@ncl.ac.uk> Message-ID: Colin Gillespie wrote: >>>I would like to place a url in my browsers address bar, then execute. >>>How can do this? >>> >> >>def goToGoogle(): >> import webbrowser >> webbrowser.open("www.google.com"); >> > > > Thanks for the quick reply. Do you know what module I would use to fill > out a form on an open web page? > > Thanks > > Colin You could take a look at John Lee's ClientForm module. Start at http://wwwsearch.sourceforge.net/ClientForm/ regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lycka at carmen.se Fri Aug 19 08:25:36 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 19 Aug 2005 14:25:36 +0200 Subject: up to date books? In-Reply-To: References: Message-ID: John Salerno wrote: > Just one more quick question: I'm basically learning programming for > fun, and I'm concentrating on C# right now. Python seems interesting, > but I was wondering if I should even bother. Would it supplement C# in > any way, or can C# do everything Python can? Python is an excellent tool in any programmers toolbox. No one language is ideal for every task, but Python very often provides a more rapid solution to your problem than other languages do. Particularly for small problems. It's common to use Python to solve a problem in 3 minutes that would take 10 or 30 minutes to solve in some other way. It's also great for building something in 3 man-months instead of 3 man-years, but you need more time to verify that claim! ;^) If you need a GUI for some simple task, it might often be more convenient to use something like Excel or VB. I haven't used MS's C# environment, so I can't compare with that, but it's often just a bad habit to build captive user interfaces for every task we want to solve. It certainly makes it much more difficult to make modular and reusable software. Most Python programs I write work both as standalone programs and as modules that other programs can use. This versatility basically costs one line of code. If I was a professional C# developer, I'm pretty sure I'd use Python quite a bit. As a professional C++ programmer and database developer, I've used Python to manage tests, find and repair broken data in mission critical production systems, automate database administration tasks such as upgrading multiple databases, extracting, converting and copying data, create database reports, post-process generated source code, analyze large software systems and databases etc etc. Actually, during seven years as an independent consultant, I found good use for Python with every client. From krzychu at bmpg.pl Wed Aug 31 10:20:49 2005 From: krzychu at bmpg.pl (krzychu at bmpg.pl) Date: 31 Aug 2005 07:20:49 -0700 Subject: plone site in separate database - MountFolder Message-ID: <1125498049.013146.269700@o13g2000cwo.googlegroups.com> Hallo, I have an existing plone site called "info", I've added some scripts to it. I would like to have that plone site into a separate ZODB database(separate .fs file). There is a MountFolder product (1.2 - the latest release), by mean of this you can create MountFolder which data is stored in separate ZODB database. See manual http://cvs.sourceforge.net/viewcvs.py/ingeniweb/MountFolder/README.txt?rev=1.6 (I don't use ZEO section). Creating this MountFolder works fine. There is my registry in etc/zope.conf file of my zope instance: path $INSTANCE/var/infi2.fs mount-point /infi2 container-class Products.MountFolder.MountFolder.MountFolder But I can't import my plone site or even create brand new plone site from Add menu in the MountFolder. When I try to import my plone site I get the following error: Error Type: AttributeError Error Value: portal_types When I try to add brand new plone site from Add menu (Plone Site position) I get the following error: Error Type: AttributeError Error Value: portal_url I've noticed that some standard actions in MountFolder don't work as well. For instance when I try to paste Image object into MountFolder I get error too: Error Type: AttributeError Error Value: portal_url How can I solve this problem? Do you have any ideas how to put existing plone site into separate database? Regards Crissssss From yoav_artzi at il.vio.com Wed Aug 24 09:02:35 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Wed, 24 Aug 2005 16:02:35 +0300 Subject: Getting rid of "close failed: [Errno 0] No Error" on Win32 Message-ID: <430c6ecb$1@news.bezeqint.net> I am using os.popen3 to call a console process and get its output and stderr. However on Win32 (and not OS X) I also get the Errno message. It's printed to the screen, which I wish to keep clean. How can disable this notification? Thanks. From maxerickson at gmail.com Sat Aug 20 10:02:06 2005 From: maxerickson at gmail.com (Max Erickson) Date: 20 Aug 2005 07:02:06 -0700 Subject: Creating watermark with transparency on jpeg using PIL? In-Reply-To: <1124377623.599745.17750@g44g2000cwa.googlegroups.com> References: <1124377623.599745.17750@g44g2000cwa.googlegroups.com> Message-ID: <1124543696.044647.232760@o13g2000cwo.googlegroups.com> You need to pass a mask in when you paste in the watermark. see the documentation for the paste method at http://effbot.org/imagingbook/image.htm for more information This should at least get you started... >>> import Image >>> import ImageDraw >>> import ImageFont >>> import ImageEnhance >>> im=Image.new('RGB',(300,300),(0,0,0)) >>> font=ImageFont.truetype('verdana.ttf',12) >>> wm=Image.new('RGBA',(100,50),(255,255,255)) >>> im=Image.new('RGB',(300,300),(255,255,255)) >>> draw=ImageDraw.Draw(wm) >>> draw.text((0,0),'Watermark',(0,0,0),font) >>> wm.show() >>> en=ImageEnhance.Brightness(wm) >>> mask=en.enhance(0.5) >>> im.paste(wm,(25,25),mask) >>> im.show() >>> Here, the alpha channel of 'mask' is used as the mask. max From steve at holdenweb.com Sat Aug 27 11:15:46 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Aug 2005 11:15:46 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: <7xoe7k10pm.fsf@ruckus.brouhaha.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xoe7k10pm.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Steve Holden writes: > >>If you want an exception from your code when 'w' isn't in the string >>you should consider using index() rather than find. > > > The idea is you expect w to be in the string. If w isn't in the > string, your code has a bug, and programs with bugs should fail as > early as possible so you can locate the bugs quickly and easily. That > is why, for example, > > x = 'buggy'[None] > > raises an exception instead of doing something stupid like returning 'g'. You did read the sentence you were replying to, didn't you? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From apardon at forel.vub.ac.be Mon Aug 22 09:39:05 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 22 Aug 2005 13:39:05 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> <1124705414.704694.241960@f14g2000cwb.googlegroups.com> Message-ID: Op 2005-08-22, Steve Holden schreef : > Greg McIntyre wrote: >> John Machin wrote: >> >>>>Is some way to make this code more compact and simple? It's a bit >>>>spaghetti. >>> >>>Not at all, IMHO. This is a simple forward-branching exit from a loop in >>>explicable circumstances (EOF). It is a common-enough idiom that doesn't >>>detract from readability & understandability. Spaghetti is like a GOTO >>>that jumps backwards into the middle of a loop for no discernable reason. >> >> >> While that is true, I had high hopes that I could do this: >> >> while c = f.read(1): # ... >> >> And relative to that, it is more complex. And although I am nit-picking >> to try to simplify this code, I wanted to understand why Python works >> in this way (even if that's just "historical reasons"), and check to >> see if there was not some shorter more modern Pythonic alternative. >> > Guido explicitly decided he wanted a clear differentiation between > expressions and statements, and that assignment was to be a statement. > The logic behind this design decision is documented in > > http://www.python.org/doc/faq/general.html#why-can-t-i-use-an-assignment-in-an-expression > > which may have already been mentioned in this thread. I can't help but find this a very poor reason for this decision. Sure it is a hard to find bug. but that is not because the assignment is also an expression but because the assigment operator looks so much like an equality comparator. ':=' was already in use as an assignment is a number of languages and using it would have handled the typo problem just as well while still allowing assignments in expressions. This answer gives me the impression the matter wasn't thought through thoroughly. -- Antoon Pardon From rkern at ucsd.edu Thu Aug 4 19:11:05 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 04 Aug 2005 16:11:05 -0700 Subject: Parallel arithmetic? In-Reply-To: <42f298d6$1_5@alt.athenanews.com> References: <42f298d6$1_5@alt.athenanews.com> Message-ID: Terrance N. Phillip wrote: > Given a and b, two equal length lists of integers, I want c to be > [a1-b1, a2-b2, ... , an-bn]. I can do something like: > > c = [0] * len(a) > for ndx, item in enumerate(a): > c[ndx] = item - b[ndx] > > But I'm wondering if there's a better way, perhaps that avoids a loop? > > Nick. > > (I seem to recall from my distant past that this sort of thing was dead > easy with APL... c = a-b, more or less.) If you're doing this kind of thing often, look into using Numeric. http://numeric.scipy.org In [21]: from Numeric import array In [22]: a = array(range(10)) In [23]: b = array(range(10, 20)) In [24]: c = a - b In [25]: c Out[25]: [-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,] -- 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 Tue Aug 9 05:02:04 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 09 Aug 2005 05:02:04 -0400 Subject: How to determine that if a folder is empty? In-Reply-To: References: Message-ID: could ildg wrote: > On 8/8/05, Peter Hansen wrote: >>could ildg wrote: >>>I want to check if a folder named "foldername" is empty. >>>I use os.listdir(foldername)==[] to do this, >>>but it will be very slow if the folder has a lot of sub-files. >>>Is there any efficient ways to do this? >> >>I'm just curious to know under what circumstances where it's important >>to know whether a directory is empty it's also important that the >>operation occur with lightning speed... > > I want to know this because I want to zip a directory and all of its > sub-files and sub-directories to a zip file. zipfile module of python > will not automatically include the empty directories, so I have to > check if a dir is empty and do this manually. I did this with java, > it's very fast, but when I do this with python. I use the code to > backup a directory every morning after I get up. It is not import if > it's fast or not. I just want to know whether their is better > solutions. Thanks for the reply. I'll only point out, in case it's not now obvious, that in a situation where you are already going to be compressing (or have just compressed) a potentially large number of files in a potentially not empty subdirectory, the extremely slight extra cost of another os.listdir() will *never* be seen in the overall runtime of the code. Note also that any decent OS will have some sort of caching of directory info going on, so os.listdir() will probably do very little actual disk access and you shouldn't bother trying to optimize it away. -Peter From rkern at ucsd.edu Wed Aug 17 20:51:41 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 17 Aug 2005 17:51:41 -0700 Subject: GUI tookit for science and education In-Reply-To: References: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> Message-ID: James Sungjin Kim wrote: > Michele Simionato wrote: > >>My vote is for ipython + matplotlib. Very easy and very powerful. > > Is it really easier than to use MATLAB(TM)? If you're only doing exactly the things that MATLAB or one of its toolkits was designed to do, then MATLAB will probably be somewhat more convenient. Once you move outside of that box and start doing real programming, Python (with Numeric, ipython, matplotlib, scipy, et al.) beats MATLAB handily. -- 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 could.net at gmail.com Sun Aug 14 10:09:45 2005 From: could.net at gmail.com (could ildg) Date: Sun, 14 Aug 2005 22:09:45 +0800 Subject: What does the word "quiet" mean in this paragraph? In-Reply-To: References: <311b5ce105081405453299b71b@mail.gmail.com> Message-ID: <311b5ce105081407091a5023ed@mail.gmail.com> Thank you very much. I am not a native English speeker so I have problem when understanding this sentense. Now I know that the word "quiet" is an adjective and I'm totally catch it. Thank you~ On 8/14/05, Peter Decker wrote: > On 8/14/05, could ildg wrote: > > The paragraph is as below, I mark the word quiet with *** ***. > > ___________________________________ > > One problem with distributed applications is that if no data arrives > > over a long period of time, you need to wonder why. On one hand, it > > could be that the other program just hasn't had any information to > > send recently. On the other hand, the other program could have > > crashed. TCP handles this problem by allowing you to send an "Are you > > still alive?" message every so often to ***quiet*** connections. The > > way is to call setKeepAlive() with a value of true. > > ___________________________________ > > Please tell me what does the word "quiet" mean, Thank you~ > > It means that the remote application has sent any data recently: 'if > no data arrives over a long period of time'. We commonly say that two > programs 'talk' to each other, or that one program 'tells' the other > when it has received input. If these programs aren't 'saying' > anything, they're considered to be 'quiet'. The paragraph you quoted > is concerned with determining why the remote app hasn't 'said' > anything in a while: has it crashed, or is it really not getting any > data to relay. > -- > > # p.d. > -- > http://mail.python.org/mailman/listinfo/python-list > From ray_usenet at yahoo.com Sun Aug 14 13:34:38 2005 From: ray_usenet at yahoo.com (Ray) Date: 14 Aug 2005 10:34:38 -0700 Subject: A PIL Question Message-ID: <1124040878.557813.311900@g47g2000cwa.googlegroups.com> Hello, I'm using latest PIL version with Python 2.4.1. (for solving a level in Python Challenge actually...). Anyway, I'm trying to draw a picture. My question is, why is it that putdata() won't work? Even this won't run: import Image im = Image.open("something.jpg") seq = im.getdata() image = Image.Image() image.putdata(seq) image.show() I always get: Traceback (most recent call last): File "Script1.py", line 31, in ? image.putdata(seq) File "D:\Development\Python24\Lib\site-packages\PIL\Image.py", line 1120, in putdata self.im.putdata(data, scale, offset) AttributeError: 'NoneType' object has no attribute 'putdata' Anybody has any idea why this is the case? Thanks, Ray From john at castleamber.com Wed Aug 31 04:29:42 2005 From: john at castleamber.com (John Bokma) Date: 31 Aug 2005 08:29:42 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <1125064956.863140.32270@g14g2000cwa.googlegroups.com> <1125331397.416365.14460@g43g2000cwa.googlegroups.com> Message-ID: "T Beck" wrote: > John Bokma wrote: [ Death of Usenet has been predicted often ] > I suppose I was (as many people on the internet have a bad habit of > doing) being more caustic than was strictly necessary. I don't really > forsee the death of usenet anytime soon, I just don't think the idea of > it evolving is necessarily bad. I don't really have alot of vested > interest one way or the other, to be honest, and I'm perfectly happy > with the way it is. me too. > I just think it's a naive view to presume it never will change, because > change is what the internet as a whole was built on. I can't think of changes that are coming to Usenet (other then ipv6) -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From EP at zomething.com Wed Aug 10 05:31:13 2005 From: EP at zomething.com (EP) Date: Wed, 10 Aug 2005 01:31:13 -0800 Subject: Python -- (just) a successful experiment? In-Reply-To: References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <20050808005104.862503556.EP@zomething.com> Message-ID: <20050810013113.90446113.EP@zomething.com> Robert Kern > Michael Hudson wrote: > > Michael Hudson writes: > > > >>Robert Kern writes: > >> > >>>What I'm trying to say is that posting to c.l.py is absolutely > >>>ineffective in achieving that goal. Code attracts people that like > >>>to code. Tedious, repetitive c.l.py threads attract people that like > >>>to write tedious, repetitive c.l.py threads. > >> > >>+1 QOTW, though I may be too late > > > > Not only was I late, I was unoriginal! Oh well. > > That's okay, so was the quote! it's a great quote but did this tedious, repetitive c.l.py thread not attract several people who like to code? [inserting a smiley here :-) and dropping this thread because - yes, there are things I want to code and - no, there are not enough hours in the day] cheers EP/op From piet at cs.uu.nl Thu Aug 25 06:06:19 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 25 Aug 2005 12:06:19 +0200 Subject: pipes like perl References: <1124819825.156716.72400@z14g2000cwz.googlegroups.com> <1124913560.082809.201270@g47g2000cwa.googlegroups.com> Message-ID: >>>>> "infidel" (i) wrote: >i> .readlines() won't return until it hits end-of-file, but the "man" >i> command waits for user input to scroll the content, like the "more" or >i> "less" commands let you view "pages" of information on a terminal. man shouldn't wait for user input if its output is a pipe. Try man man|cat. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tjreedy at udel.edu Tue Aug 30 04:14:42 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Aug 2005 04:14:42 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xy86k3r7n.fsf at ruckus.brouhaha.com... > Really it's x[-1]'s behavior that should go, not find/rfind. I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely useful, especially when 'x' is an expression instead of a name. But even if -1 were not a legal subscript, I would still consider it a design error for Python to mistype a non-numeric singleton indicator as an int. Such mistyping is only necessary in a language like C that requires all return values to be of the same type, even when the 'return value' is not really a return value but an error signal. Python does not have that typing restriction and should not act as if it does by copying C. > Will socket.connect_ex also go? Not familiar with it. > How about dict.get? A default value is not necessarily an error indicator. One can regard a dict that is 'getted' as an infinite dict matching all keys with the default except for a finite subset of keys, as recorded in the dict. If the default is to be regarded a 'Nothing to return' indicator, then that indicator *must not* be in the dict. A recommended idiom is to then create a new, custom subset of object which *cannot* be a value in the dict. Return values can they safely be compared with that indicator by using the 'is' operator. In either case, .get is significantly different from .find. Terry J. Reedy From grante at visi.com Mon Aug 22 10:08:50 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 22 Aug 2005 14:08:50 -0000 Subject: sending binary files to a 16 micro controller. References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> Message-ID: <11gjn3in8u2965d@corp.supernews.com> On 2005-08-22, johnny.karlsson at gmail.com wrote: > I'm working on a project were a need to be able to upload firmware > to a microcontroller based Ethernet device. But because of the memory > constraints the controller can only handle packages of 300 bytes each > time. So therefore the firmware file must be sent in chunks and i need > a header in each file describing which part of the file it is I'm > sending. Could anyone give me some pointer on how a could accomplish > that in python? I'm talking about the client that uploads the software > to the device via TCP. You have no control over packet size in TCP if you use the normal socket interface. About the only thing you can to is put delays between calls to send() in hope that the TCP stack will send a packet. If you really do want control over packet size, you'll have to use a raw socket and impliment TCP yourself. -- Grant Edwards grante Yow! After THIS, let's go at to PHILADELPHIA and have visi.com TRIPLETS!! From pink at odahoda.de Fri Aug 26 16:29:17 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Fri, 26 Aug 2005 22:29:17 +0200 Subject: Speed quirk: redundant line gives six-fold speedup References: <1124998848.919158.277620@o13g2000cwo.googlegroups.com> Message-ID: Raymond Hettinger wrote: > > Mark Dickinson wrote: >> I have a simple 192-line Python script that begins with the line: >> >> dummy0 = 47 >> >> The script runs in less than 2.5 seconds. The variable dummy0 is never >> referenced again, directly or indirectly, by the rest of the script. >> >> Here's the surprise: if I remove or comment out this first line, the >> script takes more than 15 seconds to run. So it appears that adding a >> redundant line produces a spectacular six-fold increase in speed! > > Thanks for your post. It is cute, brilliant, and interesting. > > I haven't had time to investigate but can point at the likely cause. > All of the global names are stored in a single hash table. Search time > is dictated by two factors, the sparseness of the hash table and the > distribution of hash values. With respect to sparseness, whenever that > table becomes 2/3 full, it grows by a factor of four and becomes only > 1/6 full (leading to many fewer collisions). With respect to > distribution, it should be noted that string hash values are decidely > non-random and your variable names likely congested consecutive spaces > in a nearly full table (resulting in seven times as many search probes > to find a global value). > > When the extra value was added, it likely resized the table four-fold > and redistributed the hash values into fewer consecutive positions. If that's the cause, then here's another reason to use long, descriptive names instead of C64-BASIC style a, b, c, i, j... - with long names the chances of hash collisions are pretty low. Or everyone will start optimizing their programs by using long, *random* names ;) -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From bignose+hates-spam at benfinney.id.au Tue Aug 9 23:48:31 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 10 Aug 2005 13:48:31 +1000 (EST) Subject: Bizarre error from help() References: Message-ID: Roy Smith wrote: > I've got a directory where I keep all sorts of little snippets of > python code for testing. When I start up python in that directory, > I get the error I reported. It turns out, I've got a file called > "string.py" in it [...] > > something in the help system must be doing an "import string". All hail the coming of PEP 328: -- \ "The best ad-libs are rehearsed." -- Graham Kennedy | `\ | _o__) | Ben Finney From sp1d3rx at gmail.com Thu Aug 25 12:37:28 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 25 Aug 2005 09:37:28 -0700 Subject: Experience regarding Python tutorials? In-Reply-To: <1124986050.757959.307630@o13g2000cwo.googlegroups.com> References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <3n688aF2fp4U1@uni-berlin.de> <1124986050.757959.307630@o13g2000cwo.googlegroups.com> Message-ID: <1124987848.317437.106320@z14g2000cwz.googlegroups.com> I'd say, start with Python and work yourself into more complex languages. Python teaches you to indent properly, and it is good with being simple, yet powerful at the same time. I'd be happy to teach you the basics with Python. I've taught a few people how to program, and they learn Python pretty quickly, and from that, they are able to get into the "programmer's mindset" and move on to other languages. As an example, I taught a person how to program in Python over about a week period, and after that he wanted to learn C++. We worked on a small project together, using TCP sockets and such, and eventually he made a savegame editor for some game that he was beta testing all on his own, as well as a Netware NLM that checks backup logs and reports the status to a webserver. Python is good in that it does support object oriented programming, yet it's very easy to pickup on. Also, the builtin interpreter makes it easy to try out your code as you are writing it. There are others out there though, such as Microsoft Visual Basic that do a decent job. But, the nice thing about Python is that you can run your programs on Linux as well as Windows without any (or very few) changes. From michele.simionato at gmail.com Tue Aug 2 00:41:36 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 1 Aug 2005 21:41:36 -0700 Subject: doctest bug with nested triple quotes Message-ID: <1122957696.085082.293440@o13g2000cwo.googlegroups.com> I am getting trouble with nested triple quoted strings in doctest. For instance $ cat x.py """ >>> dummy = ''' something here ''' """ import doctest; doctest.testmod() $ python x.py ********************************************************************** File "x.py", line 2, in __main__ Failed example: dummy = ''' Exception raised: Traceback (most recent call last): File "/usr/lib/python2.4/doctest.py", line 1243, in __run compileflags, 1) in test.globs File "", line 1 dummy = ''' ^ SyntaxError: EOF while scanning triple-quoted string ********************************************************************** Is this a know bug? Any workaround? Thanks for comments, Michele Simionato From benji at benjiyork.com Tue Aug 2 16:29:56 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 02 Aug 2005 16:29:56 -0400 Subject: trying to parse non valid html documents with HTMLParser In-Reply-To: <42efc9ae$0$12924$636a15ce@news.free.fr> References: <42efc9ae$0$12924$636a15ce@news.free.fr> Message-ID: <42EFD7C4.5060706@benjiyork.com> florent wrote: > I'm trying to parse html documents from the web, using the HTMLParser > class of the HTMLParser module (python 2.3), but some web documents are > not fully valids. From http://www.crummy.com/software/BeautifulSoup/: You didn't write that awful page. You're just trying to get some data out of it. Right now, you don't really care what HTML is supposed to look like. Neither does this parser. -- Benji York From gene.tani at gmail.com Fri Aug 5 10:40:03 2005 From: gene.tani at gmail.com (gene tani) Date: 5 Aug 2005 07:40:03 -0700 Subject: Oreilly CodeZoo Message-ID: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> http://radar.oreilly.com/archives/2005/08/codezoo_program_1.html http://python.codezoo.com/ Nice to see that python is in-demand, but what is the rationale for another ASPN cookbook/Parnassus / pypackage / dmoz type repository? From renting at astron.nl Mon Aug 29 03:17:39 2005 From: renting at astron.nl (Adriaan Renting) Date: Mon, 29 Aug 2005 09:17:39 +0200 Subject: variable hell Message-ID: I'm sorry for top-posting and not marking quoted text, but my e-mail reader (Novell Groupwise 6 for Linux) does not mark quoted text. The only thing it does is the >>> $NAME <$EMAIL> $DATE >>> above the quoted text. Therefore I add my comments at the top. The only alternative I have is copying all text to an editor, adding quote marks by hand, then copying it back into a new e-mail message, but this takes to much of m time. If this is to confusing I will just stop posting in this list. My original code was: exec(eval("'a%s=%s' % (count, value)")) Then Rafi said: exec("'a%s=%s' % (count, value)") To which I responded that his example does not work in my Python, and I think it's invalid. Then Martin came with: exec 'a%s = %s' % (count, value) This does work. But he seems to keep telling me I'm quoting him wrong, while I'm quoting Rafi. Furthermore I'm going with your suggestion of checking the imp, globals() and locals(). Adriaan Renting. >>>Mike Meyer 08/27/05 2:24 am >>> [The context is totally hosed by top posting and failure to mark quoted text. I gave up on recovering it.] "Adriaan Renting" writes: >Not in my Python. > >>>>for count in range(0, 10): >... value = count >... exec("'a%s=%s' % (count, value)") You left in the extra set of quotes. Try this: >>>for count in range(10): ... value = count ... exec 'a%s = %s' % (count, value) ... >>>dir() ['__builtins__', '__doc__', '__file__', '__name__', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'count', 'help', 'readline', 'rlcompleter', 'sys', 'value'] I also removed the extraneous parens that you and Rafi both used - exec is a statement, not a function. Of course, your two examples are better done using imp and globals() or locals(). >>>dir() >['__builtins__', '__doc__', '__name__', 'count', 'value'] >>>>for count in range(0, 10): >... value = count >... exec(eval("'a%s=%s' % (count, value)")) >... >>>>dir() >['__builtins__', '__doc__', '__name__', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'count', 'value'] >>>> > >I myself use code like this to load user defined classes. > exec(eval("'from %s import %s' % (script, script)")) > exec(eval("'self.user_class = %s()' % script")) > self.user_class.run() > >But this can probably be done with the imp module too. > >>>>rafi 08/25/05 6:03 pm >>> >Adriaan Renting wrote: >>You might be able to do something along the lines of >> >>for count in range(0,maxcount): >> value = values[count] >> exec(eval("'a%s=%s' % (count, value)")) > >why using the eval? > >exec ('a%s=%s' % (count, value)) > >should be fine > >-- >rafi > >"Imagination is more important than knowledge." > (Albert Einstein) >-- >http://mail.python.org/mailman/listinfo/python-list > -- Mike Meyer http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list From sklass at pointcircle.com Mon Aug 22 10:07:51 2005 From: sklass at pointcircle.com (rh0dium) Date: 22 Aug 2005 07:07:51 -0700 Subject: Using Signal Handler to timeout an rsh call Message-ID: <1124719671.001774.300000@f14g2000cwb.googlegroups.com> Hi all, I don't understand the signal module. I guess I understand what it does in principle but I can't figure out how to use it to timeout an external rsh command after a 5 seconds. Does anyone know how to do this. Here is what I have so far - which is largely based on the example on the man page.. def handler(signum, frame): print 'Signal handler called with signal', signum raise IOError, "Couldn't open device!" for host in alive: try: # Set the signal handler and a 5-second alarm signal.signal(signal.SIGALRM, handler) signal.alarm(5) (out,results) = commands.getstatusoutput( "rsh %s uname -a" % host) signal.alarm(0) # Disable the alarm #self.logger.debug( "%s Connection to %s - %s" % (out,host,results)) if out ==256: noaccess.append(host) del alive[host] break if out == 0: if re.search("SunOS",results): hosttype="sun" elif re.search("Linux",results): hosttype="linux" Can anyone point me in the right direction. Much appreciated!! From mimicico at gmail.com Thu Aug 4 06:10:20 2005 From: mimicico at gmail.com (mimicico at gmail.com) Date: 4 Aug 2005 03:10:20 -0700 Subject: Python-Excel: How to paste selected cells (range) to different location on the same sheet in Excel In-Reply-To: <1123133763.524077.205640@f14g2000cwb.googlegroups.com> References: <1123133763.524077.205640@f14g2000cwb.googlegroups.com> Message-ID: <1123150220.914373.68170@g44g2000cwa.googlegroups.com> I think you just need do: sh.Range(sh.Cells(4,1),sh.Cell?s(6,3)).Value = sh.Range(sh.Cells(1,1),sh.Cell?s(3,3)).Value From ChuckDubya at gmail.com Wed Aug 17 01:30:51 2005 From: ChuckDubya at gmail.com (ChuckDubya at gmail.com) Date: 16 Aug 2005 22:30:51 -0700 Subject: Making programs work together. Message-ID: <1124256651.450266.90580@g47g2000cwa.googlegroups.com> I'm looking to make what's basically a macro for a computer game. But I want this "macro" to take information from the game itself, so it's not really a macro. How do I access the data from my game to use in a program? From python-url at phaseit.net Fri Aug 12 18:08:04 2005 From: python-url at phaseit.net (Cameron Laird) Date: Fri, 12 Aug 2005 22:08:04 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) Message-ID: QOTW: "... So I started profiling the code and the slowdown was actually taking place at places where I didn't expect it." -- Guyon Mor?e (and about twenty-three thousand others) "[A] suggestion from the world of 'agile development': stop making so many decisions and start writing some actual code!" -- Peter Hansen Scott David Daniels and others illustrate that the most common answer for Python is, "It's (already) in there." In the case at hand the subject is primitive symbolic arithmetic: http://groups.google.com/group/comp.lang.python/index/browse_frm/thread/13ed519653969e55/ Andy Smith rails against "frameworks": http://an9.org/devdev/why_frameworks_suck?sxip-homesite=&checked=1 "Porcupine is a [Python-based] Web application server that features an embedded object database, the Porcupine Object Query Language, XMLRPC support, and QuiX, an integrated JavaScript XUL motor." http://www.innoscript.org Getters and setters are (mostly) for other languages; Python has properties (and descriptors!): http://groups.google.com/group/comp.lang.python/browse_thread/thread/f903ab167c91e6ce/ Ramza Brown confusingly but helpfully repackages "the absolute minimum libraries needed for Python to work with Win32": http://groups.google.com/group/comp.lang.python/browse_thread/thread/d0d4e4303e985729/ Paolino offers a technique for *pruning* attributes in a subclass: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1805446521e8f34e/ Hard though it may be for some of us to accept, a zillion threads might not be all bad. http://www.usenix.org/events/hotos03/tech/vonbehren.html Python helps win awards: http://groups.google.com/group/comp.lang.python/browse_thread/thread/c6190563601c437f/ Python fits on small machines, sort-of: http://groups.google.com/group/comp.lang.python/browse_thread/thread/834f5b571be0b5f6/ ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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. del.icio.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/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 alessandro.bottoni at infinito.it Thu Aug 18 04:53:56 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Thu, 18 Aug 2005 08:53:56 GMT Subject: Some questions References: Message-ID: Titi Anggono wrote: > 1. Can we use Tkinter for web application such as Java? What do you mean? If you want to build up a GUI (something like a HTML page) for a web-based application, you can do it with TKinter. Your TKinter app can connect to a web server (or any other kind of server) using the standard Python networking libraries. If you want to make a web application (a server-side application similar to the ones you can create with JSP or EJB) you do not need Tkinter at all. Just use Python itself (see Albatross, Webware and Quixote for a few web-app frameworks for Python). > 2. I use gnuplot.py module for interfacing with > gnuplot in linux. Can we make the plot result shown in > web ? I tried using cgi, and it didn't work. The ability to display a image (in this case a GNUPlot plot) on a web page depends on the browser. Normally, you have to install a specific plug-in for displaying not-standard types of images on a web page, like it happens with Macromedia Flash. I do not know if exists any GNUPlot plug-in for the most common web browsers. Maybe you can save your plot in a format that is compatible with the existing viewers, like GIF, TIFF or JPEG. Have a look at GNUPlot documentation for this. HTH ----------------------------------- Alessandro Bottoni From bokr at oz.net Wed Aug 24 05:17:54 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 24 Aug 2005 09:17:54 GMT Subject: Line Removal strategy References: <1124831235.877424.45160@g49g2000cwa.googlegroups.com> Message-ID: <430c39fc.2282494723@news.oz.net> On 23 Aug 2005 14:07:15 -0700, "PyPK" wrote: >Hi I am looking for a simple algorithm for removing straight lines in a >given Image using something like an PIL or simpler. > The simplest is if you are in control of drawing in the first place and don't draw the lines ;-) Otherwise, you need to define your requirements a little more precisely. E.g., replacing horizontal and vertical runs of identical pixels of a given color with another given background color could be one definition. Removing an arbitrarily diagonal anti-aliased line of some undprcified width running through a speckled background is a different problem ;-) Regards, Bengt Richter From grflanagan at yahoo.co.uk Tue Aug 30 13:28:08 2005 From: grflanagan at yahoo.co.uk (Gerard Flanagan) Date: 30 Aug 2005 10:28:08 -0700 Subject: Python2Html regex question Message-ID: <1125422888.376223.19970@z14g2000cwz.googlegroups.com> Hello I've been using the Html Formatter at http://www.manoli.net/csharpformat to format c# code (paste your code into the box, click the button and get html/css). Is there anything similar for Python code, does anyone know? Either way, the (c#) source is available for the above formatter and it looks like it would be straightforward to create a Python formatter by extending a base class and providing the following three things: 1) a list of python keywords 2) a regex to match python comments 3) a regex to match python strings Even my limited talents can handle the first, can anyone help me with 2) and 3)? C# uses '@' where Python uses 'r' as a 'raw-input' prefix for regex's, but I'm assuming the expressions themselves are the same in both languages? Thanks in advance. From exarkun at divmod.com Tue Aug 2 11:49:31 2005 From: exarkun at divmod.com (Jp Calderone) Date: Tue, 2 Aug 2005 11:49:31 -0400 Subject: Terminate a thread that doesn't check for events In-Reply-To: <9CA58FB7E095F146AD3E7FE1E5855929042FA8@brain.klausatlanta.local> Message-ID: <20050802154931.3914.1709785657.divmod.quotient.1576@ohm> On Tue, 2 Aug 2005 09:51:31 -0400, Liu Shuai wrote: >Can someone please comment on this? > > [snip - how to stop a thread without its cooperation?] There's no way to do this with threads, sorry. Perhaps you could use a child process, instead. Those are typically easy to terminate at arbitrary times. Jp From fredrik at pythonware.com Mon Aug 22 16:54:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 22:54:59 +0200 Subject: Can I send files through xmlrpc connections? References: <1124742818.840010.59710@g44g2000cwa.googlegroups.com> Message-ID: "dcrespo" wrote: > ...If the answer is Yes, can you give me an example either in the > server side and the client side? > > I googled a lot, but I can't find nothing regarding this. the XML-RPC specification http://www.xmlrpc.com/spec mentions the following data types four-byte signed integer boolean: 0 (false) or 1 (true) string double-precision signed floating point number date/time base64-encoded binary data structs arrays file isn't in that list. however, you can of course read the file into a variable, and send that variable over the wire (as either a string or a binary data value, depending on what kind of data you have in your files) (if the files are large, you might be better off using plain HTTP) From grig.gheorghiu at gmail.com Thu Aug 4 16:34:27 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 4 Aug 2005 13:34:27 -0700 Subject: installing python2.4.1 In-Reply-To: References: Message-ID: <1123187667.656812.275110@g49g2000cwa.googlegroups.com> I had a similar problem when trying to compile Python 2.4.1 on AIX. The configure script complained about not finding 'cc_r'. I simply did 'ln -s /usr/bin/gcc /usr/bin/cc_r' and that solved my problem. You may consider doing the same for cclplus. Grig From rkern at ucsd.edu Sat Aug 6 22:19:32 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 19:19:32 -0700 Subject: Proposed new collection methods In-Reply-To: References: <86d5oqvfqf.fsf@bhuda.mired.org> Message-ID: Robert Kern wrote: > Christopher Subich wrote: > > >>Dear Zeus no. Find can be defined as: >>def find(self, test=lambda x:1): >> try: >> item = (s for s in iter(self) if test(s)).next() >> except StopIteration: >> raise ValueError('No matching items in list') > > I would prefer that a find() operation return as soon as it locates an > item that passes the test. This generator version tests every item. Pardon me, I am retarded. -- 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 deets at web.de Mon Aug 29 10:06:55 2005 From: deets at web.de (Diez B. Roggisch) Date: 29 Aug 2005 07:06:55 -0700 Subject: NYC Opening In-Reply-To: References: Message-ID: <1125324415.780560.320730@o13g2000cwo.googlegroups.com> Kevin McGann wrote: > -Expert Java or C++ Now why exactly do you post that in c.l.python? > THEY ARE LOCATED IN NEW YORK, THIS IS FULL-TIME ONLY, WILL NOT CONSIDER > ANYONE FROM OUTSIDE THE US! THIS TEAM IS AN ELITE TEAM, YOU BETTER BE > GOOD!!!! I'm pretty sure you've some spelling wrong here, you certainly want ELITE to be written as 733T to get the attention of the proper people. SCNR, Diez From jforcier at strozllc.com Tue Aug 9 13:48:09 2005 From: jforcier at strozllc.com (Jeffrey E. Forcier) Date: 9 Aug 2005 10:48:09 -0700 Subject: sqlobject vs mysqldb module References: <1123602281.268415.288590@o13g2000cwo.googlegroups.com> Message-ID: <1123609689.304344.197910@z14g2000cwz.googlegroups.com> Skip is correct, they're somewhat different: SQLObject is an 'ORM' or 'Object-Relational Mapping', meaning that it allows you to handle everything related to the database with objects. The table handles are objects, the result set is an object, the individual rows in a result set are objects with attributes for the fields/columns. So instead of "SELECT id,name FROM people WHERE location='New York'", you'd do something like the following: for row in People.selectBy(location='New York'): print "id: %s, name: %s" % (row.id,row.name) This is nice if you value object-oriented code very highly, and don't have any specific SQL-level tricks you wish to employ (although SQLObject can handle those as well, I'm told, it's just not its main function). MySQLDB, while I haven't used it specifically, is probably similar to its Postgres cousins pyPgSQL and psycopg, in that it just provides a Python DB API compliant interface to the database (see http://www.python.org/peps/pep-0249.html). Such modules do not provide much or any object orientation, sticking with a more low-level approach of making SQL calls and getting dictionaries back, to wit: conn = [module_name].connect(connection_args) cursor = conn.cursor() cursor.execute("SELECT id,name FROM people WHERE location='New York'") print cursor.fetchall() Anyway, sorry if that's over your head (it's hard to tell your experience level from your post), but the basic gist is that SQLObject is good for a higher-level and very easy-to-use database connection, and MySQLDB is probably good if you're very comfortable with SQL and not so much with object-oriented programming (or if you have any other reason to prefer straight SQL queries). From amk at amk.ca Mon Aug 8 15:49:50 2005 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 08 Aug 2005 14:49:50 -0500 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <42f78937.926582004@news.oz.net> Message-ID: On Mon, 08 Aug 2005 16:58:40 GMT, Bengt Richter wrote: > It occurs to me that we have the PEP process for core python, but no PEP process > for the python app/lib environment. What about starting a PEEP process > (Python Environment Enhancement Proposals) modeled on PEPs, where those motivated > to formalize their pet projects or feature requests could collaborate to create > a spec to document and guide development? The PEP process could be used for some of this. There are existing informational PEPs that aren't connected to the core language, but just specify some interface for the community's use: IR 216 Docstring Format IF 248 Python Database API Specification v1.0 IF 249 Python Database API Specification v2.0 I 333 Python Web Server Gateway Interface v1.0 Other PEPs describe how to modernize code (PEP 290) and hack the code (290, 339). This is similar to RFCs: there are normative RFCs that actually specify something, and informative RFCs that publish information about an experimental protocol or system. PEPs would be especially good for things like WSGI that are intended to be supported by many different projects; it's less useful to document how a pet project works. --amk From michele.simionato at gmail.com Wed Aug 10 08:32:56 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 10 Aug 2005 05:32:56 -0700 Subject: issues with doctest and threads In-Reply-To: References: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> <1123580365.838675.182080@g14g2000cwa.googlegroups.com> Message-ID: <1123677176.525368.46050@g14g2000cwa.googlegroups.com> Tim Peters wrote: > Because the program is buggy: synchronizing threads isn't a "do it if > you feel like it" thing, it's essential to correct threaded behavior. > If you're going to show students bad thread practice, they're going to > get mysteries a lot deeper and more damaging than this one <0.5 wink>. Well, yes, but here I am using bad practices *on purpose*, trying to figure out the most likely mistakes of my students. I want to show them what they should NOT do, and what happens if they do. I personally don't have that much practice with threads (for instance, I knew about .join() but I forgot to use it) so it is also good for me if I do some mistake. Luckily the course is not about threads, but I might cover them as an optional topic. > Properly synchronize the thread, to enforce what the code requires but > cannot hope to obtain by blind luck. All it takes is the > thread.join() I suggested. I don't understand why you're fighting > that, because it's basic proper thread practice -- it's not like I > suggested an obscure expert-level hack here. I am not fighting .join() at all; but I want to know what I should expect in case I do a mistake. This is pretty useful in case I had to debug a threaded program written by my students. > If a student doesn't > know to join() a thread before they rely on that thread being done, > their thread career will be an endless nightmare. This is exactly the reason why I want to show them what happens if they don't use it ;) > All that said, this specific failure would _happen_ to go away too, if > in doctest's DocTestRunner.run(), the final 'test.globs.clear()" were > removed. If you feel it's necessary to let threads spawned by a > doctest run beyond the time doctest completes, you can arrange to > invoke DocTestRunner.run() with clear_globs=False. Perfect, this answers my question and gives me an useful tip about doctest globals. Thanks a lot! Michele Simionato From tjreedy at udel.edu Wed Aug 31 23:17:40 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2005 23:17:40 -0400 Subject: OpenSource documentation problems References: <43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: > Bryan Olson wrote: >> Whatever else one says about open-source documentation, keeping >> it current is a major unsolved problem. Python does pretty well. Doc updates, when needed, are an expected part of patches. Every couple of months or so, F. Drake releases a new 'development version' of the docs which I presume is synched with the current development version of the code. So when x.y.z or x.y.alpha1 is released, there should not be a hugh scramble to cobble together a corresponding doc set. The process is not perfect: people still find mismatches. But complaints about 'f**king docs' are truly obscene (IMO). Terry J. Reedy From jstroud at mbi.ucla.edu Mon Aug 15 18:49:46 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 15 Aug 2005 15:49:46 -0700 Subject: robust html parser In-Reply-To: References: Message-ID: <200508151549.46778.jstroud@mbi.ucla.edu> http://www.crummy.com/software/BeautifulSoup/ On Monday 15 August 2005 03:33 pm, BRA_MIK wrote: > I'm looking for a good and robust html parser that could parse complex > html/xhtml document without crashing (possibly free) > > Could you help me please ? > > TIA > MB -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From jeremy at emperorlinux.com Mon Aug 15 14:03:04 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Mon, 15 Aug 2005 14:03:04 -0400 Subject: Py_DECREF Question: Message-ID: <1124128984.3819.29.camel@localhost.localdomain> When I add an object created locally to a mapping or sequence (that will be returned from a function into an running instance of the Python interpreter), I need to call Py_DECREF on the object, right? Unfortunately, I really feel like the following code leaks memory... --- for example --- PyObject* list = Py_Buildvalue("[]"); while(go) { PyObject* num = Py_BuildValue("i", 10); PyList_Append(list, num); Py_DECREF(num); } return list; /* The responsibility of decrementing the list now lies within the scope of Python. */ --- end example --- Secondly, __and most importantly__, does anyone have any tools and/or recommendations for detecting memory leaks when writing extension modules in C? I've been using printf() and showing the OBJECT->ob_refcnt (which, is always 1 when I'm "done" with the pointer?) but this seems fairly newb. I'm mostly asking so I can cleanup any craziness in my code before I try and release pyiw (the Python bindings for Wireless Networking in Linux). I really want it to be as clean as possible before showing anyone else. :) From adam at atommic.com Tue Aug 23 20:45:44 2005 From: adam at atommic.com (Adam Atlas) Date: 23 Aug 2005 17:45:44 -0700 Subject: Multiple (threaded?) connections to BaseHTTPServer Message-ID: <1124844344.609477.32060@g47g2000cwa.googlegroups.com> Is there any built-in way for BaseHTTPServer to handle multiple connections at once, e.g. with threads? If not, can this existing module be easily extended to do this, or will I have to do lower-level socket things (and probably thus have to write my own HTTP code)? Thanks. Adam From erinhouston at gmail.com Thu Aug 11 16:20:22 2005 From: erinhouston at gmail.com (ina) Date: 11 Aug 2005 13:20:22 -0700 Subject: How to quit a Windows GUI program gracefully with Python under Cygwin? In-Reply-To: <1123761153.401824.43040@g49g2000cwa.googlegroups.com> References: <1123761153.401824.43040@g49g2000cwa.googlegroups.com> Message-ID: <1123791622.954340.74930@o13g2000cwo.googlegroups.com> Send the active program an alt-f4. I do this through shell.send keys. Hope this was of help. KB wrote: > Hi, > > I want to write a Python script that controls and automates a Windows > GUI computation program. > > My problem is that I do not know how to quit the Windows GUI program > gracefully with a command (program's or Python) in Cygwin. 'kill' or > CTRL-C command in Cygwin does not finish it gracefully, meaning that > some outputs do not come out normally. The only thing I know is to > click 'File-Exit' menu, but > this requires a manual intervention that prevents scripting. > > Is there a way to quit a Windows GUI program gracefully with Python > under Cygwin, of course, after the program finishes > normal execution? > > Thanks, > > KB From needdikinmylife2000 at yahoo.com Fri Aug 19 18:17:16 2005 From: needdikinmylife2000 at yahoo.com (allie) Date: Fri, 19 Aug 2005 22:17:16 -0000 Subject: looking to GIVE my first oral favor Message-ID: im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me From rkern at ucsd.edu Thu Aug 25 11:31:51 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 08:31:51 -0700 Subject: variable hell In-Reply-To: <430de100@127.0.0.1> References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> <430dd8e1@127.0.0.1> <430ddcd0$0$719$636a15ce@news.free.fr> <430de100@127.0.0.1> Message-ID: Nx wrote: >>""" >> >>Why unpack inputvalues if your next step is to pack'em back again ? Or >>what did I miss ? > > The original values in this case are being read from a text file > with one value including a linefeed per line and the original idea was, > that having them read into a list was the best way to massage them into the > form required to be used as input values for the insert statement. Again, why unpack them into separate variables when they are *already* in the form that you want to use them? -- 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 fakeaddress at nowhere.org Wed Aug 31 05:55:59 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 09:55:59 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <7xhdd7okn3.fsf@ruckus.brouhaha.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <7xhdd7okn3.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Not every sequence needs __len__; for example, infinite sequences, or > sequences that implement slicing and subscripts by doing lazy > evaluation of iterators: > > digits_of_pi = memoize(generate_pi_digits()) # 3,1,4,1,5,9,2,... > print digits_of_pi[5] # computes 6 digits and prints '9' > print digits_of_pi($-5) # raises exception Good point. I like the memoize thing, so here is one: class memoize (object): """ Build a sequence from an iterable, evaluating as needed. """ def __init__(self, iterable): self.it = iterable self.known = [] def extend_(self, stop): while len(self.known) < stop: self.known.append(self.it.next()) def __getitem__(self, key): if isinstance(key, (int, long)): self.extend_(key + 1) return self.known[key] elif isinstance(key, slice): start, stop, step = key.start, key.stop, key.step stop = start + 1 + (stop - start - 1) // step * step self.extend_(stop) return self.known[start : stop : step] else: raise TypeError(_type_err_note), "Bad subscript type" -- --Bryan From matt.walsh at gmail.com Wed Aug 10 09:55:07 2005 From: matt.walsh at gmail.com (matt.walsh at gmail.com) Date: 10 Aug 2005 06:55:07 -0700 Subject: PyOpenGL Message-ID: <1123682107.891810.321960@o13g2000cwo.googlegroups.com> Hey I'm a programmer looking to port some of my opengl ...although limited into a python app I've made... I'd like to know where to find any python/opengl source or a tutorial etc.. whatever I'd like to get a series of points that represent a 3d slope presented to the user. Thanks Matt From g.belyh at grsu.by Thu Aug 4 11:11:11 2005 From: g.belyh at grsu.by (Belyh G.P.) Date: Thu, 04 Aug 2005 18:11:11 +0300 Subject: installing python2.4.1 In-Reply-To: <42F22F51.8030506@grsu.by> References: <42F22F51.8030506@grsu.by> Message-ID: <42F2300F.2050007@grsu.by> Belyh G.P. wrote: OS - Debian GNU/Linux 3.1 >While I try to install python arise an error: > >I type > ./configure >... >... >checking for g++ ... no >checking for gcc ... gcc >checking for C++ compiler default output file name ... configure: error: >C++ compiler cannot create executables >See 'config.log' for more details. > > >config.log is > >This file contains any messages produced by compilers while >running configure, to aid debugging if configure makes a mistake. > >It was created by python configure 2.4, which was >generated by GNU Autoconf 2.59. Invocation command line was > > $ ./configure > >## --------- ## >## Platform. ## >## --------- ## > >hostname = zope >uname -m = i686 >uname -r = 2.6.8-2-686 >uname -s = Linux >uname -v = #1 Mon Jan 24 03:58:38 EST 2005 > >/usr/bin/uname -p = unknown >/bin/uname -X = unknown > >/bin/arch = i686 >/usr/bin/arch -k = unknown >/usr/convex/getsysinfo = unknown >hostinfo = unknown >/bin/machine = unknown >/usr/bin/oslevel = unknown >/bin/universe = unknown > >PATH: /sbin >PATH: /bin >PATH: /usr/sbin >PATH: /usr/bin >PATH: /usr/bin/X11 >PATH: /usr/local/sbin >PATH: /usr/local/bin > > >## ----------- ## >## Core tests. ## >## ----------- ## > >configure:1444: checking MACHDEP >configure:1578: result: linux2 >configure:1584: checking EXTRAPLATDIR >configure:1599: result: >configure:1618: checking for --without-gcc >configure:1667: result: no >configure:1673: checking for --with-cxx= >configure:1694: result: no >configure:1713: checking for c++ >configure:1742: result: no >configure:1713: checking for g++ >configure:1742: result: no >configure:1713: checking for gcc >configure:1729: found /usr/bin/gcc >configure:1739: result: gcc >configure:1779: checking for C++ compiler default output file name >configure:1782: gcc conftest.cc >&5 >gcc: installation problem, cannot exec `cc1plus': No such file or directory >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^6 >Where I can find "conftest.cc" or "cc1plus" ? I cannot find both in >archive... (archive is "Python-2.4.1.tgz" from >http://www.python.org/ftp/python/2.4.1/Python-2.4.1.tgz). It's my >problem or no? >configure:1785: $? = 1 >configure: failed program was: >| /* confdefs.h. */ >| >| #define _GNU_SOURCE 1 >| #define _NETBSD_SOURCE 1 >| #define __BSD_VISIBLE 1 >| #define _BSD_TYPES 1 >| #define _XOPEN_SOURCE 600 >| #define _XOPEN_SOURCE_EXTENDED 1 >| #define _POSIX_C_SOURCE 200112L >| /* end confdefs.h. */ >| >| int >| main () >| { >| >| ; >| return 0; >| } >configure:1824: error: C++ compiler cannot create executables >See `config.log' for more details. > >## ---------------- ## >## Cache variables. ## >## ---------------- ## > >ac_cv_env_CC_set= >ac_cv_env_CC_value= >ac_cv_env_CFLAGS_set= >ac_cv_env_CFLAGS_value= >ac_cv_env_CPPFLAGS_set= >ac_cv_env_CPPFLAGS_value= >ac_cv_env_CPP_set= >ac_cv_env_CPP_value= >ac_cv_env_LDFLAGS_set= >ac_cv_env_LDFLAGS_value= >ac_cv_env_build_alias_set= >ac_cv_env_build_alias_value= >ac_cv_env_host_alias_set= >ac_cv_env_host_alias_value= >ac_cv_env_target_alias_set= >ac_cv_env_target_alias_value= >ac_cv_prog_CXX=gcc > >## ----------------- ## >## Output variables. ## >## ----------------- ## > >AR='' >BASECFLAGS='' >BLDLIBRARY='' >BLDSHARED='' >BUILDEXEEXT='' >CC='' >CCSHARED='' >CFLAGS='' >CFLAGSFORSHARED='' >CONFIGURE_MACOSX_DEPLOYMENT_TARGET='' >CONFIG_ARGS='' >CPP='' >CPPFLAGS='' >CXX='gcc' >DEFS='' >DLINCLDIR='' >DLLLIBRARY='' >DYNLOADFILE='' >ECHO_C='' >ECHO_N='-n' >ECHO_T='' >EGREP='' >EXEEXT='' >EXTRAMACHDEPPATH='' >EXTRAPLATDIR='' >HAVE_GETHOSTBYNAME='' >HAVE_GETHOSTBYNAME_R='' >HAVE_GETHOSTBYNAME_R_3_ARG='' >HAVE_GETHOSTBYNAME_R_5_ARG='' >HAVE_GETHOSTBYNAME_R_6_ARG='' >INSTALL_DATA='' >INSTALL_PROGRAM='' >INSTALL_SCRIPT='' >INSTSONAME='' >LDFLAGS='' >LDLAST='' >LDLIBRARY='' >LDLIBRARYDIR='' >LDSHARED='' >LIBC='' >LIBM='' >LIBOBJS='' >LIBRARY='' >LIBS='' >LIBTOOL_CRUFT='' >LINKCC='' >LINKFORSHARED='' >LN='' >LTLIBOBJS='' >MACHDEP='linux2' >MACHDEP_OBJS='' >MAINOBJ='python.o' >OBJEXT='' >OPT='' >OTHER_LIBTOOL_OPT='' >PACKAGE_BUGREPORT='http://www.python.org/python-bugs' >PACKAGE_NAME='python' >PACKAGE_STRING='python 2.4' >PACKAGE_TARNAME='python' >PACKAGE_VERSION='2.4' >PATH_SEPARATOR=':' >PYTHONFRAMEWORK='' >PYTHONFRAMEWORKDIR='no-framework' >PYTHONFRAMEWORKINSTALLDIR='' >PYTHONFRAMEWORKPREFIX='' >RANLIB='' >RUNSHARED='' >SGI_ABI='' >SHELL='/bin/sh' >SHLIBS='' >SIGNAL_OBJS='' >SO='' >SOVERSION='1.0' >SRCDIRS='' >THREADHEADERS='' >THREADOBJ='' >TRUE='' >UNICODE_OBJS='' >USE_SIGNAL_MODULE='' >USE_THREAD_MODULE='' >VERSION='2.4' >ac_ct_CC='' >ac_ct_RANLIB='' >bindir='${exec_prefix}/bin' >build_alias='' >datadir='${prefix}/share' >exec_prefix='NONE' >host_alias='' >includedir='${prefix}/include' >infodir='${prefix}/info' >libdir='${exec_prefix}/lib' >libexecdir='${exec_prefix}/libexec' >localstatedir='${prefix}/var' >mandir='${prefix}/man' >oldincludedir='/usr/include' >prefix='NONE' >program_transform_name='s,x,x,' >sbindir='${exec_prefix}/sbin' >sharedstatedir='${prefix}/com' >sysconfdir='${prefix}/etc' >target_alias='' > >## ----------- ## >## confdefs.h. ## >## ----------- ## > >#define _BSD_TYPES 1 >#define _GNU_SOURCE 1 >#define _NETBSD_SOURCE 1 >#define _POSIX_C_SOURCE 200112L >#define _XOPEN_SOURCE 600 >#define _XOPEN_SOURCE_EXTENDED 1 >#define __BSD_VISIBLE 1 > >configure: exit 77 > > > > > > > From nixdoc at ravelox.co-dot-uk.no-spam.invalid Mon Aug 8 01:54:03 2005 From: nixdoc at ravelox.co-dot-uk.no-spam.invalid (ravelox) Date: Mon, 8 Aug 2005 05:54:03 +0000 (UTC) Subject: Python HTTP digest authentication woes... References: <2005071702335516807%n00spamdeveloper@yahoocom> Message-ID: I hacked this a little bit and it seems to do the trick. import urllib2 theurl = "192.168.0.25/TiVoConnect?Container=%2FNowPlaying&Command=QueryContainer&Recurse=Yes" print theurl protocol = 'https://' username = 'tivo' password = '1111111111' authhandler = urllib2.HTTPDigestAuthHandler() authhandler.add_password("TiVo DVR", "192.168.0.25", username, password) opener = urllib2.build_opener(authhandler) urllib2.install_opener(opener) try: pagehandle = urllib2.urlopen(protocol + theurl) print pagehandle.readlines() except IOError, e: if hasattr(e, 'code'): if e.code != 401: print 'We got another error' print e.code else: print "Error 401" print e.headers print e.headers['www-authenticate'] Cheers Dave From google at phaedro.com Mon Aug 29 02:27:54 2005 From: google at phaedro.com (google at phaedro.com) Date: 28 Aug 2005 23:27:54 -0700 Subject: SocketServer and a Java applet listener In-Reply-To: References: <1124913592.821488.204350@g47g2000cwa.googlegroups.com> Message-ID: <1125296874.552905.313490@g43g2000cwa.googlegroups.com> Steve Horsley schreef: > google at phaedro.com wrote: > > Dear newsgroup, > > > > I give up, I must be overseeing something terribly trivial, but I can't > > get a simple (Java) applet to react to incoming (python) SocketServer > > messages. > > > > Without boring you with the details of my code (on request available, > > though), here is what I do : > > > > I have a TCPServer and BaseRequestHandler . > > Connecting via telnet : everything goes OK. > > > > Connecting from Applet : > > problem 1 (worked around it) : java has some 'propietary' UTF-8 format, > > python's unicode doesn't seem to handle it correctly and I have to > > strip the first two bytes/chars , then all goes OK . > > > > Those 2 bytes are important! They are a string length indicator. > Here are the docs that tell you that it puts a 2-byte length on > the front: > http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataOutputStream.html#writeUTF(java.lang.String) > If you are ignoring these bytes, then how can you be sure you > have received the whole string? Please don't tell me you "just > hope" that the whole string will always arrive in a single read() > call. There is no guarantee of that. TCP does NOT have message > boundaries, and TCP packets can be both fragmented and coalesced. Ah, I see... I worked around this (see below), the workaround is consistent with what you assume. My question "How to send/receive between python SocketServer and java Applet (SocketListener)" then seems to be boiling down to: "How to interface between python unicode and java read/writeUTF?" > > Probably the same problem. If you didn't send a 2 byte length > indicator first, then java's readUTF() will have tried to > interpret the first 2 bytes that you did actually send as the > string length, and may well simply be waiting patiently for the > rest to arrive. > I just couldn't get read/writeUTF and python unicode to interface, so I refactored the applet's socketlistener to convert the socket.getInputStream to a BufferedInputReader on which I call the readline() method. I still skip the first two bytes in the python receiver which seems harmless since python doesn't use the byte length. On both sides I have other way to know when the end-of-message has been reached. A timeout mechanism provides some safety for partial transmission handling. Thanks ! Thijs From john at castleamber.com Fri Aug 26 17:32:21 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 21:32:21 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> Message-ID: Denis Kasak wrote: > John Bokma wrote: >> >> so use Lynx :-) >> >> One forum I visit is about scorpions. And really, it talks a bit >> easier about scorpions if you have an image to look at :-D. >> >> In short: Usenet = Usenet, and www = www. Why some people want to >> move people from www to Usenet or vice versa is beyond me. If 80% of >> the current Usenet users stop posting, Usenet is not going to die :-D > > Agreed. This is actually your first post with which content I agree > totally. From your other posts I got the impression that you are one > of those people that are trying to make Usenet and WWW more similar to > one another. No, not at all. My point is what I wrote above. But also, a lot of functionality available on Usenet is also available on www. You don't *have* to convert people to Usenet, and to warn them against a forum on www. For day to day usage I experience hardly any difference. I mean, I am not struggeling when I post a message on a web board. And if things take time to download (for example a thread with many many pictures), I switch to another tab and do something else (tab browsing is fun :-). Each has its place. I don't want www on Usenet, and I don't want Usenet on www. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From duikboot at localhost.localdomain Wed Aug 24 07:40:48 2005 From: duikboot at localhost.localdomain (db) Date: Wed, 24 Aug 2005 13:40:48 +0200 Subject: Inheritance problem ? References: <1124879676.525583.14390@g44g2000cwa.googlegroups.com> Message-ID: On Wed, 24 Aug 2005 03:34:36 -0700, tooper wrote: > Hello all, > > I'm trying to implement a common behavior for some object that can be > read from a DB or (when out of network) from an XML extract of this DB. > I've then wrote 2 classes, one reading from XML & the other from the > DB, both inheritating from a common one where I want to implement > several common methods. > Doing this, I've come to some behaviour I can't explain to myself, > which I've reproduced in the example bellow : > > ----- > > class myfather: > def __repr__(self): > return "\t a="+self.a+"\n\t b="+self.b > > class mychilda(myfather): > def __init__(self,a): > self.a= a > def __getattr__(self,name): > return "Undefined for mychilda" > > class mychildb(myfather): > def __init__(self,b): > self.b= b > def __getattr__(self,name): > return "Undefined for mychildb" > > a= mychilda("a") > b= mychildb("b") > > print "a:\n"+str(a) > print "b:\n"+str(b) > > ----- > > I was expecting to get : > > a: > a= a > b= Undefined for mychilda > b: > a= Undefined for mychildb > b= b > > but I get the following error : > > File "/home/thierry/mytest.py", line 20, in ? > print "a:\n"+str(a) > TypeError: 'str' object is not callable > > Could someone explain me what I missed ? > > Thanks in advance ! try new style classes. class myfather(object): see http://users.rcn.com/python/download/Descriptor.htm HTH Arjen From kpacka at inbox.ru Mon Aug 22 09:16:29 2005 From: kpacka at inbox.ru (Vadimir) Date: 22 Aug 2005 06:16:29 -0700 Subject: Problem with wxPython 2.6.1 In-Reply-To: <1124716449.663875.307090@f14g2000cwb.googlegroups.com> References: <1124716449.663875.307090@f14g2000cwb.googlegroups.com> Message-ID: <1124716589.437350.108290@z14g2000cwz.googlegroups.com> http://www.lind-beil.net/pyped/ ---- look here, there are binary packages for ubuntu.... From martin at v.loewis.de Mon Aug 8 04:15:20 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 08 Aug 2005 10:15:20 +0200 Subject: visual studio 2005 In-Reply-To: <1123448372.152963.155180@g47g2000cwa.googlegroups.com> References: <1123448372.152963.155180@g47g2000cwa.googlegroups.com> Message-ID: <42f71498$0$13973$9b622d9e@news.freenet.de> wilf wrote: > Has anyone had success compiling python with this? I personally didn't try yet. Did you? Regards, Martin From pink at odahoda.de Fri Aug 19 11:13:14 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Fri, 19 Aug 2005 17:13:14 +0200 Subject: Save Binary data. References: Message-ID: GMane Python wrote: > Hello All. > I have a program that downloads 'gigabytes' of Axis NetCam photos per > day. > Right now, I set up the process to put the images into a queue, and every > 30 > or so seconds, 'pop' them from the queue and save them to disc. I save > them as individual files. > > I think that I'd like to modify it to save into one file 100-200 images, > so that I don't have directories with 50,000-90,000 frames before handing > that off to a DivX Encoder. > > I don't know if I need to use something like cPickle, or maybe just save > them as a binary data file (which would be a temp file until later in the > day when I open it to begin the encoding process.) > > Can someone please help me with some direction? You could use the tarfile module to create a single file holding a arbitrary number of files - including compression, if you want, but if your images are JPEGs then further compression is mostly a waste of CPU cycles. You can extract the images later on with either a python script and tarfile or using the standard commandline tool 'tar'. If the images are uncompressed anyway, you could have a look at the netpbm suite and its fileformat (which is pretty simple, but uncompressed and would bloat JPEGs to a multiple of the original filesize) which supports 'image sequences'. Perhaps a DivX encoder could even support this fileformat directly as input. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From paul at fxtech.com Fri Aug 26 10:05:30 2005 From: paul at fxtech.com (Paul Miller) Date: Fri, 26 Aug 2005 09:05:30 -0500 Subject: MacPython 2.2 on Mac OS X 10.3.8 - configurePython error In-Reply-To: References: Message-ID: Robert Kern wrote: > Paul Miller wrote: > >>I have a user who is is having trouble getting MacPython on his OS X >>10.3.8 system. >> >>When he runs ConfigurePythonCarbon, he gets this error: >> >>[terminated] >>'import site' failed; use -v for traceback >>traceback )most recent call last): >>File "Moes:SWdev:Jack:Python2.2:Mac:script:configurePython.py", line 11 >>, in ? >>Import error: No module named os >> >> >>I have had no trouble on my system (same version). >> >>What can cause this? > > > os.py got deleted from its home, probably. I doubt anyone is going to > help fix the problem though. MacPython 2.2 has been long abandoned. The > official OS X binary for Python 2.4.1 can be found here: > > http://www.python.org/ftp/python/2.4.1/MacPython-OSX-2.4.1-1.dmg I realize that, but I have an application that is linked with MacPython 2.2. I can't just drop 2.4 in. He claims the only thing that has changed is his preferences were wiped out. There must be some solution for what is probably a not too uncommon problem. > From john.coppens at gmail.com Sat Aug 6 01:08:45 2005 From: john.coppens at gmail.com (john.coppens at gmail.com) Date: 5 Aug 2005 22:08:45 -0700 Subject: Problem with new python (2.4.1) installation In-Reply-To: References: <1123293065.790239.171500@g47g2000cwa.googlegroups.com> Message-ID: <1123304925.565088.191750@f14g2000cwb.googlegroups.com> >Without the traceback for the first error Hello Peter... There was no traceback to the first error - in none of the cases the error appeared was a traceback present. I just found the error - the configuration of pygtk mentioned right in the middle somewhere that the atk version wasn't up-to-date, but did not signal any error at the end... Installed&compiled a newer atk and recompiled pygtk and that part seems ok. I'd suggest to the pygtk people to change their message at the end of the configure to something like: gtk yes atk no pango yes That way there would be a positive indication at the end that something was amiss. Thanks Peter! John From bokr at oz.net Mon Aug 8 12:58:40 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 08 Aug 2005 16:58:40 GMT Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> Message-ID: <42f78937.926582004@news.oz.net> On Mon, 8 Aug 2005 00:51:04 -0800, "EP" wrote: >Robert Kern wrote: > >> Which is exactly why I said at the beginning that people shouldn't = > >> bother with this thread and should instead just get to work. >> = > > > >Robert, you are probably right, but I think how we get to work is important= > as well. > >What I posted was a little intellectually thin, but it would be nice to sti= >r the collective energy toward some common (and useful) objectives. I thin= >k that something more than a superior language specification is required fo= >r a language to get a firm foothold in the IT world (and that is something = >I would personally like for Python.) > >It seems there are people very capable and willing to develop the good appl= >ications/tools/frameworks on top of Python, but too many of those projects = >do not gain critical mass; rather we have dozens of competing applications = >and frameworks that never blossom to their full potential. I'd love to see= > a little consensus on what "goodies" should be developed atop the language= >; what standards, principles, and API/hooks those goodies should provide; a= >nd then a collaborative effort to get there. Projects with a broader buy-i= >n have a greater chance of achieving their potential. It occurs to me that we have the PEP process for core python, but no PEP process for the python app/lib environment. What about starting a PEEP process (Python Environment Enhancement Proposals) modeled on PEPs, where those motivated to formalize their pet projects or feature requests could collaborate to create a spec to document and guide development? > >It does seem that perhaps some ground was gained with the WSGI effort. I u= >nderstand Django [http://www.djangoproject.com/], a RoR alternative based o= >n the WSGI spec, already has some buzz though "the cat got out of the bag a= > bit early" and Django is "not officially launched just yet." > >It makes sense to ask one's fellow developers and Python users what a new o= >pen source development should look and act like if one wants to develop som= >ething great. Open source code denotes sharing, but we should add teamwork= > and community involvement in the code as connotations if we want our open = >source to reach its potential. > PEEP as a vehicle? > >What are the top 5 developments, aside from specification and implementatio= >n details of the language itself, which Python still needs for greater succ= >ess in the day to day IT world? > > > > >EriPy pyDerson > > > > > >P.S. In terms of a more concrete suggestion, I propose the Python communit= >y form an intervention team who are ready to fly in and intercede any time = >a developer, whose brilliance has been expended in their heroic coding effo= >rt, goes to name their new module, package, or application with a "py" othe= >r than to the right of the dot. > Probably better to have the PSF hire a patent/trademark lawyer to reserve rights to py... names and the "py"-prefixing business process ;-/ Regards, Bengt Richter From Dennis.Hoffman at seagate.com Thu Aug 18 15:44:45 2005 From: Dennis.Hoffman at seagate.com (Dennis.Hoffman at seagate.com) Date: Thu, 18 Aug 2005 13:44:45 -0600 Subject: certificate-based authentication (Martin v. L?wis) In-Reply-To: Message-ID: >> I have been using XML-RPC to get information from one of our remote >> servers. To improve security, the server now has a certificate installed, >> and when I try to access it, I get an 'Unauthorized' exception. Is there >> an xmlrpclib module that supports (client-side) certificate-based >> authentication? If so, where can I get it, and what is involved in doing >> the authentication? If not, what are my options? > The standard xmlrpclib should work fine. You need to inherit from the > SafeTransport class, overriding get_host_info to return the x509_info. > You then pass an instance of your transport to the ServerProxy. > HTH, > Martin I'm using Python version 2.2 - the SafeTransport class in it's xmlrpclib doesn't have a 'get_host_info' method. Which version were you referring to? thanks Dennis From dd55 at cornell.edu Thu Aug 11 14:25:29 2005 From: dd55 at cornell.edu (Darren Dale) Date: Thu, 11 Aug 2005 14:25:29 -0400 Subject: command line reports Message-ID: Is there a module somewhere that intelligently deals with reports to the command line? I would like to report the progress of some pretty lengthy simulations, and currently I have the new reports written on a new line rather rather than overwriting the previous report. Thanks, Darren From richardlewis at fastmail.co.uk Fri Aug 26 09:15:45 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Fri, 26 Aug 2005 14:15:45 +0100 Subject: DOM text In-Reply-To: References: <1125050185.2182.241533364@webmail.messagingengine.com> Message-ID: <1125062145.16843.241544364@webmail.messagingengine.com> On Fri, 26 Aug 2005 13:59:09 +0200, "Fredrik Lundh" said: > Robert Kern wrote: > > > You might find that the more Pythonic XML modules are better suited to > > handling mixed content. I've been using lxml and ElementTree quite > > successfully. > > fwiw, here's an ET snippet that inserts an anchor element inside > a paragraph element: > > # from lxml.etree import * # or > # from cElementTree import * # or > from elementtree.ElementTree import * > > p = XML("

a link and some bold text

") > > a = Element("a", href="link") > > text = p.text # "a link and some " > > p.text = text[:2] # "a " is left after

> a.text = text[2:6] # "link" goes inside > a.tail = text[6:] # " and some" goes after > > p.insert(0, a) > > print tostring(p) # "

a link and some bold > text

" > > (this works with ET, cET, lxml.etree, and any other ET-com- > patible library, of course) > Thanks for this suggestion. I've not come accress ElementTree before, but it looks really useful (plus there are Debian packages :-) The only thing is that I've already written quite a lot of my code using minidom and mixing the two sounds like a recipe for disaster. But I'll certainly keep ET in mind for my next Python/XML project! Cheers, Richard From dmqatpobox.com Thu Aug 25 11:38:34 2005 From: dmqatpobox.com (David MacQuigg) Date: Thu, 25 Aug 2005 08:38:34 -0700 Subject: Fighting Spam with Python References: Message-ID: On Thu, 25 Aug 2005 10:18:37 -0400, Peter Hansen wrote: >David MacQuigg wrote: >> Are you as mad about spam as I am? Are you frustrated with the >> pessimism and lack of progress these last two years? Do you have >> faith that an open-source project can do better than the big companies >> competing for a lock-in solution? If so, you might be interested in >> the Open-Mail project. >> >> I'm writing some scripts to check incoming mail against a registry of >> reputable senders, using the new authentication methods. Python is >> ideal for this because it will give mail-system admins the ability to >> experiment with the different methods, and provide some real-world >> feedback sorely needed by the advocates of each method. So far, we >> have SPF and CSV. See http://purl.net/macquigg/email/python for the >> latest project status. > >You might find www.spambayes.org of interest, in several ways. Integration of a good spam filter is one of our top priorities. Spambayes looks like a good candidate. The key new features needed in a spam filter are the ability to extract the sender's identity (not that of the latest forwarder), and to factor into the spam score the reputation of that identity. We could use some help on this integration. I guess I should have said a little more about the Open-Mail project. We are not focused on developing new authentication or filtering methods, but rather, providing a platform that will bring these pieces together and allow the mail admin to chose which methods are used and in what order. Interoperability has been the main barrier to widescale use of authentication. Python is superb at gluing these pieces together. In the flow we envision, the spam filter is the final process, used only on the 5% that is hard to classify. 80% will get an immediate reject. 15% will get an immediate accept without filtering, because the sender is authenticated and has a good reputation. Eventually, all reputable senders will join the 15%, and the 5% will shrink to where we can ignore it. -- Dave From peter at engcorp.com Thu Aug 11 08:35:03 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 11 Aug 2005 08:35:03 -0400 Subject: client server question In-Reply-To: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> References: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> Message-ID: John wrote: > I have a simple script that runs a server where one client can connect. > I would like to make it so that many clients can connect to one server > on the same port. Where can I find how to do this? Start by reading http://www.catb.org/~esr/faqs/smart-questions.html to learn how to ask better questions. Then consider that "script that runs a server" could mean either you've written a Python "script" that runs *as* a server, but has the limitation of only one client connection at a time, or it could mean that your script simply runs (via, for example, a call to os.system()) an external server program which has this limitation. Given the ambiguity of your request, it's impossible to give a useful answer without lots of guessing. Please clear up the above question and provide much more detail and you'll likely get a more directly useful response. -Peter From Dennis.Hoffman at seagate.com Fri Aug 19 12:06:19 2005 From: Dennis.Hoffman at seagate.com (Dennis.Hoffman at seagate.com) Date: Fri, 19 Aug 2005 10:06:19 -0600 Subject: certificate-based authentication (Martin v. =?ISO-8859-1?Q?L=F6wis=29?= In-Reply-To: Message-ID: > The standard xmlrpclib should work fine. You need to inherit from the > SafeTransport class, overriding get_host_info to return the x509_info. > You then pass an instance of your transport to the ServerProxy. Ok - I have upgraded to the newer version of xmlrpclib that has the 'get_host_info' method. I have created a new class (inherited from the SafeTransport class), and overriden the get_host_info method. So my question now is where does the the x509_info come from? Is that the key/certificate comming back from the server? If so, how do I get that? If not, then where does it come from? You must excuse my ignorance, as this is all fairly new to me, and am still in the learning phase. Thanks Dennis From mcfletch at rogers.com Thu Aug 4 10:24:30 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 04 Aug 2005 10:24:30 -0400 Subject: Metaclasses and class variables In-Reply-To: <3756d97505080406543aea76aa@mail.gmail.com> References: <3756d97505080406543aea76aa@mail.gmail.com> Message-ID: <42F2251E.4020701@rogers.com> Jan-Ole Esleben wrote: >Yes, that works, but it is unfortunately not an option (at least not a >good one). > >Is there no way to create a class variable that exists during >definition of the class? (I cannot imagine there isn't, since >technically it's possible and manually it can be done...) > >Ole > > The metaclass hook occurs *after* class definition, anything using a side-effect of a metaclass hook then, *must* occur after the execution of the metaclass hook. At the time you want to write classvar.append the "class" is only a namespace, so, if you really need this feature you'll need to look elsewhere for at least *part* of the solution. A global "classvar" that, when appended to, caches values until your metaclass is called and transfers the cache to the class should *work*, but egads that's ugly compared to just classvar = [] . I guess what I'd ask is *why* is avoiding that single line so important. It could be there's a reasonable answer, but the amount of machinery required to avoid it is going to be significant. class meta( type ): newClassVar = [] def __new__( cls, name, bases, dictionary ): dictionary[ 'classvar' ] = cls.newClassVar[:] del cls.newClassVar[:] return super( meta, cls ).__new__( cls, name, bases, dictionary ) __metaclass__ = meta classvar = meta.newClassVar or something along those lines... Um, ick, but HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From python at rcn.com Fri Aug 26 18:16:14 2005 From: python at rcn.com (Raymond Hettinger) Date: 26 Aug 2005 15:16:14 -0700 Subject: Speed quirk: redundant line gives six-fold speedup References: <1124998848.919158.277620@o13g2000cwo.googlegroups.com> Message-ID: <1125094574.541657.101560@z14g2000cwz.googlegroups.com> [Raymond Hettinger] > > With respect to > > distribution, it should be noted that string hash values are decidely > > non-random and your variable names likely congested consecutive spaces > > in a nearly full table (resulting in seven times as many search probes > > to find a global value). > > > > When the extra value was added, it likely resized the table four-fold > > and redistributed the hash values into fewer consecutive positions. [Benjamin Niemann] > If that's the cause, then here's another reason to use long, descriptive > names instead of C64-BASIC style a, b, c, i, j... - with long names the > chances of hash collisions are pretty low. > Or everyone will start optimizing their programs by using long, *random* > names ;) The wink applied to second line but could have also applied to the first. For the most part, the non-randomness of string hashes tends to work in your favor -- it can result in collision free hash tables. For optimization, the best approach is to use local variables in your innermost loops. Alternatively, if you want to be tricky, try something like this: globals().update(globals()) What this does and why it can improve search times is left as an exercise for the reader :-) Raymond From billiejoex at fastwebnet.it Tue Aug 16 06:22:24 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Tue, 16 Aug 2005 12:22:24 +0200 Subject: sniffer in python References: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> <0KmdncVnD80_Hp3eRVn-rw@powergate.ca> Message-ID: Sorry... the text has been wrong formatted. Read this, plz >>> Thanks for your help. Like you suggested I converted the integer value in a string one by using the repr() funtion applied on the print: print '%d \n %s' %(count, repr(iface)) The program now permit me to select the interface. The output is in a strange hex-similar form: http://billiejoex.altervista.org/test.txt When I select the interface (0 or 1) I encounter an encoding error: Traceback (most recent call last): File "C:\Python24\test.py", line 108, in ? main(filter) File "C:\Python24\test.py", line 92, in main p = open_live(dev, 1500, 0, 100) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15: ordi nal not in range(128) - How con I resolve this encoding problem? - How can I display the interface names in a 'human' form? Best regards billie From max at alcyone.com Thu Aug 11 21:26:19 2005 From: max at alcyone.com (Erik Max Francis) Date: Thu, 11 Aug 2005 18:26:19 -0700 Subject: Jargons of Info Tech industry In-Reply-To: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <6rCdnRM5Y9QmZ2bfRVn-1Q@speakeasy.net> Xah Lee wrote: > Jargons of Info Tech industry > > (A Love of Jargons) > > Xah Lee, 2002 Feb Congratulations, this time you managed to get to your second paragraph before your Tourette's kicked in. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Behind an able man there are always other able men. -- (a Chinese proverb) From wolfgang.keller.nospam at gmx.de Tue Aug 2 07:22:00 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Tue, 02 Aug 2005 13:22:00 +0200 Subject: Python IDE's References: <20050731205901.53A6E1E4005@bag.python.org> Message-ID: Hello, > Thanks for your reply - that link is very useful, and i have been browsing > through the various multiplatform editors/ide's (i'm looking for something to > use on both my Windows machines and my Mac) You might want to have a look at the archive of the Python-Mac mailinglist. Someone who's maintaining the Mac OS X installers for several open-source IDEs has posted a quite extensive review of some IDEs very recently. To me it looks like Wing IDE may be the best choice if you want something perfectly solid and don't mind paying a reasonable price. Sincerely, Wolfgang Keller From no at spam Fri Aug 12 10:49:08 2005 From: no at spam (D H) Date: Fri, 12 Aug 2005 09:49:08 -0500 Subject: Python's Exception, and Capitalization In-Reply-To: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> References: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> Message-ID: Ray wrote: > Hello guys, > > OK, I've been reading some more about Python. There are some things > about Python exception that I haven't been able to grasp: > > 1. This is a small thing, but why is object spelled "object", and the > mother of all exception "Exception" (with capital E)? Why is not object > spelled "Object" then? I would guess that object is considered a primitive/basic type like int or float or string. > I mean, in Java, > it's Object. Whereas in C++, they're quite consistent, standard stuff > are usually all lowercaps (basic_string, iostream, etc.). Python seems > to have a mix of both. Yeah java capitalizes anything that is a class like String, Object, Integer, and lowercases its primitives like int, byte. > By the way, what's the convention for functions? It's a bit confusing > because when I see Python builtins, it seems that they follow C++ style > (e.g.: has_key, readline). So... does it mean that when I write my own > function, customarily I'd say myFunction() (or MyFunction()?) Yeah, the python standard library has been built by lots of different people. It wasn't designed by one entity using one standard like the java standard library or .NET/Mono class library. > 2. I'm quite baffled that you either have try/except, or try/finally. Apparently that will be fixed sometime: http://python.miscellaneousmirror.org/peps/pep-0341.html From listspam at flowtheory.net Tue Aug 30 01:46:57 2005 From: listspam at flowtheory.net (Joshua Ginsberg) Date: Mon, 29 Aug 2005 23:46:57 -0600 Subject: Lambda with copy.deepcopy() Message-ID: Howdy -- I have a class that has an attribute that is a dictionary that contains an object that has a kword argument that is a lambda. Confused yet? Simplified example: import copy class Foo: def __init__(self, fn=None): self.fn = fn class Bar: d = {'foobar': Foo(fn=lambda x: x*x)} def cp(self): self.xerox = copy.deepcopy(self.d) When I execute: b = Bar() b.cp() Using Python version: Python 2.3 (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin I get: Traceback (most recent call last): File "", line 1, in ? File "", line 5, in cp File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 179, in deepcopy y = copier(x, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 270, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 179, in deepcopy y = copier(x, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 307, in _deepcopy_inst state = deepcopy(state, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 179, in deepcopy y = copier(x, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 270, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 206, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy.py", line 338, in _reconstruct y = callable(*args) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/copy_reg.py", line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: function() takes at least 2 arguments (0 given) I've googled for deepcopy and lambda and found somebody else asking the same question on a LUG somewhere, but they gave no advice and nobody else seems to have run into this. Any ideas on what the problem is/how to get around it? Thanks! -jag From matt.hammond at rd.bbc.co.uk Mon Aug 22 08:34:39 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Mon, 22 Aug 2005 13:34:39 +0100 Subject: passing arguments from scale widget to function References: <430828c4$1@duster.adelaide.on.net> <4309b3f2$1@duster.adelaide.on.net> <4309bd93$1@duster.adelaide.on.net> Message-ID: > Ahhhh. Partial success with : command = Calc. A slider will now pass its > argument to a function without problem. My Calc function however is > expecting 3 arguments - 1 from each slider i.e moving any of the 3 > sliders should cause a recalculation. I am now getting the following > error: > TypeError: Calc() takes exactly 3 arguments (1 given) I'm sure you can figure this out now! Either: use lambda functions, as described, to call Calc with the correct arguments or: write three functions (one for each slider) that call Calc with all 3 arguments it requires regards Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From jdhunter at ace.bsd.uchicago.edu Fri Aug 5 13:39:21 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Fri, 05 Aug 2005 12:39:21 -0500 Subject: Passing a variable number of arguments to a wrapped function. References: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> Message-ID: <877jf0s2pi.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "stephen" == stephen writes: stephen> Is there a better way of doing this so that I don't have stephen> to go through every permutation of possible arguments stephen> (the example here from the matplotlib 'plot' function): You can make linecolor=None and linewidth=None, and then use matplotlib's rc defaults from matplotlib import rcParams def makeplot(self, xvalues, yvalues, linecolor=None, linewidth=None): if linecolor is None: linecolor = rcParams['lines.color'] if linewidth is None: linewidth = rcParams['lines.linewidth'] plot(xvalues, yvalues, color=linecolor, linewidth=linewidth) Then you can customize the defaults in the rc file (http://matplotlib.sf.net/matplotlibrc) any way you want. Alternatively, you can also set the defaults in your script from matplotlib import rc rc('lines', linewidth=1.0, color='red') JDH From spammers-go-here at spam.invalid Tue Aug 30 13:36:57 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Tue, 30 Aug 2005 13:36:57 -0400 Subject: Precise timings ? Message-ID: <431498f4$0$18638$14726298@news.sunsite.dk> Hi I am using time.clock() to get the current time of the processor in seconds. For my application, I need really high resolution but currently seem to be limited to 0.01 second. Is there a way to specify the resolution (say 1-10 microseconds) ? My processor is a 1.4 MHz Intel processor. Surely, it should be able to report times a few (or at least 10) microseconds apart. Thanks. From brian at sweetapp.com Wed Aug 3 05:07:05 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 03 Aug 2005 11:07:05 +0200 Subject: Python Programming Contest: First results In-Reply-To: <42EF352D.2060702@sweetapp.com> References: <1121838061.749455.44630@g14g2000cwa.googlegroups.com> <42DE18B2.903@sweetapp.com> <42EF352D.2060702@sweetapp.com> Message-ID: <42F08939.7010505@sweetapp.com> Brian Quinlan wrote: > Tomi Ky?stil? wrote: > >Why don't I see my solution (__author__ = "dOb") in the results? I'm >sure that you got it as you replied to my mail. Your solution is now included. See: http://www.sweetapp.com/pycontest/contest1/results.html Good job! Cheers, Brian From axel at white-eagle.invalid.uk Mon Aug 29 08:26:11 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Mon, 29 Aug 2005 12:26:11 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <861x4fuqzg.fsf@bhuda.mired.org> Message-ID: In comp.lang.perl.misc Mike Meyer wrote: > axel at white-eagle.invalid.uk writes: >> In comp.lang.perl.misc John Bokma wrote: >>> Chris Head wrote: >>>> What advantages would those be (other than access from 'net cafes, but >>>> see below)? >>> And workplaces. Some people have more then one computer in the house. My >>> partner can check her email when I had her over the computer. When I >>> want to check my email when she is using it, I have to change the >>> session, fire up Thunderbird (which eats away 20M), and change the >>> session back. >> Not a Windows solution, but I find the 'screen' utility invaluable as >> I can have my email, news, and an editor open in different screens >> and then when I need to move to a different machine, I can simply >> detach and reattach screen without disturbing anything that >> might be running. > For a more portable solution, check out VNC. I know... but it is a bugger to set up and I believe it is no longer freeware (if it ever was), and it does not have the stark simplicity which screen has... I only need to have a compiled version of screen on the machine on which I do most of my work and be able to ssh/telnet to that machine without involving any additional software installations on other machines. Axel From codecraig at gmail.com Tue Aug 16 12:02:31 2005 From: codecraig at gmail.com (codecraig) Date: 16 Aug 2005 09:02:31 -0700 Subject: libdnet and python (scapy) Message-ID: <1124207098.326863.250170@g43g2000cwa.googlegroups.com> I am interested in using libdnet with Python, how can I go about "installing" it on windows? http://libdnet.sourceforge.net/ Ultimately, I would like to get Scapy (http://www.secdev.org/projects/scapy/) running on windows...currently it is a *nix app written in Python, so I think I should be able to get it to work on Windows, just need some help I guess. Anyone get Scapy on Windows before or libdnet? Thanks From u.hobelmann at web.de Fri Aug 26 07:43:02 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Fri, 26 Aug 2005 13:43:02 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> Message-ID: <3n8di6Fbhg7U2@individual.net> John Bokma wrote: > Ulrich Hobelmann wrote: > >> What I hate about most are the sites that don't even *mention* that >> they want cookies. Often I have to wonder, reinput input fields etc. >> and then after ten minutes trying *bang*, the idea, maybe to allow >> cookies for that site. > > So your browser doesn't warn you? About what? I have cookies off, with explicit exception for sites where I want cookies. When the crappy website doesn't bother to MENTION that it wants cookies, i.e. give me an error page, how am I to know that it needs cookies? Do I want EVERY website to ask me "do you allow XY to set a cookie?" NO! -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From draghuram at gmail.com Wed Aug 17 17:41:17 2005 From: draghuram at gmail.com (draghuram at gmail.com) Date: 17 Aug 2005 14:41:17 -0700 Subject: creating/modifying sparse files on linux In-Reply-To: References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> Message-ID: <1124314877.646737.266290@z14g2000cwz.googlegroups.com> Thanks for the info on xrange. Writing single char is just to get going quickly. I knew that I would have to improve on that. I would like to write chunks of 1MB which would require that I have 1MB string to write. Is there any simple way of generating this 1MB string (other than keep appending to a string until it reaches 1MB len)? I don't care about the actual value of the string itself. Thanks, Raghu. From duncan.booth at invalid.invalid Fri Aug 12 03:49:24 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Aug 2005 07:49:24 GMT Subject: Regular expression to match a # References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> <42fbb9a9$1@news.eftel.com> <1123799252.257355.158320@f14g2000cwb.googlegroups.com> <42fbd1a1$1@news.eftel.com> <1123801101.340465.282320@g43g2000cwa.googlegroups.com> <42fbdb81$1@news.eftel.com> Message-ID: John Machin wrote: >> Your wording makes it hard to distinguish what exactly is "dopey". >> > > """ > dopey implementations of search() (which apply match() at offsets 0, 1, > 2, .....). > """ > > The "dopiness" is that the ^ operator means that the pattern cannot > possibly match starting at 1, 2, 3, etc but a non-optimised search will > not recognise that and will try all possibilities, so the failing case > takes time dependant on the length of the string. The ^ operator can match at any position in the string if the preceding character was a newline. 'Dopey' would be failing to take this into account. From rkern at ucsd.edu Thu Aug 25 05:08:34 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 02:08:34 -0700 Subject: How to start PEP process? In-Reply-To: <8DDC1FE0-640C-48A3-A022-ABCBDC2B082B@sbcglobal.net> References: <8DDC1FE0-640C-48A3-A022-ABCBDC2B082B@sbcglobal.net> Message-ID: Kenneth McDonald wrote: > Should I just put a "Proposed PEP" message here? "Proposed Python Enhancement Proposal"? A bit redundant, don't you think? :-) I think "pre-PEP" is the usual term. > Or is there a more > formal way? Not until you get to the post-pre-PEP stage. By all means, please do post it here and get some feedback before formally submitting it. -- 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 CantankerousOldGit at gmail.com Tue Aug 16 12:56:42 2005 From: CantankerousOldGit at gmail.com (Cantankerous Old Git) Date: Tue, 16 Aug 2005 17:56:42 +0100 Subject: Windows message pump problems Message-ID: I am trying to write a program that I hope to get working as a command-line app to start with, and then eventually use a windows service wrapper to call it as a service. Its purpose is to attach to an already running (not ours) service using an API DLL, where it will do houskeeping and monitoring tasks. This is where it all gets strange. Although I can make calls into the API and do things proactively, when I register a callback for event notification, this callback doesn't get called. I am told that if I want event notifications, I must create a window and run a "message pump" on it, and pass the window handle to the API when I register my callback function. This is despite the fact that I don't want my service to ever display a window. I gather I don't have to act on any messages either, but somehow the API won't tell me about any events unless I do this. So I am trying to create a skeleton that will create a window and run a "Message Pump". This is fairly succesful, in that I can create the window and the API then magically calls my event handler. But I want to be able to stop my service on demand, and this involved killing the message pump loop and destroying the window. I can't figure out how to do that. Problem 1: If I have another thread call DestroyWindow after a delay, it gets an error "permission denied". I really can't see why. Problem 2: I thought that maybe catching some kind of message might help. I have tried registering both a message-map and a wndProc handler. In both instances (see the code below) I don't get the WM_CREATE message that I hope to see first. Also, if I use the wndProc method, the CPU slams to 100% and I seem to receive an infinite number of messages of some sort. Problem 3: I thought if I pump the messages using GetMessage and DispatchMessage in my own loop, I might be able to check a flag and exit the loop when required. But I can't figure out the callling arguments to these calls. Below is the code I have done so far. I have stripped to as simple as I can make it. I would really appreciate some guidance or links to articles. I am struggling to understand even the basics, I think. The Cog. import win32gui import win32api import win32con import traceback, time, threading def onCreate(): print 'GOT WM_CREATE' def onDestroy(): print 'GOT WM_DESTROY' def wndProc(hwnd, msg, wparam, lparam): #print '~~~wndProc get a message' if msg == win32con.WM_CREATE: onCreate() if msg == win32con.WM_DESTROY: onDestroy() return 0 def registerWindowClass(): wc = win32gui.WNDCLASS() wc.hInstance = hinst wc.lpszClassName = "Eric the half-a-bee" messageMap = {win32con.WM_CREATE : onCreate , win32con.WM_DESTROY : onDestroy } wc.lpfnWndProc = messageMap # no messages if I do this #wc.lpfnWndProc = wndProc # infinite stream of messages if I do this return win32gui.RegisterClass(wc) def createWindow(registeredClassAtom): return win32gui.CreateWindow( registeredClassAtom, "This is a window", 0, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) hinst = win32api.GetModuleHandle(None) hwnd = createWindow(registerWindowClass()) win32gui.ShowWindow(hwnd, True) # I'll try hide it later win32gui.UpdateWindow(hwnd) # wait 10 secs then kill the window def timeKill(): print 'sleeping...' time.sleep(10) print 'killing' win32gui.DestroyWindow(hwnd) print 'starting killer timer' threading.Thread(target=timeKill).start() # This message pump traps the thread and never returns win32gui.PumpMessages() From kbchung at hongik.ac.kr Thu Aug 11 07:52:33 2005 From: kbchung at hongik.ac.kr (KB) Date: 11 Aug 2005 04:52:33 -0700 Subject: How to quit a Windows GUI program gracefully with Python under Cygwin? Message-ID: <1123761153.401824.43040@g49g2000cwa.googlegroups.com> Hi, I want to write a Python script that controls and automates a Windows GUI computation program. My problem is that I do not know how to quit the Windows GUI program gracefully with a command (program's or Python) in Cygwin. 'kill' or CTRL-C command in Cygwin does not finish it gracefully, meaning that some outputs do not come out normally. The only thing I know is to click 'File-Exit' menu, but this requires a manual intervention that prevents scripting. Is there a way to quit a Windows GUI program gracefully with Python under Cygwin, of course, after the program finishes normal execution? Thanks, KB From borges2003xx at yahoo.it Sat Aug 6 06:20:43 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 6 Aug 2005 03:20:43 -0700 Subject: substring and regular expression In-Reply-To: References: <1123140231.118099.4890@g43g2000cwa.googlegroups.com> <42f21930$1_2@newspeer2.tds.net> <1123166163.109766.297420@g43g2000cwa.googlegroups.com> Message-ID: <1123323643.102349.219860@g47g2000cwa.googlegroups.com> can you be so kind to show me a small example in spark if u like for remove all string with a substring of length 4 and the reverse of it? i thank you a lot From spammers-go-here at spam.invalid Thu Aug 18 12:40:24 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Thu, 18 Aug 2005 12:40:24 -0400 Subject: Testing for presence of arguments References: <430353e1$0$18641$14726298@news.sunsite.dk> <430360d8$0$18639$14726298@news.sunsite.dk> Message-ID: <4304b9d7$0$18644$14726298@news.sunsite.dk> Peter Maas wrote: >> Thanks for the suggestion, but seems needlessly complicated for > > something very simple. > > What is "very simple"? The problem or the solution? :) If you examine The form of the solution. > this suggestion more closely you will note that it is more or less > the same as Benji York's one except Benji used a built-in class. Many good solutions have some similarity. From the point of view of a user trying to include some simple functionality in a already complicated application, Benji's answer was most definitely more useful. > > If you are interested in getting help on usenet you should abstain > from devaluating efforts to give you a useful reply. "Thanks for > the suggestion" or even no answer would have been sufficient. > One might have thought that a truthful assessment would have been appreciated at the other end. I myself help people on the Usenet on some other newsgroups, and am usually welcoming of responses that offer a relevant criticism. The exchange improves me as much as it improves them. Thanks for the suggestion, anyways :) From john at hazen.net Thu Aug 11 19:10:08 2005 From: john at hazen.net (John Hazen) Date: Thu, 11 Aug 2005 16:10:08 -0700 Subject: Why is this? In-Reply-To: References: Message-ID: <20050811231008.GA16347@gate2.hazen.net> > >>>> [[]]*2 > > [[], []] > >>>> [[], []] == [[]]*2 > > True > > Same effect. But try the 'is' operator, to see if they are actually the > same instances of 'empty list': > > >>>> [[], []] is [[]]*2 > > True Just curious, did you actually cut and paste this from a real interactive session? (I think not.) My interpreter (yes, I know it's old) gives: $ python Python 2.3 (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> [[], []] is [[]]*2 False Which is, I think, the point you were trying to make. -John From cam.ac.uk at mh391.invalid Sat Aug 6 09:55:40 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sat, 06 Aug 2005 14:55:40 +0100 Subject: Some simple performace tests (long) In-Reply-To: <1123334835.548075.129430@z14g2000cwz.googlegroups.com> References: <1123334835.548075.129430@z14g2000cwz.googlegroups.com> Message-ID: TPJ wrote: > I decided to measure the performance of range and xrange... > > The results were as follows: > > n rprint xrprint > > 10^4 0.37 s 0.34 s <- (1) > 10^5 4.26 s 4.25 s > 10^6 42.57 s 42.57 s > 10^7 431.94 s 438.32 s <- (2) > > n rpass xpass > > 10^4 0.0012 s 0.0011 s > 10^5 0.0220 s 0.0139 s > 10^6 0.1463 s 0.1298 s > 10^7 1.4818 s 1.1807 s > > The values are the average times printed by tested functions. The number of replicates and standard deviations would be useful in analyzing these results. -- Michael Hoffman From esleben at gmail.com Thu Aug 4 09:46:10 2005 From: esleben at gmail.com (Jan-Ole Esleben) Date: Thu, 4 Aug 2005 15:46:10 +0200 Subject: Metaclasses and class variables In-Reply-To: References: Message-ID: <3756d97505080406463f3400cc@mail.gmail.com> I thought __new__ was called upon construction of the _class_ object that "Meta" is the type of. Then it would be available at the time of the definition of my class. Or am I mistaken? Ole 2005/8/4, Christopher Subich : > Jan-Ole Esleben wrote: > > class Meta(type): > > def __new__(cls, name, bases, d): > > d['classvar'] = [] > > return type.__new__(cls, name, bases, d) > > The problem is that __new__ is called upon object construction, not > class definition, but you're trying to set the class variables at > definition-time. > -- > http://mail.python.org/mailman/listinfo/python-list > From draghuram at gmail.com Wed Aug 31 16:59:05 2005 From: draghuram at gmail.com (draghuram at gmail.com) Date: 31 Aug 2005 13:59:05 -0700 Subject: Calling ftp commands from python In-Reply-To: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> References: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> Message-ID: <1125521945.668330.24190@g47g2000cwa.googlegroups.com> Your best bet would be to use "pexpect" module. Code may look something like: import pexpect import sys child = pexpect.spawn ('ftp ftp.site.com') child.expect ('Name .*: ') child.sendline ('username') child.expect ('Password:') child.sendline ('password') child.expect ('ftp> ') child.sendline ('cd testdir') child.expect ('ftp> ') child.sendline ('bin') child.expect ('ftp> ') child.sendline ('hash') child.expect ('ftp> ') child.sendline ('get testfile') child.expect ('ftp> ') print child.before child.sendline ('bye') Raghu. ~ From dan at cellectivity.com Thu Aug 11 12:34:56 2005 From: dan at cellectivity.com (Dan) Date: Thu, 11 Aug 2005 17:34:56 +0100 Subject: Writing a small battleship game server in Python In-Reply-To: <200508111746.15668.mail@tuxipuxi.org> References: <200508111746.15668.mail@tuxipuxi.org> Message-ID: <1123778097.6562.35.camel@localhost.localdomain> > The server should accept connections from new players and be able to handle > multiple games concurrently. Multiple threads would be the way to go for a real application. But if you want to avoid the complexity involved in threading and synchronization in this exercize, you can avoid threads by using "select" instead: http://www.python.org/doc/2.3.5/lib/module-select.html The "select" function allows you to determine (without blocking) which sockets have input available. Python's "select" is a wrapper for the C function with the same name. On Unix you can learn more about it using "man select". -- Yield in childhood to selfishness and you will find it the most enchaining tyrrany on earth. - Oswald Chambers, My Utmost For His Highest, p. 74 From roccomoretti at hotpop.com Tue Aug 9 13:12:26 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Tue, 09 Aug 2005 12:12:26 -0500 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: Gregory Pi?ero wrote: > Ahh, so it's a mutable thing. That makes sense that I can't change a > mutable object and thus can't affect it outside of the function. If you meant "immutable" for the second mutable, you're right. > Does > that mean Python functions aren't always byref, but are sometimes > byval for nonmutables? It'd probably do you good to get away from the by reference/by value thinking. Python isn't C/Basic/Fortran/etc. Variables in Python are names. They aren't the cubbyholes into which you put values, they are sticky notes on the front of the cubby hole. Parameter passing in Python always work the same way - you create a new name pointing to the passed object. Fin. The confusion you're having isn't in parameter passing, it's in the difference between assignment and mutation. Mutation changes the object itself (what's in the cubby hole), so it doesn't matter what or how many names/variables it has (what sticky notes are on the front). Assigment just changes where names point, not the contents of objects. (It's moving that sticky note, and only that sticky note, from one cubby to a different one.) Assignment justs affects that name, not any other name which point to the same object, including the variables in the passing scope. From brakjoller at gmail.com Mon Aug 15 06:22:27 2005 From: brakjoller at gmail.com (Mathias Dahl) Date: 15 Aug 2005 12:22:27 +0200 Subject: Invoking GUI for app running in background with a keypress Message-ID: I am creating a small app called PyQe (http://klibb.com/cgi-bin/wiki.pl/PyQe) to launch commands and programs quickly. I works more or less as I want it now and I have managed to make my window manager (Metacity) under Mandrake GNU/Linux start my program so that it can be started easily with just a keypress. Now, the only annoyance I have is that when I have not started the program for a while, the OS seems to not have Python or the program in "the cache" (or whatever, what I mean is that if I have started the program "recently" it starts fast the next time) anymore, which means that the program, even though quite small, takes about a second to start. This is too slow to feel good given the nature of the program (a quick launcher). I have tried making it start faster by calling python with the -S switch and by compiling my program to a .pyc file. It has not helped much. So, I was wondering if I could have my program running in the background and instead capture a certain keystroke (the same one I have my window manager to capture now) to make the GUI appear. How does one go about doing this? I found a small program written in C (xbindkeys) that can do this and understand that it probably involves a lot of "low-level" stuff in X which feels a bit "scary" :). Any clues of doing this "easily" in Python + some module? /Mathias From jeffrey.schwab at rcn.com Wed Aug 10 10:39:16 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Wed, 10 Aug 2005 10:39:16 -0400 Subject: Help with Regular Expressions In-Reply-To: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> Message-ID: Harlin Seritt wrote: > I am trying to find some matches and have them put into a list when > processing is done. I'll use a simple example like email addresses. > > My input is the following: > wordList = ['myname1', 'myname2 at domain.tld', 'myname3 at domain.tld', > 'myname4 at domain', 'myname5 at domain.tldx'] > > My regular expression would be something like '\w\@\w\.\w' (I realize > it could and should be more detailed but that's not the point for now). FYI, matching all compliant email addresses is ridiculously complicated. Before you spend too much time on it, you might want to borrow the complete and thoroughly explained example in Regular Expressions (O'Reilly): http://www.oreilly.com/catalog/regex/ From johnjsal at NOSPAMgmail.com Thu Aug 18 14:55:46 2005 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Thu, 18 Aug 2005 18:55:46 GMT Subject: up to date books? In-Reply-To: References: Message-ID: Also, are Python and Ruby similar languages? Which would be better to learn? John Salerno wrote: > Thanks for the great replies everyone! "Learning Python" was my first > choice, but it was also the reason I asked about older books, since it's > from 2003. But it seems that isn't an issue, and I think that would be a > nice place to start. > > Just one more quick question: I'm basically learning programming for > fun, and I'm concentrating on C# right now. Python seems interesting, > but I was wondering if I should even bother. Would it supplement C# in > any way, or can C# do everything Python can? > > Thanks, > John > > John Salerno wrote: > >> hi all. are there any recommendations for an intro book to python that >> is up-to-date for the latest version? >> >> would reading a book from a year or two ago cause me to miss much? >> >> thanks! From onurb at xiludom.gro Thu Aug 25 10:59:26 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 25 Aug 2005 16:59:26 +0200 Subject: variable hell In-Reply-To: <430dd8e1@127.0.0.1> References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> <430dd8e1@127.0.0.1> Message-ID: <430ddcd0$0$719$636a15ce@news.free.fr> Nx wrote: > Thanks for the many replies > > here is an example for what it will be used for , in this case > fixed at 31 fieldvalues: > > inputvalues=(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25, > s26,s27,s28,s29,s30,s31) > MYINSERTSELECT = "INSERT INTO > ADDRESS(ALIAS,COMPANY,ADDRESSLI1,ADDRESSLI2,ADDRESSCO,TOWN,ZIP,COUNTRY,TEL1,TEL2,FAX,EMAIL,INTERNET,PERSON1,TITLE1,RES1,PERSON2,TITLE2,RES2,PERSON3,TITLE3,RES3,PERSON4,TITLE4,RES4,PERSON5,TITLE5,RES5,PRODALIAS,PAGER,TLX,ADDMEMO) > VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" > > con1.commit() > cur = con1.cursor() > try : > cur.execute(MYINSERTSELECT,inputvalues) If I refer to your original post, there's someting I dont understand: """ I am unpacking a list into variables, for some reason they need to be unpacked into variable names like a0,a1,a2....upto aN whatever is in the list. """ Why unpack inputvalues if your next step is to pack'em back again ? Or what did I miss ? -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From devlai at gmail.com Mon Aug 1 12:36:58 2005 From: devlai at gmail.com (Devan L) Date: 1 Aug 2005 09:36:58 -0700 Subject: Wheel-reinvention with Python In-Reply-To: References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <7x3bpuxtwa.fsf@ruckus.brouhaha.com> Message-ID: <1122914218.663227.34150@g14g2000cwa.googlegroups.com> Ed Leafe wrote: > On Sunday 31 July 2005 22:39, Paul Rubin wrote: > > > > import dabo > > > app = dabo.dApp() > > > dApp.start() > > > > > > Sorry, I couldn't do it in 5. ;-) Oh, and that includes a full menu, > > > too. > > > > I get an ImportError exception when I try that. Any suggestions? Note > > that I don't get that exception from Tkinter. > > bash-3.00$ python > > Python 2.3.4 (#1, Oct 26 2004, 16:42:40) > > [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import dabo > > Traceback (most recent call last): > > File "", line 1, in ? > > ImportError: No module named dabo > > >>> import Tkinter > > >>> > > Oh, c'mon now Paul, now you're trolling. You know exactly what the problem > is, and try to make it look like a bug. > > Fine: you don't want to use anything that doesn't come standard with Python. > You've made your point. We get it. There is no need to repeat yourself > constantly. > > The only point of my post was that for those without your aversion to > installing useful tools, Dabo provides a ton of functionality. Also, as my > partner Paul McNett pointed out, I could have done it in *two* lines: > > import dabo > dabo.dApp().start() > > ;-) > > -- > > -- Ed Leafe > -- http://leafe.com > -- http://dabodev.com If you're creating a new instance of your dApp(I assume its a class) with no arguments, then effectively your just creating a default program which is already defined in the dabo module. If you could write it in a few, short lines of code by defining a new class, then you might have something there. From stas at tuxzilla.tuxhome Sat Aug 13 13:07:20 2005 From: stas at tuxzilla.tuxhome (stas) Date: Sat, 13 Aug 2005 19:07:20 +0200 Subject: wx.MessageDialog displayed without components inside References: <1123951035.856439.173160@g44g2000cwa.googlegroups.com> Message-ID: On Sat, 13 Aug 2005 09:37:15 -0700, perchef wrote: > Is there a reason why a wx.MessageDialog would be displayed without > components inside ? > > this : > > md = wx.MessageDialog(None,'foo','bar',wx.YES_NO) Here you create a dialog > result = md.ShowModal() Now you show it > md.Destroy() But right after showing it, you destroy it. > In my application, give me : > http://img252.imageshack.us/my.php?image=messagedialog6nw.jpg > > This isn't a bug in wxPython because when I use the same code in > pyshell I obtain the expected result. So, there must be a reason but I > can't figure out why. Because in the shell you first have to type the Destroy call so the dialog has some time to live. :-) Stas From spam.csubich+block at block.subich.spam.com Tue Aug 9 16:11:28 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 16:11:28 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: Gregory Pi?ero wrote: > So what if I do want to share a boolean variable like so: Well, the easiest way is to wrap it in a list: mybool = [True] mybool[0] = False mybool[0] = True and so on. Alternately, what is this boolean attached to that's so significant? Sharing an arbitrary boolean, without any context, is rather strange -- perhaps it would be best to include both the boolean and associated context in a single, larger object. Also, remember that Python functions can return more than one value, through implicit tuple packing and unpacking. This greatly reduces the need for C-like result = function(&other_result) - isms. def myfunc(): return 1,2,3 (a,b,c) = myfunc() a == 1 b == 2 c == 3 From lycka at carmen.se Tue Aug 16 13:08:50 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 16 Aug 2005 19:08:50 +0200 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: Terry Hancock wrote: > Zope recently started going through some massive changes to make > it more like a toolkit (which is the term I use instead of library here). > Even if there must be a framework, a thin framework with good tools > tends to be better than a complex framework, even if they can, in > principle do the same job. I think the Python community would benefit a lot if more of the Zope code becomes usable independently from Zope, and I hope it can influence not only the core Zope components, but also how people who code for Zope write their code. I've used ZODB successfully without Zope, and now I've started to use Twisted, and thus Zope Interfaces. Once upon a time I used bobo a little for things where Zope would be overkill. Zope contains a lot of code written by very smart Python developers, and I'm sure there are more gems to pick. Concerning 3rd party software, there does for instance seem to be a number of Zope workflow engines, but I don't know of any capable open source workflow engines in the non-Zope Python world. Things like that would be useful. None of this contradicts that frameworks can be useful and productive tools, but I think that just as with GUI tool kits, it's good practice to write your main business logic in a generic and toolkit independent way, and to use a thin layer of toolkit or framework etc to make things work in just that context. Just avoiding existing frameworks isn't the solution--you'll just end up inventing your own framework instead. From nyamatongwe+thunder at gmail.com Mon Aug 8 02:07:14 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Mon, 08 Aug 2005 06:07:14 GMT Subject: How to determine that if a folder is empty? In-Reply-To: References: Message-ID: could ildg: > I want to check if a folder named "foldername" is empty. > I use os.listdir(foldername)==[] to do this, > but it will be very slow if the folder has a lot of sub-files. > Is there any efficient ways to do this? The first thing to do is measure the performance of this operation in the context of your application to see if it is really worth extra effort. Tweaking this will depend on the platform. On Windows you can use ctypes and the system functions FindFirstFile/FindNextFile/FindClose, finishing once you see a single file. Directories always contain "." and ".." entries so they should be ignored. On other platforms there will be similar low level functions. Neil From __peter__ at web.de Tue Aug 23 03:48:41 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Aug 2005 09:48:41 +0200 Subject: loop in python References: Message-ID: km wrote: > the first thing any newbie to python asks me is abt "raw speed in > comparison with similar languages like perl" when i advocate python to > perl. In that case it is easy enough to follow the common industry practice and tweak your test cases until your favourite product comes out faster. $ time perl -e $'sub f() {for $i (0..10000000) {}} f();' real 0m1.075s user 0m1.073s sys 0m0.000s $ time python2.4 -c $'def f():\n for i in xrange(10000001): pass\nf()' real 0m0.878s user 0m0.871s sys 0m0.005s Working hypothesis: All benchmarks where Python comes out slower than Perl are not done properly :-) Peter From lickspittle at gmail.com Wed Aug 10 03:15:28 2005 From: lickspittle at gmail.com (lickspittle at gmail.com) Date: 10 Aug 2005 00:15:28 -0700 Subject: Windows embedding problems with stdin and stdout Message-ID: <1123658128.357406.145190@z14g2000cwz.googlegroups.com> Hi, I have Python embedded with my other code, and when my other code opens a console and redirects stdout, stdin and stderr to it, then calls PyRun_InteractiveLoop, it immediately returns with an EOF. After some debugging the reason for this appears to be that the stdin and stdout that the ReadLine function in the tokeniser include are not affected by my redirection and refer to a non-terminal so don't stall waiting for input from my console. This is the C code, effectively. It should suffice as an example of what I am doing, although as it is from memory, it may have minor semantic errors, please ignore them: /* This goes nowhere because the old stdin and stdout are no longer valid */ printf("Test\n"); /* This opens a console and redirects the in, out and err */ AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "a", stdout); freopen("CONOUT$", "a", stderr); /* I've tested stdin, stdout and stderr at this point and they all work correctly on the opened console window. */ printf("Test stdout working, isatty(stdin) = %d\n", isatty(fileno(stdin))); /* Returns 64 */ /* This call returns immediately. The stdin and stdout when the code gets to the actual reading, return isatty(fileno(x)) == 0 and so it uses the non terminal reading. */ PyRun_InteractiveLoop(stdin, "Opened Console"); Can anyone help me? I have no idea how to get Python to adopt the new stdin, stdout and stderr, but I have to assume it is pretty straightforward. Thanks. From wierob at gmx.de Wed Aug 10 07:14:26 2005 From: wierob at gmx.de (Robert Wierschke) Date: Wed, 10 Aug 2005 13:14:26 +0200 Subject: What is Python?! Message-ID: hi I'm learning python since 3 days. I' ve some programming experience in BASIC, Pascal, C, C++ and Java. Actually I want to add a scripting language to this repertoire (I have virtually no experience with scripting). Having read that python is object orientated, I start wondering if python is the right choice and what it is... a scripting language or a "normal" language like C++ etc. So please tell me what python is, what are it's strength, what is it good for and when should I use it and not one of the other languages. other questions: What about graphic? Can I create graphical interfaces with python? Python is interpreted but is it compiled to something like the java byte code or are there other ways to prevent the user to read my code? further hints for learning python and recommendations on books, tutorials, exampels, etc. are also welcome. thanks From tprimke at interia.pl Mon Aug 15 14:08:43 2005 From: tprimke at interia.pl (TPJ) Date: 15 Aug 2005 11:08:43 -0700 Subject: GUI tookit for science and education References: Message-ID: <1124129323.597444.103940@z14g2000cwz.googlegroups.com> Recently I was considering the choice of PyGTK or wxPython. They are both rich GUI libraries, and they both are cross-platform ones (well... they work on GNU/Linux and on Windows). I chose PyGTK, because it has *much* better documentation (I wasn't very happy when I had to look for information in documentation of wxPython - and lose a couple of hours - when I wanted to do something really simple...) and it seems to work stable on Windows. > Let's say someone has big amount of algorithms and > statistical models implemented in Pascal > (not well designed console apps). OT: I would recommend the use of Python + Numeric and, eventually, C (when the performance becomes really crucial). I'm working on genetic algorithms and - for now - the combination of Python and C was the best I got ever. In a few days I will run the first version of GAs implemented with Numeric. From steve at holdenweb.com Sat Aug 27 23:43:23 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Aug 2005 23:43:23 -0400 Subject: Cygwin font problems Message-ID: Is anyone aware of (a fix for) problems I'm having getting PIL 1.1.5 to create bitmaps using TrueType and openType fonts? When I create an image using the standard PIL fonts everything seems fine, but when I use ImageFont.truetype(, ) no text is drawn. setup.py reports from debug print statements that it's finding freetype21. The same code using (Fredrik's pre-built binary) on Windows runs correctly and produces correct images. Cygwin runs Python 2.4.1, Windows runs 2.4. Any light on this mystery gratefully received. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From philippe at philippecmartin.com Sat Aug 13 11:40:02 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sat, 13 Aug 2005 15:40:02 GMT Subject: How to find Python path in Visual C++ install wizard References: Message-ID: Thanks you all. As my software has python "executables" and libraries + c++ libs, the HKEY_LOCAL.... should be myt way out. Best regards, Philippe Philippe C. Martin wrote: > Hi, > > I realize this is not really a Python question but ... > > I am trying to setup an .msi for my software (Python code (.pyc) + > drivers) to make installation easier for Windows users. > > I am using the installer that comes with V. C++ 7.1. > > I would like to find the way to make sure Python is installed and then > copy automatically my files into its hierarchy. > > > PS: for many reasons, I do not wish to use setup.py. > > Best regards, > > Philippe From zen19725 at zen.co.uk Thu Aug 11 06:43:43 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Thu, 11 Aug 2005 11:43:43 +0100 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123697696.506898.66580@z14g2000cwz.googlegroups.com> <42fab7d0.1135118033@news.oz.net> Message-ID: On Thu, 11 Aug 2005 02:35:40 GMT, Bengt Richter wrote: >On Wed, 10 Aug 2005 20:39:03 +0100, zen19725 at zen.co.uk (phil hunt) wrote: >[...] >> >>I've not personally had problems with the wrong number of argumnets >>to a function call -- they get caught at run-time and are easy >>enough to fix -- but I do sometimes get errors because a varialbe is >>the wrong time, e.g. a string when it should be an int. >> >>One problem I once encountered was wit this and I waasn't picking it >>up because my debugging code looked like this: >> >> if debug: print "v=%s" % (v,) >> >>Which of course prints the same output whether v is '2' or 2. >> >>For this reason I tend to debug print statements like this now: >> >> if debug: print "v=%s" % (v,) > >I usually prefer %r over %s for debug prints > > if debug: print "v=%r" % (v,) Arrghh!! Yes, that's what I meant to write. -- Email: zen19725 at zen dot co dot uk From mark.a.brand at gmail.com Tue Aug 9 06:52:00 2005 From: mark.a.brand at gmail.com (mrelectron) Date: 9 Aug 2005 03:52:00 -0700 Subject: new python debugger Message-ID: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> hi: Nir Aides who wrote the rpdb debugger has enhanced it and stuck a frontend on it whoo-hoo. it is fantastico! see and download it at http://www.digitalpeers.com/pythondebugger/ cheers mark From peter at engcorp.com Mon Aug 22 11:45:42 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 11:45:42 -0400 Subject: sending binary files to a 16 micro controller. In-Reply-To: <1124725190.368311.306720@z14g2000cwz.googlegroups.com> References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <11gjn8k74pb6uc0@corp.supernews.com> <1124725190.368311.306720@z14g2000cwz.googlegroups.com> Message-ID: johnny.karlsson at gmail.com wrote: > I'm going to try the timed wait alternative, if i get it the > application to work properly i'll post the results in this group and > the code if anyone want's it. It's such a contrast to code a tcp-server > for the microcontroller (MC9S12NE64) in C and coding in python :-) I > really hope embedded python takes of again! You mean you wrote the TCP server in the micro in the first place? You must already know about its restrictions then and, more importantly, what it expects in the way of time delays and such. Also, couldn't you have supported UDP as well? It's simpler and on the PC side you can ensure that small packets are sent without being combined or any such monkey business. As for embedded Python, it's very unlikely any Python that might ever be shoe-horned into an HC12 is going to support enough of Python to make this a no-brainer. And Python doesn't itself provide the TCP stack, so even this wouldn't have helped. -Peter From the_bearded_oneder at yahoo.com Sun Aug 14 09:48:58 2005 From: the_bearded_oneder at yahoo.com (Alex) Date: Sun, 14 Aug 2005 13:48:58 GMT Subject: Jargons of Info Tech industry ... and Xah Lee (I mean Jerry) Springer In-Reply-To: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: Xah Lee wrote: > Jargons of Info Tech industry > > (A Love of Jargons) > > Xah Lee, 2002 Feb > > The jargon-soaked stupidity in computing field can be grouped into > classes ... One flagrant example is Sun Microsystem's > Java stuff ... fucking stupid Java and fuck Sun > Microsystems. This is just one example of Jargon hodgepodge of one > single commercial entity. > > The other class of jargon stupidity is from computing practitioners, of > which the Unix/Perl community is exemplary ... These types of > jargons exudes juvenile humor. Cheesiness and low-taste is their > hall-mark. > > There is another class of jargon moronicity, which i find them most > damaging to society, ... I think the reason for these, is that these > massive body of average programers usually don't have much knowledge of > significant mathematics, ... these people defining > or hatching terms ... are often a result of sopho-morons > trying to sound big. > ... Because most programers are > sopho-morons who are less capable of clear thinking but nevertheless > possess human vanity, ... > ... One can see that the term > ?closure? is quite vague in conveying its meaning. The term > nevertheless is very popular among talkative programers and dense > tutorials, precisely because it is vague and mysterious. These > pseudo-wit living zombies, never thought for a moment that they are > using a moronic term, ... (for an example of the > fantastically stupid write-up on closure by the Perl folks ... > ... > ... (one may think from the above tree-diagram > that Java the language has at least put clear distinction to interface > and implementation, whereas in my opinion they are one fantastic fuck > up too, in many respects.) > I've extracted the preceding castigating snippets from Mr. Lee's Jargon "thesis". :)) When reciprocated upon his own posts; one could offer up the proverb, "he who lives in glass houses should not throw stones." His inflammatory rhetoric - light on facts, weak in application, and generously peppered with self-aggrandizing insults - would probably offend Jerry Springer by comparison. Perhaps the "professor" should more carefully scrutinize himself before attempting to castigate others, less he acquire the reputation of a hypocrite, e.g. - "are often a result of sopho-morons trying to sound big."; "who are less capable of clear thinking but nevertheless possess human vanity"; "These types of jargons exudes juvenile humor."; "Cheesiness and low-taste is their hall-mark." Elementary courses in Critical Reasoning, Topical Research, Grammar, Creative Writing, and Technical Writing also seem warranted. A little one on one time with a mental health practitioner probably wouldn't hurt either. :)) P.S. Until then, does anyones else deem it appropriate to give "professor" Lee the nickname "Xah Lee Springer"? From http Sun Aug 7 00:21:08 2005 From: http (Paul Rubin) Date: 06 Aug 2005 21:21:08 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> Message-ID: <7xpssqv0ln.fsf@ruckus.brouhaha.com> Joseph Garvin writes: > >That's the second time in one or two days that I've heard Ruby on > >Rails mentioned. Can anyone here post a paragraph or two description? > >I sort of know what Ruby is, a very OOP-ified Perl-resemblant > >language, that's also implemented only as an interpreter. I can't see > >punting Python for it. > > > www.google.com Thanks but I wanted a more Pythonic point of view. From felix at keyremovethisghost.com Tue Aug 2 22:09:55 2005 From: felix at keyremovethisghost.com (Felix Collins) Date: Wed, 03 Aug 2005 14:09:55 +1200 Subject: HELP:sorting list of outline numbers In-Reply-To: References: Message-ID: Felix Collins wrote: > > Thanks Scott and Robert for your quick help. This list is amazing! > > Regards, > Felix Using Decorate, Sort , Undecorate... works like a charm. Thanks again. Felix From simon.brunning at gmail.com Wed Aug 17 04:50:46 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Wed, 17 Aug 2005 09:50:46 +0100 Subject: Need better way to unpack a list In-Reply-To: References: Message-ID: <8c7f10c6050817015037cc87ce@mail.gmail.com> On 8/17/05, Nx wrote: > I want to unpack a list into variables > the list is created at runtime and I do not know > how many items there will be , but I know not more than 25. > The list unpacks into variables which are prev. defined as > line1,line2....line25 which are actually the names of lineedit fields in > a Qt gui application and which need to be populated. > I currently use following to achieve that : > > c=0 > while c < len(mylinelist): > c = c + 1 > if c==1: > self.line1.setText(mylinelist[c]) > if c==2 : > self.line2.setText(mylinelist[c]) > . > . > . > if c==25: > self.line25.setText(mylinelist[c]) > > I rather have someting like > pseudo code follows: > > self.line+"c"+.setText(mylinelist[c]) > > How to do that ? Lift would be much easier if you held your 'linenn' lineedit fields in a list instead. Is that possible? If so, you could do something like (untested): for index, line in enumerate(mylinelist): self.lines[index].setText(line) -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From Dan_Patterson at sympatico.ca Fri Aug 19 10:03:39 2005 From: Dan_Patterson at sympatico.ca (Dan Patterson) Date: Fri, 19 Aug 2005 10:03:39 -0400 Subject: GIS Related Scripting Issue References: <21234D0B49BFB444AEB633CF9CAF2AC7172C98@tpc2003server> Message-ID: you might want to try http://forums.esri.com/forums.asp?c=93 and post in the geoprocessing section with code details "Fredrik Lundh" wrote in message news:mailman.3207.1124364723.10512.python-list at python.org... > Mike Rose wrote: > >> I am currently using ArcGIS 9.1 and was referred to this list to ask my >> question. I am using a python script to loop through a series of >> features, select all polygons that are within 5 miles, run statistics on >> those selected polygons, then append the values to a new database(dbf). >> I am not sure if I am going about this correctly or not, but my script > < is definitely not working. I am getting an error when it tries to >> append to the dbf. > > can you perhaps post the error message? > > > > From stygian at tesco.net Mon Aug 1 05:04:15 2005 From: stygian at tesco.net (glen) Date: Mon, 1 Aug 2005 10:04:15 +0100 Subject: Newb: Telnet 'cooked data','EOF' queries In-Reply-To: <42EDE2DA.5@tesco.net> References: <42EDE2DA.5@tesco.net> Message-ID: <200508011004.15533.stygian@tesco.net> > > Could someone explain what "cooked data" is. > discussed in the telnet RFC, which is in RFC854 telnetlib docstring. > "Cooked" data is data after these special sequences are removed. > >>'when' is an EOF received. > the only EOF in telnet is when the other side closes the socket. Thanks, thats got me started. From bokr at oz.net Thu Aug 11 21:07:59 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 12 Aug 2005 01:07:59 GMT Subject: Help sorting a list by file extension References: Message-ID: <42fbf3be.1215996460@news.oz.net> On Fri, 12 Aug 2005 00:06:17 GMT, Peter A. Schott wrote: >Trying to operate on a list of files similar to this: > >test.1 >test.2 >test.3 >test.4 >test.10 >test.15 >test.20 > >etc. > >I want to sort them in numeric order instead of string order. I'm starting with >this code: > >import os > >for filename in [filename for filename in os.listdir(os.getcwd())]: > print filename > #Write to file, but with filenames sorted by extension > > >Desired result is a file containing something like: >C:\MyFolder\test.1,test.001 >C:\MyFolder\test.2,test.002 >C:\MyFolder\test.3,test.003 >C:\MyFolder\test.4,test.004 >C:\MyFolder\test.10,test.010 >C:\MyFolder\test.15,test.015 >C:\MyFolder\test.20,test.020 > >I need to order by that extension for the file output. > >I know I've got to be missing something pretty simple, but am not sure what. >Does anyone have any ideas on what I'm missing? > >Thanks. > Decorate with the integer value, sort, undecorate. E.g., >>> namelist = """\ ... test.1 ... test.2 ... test.3 ... test.4 ... test.10 ... test.15 ... test.20 ... """.splitlines() >>> namelist ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20'] Just to show we're doing something >>> namelist.reverse() >>> namelist ['test.20', 'test.15', 'test.10', 'test.4', 'test.3', 'test.2', 'test.1'] this list comprehension makes a sequence of tuples like (20, 'test.20'), (15, 'test.15') etc. and sorts them, and then takes out the name from the sorted (dec, name) tuple sequence. >>> [name for dec,name in sorted((int(nm.rsplit('.',1)[1]),nm) for nm in namelist)] ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20'] The lexical sort, for comparison: >>> sorted(namelist) ['test.1', 'test.10', 'test.15', 'test.2', 'test.20', 'test.3', 'test.4'] This depends on the extension being nicely splittable with a single '.', but that should be the case for you I think, if you make sure you eliminate directory names and file names that don't end that way. You can look before you leap or catch the conversion exceptions, but to do that, you'll need a loop instead of a listcomprehension. >>> [name for dec,name in sorted((int(nm.split('.')[1]),nm) for nm in namelist)] ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20'] >>> sorted(namelist) ['test.1', 'test.10', 'test.15', 'test.2', 'test.20', 'test.3', 'test.4'] Regards, Bengt Richter From andy at mkaeurope.com Fri Aug 19 09:58:20 2005 From: andy at mkaeurope.com (Andy W) Date: Fri, 19 Aug 2005 13:58:20 GMT Subject: Adobe COM with Python In-Reply-To: References: Message-ID: <0AlNe.1502$jr4.1346@fe3.news.blueyonder.co.uk> What i want to do is use, python COM to fireup Adobe and print the pdf file to a printer. import win32com.client import pythoncom pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED) acro = win32com.client.DispatchEx('PDF.PdfCtrl.1') The above does not work, Do i need to install the SDK as well ? I'm new to this COM stuff as you can guess. Benjamin Niemann wrote: > Andy W wrote: > > >>I'm wanting to automate Adove Acrobat Reader using Com thru Python and >>win32com, but i can't find any documentation for the Adobe stuff? Has >>anyone done anything with Acrobat COM ? >> >>I've searched Google groups and the web but am unable to find anything. > > > I have not hacked Acrobat yet, but done a bit with InDesign - Adobe's > documentation is less than perfect, but still pretty good. You might look > at > > - in InDesign I could easily map the methods and attributes from the JS > documentation to COM calls (the JS members start with lowercase - e.g. > 'properties' -, while COM need uppercase - 'Properties'). > > From cmd at alephant.net Mon Aug 29 17:00:10 2005 From: cmd at alephant.net (Christopher DeMarco) Date: Mon, 29 Aug 2005 17:00:10 -0400 Subject: Python-list Digest, Vol 23, Issue 415 In-Reply-To: References: Message-ID: <20050829210010.GA15168@onion.alephant.net> On Mon, Aug 29, 2005 at 10:43:46PM +0200, python-list-request at python.org wrote: > Date: Mon, 29 Aug 2005 16:32:59 -0400 > To: python-list at python.org > From: Steve Holden > Subject: Re: NYC Opening > >THEY ARE LOCATED IN NEW YORK, THIS IS FULL-TIME ONLY, WILL NOT CONSIDER > >ANYONE FROM OUTSIDE THE US! THIS TEAM IS AN ELITE TEAM, YOU BETTER BE > >GOOD!!!! > It seems like this bank expects much more of its programmers than it > does of its recruitment consultants ... They've outsourced most of the work to Nigeria... PY7HON P.R.O.G.R.A.M.M.E.R.S DELIVERED DISCRETELY TO YOUR DOORSTEP -- Christopher DeMarco Alephant Systems (http://alephant.net) PGP public key at http://pgp.alephant.net +1 412 708 9660 From en.karpachov at ospaz.ru Wed Aug 17 06:16:25 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Wed, 17 Aug 2005 14:16:25 +0400 Subject: Embedding Python in C, undefined symbol: PyExc_FloatingPointError In-Reply-To: <1124260183.5033.15.camel@localhost.localdomain> References: <1124260183.5033.15.camel@localhost.localdomain> Message-ID: <20050817141625.41a8b82a.jk@ospaz.ru> On Wed, 17 Aug 2005 14:29:43 +0800 Simon Newton wrote: > The C program is being built like so: > > gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 > -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes > gcc main.o -L/usr/lib -lpthread -ldl -lutil > -lm /usr/lib/python2.4/config/libpython2.4.a -o main Try to link libpython as a library (as it should be), not as an object module: gcc main.o -L/usr/lib -lpthread -ldl -lutil -lm -lpython2.4 -o main -- jk From aisaac0 at verizon.net Sat Aug 13 16:24:43 2005 From: aisaac0 at verizon.net (David Isaac) Date: Sat, 13 Aug 2005 20:24:43 GMT Subject: Permutation Generator References: Message-ID: "Talin" wrote in message news:mailman.3042.1123875574.10512.python-list at python.org... > I wanted to share > this: a generator which returns all permutations of a list: Try this instead: def permuteg(lst): return ([lst[i]]+x for i in range(len(lst)) for x in permute(lst[:i]+lst[i+1:])) \ or [[]] Alan Isaac From grante at visi.com Tue Aug 30 10:26:55 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 30 Aug 2005 14:26:55 -0000 Subject: micro-python - is it possible? References: <431440bb$1@news.orcon.net.nz> Message-ID: <11h8r5f3r8gs7dd@corp.supernews.com> On 2005-08-30, Evil Bastard wrote: > Has anyone done any serious work on producing a subset of python's > language definition that would suit it to a tiny microcontroller > environment? No, not a tiny microcontroller environment. In the microcontroller world, "tiny" means 100 bytes of ram and 4KB of code space. OTOH, if you want to talk about medium-large uC stuff (hundreds of KB or RAM and code space), somebody did port and old version of Python to something like that. Google for "deeply embedded python". > Is it even possible to devise a tiny python subset that has at least > some of python's advantages, but at the same time can be compiled to > low-footprint resource-lean code? I doubt it. -- Grant Edwards grante Yow! I appoint you at ambassador to Fantasy visi.com Island!!! From alessandro.bottoni at infinito.it Thu Aug 18 12:32:14 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Thu, 18 Aug 2005 16:32:14 GMT Subject: New to python References: Message-ID: pcaro8a wrote: > I am new to python I am trying to install the numeric library and I > get the following error: > > error: Python was built with version 6 of Visual Studio, and > extensions need to > be built with the same version of the compiler, but it isn't installed. > > Do I need Visual Studio to make this work or is there any other reason > for this message? Well, the message is clear: the Python interpreter and PyNumeric were not built with the same version of the MS compiler. Did you get both of them from the same repository? Did you check the python version required by PyNumeric before installing it? If so, try to contact the PyNum people and ask for help. BTW: to fix this problem, you should either: 1) borrow a copy of VC6.X and (re)compile PyNumeric with it (or find someone that can do this for you on the Net. Do not look at me: I'm using Linux.) 2) compile both the Python interpreter and PyNumeric with the same compiler, using a compiler of your choice (as long as it is a supported ANSI C compiler) Given the open source nature of Python you _could_ download its source and recompile the interpreter with the compiler of your choice. You can do the same with its extensions. Unfortunately, as you can imagine, compiling the interpreter and its extension from their sources can be quite hard, in particular if you have to use a compiler other from the standard (MSVC on Windows, I think). Should you be forced to recompile your stuff, have a look at the www.python.org site and at the official documentation. You will find a section devoted to the task of compiling python from source with a list of the supported compilers (and have a experienced C programmer at hand, if possible). HTH ----------------------------------- Alessandro Bottoni From paul at boddie.org.uk Wed Aug 31 11:33:50 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 31 Aug 2005 08:33:50 -0700 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. References: Message-ID: <1125502430.504110.134500@f14g2000cwb.googlegroups.com> Alan Kennedy wrote: [PCW award to SpamBayes] > (PCW, for those who don't know it, is sort of the UK's equivalent of Byte Magazine, > except that it's still publishing after almost 25 years). Hmmm. Even Byte at its lowest point was far better than PCW ever was. [...] > The only problem was they listed the "manufacturer" of the software as > SourceForge, so the product was known as "SourceForge SpamBayes". PCW may still be publishing after 25 years (half the magazine being adverts probably keeps it just about economically viable), but they clearly haven't yet managed to shake off that classic 1980s mindset where "everything is a product by a company" (and, given the superficial understanding of software licensing still likely to be pervasive in the mainstream UK IT press, "everything else is public domain"). As for URLs and other things, last time I looked at the PCW Web site, it was all time-limited (or page-view-limited) viewing for non-subscribers. If British print distribution wasn't such a lock-in, I'd imagine PCW would have taken its place alongside Byte, staring at us from the print media fossil record. Paul From hancock at anansispaceworks.com Wed Aug 31 18:02:04 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 31 Aug 2005 17:02:04 -0500 Subject: Epydoc - Documenting class members? In-Reply-To: <20050831141106.GG2656@zoran.com> References: <20050831141106.GG2656@zoran.com> Message-ID: <200508311702.04363.hancock@anansispaceworks.com> On Wednesday 31 August 2005 09:11 am, Miki Tebeka wrote: > Is there a way to document class members in Epydoc? Yes. See additions below: > Something like: > > class Point: """ @ivar x: This is where you document x. @ivar y: This is where you document y. """ > def __init__(self, x, y): > '''Create new point > @param x: X coord > @param y: Y coord > ''' > self.x = x # How do I document here? > self.y = y # How do I document here? All of the fields are documented on the http://epydoc.sf.net website, by the way. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From pink at odahoda.de Wed Aug 24 07:23:11 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 24 Aug 2005 13:23:11 +0200 Subject: Warning when doubly linked list is defined gloablly References: <1124881914.018491.315800@g14g2000cwa.googlegroups.com> Message-ID: chand wrote: > Hi., > > In my api.py file 'g_opt_list' is defined globally > g_opt_list =[[],[],[],[],[],[],[]] > > I am using this global list in the fucntion > > def function (): > gloabl g_opt_list global? > when I run the py file, I am getting the Following Error > > SyntaxWarning: name 'g_opt_list' is used prior to global declaration > > Please let me know how to remove this error This happens in cases like >>> a = 1 >>> def c(): ... a ... global a Does your source only consist of the three lines above? (These would trigger a SyntaxError because of the typo...) You should provide a more complete example, so we can tell you where the problem is. Try to build a minimal file that reproduces the problem. Often you will find the line causing the error yourself - and the fix might be obvious to you -, if your strip stuff away. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From geskerrett at hotmail.com Tue Aug 9 13:29:14 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 9 Aug 2005 10:29:14 -0700 Subject: Does any one recognize this binary data storage format Message-ID: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> I am hoping someone can help me solve a bit of a puzzle. We are working on a data file reader and extraction tool for an old MS-DOS accounting system dating back to the mid 80's. In the data files, the text information is stored in clearly readable ASCII text, so I am comfortable that this file isn't EBCIDIC, however, the some of the numbers are stored in a format that we can't seem to recognize or unpack using the standard python tools (struct, binascii) ... or or atleast our understanding of how these tools work ! Any assistance would be appreciated. Here are a few examples of telephone numbers; Exmaple 1: Phone 1: 5616864700 Hex On Disk: C0DBA8ECF441 Phone 2: 5616885403 Hex on Disk: B0E9ADECF4F1 Another example: Phone 1: 8003346488 Hex On Disk: 800396d0fd41 Phone2: 9544261331 Hex On Disk: F8f50ec70142 Phone3: 9544278601 Hex On Disk: 481211c70142 TIA. From pydecker at gmail.com Thu Aug 18 21:49:05 2005 From: pydecker at gmail.com (Peter Decker) Date: Thu, 18 Aug 2005 21:49:05 -0400 Subject: Python jobs (was Re: Python for Webscripting (like PHP)) In-Reply-To: References: Message-ID: On 18 Aug 2005 10:58:46 -0700, Aahz wrote: > OTOH, the big sucking sound from Google and Yahoo (plus other places > like Ironport) is making it more difficult to hire Python programmers in > the Bay Area... Then start looking for telecommuting people. There are lots of us who can use work and have excellent telecommuting references, but who don't happen to live in a major metro area! -- # p.d. From billiejoex at fastwebnet.it Fri Aug 26 09:19:34 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Fri, 26 Aug 2005 15:19:34 +0200 Subject: Integrate C source in a Python project Message-ID: Hi all. I was wondering if it ispossible to integrate C source in a python project. Best regards From could.net at gmail.com Mon Aug 8 02:27:50 2005 From: could.net at gmail.com (could ildg) Date: Mon, 8 Aug 2005 14:27:50 +0800 Subject: How to determine that if a folder is empty? In-Reply-To: References: Message-ID: <311b5ce1050807232720527803@mail.gmail.com> Thank you . so you mean that this is not platform-independent? On 8/8/05, Neil Hodgson wrote: > could ildg: > > > I want to check if a folder named "foldername" is empty. > > I use os.listdir(foldername)==[] to do this, > > but it will be very slow if the folder has a lot of sub-files. > > Is there any efficient ways to do this? > > The first thing to do is measure the performance of this operation > in the context of your application to see if it is really worth extra > effort. > Tweaking this will depend on the platform. On Windows you can use > ctypes and the system functions FindFirstFile/FindNextFile/FindClose, > finishing once you see a single file. Directories always contain "." and > ".." entries so they should be ignored. On other platforms there will be > similar low level functions. > > Neil > -- > http://mail.python.org/mailman/listinfo/python-list > From martin at v.loewis.de Thu Aug 25 19:19:54 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 26 Aug 2005 01:19:54 +0200 Subject: pre-PEP: Object-oriented file module In-Reply-To: References: <430e4621$0$16867$9b622d9e@news.freenet.de> Message-ID: <430E521A.80107@v.loewis.de> Kenneth McDonald wrote: > Why would any of the issues below be any more difficult than they are with > the current file functions? I'm not proposing a C replacement for current > functions, merely a Python module that wraps all of those functions (and > adds some additional ones) in an appropriate class. I'm not saying they are difficult. I want to know how your library deals with them. There is a good chance that some of these questions remain unanswered in the PEP, and I just want to indicate that I would be unhappy if they are. Specifying this API is a huge task, much more so than coming up with an implementation that does "something". This is one of the reasons why nothing like this has made it to the standard library: as a library module, it would have to face many more scenarios that the authors of the module originally did not consider. Therefore, the documentation must be complete and consistent, and there should be an agreement as to what this library can do and what it cannot do. Regards, Martin From nephish at xit.net Sun Aug 21 17:15:15 2005 From: nephish at xit.net (nephish at xit.net) Date: 21 Aug 2005 14:15:15 -0700 Subject: question about binary and serial info In-Reply-To: <11gag9de4vgbu33@corp.supernews.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <43053b81$1@news.eftel.com> <11gag9de4vgbu33@corp.supernews.com> Message-ID: <1124658915.090253.168700@g47g2000cwa.googlegroups.com> Sorry i am late getting back on this. ord() is finally what is giving me what i wanted. the vendor told me that what was comming in was an ascii string representing hex characters. So i expected when i used the serial module that what i would be getting was something along the lines of 4A, 3D, etc.. but i got weird characters. So then (with the help of this very thread) discovered that i am reading raw bytes. i am supposed to validate the bytes as they come in because the message comes in four at a time. and i validate each byte like this var = (validation number) a = ser.read(1) x = ord(a) then to validate : x = (x & var) I am really sorry about the confusion. i am really new at this. but i am getting what i am supposed to now. i dont have the details on the script, because it is at work. but i will post it monday. thanks for everything. i would still be banging my head if not for this thread From borges2003xx at yahoo.it Fri Aug 26 05:52:16 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 26 Aug 2005 02:52:16 -0700 Subject: minimalist regular expression In-Reply-To: References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> Message-ID: <1125049935.989992.80290@z14g2000cwz.googlegroups.com> the shortest description in regex way From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 8 03:06:20 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 08 Aug 2005 09:06:20 +0200 Subject: IronPython 0.9 Released In-Reply-To: <11fdm9caa2p3h84@corp.supernews.com> References: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> <11fdm9caa2p3h84@corp.supernews.com> Message-ID: <3loejcF139eh3U2@individual.net> Al Christians wrote: > EP wrote: >> >> yes, my apologies to all things Iron and or Python. >> >> "language" and "version" can be confusing if one stays up late without coffee, or perhaps if one has not been debugging their English code properly. >> > > Still, it's a bit of a PITB to me that it says XP and not Win2000. Forcing you to upgrade, isn't it? Usual MS strategy. Reinhold From jeffrey.schwab at rcn.com Sun Aug 21 16:17:19 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sun, 21 Aug 2005 16:17:19 -0400 Subject: Gimp-Python In-Reply-To: References: Message-ID: danilo wrote: > > Salve, > > qualcuno sa se ? ancora in fase di sviluppo e qual'? il sito di > riferimento? > > Grazie > Danilo Gesundheit. From michele.simionato at gmail.com Thu Aug 25 04:23:57 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 25 Aug 2005 01:23:57 -0700 Subject: Externally-defined properties? In-Reply-To: References: Message-ID: <1124958237.296478.18630@f14g2000cwb.googlegroups.com> Well, I have used factories of properties external to the class many times, and they work pretty well. Michele Simionato From onurb at xiludom.gro Tue Aug 23 12:58:06 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 23 Aug 2005 18:58:06 +0200 Subject: split function In-Reply-To: References: Message-ID: <430b55a5$0$12417$626a14ce@news.free.fr> Mohammed Altaj wrote: > Dear All > > What i want to do is , my input is like > 0 2 > 0 3 > 0 4 > 1 2 > 1 4 > 2 3 > 3 4 > > I am comparing and put the number in group , like ,the first three lines > , all has zero as first input for each line, so the out put should look > like > 0 2 3 4 > and so on > 1 2 4 > 2 3 > 3 4 > > I managed to do what i need , but i did in this case , there is no space > between numbers , like > 02 > 03 > 04 > 12 > 14 > 23 > 34 > > so , how can i do this with spaces between numbers Remove them ? > This is my code Your code does not seems to work as expected. I get: 0 3 4 2 1 3 0 4 3 2 0 4 1 1 4 2 3 1 4 2 3 3 > > def belong_to(x,a): > c=-1 > for i in range(len(a)-1): > if x==int(a[i]): > c=i > return c def belong_to(x, line): for i, c in enumerate(line.strip()): if x == int(c): return i return -1 def belong_to(x, line): return line.find(str(x)) belong_to = lambda x, line: line.find(str(x)) Now, is it useful to define a function for such a trivial test ? > def list_belong(x,a): # This function to check if this line > c=-1 # line has been searched > before or not > for i in range(len(a)): > if a[i]==x: > c=1 > break > return c def list_belong(line, lines): return line in lines ... is it really useful to define a function for such a trivial test ? > x=0 > occur=[] > > in_file=open('data.dat','r') > out_file=open('result.dat','w') > fileList = in_file.readlines() > for k in fileList: > v=k > occur.append(k) > n=len(v)-1 > for i in range(n): > temp=int(v[i]) > print temp, > out_file.write(str(temp)) > for line in fileList: > if v!=line: > if list_belong(line,occur)!=1: > if belong_to(temp,line) != -1: > j=belong_to(temp,line) > for i in range(len(line)-1): > if i!=j: > print line[i], > out_file.write(line[i]) ouch :( > > print > out_file.write("\n") > > out_file.close() > in_file.close() > May I suggest a much more simple version that conform to your specs and solves the space problem ? from itertools import groupby in_file=open('data.dat','r') # strip EOLs and get rid of whitespaces lines = [line.strip().replace(' ', '') for line in_file.readlines()] in_file.close() out_file=open('result.dat','w') # group lines by first char for key, groups in groupby(lines, lambda line: line[0]): buf = "%s %s" % (key, " ".join([group[1] for group in groups])) print buf out_file.write("%s\n" % buf) out_file.close() Python is meant to make your life easier... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From jburgy at gmail.com Fri Aug 5 07:53:34 2005 From: jburgy at gmail.com (jburgy) Date: 5 Aug 2005 04:53:34 -0700 Subject: Parallel arithmetic? References: <42f298d6$1_5@alt.athenanews.com><42f2c81a$1_3@alt.athenanews.com> Message-ID: <1123242814.509996.137890@g44g2000cwa.googlegroups.com> Dennis Lee Bieber wrote: > On Thu, 04 Aug 2005 20:59:33 -0500, "Terrance N. Phillip" > declaimed the following in > comp.lang.python: > > > Thank-you very much for all the excellent replies. I'm thinking of using > > this to determine if a sequence is a "run" (as in a card game). If I've > > got a sorted hand [3, 4, 5, 6, 7], then I know I've got a 5-card run > > A sorted list? > > if (hand[-1] - hand[0]) == (len(hand) - 1) > > would seem to do it for your example. > > Actually, if you KNOW the list is only 5 entries long > > if (hand[4] - hand[0]) == 4 > It's cute but wrong! How 'bout hand = [ 0, 0, 0, 4 ]? It's sorted, passes your test and does not meet the OP's requirement :( > would do it. > > Or any equivalent... (hand[0] + 4) == hand[4] > > > -- > > ============================================================== < > > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > > wulfraed at dm.net | Bestiaria Support Staff < > > ============================================================== < > > Home Page: < > > Overflow Page: < From EP at zomething.com Fri Aug 5 05:08:34 2005 From: EP at zomething.com (EP) Date: Fri, 5 Aug 2005 01:08:34 -0800 Subject: IronPython 0.9 Released In-Reply-To: References: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> Message-ID: <20050805010834.1316716405.EP@zomething.com> > I've got both 1.1 and 2.0 on this machine... Note that the > warning applies to /language/: as in English or French... You can not > install French if you have an English version installed. > yes, my apologies to all things Iron and or Python. "language" and "version" can be confusing if one stays up late without coffee, or perhaps if one has not been debugging their English code properly. From peter at somewhere.com Thu Aug 25 09:47:37 2005 From: peter at somewhere.com (Peter Maas) Date: Thu, 25 Aug 2005 15:47:37 +0200 Subject: variable hell In-Reply-To: <430dc538@127.0.0.1> References: <430dc538@127.0.0.1> Message-ID: Nx schrieb: > Hi > > I am unpacking a list into variables, for some reason they need to be > unpacked into variable names like a0,a1,a2....upto aN whatever is > in the list. > > How to create the variables dynamically ? > > I am looking for something like > pseudo code line follows : > > a%s = str(value) >>> suffix = 'var' >>> vars()['a%s' % suffix] = 45 >>> avar 45 -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From enleverlesO.OmcO at OmclaveauO.com Sun Aug 28 02:59:49 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Sun, 28 Aug 2005 08:59:49 +0200 Subject: Windows/win32all, unicode and long filenames References: Message-ID: <43116496$0$999$8fcfb975@news.wanadoo.fr> Hi ! You are true. But, more, don't believe : for use with CD-Rom/DVD, a path cannot to have more than 64 caracteres. @-salutations Michel Claveau From deets at web.de Thu Aug 18 17:44:44 2005 From: deets at web.de (Diez B. Roggisch) Date: 18 Aug 2005 14:44:44 -0700 Subject: Really virtual properties In-Reply-To: <87slx7c4g5.fsf@wilson.rwth-aachen.de> References: <87slx7c4g5.fsf@wilson.rwth-aachen.de> Message-ID: <1124401484.405687.119030@g43g2000cwa.googlegroups.com> I don't think so - the reason is that property() is evaluated in the baseclass, and stores a callable, not a name. the only thing you could do is either - create a level of indirection, using lambda, to force the lookup: x = property(lamda self: self.get_x()) - use a metaclass, that tries to scan the baseclass for properties that uise functionnames which are redefined in the current class, and recrerate a new property for those. Diez From zen19725 at zen.co.uk Wed Aug 3 07:40:00 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 12:40:00 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: Message-ID: On Tue, 2 Aug 2005 12:53:29 +0100, Tim Golden wrote: >[Michael Sparks] >| Phil Hunt wrote: >| >| > Kamaelia seems it might be an interesting project. However, I don't >| > think the project is well served by this announcement -- which I >| > find vague and hard to understand. Which is a shame, because it >| > means that other people probably don't understand it very well >| > either, which means less people will use it. >| >| It is a shame, and thanks for mentioning this. Let me have another >| go :-) (ripping to shreds welcome :) >| >| OK, here's a better go. (It's always difficult to think where to pitch >| this sort of thing) > >[... snip ...] > >I just wanted to say that I find the ideas behind Kamaelia >interesting, and I only wish I had an application for it! >Because I'm not especially into media-streaming, I'm more >interested in it from the point of view of the generator-based >architecture. > >What prompted me to write now was in appreciation of Michael's >taking the effort to recast his words into a form which might >well be understood better by others (including me) when he >might well have simply huffed a bit and told the other poster >to read the words on the site and stop complaining about the HTML! I'd second that! I'm not trying to be critical, honestly, I'm trying to understand something that looks like it could be very cool indeed. (And on a more general level to improve the average quality of documentation for open source projects. Something which is bvery often deficient.) -- Email: zen19725 at zen dot co dot uk From jbar at hosting4u.cz Wed Aug 10 06:40:54 2005 From: jbar at hosting4u.cz (Jiri Barton) Date: Wed, 10 Aug 2005 12:40:54 +0200 Subject: Why is this? Message-ID: Hi everyone, I have a problem with initialization. >>> a, b = [[]]*2 >>> a.append(1) >>> b [1] Why is this? Why does not this behave like the below: >>> a, b = [[], []] >>> a.append(1) >>> b [] And, just to add to my confusion: >>> [[]]*2 [[], []] >>> [[], []] == [[]]*2 True Thanks in advance for the explanation. jbar BTW, if it matters... Python 2.4.1 (#2, Mar 30 2005, 20:41:35) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 From mwm at mired.org Mon Aug 22 14:24:13 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 22 Aug 2005 14:24:13 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <1bghg15apbvjaucj8liqkgghnlmsjm1h5a@4ax.com> Message-ID: <867jedq182.fsf@bhuda.mired.org> Dennis Lee Bieber writes: > On Sat, 20 Aug 2005 22:30:43 -0400, Mike Meyer declaimed > the following in comp.lang.python: >> with these issues. If I ever find myself having to have non-trivial >> threads again, I'll check the state of the threading models in other >> languages, and make a serious push for implementing parts of the >> program in a less popular language with a less primitive threading >> model. > The June edition of "SIGPLAN Notices" (the PLDI'05 proceeding issue) > has a paper titled "Threads Cannot Be Implemented As a Library" -- which > is primarily concerned with the problems of threading being done, well, > via an add-on library (as opposed to a native part of the language > specification: C#, Ada, Java). Thanks for the reference. A litte googling turns up a copy published via HP at . > I suspect Python falls into the "library" category. Well, that's what it's got now, so that seem likely. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From Scott.Daniels at Acm.Org Mon Aug 22 15:12:01 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Aug 2005 12:12:01 -0700 Subject: Error with Python In-Reply-To: References: Message-ID: <430a1791$1@nntp0.pdx.net> Robert wrote: > Hello > > I have created a tool in Python 2.3 under WinXP > Now I extended this tool and now my tool makes Python crash. I see Dr Watson > showing a stacktrace. > This tool also uses wxPython. > > Dr Watson says: > AppName: python.exe > AppVer: 0.0.0.0 > ModName: python23.dll > ModVer: 2.3.5150.1012 > Offset: 0003736a > > The stacktrace is very long and I don't know how to copy and paste it, > because it cannot be selected. (I have made some screenshots) > > Python crashes as I can see from my tools log file, when the tool is > handling messages on the Queue object. My tool is multi threaded and unsing > Queue to send messages between threads and the main GUI thread. > > My questions now are: > - can I get some help from somebody on this problem (is Python 2.3 > supported)? > - how do I find out if this is Python or wxPython related problem? > - which information or tool could help me to search for the problem myself? > - do I have to be the absolute Python guru to find the problem or is it > enough to know programming a little bit? > - where to start? > > > I would change to Python 2.4 but then I have also to change to new wxPython > and this is a big migration effort (I have tried already). > > Hope someone can give me some hints... > > Regards > > Robert > > You could ask about this on the wxPython mailing list (accessible as news:gmane.comp.python.wxpython), and if it important enough to you, offer a bounty for help reflecting its importance to you. --Scott David Daniels Scott.Daniels at Acm.Org From daniel.dittmar at sap.corp Mon Aug 1 12:56:28 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Mon, 01 Aug 2005 18:56:28 +0200 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> Message-ID: Cliff Wells wrote: > I can understand this, but from my experience, their concerns are badly > misplaced: I recently wrote a fairly sizable Python app (~8K LOC) that > utilized several 3rd party python librarys: wxPython, Twisted, > FeedParser, DateUtils and SQLite to name a few off the top of my head > (plus I had to repackage libxml and libxslt on OS/X because 10.3 ships > with broken versions :P). > > It ran on Windows and OS/X (and Linux, but that was never deployed as > the customer wasn't interested). This was for a *very* large customer > and made it to nearly 10,000 desktops. Not one complaint had to do with > installation of 3rd party packages. Why? Because I *packaged* it for Actual success stories like this one are often more convincing than general remarks about how any problem is solvable, given enough effort. > In short, these people's complaints reveal only two things: 1) they are > hopelessly pessimistic, whether out of pure laziness, lack of experience It might be very specific experiences. Many people using third party controls with Visual Basic got burned. > endeavor. As I mentioned earlier, programming is half brains and half > tenacity. I'd add a bit of gambling, because often, you don't have enough information. Telling what works from your experience adds useful information so that the brain can decide where to invest the tenacity. Daniel From noway at sorry.com Sat Aug 20 15:48:30 2005 From: noway at sorry.com (Giovanni Bajo) Date: Sat, 20 Aug 2005 19:48:30 GMT Subject: pythonXX.dll size: please split CJK codecs out Message-ID: Hello, python24.dll is much bigger than python23.dll. This was discussed already on the newsgroup, see the thread starting here: http://mail.python.org/pipermail/python-list/2004-July/229096.html I don't think I fully understand the reason why additional .pyd modules were built into the .dll. OTOH, this does not help anyone, since: - Normal users don't care about the size of the pythonXX.dll, or the number of dependencies, nor if a given module is shipped as .py or .pyd. They just import modules of the standard library, ignoring where each module resides. So, putting more modules (or less modules) within pythonXX.dll makes absolutely no differences for them. - Users which freeze applications instead are *worse* served by this, because they end up with larger programs. For them, it is better to have the highest granularity wrt external modules, so that the resulting freezed application is as small as possible. A post in the previous thread (specifically http://mail.python.org/pipermail/python-list/2004-July/229157.html) suggests that py2exe users might get a small benefit from the fact that in some cases they would be able to ship the program with only 3 files (app.exe, python24.dll, and library.zip). But: 1) I reckon this is a *very* rare case. You need to write an application that does not use Tk, socket, zlib, expat, nor any external library like numarray or PIL. 2) Even if you fit the above case, you still end up with 3 files, which means you still have to package your app somehow, etc. Also, the resulting package will be *bigger* for no reason, as python24.dll might include modules which the user doesn't need. I don't think that merging things into python24.dll is a good way to serve users of freezing programs, not even py2exe users. Personally, I use McMillan's PyInstaller[1] which always builds a single executable, no matter what. So I do not like the idea that things are getting worse because of py2exe: py2exe should be fixed instead, if its users request to have fewer files to ship (in my case, for instance, this missing feature is a showstopper for adopting py2exe). Can we at least undo this unfortunate move in time for 2.5? I would be grateful if *at least* the CJK codecs (which are like 1Mb big) are splitted out of python25.dll. IMHO, I would prefer having *more* granularity, rather than *less*. +1 on splitting out the CJK codecs. Thanks, Giovanni Bajo [1] See also my page on PyInstaller: http://www.develer.com/oss/PyInstaller From john at castleamber.com Mon Aug 29 17:12:13 2005 From: john at castleamber.com (John Bokma) Date: 29 Aug 2005 21:12:13 GMT Subject: Jargons of Info Tech industry References: <3n6kkjF4qppU1@individual.net> <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> Message-ID: Alan Balmer wrote: > On 29 Aug 2005 18:21:12 GMT, John Bokma wrote: > >>Alan Balmer wrote: >> >>> Why on earth was this cross-posted to comp.lang.c.? Followups set. >> >>Your reply is even more meaningless and more noise compared to the >>crosspost. Why? You didn't add anything, you quote an entire message and >>you just tweaked the follow up to header in a bad way. > > My aim was simply to get it the hell off c.l.c as quickly as possible. So you edited that one out, and decided to bother all other groups with your ineffective attempt? > Now, go away. And please, stay away. Like I already said, it doesn't work that way. The only way to make an follow up effective is to write a useful contribution to the thread, and set the follow up to the most appropriate group (and keep your fingers crossed). Not what you did, moreover you only add noise instead of removing it. Ignore the thread, it will end in 2-3 days. If you keep feeding it your way it will become more and more off topic and last 5-10 days. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From tompa1969 at yahoo.com Sun Aug 28 16:09:10 2005 From: tompa1969 at yahoo.com (Tompa) Date: Sun, 28 Aug 2005 20:09:10 +0000 (UTC) Subject: Dynamic image creation for the web... References: <1125226041.6362.241637673@webmail.messagingengine.com> Message-ID: Richard Lewis fastmail.co.uk> writes: > It would be useful to know what web server software you're using. I intended to add that info but forgot... I run IIS on W2K, python 2.4.1 and PIL 1.1.5. > The other thing you may need to check is the HTTP header of the > generated image. If possible I'd rather separate the HTTP/HTML-stuff from image creation. I'd like to have an HTML file that refers to a py-file that creates images which are returned somehow (sys.stdout or something else in memory) and incorporated within the HTTP-response. > It should be possible to create an HTTP response from > your create_image.py script (as opposed to just an image) with a MIME > type of image/jpeg and manually insert the binary image data in the > response body... Yes, I believe so too. Something like this, as suggested by Benjamin: sys.stdout.write('Status: 200 OK\r\n') sys.stdout.write('Content-type: image/gif\r\n') sys.stdout.write('\r\n') im.save(sys.stdout, "GIF") But it does not work for some reason!? Besides, I was hoping for a solution which could skip the HTTP-header related stuff... Regards, /Tompa From fredrik at pythonware.com Thu Aug 25 09:38:41 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 25 Aug 2005 15:38:41 +0200 Subject: RE Despair - help required References: <430d8883@news.bezeqint.net> Message-ID: "Yoav" wrote: >I am trying the following: > > re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") > > and I get a return of NoneType, and I have no idea why. I know that I > missing something here, but I really can't figure out why instead of struggling with weird REs, why not use Python's standard filename manipulation library instead? http://docs.python.org/lib/module-os.path.html From bokr at oz.net Tue Aug 16 14:10:36 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 16 Aug 2005 18:10:36 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <4302228e.1621136831@news.oz.net> On Sat, 06 Aug 2005 20:56:13 GMT, Dennis Lee Bieber wrote: >On Sat, 06 Aug 2005 21:16:13 +0200, Paolino >declaimed the following in comp.lang.python: > > >> The point is not to understand obvious technical things, but having a >> coherent programming framework.If I can modify an out of scope object > > Seems coherent to me: > >a) names /BIND/ locally unless declared global (at which point they >bind within the file) > >b) name /lookup/ is local first, then global > >c) conflict occurs when a name lookup potentially could find a >global [clause b: name not found in local space, found in global], but >later in the same function that same name is bound locally [clause a: no >global declaration was seen so binding is to a local]. However, the >static language parse will have flagged the name as reserved for a >local, and then complains because one is attempting to use a local >before it has been bound to a value. > > If you aren't changing the binding of the name, you don't need >to worry about "global" > > And, in Python, this concept of BINDING is a core language >feature -- it is NOT something compatible to other languages, and >removing it will mean creating a new language that is NOT Python. > > In other languages, a "name" is a synonym for a memory address >(call it a box), and it will always be the same box. Assignment copies >box contents from source to destination box. > > In Python, a "name" is a movable label that is stuck to a box, >and the name can be moved to other boxes. "Assignment" in Python moves >the label from the "destination" (the old box) TO the "source" box -- >the source box now has multiple labels (names) bound to it. Both names >refer to the same box. > > var[i] is a two step process: first find the box with the label >"var", THEN open the box and find the i'th item /in/ the box... You can >change the item /in/ the box without changing the label on the box. > I find the above label/box metaphor a bit misleading, because the "box" surfaces where "labels" may be stuck are name spaces, and IMO are more like cork bulletin boards than the containers suggested by "box" (although admittedly a bulletin board could be viewed as a kind of container for labels ;-) I prefer the name-tags-with-strings metaphor, where name tags may be pinned on any namespace/bulletin board and the strings from tags on many different bulletin boards may be tied to (bound) the same object. But to carry this a little further, name tags aren't really the only things that have strings that lead to objects. Name tags's strings are accessed via name space objects' lookup mechanisms, which we program with various name lookup syntax, but other objects can also have strings leading to objects, e.g. lists, where you retrieve a string originating from the nth string-tying-point instead of finding a string-tying-point by name amongst a bunch of labels pinned to a bulletin board. IOW, "...open the box and find the i'th item /in/ the box..." is not really finding the i'th item _itself_ "/in/" the box. It is finding one end of a string tied to some point /in/ the box, but the actual item/object is at the other end of the string, not /in/ the box, and many other strings may potentially also be leading to the same object, whether originating from anonymous structural binding points in other objects, or named binding points in name-tag-containing objects/namespaces. Regards, Bengt Richter From steven.bethard at gmail.com Thu Aug 18 22:29:43 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 18 Aug 2005 20:29:43 -0600 Subject: dict duplicity In-Reply-To: References: Message-ID: <9MKdnXoVNe2F2ZjeRVn-sg@comcast.com> Randy Bush wrote: > for pKey, pVal in dict.iteritems(): > print \ > pKey[0], hash(pKey[0]), \ > pKey[1], hash(pKey[1]), \ > pKey[2], hash(pKey[2]), \ > "hash=", hash(pKey), \ > pVal[0], hash(pVal[0]), \ > pVal[1], hash(pVal[1]) > > when run with | sort, produces > > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 > > not that there are two entries with the same hash= Whatever the hash function is for your keys, it returns the same value for two different keys. A simple example of this kind of phenomenon: py> class C(object): ... def __hash__(self): ... return 1 ... py> c1, c2 = C(), C() py> d = {c1:1, c2:2} py> for key, value in d.iteritems(): ... print hash(key), key, value ... 1 <__main__.C object at 0x0126CCD0> 1 1 <__main__.C object at 0x012739D0> 2 Note that the hashes are the same. But are the objects the same? py> c1 == c2 False Nope. (This is because the default __eq__ method compares the ids of the two objects, and as you can see, they have different ids.) The point is this: you can have multiple objects in the same dict that have the same hash(), as long as none of those objects equals another. For more information, see: http://wiki.python.org/moin/DictionaryKeys STeVe From kay.schluehr at gmx.net Wed Aug 31 15:03:35 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 Aug 2005 12:03:35 -0700 Subject: Epydoc - Documenting class members? References: Message-ID: <1125515015.559158.326170@g44g2000cwa.googlegroups.com> This should help: http://epydoc.sourceforge.net/fields.html Kay From steve at holdenweb.com Mon Aug 22 22:10:03 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 22:10:03 -0400 Subject: Python Light Revisted? In-Reply-To: References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: Bryan wrote: >>Someone recently produced a distribution capable of running from a CD >>and designed to make it easy to use Python on machines where it wasn't >>actually installed. That might be a useful starting point too, but I >>can't find the right incantation to get Google to bring it up. >> >>regards >> Steve > > > steve, > > are you thinking about moveable python? > > http://www.voidspace.org.uk/python/movpy/ > The very one, thanks. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From deets at nospam.web.de Mon Aug 22 18:35:43 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Aug 2005 00:35:43 +0200 Subject: Sanitizing untrusted code for eval() In-Reply-To: <430a1a45$1@nntp0.pdx.net> References: <3muhfnF18o689U1@uni-berlin.de> <430a1a45$1@nntp0.pdx.net> Message-ID: <3mv2a0F18cpprU1@uni-berlin.de> > Another thing you can do is use the compile message and then only allow > certain bytecodes. Of course this approach means you need to implement > this in a major version-dependent fashion, but it saves you the work of > mapping source code to python. Eventually there will be another form > available (the AST form), but that will show up no earlier than 2.5. > As a matter of pure practicality, it turns out you can probably use > almost the same code to look at 2.3 and 2.4 byte codes. I don't know much about python byte code, but from the JASON-HP - which features the grammar for JASON on the first page - I'm under the strong impression that abusing the python parser by whatever means, including the byte-code ahck you propse, is way more complicated than writing a small parser - I don't know pyparsing, but I know spark, and it would be a matter of 30 lines of code. And 100% no loopholes... Additionally, having a parser allows you to spit out meaningful errors - whilst mapping byte code back to input lines is certainly not easy, if feasible at all. Regards, Diez From joe at invalid.address Thu Aug 25 13:24:36 2005 From: joe at invalid.address (joe at invalid.address) Date: 25 Aug 2005 12:24:36 -0500 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: "Mike Schilling" writes: > "Rich Teer" wrote in message > news:Pine.SOL.4.58.0508250932360.5888 at zen.rite-group.com... > > On Thu, 25 Aug 2005, Mike Schilling wrote: > > > >> Another advantage is that evewry internet-enabled computer today > >> already comes with an HTML renderer (AKA browser), so that a > >> message saved to a file can be read very easily. > > > > I think you're missing the point: email and Usenet are, > > historically have been, and should always be, plain text mediums. > > Gosh, if you say they should be, there's no point trying to have an > intelligent discussion, is there? Errm, isn't that what you're doing as well then? Rich just gave an opinion, you've been giving an opinion. Rich's opinion happens to have a lot of history and good reasons behind it. I don't see why it should be viewed as some kind of discussion ending dogmatism. Although it might not be bad if this discussion ended :-) Joe From spammers-go-here at spam.invalid Mon Aug 8 00:51:25 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Mon, 08 Aug 2005 00:51:25 -0400 Subject: Embedding a runtime graph in Qt3 designer generated UI Message-ID: <42f6e4c8$0$18646$14726298@news.sunsite.dk> Hi Two questions : 1. Is it possible to use an import command in a qt3 designer code ? (I know that it is possible to write python inside the braces -- but is it possible to use an import command for some rather large libraries I wrote that I need to access ?). 2. In the same vein, how does one embed a runtime plot in a qt3 UI ? It will need to be a python solution since I am using python libraries to acquire the data. From rkern at ucsd.edu Fri Aug 5 07:45:18 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 05 Aug 2005 04:45:18 -0700 Subject: Some question about setuptools module In-Reply-To: <505f13c05080504272fdaa303@mail.gmail.com> References: <505f13c05080504272fdaa303@mail.gmail.com> Message-ID: limodou wrote: > I'm sorry may be this letter is not suit for this maillist. You'll get better help on the Distutils-SIG list. http://mail.python.org/mailman/listinfo/distutils-sig/ Phillip Eby hangs out there for the care and feeding of setuptools adopters. -- 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 mwm at mired.org Sat Aug 27 21:17:34 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 27 Aug 2005 21:17:34 -0400 Subject: Writing portable applications (Was: Jargons of Info Tech industry) References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> Message-ID: <86u0hauafl.fsf@bhuda.mired.org> Rich Teer writes: > On Sat, 27 Aug 2005, Mike Meyer wrote: >> I think you're right - a web standard designed for writing real >> applications probably wouldn't start life as a markup for text. The >> only thing I can think of that even tries is Flash, but it's > What about Java? Using HTML, I can build applications that work properly on anything from monochrome terminals to the latest desktop box. Is there a UI toolkit for Java that's that flexible? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jack at performancedrivers.com Wed Aug 10 12:10:15 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 10 Aug 2005 12:10:15 -0400 Subject: Module Extension C/CPI Question In-Reply-To: <1123636517.6746.10.camel@localhost.localdomain> References: <1123636517.6746.10.camel@localhost.localdomain> Message-ID: <20050810161015.GG1365@performancedrivers.com> On Tue, Aug 09, 2005 at 09:15:17PM -0400, Jeremy Moles wrote: > When using the C API and writing extension modules, how do you normally > pass a structure up into the python module? For instance, if I have a > structure: > > typedef struct Foo { > int x; > int y; > int z; > char xyz[100]; > } Foo; > > Is there an "accepted" way of propagating this upstream? I was thinking > one of these two: > > 1. Returning a enormous tuple of the struct's members using > Py_BuildValue("(iiis)", f.x, f.y, f.z, f.xyz) which would later be > converted to a similar object in Python for clients of my module to use. > > 2. Creating a PyObject and calling PyObject_SetAttrString(O, "x", > Py_BuildValue("i", f.x)) for each member, finally returning a generic > PyObject using the "O" flag in BuildValue. > The easiest thing to do is to return a dictionary myd = PyDict_New(); assert(myd != NULL); PyDict_SetItemString(myd, "x", PyInt_FromLong((long)mystruct->x)); PyDict_SetItemString(myd, "y", PyInt_FromLong((long)mystruct->y)); PyDict_SetItemString(myd, "z", PyInt_FromLong((long)mystruct->z)); return myd Creating a full fledged object by hand isn't hard and if you are accessing a lot of these it is worth it (instead of creating new dictionaries all the time). But try this first as a quick and dirty, upgrade to a full object if it is still too slow. To see examples of C objects check the python source under Objects/ http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Objects/ (warning, SourceForge CVS is currently being upgraded and is flaky) HTH, -jackdied From mvanaswegen at gmail.com Wed Aug 24 07:01:36 2005 From: mvanaswegen at gmail.com (vpr) Date: 24 Aug 2005 04:01:36 -0700 Subject: slip beta code released In-Reply-To: <1124874627.194019.282930@g47g2000cwa.googlegroups.com> References: <1124874627.194019.282930@g47g2000cwa.googlegroups.com> Message-ID: <1124881296.562997.265380@g47g2000cwa.googlegroups.com> I forgot to say that this is my little P2P pet project. Need to send files quickly between systems without having to set up shares or start ftp servers. The idea is to make it easy to "slip" files between parties esp if they are on different OS's. From geskerrett at hotmail.com Wed Aug 24 07:54:53 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 24 Aug 2005 04:54:53 -0700 Subject: Anyone recognize this numeric storage format - similar to "float", but not quite In-Reply-To: <430c3fc2.2283972098@news.oz.net> References: <1124849085.656718.97720@g43g2000cwa.googlegroups.com> <430c3fc2.2283972098@news.oz.net> Message-ID: <1124884493.341359.148450@g44g2000cwa.googlegroups.com> Thanks Bengt for directing me to your previous post. I think I agree with you on the "reversing bit" and the constant MSB. In reworking my examples I was always changing the 0 to 1. From steve at holdenweb.com Wed Aug 31 22:20:42 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Aug 2005 21:20:42 -0500 Subject: change date format In-Reply-To: <1125533583.606398.5770@g43g2000cwa.googlegroups.com> References: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> <200508311236.49648.lars@gustaebel.de> <1125533583.606398.5770@g43g2000cwa.googlegroups.com> Message-ID: alex23 wrote: > Fredrik Lundh wrote: > >>perhaps, but why is he posting apache questions to the python list? > > > The real question is why is he asking for our help at all, given: > > Xah Lee wrote: > >>Fuck the Python programing morons. > He isn't asking for help. He's simply masturbating. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From captainkoala at gmail.com Sat Aug 27 13:39:03 2005 From: captainkoala at gmail.com (captainkoala at gmail.com) Date: 27 Aug 2005 10:39:03 -0700 Subject: fontifying a pattern in a Tkinter Text widget Message-ID: <1125164343.761645.226710@g44g2000cwa.googlegroups.com> Hi, I'm writing a program which needs to change various format features of a specific pattern ("remote_user" for example) withing a Text widget. This pattern could potentially be anywhere within the widget. I'm unsure of how to implement the various tag methods, so a little push in the right direction would be greatly appreciated. Thanks -Andrew From claudio.grondi at freenet.de Thu Aug 25 19:10:55 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Thu, 25 Aug 2005 23:10:55 -0000 Subject: Speed quirk: redundant line gives six-fold speedup References: <430E0C8D.5000506@ceid.upatras.gr> <20050825182936.GE5991@performancedrivers.com> Message-ID: <3n6qh2F5igjU1@individual.net> > I've learnt my lesson :) Thank you for your help, and apologies > for wasting other people's time with this as well as my own! I've learnt my lesson reading through this thread, too. I am glad to be given the chance of wasting my time with it and very happy and thankful, that you posted your problem here before I have bumped into similar one myself. I suppose, that there are many others on this newsgroup who appreciated your posting, too. Claudio From prabapython at yahoo.co.in Wed Aug 24 04:04:06 2005 From: prabapython at yahoo.co.in (praba kar) Date: Wed, 24 Aug 2005 09:04:06 +0100 (BST) Subject: Reg Python Modules/Packages In-Reply-To: Message-ID: <20050824080406.78072.qmail@web8406.mail.in.yahoo.com> Dear All, I know how to use modules. But I want to know how to create package. Can any one let me know how to write package through small specimen code. regards PRabahar ____________________________________________________ Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html From berlin.brown at gmail.com Thu Aug 11 19:49:49 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Thu, 11 Aug 2005 19:49:49 -0400 Subject: The python license model In-Reply-To: References: Message-ID: Ramza Brown wrote: > Can you distribute a python system with only a couple of libraries that > you plan to use. For example, I generally avoid having a system with > hundreds of loose scripts(ie python library). So, I have considered > only taking the libraries I need. My question, is python license > friendly for doing this? > > I haven't worked with 'egg' too much. > Also, are there any articles for distributing python applications without the default python install. -- Ramza from Atlanta http://www.newspiritcompany.com From ray_usenet at yahoo.com Sat Aug 20 05:34:24 2005 From: ray_usenet at yahoo.com (Ray) Date: 20 Aug 2005 02:34:24 -0700 Subject: Please Criticize My Code In-Reply-To: References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> Message-ID: <1124530464.953087.134280@z14g2000cwz.googlegroups.com> Michael Hoffman wrote: > Ray wrote: > > > I just wrote a short script that generates look and say sequence. What > > do you Python guys think of it? Too "Java-ish"? > > Yes, but that's beside the point. :) Well... I'm always paranoid that I'm, you know, writing Java in Python :) Thanks for the examples! That last one took me a while to understand. I like the way you approach it though (e.g.: going after clarity first instead of shortness). Cheers Ray From sjmachin at lexicon.net Thu Aug 18 18:55:23 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 08:55:23 +1000 Subject: up to date books? In-Reply-To: References: Message-ID: <430511db$1@news.eftel.com> Alessandro Bottoni wrote: > > > Python did not changed too much since rel. 1.5. I presume by "too much" you mean "very much" rather than "inordinately" or "excessively". IMHO the addition of [list off the top of my head] string methods, Unicode, new-style classes, generators, list comprehensions, etc etc since 1.5 would indicate that pointing a newbie at an old book would not be such a good idea. From onurb at xiludom.gro Wed Aug 3 06:51:05 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 03 Aug 2005 12:51:05 +0200 Subject: Python IDE's In-Reply-To: References: <20050731205901.53A6E1E4005@bag.python.org> <1122915471.559698.231740@g43g2000cwa.googlegroups.com> Message-ID: <42f0a19b$0$15707$626a14ce@news.free.fr> Jon Hewer wrote: > I do use Vim a lot. I am currently using it for some PHP development > i'm doing. I'm been using it so much recently that i keep pressing > ESC and typing vi commands out of vi. > > But, if i use Vi, then whenever i want to test some code i have to > open up python, import the necessary modules and run it - I like the > idea of developing python in an IDE and just hitting a run button. the Emacs + python-mode combo solve this problem - and in fact gives much more than the common "run and print results" feature of most IDEs, since you can run either the whole script or any part of it in an (embedded) interactive python shell - just as if you had copy/pasted the code in the python shell... This is very useful for exploring/quick testing. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From Peter.Beattie at web.de Thu Aug 25 12:00:10 2005 From: Peter.Beattie at web.de (Peter Beattie) Date: Thu, 25 Aug 2005 18:00:10 +0200 Subject: Experience regarding Python tutorials? In-Reply-To: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> Message-ID: <3n688aF2fp4U1@uni-berlin.de> Shoeshine wrote on 25/08/2005 17:43: > Cheers everyone, I aim to learn a programming language and haven't yet > decided on what's going to be. Here I'd like to hear some voices on > where I should start, and pls don't hit me google. I have been doing > some research, but I'd like to hear about some real life expiriencies on > subject. Is Python maybe a to small target for newcomers? Make it > compared to Perl... Try [http://www.python.org/doc/Intros.html]. There are lots of different-level introductions and tutorials available that should give you an idea of what to expect of Python. -- Peter From python at rcn.com Thu Aug 25 15:40:48 2005 From: python at rcn.com (Raymond Hettinger) Date: 25 Aug 2005 12:40:48 -0700 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: <1124998848.919158.277620@o13g2000cwo.googlegroups.com> Mark Dickinson wrote: > I have a simple 192-line Python script that begins with the line: > > dummy0 = 47 > > The script runs in less than 2.5 seconds. The variable dummy0 is never > referenced again, directly or indirectly, by the rest of the script. > > Here's the surprise: if I remove or comment out this first line, the > script takes more than 15 seconds to run. So it appears that adding a > redundant line produces a spectacular six-fold increase in speed! Thanks for your post. It is cute, brilliant, and interesting. I haven't had time to investigate but can point at the likely cause. All of the global names are stored in a single hash table. Search time is dictated by two factors, the sparseness of the hash table and the distribution of hash values. With respect to sparseness, whenever that table becomes 2/3 full, it grows by a factor of four and becomes only 1/6 full (leading to many fewer collisions). With respect to distribution, it should be noted that string hash values are decidely non-random and your variable names likely congested consecutive spaces in a nearly full table (resulting in seven times as many search probes to find a global value). When the extra value was added, it likely resized the table four-fold and redistributed the hash values into fewer consecutive positions. Raymond P.S. To analyze it further, start with something like this: >>> len(set(hash('dummy%d' %i) & 31 for i in xrange(29))) 26 >>> len(set(hash('dummy%d' %i) & 127 for i in xrange(29))) 29 From could.net at gmail.com Thu Aug 4 04:49:48 2005 From: could.net at gmail.com (could ildg) Date: Thu, 4 Aug 2005 16:49:48 +0800 Subject: Does pyparsing support UNICODE strings? In-Reply-To: References: <311b5ce10508040013750360e6@mail.gmail.com> Message-ID: <311b5ce105080401495341f43d@mail.gmail.com> I want to parse some Chinese words. It seems that pyparsing doesn't work for me. Thank you. I have to use re directly, although it's harder, but it'll always work. On 8/4/05, Robert Kern wrote: > could ildg wrote: > > pyparsing is very convenient to use. But I want to find some a py tool > > to parse non-English strings. Does pyparsing support UNICODE strings? > > If not, can someone tell me what py tool can do it? Thanks in advance. > > Try it! > > # vim:fileencoding=utf-8 > > from pyparsing import Word > > text = "????????, ?????!".decode('utf-8') > alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce)) > > greet = Word(alphas) + u',' + Word(alphas) + u'!' > greeting = greet.parseString(text) > print greeting > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list From ms at cerenity.org Sun Aug 28 12:47:55 2005 From: ms at cerenity.org (Michael Sparks) Date: Sun, 28 Aug 2005 17:47:55 +0100 Subject: Release of PyPy 0.7.0 References: Message-ID: <4311ea97$0$1276$ed2619ec@ptn-nntp-reader02.plus.net> Carl Friedrich Bolz wrote: [[... great news ...]] Would it be useful for people to start trying out their modules/code to see if they work with this release, and whether they can likewise be translated using the C/LLVM backends, or would you say this is too early? (I'm more thinking in terms of it providing real world usecases in the hope of finding things that don't work - rather than anything else) Either way, this looks like a great milestone - congratulations to the entire team. (I remember PyPy being met with skepticism as to whether it could even be done! :-) Best Regards, Michael From kay.schluehr at gmx.net Sat Aug 6 13:07:27 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 6 Aug 2005 10:07:27 -0700 Subject: Proposal: unshadow operator '&' References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <1123348047.409669.98720@f14g2000cwb.googlegroups.com> seberino at spawar.navy.mil wrote: > I've heard 2 people complain that word 'global' is confusing. > > Perhaps 'modulescope' or 'module' would be better? > > Am I the first peope to have thought of this and suggested it? > > Is this a candidate for Python 3000 yet? > > Chris Maybe a solution would be best that is able to resolve shadowing of a variable in an explicit manner. Example. you might have the following nested function: x = 0 def h(): x = 1 # module scoped x will be shadowed def g(): x = 2 # module scoped x and h's local x will be shadowed def f(): print x # printing x defined locally in g f() g() The module level x is always accessible from each inner function using the global keyword but it is not possible to access x defined locally in h from f. Two hypothetical variants using an "unshadow operator" & explicitely: x = 0 def h(): x = 1 def g(): x = 2 def f(): print &x # unshadowing x defined in h f() g() x = 0 def h(): x = 1 def g(): x = 2 def f(): print &&x # unshadowing x defined on module level f() g() Since we can always shadow some module scoped variable defining a local one we might create a side-effect binding values to the unshadowed name: x = 0 def f(): x = 1 &x = 7 >>> f() >>> x 7 Regards, Kay From godoy at ieee.org Mon Aug 1 11:32:28 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 01 Aug 2005 12:32:28 -0300 Subject: Dabo in 30 seconds? References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> Message-ID: <8ur1s2-r5t.ln1@strongwill.g2ctech> Daniel Dittmar wrote: > To be fair to those slothes: some of them want to write software for a > commercial setting where they have to install it on other peoples > machines. So it isn't just getting it to work one one own's machine. > Using a specifc Python library with external dependencies means also > installing and *supporting* it on a possible large set of configurations. I see no problem with that. Specially since there are lots of ways to share directories on a network installation. You install it once and it's done. -- Jorge Godoy From donn at u.washington.edu Mon Aug 8 14:56:55 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 08 Aug 2005 11:56:55 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> Message-ID: In article <7xwtmx7zp6.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > "Donn Cave" writes: > > My vote would be Haskell first, then other functional languages. > > Learning FP with Objective CAML is like learning to swim in a > > wading pool -- you won't drown, but there's a good chance you > > won't really learn to swim either. Has an interesting, very > > rigorous OOP model though. > > I'm not sure what you mean by that about OCAML. That its functional > model is not pure enough? I'd like to look at Haskell as well, but I > have the impression that its implementation is not as serious as > OCaml's, i.e. no native-code compiler. On the contrary, there are a couple. Ghc is probably the leading implementation these days, and by any reasonable measure, it is serious. Objective CAML is indeed not a pure functional language. Donn Cave, donn at u.washington.edu From MCollins at seminolecountyfl.gov Thu Aug 18 07:49:35 2005 From: MCollins at seminolecountyfl.gov (MCollins at seminolecountyfl.gov) Date: Thu, 18 Aug 2005 07:49:35 -0400 Subject: unsubscriptable object error Message-ID: getting an unsubscriptable object error on an if else statement db = MSSQL.connect(server,login,pwd,database) c = db.cursor() c.execute(mySQL) rows = c.fetchone() #determine recipient if str(rows[3]) == str(rows[4]): recipient = str(rows[0]) + " " + str(rows[1]) else: recipient = "test" the above code works fine if rows[3] == rows[4]. it's when it doesn't equal that it gives the error:: TypeError: unsubscriptable object args = ('unsubscriptable object',) Matthew Collins Senior Programmer Analyst, Information Technologies Seminole County Government 1101 E First St Sanford, FL 32771 Office 407-665-1072 Fax 407-665-1025 http://www.seminolecountyfl.gov --****Florida has a very broad Public Records Law. Virtually all written communications to or from State and Local Officials and employees are public records available to the public and media upon request. Seminole County policy does not differentiate between personal and business emails. E-mail sent on the County system will be considered public and will only be withheld from disclosure if deemed confidential pursuant to State Law.**** -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at engcorp.com Wed Aug 10 15:33:19 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Aug 2005 15:33:19 -0400 Subject: interpreter frame In-Reply-To: <1123689998.800361.278370@g43g2000cwa.googlegroups.com> References: <1123689998.800361.278370@g43g2000cwa.googlegroups.com> Message-ID: Leo wrote: > Why is it not possible to get the frame from the interpreter using the > inspect library? Because sys._getframe() does the job instead? -Peter From vincent at visualtrans.de Tue Aug 16 07:42:38 2005 From: vincent at visualtrans.de (vincent wehren) Date: Tue, 16 Aug 2005 13:42:38 +0200 Subject: zlib + Windows 32 service problem (ImportError) References: <43008D0D.4000509@geochemsource.com> Message-ID: "Laszlo Zsolt Nagy" schrieb im Newsbeitrag news:mailman.3121.1124180797.10512.python-list at python.org... | vincent wehren wrote: | | >"Laszlo Zsolt Nagy" schrieb im Newsbeitrag | >news:mailman.3098.1124117300.10512.python-list at python.org... | >| Sorry, I realized that the import zlib was not executed from my | >| (working) service. | >| So here is the question: why can't I use zlib from a win32 service? Is | >| there any way to make it working? | >| | >| >------------- | >| >Python could not import the service's module | >| > File "T:\Python\Projects\NamedConnector\Service.py", line 17, in ? | >| > from Processor import * | >| > File "c:\Python\Projects\NamedConnector\Processor.py", line 35, in ? | >| > from mess import MessageSocket | >| > File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ? | >| > import zlib | >| >exceptions.ImportError: dynamic module does not define init function | >| >(initzlib) | >| >------------- | >| | >| | >| | >I had a similar problem where a zlib.dll that is *not a Python extension* is | >in sys.path *before* zlib.pyd. Python will try to import this zlib.dll and | >find the dll doesn't export a initzlib: | >for more info see | >http://mail.python.org/pipermail/python-list/2004-October/thread.html#248107 | > | > | Thanks. I set my system environment variable 'PATH' to this: | | C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program | Files\Common Files\GTK\2.0\bin | | Then I restarted my computer. It is still missing initzlib. :-( | Please note that I can run the same program as an application, logged in | as the same user. | | Les Changing the Windows dll search path doesn't make any difference. It is sys.path (Python's search path) that's causing you the headache. Please see the mentioned thread for proposed solutions. Regards, -- Vincent Wehren From http Sun Aug 7 01:06:05 2005 From: http (Paul Rubin) Date: 06 Aug 2005 22:06:05 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> Message-ID: <7xu0i2nxoi.fsf@ruckus.brouhaha.com> "Kay Schluehr" writes: > The whole ML family ( including OCaml ) and languages like Haskell > based on a Hindley-Milnor type system clearly make a difference. I > would say that those languages are also cutting edge in language theory > research. It should be definitely interesting to you. Since there is no > single language implementation you might also find one that supports > concepts you need most e.g. concurrency: > > http://cml.cs.uchicago.edu/ Thanks. That link doesn't work right now but I'll try again later. I wonder why the ML's didn't just dispense with the syntax nonsense and present themselves unabashedly as statically typed Lisp dialects complete with parentheses. For concurrency, Oz looks neat, but probably doomed to Python-like slow performance (at least the shootout benchmarks have been pretty poor). I find it easier to understand than ML though I haven't coded anything in it either. I wonder if using logic variables for inter-thread communication without careful conventions can lead to total spaghetti. I also want to check out Erlang and Occam, in my copious free time. From sjmachin at lexicon.net Mon Aug 8 08:04:35 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 08 Aug 2005 22:04:35 +1000 Subject: How to determine that if a folder is empty? In-Reply-To: <3loeiiF139eh3U1@individual.net> References: <3loeiiF139eh3U1@individual.net> Message-ID: <42f74a54@news.eftel.com> Reinhold Birkenfeld wrote: > could ildg wrote: > >>I want to check if a folder named "foldername" is empty. >>I use os.listdir(foldername)==[] to do this, >>but it will be very slow if the folder has a lot of sub-files. >>Is there any efficient ways to do this? > > > try: > os.rmdir(path) > empty = True > except OSError: > empty = False > > should be efficient. But it removes the folder if it is empty. Perhaps it's not efficient to create the folder again. From fakeaddress at nowhere.org Sat Aug 13 16:13:26 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 13 Aug 2005 20:13:26 GMT Subject: thread limit in python In-Reply-To: References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> <1123859196.289006.200380@g44g2000cwa.googlegroups.com> Message-ID: Peter Hansen wrote: > My question was in the context of the OP's situation. What possible use > for 1000 OS threads could he have? Is this a language thing? Surely you realize that "what possible use could be" carries an insinuation that is not such a good idea. Possible uses are many and perfectly reasonable, such as building a quick, responsive server like MySQL. > Is the OP's situation IO-bound, > CPU-bound, or just an experiment to see how many threads he can pile on > the machine at one time? The fact that these threads are all sleeping > implies the latter, though what he posted could have been a contrived > example. I'm interested in the real requirements, and whether more than > 1000 threads in this day and age (not some imaginary future) might not > be a poor approach. If you're interested in his requirements, why not just ask him about his requirements? Kind of premature to condemn his approach. -- --Bryan From "markusweimer\" at ipsi(dot)fraunhofer(.)de Tue Aug 16 03:56:42 2005 From: "markusweimer\" at ipsi(dot)fraunhofer(.)de (. (dot)) Date: Tue, 16 Aug 2005 09:56:42 +0200 Subject: How to build Python modules on windows? In-Reply-To: References: <42fcda84$1@news.fhg.de> Message-ID: <43019c38$1@news.fhg.de> Hi, >>how can I build python modules on windows? I tried to build numarray[0] >>using Microsoft Visual C++ 2003 Toolkit, but got the following error: >> >>--- >>error: Python was built with version 7.1 of Visual Studio, and >>extensions need to be built with the same version of the compiler, but >>it isn't installed. >>--- > > > Are you sure you have setup the environment variables before you build? > > Here is a reference: "Building Python Extensions with the MS Toolkit > Compiler" (http://www.vrplumber.com/programming/mstoolkit/) Thanks for the pointer. The page states at the beginning: "Note that this document represents the findings of a very limited set of tests with what is essentially an unsupported approach to building extensions. You should expect to find bugs. No warranty is made that the approach outlined is safe or appropriate." This raises the question: What is the 'supported' way of building extensions on Windows? Do I need Visual Studio for that? Thanks in advance, Markus From johnny.karlsson at gmail.com Mon Aug 22 10:28:44 2005 From: johnny.karlsson at gmail.com (johnny.karlsson at gmail.com) Date: 22 Aug 2005 07:28:44 -0700 Subject: sending binary files to a 16 micro controller. In-Reply-To: <11gjn8k74pb6uc0@corp.supernews.com> References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <11gjn8k74pb6uc0@corp.supernews.com> Message-ID: <1124720924.939114.96950@g43g2000cwa.googlegroups.com> aaah, well i believe that in Windows XPSP2 has disabled raw socket support (yes i sadly have to use windows) so that's no option. But I'll try to put a time delay and check what happens. Or otherwise perhaps i could do a socket.close each time, but that's a terrible waste of packets. From draghuram at gmail.com Wed Aug 17 14:53:39 2005 From: draghuram at gmail.com (draghuram at gmail.com) Date: 17 Aug 2005 11:53:39 -0700 Subject: creating/modifying sparse files on linux Message-ID: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> Hi, Is there any special support for sparse file handling in python? My initial search didn't bring up much (not a thorough search). I wrote the following pice of code: options.size = 6442450944 options.ranges = ["4096,1024","30000,314572800"] fd = open("testfile", "w") fd.seek(options.size-1) fd.write("a") for drange in options.ranges: off = int(drange.split(",")[0]) len = int(drange.split(",")[1]) print "off =", off, " len =", len fd.seek(off) for x in range(len): fd.write("a") fd.close() This piece of code takes very long time and in fact I had to kill it as the linux system started doing lot of swapping. Am I doing something wrong here? Is there a better way to create/modify sparse files? Thanks, Raghu. From sp1d3rx at gmail.com Thu Aug 4 13:28:05 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 4 Aug 2005 10:28:05 -0700 Subject: Getting HTML from a loaded page in Firefox In-Reply-To: References: Message-ID: <1123176485.796867.128540@g44g2000cwa.googlegroups.com> Please explain in more detail exactly what your problem was using the method you described. We can help you, but most would be hard pressed to write your code for you. From jhe13586 at bigpond.net.au Sat Aug 27 21:59:11 2005 From: jhe13586 at bigpond.net.au (Joal Heagney) Date: Sun, 28 Aug 2005 01:59:11 GMT Subject: Experience regarding Python tutorials? In-Reply-To: <1125072815.753219.62420@g47g2000cwa.googlegroups.com> References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <1125072815.753219.62420@g47g2000cwa.googlegroups.com> Message-ID: Steve wrote: > Python is an excellent place to start. Avoid Perl at all costs. > > There is a new beginners book on Python that looks interesting. It is > from WROX (the red cover folks) and called "Beginning Python". > > http://www.amazon.com/exec/obidos/tg/detail/-/0764596543/qid=1125072498/sr=1-1/ref=sr_1_1/002-4477837-1552864?v=glance&s=books > There is also a python tutor newsgroup at gmane (gmane.comp.python.tutor). It's good to be able to learn with other beginner/semi-beginners because you can pick up a lot just by lurking on other people's questions. Joal From fredrik at pythonware.com Mon Aug 29 14:18:42 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Aug 2005 20:18:42 +0200 Subject: python xml DOM? pulldom? SAX? References: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> Message-ID: Alan Kennedy wrote: > SAX is perfect for the job. See code below. depends on your definition of perfect... using a 20 MB version of jog's sample, and having replaced the print statements with local variable assignments, I get the following timings: 5 lines of cElementTree code: 7.2 seconds 60+ lines of xml.sax code: 63 seconds (Python 2.4.1, Windows XP, Pentium 3 GHz) From knaren at midascomm.com Fri Aug 26 01:13:08 2005 From: knaren at midascomm.com (knaren at midascomm.com) Date: Fri, 26 Aug 2005 10:43:08 +0530 (IST) Subject: Email client in Pyhton In-Reply-To: <20050824192915.2031.384.XPN@orion.homeinvalid> Message-ID: > Start reading related RFCs like RFC2822, RFC2045/6/7, RFC2231, RFC821 > ... and then read Python documentation and you'll find that most of > these RFC are supported/implemented by python modules like > > - email > - smtlib > - rfc822 > > As far I know the most complete mail client written in Python is Pyne, > wich is a news/mail client written with PyGTK. thank u, for suggestions. have started to read these RFCs > I'm writing a newsreader (XPN), wich can send mail replies, maybe you > can read its code. i like have a look at this too... -- K Naren, MeTel Team. http://www.midascomm.com/ From nephish at xit.net Fri Aug 26 11:58:23 2005 From: nephish at xit.net (nephish at xit.net) Date: 26 Aug 2005 08:58:23 -0700 Subject: need a little help with time In-Reply-To: References: <1125065840.477157.43290@g47g2000cwa.googlegroups.com> Message-ID: <1125071903.066401.198170@z14g2000cwz.googlegroups.com> the mxDateTime thing should be great, i have to pass this stuff back and forth with MySQL DateTime fields, thanks a lot ! From kimsj at mobile.snu.ac.kr Sun Aug 28 08:37:29 2005 From: kimsj at mobile.snu.ac.kr (James Kim) Date: Sun, 28 Aug 2005 21:37:29 +0900 Subject: Doubt C and Python In-Reply-To: References: Message-ID: Jeff Schwab wrote: > 5. Scripting is easier in Python than in Java, particularly with > regard to environment variables and process control. > > Of course, these are only my opinions. I am particularly not an expert > on Python or Java. Note that for Java experts, Jython can be used for interpreting works. Jython has the same grammer to Python, or CPython, and is also able to call Java codes very simply. See, for example: http://www.jython.org/docs/usejava.html -James (^o^) From ${rleigh} at invalid.whinlatter.ukfsn.org.invalid Tue Aug 23 17:28:26 2005 From: ${rleigh} at invalid.whinlatter.ukfsn.org.invalid (Roger Leigh) Date: Tue, 23 Aug 2005 22:28:26 +0100 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <3mv4c2F18so93U1@individual.net> Message-ID: <8764twuyv9.fsf@hardknott.home.whinlatter.ukfsn.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ulrich Hobelmann writes: > Keith Thompson wrote: >> "Xah Lee" writes: >> [the usual] > At least he noticed that tar sucks. There's nothing better than tarring > your backup back to disk, only to notice that the pathnames were "too > long." Great! That's been fixed for quite some time, though. The current GNU tar (1.15.1) writes POSIX.1-2001 (PAX) archives, and has read them for quite a long time before. Regards, Roger - -- Roger Leigh Printing on GNU/Linux? http://gimp-print.sourceforge.net/ Debian GNU/Linux http://www.debian.org/ GPG Public Key: 0x25BFB848. Please sign and encrypt your mail. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 iD8DBQFDC5T5VcFcaSW/uEgRAmJ6AKDsqFmvoBsOqsm/6zIfHQleMpI5KwCgsR6Q yO7hX52yq/iHIHC2yJ6hF2A= =MCYF -----END PGP SIGNATURE----- From http Mon Aug 1 15:50:56 2005 From: http (Paul Rubin) Date: 01 Aug 2005 12:50:56 -0700 Subject: Dabo in 30 seconds? References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> Message-ID: <7x7jf5o2qn.fsf@ruckus.brouhaha.com> Ed Leafe writes: > a lot of the Python standard library modules, many dbapi-compliant modules, > and, of course, wxPython. If someone mis-installs one of the pre-requisites, > do you expect Dabo to catch that and present you with a diagnostic message? > I'm serious here: I want to know what people consider acceptable for a > software package that relies on other packages. I seem to be in a minority here but I vote for avoiding such dependencies as much as possible. That's the best way to avoid problems in practice. I'm interested in trying out dabo if it gets tkinter support but life is too short for me to want to mess with wxpython any more, unless I have some more compelling reason. From tim.leeuwvander at nl.unisys.com Tue Aug 30 08:52:04 2005 From: tim.leeuwvander at nl.unisys.com (Tim N. van der Leeuw) Date: 30 Aug 2005 05:52:04 -0700 Subject: variable hell In-Reply-To: <1124976866.259664.265280@g49g2000cwa.googlegroups.com> References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> Message-ID: <1125406324.757354.56520@g47g2000cwa.googlegroups.com> What you could do is to create a class for this; fill it's __dict__ instance; and use custom getattr() / setattr() methods for accessing a0, a1, a2 etc. cheers, --Tim From spe.stani.be at gmail.com Fri Aug 12 22:09:39 2005 From: spe.stani.be at gmail.com (spe.stani.be at gmail.com) Date: 12 Aug 2005 19:09:39 -0700 Subject: Text/IDE Python Editor? In-Reply-To: References: Message-ID: <1123898979.433744.42650@g14g2000cwa.googlegroups.com> Next release of SPE will include the new debugger of Nir Aides to make it complete. Stani http://www.stani.be http://pythonide.stani.be http://pythonide.stani.be/screenshots From Scott.Daniels at Acm.Org Fri Aug 26 12:01:57 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Aug 2005 09:01:57 -0700 Subject: argument matching question In-Reply-To: References: <1125018189.157888.113500@g47g2000cwa.googlegroups.com> Message-ID: <430f30ea$1@nntp0.pdx.net> Leif K-Brooks wrote: > Learning Python wrote: > >>A code like this: >> >>def adder(**varargs): >> sum=varargs[varargs.keys()[0]] >> for next in varargs.keys()[1:]: >> sum=sum+varargs[next] >> return sum For that function, call: print adder(first=1, second=2, third=3) A better function definition for python 2.4 would be: def adder(**varargs): return sum(varargs.values()) And a better function definition without using sum would be: def adder(**varargs): values = varargs.values() if values: total = values[0] for element in values[1:]: total += element return total else: return 0 --Scott David Daniels Scott.Daniels at Acm.Org From chris at wintergreen.in Sat Aug 27 22:06:20 2005 From: chris at wintergreen.in (Chris Dewin) Date: Sun, 28 Aug 2005 11:06:20 +0900 Subject: python image thumbnail generator? Message-ID: Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails. A few questions: (1) Can this be done with python? If so, what module do I need to look up? (2) If it can't be done with python, is there some small utility that will do it for me? Something I could easily install locally in my own "public_html" dir on my website? (3) Is this the sort of thing which, if done regularly, would hog far far too much of my webhosts system resources? (4) Am I talking about re inventing the wheel? From rebound1618 at yahoo.com Sat Aug 6 05:06:21 2005 From: rebound1618 at yahoo.com (Jerry He) Date: Sat, 6 Aug 2005 02:06:21 -0700 (PDT) Subject: installing SWIG for python Message-ID: <20050806090621.81534.qmail@web51506.mail.yahoo.com> Hi, I just installed SWIG on Windows(Cygwin) and tried to use it to compile some of the example python programs. For the first two commands it produced no error swig -python example.i gcc -c example.c example_wrap.c -I \ /usr/include/python2.4 For the third one however ld -shared example.o example_wrap.o -o _example.so It gave me a long list of errors listed at the end of this email. The error messages were rather baffling because the C file that was to be made into a python Module was a simple gcd function, it doesn't need strlen, or any of the other C functions, and much less Tcl_Append, what does this have to do with Tcl? Any help or suggestions on this would be appreciated... -Jerry example_wrap.o:example_wrap.c:(.text+0x1cb3): undefined reference to `strlen' example_wrap.o:example_wrap.c:(.text+0x1ccf): undefined reference to `strchr' example_wrap.o:example_wrap.c:(.text+0x1cf7): undefined reference to `strstr' example_wrap.o:example_wrap.c:(.text+0x1d5d): undefined reference to `Tcl_Append Element' example_wrap.o:example_wrap.c:(.text+0x1e09): undefined reference to `Tcl_SetRes ult' example_wrap.o:example_wrap.c:(.text+0x1e40): undefined reference to `Tcl_GetStr ingFromObj' example_wrap.o:example_wrap.c:(.text+0x1e56): undefined reference to `strcmp' example_wrap.o:example_wrap.c:(.text+0x1e80): undefined reference to `strcmp' example_wrap.o:example_wrap.c:(.text+0x1ec6): undefined reference to `Tcl_GetStr ingFromObj' example_wrap.o:example_wrap.c:(.text+0x1edc): undefined reference to `strcmp' example_wrap.o:example_wrap.c:(.text+0x1f48): undefined reference to `Tcl_GetObj Result' example_wrap.o:example_wrap.c:(.text+0x1f50): undefined reference to `Tcl_Duplic ateObj' example_wrap.o:example_wrap.c:(.text+0x1f70): undefined reference to `Tcl_GetStr ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From hancock at anansispaceworks.com Mon Aug 15 14:16:34 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 15 Aug 2005 13:16:34 -0500 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: <8c7f10c6050815075443fc446a@mail.gmail.com> References: <8c7f10c6050815075443fc446a@mail.gmail.com> Message-ID: <200508151316.34512.hancock@anansispaceworks.com> On Monday 15 August 2005 09:54 am, Simon Brunning wrote: > On 8/15/05, Rocco Moretti wrote: > > Which lead me to the question - what's the difference between a library > > and a framework? > > If you call its code, it's a library. If it calls yours, it's a framework. Such concision deserves applause. ;-) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From tjreedy at udel.edu Tue Aug 9 23:22:44 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 9 Aug 2005 23:22:44 -0400 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <1123609818.770605.267740@g14g2000cwa.googlegroups.com> Message-ID: "Jeffrey E. Forcier" wrote in message news:1123609818.770605.267740 at g14g2000cwa.googlegroups.com... > Thirding the Subversion/SVN suggestions. It's generally a newer, better > CVS with some new features and a lot less of the negative features/lack > thereof, of the older system. For what it is worth, the Python developers are discussing moving the Python codebase to subversion, though other options were discussed. The result so far is PE 347 Migrating the Python CVS to Subversion. Terry J. Reedy From bokr at oz.net Tue Aug 9 23:47:06 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 10 Aug 2005 03:47:06 GMT Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> Message-ID: <42f97878.1053366641@news.oz.net> On Tue, 09 Aug 2005 21:50:06 -0000, Grant Edwards wrote: >On 2005-08-09, Scott David Daniels wrote: >> Grant Edwards wrote: >>>>Ex #1) 333-3333 >>>>Hex On disk: 00 00 00 80 6a 6e 49 41 >>>> >>>>Ex #2) 666-6666 >>>>Hex On disk: 00 00 00 80 6a 6e 59 41 >>> >>> So there's only a 1-bit different between the on-disk >>> representation of 333-3333 and 666-6666. >>> >>> That sounds pretty unlikely. Are you 100% sure you're looking >>> at the correct bytes? >> >> Perhaps the one bit is an exponent -- some kind of floating point >> based format? That matches the doubling of all digits. > >That would just be sick. I can't imagine anybody on an 8-bit >CPU using FP for a phone number. > >-- >Grant > >>> def double_binary_lehex_to_double(dhex): ... "convert little-endian hex of ieee double binary to double" ... assert len(dhex)==16, ( ... "hex of double in binary must be 8 bytes (hex pairs in little-endian order") ... dhex = ''.join(reversed([dhex[i:i+2] for i in xrange(0,16,2)])) ... m = int(dhex, 16) ... x = ((m>>52)&0x7ff) - 0x3ff - 52 ... s = (m>>63)&0x1 ... f = (m & ((1<<52)-1))|((m and 1 or 0)<<52) ... return (1.0,-1.0)[s]*f*2.0**x ... >>> double_binary_lehex_to_double('000000806a6e4941') 3333333.0 >>> double_binary_lehex_to_double('000000806a6e5941') 6666666.0 >>> double_binary_lehex_to_double('0000108777F9Fc41') 7777777777.0 ;-) Regards, Bengt Richter From dan at cellectivity.com Wed Aug 17 07:32:59 2005 From: dan at cellectivity.com (Dan) Date: Wed, 17 Aug 2005 12:32:59 +0100 Subject: PyXML and xml.dom Message-ID: <1124278379.10666.8.camel@localhost.localdomain> I'm writing a Python program that does some XML parsing, though nothing heavy, and I want to avoid requiring the user to install additional libraries like PyXML. The documentation for my version of Python (2.3.5) mentions PyXML as an additional library while discussing the DOM module . I don't seem to have PyXML installed on my system, but: >>> import xml.dom.minidom >>> print xml.dom.minidom.xml.__doc__ [blah, blah] The full PyXML package, available from http://pyxml.sf.net, is installed. [blah, blah] Is PyXML now part of the Python distribution, or is it still an add-on? -- In the early 1980s, teenagers began "getting high" from aerosols, despite clear warnings of death. Then liability lawyer Victor E. Schwartz suggested adding a (false) warning of facial disfigurement. According to Schwartz, "We haven't had a liability claim since." From onurb at xiludom.gro Sat Aug 13 11:30:22 2005 From: onurb at xiludom.gro (bruno modulix) Date: Sat, 13 Aug 2005 17:30:22 +0200 Subject: Dictionary inheritance In-Reply-To: References: Message-ID: <42fe120f$0$29931$626a14ce@news.free.fr> Talin wrote: > I want to make a dictionary that acts like a class, in other words, > supports inheritance: I must be missing your point here, since dict is a class and as such support inheritence: >>> class MyDict(dict):pass ... >>> d = MyDict() >>> d.items() [] >>> > If you attempt to find a key that isn't present, > it searches a "base" dictionary, which in turn searches its base, and so > on. That's not inheritence, that's contextual acquisition (Zope relies heavily on this concept). > Now, I realize its fairly trivial to code something like this using > UserDict, If you want to specialize dict, why use UserDict ? > but given that classes and modules already have this behavior, Nope. Inheritence is not the solution - unless of course you want to create a derived class for each and any of your 'nested dict' instances, which would be a rather strange design... Here you need composition/delegation: class HierDict(dict): def __init__(self, parent=None): self._parent = parent def __getitem__(self, name): try: return super(HierDict,self).__getitem__(name) except KeyError, e: if self._parent is None: raise return self._parent[name] # to be continued according to your needs if __name__ == "__main__": d = HierDict(None) d['test'] = 42 print d['test'] d2 = HierDict(d) d2['dead'] = "parrot" print d2['dead'] # found in d2 print d2['test'] # found in d > > Also, on a completely different subject: Has there been much discussion > about extending the use of the 'is' keyword to do type comparisons a la > C# (e.g. "if x is list:") ? I don't think there is much to discuss: x = list if x is list: print "x is list" Remember that in Python, 1/ type information pertains to objects, not to identifiers 2/ types are objects too So, the 'is' operator being the identity operator, there is no need to 'extend' it to do type comparisons: x = [] if type(x) is type([]): print "x is a list" But - even if useful in some special cases -, type comparisons in Python are rarely necessary and in most case worst than useless: def get_foo(a_dict): if type(a_dict) is type({}): foo = a_dict['foo'] else: raise TypeError, "expected a dict, got something else" h = HierDict() h['foo'] = 'bar' get_foo(h) ...definitively worst than useless... - bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From rkern at ucsd.edu Thu Aug 25 05:12:33 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 02:12:33 -0700 Subject: overload builtin operator In-Reply-To: References: Message-ID: Shaun wrote: > Hi, > > I'm trying to overload the divide operator in python for basic arithmetic. > eg. 10/2 ... no classes involved. > > I am attempting to redefine operator.__div__ as follows: > > # my divide function > def safediv(a,b): > return ... > > # reassign buildin __div__ > import operator > operator.__div__ = safediv > > The operator.__dict__ seems to be updated OK but the '/' operator still > calls buildin __div__ Actually, int1 / int2 is, I believe, equivalent to int.__div__(int1, int2) operator.__div__ does not get called. > Does anyone know if this is possible and if I'm going along the correct > path with my attempts above? > Is it possible to do this using a C extention? No, you can't replace the methods on builtin types. -- 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 http Mon Aug 29 15:15:36 2005 From: http (Paul Rubin) Date: 29 Aug 2005 12:15:36 -0700 Subject: python image thumbnail generator? References: <7x8xymby4w.fsf@ruckus.brouhaha.com> Message-ID: <7xk6i4mu5j.fsf@ruckus.brouhaha.com> "Fredrik Lundh" writes: > > You could do it with PIL, or run jpegtran in an external process. > > jpegtran may be easier. > > eh? are you sure you know what jpegtran does? > > JPEGTRAN(1) Whoops, sorry, right, jpegtran is for rotating the images. I meant: use a pipeline like djpeg -scale 1/4 | cjpeg That's how I usually do it. Main disadvantage is the scale factor has to be 1/2, 1/4, 1/8, etc., not arbitrary amounts like 0.3456. From steve at holdenweb.com Wed Aug 31 13:02:36 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Aug 2005 12:02:36 -0500 Subject: What are new-style classes? In-Reply-To: <3nm4kkF26v7eU1@individual.net> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> <3nk08hF1snjcU1@individual.net> <3nm4kkF26v7eU1@individual.net> Message-ID: <4315E2AC.1060102@holdenweb.com> Reinhold Birkenfeld wrote: > Terry Hancock wrote: > >>On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote: >> >>>The customary way is to use "class new_class(object):". There's no advantage in using >>>__metaclass__ except that you can set it globally for all classes in that module >>>(which can be confusing on its own). >>> >>>My comment mostly referred to "new-style classes must be declared as a subclass of >>>a new-style class", which is not true. >> >>Nonsense. > > > Given the rest of your post, I assume that this isn't meant as it sounds. Remember, I'm > German, so please bear with my sense of humour. ;) > German? Humour? Surely some mistake :-) not-talking-about-the-war-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From petr at tpc.cz Tue Aug 23 08:41:09 2005 From: petr at tpc.cz (McBooCzech) Date: 23 Aug 2005 05:41:09 -0700 Subject: py-serial + CSV In-Reply-To: References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> Message-ID: <1124800869.248154.309620@g47g2000cwa.googlegroups.com> So do I have to save to the file first and analyze later on? Or there is an other way how to process it (read from the serial and analyze data) on the fly? Petr Jakes From fakeaddress at nowhere.org Sun Aug 28 16:19:07 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sun, 28 Aug 2005 20:19:07 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> <7xirxri3x5.fsf@ruckus.brouhaha.com> Message-ID: <%_oQe.72$WJ3.55@newssvr21.news.prodigy.com> Steve Holden wrote: > Paul Rubin wrote: > We are arguing about trivialities here. Let's stop before it gets > interesting :-) Some of us are looking beyond the trivia of what string.find() should return, at an unfortunate interaction of Python features, brought on by the special-casing of negative indexes. The wart bites novice or imperfect Python programmers in simple cases such as string.find(), or when their subscripts accidentally fall off the low end. It bites programmers who want to fully implement Python slicing, because of the double-and- contradictory- interpretation of -1, as both an exclusive ending bound and the index of the last element. It bites documentation authors who naturally think of the non-negative subscript as *the* index of a sequence item. -- --Bryan From epost2 at gmail.com Tue Aug 16 05:39:35 2005 From: epost2 at gmail.com (bruce) Date: 16 Aug 2005 02:39:35 -0700 Subject: fsm - revert to previous state (newbie) Message-ID: <1124185175.119956.81840@f14g2000cwb.googlegroups.com> Hi all, I`m working on a fsm that looks up its transitions in some dictionaries. I`ve defined a default transition to an "error_state" that is launched when there is no match of input_symbol, state etc in other dicts. The error state just prints out that user_input was not defined. After this I want to revert back to the state before the error, so the user can try again. My solution now is to update the value in the dictionary state_transitions whose key is "state_error", inside the fsm loop. This is not very elegant I think. Does anyone know of a better way? From jeffrey.schwab at rcn.com Thu Aug 11 00:49:59 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Thu, 11 Aug 2005 00:49:59 -0400 Subject: What is Python?! In-Reply-To: <42fa51db$0$7802$626a14ce@news.free.fr> References: <42fa51db$0$7802$626a14ce@news.free.fr> Message-ID: <2tadnUdq9Z1nRWffRVn-3A@rcn.net> bruno modulix wrote: > bash is a scripting language, Bash is a shell. It is frequently used for scripting, but that is only a secondary purpose. > javascript is a scripting language, Yes, but it's a particularly specialized one. > perl is a scripting language, Blasphemy! Perl is a dynamic language, entirely suitable for large applications. I've written some pretty big programs entirely in Perl, and extended it with C and C++ to make it fit nicely into existing application frameworks. > php is a scripting language, OK, but it's also awfully specialized. > Python is *not* a scripting language !-) It's a scripting language, among other things. Why do you think non-imported source files are not automatically compiled to pyc's? From denis.kasak at gmail.com Fri Aug 26 09:43:19 2005 From: denis.kasak at gmail.com (Denis Kasak) Date: Fri, 26 Aug 2005 15:43:19 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> <3n8ddiFbhg7U1@individual.net> Message-ID: John Bokma wrote: > Ulrich Hobelmann wrote: > >> John Bokma wrote: >>> http://www.phpbb.com/mods/ >> >> Great. How can I, the user, choose, how to use a mod on a given web >> server? > > Ask the admin? And that is, in your opinion, completely comparable to running your own, private client? Is the admin obliged to install the mod? Is the admin even reachable? >> What if the web server runs another board than PHPBB? > > Check if there is a mod, and ask the admin. See above. >>> Does the user want this? And with a user stylesheet you can change it >>> quite radically :-) >> >> The look, not the feel. > > Wild guess: (signed) javascript and iframes? on your local computer? > > Otherwise: fetch HTML, parse it, restructure it, and have the > application run a local webserver. Python, Perl, piece of cake. You seem to be forgetting that we are mainly talking about end users here who most probably will not have the sufficient expertise to do all that. And even if they do, it's still time consuming. From noreply at gcgroup.net Thu Aug 25 11:46:53 2005 From: noreply at gcgroup.net (William Gill) Date: Thu, 25 Aug 2005 15:46:53 GMT Subject: a question about tkinter StringVars() In-Reply-To: References: Message-ID: Eric Brunel wrote: > On Wed, 24 Aug 2005 15:07:27 GMT, William Gill wrote: > >> Working with tkinter, I have a createWidgets() method in a class. >> Within createWidgets() I create several StringVars() and >> assign them to the textvariable option of several widgets. >> Effectively my code structure is: >> >> def createWidgets(self): >> ... >> var = StringVar() >> Entry(master,textvariable=var) >> ... >> ... >> >> Though 'var' would normally go out of scope when createWidgets >> completes, since the Entry and its reference do not go out of scope, >> only the name 'var' goes out of scope, not the StringVar object, Right? > > > Well, apparently not: > > ------------------------------------------------ > from Tkinter import * > > class MyStringVar(StringVar): > def __del__(self): > print "I'm dying!" > > root = Tk() > > def cw(): > var = MyStringVar() > Entry(root, textvariable=var).pack() > > cw() > > root.mainloop() > ------------------------------------------------ > > Running this script actually prints "I'm dying!", so there is obviously > no reference from the Entry widget to the variable object. The reference > is actually kept at tcl level between an entry and the *tcl* variable, > which knows nothing about the *Python* variable. > > BTW, the whole purpose of StringVar's is to be kept so that the text for > the entry can be retrieved or modified by another part of the program. > So what can be the purpose of creating variables in a function or method > and not keeping them anywhere else than a local variable? I posted that changing back to a non-local variable works now, and that my problem was probably name conflict. I haven't been able to verify that, but I have to assume that was the original problem. My band-aid may have 'worked' because tcl maintained the control variable and callback even though the Python variable was gone. As far as "... the purpose of creating variables ... and not keeping them anywhere else...". I actually was keeping them in a non-local list. I was creating a local variable, appending it to the list, then reusing the local name for the next new control variable: ... var= IntVar() self.variables.append(var) ... This was 'copied' from a snippet I was using as a template. I now use: ... self.variables.append(IntVar()) ... Please let me know if I'm on thin ice here. Bill From nospam at me.invalid Mon Aug 1 19:27:10 2005 From: nospam at me.invalid (anthonyberet) Date: Tue, 02 Aug 2005 00:27:10 +0100 Subject: calling functions Message-ID: <3l7pegF10qu8cU1@individual.net> This is the first time I have tried out functions (is that the main way of making subroutines in Python?) Anyway, my function, mutate, below #make a child string by randomly changing one character of the parent Def mutate(): newnum=random.randrange(27) if newnum==0: gene=' ' else: gene=chr(newnum+96) position=random.randrange(len(target)) child=parent[:position-1]+gene+parent[position+1:] mutate() The trouble is when I later (as in further down the code) attempt to retrieve the value of gene I get an error saying that gene is undefined. It works fine when I don't have the routine defined as a function. - the IF- Else structure means gene must have a value of ' ' or 'a' to 'z'. It seems that the line: mutate() is not invoking the function, but why not? Thanks again - this group is great. I despair of ever being able to contribute though :-( From steve at myplace.com Thu Aug 11 21:07:24 2005 From: steve at myplace.com (Steve M) Date: Thu, 11 Aug 2005 20:07:24 -0500 Subject: Printing to printer References: Message-ID: Kristian Zoerhoff wrote: > On 8/11/05, Steve M wrote: >> Hello, >> >> I'm having problems sending information from a python >> script to a printer. I was wondering if someone might send me >> in the right direction. I wasn't able to find much by Google > > Which platform? Directions will vary wildly. > Ooops, sorry forgot to mention I'm using Suse 9.0 and Python 2.3x TIA Steve From fredrik at pythonware.com Wed Aug 31 19:40:20 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 1 Sep 2005 01:40:20 +0200 Subject: OpenSource documentation problems References: Message-ID: Bryan Olson wrote: > >>>>import pydoc > >>>>help is pydoc.help > > > > False > > Say Fredrik, if you're going to proclaim "False" oh, I didn't proclaim anything. Python 2.4 did. let's see what Python 2.2 has to say about this: $ python2.2 Python 2.2.1 (#2, Jul 17 2002, 13:11:01) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pydoc >>> help is pydoc.help 0 I do, however, find it a bit funny when someone reads Type "help", "copyright", "credits" or "license" for more information. as Type "help(help)" /.../ and then starts ranting about how "help(help)" isn't quite as helpful as "help" (or "help()", for that matter -- which is what a plain "help" tells you to use). it's a little like the people who type "google" into the google search field, and then complain that the "I feel lucky" button doesn't seem to work. From http Tue Aug 16 04:32:16 2005 From: http (Paul Rubin) Date: 16 Aug 2005 01:32:16 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <7x8xzcck9d.fsf@ruckus.brouhaha.com> <86wtmvlti7.fsf_-_@bhuda.mired.org> <7xoe87vl0i.fsf@ruckus.brouhaha.com> <42f8c2e2.1006880848@news.oz.net> Message-ID: <7xmznijn8v.fsf@ruckus.brouhaha.com> bokr at oz.net (Bengt Richter) writes: > >built-in concurrency support. OCaml seems to crush Haskell and Erlang > >(and even Java) in performance. Occam isn't used for much practical > >any more, but takes a purist approach to concurrency that seems worth > >studying. > IIRC, I've seen something about a web server implemented in erlang > with tremendous performance at high levels of concurrency where other > implementations bog down. So I would want further details before I > believe that all OCaml versions "crush" all Erlang versions in performance. Good point you and Donn make about shootouts. However, the shootout figure differences in these particular cases are vast, and nature of the implementations seems to make that result inevitable. I've been looking a little more at the docs of the languages (haven't written any code yet). Erlang is sort of like Python: dynamically typed, and compiled to bytecode that gets interpreted. Haskell is statically typed and has apparently has a real compiler, but uses lazy evaluation for everything, which if done in the obvious way (I don't know how they actually do it), there's a closure wrapped around every value. Also, the language itself seems to do a lot of stuff for you behind the scenes, almost like Prolog. In that sense it's really a higher level language than normal imperative languages, so I can see why people like programming in it. But it doesn't make for the fastest machine code. OCaml seems to be sort of like Lisp with static types, and syntax geared towards functional-style programming. In that sense it's maybe less high-level than Haskell. But it means standard Lisp compiler techniques can make excellent output code, seriously competing with C/C++ compilers. There's an SML compiler (MLton) that seems to significantly beat C++ for scientific number crunching speed a lot of the time. > I'd suggest finding that Erlang web server writeup. > Hm, some googling ... > I think this is the graph I saw: > http://www.sics.se/~joe/apachevsyaws.html > > Can't vouch for what it means, but taken at face value > would seem to warrant a further look into details. That looks like purely a test of how many simultaneous connections the server can handle. They had each client connect to the server, read one byte, then hold the connection open and do nothing. Apache uses a separate process or OS thread for each connection, so it wedged once a few thousand requests were open. Erlang apparently uses microthreads, probably allocating every call frame on the heap like SML/NJ did, so they showed it with 80,000 connections open. The key, though, is that the clients were doing basically nothing. It just meant that many small data structures were allocated in memory of one server process. It doesn't say anything about how fast the server can actually generate and serve dynamic content. The Mnesia database looks interesting and I'm going to have to read about it further and figure out if something like it can be done in Python. I realized that my server will spend a lot of cycles in mod_gzip or the equivalent. So I think a (maybe not achievable) performance goal is for the web app to use 50% of the available cycles making html, and the other 50% go to gzipping the html. That means that the app should make dynamic output as fast as gzip can compress it, which is at least several megabytes per second. (All static content would be stored pre-gzipped and served by khttpd (Linux kernel httpd) without the dynamic app ever seeing the request). I think that requires compiled code and use of an in-process database (no remote SQL) for almost all requests. It's an order of magnitude faster than the crap that almost everyone is running on real sites. > This turned up also > http://eddie.sourceforge.net/txt/WP_1.0.html Oh, this is nice. I'm thinking of an architecture like OK Web Server (http://okws.org) but without (ugh!) C++, letting the kernel httpd serve static content as mentioned. > I guess this is a home for erlang: > http://www.erlang.se/ That's the commercial site, the free stuff is at www.erlang.org. > Much other stuff, but you know how to google ;-) Yes, thanks ;-). From mekstran at scl.ameslab.gov Mon Aug 8 10:54:33 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Mon, 8 Aug 2005 09:54:33 -0500 Subject: Extending and altering httplib to handle bad servers Message-ID: <20050808095433.301bcbed.mekstran@scl.ameslab.gov> In the course of my current project, I've had to deal with connecting to an HTTP server that isn't fully compliant with the HTTP requirements for chunked encodings. Rather than sending the end-of-data sentinel (0-length chunk), it just closes the connection (without even sending the CRLF at the end of the data). Because of this, using httplib would always throw nasty errors and not give me any useful data. Therefore, I've had to modify the httplib.py code to do something reasonable when the server just closes the connection. So, my questions are (my changes follow, against Python 2.3): - Did I patch the right place to do Something Reasonable in this case of server non-compliance? - Is there a better way to handle this case that may be more robust? Or handle more similar cases? - Is there anything special I should do (besides obviously diff-ing against CVS) before submitting a patch for this to SourceForge? (it seems to me that being tolerant of bad servers is something that would be of general interest.) Thanks, Michael ---8<------- BEGIN CONTEXT DIFF ------------ *** /usr/lib/python2.3/httplib.py 2005-05-04 02:08:57.000000000 -0500 --- httplib.py 2005-08-05 10:33:08.000000000 -0500 *************** *** 1,5 **** --- 1,7 ---- """HTTP/1.1 client library + Copyright (c) 2001 Python Software Foundation; All Rights Reserved + *************** *** 64,69 **** --- 66,75 ---- Unread-response _CS_IDLE Req-started-unread-response _CS_REQ_STARTED Req-sent-unread-response _CS_REQ_SENT + + Modified 2005-07-20 by Michael Ekstrand to deal + gracefully wtih non-compliant systems which just terminate the connection + rather than sending the end-of-data chunk in chunked HTTP responses. """ import errno *************** *** 442,448 **** amt -= chunk_left # we read the whole chunk, get another ! self._safe_read(2) # toss the CRLF at the end of the chunk chunk_left = None # read and discard trailer up to the CRLF terminator --- 448,460 ---- amt -= chunk_left # we read the whole chunk, get another ! try: ! self._safe_read(2) # toss the CRLF at the end of the chunk ! except IncompleteRead: ! # The server just closed on us, without providing appropriate ! # end-of-data things. ! self.close() ! return value chunk_left = None # read and discard trailer up to the CRLF terminator ---8<--------- END CONTEXT DIFF ------------- From lv at aol.com Tue Aug 23 09:32:09 2005 From: lv at aol.com (l v) Date: Tue, 23 Aug 2005 08:32:09 -0500 Subject: Jargons of Info Tech industry In-Reply-To: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: <1124804082_1011@spool6-east.superfeed.net> Xah Lee wrote: > (circa 1996), and email should be text only (anti-MIME, circa 1995), I think e-mail should be text only. I have both my email and news readers set to display in plain text only. It prevents the marketeers and spammers from obtaining feedback that my email address is valid. A surprising amount of information can be obtained from your computer by allowing HTML and all of it's baggage when executing on your computer. Phishing comes to my mind first and it works because people click the link without looking to see where the link really takes them. > reason for SGML and HTML should understand the problem. Many of you > familiar with drive of evolution of HTML from 1995 days to today's CSS > & XML should also understand the issue. We wish to encode information, I do not want spammers to encode information in their emails. > Xah > Please go to jobs.org Len ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From pink at odahoda.de Fri Aug 19 09:34:24 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Fri, 19 Aug 2005 15:34:24 +0200 Subject: Adobe COM with Python References: Message-ID: Andy W wrote: > I'm wanting to automate Adove Acrobat Reader using Com thru Python and > win32com, but i can't find any documentation for the Adobe stuff? Has > anyone done anything with Acrobat COM ? > > I've searched Google groups and the web but am unable to find anything. I have not hacked Acrobat yet, but done a bit with InDesign - Adobe's documentation is less than perfect, but still pretty good. You might look at - in InDesign I could easily map the methods and attributes from the JS documentation to COM calls (the JS members start with lowercase - e.g. 'properties' -, while COM need uppercase - 'Properties'). -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From pink at odahoda.de Mon Aug 1 06:28:57 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Mon, 01 Aug 2005 12:28:57 +0200 Subject: python SMTP server References: <1122759885.881136.186360@g47g2000cwa.googlegroups.com> Message-ID: Cliff Wells wrote: > On Sun, 2005-07-31 at 13:14 +0200, Benjamin Niemann wrote: > >> But you should be aware of the fact that (if you send mail from a dialup >> machine without going through a relay server) your mails will quickly be >> marked as spam - I hope you do not intend to send spam... > > Yah, Postfix on my servers uses several dnsbl's which automatically > reject home users (unless they authenticate first). Even if this isn't > the case for the majority of SMTP servers today I expect it won't be > long before it is. > > As an aside, I will say that many SMTP servers that service home users > (i.e. Comcast, et al) limit the amount of mail that you can send within > a defined period. Or completely block outgoing traffic on port 25 except to their own relay... > By using a local SMTP server to proxy, your app can > queue up a large amount of mail in a much shorter period. It won't > necessarily go out any faster, but at least your app won't be tied up > waiting for the mail to be accepted. So there is perhaps one useful > (beyond learning and fun) application for using a local SMTP server. It would be interesting what the intention of the OP is. I just stumpled upon a similar problem. The prog I'm currently working on has a function to report crashes back to me. Originally these reports where sent by mail - no problem on UNIX/Linux hosts where you can assume to have a working MDA on localhost. But what to do on Windows systems?!? Ask for a SMTP server during installation? Confusing as the program itself is totally unrelated to email. In this case you _could_ deliver the mail directly to my MX host... But instead of this I installed a small CGI on my website that sends the mails to me and gets the data via HTTP POST from my app. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From jurgenex at hotmail.com Thu Aug 11 22:12:49 2005 From: jurgenex at hotmail.com (Jürgen Exner) Date: Fri, 12 Aug 2005 02:12:49 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: Xah Lee wrote: > Jargons of Info Tech industry > > (A Love of Jargons) > > Xah Lee, 2002 Feb > > People in the computing field like to spur the use of spurious > jargons. The less educated they are, the more they like extraneous [...] Just for the records at Google et.al. in case someone stumbles across Xah's masterpieces in the future: Xah is very well known as the resident troll in many NGs and his 'contributions' are less then useless. Best is to just ignore him. But for heaven's sake unless you want to embarrass yourself really badly don't take any of his postings serious because he has proven again and again that he has no clue whatsoever about computer science or programming. jue From wouter at voti.nl Fri Aug 26 03:47:09 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Fri, 26 Aug 2005 07:47:09 GMT Subject: Should I move to Amsterdam? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> Message-ID: <430ec8be.1707977111@news.xs4all.nl> >True. Unless you have two proper locks. In that case your bike will >last a very long time. Nope. You will probably retrieve your two locks from the fencing you attached them to (if you did!), with your bike gone. Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From could.net at gmail.com Sun Aug 14 10:24:08 2005 From: could.net at gmail.com (could ildg) Date: Sun, 14 Aug 2005 22:24:08 +0800 Subject: How can I exclude a word by using re? Message-ID: <311b5ce1050814072453682c9d@mail.gmail.com> In re, the punctuation "^" can exclude a single character, but I want to exclude a whole word now. for example I have a string "hi, how are you. hello", I want to extract all the part before the world "hello", I can't use ".*[^hello]" because "^" only exclude single char "h" or "e" or "l" or "o". Will somebody tell me how to do it? Thanks. From jeffrey.schwab at rcn.com Sat Aug 13 11:28:36 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sat, 13 Aug 2005 11:28:36 -0400 Subject: Spaces and tabs again In-Reply-To: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Hello, I know this topic was discussed a *lot* in the past, sorry if it > bores you... > >>From the Daily Python-URL I've seen this interesting Floating Point > Benchmark: > http://www.fourmilab.ch/fourmilog/archives/2005-08/000567.html > > This is the source pack: > http://www.fourmilab.ch/fbench/fbench.zip > > I've read its Python sourcecode, probably there few things that can be > changed to speed it up some (like moving the main code in a function, > using Psyco, or even vectorizing it with numarray), but I've had > problems in changing the code because it mixes tabs and spaces for the > indentations. > I like a lot how Python uses indentations, I've never had problems with > them in my programs, but I have big problems when I find a source that > mixes them (I often need time to find how much spaces a tab is, to try > to convert them all in spaces). > I know that some people likes tabs, and other people likes spaces, so > probably a single standard cannot be enforced, but I think the python > compiler must generate an error (and stop compiling) when the > sourcecode of a module contains both spaces and tabs to indent the > lines of code (and comments lines too?). What's wrong with mixing spaces and tabs? Either way, it's pretty easy to convert back & forth. In Vim: :set expandtab :%retab From simon.brunning at gmail.com Wed Aug 17 04:22:03 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Wed, 17 Aug 2005 09:22:03 +0100 Subject: [Python-Dev] implementation of copy standard lib In-Reply-To: <1124220277.8589.9.camel@localhost.localdomain> References: <1124059680.11612.9.camel@localhost.localdomain> <8c7f10c605081607305068cad6@mail.gmail.com> <1124220277.8589.9.camel@localhost.localdomain> Message-ID: <8c7f10c605081701221a5f464b@mail.gmail.com> On 8/16/05, Martijn Brouwer wrote: > Well, I guess making a deep copy of an object is important in many case. > Just try this: > A=[] > B=A > A.append("foo") > print B > > Guess the output. It is: > ['foo'] I remember thinking that this behavior was odd when I learned Java many years ago. (Java shares this behavior, and I learned it before Python. In fact, I think that many OO languages behave this way - JavaScript, C#, and so on.) But these days, it's 2nd nature. I also thought that it might be dangerous, but now I know that it hardly ever is. (When is it dangerous? Well, if you are trying to build an immutable class, you have to be careful not to pass out references to mutable attributes.) > In many cases this is undesirable, so you need to make a deep copy using > something as B=copy.deepcopy(A). This is where we differ. I know that it's *occasionally* useful to be able to copy or deep-copy an object - that's why the copy module is there. But I find that it's not "many cases" - it's actually rather rare. Shallow copies of dictionaries and (especially) lists are a little less rare, but you can make those without the copy module: new_list = list(old_list) # or old_list[:] new_dict = dict(old_dict) # or old_dict.copy() -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From tjreedy at udel.edu Sun Aug 7 18:37:42 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 7 Aug 2005 18:37:42 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com><11f84j8elj07271@news.supernews.com><861x57wrui.fsf@bhuda.mired.org><11f9f9u2enfsi58@news.supernews.com><11f9u843r0fts5b@news.supernews.com><86br4avf5t.fsf@bhuda.mired.org> <11fakjctean9u8a@news.supernews.com> Message-ID: "John Roth" wrote in message news:11fakjctean9u8a at news.supernews.com... > http://martinfowler.com/articles/languageWorkbench.html This clarified your proposal for Python considerably. So I note that now and especially once the AST compiler is completed, you are quite free to start a Python AST Extension (PASTE) project quite independently of Guido and the PSF developers. Build an AST-based editor like Fowler described, with transient text presentations. (And pick your preferred GUI for doing so.) Or design a system for translating domain-specific languages into PyASTs, from whence they can be compiled to bytecode and run. Terry J. Reedy From mwm at mired.org Sun Aug 28 18:55:08 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 28 Aug 2005 18:55:08 -0400 Subject: Writing portable applications References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> <3ndociF11gd3U1@individual.net> Message-ID: <86acj1y8mr.fsf@bhuda.mired.org> Ulrich Hobelmann writes: > Mike Meyer wrote: >>> I'd rather develop a native client for the machine that people >>> actually WANT to use, instead of forcing them to use that >>> little-fiddly web browser on a teeny tiny display. >> You missed the point: How are you going to provide native clients for >> platforms you've never heard of? > Who says I have to? With open protocols, everybody can. I know many > platforms that STILL don't have a browser that would work with most > websites out there. They all have NNTP, SMTP and POP > clients. Text-mode, GUI-mode, your choice. The people who are distributing applications via the web. You want to convince them to quit using web technologies, you have to provide something that can do the job that they do. >>> And again: connections might be slow, a compact protocol is better >>> than loading the whole UI every time. And while Ajax might work, >>> despite the UI being maybe too big for the little browser window, and >>> even if it works, it's still probably more work than a simple, native >>> UI. First of all it needs to load all the JS on first load, secondly >>> sometimes for a flexible UI you'd have to replace huge parts of the >>> page with something else. Native UIs are more up to the task. >> I'm not arguing that native UI's aren't better. I'm arguing that web >> applications provide more portability - which is important for some >> applications and some developers. > Like Java provides more portability. Unless you ran NetBSD in 2003 > (there was no Java back then that worked for me), hm, IRIX?, Plan9, > BeOS the list goes on... LOTS of platforms don't have the manpower to > develop a client that renders all of the huge bloated wagonload of W3C > tech that was only designed for *markup* from the beginning. I'm still waiting for an answer to that one - where's the Java toolkit that handles full-featured GUIs as well as character cell interfaces. Without that, you aren't doing the job that the web technologies do. >>> I just wonder who wrote fully standards compliant web browsers for >>> those 90 platforms. >> Nobody. I doubt there's a fully standards compliant web browser > Nobody, huh? Then how could you run just ANY web application on those > platforms? The same way you write POSIX applications in the face of buggy implementations - by working around the bugs in the working part of the implementation, and using conditional code where that makes a serious difference. >> available for *any* platform, much less any non-trivial collection of >> them. You write portable web applications to the standards, and design >> them to degrade gracefully. Then you go back and work around any new > Oh right, they degrade gracefully. So without Javascript or cookies > (the former is often not implemented) you get a HTML page with an > error notice -- if you're lucky. You left off the important part of what I had to say - that the application be written by a moderately competent web author. > A server AND client for a simple protocol designed for its task > (i.e. not FTP for instance) can be implemented in much less work than > even designing even part of a web application backend that does that > kind of stuff. Well, if it that easy (and web applications are dead simple), it should be done fairly frequently. Care to provide an example? >> You think you're done. A lot of developers think you can stop with >> the >> first one or two. You're all right for some applications. For others, >> you're not. Personally, I like applications that run on all the >> platforms I use - and your set doesn't cover all three of those >> systems. > Ok, I'd be interested to hear what those are. VMS, RiscOS, Mac OS 9...? FreeBSD, OS X and a Palm Vx. > If a system's scheduler, or select implementation sucks, though, I'd > complain to the vendor or simply abandon the platform for > another. Competition is good :) Complaining to the vendor doesn't always get the bug fixed. And refusing to support a platform isn't always an option. Sometimes, you have to byte the bullet and work around the bug on that platform. >> same thing applies to threads, except such code typically includes a >> third option of not using threads at all. And so on. > Well, who doesn't do threads after several years of POSIX IMHO can't > be taken seriously. Ok, the BSDs didn't until recently, but those are > volunteer projects. Not all platforms are POSIX. If you're ok limiting your application to a small subset of the total number of platforms available, then there's no advantage to using web technologies. Some of us aren't satisifed with that, though. >> And we haven't even started talking about the build process... > If the libraries are installed, just build and link it (if you use > standard C, POSIX + 3rd party libs that do the same). If not, then > tough luck -- it couldn't even run in theory then. You have to have the right build tool installed. Since you use BSD, you've surely run into typing "make" only to have it blow up because it expects gmake. >>>> Of course, considering the state of most of the HTML on the web, I >>>> have *no* idea why most of them are doing this. >>> Yep. Maybe it would be best to reengineer the whole thing as ONE UI >>> spec+action language, incompatible with the current mess, compact, so >>> it can be implemented with minimum fuss. And most of all, I wouldn't >>> use a MARKUP language, as a real application is not text-based (at >>> least not as characteristic #1). >> You mean most of the applications I run aren't real applications? >> Right now, my desktop has exactly two GUI applications open on it - a >> mixer and gkrellm. Everything else is characeter based. Hell, even my >> window manager is character based. > I meant not using text elements. Of course it includes text, in your > case predominantly. But even most curses clients have other elements > sometimes, like links. A standard spec language could cater easily > for text clients, but a text language like HTML has a harder time to > cater for good GUI clients. Most apps I use have buttons and menus > that I wouldn't want to express with markup (and web pages that try to > do that most invariably suck). Well, marking up text is a pretty poor way to describe a UI - but anything that is going to replace web technologies has to have a media-independent way to describe the UI. One of the things that made the web take off early was that anyone with a text editor could create web pages. I think that's an important property to keep - you want the tools that people use to create applications be as portable/flexible as the applications. Since most GUI's are written in some programming language or another, and most programming langauges are still flat text, a GUI description as flat text exists for most GUIs, so this requirement isn't a handicap. >> I think you're right - a web standard designed for writing real >> applications probably wouldn't start life as a markup for text. The >> only thing I can think of that even tries is Flash, but it's >> proprietary so I don't know much about it. > Java has been mentioned in the other response, but there's also all > other kinds of application frameworks. Only XUL is markup based, with > the effect that there's almost no text at all between the markup tags > I guess ;) You don't have to guess - finding examples of XUL isn't hard at all. I think XML gets used in a lot of places where it isn't appropriate. One of the few places where it is appropriate is where you want a file format that lots of independent implementations are going to be reading. This could well be one of those times. >> Care to tell me how you would design such a format if the goal were to >> *not* lose any portability - which means it has to be possible to >> design interfaces that work properly on character devices, things like >> Palms three-color greyscale displays, and devices without pointers or >> without keyboards, or even in an audio-only environment. > Colors can be sampled down. Even the new Enlightenment libs do that > (they say). For mapping a GUI client to a text client, ok, tough. > Face it, lots of things just can't be expressed in pure text. Images, > PDF viewing, video, simulation with graphical representations... Applications aren't one of those things. Even applications that work with those things don't need GUI interfaces. > Pointers could be added to any kind of machine, and even without it, > you could give it a gameboy-style controller for cursor movement > (i.e. arrow keys). Yeah, if you're willing to tell your potential users "Go out and buy more hardware". If you're Microsoft, you probably do that with the addendum "from us". Not being Microsoft or a control freak, I want applications that work with whatever the users already have. > I'm just not talking about a language for audio- and text-mode clients ;) Then you're not talking about replacing HTML et. al. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fakeaddress at nowhere.org Fri Aug 12 00:08:42 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 04:08:42 GMT Subject: Bug in slice type In-Reply-To: <42fc0f1f@news.eftel.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <42fc0f1f@news.eftel.com> Message-ID: John Machin wrote: > Steven Bethard wrote: [...] >> BTW, a simpler example of the same phenomenon is: >> >> py> range(10)[slice(None, None, -2)] >> [9, 7, 5, 3, 1] >> py> slice(None, None, -2).indices(10) >> (9, -1, -2) >> py> range(10)[9:-1:-2] >> [] >> > > >>> rt = range(10) > >>> rt[slice(None, None, -2)] > [9, 7, 5, 3, 1] > >>> rt[::-2] > [9, 7, 5, 3, 1] > >>> slice(None, None, -2).indices(10) > (9, -1, -2) > >>> [rt[x] for x in range(9, -1, -2)] > [9, 7, 5, 3, 1] > >>> > > Looks good to me. indices has returned a usable (start, stop, step). > Maybe the docs need expanding. But not a usable [start: stop: step], which is what 'slice' is all about. -- --Bryan From danieldsmith at gmail.com Thu Aug 11 15:09:29 2005 From: danieldsmith at gmail.com (danieldsmith at gmail.com) Date: 11 Aug 2005 12:09:29 -0700 Subject: thread limit in python In-Reply-To: <1123786825.344176.93620@g14g2000cwa.googlegroups.com> References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> Message-ID: <1123787369.191604.237120@o13g2000cwo.googlegroups.com> disregard the C example. wasn't checking the return code of pthread_create. the C program breaks in the same place, when creating the 1021st thread. From lists at nomis52.net Wed Aug 17 02:29:43 2005 From: lists at nomis52.net (Simon Newton) Date: Wed, 17 Aug 2005 14:29:43 +0800 Subject: Embedding Python in C, undefined symbol: PyExc_FloatingPointError Message-ID: <1124260183.5033.15.camel@localhost.localdomain> Hi, I've just starting out embedding Python in C and get the following error when I try and import a module that in turn imports the math module. ImportError: /usr/lib/python2.4/lib-dynload/math.so: undefined symbol: PyExc_FloatingPointError The module is as follows: # begin script.py import math def fn(i): print "i is %d" % i # end script.py and the C code is : // start main.c #include int main(int argc, char *argv[]) { PyObject *mymod, *fn, *strargs; Py_Initialize(); mymod = PyImport_ImportModule("script"); if(mymod == NULL) { PyErr_Print(); exit(1); } fn = PyObject_GetAttrString(mymod, "fn"); if(fn == NULL) { PyErr_Print(); exit(1) ; } strargs = Py_BuildValue("(i)", 0); PyEval_CallObject(fn, strargs); Py_Finalize(); return 0; } // end main.c Testing script.py by running python and importing the module works fine. Commenting out the import math statement and import other modules (sys, string etc) work fine. The C program is being built like so: gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes gcc main.o -L/usr/lib -lpthread -ldl -lutil -lm /usr/lib/python2.4/config/libpython2.4.a -o main I've tried the above on two machines, one Debian stable and the other Debian testing. Same results on both. It's like I'm missing a library or something, any ideas ? Cheers, Simon Newton From max at alcyone.com Sun Aug 28 15:29:22 2005 From: max at alcyone.com (Erik Max Francis) Date: Sun, 28 Aug 2005 12:29:22 -0700 Subject: Release of PyPy 0.7.0 In-Reply-To: References: Message-ID: Carl Friedrich Bolz wrote: > pypy-0.7.0: first PyPy-generated Python Implementations > ============================================================== > > What was once just an idea between a few people discussing > on some nested mailing list thread and in a pub became reality ... > the PyPy development team is happy to announce its first > public release of a fully translatable self contained Python > implementation. The 0.7 release showcases the results of our > efforts in the last few months since the 0.6 preview release > which have been partially funded by the European Union: Cool. I just tested EmPy's regression suite with PyPy 0.7.0, and it ran fine (though obviously it was very slow). Nice job so far, guys! -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis It is fatal to enter any war without the will to win it. -- Douglas MacArthur From pwatson at redlinepy.com Tue Aug 16 16:26:29 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Tue, 16 Aug 2005 15:26:29 -0500 Subject: String functions deprication In-Reply-To: References: Message-ID: <43024BF5.4080304@redlinepy.com> steve morin wrote: > http://www.python.org/doc/2.4.1/lib/node110.html > > These methods are being deprecated. What are they being replaced > with? Does anyone know? > > Steve It might be helpful to compare the following lists. Python 2.1 (#1, May 23 2003, 11:43:56) [C] on aix4 Type "copyright", "credits" or "license" for more information. >>> import string >>> dir(string) ['_StringType', '__builtins__', '__doc__', '__file__', '__name__', '_float', '_idmap', '_idmapL', '_int', '_long', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill'] >>> s = "now" >>> dir(s) ['capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper'] >>> for m in dir(string): ... if m not in dir(s): ... print m ... _StringType __builtins__ __doc__ __file__ __name__ _float _idmap _idmapL _int _long atof atof_error atoi atoi_error atol atol_error capwords digits hexdigits index_error joinfields letters lowercase maketrans octdigits printable punctuation splitfields uppercase whitespace zfill >>> for m in dir(s): ... if m not in dir(string): ... print m ... encode endswith isalnum isalpha isdigit islower isspace istitle isupper splitlines startswith title From sklass at pointcircle.com Wed Aug 3 22:38:30 2005 From: sklass at pointcircle.com (rh0dium) Date: 3 Aug 2005 19:38:30 -0700 Subject: Mass importing of a template based system.. Trouble with name substitutions Message-ID: <1123123110.255400.145060@g44g2000cwa.googlegroups.com> Hi all, Basically I have a bunch of pluggins in a directory (METDIR). For each one of these templated pluggins I want to do a specific routine. Let's start with a basic template file example1.py ---------------- class example1: def __init__(self): print "Initialize" def run(self): print "Hi from example 1" ---------------- file example2.py ---------------- class example2: def __init__(self): print "Initalize" def run(self): print "example 2" ---------------- Now I want to go through each pluggin ( example1.py and example2.py ) and execute run. So here is my code but it doesn't work.. if os.path.isdir(METDIR): modules = [] # Add the metrics dir toyour path.. sys.path.insert( 0, os.getcwd() + "/" + METDIR ) for metric in glob.glob(METDIR+"/*.py"): # Now lets start working on the individual metrics module_name, ext = os.path.splitext(os.path.basename(metric)) try: module = __import__(module_name) modules.append( module ) except ImportError , e: print "Failed import of %s - %s" % ( module_name, e) pass for mod in modules: a = mod.mod() a.run() But it doesn't work with the following.. Traceback (most recent call last): File "./metriX.py", line 109, in main a = mod.mod() AttributeError: 'module' object has no attribute 'mod' So it looks like it's not doing the substitution. Does anyone know how I can do this? Thanks much From accepted at ukr.net Tue Aug 2 03:15:42 2005 From: accepted at ukr.net (Michael Rybak) Date: Tue, 2 Aug 2005 10:15:42 +0300 Subject: need for speed In-Reply-To: <91vte19had2jl6io5l0458chc6uvehe7t3@4ax.com> References: <1122888516.815400.116220@f14g2000cwb.googlegroups.com> <91vte19had2jl6io5l0458chc6uvehe7t3@4ax.com> Message-ID: <24348422.20050802101542@ukr.net> sorry for emailing privately, pressed the wrong "reply" button DLB> On Mon, 1 Aug 2005 20:14:51 +0300, Michael Rybak DLB> declaimed the following in comp.lang.python: >> >> Is there a way of profiling other than manual (debug output with DLB> Chapter 10 of the Python Library Reference... You have looked at DLB> that document, haven't you? Already am, yes! >> measurements and all)? Some tools? And is there some kind of plugin >> for native Python's IDLE to trace scripts? I'm a bit tired of getting DLB> Have you read Chapter 9? ok, I'm looking through. A bit tough for me I think, I can live with debug outputs :) Well I'm too much used to M$ V$ / Borland Delphi interfaces to switch to almost-asm-like debugging. DLB> BTW: if you are working on M$ Windows, only on that DLB> you might want to consider installing the ActiveState release I tried, and the installer gives me that stupid Internal Error 2229: Control, SELECT 'Control', 'Type', 'X', 'Y', [..snip..], 'Dialog' = ? And I forgot the OK button. DLB> -- PythonWin might be nicer than IDLE (and has the referenced DLB> manuals formatted as Windows help files). I am using a *.chm file containing all online documentation available from python.org DLB> -- DLB> > ============================================================== < DLB> > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < DLB> > wulfraed at dm.net | Bestiaria Support Staff < DLB> > ============================================================== < DLB> > Home Page: < DLB> > Overflow Page: < -- Best Regards, Michael Rybak mailto:accepted at ukr.net From saqib at saqibali.org Mon Aug 8 01:28:46 2005 From: saqib at saqibali.org (saqib at saqibali.org) Date: 7 Aug 2005 22:28:46 -0700 Subject: How to change pymssql timeout value? Message-ID: <1123478925.886923.58180@f14g2000cwb.googlegroups.com> I have a query that is running on a mssql DB that takes about 15 minutes when run "directly"; IE: thru MS SQL Query Analyzer. I know, it sucks. I'm trying to fix it. But in the meantime, I have a python process which connects to the DB using pymssql. This process runs the aformentioned query... but fails because the query times out after approx 30 seconds. Is there anyway to change/set the timeout setting on a pymssql DB connection?? I poked around a bit in the pymssql module but nothing was obvious to me..... -Saqib From onurb at xiludom.gro Wed Aug 10 11:54:51 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 10 Aug 2005 17:54:51 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <42fa234d$0$7831$626a14ce@news.free.fr> Neil Benn wrote: (snip) > If you don't have a class how can you combine functionality with data > and hold state In Python, functions can hold state in various ways: closures, generators, and - Python functions being instances of the function class - attributes. > - that is one of the points of a class. Yeps, but not the only way to solve the problem (even if it's actually my favorite one !-) (snip) > Enterprise systems have different objectives than a cgi script or single > client install stuff. Would you call Zope a cgi script or a single client install stuff ? -- bruno desthuilliers ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@')" From claird at lairds.us Fri Aug 12 20:08:04 2005 From: claird at lairds.us (Cameron Laird) Date: Sat, 13 Aug 2005 00:08:04 GMT Subject: UCALC equivalent References: <42fcea4a$1@nntp0.pdx.net> Message-ID: <8vnvs2-7ll.ln1@lairds.us> In article , Max Erickson wrote: . . . >> The python equivalent: >> >> exec "def area(length,width): return length*width" >> exec "def frac(x): return abs(abs(x) - int(abs(x)))" >> exec "def test(): return 5" >> exec "def abc(x, y=10): return x + y" >> exec "def shl(x, y): return x * 2^y" >> >> print eval("frac(150/17) * area(20,30)") >> print eval("abc(5) - abc(3,4) * shl(0x0E, 1)") >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org >> > >Ouch, I sure was wrong. You did such a good job making me look >foolish that it was mentioned in Python-URL!. At least Larry Bates >had the grace not to call me an idiot. > >max "Python-URL!" makes a point of highlighting positive achievements. We all create enough foolishness to obviate any need to pass *that* on. From kay.schluehr at gmx.net Sun Aug 21 04:29:50 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 21 Aug 2005 01:29:50 -0700 Subject: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: <1124612990.362407.87670@g43g2000cwa.googlegroups.com> Bryan Olson wrote: > Steven Bethard wrote: > > Well, I couldn't find where the general semantics of a negative stride > > index are defined, but for sequences at least[1]: > > > > "The slice of s from i to j with step k is defined as the sequence of > > items with index x = i + n*k such that 0 <= n < (j-i)/k." > > > > This seems to contradict list behavior though. [...] > > The conclusion is inescapable: Python's handling of negative > subscripts is a wart. Indexing from the high end is too useful > to give up, but it should be specified by the slicing/indexing > operation, not by the value of the index expression. It is a Python gotcha, but the identity X[-1] == X[len(X)-1] holds and is very usefull IMO. If you want to slice to the bottom, take 0 as bottom value. The docs have to be extended in this respect. Kay From renting at astron.nl Wed Aug 17 03:05:29 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 17 Aug 2005 09:05:29 +0200 Subject: Read from stdouton Popen on WinXP? Message-ID: The only way I know how to do this is using a pseudo terminal (pty), but I think that only works on Unix. The problem is the way stdout in C works: - If connected to a character device, it will flush after each line. - If connected to a block device it will flush only after it's buffer is full. Any kind of pipe or file is a block device. As this is how stdout works even your OS can't help, because as long as the application doesn't flush, the output doesn't even arrive at the pipe or file. If you have access to the source of the application you can force it to flush, otherwise you'll need to find out if anything similar to pty exists in Windows. I have 3 years of Windows programming experience, but I don't know of any solution. This probably also means your solution of piping the .exe will not work. Adriaan Renting. >>> "mhenry1384" 08/16/05 11:48 PM >>> I am trying to run a program and filter the output on Windows XP. Since I want to filter the output, I'd like to read it a line at a time and only print the lines I care about. p = subprocess.Popen(["doxygen.exe", r"Doxyfile.cfg"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while 1: line = p.stdout.readline() if not line: break print line The problem is that readline() only returns after the whole process has completed. I have tried various permutations such as using os.read() and changing the bufsize parameter and using popen4. To no avail. Obviously, it should be possible to read stdout before the process completes, since if I leave off the "stdout=" parameter, the full output shows up in stdout in "realtime" as you'd expect. About the only thing I can come up with is to pipe the .exe to another python script which could communicate to the main script via TCP/IP, but that seems ridiculous. I searched the newsgroup and didn't see anything particularly helpful. Anyone have a non-ridiculous solution? -- http://mail.python.org/mailman/listinfo/python-list Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ From noreply at gcgroup.net Wed Aug 31 23:30:21 2005 From: noreply at gcgroup.net (William Gill) Date: Thu, 01 Sep 2005 03:30:21 GMT Subject: graphical or flow charting design aid for python class development? In-Reply-To: <1125516416.486773.78270@z14g2000cwz.googlegroups.com> References: <8ckRe.3276$v83.327@newssvr33.news.prodigy.com> <1125516416.486773.78270@z14g2000cwz.googlegroups.com> Message-ID: On first glance Doxygen doesn't look like the ticket, but the screen shots of Eric3 look VERY promising. I have already downloaded it, and will try it. Thanks, Bill tooper wrote: > You may want to use Doxygen, which generates nice diagrams. It's > normally only for C++, but there are nice filters (for ex. > http://i31www.ira.uka.de/~baas/pydoxy) that generates C++ header from > python code that Doxygen can crunch. > > Another solution is to use IDE such as Eric3 that can generate UML > diags from source code on the fly. > From cantabile.03 at wanadoo.fr Mon Aug 8 11:01:21 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Mon, 08 Aug 2005 17:01:21 +0200 Subject: gettext again In-Reply-To: References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> Message-ID: <42f773c1$0$25062$8fcfb975@news.wanadoo.fr> stasz a ?crit : > Your steps seems alright. > Just a thought; you do start test1.py from a fr_FR at euro > environment do you? > I mean in a xterm do: export LANG=fr_FR at euro > And then start test1.py from there. > > Stas Whoooot ! Working at last, after three days... It wasn't the LANG param which is fr_FR at euro allright. I inadvertantly suppressed the '.mo' part of gettext.install(test1.mo') and it just worked. I guess gettext was looking for a 'test1.mo.mo' file or something. Anyways, you made my day my friend ! Many many thanks ! From bill.pursell at gmail.com Fri Aug 12 02:26:47 2005 From: bill.pursell at gmail.com (bill) Date: 11 Aug 2005 23:26:47 -0700 Subject: signals (again) References: <1123713622.727375.206270@f14g2000cwb.googlegroups.com> Message-ID: <1123828006.991996.137660@g47g2000cwa.googlegroups.com> I found a good solution to this problem in Richard Steven's _Network_Programming_. It seems like everything shows up in Steven's books! Rather than pausing, you do a blocking read on a pipe. You only write to the pipe from within the signal handler. However, this brings up the better question: why was 'pause' ever implemented? No matter what you do, the signal that you expect to wake you up may occur immediately prior to the pause, and you'll miss it. Starting that question in a new thread. From peterbe at gmail.com Tue Aug 2 11:48:36 2005 From: peterbe at gmail.com (peterbe at gmail.com) Date: 2 Aug 2005 08:48:36 -0700 Subject: time.clock() or time.time() Message-ID: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> What's the difference between time.clock() and time.time() (and please don't say clock() is the CPU clock and time() is the actual time because that doesn't help me at all :) I'm trying to benchmark some function calls for Zope project and when I use t0=time.clock(); foo(); print time.clock()-t0 I get much smaller values than when I use time.clock() (most of them 0.0 but some 0.01) When I use time.time() I get values like 0.0133562088013, 0.00669002532959 etc. To me it looks like time.time() gives a better measure (at least from a statistical practical point of view). From sklass at pointcircle.com Mon Aug 29 17:13:21 2005 From: sklass at pointcircle.com (rh0dium) Date: 29 Aug 2005 14:13:21 -0700 Subject: Using select on a unix command in lieu of signal In-Reply-To: <7xr7ccv56c.fsf@ruckus.brouhaha.com> References: <1125347796.648556.282610@g43g2000cwa.googlegroups.com> <7xr7ccv56c.fsf@ruckus.brouhaha.com> Message-ID: <1125350001.101171.255060@o13g2000cwo.googlegroups.com> Paul Rubin wrote: > "rh0dium" writes: > > Thanks much - Alternatively if anyone else has a better way to do what > > I am trying to get done always looking for better ways. I still want > > this to work though.. > > You don't have to use select, since you can use timeouts with normal > socket i/o. So you could use threads. 3000 threads is a lot but not > insanely so. OK I could use the timeout.. but I am using a queue as well. So each thread gets several commands. I assumed (could be wrong) that if I use a timeout the whole thread gets killed not the individual process. The purpose of the queue was to limit the number of concurrent workers, and keep the load on the machine somewaht manageable. So to add more to this here is how I call the runCmd # Initialize a que to 25 max hosts workQ = Queue.Queue(25) # Start some threads.. for i in range(MAX_THREADS): getReachableHosts(queue=workQ).start() # Now give the threads something to do.. The nice thing here is that by # waiting unil now this will hold up the queue.. for host in base_hosts: workQ.put(host) # After this is finally done thow a null to close the threads.. for i in range(MAX_THREADS): workQ.put(None) And then getReachables.. class getReachableHosts(threading.Thread): def __init__(self,queue=None, ): self.logger = logging.getLogger("metriX.%s" % self.__class__.__name__) self.logger.info("Initializing class %s" % self.__class__.__name__) self.__queue = queue threading.Thread.__init__(self) def run(self): self.logger.debug("Initializing function %s" % sys._getframe().f_code.co_name ) while 1: host = self.__queue.get(timeout=5) if host is None: break self.logger.debug("Getting open ports on %s" % host) command = "nmap -p 22,514 -oG - %s | perl -lane 'print unless /^#/'" % host (out,results)=self.runCmd(cmd=cmd,timeout=5) Much appreciate the advice and help!! From whereU at now.com Sun Aug 7 04:54:06 2005 From: whereU at now.com (Eric Pederson) Date: Sun, 7 Aug 2005 00:54:06 -0800 Subject: Python -- (just) a successful experiment? Message-ID: <20050807005406.1217660123.whereU@now.com> Raise your hand if you think the best technology wins! For those of you with your hands in the air, tell me: if Python is so good, why has PHP achieved such greater adoption and mindshare? Why do web scripters still cling to their Perl, even in corporate environments? Why hasn't Python made inroads against Java? Why is Ruby, and Ruby on Rails, getting such strong play? Are these better programming languages, or is it other factors? On a whim I installed Ruby on Rails today - pretty much a one-click deal. It was a very slick (Windows) installation, as it automatically figured out and downloaded dependencies - there was no question it was properly installed, and I ended up with a couple "IDE"s for Ruby, examples, etc. Markedly better than installing Python - no contest - and this downloaded a useful and easy to employ application, with a clear path to show me how to use it. As I perused the tutorial like documentation, I realized I wasn't anxious to jump into the language (Ruby), but I saw that I could certainly achieve a quicker success putting together a web application with RoR than with (take your pick: Perl, Lisp, Java, etc. etc.) If my mind wasn't appreciative of the Python language, though, Ruby would have hooked me right there. While I perceive that the future of the language Python is in good development hands - well debated, and thoughtfully strategized; the Python accoutrements can be lacking. Imagine, if you will, a new car, that does 0-60 in 2 seconds, 60-0 in .2 seconds, has a top speed of 185 mph, corners on par with an F-1 car, costs no more than a Volkswagen Passat... but comes without tires or seats, and you have to install the electrics and brakes yourself. Sure, car geeks are going to love it, but you just are not going to see that many at the grocery store, or doing car pool duty, and no garage really works on them much... forget about finding parts, you have to make your own replacements. I am not saying Python is that car, but I do think that "Python", as opposed to "Python the computer language specification", is done a great disservice by the lack of certain accoutrements. I do not know if there are features of the language (specification or philosophy) which thwart the development of the complementary items, but I firmly believe that the lack of them is a factor in Python's ho-hum adoption rate. A good computer language is great, but it pales in comparison with what can be done with such a language. What is missing? Maybe: -- Automatic dependency handling -- Tightly coupled GUI package ("tightly coupled" ~= "Pythonic") -- High level IDE (i.e. intuitive drag and drop GUI builder) -- High level database framework (perhaps a mature, killer Dabo) -- Powerful web framework as good as the language (and simple enough for the PHP guys to use) -- Etc. Applications like Zope and Plone help drive more people toward the language, though the competition is stiff. Dozens of competing half baked tools/applications... they just confuse people and take up their time with decision paralysis, though they may be fun to write. Is it wrong to appreciate Python as a language, but want to have the nice accoutrements we see in some competing languages? EP Disclaimer: only recently downloaded Eric3 for Windows, and it looks good, but I haven't had time to learn it yet. Whatsup with the troll, though? :::::::::::::::::::::::::::::::::: domainNot="@something.com" domainIs=domainNot.replace("s","z") ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs ::::::::::::::::::::::::::::::::::: From paolo_veronelli at yahoo.it Thu Aug 11 10:27:39 2005 From: paolo_veronelli at yahoo.it (Paolo Veronelli) Date: Thu, 11 Aug 2005 16:27:39 +0200 Subject: set of sets In-Reply-To: References: Message-ID: <42FB605B.6050300@yahoo.it> Matteo Dell'Amico wrote: > Paolino wrote: > >>I thought rewriting __hash__ should be enough to avoid mutables problem >>but: >> >>class H(set): >> def __hash__(self) >> return id(self) >> >>s=H() >> >>f=set() >> >>f.add(s) >>f.remove(s) >> >>the add succeeds >>the remove fails eventually not calling hash(s). > > > Why don't you just use "frozenset"? > And mostly with sets remove operation expense should be sublinear or am I wrong? Is this fast as with lists? Obviously if I use the ids as hash value nothing is guaranted about the objects contents to be unique but I don't care. My work is a self organizing net,in which the nodes keep a structure to link other nodes.As the nature of the net,the links are moved frequently so remove and add operations and contains query should be optimized. Why objects need to be hashable for this? Isn't __hash__ there to solve the problem? PS Looks like the problem is not present in class sets.Set ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From peter at engcorp.com Wed Aug 31 09:13:39 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 31 Aug 2005 09:13:39 -0400 Subject: Sockets: code works locally but fails over LAN In-Reply-To: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> Message-ID: n00m wrote: > import socket, thread > host, port = '192.168.0.3', 1434 > s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s2.connect((host, 1433)) > s1.bind((host, port)) > s1.listen(1) > cn, addr = s1.accept() > > def VB_SCRIPT(): > while 1: > data = cn.recv(4096) > if not data: return > s2.send(data) > print 'VB_SCRIPT:' + data + '\n\n' > > def SQL_SERVER(): > while 1: > data = s2.recv(4096) > if not data: return > cn.send(data) > print 'SQL_SERVER:' + data + '\n\n' Several suggestions: 1. Use repr(data) instead of just 'data' above, to see better the actual bytes without the possibility of control characters like \r and \b screwing things up. 2. I'm not at all sure that accessing the same socket object simultaneously from two threads is safe. You might consider creating a pair of Queue objects to safely communicate the information between the two threads. That, of course, poses the problem of how do you wait on data to arrive from the socket and from the Queue at the same time. One approach is to use non-blocking sockets or timeouts, while the other is to use a pre-existing asynchronous framework such as, say, Twisted, and avoid reinventing the wheel (and making all the same mistakes that other programmers have made zillions of times before you). It's also possible this is not remotely related to your problem, but I suspect without knowing more about SQL Server, VB, and your own setup I'd be guessing wildly anyway... -Peter From harlinseritt at yahoo.com Wed Aug 10 03:04:39 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: 10 Aug 2005 00:04:39 -0700 Subject: Help with Regular Expressions Message-ID: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> I have been looking at the Python re module and have been trying to make sense of a simple function that I'd like to do. However, no amount of reading or googling has helped me with this. Forgive my stone-headedness. I have done this with .NET and Java in the past but damn if I can't get it done with Python for some reason. As such I am sure it is something even simpler. I am trying to find some matches and have them put into a list when processing is done. I'll use a simple example like email addresses. My input is the following: wordList = ['myname1', 'myname2 at domain.tld', 'myname3 at domain.tld', 'myname4 at domain', 'myname5 at domain.tldx'] My regular expression would be something like '\w\@\w\.\w' (I realize it could and should be more detailed but that's not the point for now). I would like to find out how to output the matches for this expression of my 'wordList' into a neat list variable. How do I get this done? Thanks, Harlin Seritt From jgrahn-nntq at algonet.se Sun Aug 21 03:58:09 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 21 Aug 2005 07:58:09 GMT Subject: >time.strftime %T missing in 2.3 References: Message-ID: On Fri, 05 Aug 2005 01:02:48 -0500, Andy Leszczynski wrote: > Robert Kern wrote: >> Andy Leszczynski wrote: >> >>> Python 2.2/Unix >>> >>> >>time.strftime("%T") >>> '22:12:15' >>> >>time.strftime("%X") >>> '22:12:17' >>> >>> Python 2.3/Windows >>> >>> >>time.strftime("%X") >>> '22:12:47' >>> >> time.strftime("%T") >>> '' >> >> >> From http://docs.python.org/lib/node252.html >> >> """The full set of format codes supported varies across platforms, >> because Python calls the platform C library's strftime() function, and >> platform variations are common.""" >> >> So I suggest that it's a platform issue, not a Python version issue. FWIW: >> >> Python 2.4.1 (#2, Mar 31 2005, 00:05:10) >> [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import time >> >>> time.strftime("%T") >> '22:50:49' >> >>> time.strftime("%X") >> '22:50:59' >> > > I accept that, but still pain. Took me a while to filter out the problem > in the code running on the Unix and not on M$. I can imagine ... By the way, you should probably /not/ change %T to %X. %T (standardized in the Singe Unix Specification) is the same thing as ANSI C %H:%M:%S which should be usable everywhere. %X on the other hand is "The preferred time representation for the current locale without the date". Not the same thing at all, for some users. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From haircut at gmail.com Wed Aug 31 23:53:02 2005 From: haircut at gmail.com (Adam Monsen) Date: 31 Aug 2005 20:53:02 -0700 Subject: "zoning" a naive datetime object / daylight savings References: <1125523943.582080.101730@f14g2000cwb.googlegroups.com> Message-ID: <1125546782.791953.209980@g14g2000cwa.googlegroups.com> Ok, I think I figured this out. Comments/criticisms welcome. ----------------------------------8<---------------------------------- import datetime, os, time from pytz import UTC old_tz = os.environ.get('TZ') os.environ['TZ'] = 'Europe/Amsterdam' time.tzset() dutchDateParts = (2005, 8, 10, 17, 26, 0, 2, 222, -1) timestamp = time.mktime(dutchDateParts) if old_tz: os.environ['TZ'] = old_tz else: del os.environ['TZ'] time.tzset() print datetime.datetime.fromtimestamp(timestamp, UTC) ---------------------------------->8---------------------------------- The 9-integer time tuple could be fetched using the code posted here: http://snipurl.com/hcvs same URL, not snipped: http://groups.google.com/group/comp.lang.python/msg/65d8f116dfd59dd1 -- Adam Monsen http://adammonsen.com/ From sjmachin at lexicon.net Sat Aug 13 22:18:15 2005 From: sjmachin at lexicon.net (John Machin) Date: Sun, 14 Aug 2005 12:18:15 +1000 Subject: Spaces and tabs again In-Reply-To: References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> <6spsf1hr7i0ho9fa0ptauhst1s61jkig13@4ax.com> Message-ID: <42fea9e6$1@news.eftel.com> Dan Sommers wrote: > On Sun, 14 Aug 2005 01:04:04 GMT, > Dennis Lee Bieber wrote: > > >>On 13 Aug 2005 13:18:21 -0700, sigzero at gmail.com declaimed the following >>in comp.lang.python: > > >>>Are you kidding? You are going to MANDATE spaces? >>> >> >> After the backlash, Python 4.0 will ban leading spaces and require >>tabs > > > Why not petition the unicode people to include PYTHON INDENT and PYTHON > DEDENT code points, and leave the display up to the text editors? ;-) > Good idea, Dan. And when you don't want the indented/dedented display, but a repr-like "what's actually there", they could be rendered as little icons of a snake and a ladder respectively. [It's a joke, Joyce.] From peter at engcorp.com Tue Aug 16 09:35:35 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 16 Aug 2005 09:35:35 -0400 Subject: How to obtain GMT offset? In-Reply-To: References: Message-ID: Erik Max Francis wrote: > time.timezone gives you the timezone offset in minutes. Dang, that means I'm twelve days in the past! >>> import time >>> time.timezone 18000 >>> 18000/60 300 (So that would be hours? ;-) ) >>> 18000/60/24 12 Wait up guys! -Peter From apardon at forel.vub.ac.be Tue Aug 16 05:27:10 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 16 Aug 2005 09:27:10 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> Message-ID: Op 2005-08-06, Mike Meyer schreef : > "John Roth" writes: >> wrote in message >> news:1123270841.195692.21470 at g47g2000cwa.googlegroups.com... >> A much better idea would be to fix the underlying >> situation that makes the global statement necessary. > > You can't "fix" this. This code (in some python-like langauge that > isn't python): > > x = 23 > > def fun(): > x = 25 > # Rest of code > > has two possible interpretations. > > Either the occurrence of x in fun references the global, or it > references a local that shadows the global. There are reasons for > wanting both behaviors. So you have to have some way to distinguish > between the two, and you want it to happen per variable, not per > function. The method with the fewest keywords is to have one be the > default, and some keyword that triggers the other. > > So the only way to remove the global statement would be to have some > way to mark the other interpretation, with say a "local" > decleration. I thik that would be much worse than "global". For one > thing, most variables would be local whether or not they are > declared. Second, having an indication that you need to check module > globals in the function is a better than not having that clue there. I disagree here. The problem with "global", at least how it is implemented in python, is that you only have access to module scope and not to intermediate scopes. I also think there is another possibility. Use a symbol to mark the previous scope. e.g. x would be the variable in local scope. @.x would be the variable one scope up. @. at .x would be the variable two scopes up etc. -- Antoon Pardon From russandheather at gmail.com Wed Aug 10 15:01:01 2005 From: russandheather at gmail.com (Qopit) Date: 10 Aug 2005 12:01:01 -0700 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: <1123697696.506898.66580@z14g2000cwz.googlegroups.com> > Why not just find out, by trying to compile it? :-) This will likely certify me as a python newbie, but... how do you mean? How do you compile a .py file? If you mean to .pyc by doing an import on it, that may work fine for the simple example I typed up earlier, but that is easy to bypass by slapping the offending line in a function. The sample below also passes PyChecker with not even a warning: #---- def tester(a,b,c): print "bogus test function",a,b,c def try1(): tester(1,2,3) def try2(): tester(1,2) #still no error here #---- Do you mean something different? Also - thanks for the pylint comment... haven't tried it yet. It would be nice to have the capability in an IDE like SPE, though. From me at privacy.net Wed Aug 24 09:57:50 2005 From: me at privacy.net (Dragan Cvetkovic) Date: Wed, 24 Aug 2005 09:57:50 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <1124816780_7123@spool6-east.superfeed.net> <430c0eed.59907997@news.xs4all.nl> Message-ID: rlb at hoekstra-uitgeverij.nl (Richard Bos) writes: > l v wrote: > >> Mike Schilling wrote: >> > A formatting-only subset of HTML would be useful for both e-mail and Usenet >> > posts. >> >> I would *agree* (your news reader may bold that last word) > > It had bloody better not. You're cross-posting this to a C newsgroup, > where *ptr* 4 is a legal (albeit inadvisably spaced) expression. > Or _ptr_ for that matter (does it underline for you?) Well, at least on my newsreader (gnus), I can toggle the behaviour. Ditto for smileys: (setq gnus-treat-display-smileys nil) Dragan -- Dragan Cvetkovic, To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer !!! Sender/From address is bogus. Use reply-to one !!! From gregpinero at gmail.com Sat Aug 27 12:57:26 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Sat, 27 Aug 2005 12:57:26 -0400 Subject: Embedding Python in other programs In-Reply-To: <1125134294.509755.64030@g43g2000cwa.googlegroups.com> References: <312cfe2b050826084036db598f@mail.gmail.com> <1125134294.509755.64030@g43g2000cwa.googlegroups.com> Message-ID: <312cfe2b050827095711dd1f07@mail.gmail.com> see below On 27 Aug 2005 02:18:14 -0700, webraviteja at gmail.com wrote: > Steve, > He said VB6 not VB.NET > > Greg, > Just write COM servers in Python and call them from VB6. No need to > embed. Lot easier too. > Any idea how I would get started on this? I'll do a search later today. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From CantankerousOldGit at gmail.com Thu Aug 11 15:34:49 2005 From: CantankerousOldGit at gmail.com (Cantankerous Old Git) Date: Thu, 11 Aug 2005 20:34:49 +0100 Subject: how to write thread-safe module ? and pytz In-Reply-To: References: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> Message-ID: Daniel Dittmar wrote: > Dictionaries (and probably most other Python types that are implemented > in C) are inherently thread safe. That sounds like a dangerous assumption to me. Are you relying on the Global Interpreter Lock? Is is guaranteed? Does that safety transfer to Jython? How can I tell if any particular object is thread-safe? I don't know the answers to these questions, and I have the feeling that it is probably best to play safe and always use your own explicit locking. The Cog From rabkin at mweb[DOT]co[DOT]za Sun Aug 21 06:21:11 2005 From: rabkin at mweb[DOT]co[DOT]za (Max) Date: Sun, 21 Aug 2005 12:21:11 +0200 Subject: Python Light Revisted? In-Reply-To: <1124568446.496146.247180@g47g2000cwa.googlegroups.com> References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: Steve M wrote: > I agree with you in part and disagree in part. > > I don't see the point to making the distribution any smaller. 10MB for > the installer from python.org, 16MB for ActiveState .exe installer. How > is 5MB "lightweight" while 10MB isn't? The Windows XP version of Java > at java.com is 16+ MB, and the .NET framework is, well, I don't know > how big, but I doubt it's much less than 10MB. > AFAIR, it's closer to 50MB. --Max From mwh at python.net Tue Aug 2 04:31:27 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 02 Aug 2005 08:31:27 GMT Subject: Is this Pythonic? References: Message-ID: zen19725 at zen.co.uk (phil hunt) writes: > Suppose I'm writing an abstract superclass which will have some > concrete subclasses. I want to signal in my code that the subclasses > will implement certan methods. Is this a Pythonic way of doing what > I have in mind: > > class Foo: # abstract superclass > def bar(self): > raise Exception, "Implemented by subclass" > def baz(self): > raise Exception, "Implemented by subclass" > > class Concrete(Foo): > def bar(self): > #...actual implemtation... > def baz(self): > #...actual implemtation... Well, I guess you know this, but if Foo contains no implementation at all, why inherit from it? It would (possibly) be more Pythonic to define an interface instead, or just use duck typing. Cheers, mwh -- nonono, while we're making wild conjectures about the behavior of completely irrelevant tasks, we must not also make serious mistakes, or the data might suddenly become statistically valid. -- Erik Naggum, comp.lang.lisp From utabintarbo at gmail.com Fri Aug 26 08:05:42 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 26 Aug 2005 05:05:42 -0700 Subject: file access dialog In-Reply-To: References: <430ec9b1.1708219820@news.xs4all.nl> Message-ID: <1125057942.177093.164130@o13g2000cwo.googlegroups.com> For simple, it's hard to beat EasyGUI: http://www.ferg.org/easygui/ Bob From mwm at mired.org Sat Aug 6 21:37:54 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 06 Aug 2005 21:37:54 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> <86br4avf5t.fsf@bhuda.mired.org> <11fakjctean9u8a@news.supernews.com> Message-ID: <863bpmv85p.fsf@bhuda.mired.org> "John Roth" writes: > "Mike Meyer" wrote in message >>> What I want to see in Python 3000 is an AST based language >>> that lets the editors do the pretty printing. Do you want automatic >>> indenting or would you prefer end statements? It's an editor formatting >>> option. The AST neither knows or cares. Don't want to see self? >>> Editor formatting option. The AST knows what scope each >>> identifier belongs to because it's right there in the text. No need >>> for rules that you have to learn, sometimes the hard way. >> >> I'm not sure what you mean by "AST based language". Google wasn't much >> help, even in finding a definition for AST - it gets swamped by time >> zones and company names. I think you mean abstract syntax tree, but >> I'm not sure how you would go about basing a language on that. Care to >> provide pointers? > > You got it. > > http://martinfowler.com/articles/languageWorkbench.html Um - I see no mention of "AST" in that article at all. He's mostly talking about "Language Oriented Programming" (seems to be another term to describe DSLs) and "Language Workbenches". > This shows one reason _why_ designing a language with the basic > AST representation as primary may become a big deal. Maybe > not, too. This sentence is meaningless without the definition of AST that I asked for. >>> Talk to people who've moved from Python to Ruby, or to >>> some other language. Ask them why, if Python is so great, >>> what's even greater in that other language. If you still don't >>> understand, you might want to read this: >>> >>> http://martinfowler.com/bliki/CollectionClosureMethod.html >> >> I read it. I don't see what the big deal is. He praises collections >> and closurs. Python has both. Ok, the closures are sucky, but you can >> fake real one with classes. He likes anonymous blocks. There are a >> couple of proposals floating around to add those to Python. > > There have been proposals to add them to Python for as long as > I can remember. They have always been shot down. Vigorously. PEP 343 is marked as accepted. > The basic issue here is neither the collection methods nor the > closures. It's a compact yet readable syntax that puts them > together. That's what one should get out of the Fowler piece: > how nice it is to be able to do some rather common things > compactly. > > All steps in that direction have always been resisted. So you're not complaining about missing functionality, you're complaining about syntactic sugar. That's not really in line with the rest of your article, which seems to be complaining that python is missing out on adding important new functionality. I'd say resisting such changes is pythonic. Signaling that you're switching from an expression to statements with a magic character is hardly readable; statements should look like statements, not expressions. >>> I find the notion that there should be one obviously right way >>> to do something to be a good design principle, so why isn't >>> there a single supported GUI library? If I'm over in Java-land, >>> just about everything comes with a GUI. Python ships with a >>> lot of little demonstration and utility scripts - none of which has >>> a GUI. >> The standard library documentation only documents one GUI library. The >> Python distribution includes one *large* example of GUI programming >> with that library - IDLE. I agree that more examples and documentation >> would be usefull, but I'm *not* the person to write them. > And I never suggested you were. So you're dropping the complaint that Python doesn't have one standard GUI? >>> Why the jihad (and I'm using the word advisedly) >>> against the map, filter and reduce operators? >> I'd say that LCs and GEs make map and filter redundant, thus violating >> the principle of there being one obviously right way to do something >> that you like. Reduce isn't as clear. Maybe we can get it replaced by >> inject. > I've already explained that, if you want to invoke "only one way" > then list and generator comprehensions are the violation since > there were other ways of doing it. First you argue that python isn't improving. Now you complain that improving some things (and thus obsoleting others) is a bad thing. LCs are clearly superior to map and filter. They replace two builtin functions with one more readable language construct. >>> I'm not suggesting shooting at a moving target. I'm suggesting >>> getting the head out of the sand, looking at trends, and figuring >>> out the _large_ steps to take next, not the nickle and dime fixups >>> that are the only things I see in PEP 3000. (Not to say that some >>> of them aren't going to be a lot of work. Some of them are.) >> There are some large steps on the horizon. Interfaces (or maybe >> Abstract Base Classes) are being considered for addition to the >> language. > http://www.artima.com/weblogs/viewpost.jsp?thread=92662 >. > He just blogged on that yesterday; I'm going to have to look at > it in detail. Not something to look at in the middle of composing > a response. Please note that it's in terms of the Python 3000 > framework, which should be noted in context of your first point > at the top of this post. Yup. I goofed - I should have listed them as the only proposal I knew of for new features to Python 3000. >>> Another thing that stands out: the explicit versus dynamic typing debate >>> has moved on from program correctness (which is a wash) to >>> other areas that explicit (or derived) type information can be used >>> for. I see this in PyFit: the languages where explicit type information >>> is available by reflection have cleaner implementations. The languages >>> with dynamic typing all have to deal with the fact that they can't get >>> type information by reflection, and it's a diverse mess. >> There are people who strongly disagree that the programm correctness >> issue is a wash. If you've got research to back that up, I'd love to >> see it. > It seems to be the concensus on this group anyway: declarative typing > does not give enough improvement in program correctness to override > more concise programs and TDD. That may, of course, be wishful > thinking on the Python community's part. "The concensus of this group" is a *long* way from "the debate has moved on". I agree that it's the concensus of this group - but this is a group devoted to a dynamic programming language. If you go to a group devoted to a statically typed language, you'll find a different concensus. Which means the debate is still very much alive. >>> The world is moving on, in ways that I think you're not seeing. >>> And Python is standing still in many of those same ways. >> I find it hilarious that this arrived at my news server the same day >> that Peter Hansens rant (look for the subject "Syntax error after >> upgrading to Python 2.4") about Python changing to fast did. > You may find it hilarious. I find it kind of sad - painting oneself > into a corner so that upgrades become a pain for the customer > base is not a laughing matter. No, it's hilarious because of the old saw that if you're drawing criticism from both sides of a debate, you must be doing something right. > "I don't want it to change too fast" is the same as "Fat and > happy", just in different words. So we have one (count him, 1) user who complains that it's changing to fast. I suspect most readers here would disagree with him. It seems that your complaint is really that Python isn't going in the direction you want it to go. The people developing Python are doing what they think is best for the language. You may think they're wrong. I know I do at times. Unless we're one of the people doing the development, our seat on the board is non-voting, so there's not much we can do beyond complain. If we want a vote, we can work on Python rather than in Python. In the extreme case, we can secede and become BDFL of our own variant of Python. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From exogen at gmail.com Mon Aug 1 21:34:31 2005 From: exogen at gmail.com (Brian Beck) Date: Mon, 01 Aug 2005 21:34:31 -0400 Subject: Application Error (referenced error) In-Reply-To: References: Message-ID: David Blomstrom wrote: > I downloaded a content management system called Plone > and get the following error message when I try to > start it: Plone isn't a stand-alone application, it's a skin and collection of products for the Zope application server. You'll have to get Zope up and running before you can use Plone. See www.zope.org. There are also specific mailing lists (on Gmane, www.gmane.org) dedicated to Zope, Plone, and their related packages. -- Brian Beck Adventurer of the First Order From savvyside at aol.com Fri Aug 26 07:27:45 2005 From: savvyside at aol.com (michael) Date: Fri, 26 Aug 2005 11:27:45 GMT Subject: Command Line arguments References: <9gtqg1lkso6m6ukipku1ac7hk9sejhi3ld@4ax.com> Message-ID: On Thu, 25 Aug 2005 11:39:48 -0700, Trent Mick wrote: > [michael wrote] >> SOLVED! Thank you. >> >> I wonder why this was needed for 2.4 and not 2.2? I don't think it was >> lingering things from old installs because it happened on a persons >> computer that had never had any python installed before 2.4. > > It might be due to a bug in the Python 2.4 installer not setting the > proper file associations. What installer package did you use? > > Trent I used the python2.4.MSI from python.org site (dated 3-6-05). I think this was the first time they went to MSI verses an exe based installer. it says Python 2.4 (#60 November 30th, 2004) when I start it. Michael From martin at v.loewis.de Wed Aug 17 03:52:18 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 17 Aug 2005 09:52:18 +0200 Subject: Embedding Python in C, undefined symbol: PyExc_FloatingPointError In-Reply-To: References: Message-ID: <4302ecb2$0$16020$9b622d9e@news.freenet.de> Simon Newton wrote: > gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 > -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes > gcc main.o -L/usr/lib -lpthread -ldl -lutil > -lm /usr/lib/python2.4/config/libpython2.4.a -o main > > I've tried the above on two machines, one Debian stable and the other > Debian testing. Same results on both. > > It's like I'm missing a library or something, any ideas ? No. You need to export the Python symbols from your executable to extension modules. IOW, you need to pass -Xlinker -export-dynamic to the gcc invocation. Regards, Martin From peter at engcorp.com Wed Aug 10 07:34:51 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Aug 2005 07:34:51 -0400 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: Dan wrote: > You might think of modules in Python as like packages in Java. However, > putting classes in the same module doesn't give them any additional > powers to interact with each other. (At least, not that I know of.) Use of "global" to rebind shared module-scope names... -Peter From talin at acm.org Sun Aug 21 16:04:01 2005 From: talin at acm.org (Talin) Date: Sun, 21 Aug 2005 13:04:01 -0700 Subject: Further questions on dictionaries, namespaces, etc. Message-ID: <4308DE31.30908@acm.org> Thanks to everyone for pointing out my bone-headed errors :) I don't *usually* make that sort of mistake... What I'm attempting to do is create an implentation of the unification algorithm. Now, its fairly straightforward to do unification on my own custom types, all I have to do is define a unify() method for each class: def unify( self, other, bindings ): ... However, this doesn't work so well when the objects being unified are built-in python types (tuples, integers, etc.) This requires the "un-pythonic" testing of each individual type and then calling the appropriate unification function for the given type. Another thing that is important is that this particular unifier supports commutative functions (which accept their arguments in any order), which is what the permutation stuff is for. (I haven't done associativity yet, still working on it.) The unifier is structured as a stack of generators, each returning all possible matches. This allows the higher levels of the unifier to backtrack by processing alternatives produced by the lower-level generators. So here's my list of further questions: 1) Is there are better way to do "functional overloading" on built-in types than using a whole series of "if type( x ) is y". 2) Is there an easy way to determine if a given object has a callable method named "unify"? I know how to determine if there's an attribute with a name, but not how to determine whether or not that attribute is callable. 3) The "bindings" object is a dictionary that is constructed as the unification proceeds. (So for example, if I attempt to unify "x + 1" with "2 + 1" it will have the binding "x : 2" in the dictionary. I want this bindings object to behave like a function call scope - in that you can "see" the variables in the enclosing scope. In fact, I'd like to be able to use a regular python namespace (such as a module) as the enclosing scope, so that the unification algorithm has access to all of the variable definitions within that module. (Again, this is part of the notion that I want to be able to do unification operations on normal python data structures, rather than specially "wrapped" types.) In fact, I had thought about the idea of the bindings being an actual Python "module" object, however that doesn't appear to be possible (or what I want for that matter.) Similarly, being able to take the local function scope and capture it in a closure and export that to the outside world was also something I briefly pondered. Because of the backtracking nature of the matcher, I need to be able to "undefine" bindings that have been previously defined. The way I am currently doing this is to create a new "scope" each time I add a new binding, where the new scope's "parent" is the previous scope. (So in fact my dictionary has only one entry in it.) Something like this: for new_bindings in generate_matches( a, b, old_bindings ): ... If none of the alternatives pan out, it simply discards "new_bindings" and reverts back to the old_bindings. So my question here is: Do I want to continue using a subclass of dict for this, or something more exotic? 4) I've seen a couple of code examples on the net where people use the idiom "lambda x: (for x in [])" to represent a "null" iterator, i.e. one that immediately terminates. How is this any different from simply returning "()"? (Or range( n, n ) for that matter.) Which one is the most efficient? And if they are different, how about adding a null iterator to itertools :) -- Talin From fabioz at esss.com.br Mon Aug 1 09:01:26 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Mon, 01 Aug 2005 10:01:26 -0300 Subject: ANN: PyDev 0.9.7 with support to java 1.3 and 1.4 released In-Reply-To: <42E6412A.4020905@esss.com.br> References: <42A720BD.5050701@esss.com.br> <42C175A5.5000206@esss.com.br> <42E6412A.4020905@esss.com.br> Message-ID: <42EE1D26.5070501@esss.com.br> Hi All, PyDev - Python IDE (Python Development Enviroment for Eclipse) version 0.9.7 with support to java 1.3 and 1.4 has just been released. Check the homepage (http://pydev.sourceforge.net/) for more details. IMPORTANT: - A new package has been added to the pydev release with support to earlier java versions (latest release just supports java 5.0). - This package is targeted specifically for people that don't have access to java 5.0 (namely, earlier versions of MAC OS). - Support for this release is limited to the .zip distribution in the sourcforge downloads, and will not be put into the update site. Release Highlights: This build fixes some nasty bugs from 0.9.6... it is highly recommended you install it. (right now, everything but the debugger should work fine with 3.1). Important notes Note 1: Because of some issues with Eclipse, you have to uninstall all previous PyDev installations before installing the new release. Note 2: This release only works with Eclipse 3.1 (and from now on, Eclipse 3.0.x is no longer supported). Regards, Fabio -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From chris2k01 at hotmail.com Fri Aug 26 01:17:23 2005 From: chris2k01 at hotmail.com (Chris Head) Date: Fri, 26 Aug 2005 05:17:23 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Bokma wrote: [snip] >>usage consists of downloading your e-mail. When using a Webmail >>service, your bandwidth usage consists of downloading the message, >>PLUS the entire user interface. > > > Not necessary when using (i)frames + cache True. Perhaps Hotmail is not very well designed, but it doesn't use frames. I'm not really familiar with other Webmail systems, but the one provided by my ISP doesn't either. > > >>Additionally, a user interface operating inside an HTML >>renderer can NEVER be as fast as a native-code user interface with >>only the e-mail message itself passed through the renderer. > > > Nowadays, more then futile. Sorry, I don't understand what you mean. Even on my 2.8GHz Pentium 4, using Thunderbird to juggle messages is noticeably faster than wandering around Hotmail. Complex HTML rendering still isn't absolutely instantaneous. It's significantly more painful when I use my 433MHz Celeron. It simply takes a long time to jump between message, inbox, other message, inbox, other other message, inbox, etc. > > >>I mean, the way >>Webmail works, you're at the message list and click on a message to >>view. This causes a whole new page, user-interface and all, to be >>loaded. In comparison, that's like shutting down and re-opening your >>e-mail program for every single message you want to view! > > > This can be designed much better by using iframes, maybe even Ajax. Agreed. Judicious use of frames (internal or otherwise) or Javascript-based partial reloads could seriously improve the situation. They might also provide an easier way for Webmail providers to implement their pages in valid HTML: if you render the entire e-mail message alone in a frame, you don't have to start stripping out pieces of e-mail because they already exist (html and body elements, for example) > > >>Why can't we use the Web for what it was meant for: viewing hypertext >>pages? Why must we turn it into a wrapper around every application >>imaginable? > > > Because it works? > ... and purpose-built client applications (e.g. Thunderbird) don't? Maybe I'm old-fashioned but I still very much prefer thick clients. They simply feel much more solid. Perhaps part of it is that thin clients have to communicate with the server at least a little bit for just about everything they do, while thick clients can do a lot of work without ANY Internet round-trip delay at all. Hotmail has to talk to the server to move a message from one mailbox to another. Thunderbird doesn't. Ergo, Thunderbird is faster as soon as the Internet gets congested. Chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (MingW32) iD8DBQFDDqXh6ZGQ8LKA8nwRAsVyAKCjwP9iyrPRBnMsI1pB+wqZdANE6ACfYeGx w8SLwXln0VjpuwF+L7BDfKM= =pZ/B -----END PGP SIGNATURE----- From max at alcyone.com Tue Aug 2 02:15:35 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Aug 2005 23:15:35 -0700 Subject: Is this Pythonic? In-Reply-To: References: <74SdnekYvd-_EnPfRVn-2A@speakeasy.net> Message-ID: phil hunt wrote: > That's a clever trick, but it's obvious from the code that the class > is intended to be abstract, so if people are stupid enough to shoot > themselves in the foot by creating an instance, I don't feel like > adding extra code to protect themselves from their stupidity. Right. But even if you're not worried about stupidity, it's useful to have it fail in an explicit way as early as possible, rather than later on. With that addition, the moment you try to create an instance of an abstract class, you get an exception. Even if it's just a typo, and not severe negligence, that helps the problem get fixed sooner, rather than later. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Morality is a weakness of the mind. -- Arthur Rimbaud From alessandro.bottoni at infinito.it Tue Aug 9 13:01:45 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Tue, 09 Aug 2005 17:01:45 GMT Subject: Examples and tutorials about popen2/3, smtplib/multipart and icq/jabber? Message-ID: Is there any good tutorial/example about popen2 and popen3? I have to execute a given command on Linux and Windows from within a Python program. If possible, on Linux I would like to be able to set the executing user (setuid) and the niceness level of the command. (and yes: I know it is a dangerous feature...) Is there any good tutorial/example about smtplib and MIME multipart messages? I need to send a bunch of e-mail messages (possibly in HTML format) to many diverse recipients, each message with one or more attachements (typically PDF files). BTW: how about using Twisted Matrix for this task? I heard it is able to send e-mail messages asynchronously (leaving free the invoking program to go on just after the call to the "send_msg" function). Is there any good tutorial/example about Jabber or ICQ and Python? I have to send a bunch of instant messages (possibly with one or more file and/or one or more URL attached to them in some way) to many diverse recipients (I normally do not use ICQ and/or Jabber and I know them very little. Any advise or suggestion about this task is greatly welcome). Thanks in advance ----------------------------------- Alessandro Bottoni From tow21 at cam.ac.uk Fri Aug 26 05:22:35 2005 From: tow21 at cam.ac.uk (Toby White) Date: Fri, 26 Aug 2005 10:22:35 +0100 Subject: Limited XML tidy References: <1125004208.581551.205680@g44g2000cwa.googlegroups.com> Message-ID: uche.ogbuji at gmail.com writes: >> The problem is that when the sax handler raises an exception, > I can't see how to find out why. What I want to do is for > DodgyErrorHandler to do something different depending on > where we are in the course of parsing. Is there anyway > to get that information back from xml.sax (or indeed from > any other sax handler?) > > You can get raw location information, yes. See: > > http://www.xml.com/pub/a/2004/11/24/py-xml.html > > But I don't think this is enough for you. You also need recovery, > which you're implementing in crude form. (If you're referring to the Locator objects), yes I'm aware that's possible. But what I want is not my location in the document, but for the parser to say "this is an error because I am in the middle of a tag & the document ended", or "I was in the middle of a text section and the document ended", or "I was in the middle of an attribute value and the document ended", etc, so that I can then construct a simple end to the document, inserting quote marks, finishing the tag, and closing all unclosed tags as appropriate. I have just realised that I might be able to grab the message that the exception gives me, look at the expat source code and work out what parsing events cause which error messages. Which is a bit round the houses, but I think ought to work. > I tend to agree with Magnus that using an SGML parser might be your > best bet. You might even be able to turn that SGML into XML using a > tool such as James Clark's SX: > > http://www.jclark.com/sp/sx.htm If I can't get my scheme above to work, I'll have a go. But I was hoping to do this without requiring additional packages. And in any case, it doesn't need to be perfectly robust. As long as it handles 99% of cases, I'll be happy. -- Dr. Toby White Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK Email: From tjreedy at udel.edu Sun Aug 21 20:38:17 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2005 20:38:17 -0400 Subject: Python dutch References: <4e7ed7e9050821160448c09354@mail.gmail.com> Message-ID: "Dragonfly" wrote in message news:4e7ed7e9050821160448c09354 at mail.gmail.com... > hi, > Do you have a python lesson book in dutch version on your site? Did you try to look? Either by using the search bar at the top of each page or going to the documentation page http://www.python.org/doc/ where there is a link to Non-English Documents? Terry J. Reedy From steven.bethard at gmail.com Sat Aug 20 17:33:22 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sat, 20 Aug 2005 15:33:22 -0600 Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: Bryan Olson wrote: > Steven Bethard wrote: > > Well, I couldn't find where the general semantics of a negative stride > > index are defined, but for sequences at least[1]: > > > > "The slice of s from i to j with step k is defined as the sequence of > > items with index x = i + n*k such that 0 <= n < (j-i)/k." > > > > This seems to contradict list behavior though. [...] > > The conclusion is inescapable: Python's handling of negative > subscripts is a wart. I'm not sure I'd go that far. Note that my confusion above was the order of combination of points (3) and (5) on the page quoted above[1]. I think the problem is not the subscript handling so much as the documentation thereof. I posted a message about this [2], and a documentation patch based on that message [3]. [1] http://docs.python.org/lib/typesseq.html [2] http://mail.python.org/pipermail/python-list/2005-August/295260.html [3] http://www.python.org/sf/1265100 > Suppose instead of using semicolons as the PPEP proposes, we use > commas, as in: > > sequence[start, stop, step] This definitely won't work. This is already valid syntax, and is used heavily by the numarray/numeric folks. STeVe From deets at web.de Sun Aug 7 06:25:51 2005 From: deets at web.de (Diez B.Roggisch) Date: Sun, 7 Aug 2005 10:25:51 +0000 (UTC) Subject: Some newbie cgi form questions... References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> Message-ID: > The second for loop is an attempt at trying to print all the values > that were entered on the for without presenting the hidden values. I'd > really like to do this, but I can't seem to figure out how to make a > special case for hidden form values, nor can I find an example of how > to do it in any of the many python cgi pages I've visited so far. If I You can't find that out by just processing the http request - http doesn't know types in form fields. Only HTML(!) does that. But as you are the one who created the form in the first place, you should know which from fields are the hidden ones. Or - if you are more after a generic approach, use namespaces. You can do that by naming hidden fields e.g. hidden:, where is of course something like foo or bar or whatever. Diez From homeusenet at brianhv.org Mon Aug 15 08:42:54 2005 From: homeusenet at brianhv.org (Brian Victor) Date: Mon, 15 Aug 2005 12:42:54 GMT Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <1124090875.292874.199610@o13g2000cwo.googlegroups.com> Message-ID: jbperez808 at yahoo.com wrote: > Torsten Bronger wrote: >> I've been having a closer look at wxPython which is not Pythonic at >> all and bad documented. Probably I'll use it nevertheless. > Aye. Couldn't agree more. You know, whenever someone mentions wxPython being badly documented, I have to wonder whether they know about the nearly 2000 page PDF of wxWidgets documentation, which is available in html at http://www.wxwidgets.org/manuals/2.6.1/wx_contents.html wxPython has the same API as wxWidgets, except where indicated in that manual. If in doubt, you can also consult http://wxpython.org/docs/api/ And of course, the gaps are filled in by the wxPython wiki: http://wiki.wxpython.org/ I apologize if you already know about these things, but I find myself continually surprised that "wxPython is badly documented" has become conventional wisdom when I have never found that to be the case. -- Brian From wesc at fuzzyorange.com Wed Aug 17 22:08:29 2005 From: wesc at fuzzyorange.com (Wesley Chun) Date: Wed, 17 Aug 2005 19:08:29 -0700 Subject: ANN: Python training, 2005 Aug 29-31, San Francisco Message-ID: <200508180208.j7I28TWk011174@freesia.deirdre.org> hi all, just a reminder that our next Python training course is less than 2 weeks away! details can be found at http://cyberwebconsulting.com (click "Python training"). if you're interested in joining us near San Francisco, sign up soon as there's only room for 9 more people!! contact us at cyberweb-at-rocketmail.com with any questions. thanks, -wesley > Newsgroups: comp.lang.python > From: w... at deirdre.org > Date: 28 Jul 2005 09:49:31 -0700 > Subject: ANN: Python training, 2005 Aug 29-31, San Francisco > > What: Python Programming I: Introduction to Python > When: August 29-31, 2005 > Where: San Francisco, CA, USA > > Already know Java, Perl, C/C++, JavaScript, PHP, or TCL/Tk, but want to > learn Python because you've been hearing about how Google, Yahoo!, > Industrial Light & Magic, Red Hat, Zope, and NASA are using this > object-oriented, open source applications and systems development > language? Python is rapidly gaining momentum worldwide and seeing more > new users each year. While similar to those other languages, Python > differentiates itself with a robust yet simple-as-VB syntax which allows > for shorter development time and improved group collaboration. > > Need to get up-to-speed with Python as quickly as possible? Come join > us in beautiful Northern California the week before Labor Day. We are > proud to announce another rigorous Python training event taught by > software engineer and "Core Python Programming" author, Wesley Chun. > This is an intense introduction to Python programming geared towards > those who have some proficiency in another high-level language. Topics > include: > > * Python's Objects and Memory Model > * Data Types, Operators, and Methods > * Errors and Exception Handling > * Files and Input/Output > * Functions and Functional Programming > * Modules and Packages > * Classes, Methods, and Class Instances > * Callable and Executable Objects > > This course will take place daily August 29-31, 2005 (Monday through > Wednesday, 9am - 5pm) in San Bruno, CA, right near the San Francisco > International Airport at the: > > Staybridge Suites > San Francisco Airport > 1350 Huntington Ave > San Bruno, CA 94066 > 650-588-0770 > > This venue provides free shuttles to/from the airport and has easy > access to public transit (BART, CalTrain, SamTrans) to help you get all > over the Bay Area. Afterwards, feel free to enjoy the holiday weekend > in the greatest city by the Bay... bring your families!! > > Sign up quickly as we can only take 15-20 enrollees! For more infor- > mation and registration, just go to http://cyberwebconsulting.com and > click on the "Python Training" link. If you have any questions, feel > free to contact us at cyberweb-at-rocketmail.com. From billiejoex at fastwebnet.it Mon Aug 15 06:16:25 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Mon, 15 Aug 2005 12:16:25 +0200 Subject: sniffer in python Message-ID: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> Hi! I made a little, simple program that sends strings over an ICMP packet. The source here: http://billiejoex.altervista.org/a1.txt Now all I need is create a simple network sniffer able to sniff the ICMP packets and print the strings on the screen. A useful library known in a lot of other programming languages is 'libcap' (winpcap for win32 platforms). For python exist a porting called pcapy: http://oss.coresecurity.com/projects/pcapy.html ...that I'd like to use BUT... all the examples reported on the sites don't works!! Is there someone who has already created a network sniffer in python? It shouldn't be too much difficult... Best regards From me at privacy.net Thu Aug 18 21:43:39 2005 From: me at privacy.net (Dan Sommers) Date: Thu, 18 Aug 2005 21:43:39 -0400 Subject: Module Name Conflicts References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: On Thu, 18 Aug 2005 16:46:42 -0700, Robert Kern wrote: > Dan Sommers wrote: [ something that obviously doesn't work ] > That doesn't work. The first module is recorded as 'cmd' in > sys.modules and gets reused on the second import. Yes, you're right. I apologize. Regards, Dan -- Dan Sommers From sp1d3rx at gmail.com Thu Aug 18 12:26:15 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 18 Aug 2005 09:26:15 -0700 Subject: List of string In-Reply-To: References: Message-ID: <1124382375.810804.28910@g49g2000cwa.googlegroups.com> to quote you : "['0134314244133', '132443', '234'] 2nd and 3rd strings are also substrings from the 1st one , so it should be removed " Actually, no, the 2nd string does not substring match the first, nor does the 3rd. If you are referring to matching individual characters, then yes, characters 1 2 3 4 are in the first string. In that case you would want to use the replace() function. Just specify the characters you want to strip as the first arguement to "replace()". See the example below... >>>x = "this is not a test" >>>x.replace("t","") #delete the letter t 'his is no a es' >>> x.replace("not ","") 'this is a test' >>> x.replace("notas","") # wont work because it treats the first arg as a string, not a list of characters 'this is not a test' From ptmcg at austin.rr.com Mon Aug 22 08:10:42 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 22 Aug 2005 05:10:42 -0700 Subject: regular expressions use References: <6uhOe.70629$2U1.3761846@news3.tin.it> Message-ID: <1124712642.043954.270030@f14g2000cwb.googlegroups.com> Perhaps a bit more verbose than your Perl regexp, here is a decoder using pyparsing. -- Paul # download pyparsing at http://pyparsing.sourceforge.net from pyparsing import Word,Combine # define grammar for matching encoded characters hexnums = "0123456789ABCDEFabcdef" encodedChar = Combine( "%" + Word(hexnums,exact=2) ) # define and attach conversion action def unencode(s,l,toks): return chr(int(toks[0][1:],16)) encodedChar.setParseAction( unencode ) # transform test string data = "%2b/dhg-%3b %7E" print encodedChar.transformString( data ) """ Prints "+/dhg-; ~": """ From levub137 at wi.rr.com Sat Aug 20 09:24:50 2005 From: levub137 at wi.rr.com (Raymond L. Buvel) Date: Sat, 20 Aug 2005 13:24:50 GMT Subject: Class Library for Numbers Message-ID: I have just released a new module that interfaces the Class Library for Numbers (CLN) to Python. The CLN library is a C++ library that provides rational and arbitrary precision floating point numbers in real and complex form. The clnum module exposes these types to Python and also provides arbitrary precision replacements for the standard math functions in real and complex forms. For more information see http://calcrpnpy.sourceforge.net/clnum.html Ray Buvel From rkern at ucsd.edu Wed Aug 24 15:18:05 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 24 Aug 2005 12:18:05 -0700 Subject: use SciPy with Python 2.4.1? In-Reply-To: <1124895877.968739.323680@o13g2000cwo.googlegroups.com> References: <1124895877.968739.323680@o13g2000cwo.googlegroups.com> Message-ID: beliavsky at aol.com wrote: > Is SciPy usable with Python 2.4.1? At http://www.scipy.org/download/ it > says that 2.3.3 is recommended, and I don't see a binary for 2.4.1. It is usable with Python 2.4.1 on Linux and OS X at least. IIRC, mingw-compiled extensions don't work with the standard Python 2.4.1 interpreter, which is, I believe, the largest holdup for Windows binaries for 2.4.1. If you have success building Scipy for Python 2.4.1 on Windows, please let us know on the Scipy list. Thanks. -- 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 rkern at ucsd.edu Sun Aug 28 06:25:12 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 28 Aug 2005 03:25:12 -0700 Subject: What are new-style classes? In-Reply-To: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> Message-ID: Vaibhav wrote: > I recently heard about 'new-style classes'. I am very sorry if this > sounds like a newbie question, but what are they? I checked the Python > Manual but did not find anything conclusive. Could someone please > enlighten me? Thanks! There's a link on the left sidebar of http://docs.python.org http://www.python.org/doc/newstyle.html -- 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 http Fri Aug 12 21:00:51 2005 From: http (Paul Rubin) Date: 12 Aug 2005 18:00:51 -0700 Subject: Writing a small battleship game server in Python References: <200508111746.15668.mail@tuxipuxi.org> <1123778097.6562.35.camel@localhost.localdomain> Message-ID: <7xfyte8xbw.fsf@ruckus.brouhaha.com> Michael Goettsche writes: > Assuming the server accepts connections in an endless loop, how > would I handle communication without additional threads and create > new games in that loop? Could you give me pseudo-code for this? I've always done this kind of thing with the SocketServer module and the threading mixin. You'd say something like: from SocketServer import SocketServer, ThreadingMixin class Battleship_server(ThreadingMixin, SocketServer): def handle(self, request): # this method gets called in a new thread when a new connection # arrives. Just handle the whole game for that connection here. You do need some synchronization to avoid concurrency hazards when the different threads touch shared data (like a global scoreboard) but it's not as bad as it sounds. From bignose+hates-spam at benfinney.id.au Wed Aug 10 23:48:19 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2005 13:48:19 +1000 (EST) Subject: PEP 328, absolute/relative import References: Message-ID: Aahz wrote: > Ben Finney wrote: > >So, under PEP 328 rules, the original poster's current-directory > >module could only be imported (a) if the current directory was in > >sys.path, or (b) if the code specified a relative import. The > >accidental shadowing of the stdlib module could not happen. > > Normally the current directory *is* on sys.path, and the first > thing, too: Ah. I'd forgotten that, my bad. So, modules in the current directory will continue to be imported as before, because they *are* absolute imports by PEP328 definitions. -- \ "If it ain't bust don't fix it is a very sound principle and | `\ remains so despite the fact that I have slavishly ignored it | _o__) all my life." -- Douglas Adams | Ben Finney From ptmcg at austin.rr.com Sat Aug 20 02:47:29 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 19 Aug 2005 23:47:29 -0700 Subject: BeautifulSoup References: <1124476767.160347.55710@g14g2000cwa.googlegroups.com> <867jehb8fj.fsf@bhuda.mired.org> Message-ID: <1124520449.859085.315770@g47g2000cwa.googlegroups.com> Mike - Thanks for asking. Typically I hang back from these discussions of parsing HTML or XML (*especially* XML), since there are already a number of parsers out there that can handle the full language syntax. But it seems that many people trying to parse HTML aren't interested in fully parsing an HTML page, so much as they are trying to match some tag pattern, to extract or modify the embedded data. In these cases, fully comprehending HTML syntax is rarely required. In this particular instance, the OP had started another thread in which he was trying to extract some HTML content using regexp's, and this didn't seem to be converging to a workable solution. When he finally revealed that what he was trying to do was extract and modify the URL's in a web pages HTML source, this seemed like a tractable problem for a quick pyparsing program. In the interests of keeping things simple, I admittedly provided a limited solution. As you mentioned, no additional attributes are handled by this code. But many HTML scrapers are able to make simplifying assumptions about what HTML features can be expected, and I did not want to spend a lot of time solving problems that may never come up. So you asked some good questions, let me try to give some reasonable answers, or at least responses: 1. "If it were in the ports tree, I'd have grabbed it and tried it myself." By "ports tree", I assume you mean some directory of your Linux distribution. I'm sure my Linux ignorance is showing here, most of my work occurs on Windows systems. I've had pyparsing available on SF for over a year and a half, and I do know that it has been incorporated (by others) into a couple of Linux distros, including Debian, ubuntu, gentoo, and Fedora. If you are interested in doing a port to another Linux, that would be great! But I was hoping that hosting pyparsing on SF would be easy enough for most people to be able to get at it. 2. "How well does it deal with other attributes in front of the href, like ?" *This* version doesn't deal with other attributes at all, in the interests of simplicity. However, pyparsing includes a helper method, makeHTMLTags(), that *does* support arbitrary attributes within an opening HTML tag. It is called like: anchorStart,anchorEnd = makeHTMLTags("A") makeHTMLTags returns a pyparsing subexpression that *does* comprehend attributes, as well as opening tags that include their own closing '/' (indicating an empty tag body). Tag attributes are accessible by name in the returned results tokens, without requiring setResultsName() calls (as in the example). 3. "How about if my HTML has things that look like HTML in attributes, like ?" Well, again, the simple example wont be able to tell the difference, and it would process the ATTRIBUTE string as a real tag. To address this, we would expand our statement to process quoted strings explicitly, and separately from the htmlAnchor, as in: htmlPatterns = quotedString | htmlAnchor and then use htmlPatterns for the transformString call: htmlPatterns.transformString( inputHTML ) You didn't ask, but one feature that is easy to handle is comments. pyparsing includes some common comment syntaxes, such as cStyleComment and htmlComment. To ignore them, one simply calls ignore() on the root pyparsing node. In the simple example, this would look like: htmlPatterns.ignore( htmlComment ) By adding this single statement, all HTML comments would be ignored. Writing a full HTML parser with pyparsing would be tedious, and not a great way to spend your time, given the availability of other parsing tools. But for simple scraping and extracting, it can be a very efficient way to go. -- Paul From martin at v.loewis.de Sat Aug 20 02:36:59 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 20 Aug 2005 08:36:59 +0200 Subject: Version of TAR in tarfile module? TAR 1.14 or 1.15 port to Windows? In-Reply-To: <3mnhu1F17b3j4U1@individual.net> References: <3mnhu1F17b3j4U1@individual.net> Message-ID: <4306cf8d$0$15269$9b622d9e@news.freenet.de> Claudio Grondi wrote: > What TAR version is built into the tarfile module? None: the tarfile module is not built on top of GNU tar. Instead, it is a complete reimplementation. > Is there a TAR 1.14 or 1.15 port to Windows > available in Internet for download (which URL)? http://sources.redhat.com/cygwin/ Regards, Martin From littlejohn.75 at news.free.fr Mon Aug 29 10:05:57 2005 From: littlejohn.75 at news.free.fr (F. Petitjean) Date: 29 Aug 2005 14:05:57 GMT Subject: Pointers and ctypes References: <1125321557.883310.41490@g43g2000cwa.googlegroups.com> Message-ID: <43131645$0$27016$626a14ce@news.free.fr> Le 29 Aug 2005 06:19:17 -0700, rubbishemail at web.de a ?crit : > Hello, > i've got a problem with pointers in the following function which i want > to use: > > I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value) > > The function is supposed to read out the status of a digital port of > analog digital interface card. > I got this function from Dask.h which came with the card. The relevant > lines concerning this function are the following: > > typedef short I16; > typedef unsigned short U16; > typedef unsigned long U32; > > I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value) > > I tried to implement this function into python: > # I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value); > ReadOPort = dask.DO_ReadPort > ReadOPort.argtypes = [c_ushort, c_ushort, c_ulong] > ReadOPort.restype = c_short > > I can't handle the pointer "Value" which should be an unsigned long > pointer. I'd be very happy, if u could give me a hint how to implement > this pointer into python. You can use the ctypes.byref() function (as it is in an argulent list): ReadOPort.argtypes = (c_ushort, c_ushort, ctypes.POINTER(c_ulong) ) ReadOPort.restype = c_short status = c_ulong() # status value to be read number = c_ushort(1) # CardNumber = 1 port = c_ushort(11) rc = ReadOPort(number, port, ctypes.byref(status)) print rc, ststus > > Thanks a lot > > Carlo and Pierre > From fuzzyman at gmail.com Fri Aug 12 03:24:38 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 12 Aug 2005 00:24:38 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123702730.955133.105950@g49g2000cwa.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> <1123618110.763724.304990@g44g2000cwa.googlegroups.com> <1123702730.955133.105950@g49g2000cwa.googlegroups.com> Message-ID: <1123831478.283056.161650@g49g2000cwa.googlegroups.com> If you subclass strings you have to do your magic in __new__ rather than __init__. It receives the same arguments as you would normally expect to go to __init__. (Except cls rather than self). Best Regards, Fuzzy http://www.voidspace.org.uk/python From benji at benjiyork.com Tue Aug 30 10:57:10 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 30 Aug 2005 10:57:10 -0400 Subject: how to join two Dictionary together? In-Reply-To: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> Message-ID: <431473C6.6010904@benjiyork.com> See http://docs.python.org/lib/typesmapping.html for a description of the "update" method. -- Benji York From jonhewer at gmail.com Wed Aug 31 11:33:48 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Wed, 31 Aug 2005 16:33:48 +0100 Subject: command line arguments Message-ID: hi i am writing a little script and currently implementing command line arguments following the guide by mark pilgrim from dive into python; http://diveintopython.org/scripts_and_streams/command_line_arguments.html thats all fine, however i am not sure of the BEST way to handle multiple command line arguments for my script, i want to be able to accept two arguments, a name and a url, but i am not sure if its best to use one command line option/flag (eg -n to specify name) and then grab the url from the extra data which will be in 'args': opts, args = getopt.getopt(sys.argv[1:], "n:", ["name="]) or to have two command line options/flags, -n and -u, and checking that these have both been specified and then proceeding (this might be a little messier) any tips would be much appreciated thanks in advance jon From bill.mill at gmail.com Thu Aug 25 13:49:03 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 25 Aug 2005 13:49:03 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <5ZudndXd2JTen5PeRVn-2A@speakeasy.net> References: <5ZudndXd2JTen5PeRVn-2A@speakeasy.net> Message-ID: <797fe3d4050825104952c37fb@mail.gmail.com> On 8/25/05, Erik Max Francis wrote: > Bill Mill wrote: > > > Unlikely; 2 people have confirmed these results already. > > > > I did find, though, that if I remove all print statements from the > > program, the dummy and non-dummy variable versions take indentical > > time. Can others reproduce this? > > Yes, it's obviously a real effect given the other sightings. I don't > see any speed difference, myself (Pentium IV 3.0 GHz running Slackware > Linux). > Pentium M 1.8 GHz Windows 2k. Here's the top of the profile results for fast and slow on my machine (these won't look decent except in a fixed-width font): Slow: 6766494 function calls (6737594 primitive calls) in 45.740 CPU seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno(function) 3322320 20.539 0.000 31.152 0.000 test.py:135( ) 27520 10.641 0.000 41.792 0.002 :0(min) 3322320 10.613 0.000 10.613 0.000 test.py:81(rowitems) 28100/20 3.620 0.000 45.633 2.282 test.py:130(search) 27545 0.113 0.000 0.113 0.000 :0(append) 27520 0.098 0.000 0.098 0.000 :0(pop) 1 0.041 0.041 45.736 45.736 test.py:36(?) Fast: 540174 function calls (536514 primitive calls) in 3.506 CPU seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno(function) 259640 1.516 0.000 2.303 0.000 test.py:135( ) 2280 0.791 0.000 3.094 0.001 :0(min) 259640 0.788 0.000 0.788 0.000 test.py:81(rowitems) 2860/20 0.269 0.000 3.391 0.170 test.py:130(search) 1 0.045 0.045 3.499 3.499 test.py:2(?) 3645 0.021 0.000 0.021 0.000 test.py:71(colinsert) 3240 0.019 0.000 0.019 0.000 test.py:62(rowinsert) 2305 0.010 0.000 0.010 0.000 :0(append) Interestingly, the test.py:36 line, which takes 45 seconds (!!) in the slow version, does not appear at all in the fast profile. I can't figure out why - both printed out their data, so template must have been called somewhere. Peace Bill Mill bill.mill at gmail.com From dotpyFE at gmail.com Sun Aug 21 19:17:31 2005 From: dotpyFE at gmail.com (Lucas Raab) Date: Sun, 21 Aug 2005 23:17:31 GMT Subject: network programming In-Reply-To: References: Message-ID: John Walton wrote: > Hello, everyone. I just began school, and they > already assigned us science fair. Since I'm in 8th > grade, I get to do demonstrations for our projects. > I'm probably going to demonstrate Python's networking > capabilities by writing a simple instant messenger > program. I only have a few problems: > > 1. I know squat about Python network Programming > > 2. I know nothing about networks > > So if any of you know of a good Python Networking > Tutorial or a website with lots of information on > networks and networking, please reply. Thanks! > I believe the Twisted Matrix library has an IM module written for it and a tutorial on programming with the library. www.twistedmatrix.com -- -------------------------- Lucas Raab lvraab"@"earthlink.net dotpyFE"@"gmail.com AIM: Phoenix11890 MSN: dotpyfe "@" gmail.com IRC: lvraab ICQ: 324767918 Yahoo: Phoenix11890 From nephish at xit.net Thu Aug 18 13:42:32 2005 From: nephish at xit.net (nephish at xit.net) Date: 18 Aug 2005 10:42:32 -0700 Subject: question about binary and serial info In-Reply-To: <11g9hct6qkfsc28@corp.supernews.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> Message-ID: <1124386952.353027.93050@g47g2000cwa.googlegroups.com> >>> import serial >>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1) >>> a = ser.read(1) >>> print a ^ >>> ser.close() >>> type(a) >>> int(a, 16) Traceback (innermost last): File "", line 1, in ? ValueError: invalid literal for int(): ^ so i run it again the same way, only reading 4 bytes this time. >>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1) >>> a = ser.read(1) >>> print a ^A?? >>> ser.close() >>> type(a) int(a, 16) Traceback (innermost last): File "", line 1, in ? ValueError: invalid literal for int(): ^A?? i dont understand what i am missing here. the string character represents a hex character. From tjreedy at udel.edu Sat Aug 20 16:02:57 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Aug 2005 16:02:57 -0400 Subject: Database of non standard library modules... References: <11gcnlkt3q2bk53@news.supernews.com> Message-ID: "Steve Holden" wrote in message news:de70n1$m0q$1 at sea.gmane.org... >>>>http://cheeseshop.python.org/pypi >> To be fair, it's really the "Python Package Index", it just happens to >> be >> stored on a machine called cheeseshop. >> >> > You are being more that fair! The page in question reads: > > """ > Cheese Shop: Home > > The Python Cheese Shop is a repository of software for the Python > programming language. > > Customer: Now then, some cheese please, my good man. > Owner: (lustily) Certainly, sir. What would you like? > Customer: Well, eh, how about a little red Leicester. > Owner: I'm, a-fraid we're fresh out of red Leicester, sir. > > There are currently 874 packages in the Cheese Shop. You may: > > * Search > * Browse the tree of packages > * View a flat list of all packages > * Submit package information (note that you must register to submit) > """ > > followed by a list of 20 recent additions. This is simply inane web > design, and is a significant reason why Python isn't always taken > seriously. The words "Python Package Index" don't appear anywhere in the > body text. The relevant nav bar section is headed "Cheese Shop Actions", > which is more or less guaranteed to confuse many people whose first > language isn't English, and many (not in the know about Monty Python) > whose first language *is* English. You are right. This wacko intro has been added since I last looked. Truly bizarre. From spam at me.please Wed Aug 10 00:59:45 2005 From: spam at me.please (Evil Bastard) Date: Wed, 10 Aug 2005 16:59:45 +1200 Subject: python for microcontrollers In-Reply-To: References: <42f7c8d4$1@news.orcon.net.nz> <7xd5oof5qj.fsf@ruckus.brouhaha.com> <42f91c1c$1@news.orcon.net.nz> Message-ID: <42f98b24$1@news.orcon.net.nz> Peter Hansen wrote: > So while it would probably make an > interesting project, and I'm pretty sure it's quite feasible, grabbing > an off the shelf Forth might be a more productive use of your time. Heh, methinks one might be misunderstanding the Forth culture. Forth compilers are like poetry, in that the number of available works exceeds the number of users. :) Forth can, and so often does, disappear up its own ring-hole in the blink of an eye. Its hardcore extensibility is so often its own downfall since. with the way many people work with it. it earns its reputation as a 'write-only language' over and over again. Quite often, to understand a piece of Forth code, you have to crawl in and out of all the author's body cavities many times. What I'm saying is that it often takes less time to write a Forth than to properly learn and understand someone else's implemention. In this way, Forth is like undergarments - you can admire those worn by others, but you sure as hell don't want to wear them yourself. :P -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From http Fri Aug 26 05:23:35 2005 From: http (Paul Rubin) Date: 26 Aug 2005 02:23:35 -0700 Subject: Better crypto hash functions, long, with code References: Message-ID: <7xu0hdnjag.fsf@ruckus.brouhaha.com> Nice. Note that the Sourceforge bug for this issue indicates that something is already being done about it. It just happens to have been updated a day or so ago: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1123660&group_id=5470 Note to skeptics: the attacks are pretty serious. Here's a demo of a meaningful possible fraud resulting from knowing just one md5 collision, possibly found by somebody else: http://www.cits.rub.de/imperia/md/content/magnus/rump_ec05.pdf Something similar can be done with SHA1 if a collision gets published. The work factor for finding an SHA1 collision is now down to O(2**63), which is within range of a distributed internet search. The md5 attack relies on the md5's message-extension property (shared by sha-1): if you find just one collision, you can easily generate an "infinite" family of colliding messages. Anyone know if the sha-2 hashes have that property? From rkern at ucsd.edu Sat Aug 20 16:14:12 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 20 Aug 2005 13:14:12 -0700 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: <7x8xyw2z17.fsf@ruckus.brouhaha.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> <7x8xyw2z17.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Robert Kern writes: > >>>>http://www.catb.org/~esr/faqs/smart-questions.html >>> >>>Is it a *smart* way or *necessary* way? >> >>It's the polite way. And probably the only way you're going to get >>your questions actually answered. > > I wonder if there's a way to killfile posts that contain that url. > They are cluttering up the newsgroup much more than repeated newbie > questions do. You can get a good start by killfiling me. > Sheesh people, if you see a question that you don't feel like > answering, then don't answer. Same goes to you. You don't like the "smart-questions.html" response, so why do you respond? Because you want to change people's behavior. Or perhaps because it pleases you to express your displeasure about it (regardless of any effect that expression might have on other people). Coincidentally, those are exactly the reasons why I posted it in the first place. I care not a whit about decluttering the newgroup, an impossible task. -- 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 tjreedy at udel.edu Mon Aug 22 13:01:45 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Aug 2005 13:01:45 -0400 Subject: loop in python References: <20050823065501.GA24558@mrna.tn.nic.in> <20050823084306.GA24951@mrna.tn.nic.in> Message-ID: "km" wrote in message news:20050823084306.GA24951 at mrna.tn.nic.in... > ya i am sorry i tried with an empty loop first and then one which emits > a value as the snippet. I have tested it on my machine and now ... > > 1) perl (v 5.8) does the job in 0.005 seconds > 2) but python (v 2.4.1) is horribly slow its 0.61 seconds. > and using range() instead of xrange() in python snippet, it not better , > it takes 0.57 seconds. just test it urself and see. I did. "for x in xrange(10000000): pass" (cut and pasted, Python 2.2, 10 million passes) takes about 1.5 second (estimated by 'one thousand and one...' method). Divide by 10000 for your 1000 iteration test. > what more do i need to accept python is slow when it comes to loops > concept ? Valid comparitive data from honest and competant testers with different but properly functioning systems. Terry J. Reedy From Scott.Daniels at Acm.Org Mon Aug 22 15:23:33 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Aug 2005 12:23:33 -0700 Subject: Sanitizing untrusted code for eval() In-Reply-To: <3muhfnF18o689U1@uni-berlin.de> References: <3muhfnF18o689U1@uni-berlin.de> Message-ID: <430a1a45$1@nntp0.pdx.net> Diez B. Roggisch wrote: >> Does anyone know of any other "gotchas" with eval() I have not found? Or >> is eval() simply too evil? > > > Yes - and from what I can see on the JSON-Page, it should be _way_ > easier to simply write a parser your own - that ensures that only you > decide what python code gets called. > > Diez > _ Another thing you can do is use the compile message and then only allow certain bytecodes. Of course this approach means you need to implement this in a major version-dependent fashion, but it saves you the work of mapping source code to python. Eventually there will be another form available (the AST form), but that will show up no earlier than 2.5. As a matter of pure practicality, it turns out you can probably use almost the same code to look at 2.3 and 2.4 byte codes. --Scott David Daniels Scott.Daniels at Acm.Org From peter at engcorp.com Mon Aug 22 12:23:32 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 12:23:32 -0400 Subject: loop in python In-Reply-To: References: <20050823065501.GA24558@mrna.tn.nic.in> Message-ID: km wrote: > ya i am sorry i tried with an empty loop first and then one which > emits a value as the snippet. I have tested it on my machine > and now ... > > what more do i need to accept python is slow when it comes to > loops concept ? You've sort of missed some of the points being made, which in essence are saying "your benchmark is less than useless, and you're confused about what matters". One key point about benchmarking is to make the test representative. If you are going to be running empty loops, then you're doing the right thing. If *all* your loops are going to do is print stuff, then you're doing the right thing with the version that "emits values". On the other hand, if you are really doing something else entirely, then your tests are telling you nothing about your real problem, and are in fact confusing you greatly, which is why they are less than useless. With the part about "confused about what matters" I mean that you are trying to optimize something a) when you don't have working code, and b) when you don't know that you need to make it any faster. The first rule of optimization is to make your code work first, and only then consider making it fast. The second rule of optimization is that you shouldn't waste time doing it unless you really need faster results (and it requires actual elapsed time or response time measurements to know this). Since you haven't got any working code, it's not possible that you *need* whatever negligible speed difference there might be between Python and Perl. And, lastly, in case this thought didn't get through either: Python is *not* significantly slower than Perl except in certain uncommon cases -- perhaps including useless empty loops -- so if you really want to use Python, don't let your first attempts at benchmarking dissuade you. Really, trust us. Python's strengths lie in four things: the readability of the code, the huge range of library modules available, the elegance of its object oriented constructs, and the helpfulness of its community. Raw speed is not one of its strengths, but there are tens of thousands of people using it quite effectively and without daily concern for its speed (same as Perl, by the way since, again, they are _not_ significantly different in speed no matter what an empty loop test shows). -Peter From jepler at unpythonic.net Mon Aug 1 21:10:45 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 1 Aug 2005 20:10:45 -0500 Subject: Tkinter, Menu(bar) font size In-Reply-To: References: Message-ID: <20050802011045.GC9303@unpythonic.net> Tk tries to use the "native" menu control on Windows (and, I think, MacOS). One result seems to be that for the application's menu bar you can't change the font. Of course, Windows provides a way for users to select a uniform font for menu bars in all applications, in the Display control panel. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From wpower at zeta.org.au.nospamplease Sun Aug 21 20:23:37 2005 From: wpower at zeta.org.au.nospamplease (David Trudgett) Date: Mon, 22 Aug 2005 10:23:37 +1000 Subject: Gimp-Python References: Message-ID: danilo writes: > Salve, > > qualcuno sa se ? ancora in fase di sviluppo e qual'? il sito di > riferimento? Beh, tutto e' sempre in fase di sviluppo, non e' vero? An Internet search turns up: http://www.jamesh.id.au/software/pygimp but the site was not responding when I tried it. According to the gimp website (http://www.gimp.org/) the Python bindings have undergone some recent improvements (up to June this year). So, it would appear that these bindings are receiving continued attention. Perhaps you could try a mailing list to find out more? http://www.gimp.org/mail_lists.html Saluti, David -- David Trudgett http://www.zeta.org.au/~wpower/ Cos? uno, il quale fin dalla nascita avesse avuto le gambe legate e pure avesse trovato modo di camminare alla men peggio, potrebbe attribuire la sua facolt? di muoversi precisamente a quei legami, che invece non fanno che diminuire e paralizzare l'energia muscolare delle sue gambe. [...] Figuratevi che all'uomo dalle gambe legate, che abbiamo supposto, il medico esponesse tutta una teoria e mille esempi abilmente inventati per persuaderlo che colle gambe sciolte egli non potrebbe n? camminare, ne vivere; quell'uomo difenderebbe rabbiosamente i suoi legami e considererebbe nemico chi volesse spezzarglieli. -- Errico Malatesta, "Anarchia" From geskerrett at hotmail.com Tue Aug 23 22:04:45 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 23 Aug 2005 19:04:45 -0700 Subject: Anyone recognize this numeric storage format - similar to "float", but not quite Message-ID: <1124849085.656718.97720@g43g2000cwa.googlegroups.com> We are working on a project to decipher a record structure of an old accounting system that originates from the late80's mid-90's. We have come across a number format that appears to be a "float" but doesn't match any of the more standard implementations. so we are hoping this is a recognizable number storage format with an identifiable name AND pre-built conversion method similiar to the "struct" modules available in python. Here is what we have determined so far. Example Number: 1234567890 This get stored on disk as 8 bytes, resulting in the following HEX characters; 00 00 00 A4 05 2c 13 9f If we changed the order so that it is "little Endian" we get; 9F 13 2c 05 A4 00 00 00 If the HEX is converted to binary it looks like; 10011111 00010011 00101100 00000101 10100100 00000000 000000000 00000000 If the example number 1234567890 is converted to binary it looks like; 10010011 00101100 00000101 1010010 To extract the example number, you need to do the following; 1) take the decimal value of the first byte and subtract 128 2) This tells you how many of the following bits to are significant and must be read 3) Once the remaining bits are read, reverse the first bit of that group (ie if it is a 0 make it a 1) 4) convert the result to decimal ... and presto, the example number ! Using a fixed width font it is easy to see the match at the bit level; 10011111 00010011001011000000010110100100000000000000000000000000 -------- 1001001100101100000001011010010 If you are interested, the following are three other examples; Orig Hex: 00 00 00 60 92 96 72 A0 Actual Value: 4069954144 Orig Hex: 00 00 80 22 A3 26 3C A1 Actual Value: 6313297477 So ... does anyone recognize this ?? Is there a "built-in" conversion method in Python ?? Thanks in advance. From qvx3000 at gmail.com Mon Aug 1 08:03:57 2005 From: qvx3000 at gmail.com (qvx) Date: 1 Aug 2005 05:03:57 -0700 Subject: PEP on path module for standard library References: <11e06nch396gccd@news.supernews.com> <3kakh5Ftjd9mU1@individual.net> <11e0cpe7vqrm18a@news.supernews.com> <1121992173.719316df1430a706987a33a518e6ea2d@teranews> <42e15f81$1@news.eftel.com> <42e29d5c.963163926@news.oz.net> Message-ID: <1122897837.894592.225070@g43g2000cwa.googlegroups.com> Ron Adam wrote: > Bengt Richter wrote: > > > References: <200508010830.27322.ed@leafe.com> <200508011134.14398.jstroud@mbi.ucla.edu> Message-ID: <200508011445.36037.ed@leafe.com> On Monday 01 August 2005 14:34, James Stroud wrote: > I don't know. Defense code sounds like a PITA. But maybe give a hint in the > INSTALL file, or a link to the proper wxPython install? These are the > obvious things that might help people like me at least get to the point > where we can see what your software does. Take a look at the SciPy module > for good instructions. It would have been hell without the precise list of > prerequisites in the INSTALL.txt file. OK, thanks for the pointer. We appreciate all of these good ideas! -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From merkosh at hadiko.de Fri Aug 12 16:03:17 2005 From: merkosh at hadiko.de (Uwe Mayer) Date: Fri, 12 Aug 2005 22:03:17 +0200 Subject: Bug on Python2.3.4 [FreeBSD]? References: Message-ID: Friday 12 August 2005 22:12 pm paolino wrote: [...] >>>>>f = open('test', 'a+') >>>>>f.read() >> >> '' >> >> -> append mode does not read from file, *not ok* >> >> > This is right IMO 'a' is appending so seek(-1) True, thank you. f.tell() shows the file pointer is at EOF. On my Debian Linux (unstable), Python 2.3.4 +2.3.5, however, the file pointer is at the beginning of the file. Is that behaviour intended? Ciao Uwe From andreas at kostyrka.org Sun Aug 14 08:37:44 2005 From: andreas at kostyrka.org (Andreas Kostyrka) Date: Sun, 14 Aug 2005 14:37:44 +0200 Subject: Parsing a log file In-Reply-To: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> References: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> Message-ID: <1124023065.4871.5.camel@andi-lap> Am Samstag, den 13.08.2005, 14:01 -0700 schrieb CG: Well, you have described your problem nicely. One thing that's missing is how to deal with incorrect input. (For example missing connect or disconnect messages). Furthermore, you can now: a) try to find somebody who writes it for you. How you motivate that person is another question. b) try to hack some solution yourself. Start with doing the python tutorial? Andreas > I am looking for a way to parse a simple log file to get the > information in a format that I can use. I would like to use python, > but I am just beginning to learn how to use it. I am not a programmer, > but have done some simple modifications and revisions of scripts. I am > willing to attempt this on my own, if someone can point me in the right > direction (any example scripts that do similar things would be > helpful). This doesn't have to be Python, but I need a cross-platform > solution (i.e. Perl or some other kind of script). I just wanted to > try Python because I like the concept of it. > > Here is my scenario: > I have a program that connects and disconnects to a server. It writes > a simple log file like this: > > 08-13-2005 13:19:37:564 Program: CONNECTED to 'Server' > 08-13-2005 15:40:08:313 Program: DISCONNECTED from 'Server' > 08-13-2005 15:45:39:234 Program: CONNECTED to 'Server' > 08-13-2005 15:55:18:113 Program: DISCONNECTED from 'Server' > 08-13-2005 16:30:57:264 Program: CONNECTED to 'Server' > 08-13-2005 16:59:46:417 Program: DISCONNECTED from 'Server' > 08-13-2005 17:10:33:264 Program: CONNECTED to 'Server' > 08-13-2005 18:25:26:316 Program: DISCONNECTED from 'Server' > 08-13-2005 18:58:13:564 Program: CONNECTED to 'Server' > 08-13-2005 19:29:10:715 Program: DISCONNECTED from 'Server' > > What I basically want to do is end up with a text file that can be > easily imported into a database with a format like this (or I guess it > could be written in a SQL script form that could write directly to a > database like Mysql): > > Connect_Date Connect_Time Disconnect_date Disconnect_time User > ------------ ------------ --------------- --------------- ------- > 08-13-2005 13:19:37 08-13-2005 15:40:08 John > 08-13-2005 15:45:39 08-13-2005 15:55:18 John > 08-13-2005 16:30:57 08-13-2005 16:59:46 John > 08-13-2005 17:10:33 08-13-2005 18:25:26 John > 08-13-2005 18:58:13 08-13-2005 19:29:10 John > > Here are some notes about this: > * the username would come from the log file name (i.e. > John_Connect.log) > * I don't need the fractions of seconds in the timestamps > * I only need date, time, and connect or disconnect, the other info is > not important > * If it is possible to calculate the elapsed time between Connect and > Disconnect and create a new field with that data, that would help (but > I can easily do that with SQL queries) > * This log file layout seems to be consistent > * There may not be a "disconnect" statement if the log file is read > while connected, so the next time it would have to insert the > disconnect information. The file will be read quite regularly, so this > is very likely. > * This would eventually need to be done without intervention (maybe > every 5 minutes). > > I am open to other ideas or existing programs and am flexible about the > final solution. > > Thanks, > Clint > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Dies ist ein digital signierter Nachrichtenteil URL: From rkern at ucsd.edu Mon Aug 29 05:13:17 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 29 Aug 2005 02:13:17 -0700 Subject: variable hell In-Reply-To: References: Message-ID: Adriaan Renting wrote: > My original code was: exec(eval("'a%s=%s' % (count, value)")) > Then Rafi said: exec("'a%s=%s' % (count, value)") > To which I responded that his example does not work in my Python, and I think it's invalid. > Then Martin came with: exec 'a%s = %s' % (count, value) > This does work. > But he seems to keep telling me I'm quoting him wrong, while I'm quoting Rafi. Read more carefully. rafi did not put in the extraneous quotes. rafi: >>Adriaan Renting wrote: >> >>>You might be able to do something along the lines of >>> >>>for count in range(0,maxcount): >>>value = values[count] >>>exec(eval("'a%s=%s' % (count, value)")) >> >>why using the eval? >> >>exec ('a%s=%s' % (count, value)) >> >>should be fine >> >>-- >>rafi See? No extra quotes. -- 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 wezzy at despammed.com Sat Aug 27 09:24:51 2005 From: wezzy at despammed.com (Wezzy) Date: Sat, 27 Aug 2005 15:24:51 +0200 Subject: Modify a C++ instance from the embed python interpreter Message-ID: <1h1yl9h.1x14zs71pjw5fyN%wezzy@despammed.com> Hi, is there a tool that automatically expose an object to python? i have an instance of a C++ (or ObjC) object and i want to pass it to the embed interpreter that runs inside my program. Python code have to call c++ method and register some callback. I know that swig helps when python creates c++ instance but i've the instance and i want to use it with python. Thanks -- Ciao Fabio From rabkin at mweb[DOT]co[DOT]za Fri Aug 19 18:30:15 2005 From: rabkin at mweb[DOT]co[DOT]za (Max) Date: Sat, 20 Aug 2005 00:30:15 +0200 Subject: servers in python Message-ID: I am writing a Hashcash program in python. Rather than create an email client plugin, I have done this thru a proxy server which adds the Hashcash before forwarding. What I want to know is whether this is safe. I currently use this code: class HashcashServer (smtpd.PureProxy): def process_message (self, peer, mailfrom, rcpttos, data): if peer[0] in trusted_peers: # add Hashcash and forward else: pass where trusted_peers is a list of peers that are allowed to use the service (it is currently just ["localhost"]). Is there risk of any hacking, or of this becoming an open relay? --Max From bokr at oz.net Mon Aug 8 15:49:54 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 08 Aug 2005 19:49:54 GMT Subject: Fat and happy Pythonistas (was Re: Replacement forkeyword'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com><11f84j8elj07271@news.supernews.com><861x57wrui.fsf@bhuda.mired.org><11f9f9u2enfsi58@news.supernews.com><11f9u843r0fts5b@news.supernews.com><86br4avf5t.fsf@bhuda.mired.org><11fakjctean9u8a@news.supernews.com> <42f6b12e.871276739@news.oz.net> Message-ID: <42f7b483.937665701@news.oz.net> On Sun, 7 Aug 2005 23:52:40 -0400, "Terry Reedy" wrote: > >"Bengt Richter" wrote in message >news:42f6b12e.871276739 at news.oz.net... >> I think the relationship of abstract entities and their concrete >> representations >> is very interesting. > >ditto > >> BTW, maybe this is a place to mention the concept of an AST decorator, >> that works like >> a function decorator except that it is prefixed with @@ instead of @ and >> it operates >> at compile time when the AST becomes available, but before it gets >> translated to code, >> and what gets passed to the decorator is the AST > >One can do this much today: > >import compiler > >new_ast = ast_transformer(compiler.parse('''\ > >''') > >However, I can't see any way in the docs to get a code object from the AST. >I believe the AST-to-code compilet is currently being worked on. When it >is, @@ would be nice syntactic sugar but not really necessary. > >> The idea is that this form of decoration could transform the >> AST arbitrarily before code generation, and be a very flexible tool >> for mischief of course, but also useful tricky things. > >At the moment, we are limited to manipulating concrete text before >compiling it. > Have we gone backwards from this? http://groups.google.com/group/comp.lang.python/browse_thread/thread/5fa80186d9f067f4/7a2351b221063a8c I've been meaning to do something with that, to implement @@ decoration, I think probably in the context of a customized importer, where I would be able to control the whole source conversion process, anticipating usage something like (ut is my hodgepodge utility package ;-) from ut.astdecoimport import astdecoimport amodule = astdecoimport('amodule') # searches like import for amodule.py and does its thing Regards, Bengt Richter From lemon97 at gmail.com Sat Aug 6 22:01:44 2005 From: lemon97 at gmail.com (lemon97 at gmail.com) Date: 6 Aug 2005 19:01:44 -0700 Subject: Get directory from http web site References: <1122029473.532056.215900@z14g2000cwz.googlegroups.com> <42f52102$1_3@newspeer2.tds.net> Message-ID: <1123379699.223534.180860@g14g2000cwa.googlegroups.com> You might want to also modify your c:/python/Lib/urllib.py file. By adding/modifying the following headers. self.addheaders = [('User-agent', 'Mozilla/4.0')] #Trick the server into thinking it is explorer self.addheaders = [('Referer','http://www.infomedia.it')] #Trick the site that you clicked on a link from their site. From tjreedy at udel.edu Wed Aug 17 17:07:58 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Aug 2005 17:07:58 -0400 Subject: creating/modifying sparse files on linux References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> Message-ID: wrote in message news:1124304819.090356.200280 at f14g2000cwb.googlegroups.com... > Is there any special support for sparse file handling in python? Since I have not heard of such in several years, I suspect not. CPython, normally compiled, uses the standard C stdio lib. If your system+C has a sparseIO lib, you would probably have to compile specially to use it. > options.size = 6442450944 > options.ranges = ["4096,1024","30000,314572800"] options.ranges = [(4096,1024),(30000,314572800)] # makes below nicer > fd = open("testfile", "w") > fd.seek(options.size-1) > fd.write("a") > for drange in options.ranges: > off = int(drange.split(",")[0]) > len = int(drange.split(",")[1]) off,len = map(int, drange.split(",")) # or off,len = [int(s) for s in drange.split(",")] # or for tuples as suggested above off,len = drange > print "off =", off, " len =", len > fd.seek(off) > for x in range(len): If I read the above right, the 2nd len is 300,000,000+ making the space needed for the range list a few gigabytes. I suspect this is where you started thrashing ;-). Instead: for x in xrange(len): # this is what xrange is for ;-) > fd.write("a") Without indent, this is syntax error, so if your code ran at all, this cannot be an exact copy. Even with xrange fix, 300,000,000 writes will be slow. I would expect that an real application should create or accumulate chunks larger than single chars. > fd.close() > > This piece of code takes very long time and in fact I had to kill it as > the linux system started doing lot of swapping. Am I doing something > wrong here? See above > Is there a better way to create/modify sparse files? Unless you can access builting facilities, create your own mapping index. Terry J. Reedy From simon.brunning at gmail.com Mon Aug 15 07:40:10 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Mon, 15 Aug 2005 12:40:10 +0100 Subject: tuple assign variables In-Reply-To: References: Message-ID: <8c7f10c605081504405bf33260@mail.gmail.com> On 8/13/05, dimitri pater wrote: > selecting a record from a MySQL database results in a tuple like this: > (('Evelyn', 'Dog', 'No'),) > I want to assign every item of that tuple to a variable using this code > (deep_list is taken from the Python Cookbook): > > def deep_list(x): > if type(x)!=type( () ): > return x > return map(deep_list,x) > > mytuple = (('Evelyn', 'Dog', 'No'),) > mylist = deep_list(mytuple) > for item in mylist: > name, pet, modified = item > > it woks fine, but I wonder if there is a better way to achieve this. > Any suggestions? I'm fond of Greg Stein's dtuple module[1]. I've never used it with MySQL, so YMMV, but using it might look something like: cursor.execute(sql_statement) descriptor = dtuple.TupleDescriptor(cursor.description) for row in (dtuple.DatabaseTuple(descriptor, row) for row in cursor.fetchall()): print row.name # Prints "Evelyn" # etc... If your result set will be large, see also ResultIter[2]. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ [1] http://www.lyra.org/greg/python/dtuple.py [2] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/137270 From skip at pobox.com Sat Aug 27 15:57:25 2005 From: skip at pobox.com (skip at pobox.com) Date: Sat, 27 Aug 2005 14:57:25 -0500 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <7xirxri3x5.fsf@ruckus.brouhaha.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> <7xslww10ur.fsf@ruckus.brouhaha.co <7xirxri3x5.fsf@ruckus.brouhaha.com> Message-ID: <17168.50597.306522.169344@montanaro.dyndns.org> Paul> Steve Holden writes: >> A corrected find() that returns None on failure is a five-liner. Paul> If I wanted to write five lines instead of one everywhere in a Paul> Python program, I'd use Java. +1 for QOTW. Skip From mathmom at gmail.com Sat Aug 13 03:13:35 2005 From: mathmom at gmail.com (Sheila King) Date: 13 Aug 2005 00:13:35 -0700 Subject: socket setdefaulttimeout In-Reply-To: References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> <8122246.VFEYWSAU@news.verizon.net> Message-ID: <1123917214.884226.311710@g49g2000cwa.googlegroups.com> Bryan: Thanks for the tips/suggestion. I will definitely look into that. (It will be my first foray into coding with threads...I do appreciate that you've laid a great deal of it out. I will certainly refer to my references and do substantial testing on this...) Thanks! -- Sheila King http://www.thinkspot.net/sheila/ From spammers-go-here at spam.invalid Tue Aug 30 17:28:29 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Tue, 30 Aug 2005 17:28:29 -0400 Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk> <4314c264.178329924@news.oz.net> Message-ID: <4314cf38$0$18648$14726298@news.sunsite.dk> Bengt Richter wrote: > windows or unix? time.time and time.clock seem to reverse roles as > best-resolution time sources depending on which platform. > Linux. time.time() seems to report (using %e to format the o/p) a fixed number of the order ~1e9. > If you have a pentium with a rdtsc instruction, you can write an extension > module in c to get at it. In C on a 300mhz p2 I got down to 23ns minimum > delta between calls, IIRC. But even then I was subject to the small I do not need ns resolution. A few microseconds would be fine. > probability of an interrupt during my timing loop, and there are many > normally going on, so the longer the interval you are timing the greater > the probability that an interrupt will occur within it (assuming random > independence, which is also not necessarily true). This is why timing > frameworks generally either average brute force or discard outlier timings > and average, or return best-of. All these have different error properties, > and depend on lots of stuff. > > I'm wondering whats your application is. Maybe you need a real-time OS? No, no. All I am looking for is for the system to report its time with better resolution. I know it is possible on my hardware, because I can get at very precise timings using Fortran 95 intrinsics in my other code. However, with Python's time module, I do not seem to be able to access it. From python at rcn.com Wed Aug 3 21:21:10 2005 From: python at rcn.com (Raymond Hettinger) Date: 3 Aug 2005 18:21:10 -0700 Subject: Art of Unit Testing References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> Message-ID: <1123118470.749836.279610@g14g2000cwa.googlegroups.com> Christoph Zwerschke wrote: > I wasn't aware of the py lib so far. The > possibility to create fixtures at the three different scopes is exactly > what I was looking for. > > Anyway, I think it would be nice to have that feature in the standard > lib unittest as well. It should not be too hard to add setUpOnce and > tearDownOnce methods in addition to setUp and tearDown. Actually, I am > wondering that there doesn't seem to be any development progress since > unittest was included in the standard lib of Python 2.1 in August 2001. > I had expected that such an important module would be continually > improved and maintained. How come? So few people using unit tests? Or do > most people write their own testing code or use py.test? Voice of Mr. Unittest: """ The details of the implementation are not nearly as important as the test cases. If you can support a set of test cases like the ones given here, then you can write tests that are isolated and can be composed, and you will be on your way to being able to develop test-first. . . . The spirit of xUnit is simplicity. . . . Some of the implementations have gotten a little complicated for my taste. """ -- Kent Beck, Test Driven Development, p. 119. Python's unittest module is already a bit to complicated. Building it out further would be a step in the wrong direction. As it stands now, it is somewhat powerful and flexible without being overly difficult to learn. FWIW, it does not take much skill to use the existing unittest module to meet advanced testing needs. Lib/test/test_decimal.py has few lines that dynamically build a whole suite of tests from a directory of text resource files. Lib/test/test_compiler.py has just a few lines to shorten testing time by running a random subset of tests. Lib/test/test_deque.py has a handful of lines to run the suite multiple times to check reference counts and it incorporates a doctest suite to verify the examples in the documentation. Your own feature request for setUpOnce() and tearDownOnce() is trivially coded using a global or class variable to restrict running to a single occasion. If that seems unpleasant, then encapsulate the logic in a subclass of TestCase, in a decorator, or in a metaclass. If you want better, try py lib's py.test module which is both more minimalistic and more powerful. Raymond P.S. The above is based on the experience of writing thousands of lines of test code. The existing unittest module is just fine without further buildout. If it weren't for backwards compatibility issues, I would recommend pairing it down further -- only a small subset of its features are necessary to meet most needs. From ptmcg at austin.rr.com Wed Aug 10 09:27:18 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 10 Aug 2005 06:27:18 -0700 Subject: Help with Regular Expressions References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> Message-ID: <1123680438.327709.171480@z14g2000cwz.googlegroups.com> If your re demands get more complicated, you could take a look at pyparsing. The code is a bit more verbose, but many find it easier to compose their expressions using pyparsing's classes, such as Literal, OneOrMore, Optional, etc., plus a number of built-in helper functions and expressions, including delimitedList, quotedString, and cStyleComment. Pyparsing is intended for writing recursive-descent parsers, but can also be used (and is best learned) with simple applications such as this one. Here is a simple script for parsing your e-mail addresses. Note the use of results names to give you access to the individual parsed fields (re's also support a similar capability). Download pyparsing at http://pyparsing.sourceforge.net. -- Paul from pyparsing import Literal,Word,Optional,\ delimitedList,alphanums # define format of an email address AT = Literal("@").suppress() emailWord = Word(alphanums+"_") emailDomain = delimitedList( emailWord, ".", combine=True) emailAddress = emailWord.setResultsName("user") + \ Optional( AT + emailDomain ).setResultsName("host") # parse each word in wordList wordList = ['myname1', 'myname1 at domain.tld', 'myname2 at domain.tld', 'myname4 at domain', 'myname5 at domain.tldx'] for w in wordList: addr = emailAddress.parseString(w) print w print addr print "user:", addr.user print "host:", addr.host print Will print out: myname1 ['myname1'] user: myname1 host: myname1 at domain.tld ['myname1', 'domain.tld'] user: myname1 host: domain.tld myname2 at domain.tld ['myname2', 'domain.tld'] user: myname2 host: domain.tld myname4 at domain ['myname4', 'domain'] user: myname4 host: domain myname5 at domain.tldx ['myname5', 'domain.tldx'] user: myname5 host: domain.tldx From martin at v.loewis.de Fri Aug 26 17:51:41 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 26 Aug 2005 23:51:41 +0200 Subject: Command Line arguments In-Reply-To: <20050826170732.GF2012@ActiveState.com> References: <9gtqg1lkso6m6ukipku1ac7hk9sejhi3ld@4ax.com> <20050826170732.GF2012@ActiveState.com> Message-ID: <430F8EED.1000000@v.loewis.de> Trent Mick wrote: >>I used the python2.4.MSI from python.org site (dated 3-6-05). I think this >>was the first time they went to MSI verses an exe based installer. >> >>it says Python 2.4 (#60 November 30th, 2004) when I start it. > > > I think Martin has been doing MSIs for a little bit longer than that, > but I'm not sure. I started after 2.3, but MSIs were released for the 2.4 alpha and beta releases, as well. > Martin, is it possible that there is a bug in setting up the > .py/Python.File association in the python2.4.msi? Here is the start of > this thread: > > http://mail.python.org/pipermail/python-list/2005-August/296007.html I don't think the 2.4 MSI has such a bug. There were various issues in the alpha releases, but they got resolved. There was a bug in the shortcuts (IDLE would not start if TARGETDIR had a space in it), but that is an unrelated issue. Please refer to http://www.python.org/2.4/bugs.html for the most frequently reported bugs in 2.4. > What association (if any) does your Python MSI setup? "assoc .py" gives "Python.File", "ftype Python.File" gives Python.File="C:\Python24\python.exe" "%1" %* This is all done through registry (i.e. no advertised extensions). Software\Classes\.py is Python.File, Software\Classes\Python.File\shell\open\command is "[TARGETDIR]python.exe" "%1" %* My guess is that the MSI file was installed "Just for me", and then a different user tries to find the associations, which fails as they are in the other user's profile. Alternatively, the "Register Extensions" feature in the "Customize Python 2.4" dialog may have been deselected. Regards, Martin From bokr at oz.net Mon Aug 8 20:48:01 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 09 Aug 2005 00:48:01 GMT Subject: PEP: Specialization Syntax References: <42f695f8.864310192@news.oz.net> <42f79137.928629067@news.oz.net> <42f7ef3b.952697616@news.oz.net> Message-ID: <42f7fbc1.955903576@news.oz.net> On Tue, 09 Aug 2005 00:14:25 GMT, bokr at oz.net (Bengt Richter) wrote: [...] >Here is a decorator object to set up function call dispatch according to type. >It only uses positional arguments, but could be fleshed out, I think. >Not tested beyond what you see ;-) > >----< typedispatcher.py >------------------------------------------------- ># typedispatcher.py [...] > assert len(set([f.func_name]+list(f.func_name for f in self.dispdict.values()))) [...] Oops, that was a leftover hack that was supposed to check that all names were the same, and was missing ==1 at the right. Replaced by using self.name. Sorry. There's probably more, but the overall idea should be clear. Using **kw is also a leftover of starting down the trail of handling more signature variants, but I was too lazy. Regards, Bengt Richter From jeffrey.schwab at rcn.com Sat Aug 20 16:47:13 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sat, 20 Aug 2005 16:47:13 -0400 Subject: stdin -> stdout In-Reply-To: References: Message-ID: max(01)* wrote: > i was wondering, what's the simplest way to echo the standard input to > the standard output, with no modification. ... > ps: in perl you ca do this: > > ... > while ($line = ) > { > print STDOUT ("$line"); > } > ... I guess you could, but there wouldn't be much point. In Perl, you can do this with just command-line flags: perl -pe '' input.txt Or if you really want something to put in a file: print <> Here's the closest thing I could come up with in Python: import sys for line in sys.stdin: print line, From grante at visi.com Sat Aug 20 16:04:29 2005 From: grante at visi.com (Grant Edwards) Date: Sat, 20 Aug 2005 20:04:29 -0000 Subject: Well, another try Re: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> Message-ID: <11gf36deur9vf95@corp.supernews.com> On 2005-08-20, James wrote: >> for data in iter(lambda:f.read(1024), ''): >> for c in data: > > What are the meanings of Commands 'iter' and 'lambda', respectively? I > do not want you to indicate merely the related help pages. Rude much? If somebody is kind enough to point out the documentation that answers your question you ought to read it. > Just your ituitive and short explanations would be enough > since I'm really newbie to Python. What makes you think my "intuitive and short" explanation is goign to be better than what's aready written? Why should I take the time? -- Grant Edwards grante Yow! People humiliating at a salami! visi.com From phillip.watts at anvilcom.com Wed Aug 17 18:58:27 2005 From: phillip.watts at anvilcom.com (phil) Date: Wed, 17 Aug 2005 17:58:27 -0500 Subject: GUI tookit for science and education References: <7xek8vsxua.fsf@ruckus.brouhaha.com> Message-ID: <4303C113.9000008@anvilcom.com> > As I said, I'm looking for multiplatform solution. > So, I will go with Python, Tk and C++ (for algorithm and critical parts > of applications). Tk is simple, very simple, Python I like, C++ I love, > as I'm professional C++ programmer. Good choice! From fperez.net at gmail.com Thu Aug 11 14:52:52 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Thu, 11 Aug 2005 12:52:52 -0600 Subject: interpreter frame References: <1123689998.800361.278370@g43g2000cwa.googlegroups.com> <1123711701.529320.85880@g14g2000cwa.googlegroups.com> Message-ID: Peter Hansen wrote: > Leo wrote: >> Good try, but that doesn't seem to work either. Maybe I should have >> emphasized that what I really want is the line of code, as opposed to >> the entire frame. > > Ah, it wasn't clear from your first post that you were specifically > interested in a line you entered at the *interactive prompt*. The word > "interpreter" is sometimes applied to the virtual machine, so I thought > you just wanted the current frame inside an application. > > For the "interactive interpreter", I doubt the line of code that you are > executing is preserved anywhere (at least not in a supported, documented > fashion) as source, so I don't think there's a simple way to get at it. > Certainly not (I believe) through the frame or code object. Maybe > checking the source will lead to a hack solution... If using the mock interpreter in code.py (in the stdlib), the object's .buffer attribute holds that info as a list of lines. IPython exposes it publicly via its custom exception handlers mechanism (some details here: http://www.scipy.org/wikis/featurerequests/IPython). Such a buffer must also exist in the CPython interactive interpreter, but I don't think it's accessible in any way via Python-level functionality (it's most likely an internal C variable). But some perusing of the C sources could indicate a way to get to it, I'm just not familiar with that particular code. Cheers, f From rafi at free.fr Thu Aug 25 15:55:32 2005 From: rafi at free.fr (rafi) Date: Thu, 25 Aug 2005 21:55:32 +0200 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: <430e222c$0$283$626a14ce@news.free.fr> Stelios Xanthakis wrote: > Mark Dickinson wrote: > >> I have a simple 192-line Python script that begins with the line: >> >> dummy0 = 47 >> >> The script runs in less than 2.5 seconds. The variable dummy0 is never >> referenced again, directly or indirectly, by the rest of the script. >> >> Here's the surprise: if I remove or comment out this first line, the >> script takes more than 15 seconds to run. So it appears that adding a >> redundant line produces a spectacular six-fold increase in speed! >> >> (Actually, I had to add 29 dummy lines at the beginning of the code to >> get the speed increase; if any one of these lines is removed the >> running time reverts to around 15 seconds again.) >> >> Questions: >> >> (1) Can anyone else reproduce this behaviour, or is it just some quirk >> of my setup? >> (2) Any possible explanations? Is there some optimization that kicks >> in at a certain number of lines, or at a certain length of >> bytecode? >> (3) If (2), is there some way to force the optimization, so that I can >> get the speed increase without having to add the extra lines? >> > > Hi. > > I haven't been able to reproduce this but I had a similar case > before (a program that some times crashed and some times worked > perfectly and the difference was whitespace in the comments!!!). > > After lots of wondering and thinking that I must be dreaming > (luckily I had pyvm which also crashed but for different amounts > of whitespace), it was solved. The explanation is this: hash > and comparison of objects depends on the state of the memory > allocator. A sample case is this: > > class A: pass > dummy0=47 # comment this to get a different result for min > a=A() > b=A() > print min (a, b) > > the result of 'min' is not only non-deterministic but also depends > on whether other things have been allocated before. The same > thing can happen for 'dictionary.keys()' if the keys are objects > and 'iterate-over-set' when the set contains objects. I do not get the point here: isn't min comparing the adress in memory as there is nothing else to compare? [python 2.4.1 on ubuntu linux] On 10 runs from within emacs I had about 50% for `a' and 50% for `b' returned by min (a,b). It was the same without the dummy0=47. On 10 runs from the command line I had always `a' returned (with and without the dummy). The only difference was the address of b's object. (For all the run of each case the two addresses were exactly the same) For your first post: On 10 tests run for each case (average time, but each time was never different one from the other more that .02s) 0.554 when the 28 dummies are in place 6.679 when commented out, removed or put in a single multiline string 2.576 when putting the 28 dummies in a list or a dict using a for loop 7.195 when creating the 28 dummies using an exec in a for loop What about memory allocation that would be performed chunk by chunk by the interpreter? Then being at the end or at the beginning of a chunk may not be the same for processing? All the instructions of the program would then be in the cpu cache for example in the same block while in the other case theyr would be in two distinct block -> thus less caching for the cpu... [this particular problem arose when I was working several year ago on a persistent object manager for a distributed operating system] -- rafi "Imagination is more important than knowledge." (Albert Einstein) From alanmk at hotmail.com Tue Aug 30 09:50:52 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Tue, 30 Aug 2005 14:50:52 +0100 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. Message-ID: Hi All, If there any contributors of SpamBayes reading, Congratulations! SpamBayes has won the Personal Computer World (pcw.co.uk) Editors Choice award for anti-spam software, in a review of anti-SPAM solutions in the October 2005 edition. (PCW, for those who don't know it, is sort of the UK's equivalent of Byte Magazine, except that it's still publishing after almost 25 years). SpamBayes was one of two open-source apps in the group review, which included commercial products from Symantec, McAfee, and half a dozen other companies. """ ... SpamBayes 1.0.1 is definitely in a league of its own: during our tests it obtained a 100% real success rate. It would have to be trained for several months in order to check that it isn't too strict on a daily basis and that it lets most of the "good" messages through. However, the fact that it's free, offers a high level of efficiency and is compatible with Outlook makes it ideal for anyone looking for a zero cost solution. As such, we think it deserves our Editor's Choice award. As with all Bayesian filters, it gets better with use, especially in terms of detecting wanted mail. """ The only problem was they listed the "manufacturer" of the software as SourceForge, so the product was known as "SourceForge SpamBayes". You guys need to come up a team/manufacturer name. (But there is a screenshot of the software in the review, and the "Python Powered" logo is right there for all to see). Congratulations! Unfortunately, PCW don't seem to have made the review available online (yet), so I can't provide a URL. Maybe someone else will have more success finding a URL? thought-ye'd-like-to-know-ly'yrs, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From onurb at xiludom.gro Thu Aug 18 04:25:56 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 18 Aug 2005 10:25:56 +0200 Subject: how do i add a new path into sys.path? In-Reply-To: References: Message-ID: <43044615$0$4172$636a15ce@news.free.fr> wen wrote: > on my system(win2k server, python 2.3.5), > >>>>import sys >>>>print sys.path > > ['C:\\', 'C:\\WINNT\\system32\\python23.zip', > 'C:\\Python23\\lib\\site-packages\\Pythonwin', > 'C:\\Python23\\lib\\site-packages\\win32', > 'C:\\Python23\\lib\\site-packages\\win32\\lib', > 'C:\\Python23\\lib\\site-packages', 'C:\\Python23\\DLLs', > 'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win', > 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano > Scientific\\PyMOL\\modules'] > > now, i wanna add "C:\Python23\Pmw\Pmw_1_2\lib" into sys.path, how? > any help would be appreciated. hint 1: Python lists have an append() and an insert() method hint 2: sys.path is a list HTH -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From __peter__ at web.de Wed Aug 17 02:21:41 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Aug 2005 08:21:41 +0200 Subject: keeping a ref to a non-member function in a class References: <43028594.4090205@itga.com.au> Message-ID: Gregory Bond wrote: > Thanks Peter, that's a big help. You're welcome. > I can solve my problem now, but I'm chasing this further in the name of > education, because it seems there is some deep magic happening here that > I don't understand. Python resorts to deep magic only when it's inevitable, i. e. hardly ever :-) > It seems that applying staticfunction() (or perhaps assigning to the > class object) is treated differently if it happens in the class > defininition, to when it happens at "run time". (My previous attempts > to get staticmember() to do the right thing were all "run time" like the > examples below.) There is no distinction between "run time" and "class definition time". The class "body" is actually a function that is called when the module is loaded. Its locals() are then used to create a type instance, i. e. the class. > Say I wanted to keep the need for "staticmember" hidden from subclasses, > and do the staticmember() conversion in the base class methods. I've > tried 2 ways of doing this (no subclassing here, just to keep it simple): > >> class B(object): >> fn = foo >> def try1(self): >> print "B.fn is", type(B.fn) >> B.fn = staticmethod(B.fn) >> print "B try1" >> print "B.fn is now", type(B.fn) >> B.fn() >> >> def try2(self): >> fn2 = staticmethod(B.fn) >> print "B try2" >> print "fn2 is now", type(fn2) >> fn2() > > If I try method 1 (assigning to the class object - ignore for a moment > the problem of only doing this once!) I get a set of very surprising > results: > >> B.fn is >> B try1 >> B.fn is now >> Traceback (most recent call last): >> File "t_o1.py", line 28, in ? >> B().try1() >> File "t_o1.py", line 17, in try1 >> B.fn() >> TypeError: unbound method foo() must be called with B instance as first >> argument (got nothing instead) > > note that assigning the staticmember() result to B.fn does NOT change > the type of B.fn!! And foo is treated as a member function. > > So if I try method 2 (using staticmethod() at runtime): > >> B try2 >> fn2 is now >> Traceback (most recent call last): >> File "t_o1.py", line 27, in ? >> B().try2() >> File "t_o1.py", line 22, in try2 >> fn2() >> TypeError: 'staticmethod' object is not callable > > fn2 is a static method, as I'd expect, but it is somehow not callable? Your problems stem from the fact that attribute assignment to a class doesn't always roundtrip: >>> A.value = 42 >>> A.value 42 >>> def f(): pass ... >>> A.method = f >>> A.method, f (, ) If a class attribute is a descriptor i. e. it has a __get__() method (which pure python functions do) A.method is not just a dictionary lookup but a call A.__dict__["method"].__get__(None, A) This is slightly simplified as it doesn't take inheritance into account. __get__() is free to apply whatever magic, but staticmethod just gives back the original function whereas a some_func.__get__(None, SomeClass) gives you an unbound method: >>> staticmethod(f).__get__(None, A) >>> f.__get__(None, A) Is there a way to get the original function back out of the unbound method? Let's see: >>> dir(A.method) ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func', 'im_self'] im_func seems promising: >>> A.method.im_func > Can someone explain what is going on here? Pointers to language spec, > code, PEPs etc gladly accepted. > > Greg, > caught in a twisty little maze of descriptors, all different! The two relevant documents are http://users.rcn.com/python/download/Descriptor.htm http://www.python.org/2.2.1/descrintro.html Peter From percivall at gmail.com Fri Aug 19 15:43:12 2005 From: percivall at gmail.com (Simon Percivall) Date: 19 Aug 2005 12:43:12 -0700 Subject: python classes taught In-Reply-To: <1124476622.522386.166050@g14g2000cwa.googlegroups.com> References: <1124476622.522386.166050@g14g2000cwa.googlegroups.com> Message-ID: <1124480591.887738.280700@f14g2000cwb.googlegroups.com> Yeha, sure. The Royal Institute of Technology in Stockholm, Sweden teaches Python for some of its introductory programming and algorithm courses. From twic at urchin.earth.li Wed Aug 3 11:54:28 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 3 Aug 2005 16:54:28 +0100 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <1122912406.19618.333.camel@localhost.localdomain> Message-ID: On Mon, 1 Aug 2005, Benji York wrote: > Cliff Wells wrote: > >> As I mentioned earlier, programming is half brains and half >> tenacity. > > +1 QOTY (quote of the year) Personally, i'd say it was 50% brains, 40% tenacity and 20% basic arithmetic. 8) tom -- non, scarecrow, forensics, rituals, bacteria, scientific instruments, .. From Scott.Daniels at Acm.Org Tue Aug 9 17:33:43 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 09 Aug 2005 14:33:43 -0700 Subject: Does any one recognize this binary data storage format In-Reply-To: <11fi4piovsrgoe1@corp.supernews.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> Message-ID: <42f9187e$1@nntp0.pdx.net> Grant Edwards wrote: >>Ex #1) 333-3333 >>Hex On disk: 00 00 00 80 6a 6e 49 41 >> >>Ex #2) 666-6666 >>Hex On disk: 00 00 00 80 6a 6e 59 41 > > So there's only a 1-bit different between the on-disk > representation of 333-3333 and 666-6666. > > That sounds pretty unlikely. Are you 100% sure you're looking > at the correct bytes? Perhaps the one bit is an exponent -- some kind of floating point based format? That matches the doubling of all digits. --Scott David Daniels Scott.Daniels at Acm.Org From tpearce at internode.on.net Tue Aug 23 05:52:15 2005 From: tpearce at internode.on.net (m7b52000) Date: Tue, 23 Aug 2005 19:22:15 +0930 Subject: passing arguments from scale widget to function In-Reply-To: <4309ca38$1@duster.adelaide.on.net> References: <430828c4$1@duster.adelaide.on.net> <4309b3f2$1@duster.adelaide.on.net> <4309bd93$1@duster.adelaide.on.net> <4309ca38$1@duster.adelaide.on.net> Message-ID: <430af1d0$1@duster.adelaide.on.net> Problem solved. use 'command = Calc' to call my Calc function but ignore the argument passed to it. Create a list with the following elements - a.get(), b.get() and c.get(). Every time a scale slider is moved, Calc will retrieve the current scale values and I can do with them whatever I want... Now to work out how to write the answer to a text box or similar....... Thanks for your help, Matt Tony From rkern at ucsd.edu Thu Aug 25 16:23:02 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 13:23:02 -0700 Subject: variable hell In-Reply-To: <430e26c6$0$2092$626a14ce@news.free.fr> References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> Message-ID: rafi wrote: > In the meantime another question I cannot find an answer to: any idea > why does eval() consider '=' as a syntax error? > > >>> eval ('a=1') > Traceback (most recent call last): > File "", line 1, in ? > File "", line 1 > a=1 > ^ > SyntaxError: invalid syntax eval *evaluates* an expression. "a=1" is a statement. It has no value. -- 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 Sven at Tissot.de Thu Aug 4 18:09:12 2005 From: Sven at Tissot.de (Sven Tissot) Date: Fri, 05 Aug 2005 00:09:12 +0200 Subject: wxPython ListCtrl_edit and TextEditMixin on mac OS X 10.4 Message-ID: <3lfi08F11kn95U1@uni-berlin.de> Hello, I am trying to build an editable ListCtrl_edit via TextEditMixin. It displays o.k. and I can edit the first field with this is the code piece: class VokabelListCtrl(wxListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.TextEditMixin): def __init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize, style=0): wxListCtrl.__init__(self, parent, ID, pos, size, style) listmix.ListCtrlAutoWidthMixin.__init__(self) #listmix.TextEditMixin.__init__(self) uncommenting the TextEditMixin still renders the ListCtrl, but as soon as I click into the grid the application crashes with a IndexError: tuple index out of range Traceback (innermost last): File "/Users/einstein/python/wing/projects/vokabeln/wxVokabelApp.py", line 1, in ? #!/usr/bin/env python File "/Users/einstein/python/wing/projects/vokabeln/wxVokabelApp.py", line 26, in ? main() File "/Users/einstein/python/wing/projects/vokabeln/wxVokabelApp.py", line 23, in main application.MainLoop() File "/Library/Python/2.3/wx-2.6-mac-unicode/wx/_core.py", line 7493, in MainLoop wx.PyApp.MainLoop(self) File "/Library/Python/2.3/wx-2.6-mac-unicode/wx/_core.py", line 6926, in MainLoop return _core_.PyApp_MainLoop(*args, **kwargs) File "/Library/Python/2.3/wx-2.6-mac-unicode/wx/lib/mixins/listctrl.py", line 497, in OnLeftDown x,y = evt.GetPosition() File "/Library/Python/2.3/wx-2.6-mac-unicode/wx/_core.py", line 1117, in __getitem__ def __getitem__(self, index): return self.Get()[index] what is my mistake ??? Can anybody give me a hint ? P.S. I installed the curent wxPython release and applied the following * download and install http://pythonmac.org/packages/TigerPython23Compat.pkg.zip * used multiversion install via adding o import wxversion o wxversion.select("2.6") kind regards, Sven From fredrik at pythonware.com Fri Aug 26 07:59:09 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 26 Aug 2005 13:59:09 +0200 Subject: DOM text References: <1125050185.2182.241533364@webmail.messagingengine.com> Message-ID: Robert Kern wrote: > You might find that the more Pythonic XML modules are better suited to > handling mixed content. I've been using lxml and ElementTree quite > successfully. fwiw, here's an ET snippet that inserts an anchor element inside a paragraph element: # from lxml.etree import * # or # from cElementTree import * # or from elementtree.ElementTree import * p = XML("

a link and some bold text

") a = Element("a", href="link") text = p.text # "a link and some " p.text = text[:2] # "a " is left after

a link and some bold text

" (this works with ET, cET, lxml.etree, and any other ET-com- patible library, of course) From apardon at forel.vub.ac.be Fri Aug 19 09:47:19 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 19 Aug 2005 13:47:19 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-19, Donn Cave schreef : > Quoth "Greg McIntyre" : >| I have a Python snippet: >| >| f = open("blah.txt", "r") >| while True: >| c = f.read(1) >| if c == '': break # EOF >| # ... work on c >| >| Is some way to make this code more compact and simple? It's a bit >| spaghetti. > > Actually I'd make it a little less compact -- put the "break" > on its own line -- but in any case this is fine. It's a natural > and ordinary way to express this in Python. > > ... >| But I get a syntax error. >| >| while c = f.read(1): >| ^ >| SyntaxError: invalid syntax >| >| And read() doesn't work that way anyway because it returns '' on EOF >| and '' != False. If I try: > > This is the part I really wanted to respond to. Python managed > without a False for years (and of course without a True), and if > the introduction of this superfluous boolean type really has led > to much of this kind of confusion, then it was a bad idea for sure. IMO the confusion is the result of True and False appearing late. IMO having python interpret None, '', (), {} and [] as false in a conditional context goes against the spirit of: In the face of ambiguity, refuse the temptation to guess. > The condition that we're looking at here, and this is often the > way to look at conditional expressions in Python, is basically > something vs. nothing. In this and most IO reads, the return > value will be something, until at end of file it's nothing. > Any type of nothing -- '', {}, [], 0, None - will test "false", But '', {}, [] and () are not nothing. They are empty containers. And 0 is not nothing either it is a number. Suppose I have a variable that is either None if I'm not registered and a registration number if I am. In this case 0 should be treated as any other number. Such possibilities, make me shy away from just using 'nothing' as false and writing out my conditionals more explicitly. -- Antoon Pardon From dmqatpobox.com Mon Aug 29 14:00:22 2005 From: dmqatpobox.com (David MacQuigg) Date: Mon, 29 Aug 2005 11:00:22 -0700 Subject: Newbie question: Sub-interpreters for CAD program References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> <1125187206.961711.91120@o13g2000cwo.googlegroups.com> Message-ID: On 27 Aug 2005 17:00:07 -0700, "sonicSpammersGoToHellSmooth" wrote: >Cool, I went to the UofA for my MS in ECE, 2000. I did my theses under >Chuck Higgins. -- >http://neuromorph.ece.arizona.edu/pubs/ma_schwager_msthesis.pdf > >The tools we had were constantly underwhelming me, so I've been >thinking for years that a properly designed new toolset for students >should be marketable, etc. I'll take a look at your site (although I >think I may have come across it before.) A toolset for students is exactly what we need. Whether that turns into a marketable product is a question for later. At this point, we need a few people with a strong motivation to help students. Sounds like you might have what it takes. Send me an email if you are interested. -- Dave From mwh at python.net Mon Aug 1 08:57:53 2005 From: mwh at python.net (Michael Hudson) Date: Mon, 01 Aug 2005 12:57:53 GMT Subject: Changing interpreter's deafult output/error streams References: Message-ID: Robert Kern writes: > Michael Hudson wrote: >> "Ira" writes: >> >>>OK let me rephrase, >>> >>>the standard error stream (and if I'm not mistaken also the one that >>>PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go >>>ahead and write the following in python... >> Ah, OK, I think you're mistaken, and PyErr_Print prints to the C >> level >> FILE* stderr (I agree my first post was confusing on this point, sorry >> about that...). > > No, it doesn't. It grabs the appropriate object from sys.stderr. Ah, you're right, I somehow ended up reading PySys_WriteStderr... Cheers, mwh -- The only problem with Microsoft is they just have no taste. -- Steve Jobs, (From _Triumph of the Nerds_ PBS special) and quoted by Aahz on comp.lang.python From abkhd at earth.co.jp Sat Aug 20 00:11:54 2005 From: abkhd at earth.co.jp (A.B., Khalid) Date: 19 Aug 2005 21:11:54 -0700 Subject: ANN: Binary Distribution of pyMinGW-241 Message-ID: <1124511114.709010.306400@z14g2000cwz.googlegroups.com> This is to inform those interested in Python and MinGW that a binary distribution of pyMinGW-241 is now available. This is mainly a packaging of the March release in binary form for those who are finding it difficult to build Python or its standard extensions in MinGW. WHAT'S INSIDE ------------- - pyMinGW-License - pyMinGW-Readme - Python-License - python.exe - python24.dll - pythonw.exe - w9xpopen.exe - python_icon.exe + Dlls: - tcl84.dll - tclpip84.dll - tk84.dll - zlib.pyd - _bsddb.pyd - _socket.pyd (Without IPv6 support, as MinGW still lacks it) - _ssl.pyd - _testcapi.pyd - _tkinter.pyd - bz2.pyd - pyexpat.pyd - select.pyd - unicodedata.pyd - winsound.pyd + Include: pyconfig.h + Lib: + distutils + command - build_ext.py - ccompiler.py - cygwinccompiler.py - unixccompiler.py + Libs: - libpython24.a + tcl: + tcl84 + tk84 Get it from here: http://jove.prohosting.com/iwave/ipython/pyMinGW.html Regards Khalid From mediocre_person at hotmail.com Thu Aug 4 21:59:33 2005 From: mediocre_person at hotmail.com (Terrance N. Phillip) Date: Thu, 04 Aug 2005 20:59:33 -0500 Subject: Parallel arithmetic? In-Reply-To: <42f298d6$1_5@alt.athenanews.com> References: <42f298d6$1_5@alt.athenanews.com> Message-ID: <42f2c81a$1_3@alt.athenanews.com> Thank-you very much for all the excellent replies. I'm thinking of using this to determine if a sequence is a "run" (as in a card game). If I've got a sorted hand [3, 4, 5, 6, 7], then I know I've got a 5-card run because [4, 5, 6, 7] - [3, 4, 5, 6] == [1, 1, 1, 1]. I want to avoid something like if h[0] == h[1]-1 and h[1] == h[2]-1 ... Nick. From alessandro.bottoni at infinito.it Mon Aug 15 04:02:55 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Mon, 15 Aug 2005 08:02:55 GMT Subject: GUI tookit for science and education References: Message-ID: Mateusz ?oskot wrote: > I'd like to ask some scientists or students > which GUI toolkit they would recommend > to develop scientific prototypes (for education and > testing some theories). > I think such toolkit should fill a bit different > needs and requirements: > - very simple to learn > - easy to install > - beautyfiers and advanced features are not required like OpenGL, > direct access to Windows GDI subsystem, beauty look and skinning > - multiplatform required First, have a look at: - wxWidgets (http://www.wxwidgets.org) - wxPython (http://www.wxpython.org) Or, as a second choice: - FLTK (http://www.fltk.org/) - PyFLTK (http://pyfltk.sourceforge.net) There are many others GUI toolkit around. Just search Google for "multiplatform Python GUI toolkit" or something like that. > Let's say someone has big amount of algorithms and > statistical models implemented in Pascal > (not well designed console apps). > Now he want to move on using better and modern language > and GUI toolkit. > Python is seleceted as user friendly and simple > language, Pascal successor. There was a python to pascal automatic converter at: http://no.spam.ee/~andreie/software/py2pas/english-index.html (Now offline) CU ----------------------------------- Alessandro Bottoni From justin.vanwinkle at gmail.com Thu Aug 25 12:05:16 2005 From: justin.vanwinkle at gmail.com (justin.vanwinkle at gmail.com) Date: 25 Aug 2005 09:05:16 -0700 Subject: Filetypes in email attachments. Message-ID: <1124985916.435829.288930@g43g2000cwa.googlegroups.com> Hello everyone, I'm writing a simple spam filter as a project, partly to learn python. I want to filter by filetype, however, the mime content type I get using .get_content_type gives limited and possibly bogus information, especially when trying to detect viruses or spam. I would like to use the magic file to detect the filetype, if this is possible. I have the attachement stored and (generally) decoded in a variable. Justin From http Sat Aug 6 20:00:40 2005 From: http (Paul Rubin) Date: 06 Aug 2005 17:00:40 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <7xu0i21uqf.fsf@ruckus.brouhaha.com> "seberino at spawar.navy.mil" writes: > I've heard 2 people complain that word 'global' is confusing. > Perhaps 'modulescope' or 'module' would be better? > Am I the first peope to have thought of this and suggested it? > Is this a candidate for Python 3000 yet? It's not just the word that's confusing, Python's scoping system is just a mess. I hope that Python 3000 fixes it, but who knows. From cantabile.03 at wanadoo.fr Tue Aug 9 08:59:38 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Tue, 09 Aug 2005 14:59:38 +0200 Subject: gettext again In-Reply-To: References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> <42f77cb6$0$25055$8fcfb975@news.wanadoo.fr> Message-ID: <42f8a8b9$0$1207$8fcfb975@news.wanadoo.fr> Ok, I'll try that. Thanks again Stasz ! From rkern at ucsd.edu Wed Aug 3 23:25:46 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 03 Aug 2005 20:25:46 -0700 Subject: Mass importing of a template based system.. Trouble with name substitutions In-Reply-To: <1123123110.255400.145060@g44g2000cwa.googlegroups.com> References: <1123123110.255400.145060@g44g2000cwa.googlegroups.com> Message-ID: rh0dium wrote: > Hi all, > > Basically I have a bunch of pluggins in a directory (METDIR). For each > one of these templated pluggins I want to do a specific routine. Let's > start with a basic template > > file example1.py > ---------------- > class example1: > def __init__(self): > print "Initialize" > def run(self): > print "Hi from example 1" > ---------------- > > file example2.py > ---------------- > class example2: > def __init__(self): > print "Initalize" > def run(self): > print "example 2" > ---------------- > > Now I want to go through each pluggin ( example1.py and example2.py ) > and execute run. So here is my code but it doesn't work.. > > > if os.path.isdir(METDIR): > modules = [] > > # Add the metrics dir toyour path.. > sys.path.insert( 0, os.getcwd() + "/" + METDIR ) > > for metric in glob.glob(METDIR+"/*.py"): > # Now lets start working on the individual metrics > module_name, ext = os.path.splitext(os.path.basename(metric)) > try: > module = __import__(module_name) > modules.append( module ) > except ImportError , e: > print "Failed import of %s - %s" % ( module_name, e) > pass > > for mod in modules: > a = mod.mod() > a.run() > > But it doesn't work with the following.. > > Traceback (most recent call last): > File "./metriX.py", line 109, in main > a = mod.mod() > AttributeError: 'module' object has no attribute 'mod' > > So it looks like it's not doing the substitution. Doing what substitution? Neither of the modules that you showed define a mod() callable and nothing else seems to add one. -- 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 fakeaddress at nowhere.org Fri Aug 12 14:57:11 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 18:57:11 GMT Subject: Catching stderr output from graphical apps In-Reply-To: <1123856626.852626.236030@g43g2000cwa.googlegroups.com> References: <1123697339.925135.161200@g47g2000cwa.googlegroups.com> <1123856626.852626.236030@g43g2000cwa.googlegroups.com> Message-ID: Thanks. Yeah, guess I was naive to test on Windows and expect that kind of process stuff to be portable. I'll be away from Linux for a week or so, so this will take me a while. Further bulletins as events warrant. -- --Bryan From ksenia.marasanova at gmail.com Wed Aug 10 08:39:40 2005 From: ksenia.marasanova at gmail.com (Ksenia Marasanova) Date: Wed, 10 Aug 2005 14:39:40 +0200 Subject: sorting question In-Reply-To: <130df193050810053317054b26@mail.gmail.com> References: <130df193050810053317054b26@mail.gmail.com> Message-ID: <130df1930508100539792298e8@mail.gmail.com> > return [(node.id, node.ord_number) for node in self.get_path()] I meant: > return [(node.ord_number, node.id) for node in self.get_path()] -- Ksenia From fredrik at pythonware.com Wed Aug 31 10:16:45 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 16:16:45 +0200 Subject: Problem with string -> int conversion ? References: <4314dbd0$0$18648$14726298@news.sunsite.dk> <4315b8cc$0$18647$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: >> if the callback code is Python, you should be able to add a print >> statement to the line just before the failing "int" call: >> >> print repr(signalrangestr), type(signalrangestr) >> signalrange = int(signalrangestr) >> >> that print statement should be all you need to figure out what >> signalrangestr really is. > > Thanks for the hint. > > I get : > > <__main__.qt.QString object at 0xb7c1a3ec> > > The question is : > > How do I convert a QString to a plain string ? googling for "pyqt qstring" brought up this page: http://www.opendocspublishing.com/pyqt/x2068.htm From gsakkis at rutgers.edu Mon Aug 1 10:43:22 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 1 Aug 2005 07:43:22 -0700 Subject: Getting not derived members of a class References: Message-ID: <1122907402.650512.213470@g47g2000cwa.googlegroups.com> Franz Steinhaeusler wrote: > Hello NG, > > I want to retrieve the members of a class > with a baseclass. > But the problem is, how to get the non derived > members. > > class a: > def who(self): > print "who" > def __init__(self): > self._a = 3 > > class b(a): > def who1(self): > print "who1" > def __init__(self): > a.__init__(self) > self._b = 4 > > y=b() > > dir (y) > ['__doc__', '__init__', '__module__', '_a', '_b', 'who', 'who1'] > > > I need a function which lists only the members of > the "not derived" class (here class B). > > _b > _who1 > __init__ > > How can I achieve this? > With the introspect module or so? I believe you can't: Both _a and _b end up in y.__dict__ and there's no way to differentiate between the two depending on the time of their creation. By the way, these are instance attributes, not class attributes, so strictly _b is not a member of B, it's just an instance of y. To see why this is the case, check the following valid (though highly discouraged) example: class X: def __init__(self, x): if isinstance(x,str): self._s = x else: self._n = x x1 = X("1") x2 = X(1) dir(x1) ['__doc__', '__init__', '__module__', '_s'] dir(x2) ['__doc__', '__init__', '__module__', '_n'] George From aaron.ginn at gmail.com Mon Aug 29 19:58:55 2005 From: aaron.ginn at gmail.com (Angelic Devil) Date: 29 Aug 2005 16:58:55 -0700 Subject: File parser Message-ID: I'm building a file parser but I have a problem I'm not sure how to solve. The files this will parse have the potential to be huge (multiple GBs). There are distinct sections of the file that I want to read into separate dictionaries to perform different operations on. Each section has specific begin and end statements like the following: KEYWORD . . . END KEYWORD The very first thing I do is read the entire file contents into a string. I then store the contents in a list, splitting on line ends as follows: file_lines = file_contents.split('\n') Next, I build smaller lists from the different sections using the begin and end keywords: begin_index = file_lines.index(begin_keyword) end_index = file_lines.index(end_keyword) small_list = [ file_lines[begin_index + 1] : file_lines[end_index - 1] ] I then plan on parsing each list to build the different dictionaries. The problem is that one begin statement is a substring of another begin statement as in the following example: BAR END BAR FOOBAR END FOOBAR I can't just look for the line in the list that contains BAR because FOOBAR might come first in the list. My list would then look like [foobar_1, foobar_2, ..., foobar_n, ..., bar_1, bar_2, ..., bar_m] I don't really want to use regular expressions, but I don't see a way to get around this without doing so. Does anyone have any suggestions on how to accomplish this? If regexps are the way to go, is there an efficient way to parse the contents of a potentially large list using regular expressions? Any help is appreciated! Thanks, Aaron -- "Tis better to be silent and be thought a fool, than to speak and remove all doubt." -- Abraham Lincoln From roy at panix.com Tue Aug 9 23:19:26 2005 From: roy at panix.com (Roy Smith) Date: Tue, 09 Aug 2005 23:19:26 -0400 Subject: Bizarre error from help() References: Message-ID: In article , "Delaney, Timothy (Tim)" wrote: > Roy Smith wrote: > > > Traceback (most recent call last): > > File "", line 1, in ? > > File "/usr/local/lib/python2.3/site.py", line 307, in call > > import pydoc > > File "/usr/local/lib/python2.3/pydoc.py", line 49, in ? > > from string import expandtabs, find, join, lower, split, strip, > > rfind, rstrip > > ImportError: cannot import name expandtabs > > Looks most likely that there something messed up with your python > install. What happens if you do: > > >>> from string import expandtabs > > ? Do you get a similar error? No, that works fine. But, now I can't even reproduce the error I reported earlier (when I try, I get the help message as expected). And, yes, that was with a brand new interpreter session. Strange. From peter at somewhere.com Thu Aug 4 05:05:32 2005 From: peter at somewhere.com (Peter Maas) Date: Thu, 04 Aug 2005 11:05:32 +0200 Subject: API class creation In-Reply-To: References: Message-ID: kman3048 schrieb: > Now, I need to create a Class and fill it with Methods and Variables. > There are means to create (and attache) methods and variables. > However, I have not found how to create a Class within a Module. Or do import aModule c = aClassGenerator() setattr(aModule,'c',c) ci = aModule.c() -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From eric_brunel at despammed.com Wed Aug 24 11:42:23 2005 From: eric_brunel at despammed.com (Eric Brunel) Date: Wed, 24 Aug 2005 17:42:23 +0200 Subject: a question about tkinter StringVars() References: Message-ID: On Wed, 24 Aug 2005 15:07:27 GMT, William Gill wrote: > Working with tkinter, I have a createWidgets() method in a class. > Within createWidgets() I create several StringVars() and > assign them to the textvariable option of several widgets. > Effectively my code structure is: > > def createWidgets(self): > ... > var = StringVar() > Entry(master,textvariable=var) > ... > ... > > Though 'var' would normally go out of scope when createWidgets > completes, since the Entry and its reference do not go out of scope, > only the name 'var' goes out of scope, not the StringVar object, Right? Well, apparently not: ------------------------------------------------ from Tkinter import * class MyStringVar(StringVar): def __del__(self): print "I'm dying!" root = Tk() def cw(): var = MyStringVar() Entry(root, textvariable=var).pack() cw() root.mainloop() ------------------------------------------------ Running this script actually prints "I'm dying!", so there is obviously no reference from the Entry widget to the variable object. The reference is actually kept at tcl level between an entry and the *tcl* variable, which knows nothing about the *Python* variable. BTW, the whole purpose of StringVar's is to be kept so that the text for the entry can be retrieved or modified by another part of the program. So what can be the purpose of creating variables in a function or method and not keeping them anywhere else than a local variable? -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" From bokr at oz.net Mon Aug 29 18:53:24 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 29 Aug 2005 22:53:24 GMT Subject: trictionary? References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> <1125280480.602131.269670@g49g2000cwa.googlegroups.com> Message-ID: <43138b58.98701114@news.oz.net> On 28 Aug 2005 18:54:40 -0700, "mensanator at aol.com" wrote: >Steven Bethard wrote: >> Adam Tomjack wrote: >> > Steven Bethard wrote: >> > ... >> >> Using a two element list to store a pair of counts has a bad code >> >> smell to me. >> > ... >> > >> > Why is that? >> >> Note that "code smell"[1] doesn't mean that something is actually wrong, >> just that it might be. In Python, pairs are usually handled with >> tuples[2], but tuples would be inconvenient in this case, since the >> first value must be modified. Declaring a class with two attributes as >> you suggested is often a good substitute, but if the OP's code is really >> what it looks like, I get another code smell because declaring a class >> to be used by only 10 lines of code seems like overkill. >> >> I also get a code smell from a dict holding two-element lists because >> I've been writing in Python and answering questions on the Python-list >> for a couple of years now, and I've never needed one yet. ;-) >> >> STeVe >> >> [1]http://en.wikipedia.org/wiki/Code_smell >> [2]http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types > >Could you do me a favor and see what this smells like? > >I put some data in a csv file (with headers) and this will >bring it in quite simply as a dictionary with [names] as >keys and an attribute dictionary as the value. > >py_monsters.csv: > >name,hardiness,agility,friend,courage,room,weight,special_def_odds,armor,weapon,odds,dice,side,hits,reaction,desc >PIRATE,5,20,0,10,26,300,0,0,11,60,1,10,0,"not met",You see a man with a >beard and a brass ring in his ear. He is wearing clothes made of silk >and is wielding a very fancily engraved sword. > > >import csv >temp1 = [] >temp2 = [] >reader = csv.reader(file(r"py_monsters.csv")) >for rec in reader: > temp1.append(rec) >for i in temp1[1:]: > temp2.append((i[0],dict(zip(temp1[0][1:],i[1:])))) >monsters = dict(temp2) > >This gives me what I want > >[('PIRATE', {'reaction': 'not met', >'agility': '20', >'room': '26', >'weight': '300', >'armor': '0', >'weapon': '11', >'hits': '0', >'side': '10', >'special_def_odds': '0', >'courage': '10', >'hardiness': '5', >'desc': 'You see a man with a beard and a brass ring in his ear. >He is wearing clothes made of silk and is wielding a very fancily >engraved sword.', >'odds': '60', >'friend': '0', >'dice': '1'})] > >so that I can now write code like > >if monsters['PIRATE']['reaction']=='not met': > print monsters['PIRATE']['desc'] I think if the field names are legal python names, I would rather write that 'if ...' without all that line noise ;-) E.g., using simple classes (and effectively using their attribute instance dicts essentially the way you used raw dicts), you could write if monsters.PIRATE.reaction == 'not met': print monsters.PIRATE.desc Also, if the reaction, agility, etc list is fixed, you could use __slots__ for better efficiency. Also, your __init__ method for the latter could convert strings to ints for handier use later (unless csv already does that in the mode you are using). >From the above code I infer that you can do define the requisite classes, so I'll leave it to you ;-) Note that attribute access opens the door to having default values as class variables, and using properties to retrieve dynamically calculated values by name. If you are not familiar with those aspects of classes, your progammer.agility value can increase markedly with a little study ;-) E.g., a name like monsters.random_elf could live right alongside PIRATE and return one a randomly selected elf from a an internal list of elves or via random selection from a list of elf names defined at the same level as PIRATE, etc. etc. You could also dynamically configure these guys according to distance to food and time since last meal, and if you are carrying food, etc. With suitable classes you could put instances in various "spaces" defined by other classes, that define geometric or social or other interactions. > >instead of using stupid index numbers. > >But the loader seems to have a kind of perl-like odor to it, >i.e., next week I won't understand what it does. > If you have to do something tricky, choose names wisely and comment the non-obvious ;-) Regards, Bengt Richter From dan at cellectivity.com Wed Aug 10 06:18:38 2005 From: dan at cellectivity.com (Dan) Date: Wed, 10 Aug 2005 11:18:38 +0100 Subject: searching a list of dictionaries for an element in a list. In-Reply-To: References: Message-ID: <1123669118.30409.21.camel@localhost.localdomain> > I want to search list1, and the result should be all dictionaries where > primarycolor is in input. I can do this using a double for-loop, but is > there a more efficent way? Of course. :-) L = [dict for dict in list1 if dict['primarycolor'] in input] In older versions of Python, we would use the "filter" function, which accomplishes the same thing. -- [Mozilla] Firefox is better than Explorer by leaps and bounds. I don't miss Explorer one iota. Give Firefox a day's worth of Web surfing, and you won't either. - Forbes (short link: http://tinyurl.com/56j8m ) From devlai at gmail.com Thu Aug 11 23:37:59 2005 From: devlai at gmail.com (Devan L) Date: 11 Aug 2005 20:37:59 -0700 Subject: NEWB: General purpose list iteration? In-Reply-To: <42fc13f4_4@news1.prserv.net> References: <42fc13f4_4@news1.prserv.net> Message-ID: <1123817879.772095.6240@g44g2000cwa.googlegroups.com> def descend(iterable): if hasattr(iterable, '__iter__'): for element in iterable: descend(element) else: do_something(iterable) This will just do_something(object) to anything that is not an iterable. Only use it if all of your nested structures are of the same depth. If you used it on the following list of lists [[something],[[something_else],[other_thing]]] it would modify something, something_else, and other_thing. From nephish at xit.net Wed Aug 17 22:43:52 2005 From: nephish at xit.net (nephish at xit.net) Date: 17 Aug 2005 19:43:52 -0700 Subject: question about binary and serial info Message-ID: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> i have an interesting project at work going on. here is the challenge. i am using the serial module to read data from a serial input. it comes in as a hex. i need to make it a binary and compare it bit by bit to another byte. They have some weird way they set this up that i have to compare these things with AND. in other words, if bit 1 is 1 AND bit 1 is 1 then the real value is 1... long story short. is there a good way to compare bytes, bit by bit with one of the modules of python. i want to know so i dont get halfway into developing this and find that there is a much better way to do this than by hand. thanks for any suggestions. sk <>< From mauriceling at acm.org Wed Aug 31 20:57:24 2005 From: mauriceling at acm.org (Maurice LING) Date: Thu, 01 Sep 2005 10:57:24 +1000 Subject: Calling ftp commands from python References: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> Message-ID: Thierry Lam wrote: > Is it possible to run an ftp command to connect to some remote computer > on the network. > > For example, if I want to retrieve some data from > \\remcomputer\datafiles on the network and copy it to my local > computer, how do I do it in python on the Unix side? > > I don't want to use mount since I don't have permission. > > Thanks > Thierry > I use ftplib in the standard libraries. from ftplib import FTP def grab_geneontology(): """Function to download gene ontology file.""" ftp = FTP('ftp.geneontology.org') ftp.login() ftp.cwd('/pub/go/ontology') ftp.retrbinary('retr gene_ontology.obo', open('gdata/gene_ontology', 'wb').write) ftp.quit() if __name__ == '__main__': grab_geneontology() maurice From steve at holdenweb.com Wed Aug 17 06:08:11 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Aug 2005 11:08:11 +0100 Subject: List copying idiom was Re: [Python-Dev] implementation of copy standard lib In-Reply-To: References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: Tom Anderson wrote: > On Tue, 16 Aug 2005, Ron Adam wrote: > > >>Simon Brunning wrote: >> >> >>>On 8/14/05, Martijn Brouwer wrote: >>> >>> >>>>I can imagine that *a lot* of libs/scripts use the copy library, >>> >>>I think that copy is very rarely used. I don't think I've ever imported it. >> >>I use copy.deepcopy() sometimes, and more often [:] with lists. >>Dictionary objects have a copy method. All non mutable objects are >>copies. > > > When you say [:], do you mean that you copy lists like this: > > l = someList() > m = [] > m[:] = l > > ? > > That's what i've been doing. The other day, i realised that i could just > do: > > l = someList() > m = list(l) > > The same works for copying dicts. Whilst it's still not utterly obvious > that what this is about is making a copy, it's more obvious, cleaner, > shorter and probably faster than the slice assignment, which is really > kludgy (almost intercalorific, in fact - or even perlish!). > Not really: it used to be the preferred mechanism, but now it seems a little old-fashioned is all. > >>I too have wondered why copy isn't a builtin, > > > Same here. It seems like a sort of obvious thing to have, and could > probably implemented much more simply and quickly in the interpreter. > You'd probably want a __copy__ hook for classes which want special > handling, and just do a normal deep copy for everything else. > Well yes, but given that module copy now exists (and will therefore have to continue ti exist until Py3) that would introduce some redundancy. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From devlai at gmail.com Thu Aug 11 18:58:21 2005 From: devlai at gmail.com (Devan L) Date: 11 Aug 2005 15:58:21 -0700 Subject: Regular expression to match a # In-Reply-To: <42fbd1a1$1@news.eftel.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> <42fbb9a9$1@news.eftel.com> <1123799252.257355.158320@f14g2000cwb.googlegroups.com> <42fbd1a1$1@news.eftel.com> Message-ID: <1123801101.340465.282320@g43g2000cwa.googlegroups.com> John Machin wrote: > Devan L wrote: > > John Machin wrote: > > > >>Aahz wrote: > >> > >>>In article <42fb45d7$1 at news.eftel.com>, > >>>John Machin wrote: > >>> > >>> > >>>>Search for r'^something' can never be better/faster than match for > >>>>r'something', and with a dopey implementation of search [which Python's > >>>>re is NOT] it could be much worse. So please don't tell newbies to > >>>>search for r'^something'. > >>> > >>> > >>>You're somehow getting mixed up in thinking that "^" is some kind of > >>>"not" operator -- it's the start of line anchor in this context. > >> > >>I can't imagine where you got that idea from. > >> > >>If I change "[which Python's re is NOT]" to "[Python's re's search() is > >>not dopey]", does that help you? > >> > >>The point was made in a context where the OP appeared to be reading a > >>line at a time and parsing it, and re.compile(r'something').match() > >>would do the job; re.compile(r'^something').search() will do the job too > >>-- BECAUSE ^ means start of line anchor -- but somewhat redundantly, and > >>very inefficiently in the failing case with dopey implementations of > >>search() (which apply match() at offsets 0, 1, 2, .....). > > > > > > I don't see much difference. > > and I didn't expect that you would -- like I wrote above: "Python's re's > search() is not dopey". Your wording makes it hard to distinguish what exactly is "dopey". From deets at nospam.web.de Tue Aug 23 17:26:51 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Aug 2005 23:26:51 +0200 Subject: where does __class__ come from? In-Reply-To: <1124823213.701488.57580@z14g2000cwz.googlegroups.com> References: <1124823213.701488.57580@z14g2000cwz.googlegroups.com> Message-ID: <3n1ikrF198ap3U1@uni-berlin.de> > Where does __class__ come from, what does it mean and what else is > being hidden? > > I am used to using dir(...) to figure out what I can play with. > Clearly that does not always work... :-( Your question has benn answered - let me just add this from the dir()-docs: Note: Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. from http://docs.python.org/lib/built-in-funcs.html Regards, Diez From fuzzyman at gmail.com Mon Aug 8 03:29:15 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 8 Aug 2005 00:29:15 -0700 Subject: Python HTTP digest authentication woes... In-Reply-To: <2005071702335516807%n00spamdeveloper@yahoocom> References: <2005071702335516807%n00spamdeveloper@yahoocom> Message-ID: <1123486154.970275.237300@z14g2000cwz.googlegroups.com> john wrote: > I'm trying to access the XML version of my Tivo now playing list with > python. It uses auth digest HTTP authentication. I could really use > some help! > > I'm able to get this page using curl: > curl --dump-header tivoHeaders --insecure --anyauth --user tivo:8000008 > "https://192.168.1.102/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes" > > But > > when I use my python script, I get rejected: > https://192.168.1.102/TiVoConnect?Container=%2FNowPlaying&Command=QueryContainer&Recurse=Yes > Error > > 401 > Server: tivo-httpd-1:7.1b-01-2:140 > Set-Cookie: sid=DEC2D78EABF48A6D; path=/; expires="Saturday, > 16-Feb-2013 00:00:00 GMT"; > WWW-Authenticate: Digest realm="TiVo DVR", nonce="FD08EF226909CA85", qop="auth" > Content-Length: 31 > Content-Type: text/html > Connection: close > > Digest realm="TiVo DVR", nonce="FD08EF226909CA85", qop="auth" > > I've scrounged for examples out there and the couple that I've found > just don't seem to work for me.. > > Here's one way I've tried: > ===================================== > import urllib2 > > theurl = > "192.168.1.102/TiVoConnect?Container=%2FNowPlaying&Command=QueryContainer&Recurse=Yes" > print > Oh yeah - I didn't spot this before.... theurl = "192.168.1.102/TiVoConnect?Con?tainer=%2FNowPlaying&Command=Q?ueryContainer&Recurse=Yes" this includes the parameters - which it shouldn't. :-) Fuzzy http://www.voidspace.org.uk/python From krzychu at bmpg.pl Tue Aug 16 09:09:33 2005 From: krzychu at bmpg.pl (krzychu at bmpg.pl) Date: 16 Aug 2005 06:09:33 -0700 Subject: Zope, Python 2.4 pythonScripts import problem In-Reply-To: References: <1123854279.041291.39000@g44g2000cwa.googlegroups.com> Message-ID: <1124197773.365465.249690@g14g2000cwa.googlegroups.com> I see that Python 2.4.x does not work with Zope-2-7-6 properly. When I start zope I get warning that I should recompile my pythonScripts by executing manage_addProduct/PythonScripts/recompile. I do it and get list of scripts whoose were compiled but when I repeat that action I get the same list of scripts. It doesn't compile them -> when I visit script by ZMI I still get the following error message "invalid syntax (Script (Python), line 1)". The first script at page http://www.zope.org/Members/goppelt/2-4-3Upgrade gives no effect -> outcome is "invalid syntax (Script (Python), line 1)" error i scripts. I'm affraid that I will have to resign with Python 2.4.x :( I read that Python 2.4 was complaisant back but I don't think that Zope-2-7-6 is??? Regards KK Josef Meile napisal(a): > Hi, > > > I have installed brand new platform - Zope-2-7-6, Python 2.4.1, Plone > > 2.0.5, OS Debian 1:3.3.6-2. > > You may then ask in a zope or plone list. This is a python specific > list. But I will answer you any way. > > > After import a old Plone site from the following platform > > Zope-2-7-4, Python 2.3.3, Plone 2.0.3 to the new one, I get error when > > I visit PuthonScript in the ZMI. > > "invalid syntax (Script (Python), line 1)" > > > > There 2 are examples of 1 line: > > from DateTime import DateTime > > and > > request = container.REQUEST > > > > There is no syntax error! > > > > When I just save this script in ZMI then error disappers :) > > So, you are exporting the plone site, then importing it? I had once some > problem like that and the solution was to call an script that compiled > all python scripts again. I'm not sure if this solves your problem, but > you may look at the first script here: > > http://www.zope.org/Members/goppelt/2-4-3Upgrade > > > What is the reason??? > > As I said, you may ask in a zope or plone list for a better answer. My > best guess is that somewhere there is some old compiled version of your > script. > > > p.s I have the same problem when I import to the same platform but with > > Python 2.4.0 > > I just have to warn you that some persons in the zope list are going to > tell you "Python 2.4 isn't a supported option for zope". So, you may use > it only for testing and not in a production environment. > > Regards, > Josef From rkern at ucsd.edu Thu Aug 4 04:19:13 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 04 Aug 2005 01:19:13 -0700 Subject: Does pyparsing support UNICODE strings? In-Reply-To: <311b5ce10508040013750360e6@mail.gmail.com> References: <311b5ce10508040013750360e6@mail.gmail.com> Message-ID: could ildg wrote: > pyparsing is very convenient to use. But I want to find some a py tool > to parse non-English strings. Does pyparsing support UNICODE strings? > If not, can someone tell me what py tool can do it? Thanks in advance. Try it! # vim:fileencoding=utf-8 from pyparsing import Word text = "????????, ?????!".decode('utf-8') alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce)) greet = Word(alphas) + u',' + Word(alphas) + u'!' greeting = greet.parseString(text) print greeting -- 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 sybrenUSE at YOURthirdtower.com.imagination Wed Aug 24 03:12:00 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 24 Aug 2005 09:12:00 +0200 Subject: list insertion References: Message-ID: Randy Bush enlightened us with: > hold = self.next > self.next = DaClass(value) > self.next.next = hold shouldn't that last line be this? self.next.prev = hold > but i suspect (from print statement insertions) that the result is > not as i expect. What did you expect, and what did you ovserve? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From steven.bethard at gmail.com Sun Aug 28 19:53:28 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 28 Aug 2005 17:53:28 -0600 Subject: trictionary? In-Reply-To: References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> Message-ID: Adam Tomjack wrote: > Steven Bethard wrote: > ... >> Using a two element list to store a pair of counts has a bad code >> smell to me. > ... > > Why is that? Note that "code smell"[1] doesn't mean that something is actually wrong, just that it might be. In Python, pairs are usually handled with tuples[2], but tuples would be inconvenient in this case, since the first value must be modified. Declaring a class with two attributes as you suggested is often a good substitute, but if the OP's code is really what it looks like, I get another code smell because declaring a class to be used by only 10 lines of code seems like overkill. I also get a code smell from a dict holding two-element lists because I've been writing in Python and answering questions on the Python-list for a couple of years now, and I've never needed one yet. ;-) STeVe [1]http://en.wikipedia.org/wiki/Code_smell [2]http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types From john at castleamber.com Mon Aug 29 14:21:12 2005 From: john at castleamber.com (John Bokma) Date: 29 Aug 2005 18:21:12 GMT Subject: Jargons of Info Tech industry References: <3n6kkjF4qppU1@individual.net> <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> Message-ID: Alan Balmer wrote: > Why on earth was this cross-posted to comp.lang.c.? Followups set. Your reply is even more meaningless and more noise compared to the crosspost. Why? You didn't add anything, you quote an entire message and you just tweaked the follow up to header in a bad way. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From bearophileHUGS at lycos.com Sun Aug 28 16:46:04 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 28 Aug 2005 13:46:04 -0700 Subject: Bug in string.find In-Reply-To: <%_oQe.72$WJ3.55@newssvr21.news.prodigy.com> References: <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> <7xirxri3x5.fsf@ruckus.brouhaha.com> <%_oQe.72$WJ3.55@newssvr21.news.prodigy.com> Message-ID: <1125261964.371208.303040@g47g2000cwa.googlegroups.com> I agree with Bryan Olson. I think it's a kind of bug, and it has to be fixed, like few other things. But I understand that this change can give little problems to the already written code... Bye, bearophile From mhellwig at xs4all.nl Fri Aug 12 07:36:36 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Fri, 12 Aug 2005 13:36:36 +0200 Subject: What is Python?! In-Reply-To: References: <42fa51db$0$7802$626a14ce@news.free.fr> <42faccb9$1@news.orcon.net.nz> Message-ID: <42fc8a1e$0$11080$e4fe514c@news.xs4all.nl> Magnus Lycka wrote: > or what have you. How do you sell this without making it sound > like snake oil? (Particularly with that name! :) This *is* the languange you are looking for ... Stops the argument every time, although afterwards they look kind a funny at me. -- mph From onurb at xiludom.gro Fri Aug 12 04:51:37 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 12 Aug 2005 10:51:37 +0200 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <42fc631b$0$7464$636a15ce@news.free.fr> Ray wrote: > Hello, > > I've been learning Python in my sparetime. I'm a Java/C++ programmer by > trade. So I've been reading about Python OO, and I have a few questions > that I haven't found the answers for :) > > 1. Where are the access specifiers? (public, protected, private) object.name => public object._name => protected object.__name => private > 2. How does Python know whether a class is new style or old style? > E.g.: > > class A: > pass This is an old-style class. > How does it know whether the class is new style or old style? Or this > decision only happens when I've added something that belongs to new > style? How do I tell Python which one I want to use? class B(object): # or any subclass of object pass > 3. In Java we have static (class) method and instance members. But this > difference seems to blur in Python. I mean, when you bind a member > variable in Python, is it static, or instance? Depends if you bind it to the class or to the instance !-) > It seems that everything > is static (in the Java sense) in Python. Am I correct? No. class Foo(object): bar = 42 # this is a class variable # __init__ is the equivalent of Java constructors def __init__(self, baaz): self.baaz = baaz # this is an instance variable # this is a class method # (the first argument is the class object, not the instance) @classmethod def bak(cls, frooz): cls.bar = min(cls.bar, frooz) + 1138 # default is instance method def zoor(self): print "%s %d" % (self.baaz, Foo.bar) > Thanks in advance, HTH -- bruno desthuilliers ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@')" python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From florent.newsgroups at kynesthesy.org Tue Aug 2 15:30:43 2005 From: florent.newsgroups at kynesthesy.org (florent) Date: Tue, 02 Aug 2005 21:30:43 +0200 Subject: trying to parse non valid html documents with HTMLParser Message-ID: <42efc9ae$0$12924$636a15ce@news.free.fr> I'm trying to parse html documents from the web, using the HTMLParser class of the HTMLParser module (python 2.3), but some web documents are not fully valids. When the parser finds an invalid tag, he raises an exception. Then it seems impossible to resume the parsing just after where the exception was raised. I'd like to continue parsing an html document even if an invalid tag was found. Is it possible to do this ? Here is a little non valid html document. ---------- bogus link ---------- From john at castleamber.com Wed Aug 31 04:27:46 2005 From: john at castleamber.com (John Bokma) Date: 31 Aug 2005 08:27:46 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: Chris Head wrote: > John Bokma wrote: >> And workplaces. Some people have more then one computer in the house. >> My partner can check her email when I had her over the computer. When >> I want to check my email when she is using it, I have to change the >> session, fire up Thunderbird (which eats away 20M), and change the >> session back. >> >> [ .. ] > > Hmm. That would just be a matter of preference. Personally I moved my > Thunderbird profile into a shared directory and pointed everyone at > it. Now only one login session can run Thunderbird at a time, but any > login can see everyone's mailboxes. She uses hotmail, yahoo!, etc. and I don't want her accidently delete my email. >> Most people who use Thunderbird, yes. Different with OE, I am sure. >> With a thin client *everybody*. > > True. As a programmer I don't usually think about the people who never > download updates. The way I look at it, if somebody doesn't have the > latest version, they shouldn't be complaining about a bug. A lot of non-programmers have no idea that there are bugs in their software other then the crashing ones. >> Maybe because a lot of users aren't really heavy users. A nice >> example (IMO) of a web client that works quite good: webmessenger ( >> http://webmessenger.msn.com/ ). It has been some time since I used it >> the last time, but if I recall correctly I hardly noticed that I was >> chatting in a JavaScript pop up window. > > Haven't ever needed to use that program. Some of my customers use it. It has its uses, especially the block option :-D. (I don't believe that being available 24/7 has a positive effect on my work). >> I rather have my email stored locally :-) But several webmail >> services offer a form to download email. s/form/way/ > I've not seen a service that allows that. Sounds nice. IIRC gmail does it. [ reducing traffic ] > Eventually you reach the point where it's not bandwidth any more, it's > server load. All these things like mod_gzip, deltas, and so on add > server load. True. On the other hand, servers get more and more powerful. > As to the point about "page not modified", it's not in the HTML spec, Hence I wrote: >> RSS (I have the impression that there is no "page has not been >> modified" thing like with HTML, > content. For best results (due to clock mismatches etc), the client > should set the If-Modified-Since header to the value of the > Last-Modified header sent by the server when the page was first > requested and cached. But feed readers, at least the one I have had a look at, seem not to support this... > I think we can agree that in some cases, Webmail is better, and in > others, clients are better. Much of this will be personal preference, > and I would like to see ISPs offering both methods of accessing e-mail > (as mine in fact does - POP3 and Webmail). Agreed. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From roccomoretti at hotpop.com Tue Aug 9 14:30:59 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Tue, 09 Aug 2005 13:30:59 -0500 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > On Tue, 09 Aug 2005 10:39:29 -0500, Rocco Moretti > declaimed the following in comp.lang.python: > > >>Change it to "the object referenced by y is assigned to the name of x", >>and you're closer to the truth. > > In a more simplistic view, I'd reverse the phrasing... The name > "x" is assigned to the object "y" (implying it is no longer attached to > whatever used to have the name) I guess I was too subtle - my point was lost. The key thing is not to think of "the object 'y'" but to think of "the object referenced by (named) 'y'" There is a distinction between the object (object) and the name (variable), which is essential to eliminating the OP's conundrum. From fredrik at pythonware.com Wed Aug 31 07:57:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 13:57:34 +0200 Subject: change date format References: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> <200508311236.49648.lars@gustaebel.de> Message-ID: Lars Gust?bel wrote: > Not a single occurrence of the f**k word. You're making progress. perhaps, but why is he posting apache questions to the python list? From matt.hammond at rd.bbc.co.uk Fri Aug 12 08:22:52 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Fri, 12 Aug 2005 13:22:52 +0100 Subject: Why is this? References: <42fc8eb4$0$38045$bed64819@news.gradwell.net> Message-ID: On Fri, 12 Aug 2005 12:57:38 +0100, Peter Mott wrote: > If I use concatenation + instead of multiplication * then I get the > result that Jiri expected: > > >>> L = [[]] + [[]] > >>> L[1].append(1) > >>> L > [[], [1]] > > With * both elements are changed: > > >>> L = [[]] * 2 > >>> L[1].append(1) > >>> L > [[1], [1]] > > Alex Martelli says in his excellent Nutshell book that + is > concatenation and that "n*S is the concatenation of n copies of S". But > it seems not so. Surely, from a logical point of view, S + S should be > the same as S * 2? S+S is the same as S*2, but L= [[]] + [[]] is not S+S. The two terms being added are different instances of an empty list. You are adding/concatenating two different object instances. Suppose I do concatenate two of the same object instance, then I get the same behaviour as with the multiply example: >>> T = [[]] >>> L = T + T >>> L[1].append(1) >>> L [[1], [1]] In fact, you could argue this is exactly what the multiply operation is doing. (internally the implementation may be slightly different, but it is still equivalent to this) regards Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From nomail at nomail.com Sun Aug 21 06:45:13 2005 From: nomail at nomail.com (Viper Jack) Date: Sun, 21 Aug 2005 10:45:13 GMT Subject: [newbie]search string in tuples In-Reply-To: <43075bec$1@nntp0.pdx.net> References: <43075bec$1@nntp0.pdx.net> Message-ID: Thanks to all for the help. From bokr at oz.net Fri Aug 26 20:39:35 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 27 Aug 2005 00:39:35 GMT Subject: Converting from Microsoft Binary Format floats to Python Float References: <1125068126.386967.194750@o13g2000cwo.googlegroups.com> Message-ID: <430faf6d.2509167041@news.oz.net> On 26 Aug 2005 07:55:26 -0700, geskerrett at hotmail.com wrote: >In the '80's, Microsoft had a proprietary binary structure to handle >floating point numbers, In a previous thread, Bengt Richter posted >some example code in how to convert these to python floats; > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/42150c= >cc20a1d8d5/4aadc71be8aeddbe#4aadc71be8aeddbe > >I copied this code and modified it slightly, however, you will notice >that for one of the examples, the conversion isn't exact. > I suspect a typo in the hex ;-) >Can anyone advise me on how to modify this code to correct for this >situation ? >I think the problem may be related to the different lengths of the >mantissa. For double precision (8bytes) MBF format had 55 where as >Python floats (IEEE) has only 52 ?? I believe that's 53 including the "hidden" msb. UIAM that means you could lose precision if the LS byte had bits below 'F8' -- i.e., if bytes[0]&7 != 0 in the bytes passed to msd2float. But the bits that make the difference between 1234567890.0 and 1234567895.5 are nowhere near there. Hence my suspicion of a typo. > >Sample Code Below ---------------------- ># Conversion of Microsoft Binary Format numbers to Python Floats > >import binascii as bn >import struct as st > > >data =3D [(1234567890,'000000AF052C139F=AD'), [(1234567890,'000000A4052C139F=AD'), Are you sure it's not a 4? ----^ > (4069954144,'00000060929672A0'=AD), > (999999.99, '703D0AD7FF237494'), > ( 88888.88, '400ad7a3709c2d91'), > ( 22222.22, '400ad7a3709c2d8f'), > ( 33333.33, 'b047e17a54350290'), > ( 1500.34, '7814ae47e18a3b8b'), > ( 42345.00, '0000000000692590'), > ] > > >def msd2float(bytes): > #take out values that don't make sense possibly the NaN and >Infinity ?? > if sum(bytes) in [0,72,127]: > return 0.0 > b =3D bytes[:] > sign =3D bytes[-2]&0x80 > b[-2] |=3D 0x80 #hidden most sig bit in place of sign > exp =3D bytes[-1] - 0x80 - 56 #exponent offset > acc =3D 0L > for i,byte in enumerate(b[:-1]): > acc |=3D(long(byte)<<(i*8)) > return (float(acc)*2.0**exp)*((1.,-1.=AD)[sign!=3D0]) > >for line in data: > inval =3D line[0] > binval =3D bn.unhexlify(line[1]) > le_bytes =3D list(st.unpack('BBBBBBBB',binv=ADal)) > outval =3D msd2float(le_bytes) > print " In:",inval, "\nOut:",outval,"\n" The above print will use str conversion for floats, so you are not seeing a full representation of the two values. (BTW, even the repr value is not necessarily an accurate representation of the exact decimal represented by the IEEE double's bits, but it is guaranteed to be converted back to those bits from the literal string representation.) E.g. (using my exact decimal hack to show the full value), >>> from ut.exactdec import ED >>> print .1 0.1 Which is the same as >>> print str(.1) 0.1 but repr shows that's not exact >>> print repr(.1) 0.10000000000000001 but the exact decimal representation for those bits is >>> print ED(.1, 'all') ED('0.1000000000000000055511151231257827021181583404541015625') > >Sample Output ------------------------ >C:/Python24/pythonw.exe -u "C:/pytest/dms/Test MBF.pyw" > In: 1234567890 >Out: 1234567895.5 > try it with the typo fixed ;-) Regards, Bengt Richter From rrr at ronadam.com Tue Aug 16 14:31:05 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 16 Aug 2005 18:31:05 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> Message-ID: Antoon Pardon wrote: > I disagree here. The problem with "global", at least how it is > implemented in python, is that you only have access to module > scope and not to intermediate scopes. > > I also think there is another possibility. Use a symbol to mark > the previous scope. e.g. x would be the variable in local scope. > @.x would be the variable one scope up. @. at .x would be the > variable two scopes up etc. Looks like what you want is easier introspection and the ability to get the parent scope from it in a simple way. Maybe something like a builtin '__self__' name that contains the information, then a possible short 'sugar' method to access it. '__self__.__parent__', would become @ in your example and '__self__.__perent__.__self__.__parent__' could become @. at . Somthing other than '@' would be better I think. A bare leading '.' is another possiblity. Then '..x' would be the x two scopes up. This isn't the same as globals. Globals work the way they do because if they weren't automatically visible to all objects in a module you wouldn't be able to access any builtin functions or class's without declaring them as global (or importing them) in every function or class that uses them. Cheers, Ron From gene.tani at gmail.com Thu Aug 18 15:33:24 2005 From: gene.tani at gmail.com (gene tani) Date: 18 Aug 2005 12:33:24 -0700 Subject: up to date books? In-Reply-To: References: Message-ID: <1124393604.278061.24100@g49g2000cwa.googlegroups.com> well, it's not easy to find neutral comparisons of ruby and python, but http://www.ruby-doc.org/RubyEyeForThePythonGuy.html http://onestepback.org/index.cgi/Tech/Ruby/PythonAndRuby.rdoc http://www.approximity.com/ruby/Comparison_rb_st_m_java.html http://reflectivesurface.com/weblog/2004/12/19/why-rails http://martinfowler.com/bliki/CollectionClosureMethod.html Also, Hal Fulton's "Ruby Way" book has a good "Python vs. ruby syntax" appendix, if it's still in print From randy at psg.com Fri Aug 26 22:43:22 2005 From: randy at psg.com (Randy Bush) Date: Fri, 26 Aug 2005 16:43:22 -1000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> <3n8ddiFbhg7U1@individual.net> <8664tsw4y9.fsf@bhuda.mired.org> Message-ID: <17167.54090.466214.971482@roam.psg.com> i left the usenet in the latter half of the '80s. a few weeks ago i decided i wanted to do a new project with a new language, and chose python. so i joined this mailing list, which is gated to the usenet. i am impressed that the s:n has not gotten significantly worse than when i left, about 0.25, this message being my contribution to the noise. the s here is pretty darn good. but the n is pretty silly. randy From curtis.rendon at gmail.com Sat Aug 13 17:04:08 2005 From: curtis.rendon at gmail.com (curtis.rendon at gmail.com) Date: 13 Aug 2005 14:04:08 -0700 Subject: Bug on Python2.3.4 [FreeBSD]? In-Reply-To: References: <1123906696.459433@yasure> Message-ID: <1123967048.441133.286260@z14g2000cwz.googlegroups.com> Using FreeBSD 4.10 and Python 2.3.4: > uname -a FreeBSD garner_ted 4.10-RELEASE FreeBSD 4.10-RELEASE #7: Thu Apr 28 22:44:58 CDT 2005 >python Python 2.3.4 (#4, Nov 19 2004, 15:37:16) [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. using f.read('test','r+') I get the existing data, and the f.write('testing') successfully appends the text in the file. The 'a+' mode works as described, i.e. I need to f.seek(0) to read the data. I am now enlightened as to the usefulness of 'r+', as it starts the read fp at the begining of the file. Curtis W. Rendon From fakeaddress at nowhere.org Fri Aug 12 00:48:00 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 04:48:00 GMT Subject: constructing bytestrings In-Reply-To: <1123820251.064105.280190@g44g2000cwa.googlegroups.com> References: <1123820251.064105.280190@g44g2000cwa.googlegroups.com> Message-ID: <4SVKe.96$DV3.75@newssvr17.news.prodigy.com> Lenny G. wrote: > I use 's = os.read(fd, 12)' to grab 12 bytes from a file. Now, I want > to create a string, s1, which contains 16-12=4 bytes: 4,0,0,0, followed > by the contents of s. > > I know how to 's1 = "\x04\x00\x00\x00"' and how to 's3 = s1+s', but I > don't know how to construct s1 dynamically (i.e., given N, construct > "N" followed by N-1 "0", where "N" and "0" are single byte values with > N<16). How do I do this? chr(N) + '\x00' * (N - 1) -- --Bryan From bokr at oz.net Wed Aug 10 19:16:29 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 10 Aug 2005 23:16:29 GMT Subject: interpreter frame References: <1123689998.800361.278370@g43g2000cwa.googlegroups.com> <1123711701.529320.85880@g14g2000cwa.googlegroups.com> Message-ID: <42fa89ac.1123306329@news.oz.net> On 10 Aug 2005 15:08:21 -0700, "Leo" wrote: >Good try, but that doesn't seem to work either. Maybe I should have >emphasized that what I really want is the line of code, as opposed to >the entire frame. Here is the output of sys._getframe() on my system: > >Python 2.3.4 (#1, Feb 2 2005, 12:11:53) >[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> sys._getframe() > >>>> from inspect import * >>>> getframeinfo(sys._getframe()) >('', 1, '?', None, None) > >Is it different in 2.4? Maybe there is something else in sys.* that I >am having trouble finding? > Isn't there some requirement of having a source file in order to get the line of code, which an interactive session does not satisfy? (Maybe a strategically located StringIO instance encapsulating the latest interactive chunk as "source file" could solve it?) Regards, Bengt Richter From wenming_hu2002 at hotmail.com Thu Aug 18 04:50:01 2005 From: wenming_hu2002 at hotmail.com (wen) Date: Thu, 18 Aug 2005 16:50:01 +0800 Subject: how do i add a new path into sys.path? References: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> Message-ID: if i wanna add the path "C:\temp" into sys.path, and make it available for any other new python apps, like i add C:\temp into windows path , how? thank you. "apa" wrote in message news:1124353535.829964.208660 at o13g2000cwo.googlegroups.com... > You can do it this way: > > sys.path.append("C:\Temp") > > Alejandro > From mandus at gmail.com Wed Aug 3 15:17:31 2005 From: mandus at gmail.com (Mandus) Date: Wed, 3 Aug 2005 19:17:31 +0000 (UTC) Subject: socket and os.system References: Message-ID: Wed, 03 Aug 2005 15:46:50 -0000 skrev mfaujour: > > I HAVE THIS PYTHON PROGRAMM: > [snip] welcome to usenet! Maybe you get an answer if you doesn't shout that much. Or maybe you just have a problem with you Caps Lock? -- Mandus - the only mandus around. From zen19725 at zen.co.uk Mon Aug 1 04:00:40 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 1 Aug 2005 09:00:40 +0100 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> Message-ID: On Sun, 31 Jul 2005 14:52:58 -0400, Mike Meyer wrote: >Torsten Bronger writes: >> Hall??chen! >> Mike Meyer writes: >>> Torsten Bronger writes: >>>> Calvin Spealman writes: >>>>> The choice is GUI toolkits is largely seperate from >>>>> Python. Consider that they are just bindings to libraries that >>>>> are developed completely seperate of the language. GUI is should >>>>> be seperate from the language, and thus not bound to same >>>>> expectations and desires as elements of the language itself. >>>> I disagree. A modern language must provide a convenient and >>>> well-embedded way to write GUI applications. >>> The tools for writing GUI applications belong in a library, not >>> the langauge. >> None of us has talked about changing syntax. However, the standard >> library is part of the language unless you're really very petty. > >Or you use different Python implementations. There are four different >Python implementations in the world. Not everything in the CPYthon >standard library runs in all of them. I would guess that 90%+ of Python developers develop to CPython. >To put this differently, it's required if you want to succeed as a >language for the specific purpose of creating GUI applications. I'd >agree to that. But there are *lots* of other application areas around, >so limiting your definition of "success" to that one field is very >short-sighted. GUI applications are a large area; and langauge that doesn't do them tolerably well is limiting its success. -- Email: zen19725 at zen dot co dot uk From pierre.barbier at cirad.fr Sat Aug 20 11:02:02 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Sat, 20 Aug 2005 17:02:02 +0200 Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? In-Reply-To: <4jHNe.9077$ns.9030@newsread1.news.atl.earthlink.net> References: <4jHNe.9077$ns.9030@newsread1.news.atl.earthlink.net> Message-ID: <43074531$0$17386$626a14ce@news.free.fr> Lucas Raab a ?crit : > Miernik wrote: > [...] > > You can delete any two of the three and you shouldn't run into any > problems. However, the .py files are the source code and .pyc and .pyo > are compiled Python files. The .pyc and .pyo files will load faster > because they are compiled. Also, if you keep the .py files and then > execute them, .pyc files will be generated. In short, I would keep the > .pyc files and delete the others. > As I said in my other post, if you ever run python using the "-O" and have neither the .py nor the .pyo file, it won't load the module (even if the .pyc is present ...) Pierre From jason at tishler.net Sun Aug 28 08:50:22 2005 From: jason at tishler.net (Jason Tishler) Date: Sun, 28 Aug 2005 08:50:22 -0400 Subject: Cygwin font problems In-Reply-To: References: Message-ID: <20050828125022.GD3764@tishler.net> Steve, On Sat, Aug 27, 2005 at 11:43:23PM -0400, Steve Holden wrote: > Cygwin runs Python 2.4.1, Windows runs 2.4. Any light on this mystery > gratefully received. You may get better traction on the Cygwin mailing list. I recommend trying there. 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 groups at matthammond.org Thu Aug 4 06:15:35 2005 From: groups at matthammond.org (Matt Hammond) Date: 4 Aug 2005 03:15:35 -0700 Subject: Advanced concurrancy In-Reply-To: <1123146951.295678.82770@g14g2000cwa.googlegroups.com> References: <42ea98a2$0$1185$ed2619ec@ptn-nntp-reader01.plus.net> <42f154fd$0$14656$ed2619ec@ptn-nntp-reader02.plus.net> <1123146951.295678.82770@g14g2000cwa.googlegroups.com> Message-ID: <1123150535.600371.110510@z14g2000cwz.googlegroups.com> Ooops! In case you're wondering who I am, I'm working on Kamaelia with Michael Sparks at the BBC. Matt From nephish at xit.net Thu Aug 18 00:27:06 2005 From: nephish at xit.net (nephish at xit.net) Date: 17 Aug 2005 21:27:06 -0700 Subject: question about binary and serial info In-Reply-To: <1124337614.259032.4970@g14g2000cwa.googlegroups.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <1124337614.259032.4970@g14g2000cwa.googlegroups.com> Message-ID: <1124339226.523475.257400@z14g2000cwz.googlegroups.com> yeah, i think i got that down, i need help with getting the hex to binary, then splitting the byte up to compare each bit against the bit in another byte. unless i am not understanding this stuff with the bitwise right. there wasn't a lot in the python library reference about it. thanks From knaren at midascomm.com Wed Aug 24 23:47:21 2005 From: knaren at midascomm.com (knaren at midascomm.com) Date: Thu, 25 Aug 2005 09:17:21 +0530 (IST) Subject: Email client in Pyhton In-Reply-To: <20050824100732.1c8179f9.mekstran@scl.ameslab.gov> Message-ID: Thanks micheal, for help. I think this could solve most of problem. -- K Naren, MeTel Team. http://www.midascomm.com/ From steven.bethard at gmail.com Sun Aug 14 23:25:38 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 14 Aug 2005 21:25:38 -0600 Subject: Loading classes dynamically In-Reply-To: References: Message-ID: Ramza Brown wrote: > try: > load = eval('%s(props)' % (props['plugin.generate'])) > except: > > It works, doesnt seem very safe. Where props['plugin.generate'] is a > class name string. And 'props' is the first arg in the constructor. Where is the class defined? The right answer to this is usually somethign like: load = getattr(some_module, props['plugin.generate'])(props) If the class is defined in the current module, another possibility is: load = globals()[props['plugin.generate']](props) HTH, STeVe From jeremy at emperorlinux.com Thu Aug 11 18:46:02 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Thu, 11 Aug 2005 18:46:02 -0400 Subject: Printing literal text of an argument In-Reply-To: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> References: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> Message-ID: <1123800362.3900.1.camel@localhost.localdomain> def debug(s): print "s" exec(s) The line thing i'm not so sure about. Er. Hmmm. On Thu, 2005-08-11 at 14:04 -0700, Rex Eastbourne wrote: > Hi all, > > I've written the following simple macro called debug(aname, avalue) > that prints out the name of an expression and its value: > > def debug(aname, avalue): > print aname, 'is': > pprint.pprint(avalue) > > An example call is: > > debug('compose(f1,f2)', compose(f1,f2)) > > Writing the exact same thing twice (one in quotes and the other not) > sets off an alarm in my head. Is there a way to make this function take > only one argument, and use both its value and its literal form? On a > slightly different topic, is it also possible to make the macro print > the line number where the function was first called? > > Thanks, > > Rex > From skip at pobox.com Sun Aug 21 18:37:34 2005 From: skip at pobox.com (skip at pobox.com) Date: Sun, 21 Aug 2005 17:37:34 -0500 Subject: Moinmoin config In-Reply-To: <1124505462.437697.107950@z14g2000cwz.googlegroups.com> References: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> <18da$4304e393$506cf87a$23485@news.chello.at> <1124505462.437697.107950@z14g2000cwz.googlegroups.com> Message-ID: <17161.558.159963.938342@montanaro.dyndns.org> Mark> I have another question, and as of yet, have not found another Mark> discussion group for moinmoin, so sorry, but here goes: Have you tried the mailing list moin-user at lists.sourceforget.net? If you are determined to read it via Usenet, try gmane: http://dir.gmane.org/search.php?match=moin Skip From duncan.booth at invalid.invalid Fri Aug 12 03:42:30 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Aug 2005 07:42:30 GMT Subject: Regular expression to match a # References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> <42fbb9a9$1@news.eftel.com> Message-ID: John Machin wrote: > The point was made in a context where the OP appeared to be reading a > line at a time and parsing it, and re.compile(r'something').match() > would do the job; re.compile(r'^something').search() will do the job too > -- BECAUSE ^ means start of line anchor -- but somewhat redundantly, and > very inefficiently in the failing case with dopey implementations of > search() (which apply match() at offsets 0, 1, 2, .....). Answering the question you think should have been asked rather than the question which was actually asked is a great newsnet tradition, and often more helpful to the poster than a straight answer would have been. However, you do have to be careful to make it clear that is what you are doing. The OP did not use the word 'line' once in his post. He simply said he was searching a string. You didn't use the word 'line' either. If you are going to read more into the question than was actually asked, please try to say what question it is you are actually answering. If he is using individual lines and re.match then the presence or absence of a leading ^ makes virtually no difference. If he is looking for all occurences in a multiline string then re.search with an anchored match is a correct way to do it (splitting the string into lines and using re.match is an alternative which may or may not be appropriate). Either way, putting the focus on the ^ was inappropriate: the issue is whether to use re.search or re.match. If you assume that the search fails on an 80 character line, then I get timings of 6.48uS (re.search), 4.68uS (re.match with ^), 4.66uS (re.match without ^). A failing search on a 10,000 character line shows how performance will degrade (225uS for search, no change for match), but notice that searching 1 10,000 character string is more than twice as fast as matching 125 80 character lines. I don't understand what you think an implementation of search() can do in this case apart from trying for a match at offsets 0, 1, 2, ...? It could find a match at any starting offset within the string, so it must scan the string in some form. A clever regex implementation will use Boyer-Moore where it can to avoid checking every index in the string, but for the pattern I suggested it would suprise me if any implementations actually manage much of an optimisation. From http Sat Aug 6 20:32:19 2005 From: http (Paul Rubin) Date: 06 Aug 2005 17:32:19 -0700 Subject: The ONLY thing that prevents me from using Python References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <1123256939.119967.280500@z14g2000cwz.googlegroups.com> <1123264238.812930.315720@g47g2000cwa.googlegroups.com> <86br4byfpz.fsf@bhuda.mired.org> Message-ID: <7xbr4atwmk.fsf@ruckus.brouhaha.com> Mike Meyer writes: > The only way ISPs will find out that Python is popular is if potential > customers tell them they need it. So if they say no, be *sure* and > tell them you won't be using them because of that. I think the issue is low cost web hosts, not ISP's. PHP is much more available than Python among low cost hosts because those languages let multiple user scripts run in the same process without being able to mess with each others' data. That means the hosting service can run a single Apache instance with mod_php and thousands of virtual hosts all on the same IP address without needing to fork new processes for every user script. I'm not sure if mod_perl is the same way. Some hosts do let you use perl cgi's, forking a new process for every script invocation, and those hosts may as well also offer Python. But I think the really cheap hosts don't let you use any cgi's. From rich.teer at rite-group.com Thu Aug 25 12:34:53 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Thu, 25 Aug 2005 16:34:53 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: On Thu, 25 Aug 2005, Mike Schilling wrote: > Another advantage is that evewry internet-enabled computer today already > comes with an HTML renderer (AKA browser), so that a message saved to a file > can be read very easily. I think you're missing the point: email and Usenet are, historically have been, and should always be, plain text mediums. If I wanted to look at prettily formatted HTML, I'd use a web browser to look at the web. -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From spam.csubich+block at block.subich.spam.com Wed Aug 3 11:37:31 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 03 Aug 2005 11:37:31 -0400 Subject: cut & paste text between tkinter widgets In-Reply-To: References: Message-ID: William Gill wrote: > Is there a simple way to cut and paste from a tkinter text widget to an > entry widget? I know I could create a mouse button event that triggers > a popup (message widget) prompting for cut/paste in each of the widgets > using a temp variable to hold the text, but I don't wnat to reinvent the > wheel if there already is something that does the job. 1) TKinter text and entry widgets should already have proper event bindings for cut/copy/paste. Test first with your system-default keyboard shortcuts (^C, ^X, ^V on Windows). I haven't tried it myself, but I think those events bind to '<>', '<>', and '<>', so generating them should Do The Right Thing with selected text. 2) If you need to do any processing on the clipboard data, look at widget.selection_get [so named because of the way that X handles its clipboard] From arthas.thesox at gmail.com Mon Aug 1 20:05:35 2005 From: arthas.thesox at gmail.com (Arthas) Date: Tue, 2 Aug 2005 02:05:35 +0200 Subject: How to execute code when a module is imported ? Message-ID: <600d5b730508011705306de451@mail.gmail.com> How I do it? I wanna execute some code when a module is imported: -- foo.py -- #!/usr/bin/env python def codetoexecwhenloaded(): print "bar" -- end of foo.py -- -- in console -- import foo ^ and then it should print "bar" Thanks, Arthas -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at zoran.com Wed Aug 31 10:11:07 2005 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Wed, 31 Aug 2005 17:11:07 +0300 Subject: Epydoc - Documenting class members? Message-ID: <20050831141106.GG2656@zoran.com> Hello, Is there a way to document class members in Epydoc? Something like: class Point: def __init__(self, x, y): '''Create new point @param x: X coord @param y: Y coord ''' self.x = x # How do I document here? self.y = y # How do I document here? Thanks. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.bizhat.com The only difference between children and adults is the price of the toys -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 193 bytes Desc: not available URL: From wenming_hu2002 at hotmail.com Thu Aug 18 04:22:17 2005 From: wenming_hu2002 at hotmail.com (wen) Date: Thu, 18 Aug 2005 16:22:17 +0800 Subject: how do i add a new path into sys.path? Message-ID: on my system(win2k server, python 2.3.5), >>> import sys >>> print sys.path ['C:\\', 'C:\\WINNT\\system32\\python23.zip', 'C:\\Python23\\lib\\site-packages\\Pythonwin', 'C:\\Python23\\lib\\site-packages\\win32', 'C:\\Python23\\lib\\site-packages\\win32\\lib', 'C:\\Python23\\lib\\site-packages', 'C:\\Python23\\DLLs', 'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win', 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano Scientific\\PyMOL\\modules'] now, i wanna add "C:\Python23\Pmw\Pmw_1_2\lib" into sys.path, how? any help would be appreciated. with my kind regards, Wen From jdhunter at ace.bsd.uchicago.edu Tue Aug 2 09:23:09 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 02 Aug 2005 08:23:09 -0500 Subject: ANN: matplotlib 0.83.2 Message-ID: <871x5c1nia.fsf@peds-pc311.bsd.uchicago.edu> matplotlib is a 2D plotting package for python. This is a summary of recent developments in matplotlib since 0.80. For detailed notes, see http://matplotlib.sf.net/whats_new.html, http://matplotlib.sf.net/CHANGELOG and http://matplotlib.sf.net/API_CHANGES == Whats New == matplotlib wiki: this was just launched a few days ago and only has two entries to date, but we hope this will grow into a useful site with tutorials, howtos, installation notes, recipes, etc. Please contribute! Thanks to scipy.org and Enthought for hosting. http://www.scipy.org/wikis/topical_software/MatplotlibCookbook CocoaAgg: New CocoaAgg backend for native GUI on OSX, 10.3 and 10.4 compliant, contributed by Charles Moad. TeX support : Now you can (optionally) use TeX to handle all of the text elements in your figure with the rc param text.usetex in the antigrain and postscript backends; see http://www.scipy.org/wikis/topical_software/UsingTex. Thanks to Darren Dale for hard work on the TeX support. Reorganized config files: Made HOME/.matplotlib the new config dir where the matplotlibrc file, the ttf.cache, and the tex.cache live. Your .matplotlibrc file, if you have one, should be renamed to .matplotlib/matplotlibrc. Masked arrays: Support for masked arrays in line plots, pcolor and contours. Thanks Eric Firing and Jeffrey Whitaker. New image resize options interpolation options. See help(imshow) for details, particularly the interpolation, filternorm and filterrad kwargs. New values for the interp kwarg are: 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'blackman' Byte images: Much faster imaeg loading for MxNx4 or MxNx3 UInt8 images, which bypasses the memory and CPU intensive integer/floating point conversions. Thanks Nicolas Girard. Fast markers on win32: The marker cache optimization is finally available for win32, after an agg bug was found and fixed (thanks Maxim!). Line marker plots should be considerably faster now on win32. Qt in ipython/pylab: You can now use qt in ipython pylab mode. Thanks Fernando Perez and the Orsay team! Agg wrapper proper: Started work on a proper agg wrapper to expose more general agg functionality in mpl. See examples/agg_test.py. Lots of wrapping remains to be done. Subplot configuration: There is a new toolbar button on GTK*, WX* and TkAgg to launch the subplot configuration tool. GUI neutral widgets: Matplotlib now has cross-GUI widgets (buttons, check buttons, radio buttons and sliders). See examples/widgets/*.py and http://matplotlib.sf.net/screenshots.html#slider_demo. This makes it easier to create interactive figures that run across backends. Full screen mode in GTK*: Use 'f' to toggle full screen mode in the GTK backends. Thanks Steve Chaplin. Downloads available from http://matplotlib.sf.net From fredrik at pythonware.com Mon Aug 22 08:18:19 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 14:18:19 +0200 Subject: regular expressions use References: <6uhOe.70629$2U1.3761846@news3.tin.it> Message-ID: "max(01)*" wrote: > i would like to do some uri-decoding, which means to translate patterns > like "%2b/dhg-%3b %7E" into "+/dhg-; ~" >>> import urllib >>> urllib.unquote("%2b/dhg-%3b %7E") '+/dhg-; ~' From anonymousnerd at gmail.com Sun Aug 28 05:47:45 2005 From: anonymousnerd at gmail.com (Vaibhav) Date: 28 Aug 2005 02:47:45 -0700 Subject: What are new-style classes? Message-ID: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> I recently heard about 'new-style classes'. I am very sorry if this sounds like a newbie question, but what are they? I checked the Python Manual but did not find anything conclusive. Could someone please enlighten me? Thanks! From falcon3166 at hotmail.com Thu Aug 18 12:52:04 2005 From: falcon3166 at hotmail.com (Nathan Pinno) Date: Thu, 18 Aug 2005 10:52:04 -0600 Subject: (OT) Is there something that people can use instead of full blown Python to run Python programs? References: <312cfe2b05081809382d3a87b7@mail.gmail.com> Message-ID: I was thinking something like Java's Runtime Environment, but that might also do. Thanks, Nathan Pinno --------------------------------------------------------------- Early to bed, Early to rise, Makes a man healthy, wealthy, and wise. --Benjamin Franklin ------------------------------------------------------------------- Languages I know: Python, English Languages I am learning: C++, Java, Javascript ----- Original Message ----- From: Gregory Pi?ero To: Nathan Pinno Cc: python-list at python.org Sent: Thursday, August 18, 2005 10:38 AM Subject: Re: (OT) Is there something that people can use instead of full blown Python to run Python programs? I'm no expert, but I'm guessing you could compile a python with less libraries. I bet that would slim it down a lot. -Greg On 8/18/05, Nathan Pinno wrote: Hi all, Is there something besides the full blown version of Python that people can use to run Python programs, or do they have to use the full blown version of it? Thanks, Nathan --------------------------------------------------------------- Early to bed, Early to rise, Makes a man healthy, wealthy, and wise. --Benjamin Franklin ------------------------------------------------------------------- Languages I know: Python Languages I am learning: C++. Java, Javascript -- http://mail.python.org/mailman/listinfo/python-list -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From mage at mage.hu Wed Aug 3 15:45:13 2005 From: mage at mage.hu (Mage) Date: Wed, 03 Aug 2005 21:45:13 +0200 Subject: pain In-Reply-To: References: Message-ID: <42F11EC9.9060603@mage.hu> Mandus wrote: >Wed, 03 Aug 2005 17:45:34 +0200 skrev Mage: > > >> Hello, >> >>I started to learn python some months ago. Mostly for fun, but I >>replaced php to python in many tools at my company in the last weeks. >> >>Because of our boss decision now I have to learn java. I can tell java >> >> >[snip] > >maybe you can use jython, and tell your boss it's Java. A boss forcing >people to learn and use Java probably have no interest at all ever read >the code himself, so you will probably get away with it. I mean, a >clueless boss... > > Thank you, I will check this out. My company will switch to a jsp site. Isn't jython slower (I mean performance) than java? As well as I understand jython code will be interpreted twice. >or just find another place to work? > > Acceptable but I have some reasons to stay. >Don't code Java, be happy :-) > > I would be surprised if there were more than five python jobs in my country but have to look around. Mage From franz.steinhaeusler at gmx.at Mon Aug 1 10:12:12 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Mon, 01 Aug 2005 16:12:12 +0200 Subject: Getting not derived members of a class Message-ID: Hello NG, I want to retrieve the members of a class with a baseclass. But the problem is, how to get the non derived members. class a: def who(self): print "who" def __init__(self): self._a = 3 class b(a): def who1(self): print "who1" def __init__(self): a.__init__(self) self._b = 4 y=b() dir (y) ['__doc__', '__init__', '__module__', '_a', '_b', 'who', 'who1'] I need a function which lists only the members of the "not derived" class (here class B). _b _who1 __init__ How can I achieve this? With the introspect module or so? many thanks in advance! -- Franz Steinhaeusler From agentriot at gmail.com Mon Aug 22 01:22:44 2005 From: agentriot at gmail.com (Ricardo Sanchez) Date: 21 Aug 2005 22:22:44 -0700 Subject: Uploading images to imageshack.us with Python Message-ID: <1124688164.318336.55370@z14g2000cwz.googlegroups.com> Hello, I'm trying to upload images to http://imageshac.us via a Python script. I have looked at the POST request with HTTPLiveHeaders Firefox extension when I upload an image, but I can't figure what's wrong. (if I disable the cookies in the browser, it still works, so it's not that). When I try to upload images with the script below, the server replies with the following error:
Warning: Division by zero in /home/image/www/index.php on line 270
followed with the regular imageshack.us index. Currently my code is the following one (I got it from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306): # ------------------------------------------ import urllib, httplib, mimetypes def post_multipart(host, port, selector, fields, files): """ Post fields and files to an http host as multipart/form-data. fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return the server's response page. """ content_type, body = encode_multipart_formdata(fields, files) h = httplib.HTTP(host, port) h.putrequest('POST', selector) h.putheader('content-type', content_type) h.putheader('content-length', str(len(body))) h.endheaders() h.send(body) errcode, errmsg, headers = h.getreply() return h.file.read() def encode_multipart_formdata(fields, files): """ fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return (content_type, body) ready for httplib.HTTP instance """ BOUNDARY = '---------------------------13049614110900' CRLF = '\r\n' L = [] for (key, value) in fields: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"' % key) L.append('') L.append(value) for (key, filename, value) in files: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) L.append('Content-Type: %s' % get_content_type(filename)) L.append('') L.append(value) L.append('--' + BOUNDARY + '--') L.append('') body = CRLF.join(L) content_type = 'multipart/form-data; boundary=%s' % BOUNDARY return content_type, body def get_content_type(filename): return mimetypes.guess_type(filename)[0] or 'application/octet-stream' params = [('MAX_FILE_SIZE', '3145728'), ('refer', 'http://reg.imageshack.us/v_images.php')] files = [('fileupload', 'b.jpg', open('b.jpg').read())] print open('a.jpg').read() print post_multipart('proxy-a.mains.nitech.ac.jp', 8080, 'http://imageshack.us/index.php', params, files) # ------------------------------------------ Here is the HTTPLiveHeaders POST request: # ------------------------------------------ http://imageshack.us/index.php POST http://imageshack.us/index.php HTTP/1.1 Host: imageshack.us User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Referer: http://imageshack.us/ Cookie: imgshck=4d590dbf69a8461ddff60153181b6c61; img_gallery=e04663a565bc72348bfb2bdeec6d50a0%3Dp10100397vj.jpg%3Dimg185; PHPSESSID=1bd06f468149071bd87f7f8e90142cff Content-Type: multipart/form-data; boundary=---------------------------114782935826962 Content-Length: 90772 -----------------------------114782935826962 Content-Disposition: form-data; name="MAX_FILE_SIZE" 3145728 -----------------------------114782935826962 Content-Disposition: form-data; name="refer" -----------------------------114782935826962 Content-Disposition: form-data; name="fileupload"; filename="a.jpg" Content-Type: image/jpeg ???? HTTP/1.x 200 OK Date: Mon, 22 Aug 2005 05:14:16 GMT Server: Apache/2.0.54 (Unix) X-Powered-By: PHP/4.4.0 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Connection: close Content-Type: text/html; charset=ISO-8859-1 # ------------------------------------------ Any help would be appreciated. From noreply at gcgroup.net Sun Aug 14 15:28:04 2005 From: noreply at gcgroup.net (William Gill) Date: Sun, 14 Aug 2005 19:28:04 GMT Subject: help with mysql cursor.execute() Message-ID: <8XMLe.878$Z%6.698@newssvr17.news.prodigy.com> I have been trying to pass parameters as indicated in the api. when I use: sql= 'select * from %s where cusid = %s ' % name,recID) Cursor.execute(sql) it works fine, but when I try : sql= 'select * from %s where cusid like %s ' Cursor.execute(sql,(name,recID)) or sql= 'select * from ? where cusid like ? ' Cursor.execute(sql,(name,recID)) it fails. Can someone help me with the semantics of using parameterized queries? Bill From twic at urchin.earth.li Mon Aug 15 12:11:43 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Mon, 15 Aug 2005 17:11:43 +0100 Subject: __del__ pattern? In-Reply-To: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: On Mon, 15 Aug 2005, Chris Curvey wrote: > Is there a better pattern to follow than using a __del__ method? I just > need to be absolutely, positively sure of two things: An old hack i've seen before is to create a server socket - ie, make a socket and bind it to a port: import socket class SpecialClass: def __init__(self): self.sock = socket.socket() self.sock.bind(("", 4242)) def __del__(self): self.sock.close() Something like that, anyway. Only one socket can be bound to a given port at any time, so the second instance of SpecialClass will get an exception from the bind call, and will be stillborn. This is a bit of a crufty hack, though - you end up with an open port on your machine for no good reason. If you're running on unix, you could try using a unix-domain socket instead; i'm not sure what the binding semantics of those are, though. I think Brano's suggestion of using flock is a better solution. tom -- Gin makes a man mean; let's booze up and riot! From u.hobelmann at web.de Sat Aug 27 05:24:23 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Sat, 27 Aug 2005 11:24:23 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <86acj4w627.fsf@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> Message-ID: <3napq7Fl7hrU1@individual.net> Mike Meyer wrote: >> This can be designed much better by using iframes, maybe even Ajax. > > Definitely with Ajax. That's one of the things it does really well. But then you're probably limited to the big 4 of browsers: MSIE, Mozilla, KHTML/Safari, Opera. Ok, that should cover most desktop users, but you might run into problems on embedded. I've also noticed that especially web forums and dynamic websites take up looots of memory on my machine (but then I have loooots). >>> Why can't we use the Web for what it was meant for: viewing hypertext >>> pages? Why must we turn it into a wrapper around every application >>> imaginable? >> Because it works? > > Because you can - if you know how to use HTML properly - distribute > your application to platforms you've never even heard of - like the > Nokia Communicator. If the NC has software that can properly interpret all that HTML, CSS, JavaScript plus image formats, yes. But who guarantees that? I'd rather develop a native client for the machine that people actually WANT to use, instead of forcing them to use that little-fiddly web browser on a teeny tiny display. And again: connections might be slow, a compact protocol is better than loading the whole UI every time. And while Ajax might work, despite the UI being maybe too big for the little browser window, and even if it works, it's still probably more work than a simple, native UI. First of all it needs to load all the JS on first load, secondly sometimes for a flexible UI you'd have to replace huge parts of the page with something else. Native UIs are more up to the task. > I started writing web apps when I was doing internal tools development > for a software development company that had 90+ different platform > types installed inhouse. It was a *godsend*. By deploying one If that's 90+ GUI platforms, then I agree. I just wonder who wrote fully standards compliant web browsers for those 90 platforms. If you have one Windows GUI (maybe C#), one Mac GUI (Cocoa), one Gtk GUI for X, you're done. A GUI should be the smallest bunch of work on any given application, so it's not prohibitive to write a couple of them, IMHO. But then I've only ever used Swing and Cocoa and the latter *is* really convenient, might be that the others are a PITA, who knows... > well-written app, I could make everyone happy, without having to do > versions for the Mac, Windows, DOS (this was a while ago), getting it > to compile on umpteen different Unix version, as well as making it > work on proprietary workstation OS's. Well, stick to POSIX and X APIs and your stuff should run fine on pretty much all Unices. I never understood those people who write all kinds of weird ifdefs to run on all Unices. Maybe that was before my time, during the Unix wars, before POSIX. And if it's not Unix, what's a prop. workstation OS? > Of course, considering the state of most of the HTML on the web, I > have *no* idea why most of them are doing this. Yep. Maybe it would be best to reengineer the whole thing as ONE UI spec+action language, incompatible with the current mess, compact, so it can be implemented with minimum fuss. And most of all, I wouldn't use a MARKUP language, as a real application is not text-based (at least not as characteristic #1). -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From nid_oizo at yahoo.com_remove_the_ Tue Aug 9 17:41:08 2005 From: nid_oizo at yahoo.com_remove_the_ (Nicolas Fleury) Date: Tue, 09 Aug 2005 17:41:08 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <42f9037e$0$18078$9b622d9e@news.freenet.de> References: <42F66FF2.7010901@v.loewis.de> <42f9037e$0$18078$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: > Nicolas Fleury wrote: > >>Well, I'm using the alternatives. > > Perhaps not to the full power. Not perhaps, surely;) Who does anyway;) > So you don't want to write the makeArrayType function, right? > > How about this: > > # declaration > class Array(object): > __typeargs__ = ['arg1', ('arg2', someDefault)] > ... > > # use > t = specialize(Array, arg1=Int32) > > where specialize is defined as > > def specialize(ptype, *args): > result = type(ptype.__name__, (ptype,), args) > for t in result.__typeargs__: > if isinstance(t, string): > if not hasattr(result, t): > raise TypeError("missing parameter "+t) > else: > name,val = t > if not hasattr(result, name): > setattr(result, val) > return result That exact solution would not work for me, since that would replace the class metaclass, right? However, you have a good point. Such a function could be done by using the class metaclass instead of type, passing the base classes and dictionary (basically copying the class) and using a dictionary with args values as a key to avoid redundacies (can't see if there's something else). Thx and regards, Nicolas From kay.schluehr at gmx.net Sun Aug 7 13:14:33 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 7 Aug 2005 10:14:33 -0700 Subject: Chopping off spaces at both ends In-Reply-To: <42f63fac$0$18648$14726298@news.sunsite.dk> References: <42f63fac$0$18648$14726298@news.sunsite.dk> Message-ID: <1123434873.203001.207220@f14g2000cwb.googlegroups.com> Use the strip() method. Example: >>> "\t abc \n".strip() "abc" Variants are lstrip() and rstrip(). Regards, Kay From deets at nospam.web.de Tue Aug 23 18:51:10 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Aug 2005 00:51:10 +0200 Subject: Reading just a few lines from a text file In-Reply-To: <1124834875.760223.131270@z14g2000cwz.googlegroups.com> References: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> <1124834076.521797.60180@z14g2000cwz.googlegroups.com> <1124834875.760223.131270@z14g2000cwz.googlegroups.com> Message-ID: <3n1niuF18r0t3U1@uni-berlin.de> tkpmep at hotmail.com wrote: > Right now my code reads as follows: > > infile=file(FileName) > for line in reversed(infile.readlines()): #Search from the bottom up Not sure if python does some tricks here - but for me that seems to be uneccesary shuffling around of data. Better do for line in reversed(infile.readlines()[:-10]): ... Diez From torched_smurf at yahoo.com Thu Aug 18 20:17:47 2005 From: torched_smurf at yahoo.com (torched_smurf at yahoo.com) Date: 18 Aug 2005 17:17:47 -0700 Subject: Module Name Conflicts In-Reply-To: References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: <1124410667.095654.133980@g49g2000cwa.googlegroups.com> Robert Kern wrote: > Why not copy cmd.py into your package under a different name? > It offends my sense of modularity. For the record, I'm trying to use pdb, the debugger, which in turn uses cmd. So it would be a matter of taking pdb.py and hacking it to import a renamed version of cmd... kind of messy and not a very good longterm solution. That's not to say I won't resort to it if no better options are forthcoming. -Smurf From mwm at mired.org Tue Aug 2 20:23:12 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 20:23:12 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <861x5ehk4g.fsf@bhuda.mired.org> <86d5oxf0u8.fsf@bhuda.mired.org> Message-ID: <86mznzeumn.fsf@bhuda.mired.org> Jorge Godoy writes: > Mike Meyer wrote: >>> In fact this sounds more like a joke I've heard a while ago: standards, >>> if you don't like the ones out there, create your own. >> Works for me. > What works for you? You believe that chaos is better than having standards? > I believe that flexibility is good, but not chaos. I believe that multiple competing options is better than an externally enforced standard, or a single option with a near-monopoly position. If none of the options are good enough for the job at hand, you create your own. >> won't recap the thread, but other languages have been *very* >> successful without having a GUI as part of the language, all they had >> was one development environment distributed with a GUI. > One IDE, you mean? I believe the freedom to choose from multiple IDEs is > also good. Some code on VI, others on Emacs, others on Eclipse, others > on ... IDE is short for "integrated development environment". I chose a slightly broader phrase. The languages had more options than one specific distribution, but that one dominated at least one market. >> BTW, in answer to your rhetorical question about GUI's for Linux, the >> answer is plwm. > :-) > And does it integrate well with common business apps, such as a mail client, > note taking apps, addressbooks (with personal and shared entries), calendar > with ability to share appointments, etc.? Of course. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From yxxxxlxxxxx at gmail.com Fri Aug 12 12:31:08 2005 From: yxxxxlxxxxx at gmail.com (yaffa) Date: 12 Aug 2005 09:31:08 -0700 Subject: need help with my append syntax Message-ID: <1123864268.248317.23940@g44g2000cwa.googlegroups.com> dear folks, i'm trying to append a semicolon to my addr string and am using the syntax below. for some reason the added on of the ; doesn't work. when i print it out later on it only shows the original value of addr. addr = incident.findNextSibling('td') addr.append('%s;') thanks yaffa From bokr at oz.net Wed Aug 24 13:42:08 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 24 Aug 2005 17:42:08 GMT Subject: execfile in global scope References: <1124873425.620610.170970@g47g2000cwa.googlegroups.com> Message-ID: <430cb035.2312759762@news.oz.net> On 24 Aug 2005 01:50:25 -0700, v.vayer at gmail.com wrote: >I need to execfile() from a function in order to set value for a global >variable from inside the executed file. I know there are "globals" and >"locals" optional arguments for execfile, but I just can't figure out >how to use them correctly. Here is an example: > >Change.py >========= >x = 555 > >Main.py >======= > >def changevar(): > execfile("change.py") execfile("change.py", globals()) # the builtin globals function returns # the current module's global namespace # as a writable dict > >x = 111 # global var >changevar() >print x # returns 111 instead of 555 > >>> open('change.py','w').write("""\ ... x = 555 ... """) >>> print '%s\n%s%s' %('-'*30, open('change.py').read(), '-'*30) ------------------------------ x = 555 ------------------------------ >>> dir() ['__builtins__', '__doc__', '__name__'] >>> x = 111 >>> x 111 >>> def changevar(): ... execfile('change.py', globals()) ... >>> x 111 >>> changevar() >>> x 555 Regards, Bengt Richter From peter at engcorp.com Tue Aug 2 17:09:49 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 02 Aug 2005 17:09:49 -0400 Subject: time.clock() or time.time() In-Reply-To: References: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> Message-ID: Magnus Lycka wrote: > On Windows, you're likely to prefer time.clock(), to > measure relative times, since time.time() will have too low resolution > for measuring short thingies. Specifically, using the NT/XP family of Windows operating systems time.time() has a resolution of approximately 0.015 seconds (I believe it might be exactly 1/64 second, but it should be easy to confirm with a google search). From Scott.Daniels at Acm.Org Wed Aug 10 11:43:25 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Aug 2005 08:43:25 -0700 Subject: "Ordered" dicts In-Reply-To: References: Message-ID: <42fa17de$1@nntp0.pdx.net> Simon Brunning wrote: > On 8/10/05, Chris Cioffi wrote: > >>I have lots of code that looks like: >> keys = mydict.keys() >> keys.sort() > > > keys = sorted(mydict.keys()) > Or (often useful to get at contents): items = sorted(mydict.items()) as in: For key, value in sorted(mydict.items()): print '%s -> %r' % (key, value) -Scott David Daniels Scott.Daniels at Acm.Org From gene.tani at gmail.com Fri Aug 12 16:50:00 2005 From: gene.tani at gmail.com (gene tani) Date: 12 Aug 2005 13:50:00 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123864878.820070.232350@g14g2000cwa.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123857710.987790.285330@o13g2000cwo.googlegroups.com> <42fccc42$0$32450$626a14ce@news.free.fr> <1123864878.820070.232350@g14g2000cwa.googlegroups.com> Message-ID: <1123879800.675531.319370@g47g2000cwa.googlegroups.com> I think you'll like python. http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing http://dirtsimple.org/2004/12/java-is-not-python-either.html (and python-is-not-java) From guy at NOSPAM.r-e-d.co.nz Mon Aug 8 18:13:35 2005 From: guy at NOSPAM.r-e-d.co.nz (Guy Robinson) Date: Tue, 09 Aug 2005 10:13:35 +1200 Subject: python for microcontrollers In-Reply-To: <42f7c8d4$1@news.orcon.net.nz> References: <42f7c8d4$1@news.orcon.net.nz> Message-ID: How about just helping this project: http://pyastra.sourceforge.net/ I know he's trying to rewrite it to work across multiple uC's (AVR,msp430 etc) HTH, Guy Evil Bastard wrote: > Hi all, > > I'm currently tackling the problem of implementing a python to assembler > compiler for PIC 18Fxxx microcontrollers, and thought I'd open it up > publicly for suggestions before I embed too many mistakes in the > implementation. > > The easy part is getting the ast, via compiler.ast. Also easy is > generating the code, once the data models are worked out. > > The hard part is mapping from the abundant high-level python reality to > the sparse 8-bit microcontroller reality. > > I looked at pyastra, but it has fatal problems for my situation: > - no backend for 18fxxx devices > - only 8-bit ints supported > > I'm presently ripping some parts from the runtime engine of a forth > compiler I wrote earlier, to add support for 8-32 bit ints, floats, and > a dual-stack environment that offers comfortable support for local > variables/function parameters, as well as support for simpler and more > compact code generation. > > Python is all about implicitly and dynamically creating/destroying > arbitrarily typed objects from a heap. I've got a very compact > malloc/free, and could cook up a refcounting scheme, but using this for > core types like ints would destroy performance, on a chip that's already > struggling to do 10 mips. > > The best idea I've come up with so far is to use a convention of > identifier endings to specify type, eg: > - foo_i16 - signed 16-bit > - foo_u32 - unsigned 32-bit > - bar_f - 24-bit float > - blah - if an identifier doesn't have a 'magic ending', it will > be deemed to be signed 16-bit > > also, some virtual functions uint16(), int16(), uint32(), int32(), > float() etc, which work similar to C casting and type conversion, so I > don't have to struggle with type inference at compile time. > > Yes, this approach sucks. But can anyone offer any suggestions which > suck less? > From lycka at carmen.se Mon Aug 22 07:46:44 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 22 Aug 2005 13:46:44 +0200 Subject: Reg Python Byte code In-Reply-To: References: Message-ID: praba kar wrote: > Python 2.3 creates byte code with *.pyc > extention. But Python 2.4 creates bytes code with > *.pyo. Is there any difference between *.pyc > and *.pyo?. Since way back, ordinary Python bytecode uses .pyc, and optimized Python bytecode (python -O) uses .pyc. This has nothing to do with Python versions. As I recall, Python installers on the most common platforms have pre-generated both .pyc and .pyo file for the standard library since before 2.3. > Actually After python compiled a program > then that program will run from the *.pyc byte > code. If I delete that byte code what will be > happen.? Python will have to compile the module again, the next time it's imported. > If I delete *.pyc byte code in the python > 2.3 then It will create again *.pyc byte code. > But If I delete *.pyo byte code in the python > 2.4 then It will not create again *.pyo. Why > this difference. Because you didn't use 'python -O'. It used the .pyc version, not the .pyo. It's there too! > If I delete byte code of the python. > I want to know Whether it will affect the > performance of the programme or not. There is little point in removing files that will come back again. If you're allergic to bytecode files, you can writeprotect those dictionaries though. Each python process that imports a module will then have to compile the module. Whether this affects performance depends on how you use Python. For long runinng tasks, it will probably not matter, for e.g. big CGI scripts, it might have severe implications. From dimitri.pater at gmail.com Thu Aug 18 05:55:34 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Thu, 18 Aug 2005 11:55:34 +0200 Subject: up to date books? In-Reply-To: References: <430438F5.5000801@traxon.com> Message-ID: On 8/18/05, Jon Hewer wrote: > > mark pilgrim's dive into python is a good book if you're new to python I agree that dive into python is a *very* good python book, but as it is says on http://diveintopython.org/ it is "for experienced programmers". So if you are new to Python to programming in general it might NOT be the best book to get started. bye, dimitri -------------- next part -------------- An HTML attachment was scrubbed... URL: From n00m at narod.ru Wed Aug 31 08:14:32 2005 From: n00m at narod.ru (n00m) Date: 31 Aug 2005 05:14:32 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: <1125478316.530781.315540@g44g2000cwa.googlegroups.com> References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125425945.667967.181000@g49g2000cwa.googlegroups.com> <1125478316.530781.315540@g44g2000cwa.googlegroups.com> Message-ID: <1125490472.670850.247240@g49g2000cwa.googlegroups.com> Funnily but I still can't get the code working... WITHOUT IDLE. I think it's because of "import thread" line. Seems something wrong with "opening" this module. In IDLE it works OK. From pydecker at gmail.com Sun Aug 14 10:28:35 2005 From: pydecker at gmail.com (Peter Decker) Date: Sun, 14 Aug 2005 10:28:35 -0400 Subject: Standalone applications ? In-Reply-To: <1124016548.909588.77090@g47g2000cwa.googlegroups.com> References: <42feba84$0$18644$14726298@news.sunsite.dk> <42feca21$0$18650$14726298@news.sunsite.dk> <1124016548.909588.77090@g47g2000cwa.googlegroups.com> Message-ID: On 14 Aug 2005 03:49:08 -0700, TPJ wrote: > > I should have added that my platform is Linux. > > In this case you shouldn't bother yourself with executables. Python is > available on any major distribution. > > My Python apps are available as pyc files for Linux (and for those > Windows users, who have Python installed) and as executables for Win > (for those Windows users, who have no Python installed). What about any dependencies? While Linux distros may have Python installed, it may be an older version, and may not have one or two libraries that your app needs. E.g., I have Python that came with my FC2 install, but it doesn't come with Tkinter, so if you build a Tkinter-based app and just send me the .pyc file, it won't work. -- # p.d. From mhenry1384 at gmail.com Tue Aug 16 14:46:50 2005 From: mhenry1384 at gmail.com (mhenry1384) Date: 16 Aug 2005 11:46:50 -0700 Subject: get the return code when piping something to a python script? In-Reply-To: <1124217511.485128.125930@g49g2000cwa.googlegroups.com> References: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> <1124217511.485128.125930@g49g2000cwa.googlegroups.com> Message-ID: <1124218010.197387.217940@o13g2000cwo.googlegroups.com> >Didn't help you much.. Thanks, actually even hints that it's not possible helps. So I won't keep driving myself crazy figuring out how to do it. :-) From peter at engcorp.com Thu Aug 11 08:25:26 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 11 Aug 2005 08:25:26 -0400 Subject: PEP 328, absolute/relative import In-Reply-To: References: Message-ID: Ben Finney wrote: > Aahz wrote: >>Ben Finney wrote: >>>So, under PEP 328 rules, the original poster's current-directory >>>module could only be imported (a) if the current directory was in >>>sys.path, or (b) if the code specified a relative import. The >>>accidental shadowing of the stdlib module could not happen. >> >>Normally the current directory *is* on sys.path, and the first >>thing, too: > > So, modules in the current directory will continue to be imported as > before, because they *are* absolute imports by PEP328 definitions. Correct. We'll still be seeing newbies (and the odd experienced Pythonista) mistakenly shadowing standard library modules with name-colliding local ones well after PEP 328 is fully implemented. Gotta keep people on their feet! :-) -Peter From usenet at mail-2-me.com Fri Aug 12 03:23:58 2005 From: usenet at mail-2-me.com (usenet at mail-2-me.com) Date: 12 Aug 2005 00:23:58 -0700 Subject: net view /domain In-Reply-To: References: Message-ID: <1123831438.654951.83530@g43g2000cwa.googlegroups.com> Hi Tim! Thanks again for your help! I just tried it out and it does exactly what I want it to do :-) Have a nice day! Dirk From kst-u at mib.org Fri Aug 12 00:14:58 2005 From: kst-u at mib.org (Keith Thompson) Date: Fri, 12 Aug 2005 04:14:58 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <8j4of1t3h7cvuc6s0svvreu971peeh9qc7@4ax.com> Message-ID: Roedy Green writes: > On 11 Aug 2005 18:23:42 -0700, "Xah Lee" wrote or > quoted : [ the usual nonsense ] > > Jargon [...] [snip] Take a look at the Newsgroups: line. Then look for other articles Xah Lee has posted, and see if you can make sense of any of them. If you must post a followup, at least limit the newsgroups to those where it might be topical. +-------------------+ .:\:\:/:/:. | PLEASE DO NOT | :.:\:\:/:/:.: | FEED THE TROLLS | :=.' - - '.=: | | '=(\ 9 9 /)=' | Thank you, | ( (_) ) | Management | /`-vvv-'\ +-------------------+ / \ | | @@@ / /|,,,,,|\ \ | | @@@ /_// /^\ \\_\ @x@@x@ | | |/ WW( ( ) )WW \||||/ | | \| __\,,\ /,,/__ \||/ | | | jgs (______Y______) /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ============================================================== -- Keith Thompson (The_Other_Keith) kst-u at mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. From michele.simionato at gmail.com Mon Aug 8 04:46:55 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 8 Aug 2005 01:46:55 -0700 Subject: issues with doctest and threads Message-ID: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> I am getting a strange error with this script: $ cat doctest-threads.py """ >>> import time, threading >>> def example(): ... thread.out = [] ... while thread.running: ... time.sleep(.01) ... thread.out.append(".") >>> thread = threading.Thread(None, example) >>> thread.running = True; thread.start() >>> time.sleep(.1) >>> thread.running = False >>> print thread.out ['.', '.', '.', '.', '.', '.', '.', '.', '.'] """ if __name__ == "__main__": import doctest; doctest.testmod() $ python doctest-threads.py Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap self.run() File "/usr/lib/python2.4/threading.py", line 422, in run self.__target(*self.__args, **self.__kwargs) File "", line 5, in example NameError: global name 'thread' is not defined I have found out a workaround, putting 'thread' in the main program (i.e. in the globals): $ cat doctest-threads2.py """ >>> thread.running = True >>> thread.start() >>> time.sleep(.1) >>> thread.running = False >>> print thread.out ['.', '.', '.', '.', '.', '.', '.', '.', '.'] """ import time, threading def example(): thread.out = [] while thread.running: time.sleep(.01) thread.out.append(".") thread = threading.Thread(None, example) if __name__ == "__main__": import doctest; doctest.testmod() However this is strange, since replacing in the first script >>> globals()["thread"] = threading.Thread(None, example) does NOT work, so it is not just putting stuff in the globals. Also, it seems that I cannot reproduce the same error in absense of threads. Any idea of what is happening? Thanks for sharing, Michele Simionato From mkb at incubus.de Fri Aug 12 17:16:16 2005 From: mkb at incubus.de (Matthias Buelow) Date: Fri, 12 Aug 2005 23:16:16 +0200 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <864q9uzwin.fsf@drjekyll.mkbuelow.net> axel at white-eagle.invalid.uk writes: >In comp.lang.perl.misc Xah Lee wrote: >> The other class of jargon stupidity is from computing practitioners, of >> which the Unix/Perl community is exemplary. For example, the name Unix >> & Perl themselves are good examples of buzzing jargons. Unix is >> supposed to be opposed of Multics and hints on the offensive and >> tasteless term eunuchs. > >Now that connexion is a product of a truely warped mind. and one devoid of any trace of humour. mkb. From ray_usenet at yahoo.com Fri Aug 12 21:59:25 2005 From: ray_usenet at yahoo.com (Ray) Date: 12 Aug 2005 18:59:25 -0700 Subject: Python's Exception, and Capitalization In-Reply-To: <1123866072.361632.145880@z14g2000cwz.googlegroups.com> References: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> <1123866072.361632.145880@z14g2000cwz.googlegroups.com> Message-ID: <1123898365.532425.317060@o13g2000cwo.googlegroups.com> Steve M wrote: > You might find the Python Style Guide to be helpful: > > http://www.python.org/doc/essays/styleguide.html Nice! Thanks Steve. Ray From mwm at mired.org Wed Aug 10 21:41:18 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 10 Aug 2005 21:41:18 -0400 Subject: Python supports LSP, does it? References: <86wtmuk0c5.fsf@bhuda.mired.org> <42fa2606$0$23692$636a15ce@news.free.fr> Message-ID: <864q9xjlmp.fsf@bhuda.mired.org> bruno modulix writes: > Clearly, somethingElse is a subtype of baseClass, when derivedClass is > not. Don't confuse suclassing with subtyping. issinstance() let you > check for subclassing, not for subtyping. The only language-level > mechanism I know of that more or less inforce LSP is Eiffel's contracts. Eiffel's DbC has been picked up by other languages. D and SPARK come to mind. In a broader sense, a couple of Python frameworks support interfaces, which basically guarantee subtyping at the same level as Liskov's CLU language does. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lycka at carmen.se Wed Aug 10 11:06:39 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 10 Aug 2005 17:06:39 +0200 Subject: python for microcontrollers In-Reply-To: <2uydneEHCfjBeGTfRVn-oQ@powergate.ca> References: <42f7c8d4$1@news.orcon.net.nz> <7xd5oof5qj.fsf@ruckus.brouhaha.com> <42f91c1c$1@news.orcon.net.nz> <42f98b24$1@news.orcon.net.nz> <2uydneEHCfjBeGTfRVn-oQ@powergate.ca> Message-ID: Peter Hansen wrote: > (Not trying to argue, just understand, because it looks like you're > conflating Forth programs with Forth implementations, or perhaps I'm > even more ignorant than noted above and am missing a key point. :-) It's decades since I coded Forth, but I suspect that Forth compilers typically behave differently. On the other hand Forth is very simple, so it's probably not rocket science to write a new Forth compiler. It doesn't surprise me if it's simpler to write your own Forth compiler than to use one written by someone else--particularly. For a tiny device such as a PIC, it's not as if you will load a lot of third party libraries into your runtime environemt. I assume I/O functionality you desire would be implemented in the compiler, and it might well vary depending on your application how these are best designed. From nomail at nomail.com Wed Aug 17 04:25:14 2005 From: nomail at nomail.com (Nx) Date: Wed, 17 Aug 2005 16:25:14 +0800 Subject: Need better way to unpack a list Message-ID: Is there a better solution to following problem : I want to unpack a list into variables the list is created at runtime and I do not know how many items there will be , but I know not more than 25. The list unpacks into variables which are prev. defined as line1,line2....line25 which are actually the names of lineedit fields in a Qt gui application and which need to be populated. I currently use following to achieve that : c=0 while c < len(mylinelist): c = c + 1 if c==1: self.line1.setText(mylinelist[c]) if c==2 : self.line2.setText(mylinelist[c]) . . . if c==25: self.line25.setText(mylinelist[c]) I rather have someting like pseudo code follows: self.line+"c"+.setText(mylinelist[c]) How to do that ? Nx From bignose+hates-spam at benfinney.id.au Wed Aug 10 20:43:30 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2005 10:43:30 +1000 (EST) Subject: PEP 328, absolute/relative import (was: Re: Bizarre error from help()) References: Message-ID: Peter Hansen wrote: > Ben Finney wrote: > > Roy Smith wrote: > >>[current-directory module shadowing a system module] > > > > All hail the coming of PEP 328: > > > > Which, unless I misunderstand, would do nothing to change the > behaviour of the OP's situation unless the mistakingly named > "string.py" module was actually inside a package. If it was just in > the current directory at the time, I don't think the PEP328 would > have affected the situation. Once PEP 328 is fully implemented, all bare 'import foo' statements specify absolute imports (i.e. from sys.path only). To perform a relative import (e.g. from current directory) will require different syntax. "[...] relative imports will use leading dots. A single leading dot indicates a relative import, starting with the current package. Two or more leading dots give a relative import to the parent(s) of the current package [...]" So, under PEP 328 rules, the original poster's current-directory module could only be imported (a) if the current directory was in sys.path, or (b) if the code specified a relative import. The accidental shadowing of the stdlib module could not happen. -- \ "You know what would make a good story? Something about a clown | `\ who makes people happy, but inside he's real sad. Also, he has | _o__) severe diarrhea." -- Jack Handey | Ben Finney From sjmachin at lexicon.net Thu Aug 11 19:07:04 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 09:07:04 +1000 Subject: Regular expression to match a # In-Reply-To: <42fbd1a1$1@news.eftel.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> <42fbb9a9$1@news.eftel.com> <1123799252.257355.158320@f14g2000cwb.googlegroups.com> <42fbd1a1$1@news.eftel.com> Message-ID: <42fbda18@news.eftel.com> John Machin wrote: > Devan L wrote: > >> John Machin wrote: >> >>> Aahz wrote: >>> >>>> In article <42fb45d7$1 at news.eftel.com>, >>>> John Machin wrote: >>>> >>>> >>>>> Search for r'^something' can never be better/faster than match for >>>>> r'something', and with a dopey implementation of search [which >>>>> Python's >>>>> re is NOT] it could be much worse. So please don't tell newbies to >>>>> search for r'^something'. >>>> >>>> >>>> >>>> You're somehow getting mixed up in thinking that "^" is some kind of >>>> "not" operator -- it's the start of line anchor in this context. >>> >>> >>> I can't imagine where you got that idea from. >>> >>> If I change "[which Python's re is NOT]" to "[Python's re's search() is >>> not dopey]", does that help you? >>> >>> The point was made in a context where the OP appeared to be reading a >>> line at a time and parsing it, and re.compile(r'something').match() >>> would do the job; re.compile(r'^something').search() will do the job too >>> -- BECAUSE ^ means start of line anchor -- but somewhat redundantly, and >>> very inefficiently in the failing case with dopey implementations of >>> search() (which apply match() at offsets 0, 1, 2, .....). >> >> >> >> I don't see much difference. > > > and I didn't expect that you would -- like I wrote above: "Python's re's > search() is not dopey". *ahem* C:\junk>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import timeit >>> t1 = timeit.Timer('re.search("^\w"," will not work")','import re') >>> t2 = timeit.Timer('re.match("\w"," will not work")','import re') >>> t3 = timeit.Timer('obj(" will not work")','import re;obj=re.compile("^\w").s earch') >>> t4 = timeit.Timer('obj(" will not work")','import re;obj=re.compile("\w").ma tch') >>> t5 = timeit.Timer('obj(" will not work qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq")' ,'import re;obj=re.compile("^\w").search') >>> t6 = timeit.Timer('obj(" will not work qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq")' ,'import re;obj=re.compile("\w").match') >>> ["%.3f" % t.timeit() for t in t1, t2, t3, t4] ['5.510', '4.835', '1.588', '1.178'] >>> ["%.3f" % t.timeit() for t in t1, t2, t3, t4] ['5.512', '4.808', '1.584', '1.170'] Observation: factoring out the compile step makes the difference much more apparent. >>> ["%.3f" % t.timeit() for t in t3, t4, t5, t6] ['1.578', '1.175', '2.283', '1.174'] >>> ["%.3f" % t.timeit() for t in t3, t4, t5, t6] ['1.582', '1.179', '2.284', '1.172'] >>> Conclusion: search time depends on length of searched string. Meta-conclusion: Either I have to retract my based-on-hope-rather-than-on-experimentation assertion, or redefine "not dopey" to mean "surely nobody would search for ^x when match x would do, so it would be dopey to optimise re for that" :-) So, back to the original point: If re.match("something") does the job you want, don't use re.search("^something") instead. From aahz at pythoncraft.com Thu Aug 11 10:21:21 2005 From: aahz at pythoncraft.com (Aahz) Date: 11 Aug 2005 07:21:21 -0700 Subject: Pre-PEP Proposal: Codetags References: <42FAF489.3010306@v.loewis.de> Message-ID: In article <42FAF489.3010306 at v.loewis.de>, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= wrote: >Micah Elliott wrote: >> >> I also have this living as a wiki >> if people would like to add comments there. I might try to capture there >> feedback from this group anyway. First try at a PEP -- thanks for any >> feedback! > >I think you somewhat misunderstood the purpose of the PEP process. >This is meant primarily for enhancements to Python (the language >and its library), and it is meant to save the PEP author from >implementing unagreeable functionality - if the PEP is accepted, >the PEP author is typically expected to implement the proposed >functionality (in many cases, having a draft implementation is >prerequisite to accepting it). > >Both elements seem to be missing your document: it does not propose >changes to the Python language; instead, it proposes a specific >way of writing comments (ie. something that is not relevant to the >Python interpreter or libraries, only to the Python developer). >Also, there is no indication that you would like to implement >something for the PEP: what tool would you like to change in what >specific way? However, it's also true that there are plenty of informational PEPs, most notably PEP 8 (Python style guide). OTOH, it is also generally the case that such PEPs codify existing practice rather than attempting to create new practices (PEP 6 being a notable counter-example). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From no at spam Fri Aug 5 15:19:50 2005 From: no at spam (D H) Date: Fri, 05 Aug 2005 14:19:50 -0500 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> Message-ID: I would highly recommend user-mode linux (UML) hosting, like bytemark or Linode: http://user-mode-linux.sourceforge.net/uses.html Starting around the same price as average shared hosting, you get your own virtual linux box (i recommend debian), on which you can install java, mod_python, php, mono, jabber, or whatever you need. You are no longer subject to the whims of the hosting provider, with respect to things like which version of PHP they support, or how many mysql databases you can create. From jdhunter at ace.bsd.uchicago.edu Mon Aug 22 21:29:51 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 22 Aug 2005 20:29:51 -0500 Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124702804.589011.257970@o13g2000cwo.googlegroups.com> Message-ID: <87fyt1mods.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "Robert" == Robert Kern writes: Robert> Greg McIntyre wrote: >> The 2nd option has real potential for me. Although the total >> amount of code is greater, it factors out some complexity away >> from the actual job, so that code is not obscured by >> unnecessary compexity. IMHO that's great practice. Robert> Please quote the message you are replying to. We have no Robert> idea what "the 2nd option" is. I think he means the second option you presented If you must read one character at a time, def reader(fileobj, blocksize=1): """Return an iterator that reads blocks of a given size from a file object until EOF. ...snip With a decent threaded news/mail reader, the thread provides sufficient context, no? JDH From tiissa at nonfree.fr Sat Aug 13 13:46:00 2005 From: tiissa at nonfree.fr (tiissa) Date: Sat, 13 Aug 2005 19:46:00 +0200 Subject: how to append semicolon to a variable In-Reply-To: <11fs9tn73j02298@corp.supernews.com> References: <1123946072.577232.218530@o13g2000cwo.googlegroups.com> <11fs9tn73j02298@corp.supernews.com> Message-ID: <42fe31d4$0$27713$626a14ce@news.free.fr> Grant Edwards wrote: > On 2005-08-13, yaffa wrote: > >>i have the following lines of python code: >> >> couch = incident.findNextSibling('td') >> price = couch.findNextSibling('td') >> sdate = price.findNextSibling('td') >> city = sdate.findNextSibling('td') >> strUrl = addr.b.string >>currently what this ends up doing is creating something like this >> >>couch3201/01/2004newyork >> >>now what i want to do is add a semicolon after the couch, price, sdate, >>city so that i get something like this >> >>couch;32;01/01/2004;new york > > > Try this: > > s = ';'.join([couch,price,sdate,city]) > print s I'll risk myself with something like: s = ';'.join([tag.string for tag in [couch,price,sdate,city]]) Of course, from the question I wouldn't have any clue. I just like doing some guessing on problems I know nothing about. ;) >>p.s. i tried couch = couch + ';' >>and then i tried couch = couch + ";" > > both of those should have worked fine. Not really. It seems to me the OP is using BeautifulSoup (or some other SGML parser). In this case, couch and others are not strings but objects. It may also be that strUrl is their parent (but I wouldn't know, how would I?) > Perhaps you ought to read through the tutorial? That's always useful. However, the first thing is to put the minimal context in your question to help the people you want your answers from understanding your issue. I would advise you to read tutorials and documentations on the modules you're using as well as learning to ask meaningful questions[1]. [1] http://www.catb.org/~esr/faqs/smart-questions.html From grante at visi.com Tue Aug 23 10:37:00 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 23 Aug 2005 14:37:00 -0000 Subject: Doubt C and Python References: Message-ID: <11gmd4cj196se7f@corp.supernews.com> On 2005-08-23, praba kar wrote: > I want to know the link between c and python. > Some people with C background use Python instead > of programming in C.why? Because C is a dangerous, low-level language unsuitable for general-purposed application programming. I use C for: 1) Real-time, embedded stuff where memory is measured in KB rather than MB. 2) Device drivers where the other choice is assembly. -- Grant Edwards grante Yow! I will invent "TIDY at BOWL"... visi.com From dave at pythonapocrypha.com Mon Aug 8 10:33:54 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 08 Aug 2005 08:33:54 -0600 Subject: Decline and fall of scripting languages ? In-Reply-To: <7xbr4agti2.fsf@ruckus.brouhaha.com> References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123392742.576632.59400@z14g2000cwz.googlegroups.com> <7xbr4agti2.fsf@ruckus.brouhaha.com> Message-ID: <42F76D52.80909@pythonapocrypha.com> Paul Rubin wrote: > Ruby just doesn't interest me that much though (maybe I'm missing > something). I don't think you are. My impression is that if you've never used Python or Ruby, you'll generally end up liking whichever of the two you really discover first (since the common case is that you're coming from Java/C++/PHP/etc - the more mainstream languages). IIRC, the creator of Ruby got really hung up on the fact that Python was not a pure OO language, so he decided to make a new language that was (this was in the pre-metaclass, old-style class days of Python). > I was hoping for a concise explanation of what Rails does I'd say it's similar to Zope in that (1) For both, the introductory tutorials make it seem deceptively easy to use, but they hide a sometimes steep learning curve (2) For both, it's hard to find clear, concise documentation midway between introductory tutorials and reading the source code (3) For both, being frameworks, you have to commit yourself to them almost entirely and be prepared for some serious lock-in (4) Oh yeah, they're both web application frameworks :) (ROR has libraries to aid in building database-centric web applications: it includes an database ORM, a web templating language, libraries for user sessions, etc.) > and whether it's feasible to do something like it in (say) Python. I > did look at the rubyonrails.com site but there were too many marketing > buzzwords and downloadable videos for me to deal with. Yes, it's incredibly feasible. I think the Subway project is sort of heading down a similar path but using Python instead. I've tried a couple of times to use Ruby on Rails and, I have to admit, I had a tough time cutting through the hype (also, it seemed like the preferred method of learning about features was through downloading large videos). The ActiveRecord library (for handling mapping objects to the database) seems sort of powerful, but the tutorials and demo videos make a huge deal about how ROR can generate a web form by inspecting the database table metadata. (Useful? Probably. Mind-blowingly cool? Hardly.) Beyond ActiveRecord, there is some additional stuff to help you build Model-View-Controller web UIs, and then lots of the standard web app components (user sessions, security, logging, etc.). I think ROR's big selling point isn't technology-related at all: it's hype machine has helped build an active community, and it's a single framework as opposed to Python's bazillions. :) -Dave From rkern at ucsd.edu Fri Aug 19 14:20:38 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 19 Aug 2005 11:20:38 -0700 Subject: Idempotent XML processing In-Reply-To: <2f66fb64f6cf531cca8b75576548283f@scl.ameslab.gov> References: <2f66fb64f6cf531cca8b75576548283f@scl.ameslab.gov> Message-ID: Michael Ekstrand wrote: > Hello all, > > In my current project, I am working with XML data in a protocol that has > checksum/signature verification of a portion of the document. There is > an envelope with a header element, containing signature data; following > the header is a body. The signatures are computed as cryptographic > checksums of the entire Body element, including start and end tags, > exactly as it appears in the data transmission. > > Therefore, I need to extract the entire text of an element of an XML > document. I have a function that scans an XML string and does this, but > it seems like a rather clumsy way to accomplish this task. I've been > playing with xml.dom.minidom and its toxml() method, but to no avail - > the server sends me XML with empty elements as full open/close tags, > but toxml() serializes them to the XML empty element (), so > the checksum winds up not matching. > > Is there some parsing mechanism (using PyXML or any other freely usable > 3rd party library is an option) that will allow me to accomplish this? > Or am I best off sticking with my little string scanning function? Read up on XML canonicalization (abrreviated as c14n). lxml implements this, also xml.dom.ext.c14n in PyXML. You'll need to canonicalize on both ends before hashing. To paraphrase an Old Master, if you are running a cryptographic hash over a non-canonical XML string representation, then you are living in a state of sin. -- 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 rich.teer at rite-group.com Fri Aug 26 18:33:22 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Fri, 26 Aug 2005 22:33:22 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: On Fri, 26 Aug 2005, John Bokma wrote: > And workplaces. Some people have more then one computer in the house. My > partner can check her email when I had her over the computer. When I I know this is entirely inappropriate and OT, but am I th eonly person who reads that sentence with a grin? The idea of my wife checking her email while I'm "doing her" over my computer is most amusing! :-) -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From tjreedy at udel.edu Tue Aug 30 01:22:31 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Aug 2005 01:22:31 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: "Steve Holden" wrote in message news:devuln$bro$1 at sea.gmane.org... > Antoon Pardon wrote: >> So what happens if you have a module that is collecting string-index >> pair, colleted from various other parts. In one part you >> want to select the last letter, so you pythonically choose -1 as >> index. In an other part you get a result of find and are happy >> with -1 as an indictation for an invalid index. Then these >> data meet. >> > That's when debugging has to start. Mixing data of such types is > somewhat inadvisable, don't you agree? > > I suppose I can't deny that people do things like that, myself included, > but mixing data sets where -1 is variously an error flag and a valid > index is only going to lead to trouble when the combined data is used. The fact that the -1 return *has* lead to bugs in actual code is the primary reason Guido has currently decided that find and rfind should go. A careful review of current usages in the standard library revealed at least a couple bugs even there. Terry J. Reedy From esleben at gmail.com Sun Aug 7 18:41:40 2005 From: esleben at gmail.com (Jan-Ole Esleben) Date: Mon, 8 Aug 2005 00:41:40 +0200 Subject: Metaclasses and new-style classes Message-ID: <3756d9750508071541192a00e0@mail.gmail.com> Hi! I've just posted a question about metaclasses in ZOPE on the ZOPE list, and one of the replies said that metaclasses (at least "painless" metaclasses) cannot be used without new-style classes (or rather, that they don't work where you cannot explicitly use new-style classes). I haven't so far been able to find _anything_ on the subject - what is true here? TIA, Ole From spam at me.please Tue Aug 9 17:06:01 2005 From: spam at me.please (Evil Bastard) Date: Wed, 10 Aug 2005 09:06:01 +1200 Subject: python for microcontrollers In-Reply-To: <7xd5oof5qj.fsf@ruckus.brouhaha.com> References: <42f7c8d4$1@news.orcon.net.nz> <7xd5oof5qj.fsf@ruckus.brouhaha.com> Message-ID: <42f91c1c$1@news.orcon.net.nz> Paul Rubin wrote: > I don't think you want to do this. Runtime type tags and the overhead > of checking them on every operation will kill you all by themselves. > Processors like that haven't been used much as Lisp targets either, > for the same reasons. Pick a different language. On thinking about it, you might be right. Unless one implements a full dynamic OO engine, the prospect of implementing python for microcontrollers resembles the task of moving a palace's furnishings into a trailer park - you'll get a couple of things into the trailer, but will have to leave the rest outside in the mud and the rain. Maybe I should clean up my forth compiler instead, and get it ready for the prime time. -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From eric_brunel at despammed.com Wed Aug 24 12:00:34 2005 From: eric_brunel at despammed.com (Eric Brunel) Date: Wed, 24 Aug 2005 18:00:34 +0200 Subject: tkraise oddity References: <1124891827.619166.90690@g49g2000cwa.googlegroups.com> Message-ID: On 24 Aug 2005 06:57:07 -0700, twd wrote: > I'm seeing some new and unexpected behaviour with tkinter + python2.4, > in a gnome+linux environment. The code below used to work (and > continues to work under windows). The intended behaviour is that a > window is created the the first time the button is pushed, and then > de-iconified and brought to the top whenever the button is pushed > again. The behaviour I'm seeing is that the window is de-iconified (if > iconified) correctly, but if already present on the screen, it is not > raised. What exactly do you expect? Do you want to raise the window above all other windows *in your application*, or above *all* other windows? I doubt tk can guarantee the latter, and this seems to be confirmed by the manuel for tk's raise command; cf. http://www.tcl.tk/man/tcl8.4/TkCmd/raise.htm If you put the window with the button in front of the window with the label, and if pressing the button doesn't bring the window with the lable above the other, then it may be a bug. If it works, I guess it's just a matter of how the window managers interpret what "raising a window" means... But I'm no specialist here, so maybe someone else will confirm that. [snip] > from Tkinter import * > > t = None > > def cmd(): > global t > if t: > t.tkraise() > t.deiconify() > else: > t = Toplevel() > l = Label( t, text=".... some text goes here ..." ) > l.pack() > > b = Button(text="Raise",command=cmd) > b.pack() > b.mainloop() (BTW, did you try to put the deiconify before the tkraise?) HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" From tpearce at internode.on.net Mon Aug 22 08:51:03 2005 From: tpearce at internode.on.net (m7b52000) Date: Mon, 22 Aug 2005 22:21:03 +0930 Subject: passing arguments from scale widget to function In-Reply-To: References: <430828c4$1@duster.adelaide.on.net> <4309b3f2$1@duster.adelaide.on.net> <4309bd93$1@duster.adelaide.on.net> Message-ID: <4309ca38$1@duster.adelaide.on.net> Matt Hammond wrote: >> Ahhhh. Partial success with : command = Calc. A slider will now pass >> its argument to a function without problem. My Calc function however >> is expecting 3 arguments - 1 from each slider i.e moving any of the >> 3 sliders should cause a recalculation. I am now getting the >> following error: >> TypeError: Calc() takes exactly 3 arguments (1 given) > > > I'm sure you can figure this out now! Either: > use lambda functions, as described, to call Calc with the correct > arguments > or: > write three functions (one for each slider) that call Calc with all 3 > arguments it requires > > regards > > > > Matt Have already started on the 2nd aproach. I might become a programmer yet............... From fakeaddress at nowhere.org Wed Aug 31 16:15:17 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 20:15:17 GMT Subject: Sockets: code works locally but fails over LAN In-Reply-To: <11hbcu1guovme72@corp.supernews.com> References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> <11hbcu1guovme72@corp.supernews.com> Message-ID: Grant Edwards wrote: > Peter Hansen wrote: > > >>2. I'm not at all sure that accessing the same socket object >>simultaneously from two threads is safe. > > It's OK under Unix. Having one thread handle rx and a > different one handle tx is a pretty widely used method. > > Don't know about Win32... A thread for send and one for recv is also frequently used with Winsock. Can anyone vouch for the Python wrapping? -- --Bryan From apadovan at gmail.com Thu Aug 18 02:32:15 2005 From: apadovan at gmail.com (apa) Date: 17 Aug 2005 23:32:15 -0700 Subject: online interpreter Message-ID: <1124346735.431371.170910@g43g2000cwa.googlegroups.com> Hello! Does anyone knows an online python interpreter?. A time ago a found one, but lost the url and cannot find it back anymore. Thanks in advance Alejandro From jrastrick at student.usyd.edu.au Sat Aug 13 01:21:47 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 12 Aug 2005 22:21:47 -0700 Subject: Dictionary inheritance In-Reply-To: References: Message-ID: <1123910507.449136.235490@g14g2000cwa.googlegroups.com> Talin asked: > Also, on a completely different subject: Has there been much discussion > about extending the use of the 'is' keyword to do type comparisons a la > C# (e.g. "if x is list:") ? > > -- Talin No, is already has a specific, well defined meaning - object identity. IDLE 1.1 >>> a = [1,2,3] >>> a is list False >>> b = type(a) >>> b >>> b is list True "Extending it" to mean something entirely different to what it currently means is a bad idea, and is also unnessecary - the builtin function isinstance already provides the functionaliy you're looking for: >>> isinstance(b, list) False >>> isinstance(a, list) True >>> However, use sparingly - calling isinstance unnessecarily rather than relying on polymorphism is considered pretty unpythonic, and usually reflects pretty poor OO design. From zxo102 at gmail.com Fri Aug 12 02:15:18 2005 From: zxo102 at gmail.com (zxo102) Date: 11 Aug 2005 23:15:18 -0700 Subject: list to tuple In-Reply-To: <1123824627.098676.132130@g43g2000cwa.googlegroups.com> References: <1123819543.351623.324870@f14g2000cwb.googlegroups.com> <1123824627.098676.132130@g43g2000cwa.googlegroups.com> Message-ID: <1123827318.326803.120520@z14g2000cwz.googlegroups.com> Thanks for your help. From mynews44 at yahoo.com Sun Aug 7 05:12:50 2005 From: mynews44 at yahoo.com (googleboy) Date: 7 Aug 2005 02:12:50 -0700 Subject: Some newbie cgi form questions... Message-ID: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> Hi there. I am having a bit of a play with teh cgi module, trying to figure out how to process a web form. I have come a little ways from reading up variou sexamples and tutes that I've found on the net, but they all leave me with a couple of questions: My code below has an attempt at validation that doesn't seem to do anything. I am expecting that it will report an error if all the fields haven't been filled in. Instead, it seems to just ignore an empty field and carry on. The second for loop is an attempt at trying to print all the values that were entered on the for without presenting the hidden values. I'd really like to do this, but I can't seem to figure out how to make a special case for hidden form values, nor can I find an example of how to do it in any of the many python cgi pages I've visited so far. If I removed the "if not type=hidden" and fix the indentation this works pretty much as I expect. TIA Googleboy print 'Content-type: text/html\n\n' print htmlheader for key in form.keys(): if not form.has_key(key): print "

ERROR!


" print "Please go back and fill in all fields. All fields are required.
" break print "You entered the following:
" for key in form.keys(): if not type="hidden": print form[key].value + '

' print '
' + timestamp print '

' print '' From greg at puyo.cjb.net Fri Aug 19 01:21:53 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 18 Aug 2005 22:21:53 -0700 Subject: while c = f.read(1) Message-ID: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> I have a Python snippet: f = open("blah.txt", "r") while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit spaghetti. This is what I would ideally like: f = open("blah.txt", "r") while c = f.read(1): # ... work on c But I get a syntax error. while c = f.read(1): ^ SyntaxError: invalid syntax And read() doesn't work that way anyway because it returns '' on EOF and '' != False. If I try: f = open("blah.txt", "r") while (c = f.read(1)) != '': # ... work on c I get a syntax error also. :( Is this related to Python's expression vs. statement syntactic separation? How can I be write this code more nicely? Thanks From rkern at ucsd.edu Thu Aug 18 00:45:12 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 17 Aug 2005 21:45:12 -0700 Subject: GUI tookit for science and education In-Reply-To: <87pssblwas.fsf@peds-pc311.bsd.uchicago.edu> References: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> <87pssblwas.fsf@peds-pc311.bsd.uchicago.edu> Message-ID: John Hunter wrote: >>>>>>"Robert" == Robert Kern writes: > > > Robert> H = U*D*V.T > > Robert> then I'm more than happy with that tradeoff. The small > Robert> syntactic conveniences MATLAB provides are dwarfed by the > Robert> intrinsic power of Python. > > Of course, U*D*V (transpose omitted for clarity) is the classic > problem for an interpreted language: the creation of temporaries. > weave allows you, via blitz, to do chained matrix/matrix operations > without multiple passes through the loop and w/o temporaries by > run-time compilation and linking of extension code. Perhap's the OP's > reference to JIT is referring to a just in time compilation mechanism > in matlab, similar to weave's. They've already discovered LAPACK and > FFTW; it wouldn't be surprising if they solved blitzm (blitz in > matlab), antialiasing, alpha transparency and multiple colormaps per > figure in upcoming releases. I don't think so, although it is incredibly, ridiculously difficult to find information about what the JIT actually *does*. The best my Google-fu can do is this: http://www.mathworks.com/access/helpdesk_r13/help/techdoc/matlab_prog/ch7_per6.html#773530 It looks like they're primarily improving simple for loops and doing arithmetic with emitted machine code in order to speed up those operations that simply can't be "vectorized." They *might* be doing something smart with array expressions wrt temporaries, but they don't say. google("MATLAB JIT temporaries") gives nothing interesting. -- 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 thomas at thomas-lotze.de Mon Aug 1 19:39:14 2005 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Tue, 02 Aug 2005 01:39:14 +0200 Subject: Using gnu readline in my own python program? References: <1122938196.818416.234960@g44g2000cwa.googlegroups.com> Message-ID: sboyle55 wrote: > Hi...I'm a newbie to python, and very confused. I'm writing a simple > program and want the user to be able to edit a line that I display using > the full gnu readline capabilitites. (For example, control+a to go to the > beginning of the line.) > > Then I want to be able to read the line after it's been edited... Probably the built-in function raw_input already does what you want. It uses readline if available. -- Thomas From dek at bosshog.lbl.gov Mon Aug 15 10:47:28 2005 From: dek at bosshog.lbl.gov (David E. Konerding DSD staff) Date: Mon, 15 Aug 2005 14:47:28 +0000 (UTC) Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <1124090875.292874.199610@o13g2000cwo.googlegroups.com> Message-ID: In article , Ben Finney wrote: > Brian Victor wrote: >> jbperez808 at yahoo.com wrote: >> > Torsten Bronger wrote: >> >> I've been having a closer look at wxPython which is not Pythonic at >> >> all and bad documented. Probably I'll use it nevertheless. >> > Aye. Couldn't agree more. >> >> You know, whenever someone mentions wxPython being badly documented, >> I have to wonder whether they know about the nearly 2000 page PDF of >> wxWidgets documentation, which is available in html at >> http://www.wxwidgets.org/manuals/2.6.1/wx_contents.html > > All of which is oriented toward C++ programmers, with all the language > assumptions inherent to that. Actually, the real problem with the wxWidgets documentation is that it doesn't tell you *how* to do things. It does only a barely adequate job as an API reference, but what it lacks is an extensive howto. I waste too much of my time dinking around deep in wxPython demos trying to figure out what is the 'right way' to do things. See: http://www.async.com .br/faq/pygtk/index.py?req=index for an example of what's needed. The wxPython Wiki is poorly organized (like nearly all wikis). It's mandatory reading (all of it) but mainly because it's not obvious where important hints are hidden. Dave From gene.tani at gmail.com Tue Aug 30 10:38:03 2005 From: gene.tani at gmail.com (gene tani) Date: 30 Aug 2005 07:38:03 -0700 Subject: array of arrays question In-Reply-To: <1125400412.844590.258780@g14g2000cwa.googlegroups.com> References: <1125392269.199866.64910@f14g2000cwb.googlegroups.com> <7xd5nvokjt.fsf@ruckus.brouhaha.com> <1125400412.844590.258780@g14g2000cwa.googlegroups.com> Message-ID: <1125412683.586406.25480@g43g2000cwa.googlegroups.com> I think this is addressed somewhere in a python Gotchas list. These lists're huge, but if you scan thru these every once in a while, they're big timesavers: http://www.ferg.org/projects/python_gotchas.html http://zephyrfalcon.org/labs/python_pitfalls.html http://zephyrfalcon.org/labs/beginners_mistakes.html http://www.python.org/doc/faq/ http://diveintopython.org/appendix/abstracts.html http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html http://www.norvig.com/python-iaq.html http://www.faqts.com/knowledge_base/index.phtml/fid/245 http://amk.ca/python/writing/warts Meo wrote: > yes, > > thank you for your help From mscottschilling at hotmail.com Tue Aug 23 10:13:32 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 23 Aug 2005 14:13:32 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> Message-ID: "l v" wrote in message news:1124804082_1011 at spool6-east.superfeed.net... > Xah Lee wrote: >> (circa 1996), and email should be text only (anti-MIME, circa 1995), > > I think e-mail should be text only. I have both my email and news readers > set to display in plain text only. It prevents the marketeers and > spammers from obtaining feedback that my email address is valid. A > surprising amount of information can be obtained from your computer by > allowing HTML and all of it's baggage when executing on your computer. > Phishing comes to my mind first and it works because people click the link > without looking to see where the link really takes them. A formatting-only subset of HTML would be useful for both e-mail and Usenet posts. From fredrik at pythonware.com Wed Aug 31 09:22:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 15:22:07 +0200 Subject: Bicycle Repair Man usability References: <1125439673.688666.264820@z14g2000cwz.googlegroups.com> <1125492760.029184.311500@g47g2000cwa.googlegroups.com> Message-ID: Kay Schluehr wrote: > Instead of writing f(g(h(...))) it is sometimes adaequate to write > > x = h(...) > f(g(x)) > > I use this a lot in particular in C++. Optimzing compilers eliminate > runtime penalties. This is of course different in CPython. if "x" is a local variable, the penality isn't that huge: $ timeit "id(len(str(0)))" 1000000 loops, best of 3: 0.911 usec per loop $ timeit "x = str(0); id(len(x))" 1000000 loops, best of 3: 0.968 usec per loop globals are slower: $ timeit -s "global x" "x = str(0); id(len(x))" 1000000 loops, best of 3: 1.26 usec per loop From hinge.media at gmail.com Mon Aug 22 11:01:03 2005 From: hinge.media at gmail.com (spiglitz) Date: 22 Aug 2005 08:01:03 -0700 Subject: 60 GB IPOD deal found Message-ID: <1124722863.319219.315290@o13g2000cwo.googlegroups.com> I just completed this offer for a 60 gb photo ipod and it is awesome! My friend got one from it and he is waving it in my face and taunting me! Anyways, all you have to do is complete a promotion offer and cancel it before the 30 days trial is up and then get 8 referrals. It is so cool. Check it out. http://www.freephotoiPods.com/?r=21360900 From sybrenUSE at YOURthirdtower.com.imagination Tue Aug 30 10:12:03 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Tue, 30 Aug 2005 16:12:03 +0200 Subject: reg email packages work References: <20050829073514.12323.qmail@web8405.mail.in.yahoo.com> Message-ID: Steve Holden enlightened us with: > It's obvious you aren't using that EXACT code, because it doesn't > formulate a three-paragraph message. So the bit we really need to > see is how you capture and formulate the argument to set_payload(). I'd rather see what I asked for, which is the output of msg.as_string(). That contains all that's sent to the client. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From benji at benjiyork.com Wed Aug 24 08:03:34 2005 From: benji at benjiyork.com (Benji York) Date: Wed, 24 Aug 2005 08:03:34 -0400 Subject: Logging all activity on a tty/pty? In-Reply-To: References: Message-ID: <430C6216.9050108@benjiyork.com> Dan Stromberg wrote: > Is there a way, using python, to (voluntarily) log all activity in a > given shell, in a way that should work on pretty much all *ix's with a > port of python? If it's just a simple transcript you're wanting see "man script". -- Benji York From adsheehan at eircom.net Mon Aug 29 12:32:00 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 29 Aug 2005 09:32:00 -0700 Subject: GIL, threads and scheduling - performance cost In-Reply-To: <4313367d$0$1830$626a14ce@news.free.fr> References: <1125329306.425235.210840@f14g2000cwb.googlegroups.com> <4313367d$0$1830$626a14ce@news.free.fr> Message-ID: <1125333120.069180.293360@g44g2000cwa.googlegroups.com> Merci Pierre, Yes I agree and plan to move more to C/C++ and releasing the GIL when entering C/C++. I also need to understand my original question re GIL and rescheduling. I fear that lock/unlock too often is also causing delays due to context switching. BTW do you have any hints/comments on SWIG/BOOST etc to glue PY and C/C++ ? Alan From peter at engcorp.com Mon Aug 22 11:14:01 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 11:14:01 -0400 Subject: Sandboxes In-Reply-To: References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: 42 wrote: > But for what its worth, I *am* curious what sorts of holes persist. I > did try googling the archives, but with no idea what I'm looking for -- > python security brings up a mess of unrelated issues... Python in > Apache, rexec/bastion stuff, xss, issues with infinite loops and many > other 'security' issues that might be relevant to someone running python > on a web server where you have to be concerned about DOS but not of any > concern to me... and so on and so forth. > > Can you, or someone, at least give me a few keywords I should be looking > for that will bring matches for the sorts of attachs you've hinted at? "security" plus just about anything involved, such as rexec, bastion, eval, and exec, appear to bring forth reams of relevant info. Try sorting by date instead of Google's questionable "relevance" to make sure you're getting some of the more recent discussions too. -Peter From chandra.bangalore at gmail.com Wed Aug 24 07:11:54 2005 From: chandra.bangalore at gmail.com (chand) Date: 24 Aug 2005 04:11:54 -0700 Subject: Warning when doubly linked list is defined gloablly Message-ID: <1124881914.018491.315800@g14g2000cwa.googlegroups.com> Hi., In my api.py file 'g_opt_list' is defined globally g_opt_list =[[],[],[],[],[],[],[]] I am using this global list in the fucntion def function (): gloabl g_opt_list when I run the py file, I am getting the Following Error SyntaxWarning: name 'g_opt_list' is used prior to global declaration Please let me know how to remove this error --BestRegars., --Chandra From jsfrank.chen at msa.hinet.net Wed Aug 10 10:11:29 2005 From: jsfrank.chen at msa.hinet.net (Thomas Moore) Date: Wed, 10 Aug 2005 22:11:29 +0800 Subject: PyOpenGL References: <1123682107.891810.321960@o13g2000cwo.googlegroups.com> Message-ID: <001b01c59db5$6ac3b7a0$2c8cfea9@Thomas> > Hey I'm a programmer looking to port some of my opengl ...although > limited into a python app I've made... I'd like to know where to find > any python/opengl source or a tutorial etc.. whatever I'd like to get a > series of points that represent a 3d slope presented to the user. Try wxPython. From qqqwerty49 at sp.st Wed Aug 24 09:52:51 2005 From: qqqwerty49 at sp.st (bhjqsbgdhj) Date: Wed, 24 Aug 2005 15:52:51 +0200 Subject: No subject Message-ID: <430c7bb1$0$17225$8fcfb975@news.wanadoo.fr> From vivek7006 at gmail.com Tue Aug 16 18:03:20 2005 From: vivek7006 at gmail.com (vivek7006 at gmail.com) Date: 16 Aug 2005 15:03:20 -0700 Subject: random seed In-Reply-To: <430244d1$0$14955$626a14ce@news.free.fr> References: <1124215843.369517.197900@z14g2000cwz.googlegroups.com> <430244d1$0$14955$626a14ce@news.free.fr> Message-ID: <1124229800.788839.66510@o13g2000cwo.googlegroups.com> Thanks. I guess I will use the system time and pass it as seed explicitly. My goal is to replicate the random numbers that I generate to ensure repeatabilty in the regression test suite that I am trying to write. From zen19725 at zen.co.uk Wed Aug 10 12:02:47 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 10 Aug 2005 17:02:47 +0100 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: On 10 Aug 2005 08:53:15 -0700, Qopit wrote: >Hi there, > >I'm pretty new to Python and am trying to figure out how to get "will >this code compile?"-like code checking. Why not just find out, by trying to compile it? :-) -- Email: zen19725 at zen dot co dot uk From rowen at cesmail.net Tue Aug 23 16:02:21 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Tue, 23 Aug 2005 13:02:21 -0700 Subject: How to get a unique id for bound methods? References: <43067d0e.1906448017@news.oz.net> Message-ID: In article , "Fredrik Lundh" wrote: >Russell E. Owen wrote: > >>>>The current issue is associated with Tkinter. I'm trying to create a tk >>>>callback function that calls a python "function" (any python callable >>>>entity). >>>> >>>>To do that, I have to create a name for tk that is unique to my python >>>>"function". A hash-like name would be perfect, meaning a name that is >>>>always the same for a particular python "function" and always different >>>>for a different python "function". That would save a lot of housekeeping. > >have you tried Tkinter's built-in _register method? > >>>> import Tkinter >>>> w = Tkinter.Tk() >>>> help(w._register) >Help on method _register in module Tkinter: > >_register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk >instance > Return a newly created Tcl function. If this > function is called, the Python function FUNC will > be executed. An optional function SUBST can > be given which will be executed before FUNC. Thanks. That looks like just the thing. I think I had seen it but was deterred by the leading underscore (suggesting an internal method whose interface might change). Still, I guess if it gets modified I can just change my code. -- Russell From simon.brunning at gmail.com Fri Aug 12 10:52:47 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Fri, 12 Aug 2005 15:52:47 +0100 Subject: Text/IDE Python Editor? In-Reply-To: References: Message-ID: <8c7f10c6050812075227d9856a@mail.gmail.com> On 8/12/05, djanvk at gmail..com wrote: > Any recommendations on a editior/IDE for programming in python? http://wiki.python.org/moin/PythonEditors -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From zen19725 at zen.co.uk Wed Aug 3 10:52:02 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 15:52:02 +0100 Subject: Art of Unit Testing References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: On Wed, 03 Aug 2005 09:51:49 -0400, Peter Hansen wrote: >phil hunt wrote: >> On Tue, 02 Aug 2005 21:26:28 +0200, Christoph Zwerschke wrote: >>>According to the "extreme programming" paradigm, testing should be done >>>several times a day. So a requirement for extreme programm is that tests >>>are fast enough. If the testing needs too much time, people are >>>discouraged to test often. >> >> Indeed. Running the tests should ideally take less than a few >> seconds. Any longer, and people won't use them so often. > >That's probably too general a statement to be very useful, and I don't >think it's probably helpful to a newcomer who is seeking guidance. I did say "ideally"; if the test have to take longer, so be it. >If one makes the XP-style distinction between "unit" and "acceptance" >tests, then the acceptance test *suite* should take no more than some >number of minutes. I believe ten minutes absolute max is a commonly >offered rule of thumb, but I've found even eight minutes a little too >long. Five seems to be just fine, and less if of course wonderful. I think we might be talking at cross purposes here. To me "acceptance test suite" means a test suite that has to be passed each time before a new version of the software is released to the users. I don't see that 10 minutes is a sensible limit here, unless you are releasing more often that once a day. (I once had an acceptance test suite that ran for 12 hours; I used to run it nightly). >If you're doing >test-driven development (TDD), you will want to be able to run unit >tests (though maybe not all of them) sometimes a couple of times per >minute! That's what I often do. >Still, in a large project (and especially one written in Python, with >the overhead of interpreter startup and the cost of executing bytecode) >the suite can get fairly long if you have many hundreds of tests. I'm currently running one with 227 assertions in 38 test functions. It runs in <1 second on an AMD 3000+. -- Email: zen19725 at zen dot co dot uk From sjmachin at lexicon.net Sat Aug 6 09:46:05 2005 From: sjmachin at lexicon.net (John Machin) Date: Sat, 06 Aug 2005 23:46:05 +1000 Subject: Syntax error after upgrading to Python 2.4 In-Reply-To: <1123323206.151000.309140@g49g2000cwa.googlegroups.com> References: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> <1123323206.151000.309140@g49g2000cwa.googlegroups.com> Message-ID: <42f4bf1b$1@news.eftel.com> Fernando wrote: >>I don't see the problem yet. I certainly do not see anything that should >>have been affected by the upgrade (was it from 2.3 on XP also?) > > > Yes. > > >>After checking for nonprinting chars, I would shuffle the param-default >>lines to try to determine which is really at fault. Good luck, or wait for >>a more helpful response. > > > I reinstalled version 2.3.5 You didn't need to remove it in the first place. > and everything works fine now. It's > definately something related to the latest version. Oh? Did you check for nonprinting chars, as advised? > > > This is one of the main resons I finally gave up using Python Huh? You're still here, still using it, ... > and > switched to Smalltalk. You can't concentrate on your work while someone > is permanently introducing changes to your tool. Well stick with Python 2.3.5 then!! > > Constantly adding new features to a language might be fun, but it > substantially increases the odds of adding bugs and misfeatures, such > as whatever was causing problems with my code or the 'perlish' syntax > for decorators. > Or switch to (e.g.) Sather; no funsters adding bugs & misfeatures to that sucker :-) > > Feeling much better now. :-) > I hope so ... From seberino at spawar.navy.mil Sat Aug 6 00:31:02 2005 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 5 Aug 2005 21:31:02 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <1123302662.011700.260260@g49g2000cwa.googlegroups.com> I appreciate your comments. You give reasons why you think 'global' is a good idea. Are you sure that 'global' is widely assumed to mean global to a *file* in proper CS theory? Coming from C....I assumed 'global' meant global to ENTIRE EXECUTABLE!?!? You even admitted you also thought 'global' was confusing in past! So how can you say you think CS community in general won't have any problem like we BOTH did???? Chris From rafi at free.fr Tue Aug 23 17:09:31 2005 From: rafi at free.fr (rafi) Date: Tue, 23 Aug 2005 23:09:31 +0200 Subject: how to deal with space between numbers In-Reply-To: <430b6215$0$29696$636a15ce@news.free.fr> References: <430b6215$0$29696$636a15ce@news.free.fr> Message-ID: <430b9082$0$24693$636a15ce@news.free.fr> bruno modulix wrote: > Mohammed Altaj wrote: > >>Dear All >> >>This is my problem again , > > (snip) > Read my answers to your two previous posts. > (in short : use str.split() - but *do* read my answers if you want to > save you a lot of pain) especially when several persons replied to you... -- rafi "Imagination is more important than knowledge." (Albert Einstein) From marcus.obrien at cyantechnology.com Fri Aug 5 11:56:49 2005 From: marcus.obrien at cyantechnology.com (marcus.obrien at cyantechnology.com) Date: 5 Aug 2005 08:56:49 -0700 Subject: Do I need to have site.py available or not ? Message-ID: <1123257409.099201.114960@g49g2000cwa.googlegroups.com> Hi, on startup my embedded python comes up with "import site failed use -v". Later python crashes on Pyrun_file(). This is the first time I have used python and I would like to know does it require site.py to be read in, and has anyone got an idea how to pass in the -v without using the python -v command, ie the embedded way. Thanks very much. Marcus. From rkern at ucsd.edu Tue Aug 16 18:14:13 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 16 Aug 2005 15:14:13 -0700 Subject: random seed In-Reply-To: <1124229800.788839.66510@o13g2000cwo.googlegroups.com> References: <1124215843.369517.197900@z14g2000cwz.googlegroups.com> <430244d1$0$14955$626a14ce@news.free.fr> <1124229800.788839.66510@o13g2000cwo.googlegroups.com> Message-ID: vivek7006 at gmail.com wrote: > Thanks. I guess I will use the system time and pass it as seed > explicitly. My goal is to replicate the random numbers that I generate > to ensure repeatabilty in the regression test suite that I am trying > to write. In that case you should just pick a single seed yourself instead of getting it from system time. random.seed(1234567890) is traditional and works just fine. Other favorites: 3141592653589793 2718281828459045 -- 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 andymac at bullseye.apana.org.au Wed Aug 10 17:52:29 2005 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 11 Aug 2005 08:52:29 +1100 Subject: FTP over SSL (explicit encryption) In-Reply-To: References: Message-ID: <42FA771D.6050408@bullseye.apana.org.au> David Isaac wrote: > I am looking for a pure Python secure ftp solution. > Does it exist? I recall coming across an extension package (pretty sure it wasn't pure Python anyway, certainly not for the SSL bits) with SFTP - I think the name was Paramiko or something like that. ------------------------------------------------------------------------- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From pwatson at redlinepy.com Thu Aug 4 10:07:35 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Thu, 04 Aug 2005 09:07:35 -0500 Subject: Fail codecs.lookup() on 'mbcs' and 'tactis' Message-ID: <3lelp7F12526dU1@individual.net> $ python Python 2.4.1 (#1, May 16 2005, 15:19:29) [GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import codecs >>> codecs.lookup('ascii') (, , , ) >>> codecs.lookup('mbcs') Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/encodings/__init__.py", line 96, in search_function globals(), locals(), _import_tail) File "/usr/lib/python2.4/encodings/mbcs.py", line 14, in ? class Codec(codecs.Codec): File "/usr/lib/python2.4/encodings/mbcs.py", line 18, in Codec encode = codecs.mbcs_encode AttributeError: 'module' object has no attribute 'mbcs_encode' >>> codecs.lookup('tactis') Traceback (most recent call last): File "", line 1, in ? LookupError: unknown encoding: tactis From scorrie at nildram.co.uk Tue Aug 9 10:41:27 2005 From: scorrie at nildram.co.uk (Stuart Corrie) Date: Tue, 09 Aug 2005 15:41:27 +0100 Subject: Python-Excel: How to paste selected cells (range) to different location on the same sheet in Excel In-Reply-To: <1123134704.795764.94110@g43g2000cwa.googlegroups.com> References: <1123133763.524077.205640@f14g2000cwb.googlegroups.com> <1123134704.795764.94110@g43g2000cwa.googlegroups.com> Message-ID: Did you use the excel macro recorder and look at the results to help you write that program? It seems to bear all the hallmarks of code generated that way. The macro recorder can be great, but almost always it is possible to speed up code by altering it afterwards, to condense and speed up the VBA code. A slightly tighter version of your code is shown below: import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Visible=1 wb = xl.Workbooks.Add( ) sh=wb.Worksheets(1) sh.Cells(1,1).Value = "Hello World!" sh.Cells(3,3).Value = "Hello World!" sh.Range(sh.Cells(1,1),sh.Cells(3,3)).Copy(sh.Cells(4,1)) sh.Range(sh.Cells(4,1),sh.Cells(6,3)).Select() The first 7 lines are identical to yours. The way you work with excel in when entering data and formulae interactively, and so the way the macro recorder must work, involves lots of selection (or activation for switching workbooks) which can be slow and often not required when using code to manipulate excel's objects through COM from an external language or VBA in excel. Line 7 in your program "sh.Range(sh.Cells(1,1),sh.Cell?s(3,3)).Select()" actually does nothing because the range is specified again in line 8. The copy method of a range object can take a parameter for a paste destination. The macro recorder will never generate code like this because it must record the selection between the copy and the paste operations. The only minor drawback of the revised line 7 is that the range selected after the paste operation is the parameter given to copy not the data pasted, if this is required, line 8 fixes this. From tony_ha2002 at yahoo.co.uk Thu Aug 18 05:49:06 2005 From: tony_ha2002 at yahoo.co.uk (TonyHa) Date: 18 Aug 2005 02:49:06 -0700 Subject: PyPE 2.1 run problem In-Reply-To: <_HCMe.39$ea.3751@ns2.gip.net> References: <_HCMe.39$ea.3751@ns2.gip.net> Message-ID: <1124358546.523320.58590@g14g2000cwa.googlegroups.com> tony.ha at philips.com wrote: > Hello, > > I have downloaded the PyPE2.1-win-unicode.zip, after unzip it with winzip > into PyPE2.1-win-unicode dierctory on window XP. I try to run "pype.exe" > by double > click on it, but nothing has happen, then when I run it with "run as..." > using the right click button. > I have the following Message in the pype.exe.log > > Traceback (most recent call last): > File "pype.py", line 30, in ? > File "configuration.pyc", line 129, in ? > WindowsError: [Errno 267] The directory name is invalid: > 'E:\\Downloads\\Python\\PyPE\\PyPE2.1-win-unicode\\library.zip/*.*' > > I also copy the "PyPE2.1-win-unicode" directory into > "C:\Python24\Lib\site-packages" and run it, but it behaves the same !! > > Then I downloaded the source code and unzip it into "PyPe2.1-src", and run > "python pype.py" in a command window. > The progroam detected I have an older version of wxPython 2.5.5 and askes > me do I want to download the newer version > 2.6.1. Which I did. > > After downlowd the wxPython 2.6.1 (win-unicode" version). I installed it > into Python 2.4.1, then re-run PyPE. > i.e re-issue "python pype.py" in a command window." I have the following > traceback Error message: > > [ Wed Aug 17 09:32:32 2005 ] Loading history from C:\Documents and > Settings\gbr02333\.pype\history.txt > > Traceback (most recent call last): > > File "pype.py", line 3926, in ? > > main() > > File "pype.py", line 3916, in main > > filehistory.root = root = app.frame = MainWindow(None, -1, "PyPE", > sys.argv[1+opn:]) > > File "pype.py", line 438, in __init__ > > self.loadHistory() > > File "pype.py", line 1152, in loadHistory > > self.config[nam][k] = dict(v) > > TypeError: iteration over non-sequence > > > I wonder does anyone using PyPE2.1 on Windown XP SP2 and have the same > problem? Can any one help > with the problem? Thanks in advance ! > > Tony Ha. I have the following reply from the creator of PyPE (Josiah Carlson). The solution for running PyPE2.1 from the source is: "replacing line 1152 with the following 4 lines: if isinstance(v, dict): self.config[nam][k] = dict(v) else: self.config[nam][k] = v " Once I done the replacement as suggested above, PyPE2.1 can run from the source now. Thanks Josiah ! From rrr at ronadam.com Mon Aug 1 16:00:30 2005 From: rrr at ronadam.com (Ron Adam) Date: Mon, 01 Aug 2005 20:00:30 GMT Subject: [path-PEP] Path inherits from basestring again In-Reply-To: References: Message-ID: Ivan Van Laningham wrote: >>People can subclass Path and add it if they really want it. They can use >>Jason's original module. My position is that the PEP without this use of >>__div__ is (a) better as a standard module, and (b) improves the chance of >>the PEP being accepted. >> > > > I disagree. Using __div__ to mean path concatenation is no worse than > using __add__ to mean string concatenation, .... But '+' doesn't mean string concatenation, it means (calls the __add__ method) which when used with objects other than numeric types is usually an object join method. It only means string concatenation when used with string objects. In this case a path object is a string object that behaves somewhat like a list and somewhat like a string depending on how it's being accessed. Maybe a string class isn't the best way to store a path. It seems to me a list with string elements would work better. I'm not sure why it was ruled out. Maybe someone could clarify that for me. I think it's a mistake to define '+' literally to mean string concatenation. I believe the '/' will be considered a wart by many and a boon by others. If I'm right, there will be endless discussions over it if it's implemented. I'd rather not see that, so I'm still -1 concerning '/' for that reason among others. Cheers, Ron PS. Could someone repost the links to the current pre-pep and the most recent module version so I can look at it closer look? From pd at traxon.com Thu Aug 18 03:29:57 2005 From: pd at traxon.com (Paul Dale) Date: Thu, 18 Aug 2005 09:29:57 +0200 Subject: up to date books? In-Reply-To: References: Message-ID: <430438F5.5000801@traxon.com> I highly recommend the "Safari" library service from Oreilly ( http://safari.oreilly.com ) you can check out all of the books listed below and about 10,000 more. The library contains much more than just Oreilly's books, but they are, of course, all in there. The first 2 weeks is free after that it's $20/month. You can check out 10 books at a time and you have to keep them for a month. You can download chapters, print pages, and search all the books in the library, as well as search across books you've checked out. It's a great way to get access to a broad range of technical books. One thing to be careful of. As the old books are there too it's possible to grab a first version when you might want a second or third version. Always list by date and make sure you're looking at the new stuff. Cheers, Paul Adriaan Renting wrote: >I learned Python from the "Learning Python" book that's first on Alessandros list. If you have the Second Edition, that includes coverage for Python 2.3, I think you have quite a nice introductory book. >As a reference book "Python in a Nutshell" and of course the Python documentation itself are quite good. > >Adriaan > > > > >>>>Alessandro Bottoni 08/18/05 9:02 am >>> >>>> >>>> >John Salerno wrote: > > > >>hi all. are there any recommendations for an intro book to python that >>is up-to-date for the latest version? >> >> > >I do not know how much up-to-date they are but I have to suggest you these >books: > >- Learning Python >By Mark Lutz and David Ascher >published by O'Reilly >Most likely the best introductory book on Python > >- Python Cookbook >By Alex Martelli and David Ascher >published by O'Reilly >By far the most useful book on Python after your first week of real use of >this language > >Also, the fundamental >- Programming Python (the 2nd edition ONLY) >By Mark Lutz >published by O'Reilly >Is very useful for understanding the most inner details of Python > > > >>would reading a book from a year or two ago cause me to miss much? >> >> > >No. Python did not changed too much since rel. 1.5. You can still use a book >published in 2001 as a introductory book (as I do). The changes are >exhaustively described both in the official documentation and in the very >fine "what's new in..." articles written by Andrew Kuchlin for every new >release (see www.python.org). > >CU > >----------------------------------- >Alessandro Bottoni > > From sklass at pointcircle.com Thu Aug 4 10:25:51 2005 From: sklass at pointcircle.com (rh0dium) Date: 4 Aug 2005 07:25:51 -0700 Subject: Mass importing of a template based system.. Trouble with name substitutions In-Reply-To: References: <1123123110.255400.145060@g44g2000cwa.googlegroups.com> Message-ID: <1123165551.651653.243220@g44g2000cwa.googlegroups.com> Hi again, No you're right there isn't a mod.mod I want this to be evaluated from this for mod in modules: a = mod.mod() a.run() to this. for mod in modules: a = example1.example1() a.run() then for mod in modules: a = example2.example2() a.run() etc. So how is the substitution not working?? Robert Kern wrote: > rh0dium wrote: > > Hi all, > > > > Basically I have a bunch of pluggins in a directory (METDIR). For each > > one of these templated pluggins I want to do a specific routine. Let's > > start with a basic template > > > > file example1.py > > ---------------- > > class example1: > > def __init__(self): > > print "Initialize" > > def run(self): > > print "Hi from example 1" > > ---------------- > > > > file example2.py > > ---------------- > > class example2: > > def __init__(self): > > print "Initalize" > > def run(self): > > print "example 2" > > ---------------- > > > > Now I want to go through each pluggin ( example1.py and example2.py ) > > and execute run. So here is my code but it doesn't work.. > > > > > > if os.path.isdir(METDIR): > > modules = [] > > > > # Add the metrics dir toyour path.. > > sys.path.insert( 0, os.getcwd() + "/" + METDIR ) > > > > for metric in glob.glob(METDIR+"/*.py"): > > # Now lets start working on the individual metrics > > module_name, ext = os.path.splitext(os.path.basename(metric)) > > try: > > module = __import__(module_name) > > modules.append( module ) > > except ImportError , e: > > print "Failed import of %s - %s" % ( module_name, e) > > pass > > > > for mod in modules: > > a = mod.mod() > > a.run() > > > > But it doesn't work with the following.. > > > > Traceback (most recent call last): > > File "./metriX.py", line 109, in main > > a = mod.mod() > > AttributeError: 'module' object has no attribute 'mod' > > > > So it looks like it's not doing the substitution. > > Doing what substitution? Neither of the modules that you showed define a > mod() callable and nothing else seems to add one. > > -- > 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 spam.csubich+block at block.subich.spam.com Sat Aug 6 14:08:58 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Sat, 06 Aug 2005 14:08:58 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: <11f9f9u2enfsi58@news.supernews.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> Message-ID: John Roth wrote: > > "Mike Meyer" wrote in message > news:861x57wrui.fsf at bhuda.mired.org... >> >> So the only way to remove the global statement would be to have some >> way to mark the other interpretation, with say a "local" >> decleration. I thik that would be much worse than "global". For one >> thing, most variables would be local whether or not they are >> declared. Second, having an indication that you need to check module >> globals in the function is a better than not having that clue there. > > > You've got half of the answer. The other half is to have the editor/ide > translate the lexical cues into color coding and hide the lexical cues. Yes... let's make color a syntactically important feature of the language; Python can follow the massive success of colorForth. There are three principles that together mandate the use of a 'global' keyword: 1) Implicit variable definition: If all variables had to be declared ahead of time, then "var x" versus "global var x" wouldn't be an issue at all. Even though you'd still want to make the latter red and the former blue or something. Removing this from Python would also forbid things like locals()['a'] = 1, and it would also have great impact on the class syntax (namely instance variables). 2) Lexical scoping: If variable references didn't go beyond the immediate scope, then there would be no global variables and thus no need for a global keyword. Lexical scoping, though, is a fundamental feature of Python and every other block-scoping procedural language that I know of, so no-can-do there. 3) Default local scroping: Changing this, as already pointed out, would just require replacing a 'global' keyword with a 'local' one. In procedural languages that derive in spirit from Algol-likes, local variables are the far more common case than global ones, and so by Huffman/Morse principles should have the shorter syntax. (As a side note, the 'local first' assumption isn't universal; see some FORTRAN and BASICs.) Personally, I don't consider the global keyword a misfeature or even a wart; for Py3k I'd rather see more explicit namespacing (which would make it clear that namespaces end at the module-level) rather than changing even the name of the keyword. From dadapapa at gmx.net Wed Aug 17 15:55:01 2005 From: dadapapa at gmx.net (dadapapa at gmx.net) Date: 17 Aug 2005 12:55:01 -0700 Subject: Tix cannot open /usr/share/libtix Message-ID: <1124308501.145787.70210@f14g2000cwb.googlegroups.com> Hi, I have a problem getting Tix to run: Python 2.4.1 (#2, Aug 17 2005, 10:19:59) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Tix >>> t = Tix.Tk() Traceback (most recent call last): File "", line 1, in ? File "/usr/projects/EES_dev/haroldf/lib/python2.4/lib-tk/Tix.py", line 210, in __init__ self.tk.eval('package require Tix') _tkinter.TclError: couldn't load file "/usr/share/libtix8.1.8.3.so": /usr/share/libtix8.1.8.3.so: cannot open shared object file: No such file or directory >>> libtix is not in /usr/share/ but I located it in /usr/lib/ [haroldf at tlc dpd]$ locate libtix8.1.8.3.so warning: locate: warning: database /var/lib/slocate/slocate.db' is more than 8 days old /usr/lib/libtix8.1.8.3.so [haroldf at tlc dpd]$ is there any way to tell python/tkinter/tix where to look for the library? thanks, - harold - From zxo102 at gmail.com Sun Aug 14 22:40:02 2005 From: zxo102 at gmail.com (zxo102) Date: 14 Aug 2005 19:40:02 -0700 Subject: python-Excel: Chinese Characters Message-ID: <1124073601.970100.322480@o13g2000cwo.googlegroups.com> Hi there, I am trying to put data including Chinese Characters into Excel through python. But I got some problems. Here is my sample code: ################################################## # import win32com.client xlapp = win32com.client.DispatchEx("Excel.Application") xlbook = xlapp.Workbooks.Open("test.xls") sht = xlbook.Worksheets("Sheet1") # data is provided in case 1 and case 2 below ... sht.Range(sht.Cells(1, 1), sht.Cells(2,4)).Value = data # ################################################## Using the above code, I tested two cases for "data". The "data" from both two cases are same: tuple basically. But in case 1, only 2222 and 3333 are inserted into Excel. All other cells are blank. in case2, all data including Chinese Characters are inserted into Excel and everything is fine. My real data is like case 1. #case 1 ------------------------------------------ rp = {'r1':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'], 'r2':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'], 'r3':[2222,3333], 'r4':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'] } b = () for k in range(len(rp['r1'])): a = rp['r1'][k],rp['r2'][k],rp['r3'][k],rp['r4'][k] if len(b) == 0: b = a else: b = b,a data = b #case 2 ------------------------------------------ data =(('\xd6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 2222, '\xd6\xd7\xc1\xf6'), ('\xd6\xd7\xc1\xf6", '\xd6\xd7\xc1\xf6", 3333, '\xd6\xd7\xc1\xf6')) Anybody knows what is going on with it? Thanks for your help. Ouyang From schmitt at num.uni-sb.de Thu Aug 25 07:38:54 2005 From: schmitt at num.uni-sb.de (Uwe Schmitt) Date: Thu, 25 Aug 2005 13:38:54 +0200 Subject: Doubt C and Python References: Message-ID: <1124966129$mail2nntp@hades.rz.uni-saarland.de> > > On Tue, 23 Aug 2005 06:15:03 +0100, praba kar wrote: > > > Dear All, > > I want to know the link between c and python. > > Some people with C background use Python instead > > of programming in C.why? > > > > > > > > regards > > Prabahar > > > > > > > > > Just my $.02 > > I am a long time c/c++ programmer (by profession). I fell in love with > python about 2 years ago. I use python for many things now, > and I always > have said, "When it is too slow, I will write it in c++". > > I have not hit that point yet. For some reasons that are hard > to explain, > even though python "should" be slower and maybe even is sometimes, it > never is an issue. I made the same experience. The only reason I have for using C++ is number crunching. And I love boost python for building the bridge. Greetings, Uwe. From jeremy at emperorlinux.com Thu Aug 18 12:21:56 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Thu, 18 Aug 2005 12:21:56 -0400 Subject: Implementing class methods in C In-Reply-To: References: Message-ID: <1124382117.3899.19.camel@localhost.localdomain> I honestly don't know the answer to this and I am entirely guessing but--does it work without using the new module? That is: ---------------------------------------------------------------- import _test class Foo: pass foo = Foo() foo.bar = _test.func2 foo.bar() On Thu, 2005-08-18 at 12:09 -0400, nmichaud at jhu.edu wrote: > I am having a problem implementing some methods of a python class in C. > The class is defined in python, but I would like to rewrite some methods > in c. Here is an example of what I want to do: > > file _test.c: > > #include > > static PyObject * > func2(PyObject *self, PyObject *args) > { > if (self == NULL) { > PyErr_SetString(PyExc_SystemError, "self is NULL"); > return NULL; > } > > // Parse arguments > if (!PyArg_ParseTuple(args, "")) > { > return NULL; > } > > Py_INCREF(Py_None); > return Py_None; > } > > static PyMethodDef TestMethods[] = { > {"func2", func2, METH_VARARGS, "func2."}, > {NULL, NULL, 0, NULL} /* Sentinel */ > }; > > PyMODINIT_FUNC > init_test(void) > { > (void) Py_InitModule("_test", TestMethods); > } > > ---------------------------------------------------- > test.py: > > class Test: > def func1(self): > print "I am in func 1" > > import _test > import new > Test.func2 = new.instancemethod(_test.func2, None, Test) > del(new) > > t = Test() > t.func2() > > > When I run test.py, I get a SystemError exception (which is what I raise > if self is NULL). I think my confusion lies in the use of PyObject* self > in the function declaration. Shouldn't this be set to point to the > instance of class Test that I am calling it from? Am I misunderstanding > the purpose of PyObject* self? Thanks. > > Naveen > > --------------------------------------------------------------------- > Naveen Michaud-Agrawal > Program in Molecular Biophysics > Johns Hopkins University > (410) 614 4435 From nmichaud at jhu.edu Thu Aug 18 12:42:33 2005 From: nmichaud at jhu.edu (nmichaud at jhu.edu) Date: Thu, 18 Aug 2005 12:42:33 -0400 (EDT) Subject: Implementing class methods in C In-Reply-To: <1124382117.3899.19.camel@localhost.localdomain> References: <1124382117.3899.19.camel@localhost.localdomain> Message-ID: Nope, it still doesn't work. Anyway, that's not exactly what i want, since i want func2 to be accessible from all instances of Test() Naveen On Thu, 18 Aug 2005, Jeremy Moles wrote: > I honestly don't know the answer to this and I am entirely guessing > but--does it work without using the new module? That is: > > ---------------------------------------------------------------- > > import _test > > class Foo: > pass > > foo = Foo() > > foo.bar = _test.func2 > > foo.bar() > > On Thu, 2005-08-18 at 12:09 -0400, nmichaud at jhu.edu wrote: > > I am having a problem implementing some methods of a python class in C. > > The class is defined in python, but I would like to rewrite some methods > > in c. Here is an example of what I want to do: > > > > file _test.c: > > > > #include > > > > static PyObject * > > func2(PyObject *self, PyObject *args) > > { > > if (self == NULL) { > > PyErr_SetString(PyExc_SystemError, "self is NULL"); > > return NULL; > > } > > > > // Parse arguments > > if (!PyArg_ParseTuple(args, "")) > > { > > return NULL; > > } > > > > Py_INCREF(Py_None); > > return Py_None; > > } > > > > static PyMethodDef TestMethods[] = { > > {"func2", func2, METH_VARARGS, "func2."}, > > {NULL, NULL, 0, NULL} /* Sentinel */ > > }; > > > > PyMODINIT_FUNC > > init_test(void) > > { > > (void) Py_InitModule("_test", TestMethods); > > } > > > > ---------------------------------------------------- > > test.py: > > > > class Test: > > def func1(self): > > print "I am in func 1" > > > > import _test > > import new > > Test.func2 = new.instancemethod(_test.func2, None, Test) > > del(new) > > > > t = Test() > > t.func2() > > > > > > When I run test.py, I get a SystemError exception (which is what I raise > > if self is NULL). I think my confusion lies in the use of PyObject* self > > in the function declaration. Shouldn't this be set to point to the > > instance of class Test that I am calling it from? Am I misunderstanding > > the purpose of PyObject* self? Thanks. > > > > Naveen > > > > --------------------------------------------------------------------- > > Naveen Michaud-Agrawal > > Program in Molecular Biophysics > > Johns Hopkins University > > (410) 614 4435 > From mcfletch at rogers.com Mon Aug 22 11:57:31 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 22 Aug 2005 11:57:31 -0400 Subject: Decorator and Metaclasses Documentation In-Reply-To: <430980d6$0$4892$626a14ce@news.free.fr> References: <430980d6$0$4892$626a14ce@news.free.fr> Message-ID: <4309F5EB.5050201@rogers.com> bruno modulix wrote: >Mike C. Fletcher wrote: >(snip) > > >>Though the don't go into extreme detail on decorators (they are >>basically syntactic sugar for a particular type of descriptor). >> >> >> >Err... Could you elaborate on this ? Decorators are syntactic sugar for >function wrapping, while descriptors are a 'protocol' to hook into >attribute lookup, so I don't really see how one can describe the first >in terms of the second... > > There are two major types of descriptors, the elven and the dwarven. * Elven descriptors are things like property, BasicProperty, VRML97 fields, Zope Field Properties, or PEAK's mechanisms. They mediate access to an instance's attributes, (both setting and getting of values) and are used primarily for domain modeling. * Dwarven descriptors are things like staticmethod or classmethod; function-like things that tend to look like a function and quack like a function, but have some special property or functionality attached when accessed as an attribute of a class/instance (functions themselves return instance methods or class methods depending on how they are retrieved). As you'll read in the PyCon 2005 paper pointed to, the whole set basically grew out of a generalisation of what functions were already doing (conceptually). Functions are, in short, the proto-descriptor. That is, objects which control what result is returned by attribute access (e.g. an instance or unbound instance method). Many (most?) dwarven descriptors are implemented as simple wrapper functions around the base function to use the function's already-present descriptor hooks. Decorators are syntactic sugar for defining dwarven descriptors. In Python 2.2 and 2.3 a dwarven descriptor was instantiated like this: def function( cls ): """Do something simple with the class""" function = classmethod( function ) in Python 2.4+, they can be instantiated like this: @classmethod def function( cls ): """Do something simple with the class""" technically you *could* return something that's not a descriptor from the decorator (e.g. classmethod), but it's unlikely you'd do that very often. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From nid_oizo at yahoo.com_removethe_ Mon Aug 8 21:24:15 2005 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Mon, 08 Aug 2005 21:24:15 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <42f7ef3b.952697616@news.oz.net> References: <42f695f8.864310192@news.oz.net> <42f79137.928629067@news.oz.net> <42f7ef3b.952697616@news.oz.net> Message-ID: Bengt Richter wrote: > On Mon, 08 Aug 2005 16:18:50 -0400, Nicolas Fleury wrote: >>I wrote the PEP to see if was the only one that would benefit from >>generic types *before* having optional static typing in the language. >> >>It seems I'm the only one;) >> >>According to blog entry 86641, Guido himself is prototyping with >>__getitem__. However, I cannot do the same, because the framework I use >>is much more complete and keyword arguments are a must. >> > Here is a decorator object to set up function call dispatch according to type. > It only uses positional arguments, but could be fleshed out, I think. > Not tested beyond what you see ;-) That's nice. Guido also posted this multimethods solution: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 The only thing I was saying it that I can use generic types in Python right now (and I do), by using (), but I can't with what will probably be the syntax in future, i.e. using []. Regards, Nicolas From jaydonnell at gmail.com Wed Aug 31 12:36:06 2005 From: jaydonnell at gmail.com (jdonnell) Date: 31 Aug 2005 09:36:06 -0700 Subject: can't start new thread Message-ID: <1125506166.505956.144570@f14g2000cwb.googlegroups.com> I posted this about a month ago and peter asked for a stack trace. I didn't get the error again until yesterday and here is the stack trace and what I posted before. Traceback (most recent call last): File "./ab.py", line 240, in ? main() File "./ab.py", line 217, in main abThread.start() File "/usr/lib/python2.2/threading.py", line 396, in start _start_new_thread(self.__bootstrap, ()) thread.error: can't start new thread I'm at a loss on this one. I have a multithreaded script that gets 'thread.error: can't start new thread' errors randomly. I just got it right after starting the script when it was trying to create the 5th thread. Usually the script will run for a while before throwing this error, but sometimes it throws it right away. This script has worked without a problem for months, but I did make some changes recently. I don't see how those changes would cause this error though. It's also on a VPS so it's possible that they changed something in the OS. Does anyone have any suggestions about possible causes of this error? I'm using Python 2.2.3 on a custom vps version of FC1. From DRNewcomb at attglobal.NOT.net Fri Aug 12 08:11:52 2005 From: DRNewcomb at attglobal.NOT.net (Donald Newcomb) Date: Fri, 12 Aug 2005 07:11:52 -0500 Subject: NEWB: General purpose list iteration? References: <42fc13f4_4@news1.prserv.net> <1123817879.772095.6240@g44g2000cwa.googlegroups.com> Message-ID: <42fc92d1_1@news1.prserv.net> "Devan L" wrote in message news:1123817879.772095.6240 at g44g2000cwa.googlegroups.com... > This will just do_something(object) to anything that is not an > iterable. Only use it if all of your nested structures are of the same > depth. Cool! I'll try it. -- Donald Newcomb DRNewcomb (at) attglobal (dot) net From fumanchu at amor.org Wed Aug 24 00:17:17 2005 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 23 Aug 2005 21:17:17 -0700 Subject: Multiple (threaded?) connections to BaseHTTPServer Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3772830@exchange.hqamor.amorhq.net> Adam Atlas wrote: > Never mind... I've found a workable solution: > http://mail.python.org/pipermail/python-list/2001-August/062214.html > > Robert, thanks, I'll still check that out for any future projects; but > for my current purpose, it seems overkill. But I don't know for sure; > assuming BaseHTTPServer is good enough for my current needs aside from > its lack of threading, does PooledThreadedServer have any advantages > over the method I linked above? The biggest difference (and you can decide whether it's an advantage for your environment or not) is that the ThreadingMixin starts a new thread for each request, while CherryPy's PooledThreadedServer uses a thread pool. That is, you start some number of threads (say, 10) when you start the server, and those threads serve all requests as they are able. The big advantage I was secretly hoping for was that you'd read up on CherryPy and discover it already does what you want. ;) Robert Brewer System Architect Amor Ministries fumanchu at amor.org From john at castleamber.com Fri Aug 26 05:08:44 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 09:08:44 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: Chris Head wrote: > John Bokma wrote: >>>Additionally, a user interface operating inside an HTML >>>renderer can NEVER be as fast as a native-code user interface with >>>only the e-mail message itself passed through the renderer. >> >> Nowadays, more then futile. > > Sorry, I don't understand what you mean. Even on my 2.8GHz Pentium 4, > using Thunderbird to juggle messages is noticeably faster than > wandering around Hotmail. Complex HTML rendering still isn't > absolutely instantaneous. It can be made much faster. There will always be a delay since messages have to be downloaded, but with a fast connection and a good design, the delay will be very very small and the advantages are big. > It's significantly more painful when I use my 433MHz > Celeron. It simply takes a long time to jump between message, inbox, > other message, inbox, other other message, inbox, etc. ... >> This can be designed much better by using iframes, maybe even Ajax. > > Agreed. Judicious use of frames (internal or otherwise) or > Javascript-based partial reloads could seriously improve the > situation. They might also provide an easier way for Webmail providers > to implement their pages in valid HTML: if you render the entire > e-mail message alone > in a frame, you don't have to start stripping out pieces of e-mail > because they already exist (html and body elements, for example) Yup. >>>Why can't we use the Web for what it was meant for: viewing hypertext >>>pages? Why must we turn it into a wrapper around every application >>>imaginable? >> >> Because it works? > > ... and purpose-built client applications (e.g. Thunderbird) don't? if A -> B, it doesn't say that B -> A :-) I.e. that it works via HTML doesn't mean it doesn't with a dedicated client ;-). I live in Mexico, most people here rely on so called Internet cafes for their connection, and even the use of a computer. For them Thunderbird *doesn't work*. > Maybe I'm old-fashioned but I still very much prefer thick clients. > They simply feel much more solid. Perhaps part of it is that thin > clients have to communicate with the server at least a little bit for > just about everything they do, while thick clients can do a lot of > work without ANY Internet round-trip delay at all. Each has it's place. A bug in a thick client means each and everyone has to be fixed. With a thin one, just one has to be fixed :-D. > Hotmail has to talk to the server to > move a message from one mailbox to another. Thunderbird doesn't. Depends on where your mailbox resides. Isn't there something called MAPI? (I haven't used it myself, but I recall something like that). > Ergo, > Thunderbird is faster as soon as the Internet gets congested. Ah, yeah, wasn't that predicted to happen in like 2001? Also, unless you have some program that kills spam on the server, you have to download all with Thunderbird. I remember a funny day when I got 2000 messages/hour due to a virus outbreak :-( With hotmail, if you have 100 new messages you download them when you read them. Or kill them when you don't want to read. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From yxxxxlxxxxx at hotmail.com Thu Aug 11 15:47:43 2005 From: yxxxxlxxxxx at hotmail.com (yaffa) Date: Thu, 11 Aug 2005 15:47:43 -0400 Subject: Python interpreter error: unsupported operand type(s) for |: Message-ID: hey folks i get this error: Python interpreter error: unsupported operand type(s) for |: when i run this line of code: for incident in bs('tr', {'bgcolor' : '#eeeeee'} | {'bgcolor' : 'white'} ): any idea what i'm doing wrong here? thanks yaffa From not-even at dispsable.address.this.time Thu Aug 18 02:00:35 2005 From: not-even at dispsable.address.this.time (Jules Dubois) Date: Thu, 18 Aug 2005 00:00:35 -0600 Subject: As Simple As Possible? References: <1124338318.133726.304370@g49g2000cwa.googlegroups.com> Message-ID: <7677804.UTi409LUyN@knode.kde> On Wednesday 17 August 2005 22:11, jitya (<1124338318.133726.304370 at g49g2000cwa.googlegroups.com>) wrote: > Chuck Allison says: > > After three years of study, I have concluded that Python is about > as simple as a full-powered object-oriented language can get. My inner > programmer just loves it. > [snip comment and quotation] > > I know of no language to which these words apply more than Python. Smalltalk has a noticeably simpler syntax and is a "full-powered object-oriented language". It's also built on a "full-powered object-oriented platform" written in Smalltalk so virtually all the base system can be modified without changing languages. > LINK: http://www.artima.com/cppsource/simple.html Your statement, "My inner programmer just loves it", is telling. Whatever it is about certain programming languages that make better programmers more productive is mostly a personal matter. Paul Graham has written several articles about LISP and great programmers -- and I can see why. Smalltalk is or would be my first choice if everything else were equal. Python is what I actually use. From fredrik at pythonware.com Tue Aug 16 07:35:55 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 16 Aug 2005 13:35:55 +0200 Subject: Gadfly use (Newby) References: <1124190108.482249.33400@f14g2000cwb.googlegroups.com> Message-ID: "niko" wrote: > while using gadfly, got an error that i don't understand. > Code is as follow : > cursor = connection.cursor() > cursor.execute('select id_m from mots where nom_m = "%s"' % nom_m) > id_m = cursor.fetchall() > > Error message : > File "C:\Python24\Lib\site-packages\gadfly\kjParser.py", line 567, in > getmember > (Token,skip) = self.LexDict.Token(self.String, self.Position) > File "C:\Python24\Lib\site-packages\gadfly\kjParser.py", line 433, in > Token > raise LexTokenError, "Lexical token not found "+info > gadfly.kjParser.LexTokenError: Lexical token not found near :: > ' where nom_m = '*'"Ancient s Pled' > > Stored value seems to interfere with somethong ? Am i wrong ? Did i > missed something ? Thanks in advance for any help. the "%" operator does the substitution *before* the execute method is called. maybe you meant > cursor.execute('select id_m from mots where nom_m = %s', nom_m) ? From __peter__ at web.de Thu Aug 4 03:24:42 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Aug 2005 09:24:42 +0200 Subject: Python's CSV reader References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> Message-ID: Stephan wrote: > Can the CSV module be coerced to read two line formats at once or am I > better off using read and split? Yes, it can: import csv import sys reader = csv.reader(sys.stdin) while True: try: names = reader.next() values = reader.next() except StopIteration: break print dict(zip(names, values)) Python offers an elegant way to do the same using the zip() or itertools.izip() function: import csv import sys from itertools import izip reader = csv.reader(sys.stdin) for names, values in izip(reader, reader): print dict(izip(names, values)) Now let's add some minimal error checking, and we are done: import csv import sys from itertools import izip, chain def check_orphan(): raise Exception("Unexpected end of input") yield None reader = csv.reader(sys.stdin) for names, values in izip(reader, chain(reader, check_orphan())): if len(names) != len(values): if len(names) > len(values): raise Exception("More names than values") else: raise Exception("More values than names") print dict(izip(names, values)) Peter From dotpyFE at gmail.com Sat Aug 27 09:22:21 2005 From: dotpyFE at gmail.com (Lucas Raab) Date: Sat, 27 Aug 2005 13:22:21 GMT Subject: Is there any module to play mp3 or wav format files? In-Reply-To: <%JOPe.6340$UE2.3907@tornado.socal.rr.com> References: <%JOPe.6340$UE2.3907@tornado.socal.rr.com> Message-ID: el chupacabra wrote: > Is there any module to play mp3 or wav format files? > > any sample code available somewhere? > > thanks, > el chupacabra > > > --------------= Posted using GrabIt =---------------- > ------= Binary Usenet downloading made easy =--------- > -= Get GrabIt for free from http://www.shemes.com/ =- > http://pymedia.org -- -------------------------- Lucas Raab lvraab"@"earthlink.net dotpyFE"@"gmail.com AIM: Phoenix11890 MSN: dotpyfe "@" gmail.com IRC: lvraab ICQ: 324767918 Yahoo: Phoenix11890 From kyoguan at gmail.com Fri Aug 12 00:25:34 2005 From: kyoguan at gmail.com (kyo guan) Date: Fri, 12 Aug 2005 12:25:34 +0800 Subject: How to Adding Functionality to a Class by metaclass(not by inherit) Message-ID: <42fc24cd.5258bb48.52c3.3f05@mx.gmail.com> How to Adding Functionality to a Class by metaclass(not by inherit) #example: import inspect class Foo(object): def f(self): pass def g(self): pass class MetaFoo(type): def __init__(cls, name, bases, dic): super(MetaFoo, cls).__init__(name, bases, dic) for n, f in inspect.getmembers(Foo, inspect.ismethod): setattr(cls, n, f) #Bar want to achieve Foo's part/all functionality, but not by inherit class Bar(object): __metaclass__ = MetaFoo >>> b = Bar() >>> b.f() TypeError: unbound method f() must be called with Foo instance as first argument (got nothing instead) >>> Bar.f >>> b.f how can I set Bar.f as From steve at holdenweb.com Wed Aug 17 06:27:55 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Aug 2005 11:27:55 +0100 Subject: socket setdefaulttimeout In-Reply-To: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> Message-ID: Sheila King wrote: > I'm doing DNS lookups on common spam blacklists (such as SpamCop..and > others) in an email filtering script. Sometimes, because the DNS server > that is resolving the looksup can go down, it is important to make sure > that the socket doesn't just hang there waiting for a response. > > After a recent system upgrade to Python 2.4.1 (from 2.2.2) I thought I > could take advantage of the setdefaulttimeout in the socket module, to > limit the amount of time the sockets take for a lookup. > > As a test, I set the default timout ridiculously low. But it doesn't > seem to be having any effect. The sockets will take several seconds to > make the connection and complete the lookups, even though I've set the > timeout to millionths of a second, which I thought would ensure a > timeout (sample script below). > > Am I doing something wrong? Do I misunderstand something? Is what I > want to do simply not possible? > > Thanks for any tips. Example code follows signature... > > -- > Sheila King > http://www.thinkspot.net/sheila/ > > #!/usr/local/bin/python2.4 > import socket > import sys > from time import time, asctime, localtime > > socket.setdefaulttimeout(.00001) > debugfile = "socketdebug.txt" > > > def debug(data): > timestamp = str(asctime(localtime(time()))) > try: > f = open(debugfile, 'a') > f.write('\n*** %s ***\n' % timestamp) > f.write('%s\n' % data) # 24-Dec-2003 -ctm- removed one > linefeed > f.close() > except IOError: > pass > # do nothing if the file cannot be opened > > > IPaddy = '220.108.204.114' > > if IPaddy: > IPquads = IPaddy.split('.') > IPquads.reverse() > reverseIP = '.'.join(IPquads) > > bl_list = { 'bl.spamcop.net' : 'IP Address %s Rejected - see: > http://spamcop.net/bl.shtml' % IPaddy, \ > 'relays.ordb.org' : 'IP Address %s Rejected - see: > http://ordb.org/' % IPaddy, \ > 'list.dsbl.org' : 'IP Address %s Rejected - see: > http://dsbl.org' % IPaddy} > > timing_done = 0 > start_time = time() > for host in bl_list.keys(): > if host in bl_list.keys(): > IPlookup = "%s.%s" % (reverseIP, host) > try: > debug(" IPlookup=%s=" % IPlookup) > resolvesIP = socket.gethostbyname(IPlookup) > debug(" resolvesIP=%s=" % resolvesIP) > if resolvesIP.startswith('127.'): > end_time = time() > elapsed_time = end_time - start_time > timing_done = 1 > debug("Time elapsed for rDNS on bl_list: %f secs" % > elapsed_time) > debug("exiting--SPAM! id'd by %s" % host) > print bl_list[host] > sys.exit(0) > except socket.gaierror: > pass > if not timing_done: > end_time = time() > elapsed_time = end_time - start_time > debug("2nd try:Time elapsed for rDNS on bl_list: %f secs" % > elapsed_time) > I don't believe that gethostbyname()'s use of socket technology can be expected to raise socket timeout exceptions, since in general it's a call to a library that uses standard system calls. This would at least explain the behaviour you were seeing. It might just be easier to to the DNS work yourself using the rather nifty "dnspython" module. This does allow you to easily implement timeouts for specific interactions. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From cantabile.03 at wanadoo.fr Tue Aug 2 20:40:01 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Wed, 03 Aug 2005 02:40:01 +0200 Subject: pygettext ? Message-ID: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Hi, I'm trying to write an internationalized app. I'm learning python and read that pygettext would help me, but I found elsewhere it was obsolete (??) So, what's the correct and up to date tool to i18n python ? Is there a tutorial somewhere (python docs has nothing really usable : I'd like at least an example!) Do you have links to pages or documents about that ? Thanks :) From jzgoda at gazeta.usun.pl Wed Aug 3 04:42:32 2005 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Wed, 03 Aug 2005 10:42:32 +0200 Subject: pygettext ? In-Reply-To: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: cantabile napisa?(a): > Hi, I'm trying to write an internationalized app. I'm learning python > and read that pygettext would help me, but I found elsewhere it was > obsolete (??) > So, what's the correct and up to date tool to i18n python ? > Is there a tutorial somewhere (python docs has nothing really usable : > I'd like at least an example!) Here's a page from wxPython wiki, but I think it may be usable also with other GUI toolkits, as it contains many generic introductory informations: http://wiki.wxpython.org/index.cgi/Internationalization Also, check sources of some existing application that has good i18n implementation, Gajim (http://www.gajim.org/) comes first to my mind. -- Jarek Zgoda http://jpa.berlios.de/ From jeffrey.schwab at rcn.com Thu Aug 11 23:43:15 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Thu, 11 Aug 2005 23:43:15 -0400 Subject: Python Challenge on BBC In-Reply-To: References: Message-ID: Magnus Lie Hetland wrote: > Just saw this on the BBC World program Click Online: > > http://bbcworld.com/content/template_clickonline.asp?pageid=665&co_pageid=6 > > I must say, I think this is the first time I've heard Python discussed > on TV at all... Cool :) > > (Now maybe I'll have to finish the rest of those P.C. levels... ;) > Boy, Python Challenge is addictive! From km at mrna.tn.nic.in Tue Aug 23 03:34:54 2005 From: km at mrna.tn.nic.in (km) Date: Tue, 23 Aug 2005 13:04:54 +0530 Subject: loop in python In-Reply-To: References: <20050823065501.GA24558@mrna.tn.nic.in> Message-ID: <20050823073454.GA27747@mrna.tn.nic.in> > If you want a fast language, try Holden. I've just invented it. > Unfortunately it gets the answer to every problem wrong unless the > answer is 42, but boy it runs quickly. The code for the whole > interpreter (it's written in Python) follows: > print 42 great ! u can use it for ur own projects. but pls donot suggest it to anyone else. i think u can get an award for developing such a fast language in such a shorter time ;-) may be u can also be called 'Guido Holden Rossum' ;-) anyway improve it - its quite buggy now :-D > Speed of execution is so insignificant for the majority of programming problems I donot agree with that. If thats the case then no one would be using C or C++ etc for instance. one important thing is that i am not comparing python with C but with similar language, Perl. well ofcourse i dont jump into conclusion, just with just a simple 'loops' snippet, that python is slower than perl. but when speed is important then ? also i hate people recommending "if u need speed code it as a C extension module". ofcourse i donot expect pure python/perl program to execute at the speed of a C program. > that this obsession reveals a certain inexperience. its neither obsession nor inexperience ... its just the requirement. i think less buggy code is not the main concern for all. if thats the case there are better languages (like Ada with better built in exception classes) and so used in mission critical applications. even perl is still popular even its difficult to maintain, but when one looks for speed (naturally), rather than the readability & maintainability of the code, does python suit perl ? i am aware one of the main principle python isn founded is better readability but is that a feature which decreases execution speed ? then what is it ? even perl is still popular even if its difficult to maintain after a certian stage of coding. there obviously will be a bias in this list towards python but i need a honest opinion of python vs perl. (especially when it comes to webscripting) > regards > Steve "The inventor of Holden" regards, KM From mekstran at scl.ameslab.gov Fri Aug 19 15:41:18 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Fri, 19 Aug 2005 14:41:18 -0500 Subject: Idempotent XML processing In-Reply-To: References: <2f66fb64f6cf531cca8b75576548283f@scl.ameslab.gov> Message-ID: <9e2a58f41c68152733d84a359862d9be@scl.ameslab.gov> On Aug 19, 2005, at 1:20 PM, Robert Kern wrote: > Read up on XML canonicalization (abrreviated as c14n). lxml implements > this, also xml.dom.ext.c14n in PyXML. You'll need to canonicalize on > both ends before hashing. > > To paraphrase an Old Master, if you are running a cryptographic hash > over a non-canonical XML string representation, then you are living in > a > state of sin. Canonicalization seems to be the needed thing. Looking at the protocol specification again, it mentions canonicalization; I had glossed over that previously because I was unware of any defined meaning it had. But the c14n module should provide the needed results (now that I've finally dug up documentation for it). -Michael From T.A.Meyer at massey.ac.nz Mon Aug 29 06:00:49 2005 From: T.A.Meyer at massey.ac.nz (Meyer, Tony) Date: Mon, 29 Aug 2005 22:00:49 +1200 Subject: Python built email message doesn't support OutLook Express Message-ID: > I used below code to build email message [...] > msg.set_payload("Body of the email messagge") [...] > This code will build plain email message properly. > But after building the message. If a email user > download this mail through out look express then > this email message will display without any alignment. What do you mean without any alignment? Text always has an alignment (unless the letters are scattered across the screen, I suppose). You're sending a plain-text email (with a MIME type of 'html'), so it's up to the client (OE) to decide how to display it. > If a user type 3 paragraph message > outlook express display as a single line. Are you putting line breaks in the message? I suspect that what you're missing is that you're meaning to put some HTML in the message, and aren't (the content type hints at this). =Tony.Meyer From jonathon.blake at gmail.com Fri Aug 26 19:58:00 2005 From: jonathon.blake at gmail.com (Jonathon Blake) Date: Fri, 26 Aug 2005 23:58:00 +0000 Subject: Python library/module for MSAccess Message-ID: All: I thought I had seen a python library/module that easily enabled one to read / write / create MSAccess databases a couple of years ago. [My impression is that the Jet Database engine was _not_ required.] Now, I can't find it, or any reference to such a library or module. [I used google, and the module search tools on python. Can somebody point me to an MSAccess library/module that does that? xan jonathon -- Does your Office Suite conform to ISO Standards? From bokr at oz.net Tue Aug 30 16:22:05 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 30 Aug 2005 20:22:05 GMT Subject: Yielding a chain of values References: Message-ID: <4314bf65.177562962@news.oz.net> On Tue, 30 Aug 2005 12:18:59 GMT, Michael Hudson wrote: >Talin writes: > >> I'm finding that a lot of places within my code, I want to return the >> output of a generator from another generator. Currently the only >> method I know of to do this is to explicitly loop over the results >> from the inner generator, and yield each one: >> >> for x in inner(): >> yield x >> >> I was wondering if there was a more efficient and concise way to do >> this. And if there isn't, > >Greenlets, perhaps? (for which, see google). > Maybe yield in inner() could be sugar for the above and become something optimized? Regards, Bengt Richter From pink at odahoda.de Fri Aug 5 13:54:06 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Fri, 05 Aug 2005 19:54:06 +0200 Subject: minidom xml & non ascii / unicode & files References: <42f38284$0$5314$636a15ce@news.free.fr> Message-ID: webdev wrote: > lo all, > > some of the questions i'll ask below have most certainly been discussed > already, i just hope someone's kind enough to answer them again to help > me out.. > > so i started a python 2.3 script that grabs some web pages from the web, > regex parse the data and stores it localy to xml file for further use.. > > at first i had no problem using python minidom and everything concerning > my regex/xml processing works fine, until i tested my tool on some > french page with "non ascii" chars and my script started to throw errors > all over the place.. > > I've looked into the matter and discovered the unicode / string encoding > processes implied when dealing with non ascii texts and i must say i > almost lost my mind.. I'm loosing it actually.. The general idea is: - convert everything that's coming in (from the net, database, files) into unicode - do all your processing with unicode strings - encode the strings to your preferred/the required encoding when you write it to the net/database/file > so here are the few questions i'd like to have answers for : > > 1. when fetching a web page from the net, how am i supposed to know how > it's encoded.. And can i decode it to unicode and encode it back to a > byte string so i can use it in my code, with the charsets i want, like > utf-8.. ? First look at the HTTP 'Content-Type' header. If it has a parameter 'charset', that the encoding to use, e.g. Content-Type: text/html; charset=iso-8859-1 If there's not encoding specified in the header, look at the prolog, if you have a XHTML document at hand (and it's present). Look below for the syntax. The last fallback is the tag. The content attribute has the same format as the HTTP header. But you can still run into UnicodeDecodeErrors, because many website just don't get their encoding issues right. Browser do some (more or less) educated guesses and often manage to display the document as intended. You should probably use htmlData.encode(encoding, "ignore") or htmlData.encode(encoding, "replace") to work around these problems (but loose some characters). And, as said above: don't encode the unicode string into bytestrings and process the bytestrings in your program - that's a bad idea. Defer the encoding until you absolutely necessary (usually file.write()). > 2. in the same idea could anyone try to post the few lines that would > actually parse an xml file, with non ascii chars, with minidom > (parseString i guess). The parser determines the encoding of the file from the line. E.g. if your file is encoded in utf-8, add the line at the top of it, if it's not already present. The parser will then decode everything into unicode strings - all TextNodes, attributes etc. should be unicode strings. When writing the manipulated DOM back to disk, use toxml() which has an encoding argument. > Then convert a string grabbed from the net so parts of it can be > inserted in that dom object into new nodes or existing nodes. > And finally write that dom object back to a file in a way it can be used > again later with the same script.. Just insert the unicode strings. > I've been trying to do that for a few days with no luck.. > I can do each separate part of the job, not that i'm quite sure how i > decode/encode stuff in there, but as soon as i try to do everything at > the same time i get encoding errors thrown all the time.. > > 3. in order to help me understand what's going on when doing > encodes/decodes could you please tell me if in the following example, s > and backToBytes are actually the same thing ?? > > s = "hello normal string" > u = unicode( s, "utf-8" ) > backToBytes = u.encode( "utf-8" ) > > i knwo they both are bytestrings but i doubt they have actually the same > content.. Why not try it yourself? "hello normal string" is just US-ASCII. The utf-8 encoded version of the unicode string u"hello normal string" will be identical to the ASCII byte string "hello normal string". > > 4. I've also tried to set the default encoding of python for my script > using the sys.setdefaultencoding('utf-8') but it keeps telling me that > this module does not have that method.. i'm left no choice but to edit > the site.py file manually to change "ascii" to "utf-8", but i won't be > able to do that on the client computers so.. > Anyways i don't know if it would help my script at all.. There was just recently a discussing on setdefaultencoding() on various pythonistic blogs, e.g. http://blog.ianbicking.org/python-unicode-doesnt-really-suck.html > > any help will be greatly appreciated > thx > > Marc -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From timr at probo.com Thu Aug 25 03:46:41 2005 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Aug 2005 00:46:41 -0700 Subject: Command Line arguments References: Message-ID: <9gtqg1lkso6m6ukipku1ac7hk9sejhi3ld@4ax.com> michael wrote: >I have a question about Windows based python (2.4 and later). > >For example, if I make a script called test.py like so: > >import sys >print sys.argv > >then run it: > >python test.py this is a test > >I see a list with > >['test.py', 'this', 'is', 'a', 'test'] > > >All is good! > >BUT... > >If i make .py extensions be run as exes (by setting the .py extension to >be executable with PATHEXT setting in environment variables, the Python >program will run, but NO arguments are passed! > >For example, after setting .py extension to be executable, i get this: > >test this is a test > >I get ['test.py]. NO arguments are passed. > >NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and >earlier works FINE. It is a configuration problem. Bring up a Command Shell and run the assoc and ftype commands like this: C:\Tmp>assoc .py .py=Python.File C:\Tmp>ftype Python.File Python.File="C:\Apps\Python24\python.exe" "%1" %* C:\Tmp> The KEY part of that is the %* at the end of the Python.File defintion. That tells the system to insert the rest of the command line parameters at that point. If you have ONLY the "%1", the command will run but no parameters will be forwarded. If so, you can fix this by typing: C:\Tmp>ftype Python.File="C:\Apps\Python24\python.exe" "%1" %* Substituting your own path, of course. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From u.hobelmann at web.de Fri Aug 12 16:05:15 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Fri, 12 Aug 2005 22:05:15 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <3m4dnrF1519hpU1@individual.net> jan V wrote: > Did you know that some deranged people take sexual pleasure out of starting > fires? Apparently some of the latest forest/bush fires in southern Europe > were even started by firemen (with their pants down?). I've only heard of people trying to extinguish fires with their pants down. Oh well... -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From rkern at ucsd.edu Thu Aug 25 12:22:15 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 09:22:15 -0700 Subject: variable hell In-Reply-To: References: <430dc538@127.0.0.1> Message-ID: Ron Garret wrote: > If you really want to make something like this work you can define a > class that would work like this: > > vars = funkyclass() > varname = 'x' > vars[varname] = value > vars.x > > But this is clearly a design mistake. Either you know the names of the > variables when you write the code or you do not. If you know them you > can simply assign them directly. If you do not know them then you can't > put them in the code to read their values anyway, and what you need is > just a regular dictionary. In fact, I do this all of the time. class Bunch(dict): def __init__(self, *args, **kwds): dict.__init__(self, *args, **kwds) self.__dict__ = self It's a lifesaver when you're working at the interactive prompt. In the bowels of my modules, I may not know what the contents are at code-time, but at the prompt I probably do. Bunch assists both usages. -- 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 tjreedy at udel.edu Sat Aug 13 09:30:31 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Aug 2005 09:30:31 -0400 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk><1123602877.802803.281500@g14g2000cwa.googlegroups.com><42F9BC7D.1050300@le.ac.uk> <42FB55BC.70608@sweetapp.com> <86r7cy63wi.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86r7cy63wi.fsf at bhuda.mired.org... > Magnus Lycka writes: >> Terry Reedy wrote: >>> However, everything is an instance of a class or type. >> Except whitespace, comments, operators and statements! >> (Did I miss anything?) > [snip] Maybe the properly > refined version of Terry's statement should be: > > Everything you can manipulate is an instance of a class or a > type. Yes and no. First, the context of the statement was a previous claim that some things are class instances and some not. So my point in that context was a) that adding 'or type' changes 'some' to 'every' and that new classes mostly eliminate the difference between class and type, making the addition eminently sensible. So while I thought of a qualifier like that, I left it out as irrelevant and a distractions. Second, any qualifier I can think of seems to have the danger of confusing as well as enlightening. One might not realize, for instance, that functions are something you can manipulate and might therefore mistakenly think that the qualifier excludes functions. I also thought of putting it as 'everything in Python's dataspace ...', but that has the same problem. Perhaps 'every runtime entity...'. would work. That seems to excludes source code (and things within source code like comments and whitespace and operator symbols), unless the code or pieces thereof *are* turned into (or wrapped as) string instances. Names might seem like an exception, but again, they are only accessible at runtime as string instances. Or maybe a more direct statement 'except for source code, everything...' would be better. So I have so far not settled on a 'best' context-free statement of the design principle. Terry J. Reedy From zen19725 at zen.co.uk Mon Aug 1 03:55:43 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 1 Aug 2005 08:55:43 +0100 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> Message-ID: On 31 Jul 2005 10:07:52 -0700, Kay Schluehr wrote: > >Ed Leafe wrote: >> On Sunday 31 July 2005 01:02, phil hunt wrote: >> >> > You mightn't have, but I suspect more Python programers who've >> > written GUI apps have used Tkinter than any of the other APIs. >> > >> > Not that I'm a particular fan of it, it's just I like >> > standardisation, because then you get network effects. >> >> At PyCon DC 2004, Guido was asked about wxPython: "wxPython is the best and >> most mature cross-platform GUI toolkit, given a number of constraints. The >> only reason wxPython isn't the standard Python GUI toolkit is that Tkinter >> was there first." > >Maybe. But Guidos intention with Python was to create a secondary >language originally - an extension language of C - ( unlike Java that >was concepted as a radically platform independent language and a >successor of C++ ). These days you can almost think of C++ as a secondary language to Python: code the app in Python and then optimise by recoding the bits that need speed in C++. >Some other people already abandoned Python not for the worst reasons: > >http://www.kevin-walzer.com/pivot/entry.php?id=69 > >My objection with wrappers around wrappers around wrappers is that I >have no hope ever watching the ground. If some error occurs, which >layer has to be addressed? Good point. -- Email: zen19725 at zen dot co dot uk From esleben at gmail.com Thu Aug 4 09:54:10 2005 From: esleben at gmail.com (Jan-Ole Esleben) Date: Thu, 4 Aug 2005 15:54:10 +0200 Subject: Metaclasses and class variables In-Reply-To: References: Message-ID: <3756d97505080406543aea76aa@mail.gmail.com> Yes, that works, but it is unfortunately not an option (at least not a good one). Is there no way to create a class variable that exists during definition of the class? (I cannot imagine there isn't, since technically it's possible and manually it can be done...) Ole > classvar is defined AFTER the class has been created. So, this should > work: > > class Test: > __metaclass__ = Meta > > Test.classvar.append(1) > > Thomas > -- > http://mail.python.org/mailman/listinfo/python-list > From saint.infidel at gmail.com Tue Aug 9 15:00:27 2005 From: saint.infidel at gmail.com (infidel) Date: 9 Aug 2005 12:00:27 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123613673.097932.265430@g47g2000cwa.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> <1123613673.097932.265430@g47g2000cwa.googlegroups.com> Message-ID: <1123614027.149764.143040@z14g2000cwz.googlegroups.com> > Are you sure you can specify arbitrary arguments to the __new__ method? > I thought they had to be the class object, the tuple of bases, and the > dictionary of names. Nevermind, I think I was imagining metaclasses rather than just regular overriding of __new__ From kay.schluehr at gmx.net Mon Aug 8 09:22:37 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Aug 2005 06:22:37 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <7xpsso3jih.fsf@ruckus.brouhaha.com> References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <7xpsso3jih.fsf@ruckus.brouhaha.com> Message-ID: <1123507357.148189.27540@g47g2000cwa.googlegroups.com> Paul Rubin schrieb: > Having a good FFI is certainly an important feature but Python > programs should first and foremost be Python programs. Python was originally created as an extension language for C. In some sense it is an abstraction layer for C libs. > Compare the > situation with Java or Common Lisp for example. Both of those > languages have better FFI's than Python in every serious > implementation (consider why SWIG is popular--because Python's C API > is so clumsy), and yet the specs for those languages are far more > thorough than the Python docs. Did you ever check out ctypes? I appreciate it very much. http://starship.python.net/crew/theller/ctypes/ Kay From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 24 03:49:58 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 24 Aug 2005 09:49:58 +0200 Subject: pipes like perl References: <430b6311$0$29696$636a15ce@news.free.fr> Message-ID: max(01)* enlightened us with: > but i need to check the success/failure of the external command > *before* closing the file! You can't, unless you have a more intimite knowledge of the command involved. If you know, for instance, that any output on stderr means an error, you can check for just that. Without knowledge of the command and it's output, the only thing you can check on is the exit code. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From billiejoex at fastwebnet.it Wed Aug 31 09:11:21 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Wed, 31 Aug 2005 15:11:21 +0200 Subject: use threading without classes References: Message-ID: Thank you for your helping. From krisztian.sinka at ericsson.com Fri Aug 26 07:50:43 2005 From: krisztian.sinka at ericsson.com (Krisz) Date: 26 Aug 2005 04:50:43 -0700 Subject: Excel Character object through COM Message-ID: <1125057043.800968.180180@g47g2000cwa.googlegroups.com> Hi! Maybe this question is already answared somewhere, but I could not find it: I want to modify one of the letters of a text of a Excel cell through COM; let's say to make it red. The VB reference tells that it can be managed with: With Worksheets("Sheet1").Range("A1") .Value = "abcdefg" .Characters(3, 1).Font.Bold = True End With However when I try the similar in Python (I used the 'COM Makepy utility' of Pythonwin) I got the following (Here 'A' is a class that wraps the 'com' things): >>> A.book.Worksheets(1).Range("a1").Characters >>> A.book.Worksheets(1).Range("a1").Characters(1,1) Traceback (most recent call last): File "", line 1, in ? AttributeError: Characters instance has no __call__ method So my question is that am I doing something wrong or there is a different way to modify the color of a charater through COM. Thank you. Regards, Krisztian From brian at sweetapp.com Mon Aug 1 07:21:01 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 01 Aug 2005 13:21:01 +0200 Subject: Python Programming Contest: First results In-Reply-To: <42DE18B2.903@sweetapp.com> References: <1121838061.749455.44630@g14g2000cwa.googlegroups.com> <42DE18B2.903@sweetapp.com> Message-ID: <42EE059D.8000406@sweetapp.com> Here are the results for the first problem in the Python Programming Contest. I haven't been able to find as much time as I excepted, so my analysis is not very in depth. You can find the results here: http://www.sweetapp.com/pycontest/contest1/results.html And the problem definition here: http://www.sweetapp.com/pycontest/contest1/ Kudos to everyone who participated but especially to Raymond Hettinger and Thomas Lotze, whose solutions were nearly 50 times faster than mine. I'd also like to point out that Thomas Guettler's solution, which is the slowest, was completed in less than 3 hours after the contest was announced. That's impresive for a correct solution. Cheers, Brian From sjdevnull at yahoo.com Wed Aug 31 13:33:57 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 31 Aug 2005 10:33:57 -0700 Subject: global interpreter lock In-Reply-To: References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> Message-ID: <1125509637.081147.124010@z14g2000cwz.googlegroups.com> phil hunt wrote: > Some times concurrency is the best (or only) way to do a job. Other > times, it's more trouble than its worth. A good programmer will know > which is which, and will not use an overly complex solution for the > project he is writing. Also, a good programmer won't conflate concurrency with threads. From zarnovican at gmail.com Mon Aug 15 14:22:02 2005 From: zarnovican at gmail.com (BranoZ) Date: 15 Aug 2005 11:22:02 -0700 Subject: Using for in one-liner In-Reply-To: <4300D3D1.6080909@redlinepy.com> References: <3mbu82F15h18oU1@individual.net> <1124124590.563497.241560@g43g2000cwa.googlegroups.com> <4300CB9D.2020809@redlinepy.com> <1124126384.664929.313090@g43g2000cwa.googlegroups.com> <4300D3D1.6080909@redlinepy.com> Message-ID: <1124130122.840575.5650@g14g2000cwa.googlegroups.com> Paul Watson wrote: > Using a '$' before the string works in the ksh that is part of FC4. > However, it does not work on the pdksh that is in FC3 and Cygwin. It > also does not work on AIX ksh. > > $ print $'now' > $now In bash you can also use Ctrl-v followed by special character. (I used to reset terminal by echo "c") Ctrl-v, Enter -> generate 0x0d to command-line Crtl-v, Ctrl-m -> the same as above Ctrl-v, Ctrl-j -> generate 0x0a (UNIX \n) So type: python -c 'import sys; then press Ctrl-v followed by Ctrl-j and type the rest.. In vi it looks like ^@. At CLI it realy does a newline. I guess, you can no longer call it an one-liner ;-) I'm not sure whether Ctrl-v is a bash feature. More probably the tty driver. So, it may be worth tring it on bash-less UNIXes (that deserve to extinct) BranoZ From rafi at free.fr Thu Aug 25 16:41:51 2005 From: rafi at free.fr (rafi) Date: Thu, 25 Aug 2005 22:41:51 +0200 Subject: variable hell In-Reply-To: References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> Message-ID: <430e2d06$0$6453$626a14ce@news.free.fr> Steve Holden wrote: > Because eval() takes an expression as an argument, and assignment is a > statement. I am definitely not a language lawyer... but I should a little bit more thanks, -- rafi "Imagination is more important than knowledge." (Albert Einstein) From http Sat Aug 27 00:08:05 2005 From: http (Paul Rubin) Date: 26 Aug 2005 21:08:05 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: <7xoe7k10pm.fsf@ruckus.brouhaha.com> Steve Holden writes: > If you want an exception from your code when 'w' isn't in the string > you should consider using index() rather than find. The idea is you expect w to be in the string. If w isn't in the string, your code has a bug, and programs with bugs should fail as early as possible so you can locate the bugs quickly and easily. That is why, for example, x = 'buggy'[None] raises an exception instead of doing something stupid like returning 'g'. From peter at engcorp.com Sun Aug 7 08:43:51 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 07 Aug 2005 08:43:51 -0400 Subject: Making a timebomb In-Reply-To: References: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> Message-ID: Cantankerous Old Git wrote: > Peter Hansen wrote: >> Cantankerous Old Git wrote: >>> The dirty way, which can leave corrupt half-written files and other >>> nasties, is something like sys.exit(). >> >> sys.exit() won't help you if your server is running in the main >> thread, nor if your server thread is not marked as a daemon, but that >> does raise another possibility. > > I assume you know that I actually meant System.exit(). Why do you think > that won't help? No, I didn't know that, but if you were confused the first time, I think you're getting even more confused now. What is System.exit()? I don't have one, and have never seen it mentioned. Perhaps you meant SystemExit, the exception that's raised when you call sys.exit()? If so, I still don't see your point, because there's no difference between the two in this context. Maybe you meant os._exit()? Now *that* one is messy, and will work as you described. -Peter From mwm at mired.org Fri Aug 19 23:20:48 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 19 Aug 2005 23:20:48 -0400 Subject: BeautifulSoup References: <1124476767.160347.55710@g14g2000cwa.googlegroups.com> Message-ID: <867jehb8fj.fsf@bhuda.mired.org> "Paul McGuire" writes: > Here's a pyparsing program that reads my personal web page, and spits > out HTML with all of the HREF's reversed. Parsing HTML isn't easy, which makes me wonder how good this solution really is. Not meant as a comment on the quality of this code or PyParsing, but as curiosity from someone who does a lot of [X}HTML herding. > -- Paul > (Download pyparsing at http://pyparsing.sourceforge.net.) If it were in the ports tree, I'd have grabbed it and tried it myself. But it isn't, so I'm going to be lazy and ask. If PyParsing really makes dealing with HTML this easy, I may package it as a port myself. > from pyparsing import Literal, quotedString > import urllib > > LT = Literal("<") > GT = Literal(">") > EQUALS = Literal("=") > htmlAnchor = LT + "A" + "HREF" + EQUALS + > quotedString.setResultsName("href") + GT > > def convertHREF(s,l,toks): > # do HREF conversion here - for demonstration, we will just reverse > them > print toks.href > return "" % toks.href[::-1] > > htmlAnchor.setParseAction( convertHREF ) > > inputURL = "http://www.geocities.com/ptmcg" > inputPage = urllib.urlopen(inputURL) > inputHTML = inputPage.read() > inputPage.close() > > print htmlAnchor.transformString( inputHTML ) How well does it deal with other attributes in front of the href, like ? How about if my HTML has things that look like HTML in attributes, like ? Thanks, http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From cam.ac.uk at mh391.invalid Thu Aug 4 19:01:13 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Fri, 05 Aug 2005 00:01:13 +0100 Subject: Parallel arithmetic? In-Reply-To: <42f298d6$1_5@alt.athenanews.com> References: <42f298d6$1_5@alt.athenanews.com> Message-ID: Terrance N. Phillip wrote: > Given a and b, two equal length lists of integers, I want c to be > [a1-b1, a2-b2, ... , an-bn]. I can do something like: > > c = [0] * len(a) > for ndx, item in enumerate(a): > c[ndx] = item - b[ndx] > > But I'm wondering if there's a better way, perhaps that avoids a loop? Here's one way: c = [a_item - b_item for a_item, b_item in zip(a, b)] And another: import operator c = map(operator.sub, a, b) -- Michael Hoffman From paolo_veronelli at tiscali.it Wed Aug 10 08:30:07 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Wed, 10 Aug 2005 14:30:07 +0200 Subject: Why is this? In-Reply-To: <42F9F05E.1050604@tiscali.it> References: <42F9F05E.1050604@tiscali.it> Message-ID: <42F9F34F.4060505@tiscali.it> Paolino wrote: > Jiri Barton wrote: > >>Hi everyone, >> >>I have a problem with initialization. >> >> >>>>>a, b = [[]]*2 >>>>>a.append(1) >>>>>b >> >>[1] >> >>Why is this? Why does not this behave like the below: >> > > >>> a, b = [[]]*2 > >>> a==b > True Ooops I should write 'a is b' > > >>And, just to add to my confusion: >> >> >> >>>>>[[]]*2 >> >>[[], []] >> >> >>>>>[[], []] == [[]]*2 >> >>True > > This confuses me also,looks like empty lists share same object. This is actually OK as lists are compared for their contents ;-) > Paolino > > > > > > > ___________________________________ > Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB > http://mail.yahoo.it ___________________________________ Aggiungi la toolbar di Yahoo! Search sul tuo Browser, e'gratis! http://it.toolbar.yahoo.com From paul at fxtech.com Fri Aug 26 16:14:17 2005 From: paul at fxtech.com (Paul Miller) Date: Fri, 26 Aug 2005 15:14:17 -0500 Subject: MacPython 2.2 on Mac OS X 10.3.8 - configurePython error In-Reply-To: References: Message-ID: Robert Kern wrote: > Paul Miller wrote: > >>Robert Kern wrote: > > >>>MacPython 2.2 has been long abandoned. The >>>official OS X binary for Python 2.4.1 can be found here: >>> >>>http://www.python.org/ftp/python/2.4.1/MacPython-OSX-2.4.1-1.dmg >> >>I realize that, but I have an application that is linked with MacPython >>2.2. I can't just drop 2.4 in. > > > Is this an application that you've written? If so, then I realize that > you can't just drop 2.4 in painlessly, but you really should consider > upgrading your software to use a newer Python. No one is going to > support MacPython 2.2. Yes, this is an app I have written. I could take the time to rebuild it with the latest Python, yes. However, the simpler solution seemed to be to try to figure out why it won't reconfigure itself. I have OS X 10.3.8 and a clean install works perfectly fine. Surely someone somewhere has used MacPython 2.2 on OS X 10.3.8 and heard of a similar issue, with ConfigurePythonCarbon not working after preferences were destroyed. This is why I asked here. >>He claims the only thing that has changed is his preferences were wiped >>out. There must be some solution for what is probably a not too uncommon >>problem. > > It *is* uncommon. Judging from the traffic on the Pythonmac-SIG, > virtually no one is using MacPython 2.2 anymore. You can ask for help on > there, but I don't think you'll fare any better. Perhaps I am the only developer with a legacy application he's trying to support. But I doubt it. From peter at engcorp.com Tue Aug 2 17:21:00 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 02 Aug 2005 17:21:00 -0400 Subject: Pickle, __init__, and classes In-Reply-To: References: <1123013424.847230.300030@g47g2000cwa.googlegroups.com> Message-ID: Russell Blau wrote: > Try __new__(). http://docs.python.org/ref/customization.html This isn't > the usual application of __new__, but since it returns an object it should > be ideal for your purposes. Or simply create a factory function to return your instances -- which is in effect what __new__ does -- but without the baggage. -Peter From steve at holdenweb.com Tue Aug 30 13:17:23 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Aug 2005 12:17:23 -0500 Subject: Writing Multithreaded Client-Server in Python. In-Reply-To: <7xll2jhlb6.fsf@ruckus.brouhaha.com> References: <1125376325.572881.163770@g44g2000cwa.googlegroups.com> <7x3bos55vb.fsf@ruckus.brouhaha.com> <1125389989.030999.172080@g47g2000cwa.googlegroups.com> <7xll2jhlb6.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > google at phaedro.com writes: > >>What it does do, is handle each request (from the same client too) in a >>new separate thread. Convenient if your processing intensive handle may >>otherwise slow down the main server process becoming less responsive to >>other requests. >>What it doesn't do (and what Sidd seems to search as is suggested by >>his 'select()' remark) is handle each client in a separate thread. > > > I don't know what you mean by that. It launches a new thread for each > client connection. The connection is two-way and can last as long as > desired. If you're imagining something like a web server handling > http requests, using http 1.1 keepalive, you could handle any number > of requests in that connection. > I suspect he was trying to say that BaseHTTPServer has no mechanism for handling state. As you know, of course, this is most relevant across multiple successive connections to a server from the same client, and has little to do with threads. > >>If you want to apply SocketServer such that each client corresponds to >>one thread that handles its' requests (and maintains its state), don't >>use ThreadingMixIn - only the thread-selection will be executed in a >>separate thread. > > > What do you mean by "each client"? If a client connects, does some > stuff, disconnects, and later reconnects, how do you know that it's > the same client that's come back? The assertion that ThreadingMixIn doesn't handle *sessions* might be more appropriate, but then there's no reason why it really should (since if they were handled at all they would be better handled in the base server classes). By "each client" I suspect the OP really meant "each session", and was ignoring the fact that the same client can have multiple sessions to the same server. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sybrenUSE at YOURthirdtower.com.imagination Sun Aug 21 20:29:34 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 22 Aug 2005 02:29:34 +0200 Subject: SOAP and XMLRPC References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Message-ID: phil hunt enlightened us with: > I thought it was the whole point of XMLRPC that the server can be > written in one language and the client in another. Am I wrong? It is, but not all SOAP libs really support the standard. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From jarrod.roberson at gmail.com Thu Aug 18 02:32:09 2005 From: jarrod.roberson at gmail.com (fuzzylollipop) Date: 17 Aug 2005 23:32:09 -0700 Subject: Obfuscator for Python Code In-Reply-To: <1124298063.074422.252770@g14g2000cwa.googlegroups.com> References: <1124298063.074422.252770@g14g2000cwa.googlegroups.com> Message-ID: <1124346729.470027.246610@z14g2000cwz.googlegroups.com> i guess you didn't find anything using Google? From roy at panix.com Tue Aug 9 23:25:16 2005 From: roy at panix.com (Roy Smith) Date: Tue, 09 Aug 2005 23:25:16 -0400 Subject: Bizarre error from help() References: Message-ID: Roy Smith wrote: > No, that works fine. But, now I can't even reproduce the error I reported > earlier (when I try, I get the help message as expected). And, yes, that > was with a brand new interpreter session. Strange. I got it now! Oh, this is funny. I've got a directory where I keep all sorts of little snippets of python code for testing. When I start up python in that directory, I get the error I reported. It turns out, I've got a file called "string.py" in it, with the contents: ---------------------------- Roy-Smiths-Computer:play$ cat string.py #!/usr/bin/env python class myString (str): def __init__ (self, value): self.value = value def plural (self): if self.value[-1] in "sz": return self.value + "es"; else: return self.value + "s"; foo = myString("foo") bar = myString("bar") baz = myString("baz") print foo.plural(), bar.plural(), baz.plural() print foo.capitalize() ---------------------------- something in the help system must be doing an "import string". From jonhewer at gmail.com Wed Aug 3 03:56:55 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Wed, 3 Aug 2005 08:56:55 +0100 Subject: pygettext ? In-Reply-To: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: Hi I'm pretty new to Python, and recently been working my way through Dive Into Python, and I'm currently writing a really simple rss reader purely to get familiarised with the language. I want to move onto something a little more challenging, but I'm stuck for ideas on what to do. I'm after a project that can start quite simple, but has lots of room for expansion when I get more confident with Python. Ideally something which would start as a command line program, and then when I feel adventurous I could build a GUI for it. I have just bought the Foundations of Python Network Programming book, so maybe something network related would be good? Cheers Jon From peter at somewhere.com Fri Aug 26 05:57:10 2005 From: peter at somewhere.com (Peter Maas) Date: Fri, 26 Aug 2005 11:57:10 +0200 Subject: variable hell In-Reply-To: References: <430dc538@127.0.0.1> Message-ID: Benji York schrieb: >> >>> suffix = 'var' >> >>> vars()['a%s' % suffix] = 45 >> >>> avar >> 45 > > > Quoting from http://docs.python.org/lib/built-in-funcs.html#l2h-76 about > the "vars" built in: > > The returned dictionary should not be modified: the effects on the > corresponding symbol table are undefined. I tried this once and it worked. This may be too naive, so thanks for the warning :) -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From rkern at ucsd.edu Mon Aug 1 08:15:54 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 01 Aug 2005 05:15:54 -0700 Subject: Changing interpreter's deafult output/error streams In-Reply-To: References: Message-ID: Ira wrote: > OK let me rephrase, > > the standard error stream (and if I'm not mistaken also the one that > PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go > ahead and write the following in python... > > SomeNewStreamOrFileOrWhateverItIs = new stream > sys.stderr = SomeNewStreamOrFileOrWhateverItIs > > I can go ahead and do the exact same thing from the C source code. All I > need to do is to figure out how to wrap a c-style FILE* with a PyObject, And > PySys_SetObjet("stderr", newstream); > > I'm very new to python so that might be nonsense but it appeals to my > programmer's common sense. Can anyone tell me how to do this? http://docs.python.org/api/fileObjects.html -- 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 john at castleamber.com Fri Aug 26 18:13:16 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 22:13:16 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: Chris Head wrote: > John Bokma wrote: >> Chris Head wrote: [HTML] >> It can be made much faster. There will always be a delay since >> messages have to be downloaded, but with a fast connection and a good >> design, the delay will be very very small and the advantages are big. > > What advantages would those be (other than access from 'net cafes, but > see below)? And workplaces. Some people have more then one computer in the house. My partner can check her email when I had her over the computer. When I want to check my email when she is using it, I have to change the session, fire up Thunderbird (which eats away 20M), and change the session back. [ .. ] >> Each has it's place. A bug in a thick client means each and everyone >> has to be fixed. With a thin one, just one has to be fixed :-D. > > True. However, if people are annoyed by a Thunderbird bug, once it's > fixed, most people will probably go and download the fix (the > Thunderbird developers really only need to fix the bug once too). Most people who use Thunderbird, yes. Different with OE, I am sure. With a thin client *everybody*. >> Depends on where your mailbox resides. Isn't there something called >> MAPI? (I haven't used it myself, but I recall something like that). > > IMAP. It stores the messages on the server. Even so, it only has to > transfer the messages, not the bloated UI. But technically the UI (whether bloated or not) can be cached, and with Ajax/Frames, etc. there is not really a need to refresh the entire page. With smarter techniques (like automatically zipping pages), and techniques like transmitting only deltas (Google experimented with this some time ago) and better and faster rendering, the UI could be as fast as a normal UI. Isn't the UI in Thunderbird and Firefox created using JavaScript and XML? Isn't how future UIs are going to be made? > I concede that Webmail > might be just as fast when using a perfectly-designed > Javascript/frames-driven interface. In the real world, Webmail isn't > (unfortunately) that perfect. Maybe because a lot of users aren't really heavy users. A nice example (IMO) of a web client that works quite good: webmessenger ( http://webmessenger.msn.com/ ). It has been some time since I used it the last time, but if I recall correctly I hardly noticed that I was chatting in a JavaScript pop up window. > As I said above regarding 'net cafes: > > If the Internet cafe has an e-mail client installed on their > computers, you could use IMAP to access your messages. You'd have to > do a bit more configuration than for Webmail, so it depends on the > user I guess. Personally I doubt my ISP would like me saving a few > hundred megs of e-mail on their server, while Thunderbird is quite > happy to have 1504 messages in my Inbox on my local machine. If I had > to use an Internet cafe, I would rather use IMAP than Webmail. I rather have my email stored locally :-) But several webmail services offer a form to download email. >>>Ergo, >>>Thunderbird is faster as soon as the Internet gets congested. >> >> Ah, yeah, wasn't that predicted to happen in like 2001? > > Wasn't what predicted to happen? Congestion? It happens even today > (maybe it's the Internet, maybe it's the server, whatever...). Hotmail > is often pretty slow. I read sometime ago that about 1/3 of traffic consists out of bittorrent traffic... If the Internet gets congested, new techniques are needed, like mod_gzip on every server, a way to transfer only deltas of webpages if an update occured (like Google did some time ago). Better handling of RSS (I have the impression that there is no "page has not been modified" thing like with HTML, or at least I see quite some clients fetch my feed every hour, again and again). -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From gkj at gregorykjohnson.com Fri Aug 26 13:58:36 2005 From: gkj at gregorykjohnson.com (Gregory K. Johnson) Date: Fri, 26 Aug 2005 13:58:36 -0400 Subject: Email client in Pyhton In-Reply-To: <1125037713.267177.96100@g14g2000cwa.googlegroups.com> References: <1125037713.267177.96100@g14g2000cwa.googlegroups.com> Message-ID: <20050826175836.GB17391@andy.gregorykjohnson.com> On Thu, Aug 25, 2005 at 11:28:33PM -0700, Oren Tirosh wrote: > The mailbox module has recently been upgraded for full read-write > access by a student participating in google's Summer of Code. It is > currently under review for inclusion in the standard library. Yeah. I'm the student. :-) The OP may be interested in the project Web site, with documentation and a pointer to the source in Python CVS: http://gkj.freeshell.org/soc/ -- Gregory K. Johnson From pydecker at gmail.com Mon Aug 1 10:14:57 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 1 Aug 2005 10:14:57 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <7xr7de5zoe.fsf@ruckus.brouhaha.com> References: <20050730171613.1839738924.EP@zomething.com> <200507302029.34011.jstroud@mbi.ucla.edu> <7xy87nctxm.fsf@ruckus.brouhaha.com> <7xr7de5zoe.fsf@ruckus.brouhaha.com> Message-ID: On 31 Jul 2005 16:22:09 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > I spent several hours trying to install wxPython on Linux without > success (a lot of that was figuring out that some undefined symbol it > was complaining about was some GTK 1.5 function that had didn't exist > in GTK 2.1). As I remember, wxPython itself compiled without too much > trouble but wxWidgets and/or GTK 1.5 (once I got a copy of that) had > some problems. I decided I just didn't care enough to keep pursuing it. I'll bet you didn't even bother to read the docs, which give precise step-by-step instructions for building from source. Oh, that's right, you don't care enough to read directions. I suppose with that attitude, you can make just about anything fail. -- # p.d. From mwm at mired.org Fri Aug 26 20:24:56 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 26 Aug 2005 20:24:56 -0400 Subject: variable hell References: Message-ID: <86u0hcw7jb.fsf@bhuda.mired.org> [The context is totally hosed by top posting and failure to mark quoted text. I gave up on recovering it.] "Adriaan Renting" writes: > Not in my Python. > >>>> for count in range(0, 10): > ... value = count > ... exec("'a%s=%s' % (count, value)") You left in the extra set of quotes. Try this: >>> for count in range(10): ... value = count ... exec 'a%s = %s' % (count, value) ... >>> dir() ['__builtins__', '__doc__', '__file__', '__name__', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'count', 'help', 'readline', 'rlcompleter', 'sys', 'value'] I also removed the extraneous parens that you and Rafi both used - exec is a statement, not a function. Of course, your two examples are better done using imp and globals() or locals(). >>> dir() > ['__builtins__', '__doc__', '__name__', 'count', 'value'] >>>> for count in range(0, 10): > ... value = count > ... exec(eval("'a%s=%s' % (count, value)")) > ... >>>> dir() > ['__builtins__', '__doc__', '__name__', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'count', 'value'] >>>> > > I myself use code like this to load user defined classes. > exec(eval("'from %s import %s' % (script, script)")) > exec(eval("'self.user_class = %s()' % script")) > self.user_class.run() > > But this can probably be done with the imp module too. > >>>>rafi 08/25/05 6:03 pm >>> > Adriaan Renting wrote: >>You might be able to do something along the lines of >> >>for count in range(0,maxcount): >> value = values[count] >> exec(eval("'a%s=%s' % (count, value)")) > > why using the eval? > > exec ('a%s=%s' % (count, value)) > > should be fine > > -- > rafi > > "Imagination is more important than knowledge." > (Albert Einstein) > -- > http://mail.python.org/mailman/listinfo/python-list > -- Mike Meyer http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lbates at syscononline.com Fri Aug 12 13:30:15 2005 From: lbates at syscononline.com (Larry Bates) Date: Fri, 12 Aug 2005 12:30:15 -0500 Subject: UCALC equivalent In-Reply-To: References: Message-ID: <42FCDCA7.7030107@syscononline.com> Python has built in eval function and doesn't require a library. Larry Bates Dark Cowherd wrote: > http://www.ucalc.com/mathparser/index.html > > There is a great library called UCALC which allows you to set up an > expression and evaluate it > for e.g. you an define an expression by calling a function in UCALC > then call it with various values of x > > for e.g. see this page > http://www.ucalc.com/mathparser/sample6.html > > > It is very fast. I have used it in VB when there is lot of number > crunching to be done. > Is there a Python equivalent. > > I looked at numPy and SciPy sites (just skimmed through) did'nt seem > to have what I wanted. > > Any pointers? > > From gelios at rbcmail.ru Wed Aug 10 13:12:25 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Wed, 10 Aug 2005 21:12:25 +0400 Subject: MainThread blocks all others References: <42f9d4ef_2@news.isis.de> <42fa0457_2@news.isis.de> Message-ID: Hello Dennis and Bryan! You were absolutely right. I should show you real code instead of brain fucking. I am very sorry. Please find below real code. Sorry for amount of sources. Main aspect of program is all process should be in one determined sequence containing 3 stages. They are defined as stage1(), stage2() and stage3() in appMainFrame() Execution started when Start button presses (handler def OnStart() in appMainFrame() ). At the same time CardsObserver calls appMainFrame.addCards() to increment counter and in each stages wait this counter. All other code from library. Kind regards, /Gelios #######################Main application:################################ #exception class class NotASIMCardException: def __init__( self, message ): self.message = message def __str__(self): return repr( self.message ) class SmartCardOperations: def getATR( self, readerDescr ): atr="" self.attachedReaders = readers() for reader in self.attachedReaders: if readerDescr == str( reader ): connection=reader.createConnection() try: connection.connect() atr=toHexString( connection.getATR() ) connection.disconnect() except NoCardException: atr="no card inserted" return atr def decodeICCID( self, iccidBytes ): resIccid = [] #swap bytes i = 0 while i < len(iccidBytes): strTmp = str( hex( iccidBytes[i] ) ) if len(strTmp) == 3: strTmp = strTmp[0] + strTmp[1] + "0" + strTmp[2] resIccid += [strTmp[3] + strTmp[2]] i += 1 #remove last 2 bytes resIccid = resIccid[:-2] #remove first last digit strTmp = str( resIccid[i-3] ) if len(strTmp) == 1: strTmp += "0" resIccid[i-3] = strTmp[0] return resIccid def getICCID(self, readerDescr): self.attachedReaders = readers() for reader in self.attachedReaders: if readerDescr == str( reader ): session = smartcard.Session( reader ) try: data, sw1, sw2 = session.sendCommandAPDU( SELECT + DF_ROOT ) data, sw1, sw2 = session.sendCommandAPDU( SELECT + EF_ICCID ) data, sw1, sw2 = session.sendCommandAPDU( READ_BINARY + [0x0A]) if sw1 == 0x90 or sw1 == 0x91: msg = "Ok" else: msg = "ICCID read error. Error code: " + str(hex(sw1)) + str(hex(sw2)) session.close() except NoCardException: msg = "ICCID read error. Error code: " + str(hex(sw1)) + str(hex(sw2)) return msg, self.decodeICCID(data), data def getADM0( self, readerDescr, iccid ): self.attachedReaders = readers() for reader in self.attachedReaders: if readerDescr == str( reader ): session = smartcard.Session( reader ) try: data, sw1, sw2 = session.sendCommandAPDU( SAM_SEND_ICCID + iccid ) resBytesStr = str(sw1) + ' ' + str(sw2) if resBytesStr != "61 08": msg = "?????? ?????? ? SAM ??????" return msg, None data, sw1, sw2 = session. sendCommandAPDU( SAM_GET_ADM0 ) except NoCardException: msg = "ADM0 getting error. Error code: " + str(hex(sw1)) + str(hex(sw2)) msg = "Ok" return msg, data def chgEfLnd( self, iccid, adm0 ): self.attachedReaders = readers() for reader in self.attachedReaders: if readerDescr == str( reader ): session = smartcard.Session( reader ) try: data, sw1, sw2 = session.sendCommandAPDU( VERIFY_KEY_SIMERA3 + adm0 ) resBytesStr = str(sw1) + ' ' + str(sw2) if resBytesStr == "98 04" or resBytesStr == "98 40": msg = "?????? ??????? ? ?????" return msg data, sw1, sw2 = session.sendCommandAPDU( SELECT + DF_ROOT ) data, sw1, sw2 = session.sendCommandAPDU( SELECT + DF_GSM ) data, sw1, sw2 = session.sendCommandAPDU( DELETE_FILE ) if sw1 != 0x90 or sw1 != 0x91: msg = "?????? ??????? ? ?????" return msg data, sw1, sw2 = session.sendCommandAPDU( SELECT + DF_GSM ) data, sw1, sw2 = session.sendCommandAPDU( smartcard.util.toBytes(CREATE_FILE_APDU) if sw1 != 0x90 or sw1 != 0x91: msg = "?????? ??????? ? ?????" return msg except NoCardException: msg = "ADM0 getting error. Error code: " + str(hex(sw1)) + str(hex(sw2)) msg = "Ok" return msg class appMainFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(150,150), size=(640,400), style = wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.SYSTEM_MENU) self.panel = wx.Panel(self) # select reader controls self.selectReaderTxt = wx.StaticText(self.panel, -1, "?????????? ???????? reader: ", pos = (10, 12), size = (170, 21)) self.readerChoice = wx.Choice(self.panel, 120, pos = (180, 10), size = (230,21), choices=['?? ??????']) self.readerChoice.Select( 0 ) EVT_CHOICE( self, 120, self.selectReader) self.cardDescr = wx.TextCtrl(self.panel, -1, "????? ?? ?????????", pos = (415, 10), size = (205,21), style = wx.TE_READONLY ) self.staticLine2 = wx.StaticLine( self.panel, 210, pos = (10, 40), size = (610, 2) ) #Log self.logAreaTxt = wx.StaticText(self.panel, -1, "??????: ", pos = (10, 50), size = (105, 21)) self.logArea = wx.TextCtrl( self.panel, 301, "", pos = (10, 72), size = (610, 260), style=wx.TE_MULTILINE | wx.TE_READONLY ) self.saveLogButton = wx.Button( self.panel, -1, "?????? ??????? ? ????", pos = (20, 345) ) EVT_BUTTON( self, self.saveLogButton.GetId(), self.OnSaveLog ) #Buttons self.resetButton = wx.Button( self.panel, -1, "?????", pos = (300, 345) ) self.startButton = wx.Button( self. panel, -1, "?????", pos = (380, 345) ) self.closeButton = wx.Button( self.panel, -1, "?????", pos = (460, 345) ) EVT_BUTTON( self, self.resetButton.GetId(), self.OnReset ) EVT_BUTTON( self, self.startButton.GetId(), self.OnStart ) EVT_BUTTON( self, self.closeButton.GetId(), self.OnClose ) # Set properties self.SetTitle(title) self.Layout() #Smart card operations self.scOps = SmartCardOperations() self.START = False self.step = None self.cardEvent = threading.Event() def selectReader(self, event): self.selectedReader = event.GetString() self.cardDescr.SetValue( self.scOps.getATR(self.selectedReader) ) def removeReaders( self, removedreaders ): for readerToRemove in removedreaders: self.readerChoice.Delete( self.readerChoice.FindString( str( readerToRemove ) ) ) def addReaders( self, addedreaders ): for readerToAdd in addedreaders: self.readerChoice.Append( str ( readerToAdd ) ) def removeCards( self, removedcards ): if self.readerChoice.GetSelection() != 0: self.cardDescr.SetValue("????? ?? ?????????.") else: self.cardDescr.SetValue("?? ?????? reader.") def addCards( self, cardsToAdd ): if self.readerChoice.GetSelection() != 0: self.cardDescr.SetValue( self.scOps.getATR(self.selectedReader) ) if self.START == True: rpdb2.settrace() if self.step != None: self.step.release() #self.cardEvent.set() def OnReset( self, event ): if self.step != None: self.step = None self.START = False self.logArea.AppendText("????? ????????. ??? ?????? ??????? ?????\n") event.Skip() def OnClose( self, event ): sys.exit() event.Skip() def OnStart( self, event ): self.START = True self.step = threading.Semaphore(0) if self.step == 0: #start process #STAGE 1 self.logArea.AppendText( "1. ?????????? ???????? ?????????????? ????? ? reader\n" ) iccid, plainIccid = self.stage1() if iccid == None: event.Skip() return None self.logArea.AppendText( "?????????? ?????? ?????????????? ?????\n" ) #STAGE 2 self.logArea.AppendText( "2. ?????????? ???????? SAM ????? ? reader\n" ) adm0 = self.stage2( plainIccid ) if adm0 == None: event.Skip() return None self.logArea.AppendText( "?????????? ?????? SAM ?????\n" ) #STAGE 3 self.logArea.AppendText( "3. ?????????? ???????? ?????????????? ????? ? reader\n" ) result = self.stage3(iccid, adm0) if result == True: self.logArea.AppendText( "????? ??????? ??????????\n" ) else: self.logArea.AppendText( "?????? ????????? ?????.\n" ) else: self.logArea.AppendText( "??????? ??? ???????? ? ???????????? ??????????????????. ??????? ????? ? ??????? ??????\n" ) self.step = None self.START = False def stage1( self ): #wait SIM card insertion while self.step != 1: pass rpdb2.settrace() ###########################BLOCKING HERE################################## if not self.cardEvent.isSet(): self.cardEvent.wait() self.cardEvent.clear() #check inserted card is a SIM card msg, atr = self.scOps.getATR( self.selectedReader ) while atr == SAM_ATR: self.logArea.AppendText( "??????????? ????? ???????? SAM ??????. ?????????? ???????? SIM ????? ? reader\n" ) ########## Decrement semaphore value############## self.step.acquire() msg, atr = self.scOps.getATR( self.selectedReader ) if msg != "Ok": self.logArea.AppendText( "?????? ?????? ?????. ??????? ????? ? ??????? ??????\n" ) return None, None #read iccid of sim card msg, iccid, plainIccid = self.scOps.getICCID( self.selectedReader ) if msg != "Ok": self.logArea.AppendText( "?????? ?????? ?????. ??????? ????? ? ??????? ??????\n" ) return None, None return iccid, plainIccid def stage2( self, iccid ): #wait SAM card insertion while self.step != 2: pass #while not self.cardEvent.isSet(): # self.cardEvent.wait() #self.cardEvent.clear() #check is it SAM card msg, atr = self.scOps.getATR( self.selectedReader ) while atr != SAM_ATR: self.logArea.AppendText( "??????????? ????? ???????? ?? SAM ??????. ?????????? ???????? SAM ????? ? reader\n" ) ########## Decrement semaphore value############## self.step.acquire() msg, atr = self.scOps.getATR( self.selectedReader ) if msg != "Ok": self.logArea.AppendText( "?????? ?????? ?????. ??????? ????? ? ??????? ??????\n" ) return None #get ADM0 key msg, adm0 = self.scOps.getADM0( self.selectedReader, iccid ) if msg != "Ok": self.logArea.AppendText( "?????? ?????? ? SAM ??????. ??????? ????? ? ??????? ??????\n" ) return None return adm0 def stage3( self, old_iccid, adm0 ): #wait SIM card insertion while self.step != 3: pass #while not self.cardEvent.isSet(): # self.cardEvent.wait() #self.cardEvent.clear() #check ATR msg, atr = self.scOps.getATR( self.selectedReader ) while atr == SAM_ATR: self.logArea.AppendText( "??????????? ????? ???????? ?? SAM ??????. ?????????? ???????? SAM ????? ? reader\n" ) ########## Decrement semaphore value############## self.step.acquire() msg, atr = self.scOps.getATR( self.selectedReader ) if msg != "Ok": return False #check iccid msg, new_iccid, plain_new_iccid = self.scOps.getICCID( self.selectedReader ) if msg != "Ok": return False while old_iccid != new_iccid: if old_iccid != new_iccid: self.logArea.AppendText( "? reader ????????? ????? ? ICCID=" + str(new_iccid) + ". ????????? ??????? ????? ? ICCID=" + str(old_iccid)) msg = self.scOps.chgEfLnd(plain_new_iccid, adm0) if msg != "Ok": return False return True def OnSaveLog(self, event): dlg = wx.FileDialog(self, "Choose a file", ".", "", "*.*", wx.OPEN) try: if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() logfile = open(filename, 'w') logfile.write(self.logArea.GetValue()) logfile.close() finally: dlg.Destroy() def showMessage( self, message, title): msgWin = wxMessageDialog ( None, message, title, wxOK ) msgWin.ShowModal() msgWin.Destroy() class ReadersObserver: def __init__ ( self, frame ): self.mainFrame = frame def update( self, observable, ( addedreaders, removedreaders ) ): self.mainFrame.removeReaders( removedreaders ) self.mainFrame.addReaders( addedreaders ) class CardsObserver: def __init__( self, frame ): self.mainFrame = frame def update( self, observable, ( addedcards, removedcards ) ): self.mainFrame.removeCards( removedcards ) self.mainFrame.addCards( addedcards ) class appChgLnd(wx.PySimpleApp): def OnInit(self): #create frame self.appFrame = appMainFrame(None, "SimUpdate") self.SetTopWindow( self.appFrame ) #create observer class instances readersObserver = ReadersObserver( self.appFrame ) cardsObserver = CardsObserver( self.appFrame ) #subscribe to readers monitor and card monitor self.cardsMonitor = CardMonitor() self.cardsMonitor.addObserver( cardsObserver ) self.readersMonitor = ReaderMonitor() self.readersMonitor.addObserver( readersObserver ) #show frame self.appFrame.Show(True) return True if __name__ == '__main__': try: app = appChgLnd(0) app.MainLoop() except: traceback.print_exc( file=open('errors.log', 'w')) ########################################## CARD OBSERVER################################### from sys import exc_info from threading import Thread, Event from time import sleep from smartcard.System import readers from smartcard.Exceptions import CardRequestTimeoutException from smartcard.Observer import Observer from smartcard.Observer import Observable from smartcard.CardType import AnyCardType from smartcard.CardRequest import CardRequest # CardObserver interface class CardObserver(Observer): """ CardObserver is a base abstract class for objects that are to be notified upon smartcard reader insertion/removal. """ def __init__(self): pass def update( self, observable, (addedcards, removedcards) ): """Called upon reader insertion/removal. observable: addedcards: list of added readers causing notification removedcards: list of removed readers causing notification """ pass class CardMonitor: """Class that monitors smart card insertion/removal. and notify observers """ class __CardMonitorSingleton( Observable ): """The real smartcard monitor class. A single instance of this class is created by the public CardMonitor class. """ def __init__(self): Observable.__init__(self) self.rmthread=None def addObserver(self, observer): """Add an observer. We only start the card monitoring thread when there are observers. """ Observable.addObserver( self, observer ) if self.countObservers()>0 and self.rmthread==None: self.rmthread = CardMonitoringThread( self ) def deleteObserver(self, observer): """Remove an observer. We delete the CardMonitoringThread reference when there are no more observers. """ Observable.deleteObserver( self, observer ) if self.countObservers()==0: if self.rmthread!=None: self.rmthread=None # the singleton instance = None def __init__(self): if not CardMonitor.instance: CardMonitor.instance = CardMonitor.__CardMonitorSingleton() def __getattr__(self, name): return getattr(self.instance, name) class CardMonitoringThread: """Card insertion thread. This thread waits for card insertion. """ class __CardMonitoringThreadSingleton( Thread ): """The real card monitoring thread class. A single instance of this class is created by the public CardMonitoringThread class. """ def __init__(self, observable): Thread.__init__(self) self.observable=observable self.stopEvent = Event() self.stopEvent.clear() self.cards = [] self.cardrequest = CardRequest( timeout=2 ) self.setDaemon(True) # the actual monitoring thread def run(self): """Runs until stopEvent is notified, and notify observers of all card insertion/removal. """ while self.stopEvent.isSet()!=1: try: currentcards = self.cardrequest.waitforcardevent() addedcards=[] for card in currentcards: if not self.cards.__contains__( card ): addedcards.append( card ) removedcards=[] for card in self.cards: if not currentcards.__contains__( card ): removedcards.append( card ) if addedcards!=[] or removedcards!=[]: self.cards=currentcards self.observable.setChanged() self.observable.notifyObservers( (addedcards, removedcards) ) except: import sys print sys.exc_info()[1] print sys.exc_info()[2] print sys.exc_info()[0] # stop the thread by signaling stopEvent def stop(self): self.stopEvent.set() # the singleton instance = None def __init__(self, observable): if not CardMonitoringThread.instance: CardMonitoringThread.instance = CardMonitoringThread.__CardMonitoringThreadSingleton( observable ) CardMonitoringThread.instance.start() def __getattr__(self, name): return getattr(self.instance, name) def __del__(self): if CardMonitoringThread.instance!=None: CardMonitoringThread.instance.stop() CardMonitoringThread.instance = None ##################################### GENERAL OBSERVER############################## Class support for "observer" pattern. The observer class is the base class for all smartcard package observers. """ from smartcard.Synchronization import * class Observer: def update(observable, arg): '''Called when the observed object is modified. You call an Observable object's notifyObservers method to notify all the object's observers of the change.''' pass class Observable(Synchronization): def __init__(self): self.obs = [] self.changed = 0 Synchronization.__init__(self) def addObserver(self, observer): if observer not in self.obs: self.obs.append(observer) def deleteObserver(self, observer): self.obs.remove(observer) def notifyObservers(self, arg = None): '''If 'changed' indicates that this object has changed, notify all its observers, then call clearChanged(). Each observer has its update() called with two arguments: this observable object and the generic 'arg'.''' self.mutex.acquire() try: if not self.changed: return # Make a local copy in case of synchronous # additions of observers: localArray = self.obs[:] self.clearChanged() finally: self.mutex.release() # Updating is not required to be synchronized: for observer in localArray: observer.update(self, arg) def deleteObservers(self): self.obs = [] def setChanged(self): self.changed = 1 def clearChanged(self): self.changed = 0 def hasChanged(self): return self.changed def countObservers(self): return len(self.obs) synchronize(Observable, "addObserver deleteObserver deleteObservers " + "setChanged clearChanged hasChanged " + "countObservers") #:~ ############################ SYNC###################### Simple emulation of Java's 'synchronized' keyword, from Peter Norvig. """ from threading import RLock def synchronized(method): def f(*args): self = args[0] self.mutex.acquire(); # print method.__name__, 'acquired' try: return apply(method, args) finally: self.mutex.release(); # print method.__name__, 'released' return f def synchronize(klass, names=None): """Synchronize methods in the given class. Only synchronize the methods whose names are given, or all methods if names=None.""" if type(names)==type(''): names = names.split() for (name, val) in klass.__dict__.items(): if callable(val) and name != '__init__' and \ (names == None or name in names): # print "synchronizing", name klass.__dict__[name] = synchronized(val) # You can create your own self.mutex, or inherit # from this class: class Synchronization: def __init__(self): self.mutex = RLock() #:~ From nephish at xit.net Tue Aug 30 13:42:41 2005 From: nephish at xit.net (nephish at xit.net) Date: 30 Aug 2005 10:42:41 -0700 Subject: trouble with time --again Message-ID: <1125423761.517155.162710@g44g2000cwa.googlegroups.com> Hey there, could someone show me where i am going wrong here? >>> date1 = '2005-01-01 8:20:00' >>> date1 = strptime('%Y-%m-%d %H:%M:%S',date1) raise ValueError("time data did not match format: data=%s fmt=%s" % ValueError: time data did not match format: data=%Y-%m-%d%H:%M:%S fmt=2005-01-01 8:20:00 i have looked over the strptime and strftime over and over, dont get where i am missing it here. thanks From usenet.20.evilspam at spamgourmet.com Sun Aug 14 16:57:29 2005 From: usenet.20.evilspam at spamgourmet.com (Chris Spencer) Date: Sun, 14 Aug 2005 20:57:29 GMT Subject: Persistent XMLRPC Connection Message-ID: I noticed the SimpleXMLRPCServer/ServerProxy creates a new socket for remote procedure call. I've written a simple IP based authentication scheme for the Server, and I'd like to include the port in the authentication, which is currently not possible since the port keeps changing. I've looked at the code in SimpleXMLRPCServer.py, xmlrpclib.py, SocketServer.py, and BaseHTTPServer.py, but it's a little overwhelming. How difficult would it be to reuse connections so that only one port per persistent client connection is used? Sincerely, Chris From claird at lairds.us Wed Aug 31 20:08:06 2005 From: claird at lairds.us (Cameron Laird) Date: Thu, 01 Sep 2005 00:08:06 GMT Subject: Calling ftp commands from python References: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> <1125521945.668330.24190@g47g2000cwa.googlegroups.com> Message-ID: In article <1125521945.668330.24190 at g47g2000cwa.googlegroups.com>, draghuram at gmail.com wrote: > >Your best bet would be to use "pexpect" module. Code may look something >like: > >import pexpect >import sys >child = pexpect.spawn ('ftp ftp.site.com') >child.expect ('Name .*: ') >child.sendline ('username') >child.expect ('Password:') >child.sendline ('password') >child.expect ('ftp> ') >child.sendline ('cd testdir') >child.expect ('ftp> ') >child.sendline ('bin') >child.expect ('ftp> ') >child.sendline ('hash') >child.expect ('ftp> ') >child.sendline ('get testfile') >child.expect ('ftp> ') >print child.before >child.sendline ('bye') > >Raghu. >~ > ... and, for those for whome pexpect is somehow infeasible, there are a variety of ways to work around its absence . From seberino at spawar.navy.mil Sat Aug 6 00:26:41 2005 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 5 Aug 2005 21:26:41 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: <11f84j8elj07271@news.supernews.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> Message-ID: <1123302401.434361.220430@g43g2000cwa.googlegroups.com> Your solution is the best of them all. However, I don't have the foggiest idea how it would be accomplished. Are you *sure* you can change design so that there is no need for a keyword like 'global'? Please enlighten me. I'd really appreciate it. Chris From gelios at rbcmail.ru Wed Aug 10 04:14:36 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Wed, 10 Aug 2005 12:14:36 +0400 Subject: MainThread blocks all others References: Message-ID: <42f9d4ef_2@news.isis.de> Hi Bryan, Thanks for your reply. I tried to test your solution, but it doesn't work, hence threading.Semaphore object hasn't method to get value of semaphore. I looked to source code of semaphore.py and find out that value is private variable. Best regards, /Gelios "Bryan Olson" wrote in message news:fRaKe.3656$zr1.2646 at newssvr13.news.prodigy.com... >I wrote: > > Make self.counter a semaphore. Untested code: > > A little clean-up. Still untested: > > import threading > > class class1: > def __init__(self): > self.counter = threading.semaphore(0) > result = self.doSomeJob() > > def increaseCounter(self): > self.counter.release() > > def doSomeJob(self): > # Busy-waiting sucks. > # while counter != 1: > # pass > self.counter.acquire() > # ... continue... > > > -- > --Bryan From fuzzyman at gmail.com Mon Aug 1 09:02:49 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 1 Aug 2005 06:02:49 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <871x5gs6oy.fsf@wilson.rwth-aachen.de> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <871x5gs6oy.fsf@wilson.rwth-aachen.de> Message-ID: <1122901369.748478.82450@g49g2000cwa.googlegroups.com> Torsten Bronger wrote: > Hall?chen! > > Peter Decker writes: > > > On 7/30/05, Torsten Bronger wrote: > > > >> I've been having a closer look at wxPython which is not Pythonic > >> at all and bad documented. Probably I'll use it nevertheless. > >> PyGTK and PyQt may have their own advantages and disadvantages. > >> > >> However, in my opinion we don't need yet another binding so thin > >> that C or C++ is shining through, but a modern replacement for > >> Tkinter with its Pythonic way of thinking. > > > > I had the exact same impression when I started working with > > wxPython: [...] I then discovered Dabo (http://dabodev.com), which > > is a full application framework, but whose UI layer is a very > > Pythonic wrapper around wxPython. I've created several apps now > > using Dabo, even though I haven't even looked at the data > > connectivity aspects of it; the UI code works fine without it. > > I'm aware of it (and there is Wax and maybe a third one). Actually > it illustrates my point quite well: These projects are small and > instable (Dabo has a developer basis of very few people, Wax has > only one); they are even worse documented; they add another layer > which slows down and requires the end-user to install another > package; they force you to test even more GUI approaches. > Wax is small enough to distribute *with* large apps. It now has several developers and part of the two 'google summer of code' projects working on it will be to generate full documentation. I find it makes writing GUI apps easier than with Tkinter and there is no speed bottleneck form the GUI code ! All the best, Fuzzy http://www.voidspace.org.uk/python > ==> They contribute heavily to Dark Cowherd's observation that "it > is shambles". > > Tsch?, > Torsten. > > -- > Torsten Bronger, aquisgrana, europa vetus From icoba at yahoo.com Tue Aug 23 06:23:01 2005 From: icoba at yahoo.com (icoba at yahoo.com) Date: 23 Aug 2005 03:23:01 -0700 Subject: Import Error ('mutual inclusion of modules'?) Message-ID: <1124792581.450156.214960@g44g2000cwa.googlegroups.com> I have the following code: A.py ==== from B import B class R: def __str__(self): return "hello world" b = B() print b B.py ==== from A import R class B: def __init__(self): self.r = R() def __str__(self): return self.r.__str__() When I try to execute A.py I get the following error: [python2.3]$ python A.py Traceback (most recent call last): File "A.py", line 1, in ? from B import B File "python2.3/B.py", line 1, in ? from A import R File "python2.3/A.py", line 1, in ? from B import B ImportError: cannot import name B I think python does not support this kind of 'mutual inclusion'. Am I right? Thanks. Cesar. From tchur at optushome.com.au Wed Aug 10 17:39:14 2005 From: tchur at optushome.com.au (Tim Churches) Date: Thu, 11 Aug 2005 07:39:14 +1000 Subject: Python-based system wins 2005 Australian Eureka Science Prize Message-ID: <42FA7402.5030208@optushome.com.au> See http://www.amonline.net.au/eureka/communications_technology/2005_winner.htm A Google search on "scamseek python" reveals the nexus with Python - see for example http://www.cs.usyd.edu.au/~lkmrl/Scamseek-Project-data-mining-conf-v0.pdf Congratulations to Prof Jon Patrick and team on their win, and for choosing Python! Tim C From russandheather at gmail.com Wed Aug 10 15:44:18 2005 From: russandheather at gmail.com (Qopit) Date: 10 Aug 2005 12:44:18 -0700 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: <1123703058.378299.133980@g47g2000cwa.googlegroups.com> How embarassing... thanks, jk. I grabbed a copy of pychecker v0.8.14 directly (not the one in SPE) and it catches it exactly as you showed. Now I wonder why the SPE one doesn't catch it (and why it is sooo comparatively slow)! Now I'm running into another snag when checking some other code I have. Pychecker gets hung up on raw_input... it actually executes code rather than just checking it, it seems. For example, the snippet below hangs pychecker:: #--- while 1: x = raw_input("meh:") #--- Curious. I'm going to look into some of the code checking capabilities (if present) of Komodo and Wing. Anyone familiar enough with their ability to comment? From gelios at rbcmail.ru Thu Aug 11 05:05:43 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Thu, 11 Aug 2005 13:05:43 +0400 Subject: MainThread blocks all others References: <42f9d4ef_2@news.isis.de> <42fa0457_2@news.isis.de> Message-ID: <42fb151d_1@news.isis.de> Dennis, I am really appreciated you comments. Thanks you very much. And let me a little bit explain idea of program. I should did it earlier. Instead of empty loops i already tried to use time.sleep() firstly, but effect was same, all other threads do not working too and as experiment i tried empty loops then. All stages as numbered should be accomplished sequently and no thread needed there. The reason of waiting in the begining of each stage is waiting insertion of Sim cards to reader. When card inserted CardMonitor which implements observer calls update() method of each subscriber. In my case this is CardsObserver.update() method. This is accomplished in seperate thread created in CardMonitor library class (by the way I just only write main application, all other sources are from framework). As you can see CardsObserver.update () calls appMainFrame.addCards method which update step semaphore. I did realize it by using semaphore based on Bryan solution. Firstly it was just only integer variable and addCards() increment it by 1. In any case I cannot understand why when MainThread is doing some action, even sleeping (time.sleep()) all other threads blocked as well. Regarding to other your comments. Honestly this is my first experience in Python and as I suppose I didn't understand main principles and ideas of Python up to now. Well, this is a way for future investigation. :) Best regards, /Gelios From http Sat Aug 6 23:19:34 2005 From: http (Paul Rubin) Date: 06 Aug 2005 20:19:34 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> Message-ID: <7xbr4ae8mx.fsf@ruckus.brouhaha.com> Cliff Wells writes: > It didn't say what they left PHP, Perl and Python for (if you are to > even believe their findings). > > PHP has been losing programmers in droves... to Ruby on Rails, but I'm > not sure how that is bad news for scripting-language fans. That's the second time in one or two days that I've heard Ruby on Rails mentioned. Can anyone here post a paragraph or two description? I sort of know what Ruby is, a very OOP-ified Perl-resemblant language, that's also implemented only as an interpreter. I can't see punting Python for it. Lately I'm interested in OCAML as a possible step up from Python. It has bogosity of its own (much of it syntactic) but it has static typing and a serious compiler, from what I understand. I don't think I can grok it from just reading the online tutorial; I'm going to have to code something in it, once I get a block of time available. Any thoughts? From noreply at gcgroup.net Wed Aug 24 11:07:27 2005 From: noreply at gcgroup.net (William Gill) Date: Wed, 24 Aug 2005 15:07:27 GMT Subject: a question about tkinter StringVars() Message-ID: Working with tkinter, I have a createWidgets() method in a class. Within createWidgets() I create several StringVars() and assign them to the textvariable option of several widgets. Effectively my code structure is: def createWidgets(self): ... var = StringVar() Entry(master,textvariable=var) ... ... Though 'var' would normally go out of scope when createWidgets completes, since the Entry and its reference do not go out of scope, only the name 'var' goes out of scope, not the StringVar object, Right? Thanks, Bill From bokr at oz.net Tue Aug 9 12:20:34 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 09 Aug 2005 16:20:34 GMT Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <7x8xzcck9d.fsf@ruckus.brouhaha.com> <86wtmvlti7.fsf_-_@bhuda.mired.org> <7xoe87vl0i.fsf@ruckus.brouhaha.com> Message-ID: <42f8c2e2.1006880848@news.oz.net> On 08 Aug 2005 20:37:01 -0700, Paul Rubin wrote: [...] >Right now I'm mainly interested in OCaml, Haskell, Erlang, and maybe >Occam. Haskell seems to have the happiest users, which is always a >good thing. Erlang has been used for real-world systems and has >built-in concurrency support. OCaml seems to crush Haskell and Erlang >(and even Java) in performance. Occam isn't used for much practical >any more, but takes a purist approach to concurrency that seems worth >studying. IIRC, I've seen something about a web server implemented in erlang with tremendous performance at high levels of concurrency where other implementations bog down. So I would want further details before I believe that all OCaml versions "crush" all Erlang versions in performance. > >The idea is to use one of those languages for a personal project after >my current work project wraps up pretty soon. This would be both a >learning effort and an attempt to write something useful. I'm >thinking of a web application like a discussion board or wiki, >intended to outperform the existing ones, i.e. able to handle a >Slashdot or Wikipedia sized load (millions of hits/day) on a single >fast PC instead of a rack full. "Single fast PC" will probably soon >come to mean a two-cpu-chip motherboard in a 1U rack box, where each >cpu chip is a dual core P4 or Athlon, so the application should be >able to take advantage of at least 4-way multiprocessing, thus the >interest in concurrency. I'd suggest finding that Erlang web server writeup. Hm, some googling ... I think this is the graph I saw: http://www.sics.se/~joe/apachevsyaws.html Can't vouch for what it means, but taken at face value would seem to warrant a further look into details. This turned up also http://eddie.sourceforge.net/txt/WP_1.0.html which I hadn't seen before, and which looks interesting though maybe stale? I guess this is a home for erlang: http://www.erlang.se/ Much other stuff, but you know how to google ;-) Regards, Bengt Richter From rich.teer at rite-group.com Sat Aug 27 18:14:54 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Sat, 27 Aug 2005 22:14:54 GMT Subject: OpenSource documentation problems In-Reply-To: <1125179974.483320.116780@g49g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1125179974.483320.116780@g49g2000cwa.googlegroups.com> Message-ID: On Sat, 27 Aug 2005, Xah Lee wrote: His usual crap. ___________________ /| /| | | ||__|| | Please do | / O O\__ NOT | / \ feed the | / \ \ trolls | / _ \ \ ______________| / |\____\ \ || / | | | |\____/ || / \|_|_|/ \ __|| / / \ |____| || / | | /| | --| | | |// |____ --| * _ | |_|_|_| | \-/ *-- _--\ _ \ // | / _ \\ _ // | / * / \_ /- | - | | * ___ c_c_c_C/ \C_c_c_c____________ -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From aweinstein at on.cl Tue Aug 30 19:41:14 2005 From: aweinstein at on.cl (Alejandro Weinstein) Date: Tue, 30 Aug 2005 20:41:14 -0300 Subject: micro-python - is it possible? In-Reply-To: <431440bb$1@news.orcon.net.nz> References: <431440bb$1@news.orcon.net.nz> Message-ID: Evil Bastard wrote: > Hi, > > Has anyone done any serious work on producing a subset of python's > language definition that would suit it to a tiny microcontroller > environment? Take a look at PyMite : http://www.python.org/pycon/papers/pymite/ From the abstract : "PyMite is a flyweight Python interpreter written from scratch to execute on 8-bit microcontrollers as well as desktop computers..." Regards, Alejandro. From rphillips at engineer.co.summit.oh.us Fri Aug 19 07:51:06 2005 From: rphillips at engineer.co.summit.oh.us (paron) Date: 19 Aug 2005 04:51:06 -0700 Subject: Python for Webscripting (like PHP) In-Reply-To: References: <1124449823.428290.206950@g47g2000cwa.googlegroups.com> Message-ID: <1124452266.755404.197360@z14g2000cwz.googlegroups.com> Yes, there's a tutorial about that -- there are several options depending on the URL structure you want to expose, and your version of Apache. None of them are torturous, though. Start at http://www.cherrypy.org/wiki/CherryPyProductionSetup and follow the links down. Ron From notanlinesgirly2 at yahoo.com Thu Aug 25 23:49:47 2005 From: notanlinesgirly2 at yahoo.com (Lacy) Date: Fri, 26 Aug 2005 03:49:47 -0000 Subject: wanna stop by my homemade glory hole? Message-ID: my husband is installing an extra bathroom poolside. there is a perfect size hole (unless you have a huge cock) to stick your dick through into the adjoing room. come around the side of my house(perfect if you look like a repair man) enter into the unfisnished bathroom and I'll service you from the other side. you can leave when your done, no talking or small talk. i want to do this before the hole gets patched up. its been a huge fantasy of mine ever since I've seen a glory hole online. you can email me for a time convienient for you. im home all-day most days so my schedule is open. do you prefer a certain color of lipstick? check out my pic and email here under kallegirl26 www.no-strings-fun.net/kallegirl26 ready and waiting, me ;o) From googlenews at tooper.org Wed Aug 24 06:52:41 2005 From: googlenews at tooper.org (tooper) Date: 24 Aug 2005 03:52:41 -0700 Subject: execfile in global scope In-Reply-To: <1124873425.620610.170970@g47g2000cwa.googlegroups.com> References: <1124873425.620610.170970@g47g2000cwa.googlegroups.com> Message-ID: <1124880761.547923.161640@g43g2000cwa.googlegroups.com> What about : globdict= globals() def changevar(): global globdict execfile("changevar.py",globdict) x = 111 # global var changevar() print x # returns 111 instead of 555 From nephish at xit.net Tue Aug 30 13:54:29 2005 From: nephish at xit.net (nephish at xit.net) Date: 30 Aug 2005 10:54:29 -0700 Subject: trouble with time --again In-Reply-To: References: <1125423761.517155.162710@g44g2000cwa.googlegroups.com> Message-ID: <1125424469.858102.178260@f14g2000cwb.googlegroups.com> OH my god. youre right. i feel like a complete idiot. thanks From Facundo.Batista at telefonicamoviles.com.ar Wed Aug 3 16:22:08 2005 From: Facundo.Batista at telefonicamoviles.com.ar (Batista, Facundo) Date: Wed, 3 Aug 2005 17:22:08 -0300 Subject: PyAr - Python Argentina 10th Meeting, Thursday, August 4th Message-ID: <55018DD359F5B147861F150F4689161E0BA5B3F6@escont.tcp.com.ar> The Argentine Python User Group, PyAr, will have its tenth meeting this Thursday, August 4th at 7:00pm. Agenda ------ Despite our agenda tends to be rather open, this time we would like to cover these topics: - Discuss present and future of the messaging framework Gauchito Gil (http://www.python.com.ar/Wiki/GauchitoGil) - See if we move to other meeting point. - Discuss website function and see if we go for another content manager. Where ----- We're meeting at Hip Hop Bar, Hip?lito Yirigoyen 640, Ciudad de Buenos Aires, starting at 19hs. We will be in the back room, so please ask the barman for us. About PyAr ---------- For more information on PyAr see http://pyar.decode.com.ar (in Spanish), or join our mailing list (Also in Spanish. For instructions see http://pyar.decode.com.ar/Members/ltorre/listademail) We meet on the second Thursday of every month. . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 gregpinero at gmail.com Tue Aug 2 14:55:18 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 2 Aug 2005 14:55:18 -0400 Subject: py2exe windows apps path question In-Reply-To: References: <11ev0tcg9n2ndd@corp.supernews.com> Message-ID: <312cfe2b0508021155132d062d@mail.gmail.com> > If you need something that works both on a frozen app as well as an > (unfrozen) python > script, you'd be better off using something like: > > def getAppPrefix(): > """Return the location the app is running from > """ > isFrozen = False > try: > isFrozen = sys.frozen > except AttributeError: > pass > if isFrozen: > appPrefix = os.path.split(sys.executable)[0] > else: > appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0] > return appPrefix > Vincent, This sounds interesting. A few questions for you: Why don't I see sys.frozen in interpreter? Does it only appear when it is frozen? What do you mean by frozen, how does python know? What does sys.executable do? Thanks, Greg From fakeaddress at nowhere.org Tue Aug 30 07:56:24 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 30 Aug 2005 11:56:24 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> < Message-ID: Robert Kern wrote: > Bryan Olson wrote: > > >> Currently, user-defined classes can implement Python >> subscripting and slicing without implementing Python's len() >> function. In our proposal, the '$' symbol stands for the >> sequence's length, so classes must be able to report their >> length in order for $ to work within their slices and >> indexes. >> >> Specifically, to support new-style slicing, a class that >> accepts index or slice arguments to any of: >> >> __getitem__ >> __setitem__ >> __delitem__ >> __getslice__ >> __setslice__ >> __delslice__ >> >> must also consistently implement: >> >> __len__ >> >> Sane programmers already follow this rule. > > > Incorrect. Some sane programmers have multiple dimensions they need to > index. > > from Numeric import * > A = array([[0, 1], [2, 3], [4, 5]]) > A[$-1, $-1] > > The result of len(A) has nothing to do with the second $. I think you have a good observation there, but I'll stand by my correctness. My initial post considered re-interpreting tuple arguments, but I abandoned that alternative after Steven Bethard pointed out how much code it would break. Modules/classes would remain free to interpret tuple arguments in any way they wish. I don't think my proposal breaks any sane existing code. Going forward, I would advocate that user classes which implement their own kind of subscripting adopt the '$' syntax, and interpret it as consistently as possible. For example, they could respond to __len__() by returning a type that supports the "Emulating numeric types" methods from the Python Language Reference 3.3.7, and also allows the class's methods to tell that it stands for the length of the dimension in question. -- --Bryan From kyle.tk at gmail.com Wed Aug 31 01:20:20 2005 From: kyle.tk at gmail.com (kyle.tk) Date: 30 Aug 2005 22:20:20 -0700 Subject: dynamicly updating an objects fields Message-ID: <1125465620.219693.187500@g47g2000cwa.googlegroups.com> I want to make a function that will work like this: def updateField(object, fieldName, newValue): object.fieldName = newValue fieldName could be anything, the list of objects fields will grow as my project goes on and i want to reuse the same code without adding more if statements to it this is the only way I can see doing it right now: def updateField(object, fieldName, newValue): if fieldName = 'name': nodeDict[nodeID].name = newValue if fieldName = 'color': nodeDict[nodeID].color = newValue ..many more if's.. is the top example possible? From fakeaddress at nowhere.org Mon Aug 29 15:55:20 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 29 Aug 2005 19:55:20 GMT Subject: Virtual Slicing In-Reply-To: References: Message-ID: Sybren Stuvel wrote: > Bryan Olson enlightened us with: > >>I recently wrote a module supporting value-shared slicing. > > Maybe I'm dumb, but could you explain this concept? Why would someone > whant this? My original motivation was reduce the amount of copying in some tools that parse nested structures. All I really needed at the time was a reference to a string, and the start and stop values. Once I adopted Python's sequence interface, I thought I might as well implement it consistently, generally, and completely. So the first reason someone might want this is for efficiency, in space and/or time. The second reason is more abstract. Python's slice assignment is a useful feature, but the slice selection must appear on the right-hand-side of assignment. VSlice lets one instantiate the updatable slice as an object, and pass it around. I looked into supporting slice assignment between slices of different sizes when possible, but the various options I came up with all sucked. -- --Bryan From rkern at ucsd.edu Tue Aug 2 21:37:58 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 02 Aug 2005 18:37:58 -0700 Subject: HELP:sorting list of outline numbers In-Reply-To: References: Message-ID: Felix Collins wrote: > Hi All, > does anyone know any cleaver tricks to sort a list of outline numbers. > > An outline number is a number of the form... 1.2.3 > > they should be sorted in the following way... > > 1 > 1.1 > 1.2 > 1.12 > > python's alpha sort (by design) sorts them... > > 1 > 1.1 > 1.12 > 1.2 > > That's no good for me. > I'm planning on splitting the strings into multiple lists of ints and > doing numerical sorts. > > Thanks for any clever ideas that might make it easier. Use the "key" keyword argument to list.sort(). In [1]: outline = ['1.12', '1.1', '1', '1.2'] In [2]: outline.sort(key=lambda x: map(int, x.split('.'))) In [3]: outline Out[3]: ['1', '1.1', '1.2', '1.12'] -- 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 jdennett at acm.org Mon Aug 8 03:32:24 2005 From: jdennett at acm.org (James Dennett) Date: Mon, 08 Aug 2005 00:32:24 -0700 Subject: How to determine that if a folder is empty? In-Reply-To: <3loeiiF139eh3U1@individual.net> References: <3loeiiF139eh3U1@individual.net> Message-ID: Reinhold Birkenfeld wrote: > could ildg wrote: > >>I want to check if a folder named "foldername" is empty. >>I use os.listdir(foldername)==[] to do this, >>but it will be very slow if the folder has a lot of sub-files. >>Is there any efficient ways to do this? > > > try: > os.rmdir(path) > empty = True > except OSError: > empty = False > > should be efficient. A directory (please stop calling them "folders") > can only be removed if it's empty. > > Reinhold Unfortunately that destroys the directory if it was empty, and then you can't recreate it unless (a) you went to the trouble of preserving all of its attributes before deleting it, and (b) your script has OS-level permissions to recreate the directory with its original attributes (such as owners and permissions). Also note that modifying a filesystem can be significantly slower than reading from it (it varies widely across platforms). -- James From zen19725 at zen.co.uk Wed Aug 10 10:36:36 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 10 Aug 2005 15:36:36 +0100 Subject: What is Python?! References: Message-ID: On Wed, 10 Aug 2005 13:14:26 +0200, Robert Wierschke wrote: >hi > >I'm learning python since 3 days. I' ve some programming experience in >BASIC, Pascal, C, C++ and Java. Actually I want to add a scripting >language to this repertoire (I have virtually no experience with >scripting). > >Having read that python is object orientated, I start wondering if >python is the right choice and what it is... > > a scripting language or a "normal" language like C++ etc. Both. >So please tell me what python is, what are it's strength, what is it >good for and when should I use it and not one of the other languages. > >other questions: >What about graphic? Can I create graphical interfaces with python? There are several GUIs available, for example Tkinter. >Python is interpreted but is it compiled to something like the java byte >code Yes. It is compiled to .pyc files which are then interpreted; exactly the same idea that java uses. -- Email: zen19725 at zen dot co dot uk From apardon at forel.vub.ac.be Tue Aug 23 07:49:51 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 Aug 2005 11:49:51 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-23, Magnus Lycka schreef : > Antoon Pardon wrote: >> Following a well defined specification is not contradictory >> to guessing. It may just mean that the guess was formalized >> into the specification. > > If you want the behaviour of Python to change, you should > write a PEP. Such a PEP would have no chance of being accepted, since it would break to much existing code. > It always felt natural to me to interpret empty > as false, but I could be wrong. It's strange that this flaw > managed to go unnoticed for so long though... The problem with interpreting empty as false is that empty just means no data now. But no data now can mean no data yet or it can mean no more data. The problem is not so much as having empty interpreted as false but that people don't seem to think about which false value would be more appropiate in particular circumstances. IMO reading '' from network connection is the most natural result when no data is ready and this should be treated differently from an EOF which would indicate the connection was closed. But how can you do this when somewhere else '' is used as an indication for an EOF. > If Python is too "wild" for your taste, you might like OCaml. > >> Well then I must say people here give beauty too high a priority. >> Because there seems a tendency to beautify others code when >> snippets are posted here. Often enough such snippets >> don't give enough inoformation to know whether "if var is True:" >> can be replaced by "if var:" or whether other beautifications are >> appropiate. > > You might be right about that. I didn't really notice. > > I think the typical comment is to replace "if s != '':" with > "if s:" in contexts where s is always a string, And it is IMO this kind of comments that lead to '' being used as an EOF. > or to replace > "if expr != False:" with "if expr": in cases where "expr" is an > expression that returns True or False etc. In some cases, obvious > bugs, such as "if (a and b) == True:" where the programmer > should have written "if (a and b):" are pointed out. This is not such an obvious bug. Because python allows non boolean operands with "and" the two don't behave the same. How do you know which behaviour the other person wants? > Many of us have a solid mathematical education, and in that world > it's considered good behaviour to simplify expressions and remove > redundancy. I have yet to see a mathematical work where 0, or any kind of empty sequence is treated as false. In mathematics accuracy is considered vitaly important and won't be sacrified to remove redundancy. Boolean expression are always written out fully. > If we see things such as redundant pieces in logic expressions, > functions ending in "return None", returns directly after a raise, > or other meaningless constructs, it suggests that someone might be > doing something they don't understand, and then it's helpful to > try to point that out. But you don't know if the logic expression are redundant. The suggestions made are usually not equivallent. > It's really important to understand what we do when we're > programming, not just repeat mantras or wave dead chickens. > > If people mechanically learn "I shouldn't use '!= False' in > if-statements in Python", we've failed in trying to help them. > If people learn what Python considers true and false, what the > boolean operators return, and understands how to use these > things in an effective way, we've succeeded. > > Another aspect of this particular idiom is that it's often better > to use the exception system in Python for exceptional situations, > than to use one variable to carry several different kinds of > information. In that case you wouldn't return an empty sequence if you wanted a false value in a sequence context but would throw an exception. So this would be fine by me, I just don't understand how this would support the use of empty sequences as false. I also don't see how a read from a network connection returning either: a bytestring when data is available, '' when no data is available None when the connection was closed As so much different kinds of information. Besides sometimes different kinds of information is not that exceptional, so why should I throw an exception in such a case? -- Antoon Pardon From johnjsal at NOSPAMgmail.com Thu Aug 18 14:55:01 2005 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Thu, 18 Aug 2005 18:55:01 GMT Subject: up to date books? In-Reply-To: <1124389787.873698.205070@g47g2000cwa.googlegroups.com> References: <1124389787.873698.205070@g47g2000cwa.googlegroups.com> Message-ID: <9Q4Ne.974$No6.23346@news.tufts.edu> These all seem to be focused on Java though. gene tani wrote: > Start here: > > http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing > http://dirtsimple.org/2004/12/java-is-not-python-either.html > http://ischenko.blogspot.com/2005/02/java-may-not-be-that-bad-after-all.html > > and maybe poke around ehre to learn about language design, how people > define typing, etc > http://www.artima.com/ > From en.karpachov at ospaz.ru Fri Aug 19 06:11:13 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Fri, 19 Aug 2005 14:11:13 +0400 Subject: while c = f.read(1) In-Reply-To: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <20050819141113.69536258.jk@ospaz.ru> On 18 Aug 2005 22:21:53 -0700 Greg McIntyre wrote: > I have a Python snippet: > > f = open("blah.txt", "r") > while True: > c = f.read(1) > if c == '': break # EOF > # ... work on c > > Is some way to make this code more compact and simple? It's a bit > spaghetti. import itertools f = open("blah.txt", "r") for c in itertools.chain(*f): print c # ... The "f" is iterable itself, yielding a new line from the file every time. Lines are iterable as well, so the itertools.chain iterates through each line and yields a character. -- jk From greg at puyo.cjb.net Wed Aug 24 21:18:10 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 24 Aug 2005 18:18:10 -0700 Subject: while c = f.read(1) In-Reply-To: <430ba590@news.eftel.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> <1124705414.704694.241960@f14g2000cwb.googlegroups.com> <430ba590@news.eftel.com> Message-ID: <1124932690.531735.136340@g43g2000cwa.googlegroups.com> John Machin wrote: > Sigh indeed. If you need to read it a character at a time to parse it, > the design is f***ed. There is always the potential to do 2k buffered reads and once in memory pick the contents apart character-wise. I assume something similar would happen for tokenising XML and HTML which would presumably often 'read until "<"'. From luismgz at gmail.com Mon Aug 8 08:42:40 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 8 Aug 2005 05:42:40 -0700 Subject: IronPython 0.9 Released In-Reply-To: References: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> <20050804230820.1518126954.EP@zomething.com> <20050804231232.85365666.EP@zomething.com> Message-ID: <1123504960.672394.4820@g44g2000cwa.googlegroups.com> could ildg wrote: > Why is iron python runs so fast but jython runs so slow while C# and > java seem very much the same? I've been playing with Ironpython since its first release and, in my experience, it is not faster than Cpython, although this is what they claim. Anyway, it is in alpha stage so lets wait until it's mature... From jgrh2 at hermes.cam.ac.uk Mon Aug 1 05:01:43 2005 From: jgrh2 at hermes.cam.ac.uk (J.G.R. Hewer) Date: Mon, 1 Aug 2005 10:01:43 +0100 (BST) Subject: Python IDE's In-Reply-To: References: <20050731205901.53A6E1E4005@bag.python.org> Message-ID: Thanks for your reply - that link is very useful, and i have been browsing through the various multiplatform editors/ide's (i'm looking for something to use on both my Windows machines and my Mac) There are so many options, just wondering if anyone could recommend an IDE? I have tried Eclipse with PyDev but i'm getting problems with this on my Mac (works nicely on Windows tho!). I have tried SPE but it kept crashing on me on my Mac (maybe this will be fixed in the latest release, which should go final soon) Jedit looks quite good, but does it actually let you run your Python code from within Jedit, or does it merely provide syntax highlighting etc? Cheers Jon On Mon, 1 Aug 2005, Martin Franklin wrote: > Jon Hewer wrote: >> Hi >> >> >> >> I am yet to find a Python IDE (for both Windows and Mac) that I like. >> Any suggestions? >> >> >> >> Thanks >> > > > See:= > > http://wiki.python.org/moin/PythonEditors > > > For more help > > Thanks > Martin > > > -- > http://mail.python.org/mailman/listinfo/python-list > From kay.schluehr at gmx.net Sat Aug 6 06:24:23 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 6 Aug 2005 03:24:23 -0700 Subject: Decline and fall of scripting languages ? Message-ID: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> No good news for scripting-language fans: http://www.phpmag.net/itr/news/psecom,id,23284,nodeid,113.html Regards Kay From nidoizo at yahoo.com Mon Aug 8 13:22:38 2005 From: nidoizo at yahoo.com (Nicolas Fleury) Date: Mon, 08 Aug 2005 13:22:38 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <1123493200.390420.160040@g44g2000cwa.googlegroups.com> References: <42F66FF2.7010901@v.loewis.de> <1123481295.549324.99810@g49g2000cwa.googlegroups.com> <4iEJe.5130$651.540962@weber.videotron.net> <1123493200.390420.160040@g44g2000cwa.googlegroups.com> Message-ID: Kay Schluehr wrote: > I have to admit that i don't actually understand what you want? The > problems you try to solve seem trivial to me but it's probably my fault > and i'm misreading something. You might be correct that your PEP may be > interesting only if "optional static typing" will be introduced to Py3K > and then we will suddenly have an immediate need for dealing with > generic types so that the syntax can be reused for deferred functions ( > the concept of "specialization" is usually coupled with some kind of > partial evaluation which doesn't take place somewhere in your proposal > ). But i'm not sure if this makes sense at all. Well, the partial evaluation is done when using []. def getMember[memberName](obj): return getattr(obj, memberName) x = getMember["xyz"] # specialization y = x(obj) # use I realize the term "specialization" can be confusing, since people might think of what is called in C++ "explicit specialization" and "partial specialization", while these concepts are not present in the PEP. The point is that I'm already using static-like typing in frameworks interacting with other languages with generic types. So I would already benefit from such a capability, and yes, there's workarounds. I'm clearly in a minority with such a need, but the first point fo the PEP is to extend [] syntax, so that it is possible to prototype generic types using [] operators. Regards, Nicolas From peter at engcorp.com Mon Aug 22 20:12:00 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 20:12:00 -0400 Subject: Best way to 'touch' a file? In-Reply-To: References: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Message-ID: Fredrik Lundh wrote: > Peter Hansen wrote: >>I guess it depends on whether "touch" implies creation-when-missing, as >>with the command line version, or just updating the time. > > the OP wanted "to update the modification time of a file without actually > modifying it". os.utime does exactly that; no more, no less, and no extra > dependencies. You've quoted selectively. He also said "Unix-style 'touch'", from which one could quite legitimately infer he wants the other features of the Unix touch command, including the automatic creation of missing files. Unless you know something more about the OP's needs than he's posted publicly, you're just guessing too... even if we both agree yours is the more likely interpretation. -Peter From bdesth.quelquechose at free.quelquepart.fr Thu Aug 11 18:55:04 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 12 Aug 2005 00:55:04 +0200 Subject: len(sys.argv) in (3,4) In-Reply-To: <42fbc789$1@news.eftel.com> References: <42fb7498$0$11771$626a14ce@news.free.fr> <42fbc789$1@news.eftel.com> Message-ID: <42fbcfbc$0$7473$636a15ce@news.free.fr> John Machin a ?crit : > bruno modulix wrote: > (snip) >> >> Nope. But since you're running this on a very peculiar OS, I just can >> guess that this very peculiar OS consider all args to be one same >> string... > > > NOT SO: Your cap key got stuck ? (snip) > For *any* OS: More than one CLI (command line interpreter) a.k.a. shell > may be available. "may"... BTW, I don't remember anything like a shell in MacOS 7... (please don't tell me about AppleScript). > What they do with the remainder of the command line > after the pathname of the executable (binary program or script or > whatever) is up to them, but I have never seen any which would lump > space-separated tokens into one arg without some quoting convention > having to be used. I guess I have had so frustrating experiences with Windows that I assume that anything that goes against common sens can happen !-) (snip) >> BTW, isn't the DOS syntax for command line args something like : >> >>> myprog /arg1 /arg2 > > Which DOS do you mean? IBM DOS/VS? AmigaDOS? MS-DOS? QDOS, of course !-) > The likelihood is that the OP is not running any of these, but is > running a recent version of Windows. Yes. I meant the (hum) CLI interface - which is still called "the DOS" by a lot of Windows users I know (at least those who already used MS-DOS before Windows became an OS). > The standard CLI (cmd.exe) does use > a syntax for built-in commands where '/' is used for options where a *x > shell would use '-'; however this is sublimely irrelevant. I like the use of "sublimely" in this context. > Python scripts get their args on Windows just like anywhere else. Ever used Python on MacOS Classic ? Ok, now we know that the CLI syntax is not the problem - which may be useful for the OP, thanks John -, and that John Machin tend to be somewhat reactive when one says that Windows is a somewhat peculiar OS - which is not really a useful information, but what... From hancock at anansispaceworks.com Wed Aug 31 17:59:35 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 31 Aug 2005 16:59:35 -0500 Subject: OpenSource documentation problems In-Reply-To: References: Message-ID: <200508311659.35743.hancock@anansispaceworks.com> On Wednesday 31 August 2005 07:14 am, Bryan Olson wrote: > Terry Hancock wrote: > > Bryan Olson wrote: > Then how does one distinguish stable, supported services, from > incidental behavior that can change without notice? Surprisingly often, "common sense" seems to be a workable answer here. I'm not being sarcastic, but I do find that the changes in Python over different versions have generally not caused a lot of surprise for me. I admit that's a weak answer. > > 4) But if you want a more theoretical and explained version of the > > language, there's always the "Language Reference". > > Which is what steered me wrong on the behavior of slice objects: Huh. Well, I always consider slices a bit tricky, so I always test those things out in the interpreter before using them in a real program. I guess that's why they don't bother me. > Whatever else one says about open-source documentation, keeping > it current is a major unsolved problem. Yes. But I think the real problem is that the nature of open-source documentation ensures that the old, out-of-date version will always be competing with the newer version. Dates on documentation are not only not always kept up, but even when they are, they are often deceptive (e.g. they don't actually reflect the last update or the last update ignored significant outdated material). Then again, I saw a textbook with a very similar problem not that long ago. There was a reference to a certain thing being common "20 years ago", but I was pretty sure it's more like 40. I suspect that it was copied from a 20-year-old edition of the same book without being updated. > > I have NEVER seen a closed source application or programming > > language that came with that much documentation and support. > > I'm no fan of Microsoft, but in general, the Win32 API is far > better documented than is Python. (Just don't use the searching > facilities on the MSDev CD's to find the doc; Google it up.) Okay, I was being a little bit tricky here, too. I said I'd *never seen* better documentation on a closed source application. It's unclear to me whether that means it doesn't exist, or I just can't get hold of it, because it's closed source code. > [...] > > I also have to say, that as a module writer, Python's support > > for self-documenting code or "literate programming" is excellent. > > I'm really coming to appreciate the value of this. > > Unfortunately, it's also full of traps. Sorry? I missed that part. What "traps" are you referring to? I can see for example that there's more than one mark-up language for doc strings and I wasn't too happy with the state of happydoc, which has apparently never been fully updated to version 3. So I converted to epydoc. This did not take a massive amount of time, though. If there are "traps", I think I would like to hear more about it. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From martin at v.loewis.de Sun Aug 21 16:38:10 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 21 Aug 2005 22:38:10 +0200 Subject: pythonXX.dll size: please split CJK codecs out In-Reply-To: References: <43082c5f$0$31577$9b622d9e@news.freenet.de> Message-ID: <4308e632$0$31533$9b622d9e@news.freenet.de> Ron Adam wrote: > I would put the starting minimum boundary as: > > 1. "The minimum required to start the python interpreter with no > additional required files." > > Currently python 2.4 (on windows) does not yet meet that guideline, so > it seems some modules still need to be added while other modules, (I > haven't checked which), are probably not needed to meet that guideline. I'm not sure, either, but I *think* python24 won't load any .pyd file on interactive startup. > This could be extended to: > > 2. "The minimum required to run an agreed upon set of simple Python > programs." > > I expect there may be a lot of differing opinions on just what those > minimum Python programs should be. But that is where the PEP process > comes in. As I mentioned earlier, there also should be a negative list: modules that depend on external libraries should not be incorporated into python24.dll. Most notably, this rules out zlib.pyd, _bsddb.pyd, and _ssl.pyd, all of which people may consider to be useful into these simple programs. Regards, Martin From maxerickson at gmail.com Fri Aug 12 13:49:44 2005 From: maxerickson at gmail.com (max) Date: Fri, 12 Aug 2005 17:49:44 -0000 Subject: UCALC equivalent References: <42FCDCA7.7030107@syscononline.com> Message-ID: Larry Bates wrote in news:42FCDCA7.7030107 at syscononline.com: > Python has built in eval function and doesn't require > a library. > > Larry Bates > Are you kidding? Read the original post a little more closely. The o.p. is looking for a library that evaluates mathematical expressions and is callable from python code. max From dickinsm at verizon.net Thu Aug 25 12:44:24 2005 From: dickinsm at verizon.net (Mark Dickinson) Date: Thu, 25 Aug 2005 16:44:24 GMT Subject: Speed quirk: redundant line gives six-fold speedup Message-ID: I have a simple 192-line Python script that begins with the line: dummy0 = 47 The script runs in less than 2.5 seconds. The variable dummy0 is never referenced again, directly or indirectly, by the rest of the script. Here's the surprise: if I remove or comment out this first line, the script takes more than 15 seconds to run. So it appears that adding a redundant line produces a spectacular six-fold increase in speed! (Actually, I had to add 29 dummy lines at the beginning of the code to get the speed increase; if any one of these lines is removed the running time reverts to around 15 seconds again.) Questions: (1) Can anyone else reproduce this behaviour, or is it just some quirk of my setup? (2) Any possible explanations? Is there some optimization that kicks in at a certain number of lines, or at a certain length of bytecode? (3) If (2), is there some way to force the optimization, so that I can get the speed increase without having to add the extra lines? I'm running Python 2.4.1 on a 1.2Ghz iBook G4: Python 2.4.1 (#1, May 21 2005, 19:56:42) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin I've posted the code below, with some trepidation, since it's not a work of art and wasn't really intended to be seen by other human beings. It's necessarily quite long: any attempt to shorten it significantly seems to cancel the speed gain. Any clues as to what might be going on would be greatly appreciated! Mark # code starts here dummy0 = 47 dummy1 = 47 dummy2 = 47 dummy3 = 47 dummy4 = 47 dummy5 = 47 dummy6 = 47 dummy7 = 47 dummy8 = 47 dummy9 = 47 dummy10 = 47 dummy11 = 47 dummy12 = 47 dummy13 = 47 dummy14 = 47 dummy15 = 47 dummy16 = 47 dummy17 = 47 dummy18 = 47 dummy19 = 47 dummy20 = 47 dummy21 = 47 dummy22 = 47 dummy23 = 47 dummy24 = 47 dummy25 = 47 dummy26 = 47 dummy27 = 47 dummy28 = 47 # Sudoku puzzle solver via Knuth's method of `dancing links'. # Initial data: list of constraints, list of moves, and map from moves to lists of constraints template = (" | %s %s %s | %s %s %s | %s %s %s |\n" * 3).join([" +-------+-------+-------+\n"] * 4) div_nums = range(9) symbols = "123456789" constraints = ["position %d, %d" % (i, j) for i in div_nums for j in div_nums] + \ ["%s in %s %d" % (i, j, k) for i in symbols for j in ["row", "column", "block"] for k in div_nums] satisfies = dict(((s, i, j), ["position %d, %d" % (i, j), "%s in row %d" % (s, i), "%s in column %d" % (s, j), "%s in block %d" % (s, i-i%3+j//3)]) for s in symbols for i in div_nums for j in div_nums) moves = satisfies.keys() class LLentry(object): pass # First set up the data objects and column objects def rowhead(obj): obj.L = obj.R = obj.M = obj def colhead(obj): obj.U = obj.D = obj.C = obj obj.S = 0 def rowinsert(obj, pos): # insert into doubly-linked list with header pos posL = pos.L obj.R = pos pos.L = obj obj.L = posL posL.R = obj obj.M = pos def colinsert(obj, pos): # as above posU = pos.U obj.D = pos pos.U = obj obj.U = posU posU.D = obj obj.C = pos pos.S += 1 def rowitems(pos): c = pos.R while c is not pos: yield c c = c.R def move(m): cc = m.R while cc is not m: c = cc.C c.R.L = c.L; c.L.R = c.R r = c.D while r is not c: j = r.R while j is not r: j.D.U = j.U j.U.D = j.D j.C.S -= 1 j = j.R r = r.D cc = cc.R moves_so_far.append(m) h = LLentry() rowhead(h); colhead(h) constraint_from_name = {} for name in constraints: obj = LLentry() obj.N = name; constraint_from_name[name] = obj rowinsert(obj, h); colhead(obj) obj.S = 0 move_from_name = {} for m in satisfies.keys(): # we must assume that each move satisfies at least one constraint obj = LLentry() obj.N = m; move_from_name[m] = obj colinsert(obj, h); rowhead(obj) ones = [(move_from_name[m], constraint_from_name[c]) for m, cc in satisfies.items() for c in cc] for m, c in ones: obj = LLentry() rowinsert(obj, m) colinsert(obj, c) moves_so_far = [] # everything's now set up to start the search def search(): if h.L is h: data = dict(((i, j), s) for s, i, j in (m.N for m in moves_so_far)) yield template % tuple(data[i, j] for i in div_nums for j in div_nums) else: mm = min((c.S, c) for c in rowitems(h))[1].D while mm is not mm.C: m = mm.M cc = m.R while cc is not m: c = cc.C c.R.L = c.L c.L.R = c.R r = c.D while r is not c: j = r.R while j is not r: j.D.U = j.U j.U.D = j.D j.C.S -= 1 j = j.R r = r.D cc = cc.R moves_so_far.append(m) for solution in search(): yield solution m = moves_so_far.pop() cc = m.L while cc is not m: c = cc.C r = c.U while r is not c: j = r.L while j is not r: j.D.U = j.U.D = j j.C.S += 1 j = j.L r = r.U c.R.L = c.L.R = c cc = cc.L mm = mm.D rows = [ "7......19", "46.19....", "...6827.4", ".9......7", "...3..4.5", "..67.....", "..1......", "2...74...", "...2..3.."] for r, row in enumerate(rows): for c, entry in enumerate(row): if entry != '.': move(move_from_name[(entry, r, c)]) import time t = time.time() for i in range(10): for solution in search(): print solution print "Total time taken: %s seconds" % (time.time() - t) From ms at cerenity.org Sun Aug 28 17:33:05 2005 From: ms at cerenity.org (Michael Sparks) Date: Sun, 28 Aug 2005 22:33:05 +0100 Subject: aproximate a number References: Message-ID: <43122d6d$0$97103$ed2619ec@ptn-nntp-reader03.plus.net> billiejoex wrote: > Hi all. I'd need to aproximate a given float number into the next (int) > bigger one. Because of my bad english I try to explain it with some > example: > > 5.7 --> 6 > 52.987 --> 53 > 3.34 --> 4 > 2.1 --> 3 What about 2.0? By your spec that should be rounded to 3 - is that what you intend? If you do, you can simply do this: def approx(x): return int(x+1.0) Regards, Michael. From tjreedy at udel.edu Mon Aug 22 13:54:39 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Aug 2005 13:54:39 -0400 Subject: PIL: retreive image resolution (dpi) References: <1124709169.824131.49120@g44g2000cwa.googlegroups.com> Message-ID: wrote in message news:1124709169.824131.49120 at g44g2000cwa.googlegroups.com... > AlexGreif.2609394 at bloglines.com wrote: > >> I looked at the PIL Image class but cannot see a posibility to retreive >> the image resolution dots per inch (or pixels per inch) > > Not all formats provide a DPI value; since PIL doesn't do anything with > DPI it's not part of the main interface. Digital images intrinsically have a size in pixels, not a 'resolution'. Resolutions (dpi or whatever) represent relationships and transformations between images and physical substrates. Somes images have an input transform, though for digital cameras, the input dpi or dpm(illimeter) of the ccd imager is seldom useful. Some have one *or more* output transforms. Some have both. So I think the option i/o transforms are best thought of and kept as 'extra' data. (The same applies to strings and I/O formats.) Terry J. Reedy Terry J. Reedy From steven.bethard at gmail.com Sun Aug 28 19:21:10 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 28 Aug 2005 17:21:10 -0600 Subject: trictionary? In-Reply-To: References: Message-ID: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> Randy Bush wrote: > now i want to add a second count column, kinda like > > bin = {} > for whatever: > for [a, b] in foo: > x = 42 - a > if bin.has_key(x): > bin[x.b] += 1 > else: > bin[x.b] = 1 > bin[x.not b] = 0 > for x, y, z in bin.iteritems(): > print x, y, z > > should the dict value become a two element list, or is > there a cleaner way to do this? It would probably help if you explained what the real problem is you're trying to solve. Using a two element list to store a pair of counts has a bad code smell to me. That said, you could write your code something like: bin = {} for whatever: # NOTE: brackets are unnecessary for a, b in foo: x = 42 - a # NOTE: 'in' is generally faster than has_key() if x in bin bin[x][0] += 1 else: bin[x] = [1, 0] # NOTE: extra parens necessary to unpack count list for x, (y, z) in bin.iteritems(): print x, y, z STeVe From stephen at theboulets.net Fri Aug 5 11:34:32 2005 From: stephen at theboulets.net (stephen at theboulets.net) Date: 5 Aug 2005 08:34:32 -0700 Subject: Passing a variable number of arguments to a wrapped function. Message-ID: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> Is there a better way of doing this so that I don't have to go through every permutation of possible arguments (the example here from the matplotlib 'plot' function): def makeplot(self, xvalues, yvalues, linecolor='', linewidth=''): if linecolor and linewidth: plot(xvalues, yvalues, linecolor, linewidth=linewidth) elif linecolor: plot(xvalues, yvalues, linecolor) elif linewidth: plot(xvalues, yvalues, linewidth=linewidth) else: plot(xvalues, yvalues) Stephen From mwh at python.net Wed Aug 31 04:49:23 2005 From: mwh at python.net (Michael Hudson) Date: Wed, 31 Aug 2005 08:49:23 GMT Subject: OpenSource documentation problems References: Message-ID: "Adriaan Renting" writes: > The good commercial docs are better because there it is understood > how important this is. Also, they are probably written by people who are trained technical writers which has to help at least a bit... writing good documentation is hard. Whether the Python documentation is good or bad depends on what you're comparing it to. It's probably not as good, say, as Apple's documentation for Cocoa, but it could certainly be much, much worse. Cheers, mwh -- Enlightenment is probably antithetical to impatience. -- Erik Naggum, comp.lang.lisp From mwm at mired.org Fri Aug 26 22:01:33 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 26 Aug 2005 22:01:33 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> Message-ID: <86y86ouohu.fsf@bhuda.mired.org> Paul Rubin writes: > zen19725 at zen.co.uk (phil hunt) writes: >> >Let's see. Reality is that writing correct programs is hard. Writing >> >correct programs that use concurrency is even harder, because of the >> >exponential explosion of the order that operations can happen >> >in. Personally, I'm willing to use anything I can find that makes >> >those tasks easier. >> Indeed so. Use threading (or whatever) when one has to, use an >> asynchronous single-threaded process whenever you can. > This is silly. You could say the exact same thing about if > statements. The number of paths through the program is exponential in > the number of if statements executed. So we better get rid of if > statements. The number of paths through a program isn't exponential in the number of if statements, it's multiplicative. Each if statement multiplies the number of paths through the program by 2, no matter how many other statements you have. On the other hand, with threads, the number of possible execution orders is the number of threads raised to the power of the number of instructions (assuming that instructions are atomic, which is probably false) in the shared code segment. It's a *much* nastier problem. > Really, the essence of programming is to find ways of organizing the > program to stay reliable and maintainable in the face of that > combinatorial explosion. That means facing the problem and finding > solutions, not running away. The principle is no different for > threads than it is for if statements. Correct. But choosing to use a tool that has a less complex model but solves the problem is *not* running away. If it were, you'd have to call using if statements rather than a goto running away, because that's that's exactly what you're doing. I do agree that we should face the problems and look for solutions, because some problems can't be solved with async I/O. That's why I posted the article titled "Static vs. dynamic checking for support of concurrent programming" - I'm trying to find out if one potential solution could be adapted for Python. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From kay.schluehr at gmx.net Wed Aug 31 14:25:51 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 Aug 2005 11:25:51 -0700 Subject: Infinity syntax. Re: Bug in string.find; was... In-Reply-To: <4315c414.244297871@news.oz.net> References: <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> <43156165.219034725@news.oz.net> <1125497606.359002.131900@g14g2000cwa.googlegroups.com> <4315c414.244297871@news.oz.net> Message-ID: <1125512751.548481.123570@g44g2000cwa.googlegroups.com> Bengt Richter wrote: > >>>> range(9)[4:-!0:-1] == range(5) > >True > Interesting, but wouldn't that last line be > >>> range(9)[4:-!0:-1] == range(5)[::-1] Ups. Yes of course. > >Life can be simpler with unbound limits. > Hm, is "!0" a di-graph symbol for infinity? > What if we get full unicode on our screens? Should > it be rendered with unichr(0x221e) ? And how should > symbols be keyed in? Is there a standard mnemonic > way of using an ascii keyboard, something like typing > Japanese hiragana in some word processing programs? You can ask questions ;-) > I'm not sure about '!' since it already has some semantic > ties to negation and factorial and execution (not to mention > exclamation ;-) If !0 means infinity, what does !2 mean? > > Just rambling ... ;-) I'm not shure too. Probably Inf as a keyword is a much better choice. The only std-library module I found that used Inf was Decimal where Inf has the same meaning. Inf is quick to write ( just one more character than !0 ) and easy to parse for human readers. Rewriting the above statements/expressions leads to: >>> Inf Inf >>> Inf+1 Inf >>> Inf>n # if n is int True >>> Inf/Inf Traceback (...) ... UndefinedValue >>> Inf - Inf Traceback (...) ... UndefinedValue >>> -Inf -Inf >>> range(9)[4:Inf] == range(9)[4:] True >>> range(9)[4:-Inf:-1] == range(5)[::-1] True IMO it's still consice. Kay From jules at REMOVETHIS.op59.net Mon Aug 22 15:04:31 2005 From: jules at REMOVETHIS.op59.net (Julian Smith) Date: Mon, 22 Aug 2005 20:04:31 +0100 Subject: Creating anonymous functions using eval References: <20050712120218.53d28b44.jules@REMOVETHIS.op59.net> <1121182125.554486.316880@z14g2000cwz.googlegroups.com> Message-ID: <20050822200431.22099c39.jules@REMOVETHIS.op59.net> On 12 Jul 2005 08:28:45 -0700 "Devan L" wrote: [ here's some context: > > I've been playing with a function that creates an anonymous function by > > compiling a string parameter, and it seems to work pretty well: > > > > def fn( text): > > exec 'def foo' + text.strip() > > return foo > > > > This can be used like: > > > > def foo( x): > > print x( 2, 5) > > > > foo( fn( ''' > > ( x, y): > > print 'x^2 + y^2 = ', x*x + y*y > > return y > > ''')) > > > > - which outputs: > > > > x^2 + y^2 = 29 > > 5 ] > How is this different from a nested function? It's different because it is defined in an expression, not by a statement. So you can create a new function inside a function call, for example. Like I said in the original post, it's a way of overcoming the limitations of python's lambda. The simple version I posted fails to lookup things in the caller's context, which one can easily fix by passing locals() as an extra parameter. Hopefully it'll be possible to grab the caller's locals() automatically using traceback or similar. Here's a version I've been using for a while which seems to work pretty well: def fn( text, globals_={}, locals_={}): ''' Returns an anonymous function created by calling exec on . should be a function definition, ommiting the initial `def ' (actually, leading `def' can be retained, for clarity). Any leading/trailing white space is removed using str.strip(). Leading white space on all lines will be handled automatically by exec, so you can use an indented python triple-quoted string. In addition, newlines and backslashes are re-escaped inside single/double-quoted strings. this enables nested use of fn(). example usage: fn( """ def ( target, state): if target != 'foo': return None return [], None, 'touch foo' """, globals(), locals()) Would be nice to grab our caller's globals() and locals() if globals_/locals_ are None, using some sort of introspection. For now, you'll have to pass globals() and locals() explicitly. ''' text = text.strip() if text.startswith( 'def'): text = text[ 3:].strip() if not text.startswith( '('): raise Exception( 'fn string must start with `(\'') def _escape_quotes( text): ''' escape newlines and backslashes that are inside single/double-quoted strings. should probably do something about backslashes inside triple-quoted strings, but we don't bother for now. ''' quote = None ret = '' for c in text: if quote: if c=='\n': ret += '\\n' elif c=='\\': ret += '\\\\' else: if c==quote: quote = None ret += c else: if c=='\'' or c=='"': quote = c ret += c return ret text = _escape_quotes( text) #print 'execing:', text # the exec will put the fn in the locals_ dict. we return it after # removing it from this dict. exec 'def _yabs_fn_temp' + text in globals_, locals_ ret = locals_['_yabs_fn_temp'] del locals_['_yabs_fn_temp'] return ret - Julian -- http://www.op59.net/ From dan at cellectivity.com Fri Aug 12 07:41:35 2005 From: dan at cellectivity.com (Dan) Date: Fri, 12 Aug 2005 12:41:35 +0100 Subject: __getattribute__ for class object In-Reply-To: <42FC87D7.3080807@libero.it> References: <42FC87D7.3080807@libero.it> Message-ID: <1123846895.16674.25.camel@localhost.localdomain> > > but if i want to have a __getattribute__ for class attributes > > Read something on metaclasses. Depending on what you want to do, it might be better to use properties instead: class Meta(type): x = property(lambda klass: 'Called for '+str(klass)) class Foo(object): __metaclass__=Meta print Foo.x -- Do I know what's in this bill? Are you kidding? Only God knows... - U.S. Senator Robert Byrd, when asked if he knew the contents of a $520 billion, 4000-page spending bill From zarnovican at gmail.com Tue Aug 16 19:29:39 2005 From: zarnovican at gmail.com (BranoZ) Date: 16 Aug 2005 16:29:39 -0700 Subject: __del__ pattern? In-Reply-To: <1124232686.973363.317640@z14g2000cwz.googlegroups.com> References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> <1124232686.973363.317640@z14g2000cwz.googlegroups.com> Message-ID: <1124234979.494554.283670@g44g2000cwa.googlegroups.com> bryanjugglercryptographer at yahoo.com wrote: > For a reasonably portable solution, leave the lock file open. > On most systems, you cannot delete an open file,.. On most UNIXes, you can delete an open file. Even flock-ed. This is BTW also an hack around flock. 1. Process A opens file /var/tmp/test1, and flocks descriptor. 2. Process H unlinks /var/tmp/test1 3. Process B opens file /var/tmp/test1, and flocks _another_ descriptor 4. Processes A and B are running simultaneously Do you need protection agains H ? Use file that is writeable by A and B in a directory that is writeable only by root. BranoZ From spam_john at comcast.net Thu Aug 11 12:17:19 2005 From: spam_john at comcast.net (spam_john at comcast.net) Date: 11 Aug 2005 09:17:19 -0700 Subject: Using PyThreadState_SetAsyncExc with PyEval_CallObject Message-ID: <1123777038.984474.216880@o13g2000cwo.googlegroups.com> I am attempting to raise an exception in a thread currently calling PyEval_CallObject from another thread using PyThreadState_SetAsyncExc. The PyEval_CallObject is currently calling of a function with looks like def fun() : import time count = 0 while 1: count = count + 1 time.sleep( 1 ) PyThreadState_SetAsyncExc is returning 1 which I beleive means that it found the thread id, but PyEval_CallObject is never returning. Here's the code I'm using to raise the exception - PyEval_AcquireLock (); PyThreadState_Swap( thread_state ); PyObject * exc = PyErr_NewException( "exit_exc", 0, 0 ); int count = PyThreadState_SetAsyncExc( thread_id, exc ); std::cout << "PyThreadState_SetAsyncExc returned " << count << std::endl; if (count > 1) { std::cout << "PyThreadState_SetAsyncExc returned > 1, all bets are off!" << std::endl; PyThreadState_SetAsyncExc( thread_id, NULL ); } Py_DECREF( exc ); PyThreadState_Swap(0); PyEval_ReleaseLock(); I know that the 'party line' is for my thread to check to see if it should cancel. In my application the functions running in the threads are completely end user defined so there's no way I can guarantee that it will check to see if it should exit. Is it possible to cancel a call to PyEval_CallObject? This is running on Python 2.4/Win32 but any solution will have to be portable to PPC Linux. Thanks- John From bokr at oz.net Tue Aug 9 01:12:06 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 09 Aug 2005 05:12:06 GMT Subject: PEP: Specialization Syntax References: <42f695f8.864310192@news.oz.net> <42f79137.928629067@news.oz.net> <42f7ef3b.952697616@news.oz.net> Message-ID: <42f83241.969855638@news.oz.net> On Mon, 08 Aug 2005 21:24:15 -0400, Nicolas Fleury wrote: >Bengt Richter wrote: >> On Mon, 08 Aug 2005 16:18:50 -0400, Nicolas Fleury wrote: >>>I wrote the PEP to see if was the only one that would benefit from >>>generic types *before* having optional static typing in the language. >>> >>>It seems I'm the only one;) >>> >>>According to blog entry 86641, Guido himself is prototyping with >>>__getitem__. However, I cannot do the same, because the framework I use >>>is much more complete and keyword arguments are a must. >>> >> Here is a decorator object to set up function call dispatch according to type. >> It only uses positional arguments, but could be fleshed out, I think. >> Not tested beyond what you see ;-) > >That's nice. Guido also posted this multimethods solution: >http://www.artima.com/weblogs/viewpost.jsp?thread=101605 > When I first read that, I thought you meant he had posted the very same thing. Anyway, maybe mine is different enough to be a little interesting ;-) >The only thing I was saying it that I can use generic types in Python >right now (and I do), by using (), but I can't with what will probably >be the syntax in future, i.e. using []. > Ok ;-) Maybe sometime in the future it will be possible to modify the language grammar and define a few classes and regenerate a whole new python interpreter that interprets new syntax. Regards, Bengt Richter From mage at mage.hu Wed Aug 3 16:13:34 2005 From: mage at mage.hu (Mage) Date: Wed, 03 Aug 2005 22:13:34 +0200 Subject: pain In-Reply-To: References: <42F11EC9.9060603@mage.hu> Message-ID: <42F1256E.6010201@mage.hu> Terry Reedy wrote: >"Mage" wrote in message news:42F11EC9.9060603 at mage.hu... > > >>Thank you, I will check this out. My company will switch to a jsp site. >>Isn't jython slower (I mean performance) than java? As well as I >>understand jython code will be interpreted twice. >> >> > >I believe only in the sense that Java is interpreted twice: once to compile >to Java bytecode and again, as often as you want, to run the bytecode >(assuming that it is kept around, just as .pyc files are). > > Thank you, I will read it thoroughly instead of just fast-reading the mainpage as last time :) Mage From roy at panix.com Sun Aug 7 10:42:21 2005 From: roy at panix.com (Roy Smith) Date: Sun, 07 Aug 2005 10:42:21 -0400 Subject: Python -- (just) a successful experiment? References: <1123422959.086345.76190@g49g2000cwa.googlegroups.com> Message-ID: "Paul Boddie" wrote: > Perl had the "cool tool" buzz a good ten years ago. That's true, but I think it understates just how important a development Perl really was. Before Perl, unix scripting consisted of awk, sed, grep, tr, a random assortment of incompatible shells, and lots of duct tape. For all of its faults, there is no doubt that Perl was a huge improvement over that mess. Much of the uglyness in Perl's syntax was a deliberate attempt to be backwards compatable with both awk and shell, which contributed to its quick uptake by the Unix sysadmin community. The next thing that drove its popularity is that it was quickly ported to run on DOS/Windows. If there was a community even more in need of a better toolkit than the early Unix sysadmins, the DOS/Windows world was it. Compared to what existed at the time, in both the Unix and DOS/Windows world, it was the best tool available at the time. No question about it. Perl also had (AFAICT) a three-year head start on Python. That's a lot of momentum to overcome. The fact that 15+ years of experience has shown that there are better ways to do things, should not in any way take away from Perl's importance. Perl got where it is because it filled a huge need, not just because it got good buzz. From fakeaddress at nowhere.org Wed Aug 31 18:50:12 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 22:50:12 GMT Subject: OpenSource documentation problems In-Reply-To: References: Message-ID: Sybren Stuvel wrote: > I don't have any problems with the documentation. It just works for > me. If you find any errors or omissions, fix them and send the > document maintainer an email. Why don't you help us by improving the > documentation? Workin' on it. -- --Bryan From wouter at voti.nl Tue Aug 30 10:53:18 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Tue, 30 Aug 2005 14:53:18 GMT Subject: micro-python - is it possible? References: <431440bb$1@news.orcon.net.nz> <11h8r5f3r8gs7dd@corp.supernews.com> Message-ID: <431472a9.242312356@news.xs4all.nl> >No, not a tiny microcontroller environment. In the >microcontroller world, "tiny" means 100 bytes of ram and 4KB of >code space. That's medium :) PIC10F200: 256 12-bit instructions, 16 bytes RAM. Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From gandalf at geochemsource.com Mon Aug 15 10:47:58 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Mon, 15 Aug 2005 16:47:58 +0200 Subject: zlib + Windows 32 service problem (ImportError) In-Reply-To: <43008D0D.4000509@geochemsource.com> References: <43008D0D.4000509@geochemsource.com> Message-ID: <4300AB1E.20305@geochemsource.com> Sorry, I realized that the import zlib was not executed from my (working) service. So here is the question: why can't I use zlib from a win32 service? Is there any way to make it working? >------------- >Python could not import the service's module > File "T:\Python\Projects\NamedConnector\Service.py", line 17, in ? > from Processor import * > File "c:\Python\Projects\NamedConnector\Processor.py", line 35, in ? > from mess import MessageSocket > File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ? > import zlib >exceptions.ImportError: dynamic module does not define init function >(initzlib) >------------- > > From siona at chiark.greenend.org.uk Thu Aug 25 11:09:00 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 25 Aug 2005 16:09:00 +0100 (BST) Subject: RE Despair - help required References: <430d8883@news.bezeqint.net> <430dcea0$1@news.bezeqint.net> Message-ID: In article <430dcea0$1 at news.bezeqint.net>, Yoav wrote: >Fredrik Lundh wrote: >> "Yoav" wrote: >>>I am trying the following: >>> >>>re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") >> instead of struggling with weird REs, why not use Python's standard >> filename manipulation library instead? >> >> http://docs.python.org/lib/module-os.path.html >Don't think it will do much good. I need to get them from a file and >extract the last folder in the path. For example: >if I get "c:\dos\util" >I want to extract the string "\util" Did you actually look at the docs Fredrik pointed you at? Did you, in particular, notice os.path.basename, which does (almost) exactly what you want? -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From pujasharma0381 at gmail.com Mon Aug 8 23:43:25 2005 From: pujasharma0381 at gmail.com (Pooja Sharma) Date: Tue, 9 Aug 2005 09:13:25 +0530 Subject: How to connect to UNIX machine from windows box Message-ID: <814c4b030508082043424ad507@mail.gmail.com> I want to connect to unix machine using ssh to run some commands . Is there any python module available that can be called in any other python script. Reply asap. :) Thanks From roccomoretti at hotpop.com Mon Aug 15 10:33:55 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Mon, 15 Aug 2005 09:33:55 -0500 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: Cameron Laird wrote: > Andy Smith rails against "frameworks": > http://an9.org/devdev/why_frameworks_suck?sxip-homesite=&checked=1 Slapdash Summary: Libraries good, frameworks bad - they are a straightjackets and limit sharing. Which lead me to the question - what's the difference between a library and a framework? From steve at holdenweb.com Wed Aug 31 08:56:55 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Aug 2005 07:56:55 -0500 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: <1125490472.670850.247240@g49g2000cwa.googlegroups.com> References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125425945.667967.181000@g49g2000cwa.googlegroups.com> <1125478316.530781.315540@g44g2000cwa.googlegroups.com> <1125490472.670850.247240@g49g2000cwa.googlegroups.com> Message-ID: n00m wrote: > Funnily but I still can't get the code working... WITHOUT IDLE. > I think it's because of "import thread" line. Seems something > wrong with "opening" this module. In IDLE it works OK. > Now, let's see ... [presses fingers to temples and exercises psychic powers] ... ah yes, its because you're DOING SOMETHING WRONG :-) Unfortunately "can't get the code working" isn't a very helpful description. Can you explain (preferably with a traceback) how it fails? Generally speaking, when you take your car into the garage (American: shop) because "it won't go" it's OK because the technicians can try and start it themselves. We don;t have your code readily to hand, so we need a bit more to go on. Generally speaking you would do well to try the threading module rather than thread unless you have a specific reason for not doing so. But if you post your code (or even better a subset of your code that demonstrates the error so people can pick it apart for themselves) with a traceback from the interpreter or a full description of what you expected the code to do and what it actually does we'll be able to help much more easily. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bronger at physik.rwth-aachen.de Mon Aug 8 07:11:39 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Mon, 08 Aug 2005 13:11:39 +0200 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <20050808005104.862503556.EP@zomething.com> Message-ID: <87d5oo65uc.fsf@wilson.rwth-aachen.de> Hall?chen! Robert Kern writes: > [...] > > What I'm trying to say is that posting to c.l.py is absolutely > ineffective in achieving that goal. Code attracts people that like > to code. Tedious, repetitive c.l.py threads attract people that > like to write tedious, repetitive c.l.py threads. Although I mostly agree with you, I must also say that it can be a significant motivation for a developer to see that his project is urgently needed and that he can expect a quite big user base and early fellow developers. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From steven.bethard at gmail.com Thu Aug 11 19:52:07 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 11 Aug 2005 17:52:07 -0600 Subject: Why does __init__ not get called? In-Reply-To: References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> <1123618110.763724.304990@g44g2000cwa.googlegroups.com> <1123702730.955133.105950@g49g2000cwa.googlegroups.com> Message-ID: Steven Bethard wrote: > def __call__(cls, *args, **kwargs): > obj = cls.__new__() > if not isinstance(obj.__class__, cls): ^^^^^^^^^^ issubclass > return obj > obj.__class__.__init__(obj, *args, **kwargs) > return obj STeVe From tim.golden at viacom-outdoor.co.uk Thu Aug 18 08:48:38 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 18 Aug 2005 13:48:38 +0100 Subject: Which Python library for Jabber? Message-ID: <9A28C052FF32734DACB0A288A3533991044D21CE@vogbs009.gb.vo.local> [Alessandro Bottoni] | Which Python library would you use for developing a small | Jabber client? | | jabber.py (seems to be dead since 2003) | http://jabberpy.sourceforge.net/ | | pyxmpp (looks like the "official" python library) | http://pyxmpp.jabberstudio.org/ | | xmpp.py (a russian alternative. Very well documented and | apparently quite | complete) | http://xmpppy.sourceforge.net/ I've used xmpppy recently for some very small-scale stuff (basically some commit-notification work), and it seemed to work ok. No in-depth trial, though. 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 zen19725 at zen.co.uk Wed Aug 3 07:42:50 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 12:42:50 +0100 Subject: Art of Unit Testing References: Message-ID: On Tue, 02 Aug 2005 18:44:01 +0200, Christoph Zwerschke wrote: >In August 2001, there was a thread about the "Art of Unit Testing": >http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 > >Paul Moore asked the legitimate question why there is no hook for a >"global" fixture code that is run only once for the whole TestCase, as >opposed to the normal "setUp" and "tearDown" code that is run for every >single test in the TestCase. A "global fixture" would be preferable >whenever creating the fixture is time consuming, e.g. you have to create >a database connection or even a whole database. > >What would be the preferred solution for such global fixtures? Simply >create the database, run the TestCase, and drop the database? > >Would it make sense to add "globaleSetup" and "globalTearDown" methods >to the TestCase class? I think at least it would not harm anybody. Where >should such proposals be submitted? I think this cowuld be very useful. As to the name, do other xUnit testing frameworks have a common name? If not, may I suggest setupAll() and tearDownAll(). -- Email: zen19725 at zen dot co dot uk From roy at panix.com Wed Aug 10 08:04:17 2005 From: roy at panix.com (Roy Smith) Date: Wed, 10 Aug 2005 08:04:17 -0400 Subject: What is Python?! References: Message-ID: Robert Wierschke wrote: > a scripting language or a "normal" language like C++ etc. It is difficult to define exactly what a "scripting language" is and isn't, but I think most people would classify it as a scripting language. > So please tell me what python is, what are it's strength, what is it > good for and when should I use it and not one of the other languages. I think it's biggest strengths are that it's easy to learn and easy to use. There is no separate compile stage, so testing things out is quick and easy. The language does compile to byte code (just like Java does), but unlike Java, the compile stage happens completely automatically. You just run your program, and the system figures out if it needs to compile (or re-compile) your source for you. The ability to fire up an interactive session is key. If I'm unsure of something, it's usually faster to just run python and try something out (or, use the built-in help system, or use dir() to get a listing of all of an objects methods) than to look in the manual. If your interpreter was built properly, it's even got input editing and history built in via the GNU readline library. > What about graphic? Can I create graphical interfaces with python? There are several GUI libraries. I don't do that kind of work, so I'll leave it to others to explain them. > Python is interpreted but is it compiled to something like the java byte > code or are there other ways to prevent the user to read my code? It is exactly like Java. In fact, it's so close, there's a system called Jython, which lets you compile Java source to Python byte code. Yes, this means it will always be possible for users to re-create your source code from the byte-code object files you ship. How much of an issue this is to you is a business decision. From geskerrett at hotmail.com Tue Aug 9 16:17:52 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 9 Aug 2005 13:17:52 -0700 Subject: Does any one recognize this binary data storage format In-Reply-To: References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> Message-ID: <1123618672.277757.42740@g43g2000cwa.googlegroups.com> You are correct, that was a typo. the second example should end in F441. Thanks. From schmitt at num.uni-sb.de Wed Aug 31 06:58:32 2005 From: schmitt at num.uni-sb.de (Uwe Schmitt) Date: Wed, 31 Aug 2005 12:58:32 +0200 Subject: strange behaviour of str() References: <0wfRe.15342$uD6.2810@reader1.news.jippii.net> Message-ID: <1125482106$mail2nntp@hades.rz.uni-saarland.de> > > Hello, > > I'm wondering about the following behaviour of str() with strings > containing non-ASCII characters: > > str(u'foo') returns 'foo' as expected. > > str('l??') returns 'l??' as expected. > > str(u'l??') raises UnicodeEncodeError > This does not work, because you need an encoder to convert unicode to str. str() does not know a priori which encoder to use. There are many ways to encode a unicode string to a classic byte-stream based string. you have to procede as follows: >>> s=u"???" >>> print s.encode("latin-1") ??? try "utf-8" and "utf-16" instead of "latin-1" Greetings, Uwe. From paolo_veronelli at tiscali.it Wed Aug 10 08:17:34 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Wed, 10 Aug 2005 14:17:34 +0200 Subject: Why is this? In-Reply-To: References: Message-ID: <42F9F05E.1050604@tiscali.it> Jiri Barton wrote: > Hi everyone, > > I have a problem with initialization. > >>>>a, b = [[]]*2 >>>>a.append(1) >>>>b > [1] > > Why is this? Why does not this behave like the below: > >>> a, b = [[]]*2 >>> a==b True > > And, just to add to my confusion: > > >>>>[[]]*2 > > [[], []] > >>>>[[], []] == [[]]*2 > > True This confuses me also,looks like empty lists share same object. Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From fakeaddress at nowhere.org Sat Aug 13 02:35:54 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 13 Aug 2005 06:35:54 GMT Subject: socket setdefaulttimeout In-Reply-To: <8122246.VFEYWSAU@news.verizon.net> References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> <8122246.VFEYWSAU@news.verizon.net> Message-ID: Sheila King wrote: > Bryan Olson wrote: [...] >>Under some older threading systems, any system call would block every >>thread in the process, and gethostbyname was notorious for holding things >>up. Some systems offer an asynchronous gethostbyname, but that doesn't >>help users of Python's library. Some programmers would keep around a few >>extra processes to handle their hosts lookups. Fortunately, threading >>systems are now much better, and should only block the thread waiting for >>gethostbyname. > > > Thanks, Bryan. I'm not doing any threading. But we are running this script on > incoming email as it arrives at the SMTP server, and scripts have a 16 second > max time of execution. Generally they run in much less time. However, we have > seen incidents where, due to issues with the DNS servers for the blacklists, > that the script exceed it's max time to run and the process was killed by > the OS. This results in the email being placed back into the mail queue for > attempted re-delivery later. Of course, if this issue goes undetected, the > mail can eventually be "returned to sender". There's no effective way to check > from within the running filter script that the time is not exceeded if the > gethostbyname blocks and doesn't return. :( > > As I said, normally this isn't a problem. But there have been a handful of > incidents where it did cause issues briefly over a few days. I was hoping to > address it. :/ > > Sounds like I'm out of luck. The seperate thread-or-process trick should work. Start a deamon thread to do the gethostbyname, and have the main thread give up on the check if the deamon thread doesn't report (via a lock or another socket) within, say, 8 seconds. If you have decent thread support, you might do it like as follows. (Oviously didn't have time test this well.) from threading import Thread from Queue import Queue, Empty import socket def start_deamon_thread(func): """ Run func -- a callable of zero args -- in a deamon thread. """ thread = Thread(target = func) thread.setDaemon(True) thread.start() def gethostbyname_or_timeout(hostname, timeout_secs = 8): """ Return IP address from gethostbyname, or None on timeout. """ queue = Queue(1) def attempt_ghbn(): queue.put(socket.gethostbyname(hostname)) start_deamon_thread(attempt_ghbn) try: result = queue.get(block = True, timeout = timeout_secs) except Empty: result = None return result -- --Bryan From redhackgp at rediffmail.com Fri Aug 5 09:57:18 2005 From: redhackgp at rediffmail.com (Gurpreet Sachdeva) Date: 5 Aug 2005 13:57:18 -0000 Subject: Help on Swig Message-ID: <20050805135718.24257.qmail@webmail47.rediffmail.com> Hi, I am facing a problem with swig while using Pointers: #include void Array(int *ptr) { int i; for (i = 0; i < 6; i++) { printf("Index: %d - %d\n",i, *(ptr + i)); } } %module Array %{ extern void Array(int *ptr); #include %} extern void Array(int *ptr); While running: >>> import Array >>> a=[1,3,2,4,5,6,7,9] >>> Array.Array(a) Traceback (most recent call last): File "", line 1, in ? TypeError: argument number 1: a 'int *' is expected, 'list([1, 3, 2, 4, 5, 6, 7, 9])' is received Do I need to make some changes in Interface file? Also I need to return that array after sorting it. How do I return it and collect the same in python. Thanks and Regards, Cheers! ???`?.(*?.?(`?.? ?.??)?.?*).??`?? ?.....[ Garry ].....? ???`?.(?.?*(?.?? `?.?)*?.?).??`?? Blogging at http://garrythegambler.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at monicol.co.uk Fri Aug 12 18:19:22 2005 From: peter at monicol.co.uk (Peter Mott) Date: Fri, 12 Aug 2005 23:19:22 +0100 Subject: Why is this? In-Reply-To: References: <42fc8eb4$0$38045$bed64819@news.gradwell.net> <42fcc918$0$38043$bed64819@news.gradwell.net> Message-ID: <42fd206b$0$38038$bed64819@news.gradwell.net> Duncan Booth wrote: > Peter Mott wrote: > > >>But it is still true that [[]] + [[]] is not the same as [[]] * 2. In my >>usage anyway this means that "S+S is the same as S*2" is false. Because >>there are Python expressions for which it is falsfied. >> >>The problem I have is pretty philosophical I admit, but I don't think >>you do it justice. It's really about identity. > > > So would you expect: > > random.seed(0) > random.random() + random.random() > > and: > > random.seed(0) > random.random() * 2 > > to be the same? The first call to random() in each case returns the same > result, but even though the source text is identical the second call > in the addition returns something different. It is just the same with the > lists. I don't see that this bears on what I said at all. Peter From Michael.J.Fromberger at Clothing.Dartmouth.EDU Fri Aug 12 15:48:38 2005 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Fri, 12 Aug 2005 15:48:38 -0400 Subject: Permutation Generator References: Message-ID: In article , Talin wrote: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head = lst[:1] > for x in permute( lst[1:] ): > yield head + x > yield x + head > return You're right that you're not the first person to do this: Many others have also posted incorrect permutation generators. Have you tried your code on some simple test cases? list(permute([1, 2, 3])) ==> [[1, 2, 3], [2, 3, 1], [1, 3, 2], [3, 2, 1]] Notably absent from this list are [2, 1, 3] and [2, 3, 1]. The problem gets worse with longer lists. The basic problem is that x needs to be able to occur in ALL positions, not just the beginning and the end. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From ironfroggy at gmail.com Mon Aug 1 11:08:58 2005 From: ironfroggy at gmail.com (Calvin Spealman) Date: Mon, 1 Aug 2005 11:08:58 -0400 Subject: Advanced concurrancy In-Reply-To: <1122572514.482082.270140@g44g2000cwa.googlegroups.com> References: <1122572514.482082.270140@g44g2000cwa.googlegroups.com> Message-ID: <76fd5acf050801080869160c91@mail.gmail.com> On 28 Jul 2005 10:41:54 -0700, jemfinch at gmail.com wrote: > Asynchrony is not concurrency. If you have to turn your code "inside > out," (that is, if you have to write your code such that the library > calls your code, rather than vice versa) it's very much *not* > concurrency: it's just asynchrony. > > While Twisted makes asynchronous code relatively easy to write and > maintain, it's just not concurrency. I can't simply drop my > single-threaded code into it and have it work, like I can with a truly > concurrent system. > > Jeremy When you can ever just "simply drop" any single-threaded code into an enviroment where it is sharing the resources and data with other executing code simulataniously, it just "have it work", that will be the day. Unfortunately, in practice, this simply is not how things work. For code to operate peacefully together, it must be designed to do so. Even when code is running in seperate processes, they must work together to share some resources, and that is simply the way of things. Concurrency can not (and perhaps should not) be an automatic fix-all pill. From gordonb.xfr1y at burditt.org Fri Aug 26 02:35:06 2005 From: gordonb.xfr1y at burditt.org (Gordon Burditt) Date: Fri, 26 Aug 2005 06:35:06 -0000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86acj5mpty.fsf@bhuda.mired.org> <11gt0d8bjanaabe@corp.supernews.com> <430E8EBA.129E2B61@yahoo.com> Message-ID: <11gte0qcivre8ce@corp.supernews.com> >>> HTML is designed to degrade gracefully (never mind that most web >>> authors and many browser developers don't seem to comprehend this), >>> so you don't really need a "subset" html to get the safety features >>> you want. All you need to do is disable the appropriate features in >>> the HTML renderer in your news and mail readers. JavaScript, Java, >>> and any form of object embedding. Oh yeah, and frames. >> >> And links. And cookies. And any kind of external site or local >> file access. And browser history. > >What is the risk with browser history? spyware and viruses (which can come from places other than email) sending it somewhere. Actually, there's not much point in keeping a browser history if all it can contain is mail in YOUR mailbox that may or may not have been already deleted. Gordon L. Burditt From sjmachin at lexicon.net Thu Aug 11 22:53:19 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 12:53:19 +1000 Subject: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> Message-ID: <42fc0f1f@news.eftel.com> Steven Bethard wrote: > Bryan Olson wrote: > >> >> class BuggerAll: >> >> def __init__(self, somelist): >> self.sequence = somelist[:] >> >> def __getitem__(self, key): >> if isinstance(key, slice): >> start, stop, step = key.indices(len(self.sequence)) >> # print 'Slice says start, stop, step are:', start, >> stop, step >> return self.sequence[start : stop : step] >> >> >> print range(10) [None : None : -2] >> print BuggerAll(range(10))[None : None : -2] >> >> The above prints: >> >> [9, 7, 5, 3, 1] >> [] >> >> Un-commenting the print statement in __getitem__ shows: >> >> Slice says start, stop, step are: 9 -1 -2 >> >> The slice object seems to think that -1 is a valid exclusive >> bound, but when using it to actually slice, Python interprets >> negative numbers as an offset from the high end of the sequence. >> >> Good start-stop-step values are (9, None, -2), or (9, -11, -2), >> or (-1, -11, -2). The later two have the advantage of being >> consistend with the documented behavior of returning three >> integers. > > > I suspect there's a reason that it's done this way, but I agree with you > that this seems strange. Have you filed a bug report on Sourceforge? > > BTW, a simpler example of the same phenomenon is: > > py> range(10)[slice(None, None, -2)] > [9, 7, 5, 3, 1] > py> slice(None, None, -2).indices(10) > (9, -1, -2) > py> range(10)[9:-1:-2] > [] > >>> rt = range(10) >>> rt[slice(None, None, -2)] [9, 7, 5, 3, 1] >>> rt[::-2] [9, 7, 5, 3, 1] >>> slice(None, None, -2).indices(10) (9, -1, -2) >>> [rt[x] for x in range(9, -1, -2)] [9, 7, 5, 3, 1] >>> Looks good to me. indices has returned a usable (start, stop, step). Maybe the docs need expanding. From UrsusMaximus at gmail.com Sun Aug 7 16:00:37 2005 From: UrsusMaximus at gmail.com (UrsusMaximus at gmail.com) Date: 7 Aug 2005 13:00:37 -0700 Subject: Firedrop2 Updated Tutorial and Podcast Message-ID: <1123444837.782266.299020@g49g2000cwa.googlegroups.com> I have revised, updated and added to the Mini How-To for intalling and setting up Firedrop2, and I have also posted a podcast about Firedrop2, both can be found on my Blog. Firedrop2 is a client side weblog and content management tool written by Hans Nowak. Written in Python and extensible in Python, a plugin creation tool has been made by Fuzzyman. The Mini How To (and podcast) is for helping new users install, set up and begin using Firedrop2. From spam.csubich+block at block.subich.spam.com Mon Aug 1 09:38:49 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Mon, 01 Aug 2005 09:38:49 -0400 Subject: Wheel-reinvention with Python In-Reply-To: <7xu0iacfwq.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <7xmzo25zmm.fsf@ruckus.brouhaha.com> <877jf6yzc3.fsf@wilson.rwth-aachen.de> <7xu0iacfwq.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > I think my approach is in some sense completely typical: I don't want > to install ANYTHING, EVER. I've described this before. I want to buy > a new computer and have all the software I'll ever need already on the > hard drive, and use it from that day forward. By the time the With all due respect, if you're allergic to installing software then why are you a developer? To me, your view is somewhat akin to that of a woodworker who doesn't want to buy tools, or a painter who doesn't want to buy brushes. Computers can be merely appliances, sure, but that's wasting the general purpose part of computation. Software as separate packaging exists because we (collectively) don't always know what we want the first (or second, or third, or...) time around. And when we do know what we want, we often muck it up when we try it. From franz.steinhaeusler at gmx.at Mon Aug 8 05:12:47 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Mon, 08 Aug 2005 11:12:47 +0200 Subject: How to use DrPython plugins References: Message-ID: On Sat, 06 Aug 2005 13:38:24 +0200, Laszlo Zsolt Nagy wrote: > > Hi All! Hello Laszlo, > >I have DrPython installed. I see there are cool plugins but I cannot >user them. I'm glad, you like DrPython and the plugins. What Platform do you have? Python, WxPython Version, latest DrPython 3.10.3 Version? You see this, when you call Help => About DrPython => System Info. >For example, I installed the "CodeCompletion" and "CodeMark" >plugins. I have enabled the "CodeCompletion" plugin by default. I >assigned the shortcut CTRL+SPACE to :CodeCompletion "Toggle Code >Completion". The code completition plugin is special, it is hardcoded to use the '.' char to launch the completion. >However, when I'm editing a file nothing happens. No matter >if I hit CTRL+SPACE or not. I have the same problem with CodeMark too. I could duplicate it. In codemark there there was a bug. updated Codemarks to 0.0.6. https://sourceforge.net/forum/forum.php?thread_id=1331861&forum_id=382892 Download: http://sourceforge.net/project/showfiles.php?group_id=83074 >I >setup the shortcuts but nothing happens. What am I doing wrong? Could you try again? Cheers, -- Franz Steinhaeusler From geskerrett at hotmail.com Thu Aug 25 19:22:23 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 25 Aug 2005 16:22:23 -0700 Subject: Anyone recognize this numeric storage format - similar to "float", but not quite In-Reply-To: <430c3fc2.2283972098@news.oz.net> References: <1124849085.656718.97720@g43g2000cwa.googlegroups.com> <430c3fc2.2283972098@news.oz.net> Message-ID: <1125012143.691569.298120@g44g2000cwa.googlegroups.com> I am not sure if you are still watching this thread, but I seem to have a bit of a problem with the code sample you so graciously provided. It seems to work in all instances, except the original example I provided (namely, 1234567890). On my system, the number 1234567890, gets converted to 1234567895.5. I made a few changes to your original program, but it is largely the same with different test samples samples. Any thoughts ?? Sample Code Below ---------------------- # Conversion of Microsoft Binary Format numbers to Python Floats import binascii as bn import struct as st data = [(1234567890,'000000AF052C139F'), (4069954144,'00000060929672A0'), (999999.99, '703D0AD7FF237494'), ( 88888.88, '400ad7a3709c2d91'), ( 22222.22, '400ad7a3709c2d8f'), ( 33333.33, 'b047e17a54350290'), ( 1500.34, '7814ae47e18a3b8b'), ( 42345.00, '0000000000692590'), ] def msd2float(bytes): if sum(bytes) in [0,72,127]: #take out values that don't make sense possible the NaN and Infinity ?? return 0.0 b = bytes[:] sign = bytes[-2]&0x80 b[-2] |= 0x80 #hidden most sig bit in place of sign exp = bytes[-1] - 0x80 - 56 #exponent offset acc = 0L for i,byte in enumerate(b[:-1]): acc |=(long(byte)<<(i*8)) return (float(acc)*2.0**exp)*((1.,-1.)[sign!=0]) for line in data: val = line[0] binval = bn.unhexlify(line[1]) le_bytes = list(st.unpack('BBBBBBBB',binval)) test = msd2float(le_bytes) print " In:",val, "\nOut:",test,"\n" Sample Output ------------------------ C:/Python24/pythonw.exe -u "C:/pytest/dms/Test MBF.pyw" In: 1234567890 Out: 1234567895.5 In: 4069954144 Out: 4069954144.0 In: 999999.99 Out: 999999.99 In: 88888.88 Out: 88888.88 In: 22222.22 Out: 22222.22 In: 33333.33 Out: 33333.33 In: 1500.34 Out: 1500.34 In: 42345.0 Out: 42345.0 From tjreedy at udel.edu Wed Aug 31 18:03:47 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2005 18:03:47 -0400 Subject: To the python-list moderator References: Message-ID: "Michael Hudson" wrote in message news:m2d5nuc73x.fsf at 82-33-185-193.cable.ubr01.azte.blueyonder.co.uk... > This is probably a fairly bad way of contacting the python-list > admins... Perhaps. Feel free to forward if you know a better way. As I noted ... > "Terry Reedy" writes: > >> For a couple of years, I have been reading and posting and posting to >> python-list and c.l.p via gmane.news.orgs gmane.comp.python.general >> group. >> Today I got this from 'python-list-bounces', which I presume is a >> 'machine' >> rather than a 'human' address. If there had been an address that I thought would reach the appropriate person, I would have used it. But public posting allows comments by others as to similar problems, like Gregory's. >> --------------------------- >> Your mail to 'Python-list' with the subject >> >> Re: how to join two Dictionary together? >> >> Is being held until the list moderator can review it for approval. >> >> The reason it is being held: >> >> Message has a suspicious header >> >> Either the message will get posted to the list, or you will receive >> notification of the moderator's decision. >> ----------------------------- This has a distinct 'don't call us, we'll maybe call you flavor. As of now, my post seems to still be in limbo (not on c.l.p and no notification). >> Since I had nothing to do with the headers, the problem is between >> gmane's >> sending (perhaps when responding to a message from a particular site) >> and >> your review. I hope this can be fixed. > > It's probably been flagged as UNSURE by spambayes. As I said, I hope the mismatch between legitimate senders and reviewer can be fixed. Terry J. Reedy From lycka at carmen.se Tue Aug 23 20:42:30 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 24 Aug 2005 02:42:30 +0200 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon wrote: > Such a PEP would have no chance of being accepted, since > it would break to much existing code. What's the point of this thread then? > But how can you do this when somewhere else '' is used as > an indication for an EOF. If that's your problem, I guess that's what you should attack, not that Python considers nothing to be nothing even it might some time become something. Network programming with Python works pretty well though, so it seems this is a non-issue too. >>I think the typical comment is to replace "if s != '':" with >>"if s:" in contexts where s is always a string, > > And it is IMO this kind of comments that lead to '' being used > as an EOF. Huh? Aren't the Python APIs just mirroring the behaviour of the underlying C APIs? >>or to replace >>"if expr != False:" with "if expr": in cases where "expr" is an >>expression that returns True or False etc. In some cases, obvious >>bugs, such as "if (a and b) == True:" where the programmer >>should have written "if (a and b):" are pointed out. > > This is not such an obvious bug. Because python allows non boolean > operands with "and" the two don't behave the same. How do you know > which behaviour the other person wants? I think you misread my text. If the programmer should have written "if (a and b):", adding "==True" will cause different behaviour unless True (or 1) is the only non-False value that b can have. This would not be obvious for someone who expects that the results of logical operations will return boolean values. > I have yet to see a mathematical work where 0, or any kind of > empty sequence is treated as false. In mathematics accuracy > is considered vitaly important and won't be sacrified to > remove redundancy. Boolean expression are always written out > fully. Dear Antoon. The "if" statement interprets the result of an expression to determine whether or not to execute a block of code. If "x" is an expression that returns True or False, then "x==True" is an equivalent expression. It's just not written in its minimal form. It's like writing "a / b * 100 %" instead of just "a / b" in a mathematical equation. The first version contains some kind of noise that just looks ugly for people who know that 100%==1. Why multiply with 1? At least in my home town, the MBA students write stuff like that, but mathematicians and engineers would just think it was ugly. > But you don't know if the logic expression are redundant. The > suggestions made are usually not equivallent. I think I know. Please point out if I made some mistake. It's pretty common that people fail to reduce logical expressions. I've seen C++ code checking for overlapping periods looking roughly like this: if ((start1<=start2 and stop1>=start2 and stop1<=stop2) or (start1<=start2 and stop1>=stop2) or (start1>=start2 and stop1<=stop2) or (start1>=start2 and start1<=stop2 and stop1>stop2)) For that person, his code might actually have been clearer than the less cluttered version I changed it to: if (start1<=stop2 and start2<=stop1) At least he spent a few minutes staring at it before he could accept that they were equivalent. (Maybe he just gave up.) Of course, it might well be that different brains work in different ways, and that different presentations are preferred by different people. Python seems to fit my brain. In the overlapping case above it's really a shift of perspective. He saw overlapping time periods as occuring in four different cases: * A starts before B and ends during B * A starts before B and ends after B * B starts before A and ends during A * B starts before A and ends after A. I guess my first impulse (before I asked what his code did) was that it looked redundant, but the thing is that my short version describes overlapping time periods in a different way: Both periods start before the other period ends. That's all! The kinds of simplifications in code that we talk about often has this quality. They show us that things are really simpler than the coder thought. I'm sure it happens that some people try to over- simplify things, but most systems can be made simpler, and trying to do that is a noble cause. > In that case you wouldn't return an empty sequence if you wanted > a false value in a sequence context but would throw an exception. Huh? If I want False I use False. If a sequence is empty, it's empty. It seems to me that you make things more complicated than they have to be. Perhaps you're just confused over the C APIs for network programming. I can understand that, but you seem to be pretty far away from the real target now. > So this would be fine by me, I just don't understand how this > would support the use of empty sequences as false. > > I also don't see how a read from a network connection returning > either: > > a bytestring when data is available, > '' when no data is available > None when the connection was closed > > As so much different kinds of information. > > Besides sometimes different kinds of information is not that > exceptional, so why should I throw an exception in such a > case? I don't know what you are trying to say. If you want more Pythonic network API, I'd rather use an iterator. Just make it return StopIterator when the connection closes. You would use it like this: for chunk in NetworkReader(ip, port): if chunk: print chunk This could be blocking, or use a timer and return '' on timeout. Thus the if-statement. chunk would always be a string. As you suggested, an empty string would then mean no data yet. When the connection is closed, the for loop simply ends. In this context, writing "if chunk != '':" instead of simply "if chunk:" is just a waste of resources. From dek at bosshog.lbl.gov Wed Aug 10 13:07:00 2005 From: dek at bosshog.lbl.gov (David E. Konerding DSD staff) Date: Wed, 10 Aug 2005 17:07:00 +0000 (UTC) Subject: wxPython and threads again References: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> Message-ID: In article <1123683323.056092.92800 at o13g2000cwo.googlegroups.com>, perchef wrote: > Hi, > > I have several files to download and a GUI to update. I know this is a > frequently asked question but i can't find an appropriate solution. > My Downloader extends threading.Thread and update a wx.Gauge in GUI > during the process. > > for src in urls: > downloader = Downloader( src, destination, GUI ) > downloader.start() > > #work with the downloaded files... > > If i don't use a downloader.join() in this for loop, I launch several > threads at the same time and so my wx.Gauge is bouncing up and down. > If i do add the downloader.join() my GUI is no more updated ( in fact, > nothing appears, it's frozen ) > How can I wait the end of the thread and also be able to update the GUI Well, the constraints are this: the main thread is running the wx main loop, and thus, cannot block by calling join on the downloader thread. Further, calling wx from a thread other than the one running the event loop is deep voodoo and should typically be avoided. You need another way to pass completion information between the downloader thread and the main thread; the simplest way is to define a custom wx Event, and wxPostEvent from the downloader thread when it completes ( and when the gauge should be updated). wxPostEvent is safe to call from non-eventloop threads. The main thread's wx event loop just spins, properly updating all other parts of the GUI, and receiving events from the downloader thread. ANother approach is to have a thread-safe Queue and have the main thread/event loop poll the queue with queue.get_nowait() periodically (typically 0.1-1 sec). The downloader thread shares the queue object and puts data structures (typically class instances, strings, or ints) that indicate status updates. The easiest approach, though, is to use the threadedselectreactor in Twisted (you need to check the HEAD branch out with subversion, because that reactor isn't included in any releases). With threadedselectreactor, it's easy to incorporate both the GUI event loop and the twisted reactor. Twisted already includes lots of code for doing asynchronous callback-style IO for IO bound processes like downloading. Further, you don't even think in an explicitly threaded way- createing a whole thread just to manage a download process which is motly IO and a little bookkeeping is silly. Twisted's approach just makes a lot more sense and simplifies the code too. Dave From dmqatpobox.com Mon Aug 29 13:51:25 2005 From: dmqatpobox.com (David MacQuigg) Date: Mon, 29 Aug 2005 10:51:25 -0700 Subject: Newbie question: Sub-interpreters for CAD program References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: On Sat, 27 Aug 2005 16:56:03 -0500, Terry Hancock wrote: >On Saturday 27 August 2005 03:21 am, David MacQuigg wrote: >> There is a similar lack of interest in the academic community. None >> of this is likely to lead to publications in scholarly journals. > >I'm confused by what you meant by this. Are you saying that academics >are afraid of using or creating open source CAD tools, or that they have >a lack of interest in tools development, because it won't generate papers >(directly anyway)? It seems like a lack of interest in tools development, because there are no new fundamental principles, sophisticated math, or anything that could help directly and in the short term to get a publication. There is probably also a perception, shared with engineers in industry, that the complexity of these tools is inherent in the task. It's OK for a full-time engineer to spend a few months learning the intricacies of a poorly-designed scripting language that works with just one tool, but not appropriate for students. My hope is that we can get a few good projects to demonstrate the utility of Python in doing sophisticated designs with simple tools. Then we will have a foothold in the Universities. Next will be small companies that can't afford a CAD department with 10 engineers dedicated to tool setup. -- Dave From lucasvr at gobolinux.org Wed Aug 10 22:22:38 2005 From: lucasvr at gobolinux.org (Lucas Correia Villa Real) Date: Wed, 10 Aug 2005 23:22:38 -0300 Subject: Tiny Python interpreter Message-ID: <200508102322.38626.lucasvr@gobolinux.org> Hello, I'm working with an ARM cpu which has only 64MB of flash memory available for storing applications. This system is running with an X server, some office applications and now I need to have a small Python interpreter, too (Python 2.2 is fine). I've googled a bit for the subject, but the only relevant links were outdated, and I haven't found any active project so far. Does anyone know of implementations which are still being maintained and which makes Python available for embedded systems? Thanks in advance for any suggestions, and please CC: me on replies, as I'm not subscribed to this list. -- Lucas powered by /dev/dsp From fakeaddress at nowhere.org Wed Aug 10 09:12:34 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 13:12:34 GMT Subject: MainThread blocks all others In-Reply-To: <42f9e68a_1@news.isis.de> References: <42f9d4ef_2@news.isis.de> <42f9e68a_1@news.isis.de> Message-ID: <53nKe.3824$zr1.1930@newssvr13.news.prodigy.com> Nodir Gulyamov wrote: > Tried to rewrite using Event() just as experiment, but unfortunately > MainThread will blocking all others. > Code below: > > import threading > > class class1: > def __init__(self): > self.myEvent = threading.Event() > result = doSomeJob() > > def increaseCounter(self): > self.myEvent.set() > > doSomeJob(self): > ##### BLOCKING HERE ### > if not self.myEvent.isSet(): > self.myEvent.wait() The initial 'if' is superflous. > self.myEvent.clear() > # ... continue... > > # this class subscribed to some observer which implements thread > class monitor: > def __init__(self, klass): > #do some init > self.c = klass > def update(self): > self.c.increaseCounter() > > if __name__ == "__main__": > cl1 = class1() > m = monitor(cl1) > mo = MonitorObserver(m) Obviously that won't work. You only have one thread, and it blocks in doSomeJob, so no one can ever trigger the even. -- --Bryan From albalmer at att.net Mon Aug 29 12:34:08 2005 From: albalmer at att.net (Alan Balmer) Date: Mon, 29 Aug 2005 09:34:08 -0700 Subject: Jargons of Info Tech industry References: <3n6kkjF4qppU1@individual.net> <861x4fuqzg.fsf@bhuda.mired.org> Message-ID: <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> Why on earth was this cross-posted to comp.lang.c.? Followups set. On Mon, 29 Aug 2005 12:26:11 GMT, axel at white-eagle.invalid.uk wrote: >In comp.lang.perl.misc Mike Meyer wrote: >> axel at white-eagle.invalid.uk writes: >>> In comp.lang.perl.misc John Bokma wrote: >>>> Chris Head wrote: >>>>> What advantages would those be (other than access from 'net cafes, but >>>>> see below)? >>>> And workplaces. Some people have more then one computer in the house. My >>>> partner can check her email when I had her over the computer. When I >>>> want to check my email when she is using it, I have to change the >>>> session, fire up Thunderbird (which eats away 20M), and change the >>>> session back. >>> Not a Windows solution, but I find the 'screen' utility invaluable as >>> I can have my email, news, and an editor open in different screens >>> and then when I need to move to a different machine, I can simply >>> detach and reattach screen without disturbing anything that >>> might be running. > >> For a more portable solution, check out VNC. > >I know... but it is a bugger to set up and I believe it is no longer >freeware (if it ever was), and it does not have the stark simplicity >which screen has... I only need to have a compiled version of screen >on the machine on which I do most of my work and be able to ssh/telnet >to that machine without involving any additional software installations >on other machines. > >Axel -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From fabioz at esss.com.br Fri Aug 19 15:28:35 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Fri, 19 Aug 2005 16:28:35 -0300 Subject: ANN: PyDev 0.9.7.99 released In-Reply-To: <42E6412A.4020905@esss.com.br> References: <42A720BD.5050701@esss.com.br> <42C175A5.5000206@esss.com.br> <42E6412A.4020905@esss.com.br> Message-ID: <430632E3.9050403@esss.com.br> Hi All, PyDev - Python IDE (Python Development Enviroment for Eclipse) version 0.9.7.99 has just been released. Check the homepage (http://pydev.sourceforge.net/) for more details. Details for Release: 0.9.7.99 OK, what's with the strange release version number?... Well, this version undergone lot's of changes, so, PyDev will be waiting on feedback about them... only after that will it become 0.9.8! Major highlights: ---------------- * PyDev has its first shot at Jython. you should be able to use many things already, meaning: all the common editor features and code completion. * The debugger is working. Others that are new and noteworthy: ------------------------------------ * Code completion has been improved for supporting wild imports and relative imports better (sometimes it had some problems). * There are hovers for the text and annotations (when you pass the mouse through an error it will show its description). * Block comment (Ctrl+4) now uses the size defined for the print margin. * New block-comment style added (Ctrl+Shift+4). * New icons were created. * wxPython completions now show. * Many other bug-fixes as usual. Note on Java 1.4 support: Currently Java 1.4 is not supported (only java 5.0), altough we will try to add support for java 1.4 before the 1.0 release. Special thanks --------------- This release would not be possible without help from: OctetString, for the financial support for making jython support possible! Aleks Totic, Scott Schlesier and Vitor Oba for the debugger patches! Eduardo A. Hoff, for the new logo and changes on the site layout! Cheers, Fabio -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From wuwei23 at gmail.com Wed Aug 31 22:38:32 2005 From: wuwei23 at gmail.com (alex23) Date: 31 Aug 2005 19:38:32 -0700 Subject: change date format In-Reply-To: References: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> <200508311236.49648.lars@gustaebel.de> <1125533583.606398.5770@g43g2000cwa.googlegroups.com> Message-ID: <1125542312.568029.88770@o13g2000cwo.googlegroups.com> Steve Holden wrote: > He isn't asking for help. He's simply masturbating. Now _that_ is how you kill a thread :) - alex23 From steven.bethard at gmail.com Thu Aug 18 11:17:20 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 18 Aug 2005 09:17:20 -0600 Subject: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: I wrote: > I wanted to say something about what happens with a negative stride, to > indicate that it produces (9, -1, -2) instead of (-1, -11, -2), but I > wasn't able to navigate the Python documentation well enough. > > Looking at the Language Reference section on the slice type[1] (section > 3.2), I find that "Missing or out-of-bounds indices are handled in a > manner consistent with regular slices." So I looked for the > documentation of "regular slices". My best guess was that this meant > looking at the Language Reference on slicings[2]. But all I could find > in this documentation about the "stride" argument was: > > "The conversion of a proper slice is a slice object (see section 3.2) > whose start, stop and step attributes are the values of the expressions > given as lower bound, upper bound and stride, respectively, substituting > None for missing expressions." > > This feels circular to me. Can someone help me find where the semantics > of a negative stride index is defined? Well, I couldn't find where the general semantics of a negative stride index are defined, but for sequences at least[1]: "The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < (j-i)/k." This seems to contradict list behavior though. range(10)[9:-1:-2] == [] But the values of n that satisfy 0 <= n < (-1 - 9)/-2 = -10/-2 = 5 are 0, 1, 2, 3, 4, corresponding to the x values of 9, 7, 5, 3, 1. But [range(10)[x] for x in [9, 7, 5, 3, 1]] == [9, 7, 5, 3, 1] Does this mean that there's a bug in the list object? STeVe [1] http://docs.python.org/lib/typesseq.html From poyol at hotmail.com Thu Aug 18 06:01:54 2005 From: poyol at hotmail.com (poyol at hotmail.com) Date: 18 Aug 2005 03:01:54 -0700 Subject: how do i add a new path into sys.path? In-Reply-To: References: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> Message-ID: <1124359314.826813.274420@g49g2000cwa.googlegroups.com> wen wrote: > if i wanna add the path "C:\temp" into sys.path, and make it available for > any other new python apps, like i add C:\temp into windows path , how? > thank you. Then use PYTHONPATH as you would use PATH ..... From rkern at ucsd.edu Sat Aug 6 21:03:08 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 18:03:08 -0700 Subject: SWIG again In-Reply-To: <20050806235703.63983.qmail@web51509.mail.yahoo.com> References: <20050806235703.63983.qmail@web51509.mail.yahoo.com> Message-ID: Jerry He wrote: >>Robert Kern >>Please don't make a new thread every time you post. > > sorry, I chose the digest mode when I signed up, and I > have no idea how to reply, nor any idea how to change > to the normal mode where I get individual emails so I > can actually just hit the reply button instead of > copying your name and part of your message every time > I post... If you know how, please let me know. http://mail.python.org/mailman/listinfo/python-list > On the other hand, I discovered that had the command > prompt, cmd.exe was trying to use the my cygwin python > executable instead of the Windows python executable. > > Since I didn't have the patience to wait for .NET > Framework SDK to download, (why does python need .NET > framework SDK anyway??). I tried building it on > cygwin, ... And it WORKED!!! > > I was really exited that I can do > import example > example.gcd(5, 10) > > and get the right answer... > > However, then I realized I just installed a completely > useless module. > > Can you tell me how to completely remove that module? For cygwin, it should be in whatever corresponds to /usr/lib/python2.4/site-packages . -- 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 syed_saqib_ali at yahoo.com Thu Aug 4 16:04:25 2005 From: syed_saqib_ali at yahoo.com (syed_saqib_ali at yahoo.com) Date: 4 Aug 2005 13:04:25 -0700 Subject: Tough Tkinter Scrollregion vs Window Size Problem Message-ID: <1123185865.684640.62050@g49g2000cwa.googlegroups.com> Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the original canvas-size, then the scrollregion adjusts properly. How can I make it such that the Scrollregion fills the entire space avaialable to it. I tried all permutations of setting expand=Tkinter.YES and fill=Tkinter.BOTH in the pack command?? -Saqib ---------------------------------------------------- import Tkinter class testApp2: def _setupCanvas(self): self._canvasFrame = Tkinter.Frame(self._overallFrame, bd=1, relief=Tkinter.SUNKEN) self._canvasFrame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) self._canvas = Tkinter.Canvas(self._canvasFrame, background="white", width=self._canvasWidth, height=self._canvasHeight,) # Scroll Bars vScrollbar = Tkinter.Scrollbar(self._canvasFrame) hScrollbar = Tkinter.Scrollbar(self._canvasFrame) # Scroll Bars vScrollbar = Tkinter.Scrollbar(self._canvasFrame) vScrollbar.pack(side=Tkinter.LEFT, expand=Tkinter.NO, fill=Tkinter.NONE) hScrollbar = Tkinter.Scrollbar(self._canvasFrame) hScrollbar.pack(side=Tkinter.TOP, expand=Tkinter.NO, fill=Tkinter.NONE) # Configure self._parent.rowconfigure(0, weight=1) self._parent.columnconfigure(0, weight=1) # self._scrollX0 = self._scrollY0 = 0 # self._scrollX1 = self._canvasWidth # self._scrollY1 = self._canvasHeight print "self._canvasWidth = %s" % self._canvasWidth print "self._canvasHeight = %s" % self._canvasHeight # print "self._scrollX1 = %s" % self._scrollX1 # print "self._scrollY1 = %s" % self._scrollY1 self._canvas.config( width=self._canvasWidth, height=self._canvasHeight, scrollregion=(0,0, self._canvasWidth, self._canvasHeight), yscrollcommand=vScrollbar.set, xscrollcommand=hScrollbar.set, ) vScrollbar.config(orient=Tkinter.VERTICAL, command=self._canvas.yview) hScrollbar.config(orient=Tkinter.HORIZONTAL, command=self._canvas.xview) self._canvasFrame.pack() self._canvas.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) vScrollbar.pack(side=Tkinter.RIGHT, expand=Tkinter.YES, fill=Tkinter.Y) hScrollbar.pack(side=Tkinter.BOTTOM, expand=Tkinter.YES, fill=Tkinter.X) def __init__(self, parent): self._parent = parent self._overallFrame = Tkinter.Frame(self._parent, bd=1, relief=Tkinter.SUNKEN) self._overallFrame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) self._canvasWidth = 300 self._canvasHeight = 250 self._setupCanvas() self._setCallBacks() def _setCallBacks(self): # Function Bindings self._canvas.bind("", self._b1PressEvt) def _b1PressEvt(self, event): print self._canvas.config('scrollregion') print self._canvas.config('width') print self._canvas.config('height') print "=" * 50 print "\n" root = Tkinter.Tk() app = testApp2(root) root.mainloop() From pink at odahoda.de Thu Aug 4 13:13:50 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Thu, 04 Aug 2005 19:13:50 +0200 Subject: Reliable destruction References: <1123153847.649321.235450@z14g2000cwz.googlegroups.com> <1123157779.191750.178300@g43g2000cwa.googlegroups.com> Message-ID: Pierre-Eric.Melchy at uni-konstanz.de wrote: > Hello Benjamin, > > What would happen if an exception was thrown in the middle of setup()? > tearDown could not handle this case without having a list of the > objects already constructed (Or I would have to rely on the automatic > call to __del__, if it is reliable). class measurement: def __init__(self): self.powerSupply = None ... def setup(self): self.powerSupply=apparate.PowerSupply() ... def tearDown(self): if self.powerSupply is not None: try: self.powerSupply.tearDown() except: # Exception in powerSupply.tearDown() should not stop # the following tearDown()s from being executed traceback.print_exc() ... > There is still some problem: > Imagine a communication error in run() which would cause del to fail on > the instrument. Not really sure, if I understand what you mean? Does my tearDown() above covers this? > Anyway, I think this case is still more difficult to handle. Reliable, fail-safe software *is* hard to design and implement, that's for sure.. Be happy that it's just a power supply that could overheat and not the core of a nuclear power plant. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From fredrik at pythonware.com Wed Aug 10 08:30:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 10 Aug 2005 14:30:30 +0200 Subject: Why is this? References: <42F9F05E.1050604@tiscali.it> Message-ID: Paolino wrote: > This confuses me also, looks like empty lists share same object. nope. see Matt Hammonds reply for the full story. From frr at easyjob.net Sat Aug 6 06:13:26 2005 From: frr at easyjob.net (Fernando) Date: 6 Aug 2005 03:13:26 -0700 Subject: Syntax error after upgrading to Python 2.4 References: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> Message-ID: <1123323206.151000.309140@g49g2000cwa.googlegroups.com> > I don't see the problem yet. I certainly do not see anything that should > have been affected by the upgrade (was it from 2.3 on XP also?) Yes. > After checking for nonprinting chars, I would shuffle the param-default > lines to try to determine which is really at fault. Good luck, or wait for > a more helpful response. I reinstalled version 2.3.5 and everything works fine now. It's definately something related to the latest version. This is one of the main resons I finally gave up using Python and switched to Smalltalk. You can't concentrate on your work while someone is permanently introducing changes to your tool. Constantly adding new features to a language might be fun, but it substantially increases the odds of adding bugs and misfeatures, such as whatever was causing problems with my code or the 'perlish' syntax for decorators. Feeling much better now. :-) From borges2003xx at yahoo.it Mon Aug 1 05:28:36 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 1 Aug 2005 02:28:36 -0700 Subject: need for speed Message-ID: <1122888516.815400.116220@f14g2000cwb.googlegroups.com> hi everyone can someone suggest me where find a lot programming tricks for achieving the top speed in python? thanks everyone for patience From damir at agg.astranet.ru Tue Aug 9 05:49:06 2005 From: damir at agg.astranet.ru (Damir Hakimov) Date: Tue, 09 Aug 2005 13:49:06 +0400 Subject: python for microcontrollers In-Reply-To: References: <42f7c8d4$1@news.orcon.net.nz> <7xd5oof5qj.fsf@ruckus.brouhaha.com> Message-ID: <42F87C12.7050803@agg.astranet.ru> David Cuthbert wrote: >Paul Rubin wrote: > > >>I don't think you want to do this. Runtime type tags and the overhead >>of checking them on every operation will kill you all by themselves. >>Processors like that haven't been used much as Lisp targets either, >>for the same reasons. Pick a different language. >> >> > >I was thinking that you could avoid this by adding some type inference >to Python and/or reducing everything to two basic types (strings and >ints), but the end result would require a lot of work and not look much >like Python. > > > Use Fort. From apardon at forel.vub.ac.be Tue Aug 30 04:07:45 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 30 Aug 2005 08:07:45 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <7xslwwjsft.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-08-29, Steven Bethard schreef : > Antoon Pardon wrote: >> I think a properly implented find is better than an index. > > See the current thread in python-dev[1], which proposes a new method, > str.partition(). I believe that Raymond Hettinger has shown that almost > all uses of str.find() can be more clearly be represented with his > proposed function. Do we really need this? As far as I understand most of this functionality is already provided by str.split and str.rsplit I think adding an optional third parameter 'full=False' to these methods, would be all that is usefull here. If full was set to True, split and rsplit would enforce that a list with maxsplit + 1 elements was returned, filling up the list with None's if necessary. head, sep, tail = str.partion(sep) would then almost be equivallent to head, tail = str.find(sep, 1, True) Code like the following: head, found, tail = result.partition(' ') if not found: break result = head + tail Could be replaced by: head, tail = result.split(' ', 1, full = True) if tail is None break result = head + tail I also think that code like this: while tail: head, _, tail = tail.partition('.') mname = "%s.%s" % (m.__name__, head) m = self.import_it(head, mname, m) ... Would probably better be written as follows: for head in tail.split('.'): mname = "%s.%s" % (m.__name__, head) m = self.import_it(head, mname, m) ... Unless I'm missing something. -- Antoon Pardon [1]http://mail.python.org/pipermail/python-dev/2005-August/055781.html From nephish at xit.net Tue Aug 30 14:50:55 2005 From: nephish at xit.net (nephish at xit.net) Date: 30 Aug 2005 11:50:55 -0700 Subject: trouble with time --again In-Reply-To: References: <1125423761.517155.162710@g44g2000cwa.googlegroups.com> <1125424469.858102.178260@f14g2000cwb.googlegroups.com> Message-ID: <1125427855.087594.174140@f14g2000cwb.googlegroups.com> he he. yep, just spent a lot of time on this one. life moves on. cheers! sk From ptmcg at austin.rr.com Tue Aug 16 09:18:28 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 16 Aug 2005 06:18:28 -0700 Subject: How can I exclude a word by using re? References: <430085e8$1@news.eftel.com> <1124165702.590364.107410@o13g2000cwo.googlegroups.com> Message-ID: <1124198308.584668.69390@g14g2000cwa.googlegroups.com> Just as with re you were using "?P" to assign the matching text to the variable "xxx", pyparsing allows you to associate a name with an element of your grammar using setResultsName. Here is your original re: r=re.compile(ur'valign=top>(?P??\d{1,2})]*?>?\s{0,2}' ur'' ur'(?P.+)',re.UNICO??DE|re.IGNORECASE) Here is the pyparsing expression: valign + number.setResultsName("number"?) + tdEnd + \ tdStart + SkipTo(aStart) + aStart + \ SkipTo(tdEnd) + tdEnd Here are the re and pyparsing pieces side by side: re => pyparsing ----------------------- valign=top> => valign = CaselessLiteral("valign=top>") (?P??\d{1,2}) => number = Word(nums), number.setResultsName("number") => tdEnd ]*?>? => tdStart \s{0,2} => I don't know what this re does, so I just used SkipTo(aStart) => aStart (which returns a value whose named attributes correspond to the HTML attributes, such as href) (?P.+) => SkipTo(tdEnd) *** here is where we'll make our change *** => tdEnd To capture the body of the second tag pair, we'll add setResultsName("name") to the pyparsing expression: mp3entry = valign + number.setResultsName("number"?) + tdEnd + \ tdStart + SkipTo(aStart) + aStart + \ SkipTo(tdEnd)setResultsName("name") + tdEnd Now you should be able to extract the data using: for toks,s,e in mp3Entry.scanString(targetHTML?): print toks.number, toks.starta.href, toks.name Good luck! -- Paul From stud0505 at yahoo.com Wed Aug 24 03:46:24 2005 From: stud0505 at yahoo.com (Layin'_Low) Date: 24 Aug 2005 00:46:24 -0700 Subject: FileIO problem In-Reply-To: References: <1124866383.975225.261840@o13g2000cwo.googlegroups.com> Message-ID: <1124869584.589922.283140@f14g2000cwb.googlegroups.com> thnx guys it was late and had just come from a bar and didnt reread the lines. thnx again for the help From mwm at mired.org Sun Aug 7 15:20:15 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 07 Aug 2005 15:20:15 -0400 Subject: Fat and happy Pythonistas References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> <86br4avf5t.fsf@bhuda.mired.org> <11fakjctean9u8a@news.supernews.com> <863bpmv85p.fsf@bhuda.mired.org> <5g5bf1hdh05k94f3mg2od6ej0trs0n3qdi@4ax.com> Message-ID: <86d5opftao.fsf@bhuda.mired.org> Dennis Lee Bieber writes: > On Sat, 06 Aug 2005 21:37:54 -0400, Mike Meyer declaimed > the following in comp.lang.python: >> "The concensus of this group" is a *long* way from "the debate has >> moved on". I agree that it's the concensus of this group - but this is >> a group devoted to a dynamic programming language. If you go to a >> group devoted to a statically typed language, you'll find a different >> concensus. Which means the debate is still very much alive. > For a schizoid view... read both comp.lang.ada and > comp.lang.python together Will you settle for comp.lang.eiffel + the smalleiffel list and comp.lang.python? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From en.karpachov at ospaz.ru Tue Aug 23 09:24:19 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Tue, 23 Aug 2005 17:24:19 +0400 Subject: Doubt C and Python In-Reply-To: <1124785351.793496.93990@o13g2000cwo.googlegroups.com> References: <200508221700.10647.hancock@anansispaceworks.com> <1124785351.793496.93990@o13g2000cwo.googlegroups.com> Message-ID: <20050823172419.16c0778a.jk@ospaz.ru> On 23 Aug 2005 01:22:31 -0700 James wrote: > > Some people with C background use Python instead > > of programming in C.why? > > Becuase it is much more efficient. It's rather because _they_ are much more efficient (that is, with Python). -- jk From adie at cstone.net Wed Aug 24 23:50:41 2005 From: adie at cstone.net (Adrian Pettitt) Date: Wed, 24 Aug 2005 23:50:41 -0400 Subject: How to start a DTS Package on MS-SQL-Server? Message-ID: <200508250350.j7P3odRY004925@mailrtr04.ntelos.net> I found this subject line in a post to this list on Jan 30, 2004. Does anybody know if this is possible? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Aug 29 22:15:41 2005 From: john at castleamber.com (John Bokma) Date: 30 Aug 2005 02:15:41 GMT Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: Alan Balmer wrote: > On 29 Aug 2005 21:12:13 GMT, John Bokma wrote: > >>> Now, go away. And please, stay away. >> >>Like I already said, it doesn't work that way. > > Goodbye, John. Filters set. Saidly you didn't get the message. Moreover you think that the Usenet /needs/ a public ploink message. Get a clue. People like you add more noise to Usenet compared to a thread which runs a bit wide. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From peter at engcorp.com Sun Aug 21 19:19:40 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 21 Aug 2005 19:19:40 -0400 Subject: Sandboxes In-Reply-To: References: Message-ID: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> 42 wrote: > Thoughts? Still gaping holes? Certainly. And rather than rehash them all here, I'm going to suggest you check the comp.lang.python archives for any of the many past discussions about this before you spend too much time thinking (repeatedly) that you've nailed that one last hole only to have somebody point out yet another way around it. -Peter From wenming_hu2002 at hotmail.com Fri Aug 26 10:50:20 2005 From: wenming_hu2002 at hotmail.com (wen) Date: Fri, 26 Aug 2005 22:50:20 +0800 Subject: question on "import __main__" Message-ID: i have written some code in test.py as below: import __main__ if __name__!='__main__': print 1 print 2 when i run test.py, i got 2 on the screen. now, i have some question about the code, 1. since no __main__ module at all, why it's legal to write "import __main__"? 2. since if running a script independently, the __name__ should be '__main__', why it's not in the above code? thank you in advance. with my kind regards, Wen From saint.infidel at gmail.com Fri Aug 12 10:21:31 2005 From: saint.infidel at gmail.com (infidel) Date: 12 Aug 2005 07:21:31 -0700 Subject: len(sys.argv) in (3,4) In-Reply-To: <42fb7498$0$11771$626a14ce@news.free.fr> References: <42fb7498$0$11771$626a14ce@news.free.fr> Message-ID: <1123856491.448628.67250@g49g2000cwa.googlegroups.com> > Nope. But since you're running this on a very peculiar OS, I just can > guess that this very peculiar OS consider all args to be one same string... It depends on what you're coding with. If you're writing a Win32 program in C/C++ (and by extension, Visual Basic), the WinMain() function passes all of the arguments in a single string. One of the many stunningly boneheaded Win32 decisions, IMNSHO. > BTW, isn't the DOS syntax for command line args something like : > > myprog /arg1 /arg2 No, by convention only, the "switch" character for DOS programs is "/" instead of "-" or "--". Personally, I'm of the opinion that this switch convention, backslashes in paths, and two-byte newlines are all intentionally designed to make things LESS compatibile with other OSes, and MORE difficult to interoperate. From en.karpachov at ospaz.ru Sat Aug 13 03:04:55 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Sat, 13 Aug 2005 11:04:55 +0400 Subject: "Compile time" checking? In-Reply-To: <7r0rf1p2ov2d6dpjqcomq5mn683962cc6f@4ax.com> References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <7r0rf1p2ov2d6dpjqcomq5mn683962cc6f@4ax.com> Message-ID: <20050813110455.1af2a6a4.jk@ospaz.ru> On Fri, 12 Aug 2005 22:25:07 -0700 Steve Jorgensen wrote: > Since Python does not use manifest typing, there's not much you can do about > this, but typeless languages like this are great if you're using a process > that finds the errors the compiler would otherwise find. I'm referring, of > course, to Test Driven Development (TDD). > > If you do TDD, you won't miss compile-time checking much. In fact, the extra > kruft that manifest typing requires is an annoying burden when doing TDD, so > Python is a breath of fresh air in this regard. What test should one implement to catch that kind of errors like in OP example? > On 10 Aug 2005 08:53:15 -0700, "Qopit" wrote: > > >#---- > >def tester(a,b,c): > > print "bogus test function",a,b,c > >tester(1,2,3) #this runs fine > >tester(1,2) #this obviously causes a run-time TypeError exception > >#---- -- jk From heikki at osafoundation.org Wed Aug 31 01:07:42 2005 From: heikki at osafoundation.org (Heikki Toivonen) Date: Tue, 30 Aug 2005 22:07:42 -0700 Subject: ANN: M2Crypto 0.15 Message-ID: M2crypto release 0.15 In this M2Crypto release: * Support for OpenSSL up to 0.9.8 * Support for SWIG 1.3.24 * Support for Python 2.4.1 * Twisted integration * Safer defaults for SSL context and post connection check for clients * Eliminated C pointers from interfaces (some may still remain in callbacks) * Many cases where Python interpreter crashed have been fixed * Improved thread safety of many callbacks * Memory leak fixes * And of course more of the OpenSSL API is covered, new docstrings and tests have been written To get the source: svn co http://svn.osafoundation.org/m2crypto/tags/0.15 m2crypto-0.15 Enjoy! -- Heikki Toivonen From zanesdad at bellsouth.net Sat Aug 20 07:03:45 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Sat, 20 Aug 2005 07:03:45 -0400 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> Message-ID: <43070E11.20200@bellsouth.net> James Kim wrote: >Robert Kern wrote: > > >>http://www.catb.org/~esr/faqs/smart-questions.html >> >> > >Is it a *smart* way or *necessary* way? > > Of course it's not *necessary*. I mean, the world isn't going to come to an end if it doesn't happen. There is no logical contingency making it so. But, if everyone in the group adheres to the ESR "smart questions" guide, what's the difference? >Plus, my question was not for the detail description but for the >intuitive guide leading the beginner's further study. > > But, I'll try to answer your question the best I can. From a quasi-sensory intuitive level, ``iter`` is red - kinda warm - and smells a little like cinnamon, but not too strong. ``lambda`` on the other hand is blue-green, sometimes grey, cooler, almost cold, has a damp feel to it, and tastes like pork - not chicken, mind you - that's the ``for`` statement. >I understand that too many repeated talks make cyberian tired. However, >over and over discussions of basic concepts is also very important for >technology enhancements. > Here's the deal. If you have a general question about something, ask it. But ask smartly. For example, "What is the benefit of using ``iter`` as opposed to something else? What are the alternatives to using ``iter``?" Asking questions like "What are the meanings of Commands 'iter' and 'lambda'" will not fly well here - and you may find less so elsewhere. The reason is, it smells of laziness (I'm not saying you *are* lazy - that's just the impression it leaves) and this group is full of people who have reached for the docs, wrestled with them, and have come away from it better informed programmers. >Thus, Commands 'iter' and 'lambda' should be >discussed over and over about their necessity and convenience > This is different from what you were asking. I quoted your exact words above and it's different from what you're asking here. And I'm not so sure I would put a *should* on your statement. I think usage discussions of different functions, standard library modules, practices, etc. *will* arise perpetually. But I don't think we *need* to constantly bat around the necessity of X keyword or Y function or Z module. Convenience - probably. Necessity - no. >in the >news-group as long as they are the principle keywords distinguished from >the conventional languages like c/c++, pascal, etc. > >-James > > So, if you have a question that's in line with Robert's advice, please post it and it will have a much higher chance of getting answered. I sincerely hope this helps. Jeremy Jones From fbarbuto2002.no at spam.yahoo.ca Fri Aug 12 00:32:33 2005 From: fbarbuto2002.no at spam.yahoo.ca (Fausto Arinos Barbuto) Date: Fri, 12 Aug 2005 04:32:33 GMT Subject: Psyco & Linux References: <2EUKe.193369$5V4.19467@pd7tw3no> <1123818373.058442.138240@g49g2000cwa.googlegroups.com> Message-ID: Hi Steve; Steve M wrote: >> First, I tried the usual "python setup.py install" but that did not work. > How exactly did it fail? Perhaps you can paste the error output from > this command. Sure, he is the output: linux:/home/fausto/Documents/psyco-1.4 # python setup.py install PROCESSOR = 'ivm' Copying c/ivm/prolog/insns-igen-h.i.default -> c/ivm/prolog/insns-igen-h.i Copying c/ivm/prolog/insns-threaded.i.default -> c/ivm/prolog/insns-threaded.i Copying c/ivm/prolog/insns-switch.i.default -> c/ivm/prolog/insns-switch.i Copying c/ivm/prolog/insns-igen.i.default -> c/ivm/prolog/insns-igen.i Copying c/ivm/prolog/mode_combine.pl.default -> c/ivm/prolog/mode_combine.pl Copying c/ivm/prolog/insns-table.py.default -> c/ivm/prolog/insns-table.py running install running build running build_py creating build creating build/lib.linux-x86_64-2.4 creating build/lib.linux-x86_64-2.4/psyco copying psyco/core.py -> build/lib.linux-x86_64-2.4/psyco copying psyco/kdictproxy.py -> build/lib.linux-x86_64-2.4/psyco copying psyco/logger.py -> build/lib.linux-x86_64-2.4/psyco copying psyco/profiler.py -> build/lib.linux-x86_64-2.4/psyco copying psyco/support.py -> build/lib.linux-x86_64-2.4/psyco copying psyco/__init__.py -> build/lib.linux-x86_64-2.4/psyco copying psyco/classes.py -> build/lib.linux-x86_64-2.4/psyco running build_ext building 'psyco._psyco' extension creating build/temp.linux-x86_64-2.4 creating build/temp.linux-x86_64-2.4/c gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -fmessage-length=0 -Wall -g -fPIC -DALL_STATIC=1 -Ic/ivm -I/usr/include/python2.4 -c c/psyco.c -o build/temp.linux-x86_64-2.4/c/psyco.o In file included from c/dispatcher.h:12, from c/codemanager.h:10, from c/psyco.c:3: c/codegen.h:19:3: #error "sorry -- I guess it won't work like that on 64-bits machines" In file included from c/initialize.h:46, from c/psyco.c:13: c/dispatcher.c: In function `fz_compress': c/dispatcher.c:232: warning: cast from pointer to integer of different size c/dispatcher.c:238: warning: cast to pointer from integer of different size In file included from c/initialize.h:53, from c/psyco.c:13: c/codemanager.c: In function `psyco_shrink_code_buffer': c/codemanager.c:252: warning: int format, different type arg (arg 3) In file included from c/initialize.h:61, from c/psyco.c:13: c/Objects/pabstract.c:716:3: #error "omitted code from Python 2.3 here" In file included from c/initialize.h:75, from c/psyco.c:13: c/Objects/pstructmember.c: In function `PsycoMember_GetOne': c/Objects/pstructmember.c:16: warning: unused variable `w2' c/Objects/compactobject.c: At top level: c/codegen.c:711: warning: `integer_lshift' defined but not used c/ivm/prolog/insns-igen.i:175: warning: `psyco_insn_assertdepth' defined but not used c/ivm/prolog/insns-igen.i:197: warning: `psyco_insn_dynamicfreq' defined but not used c/Objects/plongobject.c:21: warning: `PsycoLong_AsDouble' defined but not used c/Objects/plistobject.c:116: warning: `PsycoList_SingletonNew' defined but not used error: command 'gcc' failed with exit status 1 Any ideas? ;-) Clueless in Edmonton... ---Fausto From zen19725 at zen.co.uk Sun Aug 28 19:38:59 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 29 Aug 2005 00:38:59 +0100 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> Message-ID: On Sun, 28 Aug 2005 20:34:07 GMT, Bryan Olson wrote: >phil hunt wrote: > > Yes, find solutions. Don't find dangerous dead-ends that look like > > solutions but which will give you lots of trouble. > >If concurrency is a dead end, why do the programs that provide >the most sophisticated services of any in the world rely on it >so heavily? Some times concurrency is the best (or only) way to do a job. Other times, it's more trouble than its worth. A good programmer will know which is which, and will not use an overly complex solution for the project he is writing. -- Email: zen19725 at zen dot co dot uk From shane at hathawaymix.org Tue Aug 2 12:28:30 2005 From: shane at hathawaymix.org (Shane Hathaway) Date: Tue, 02 Aug 2005 10:28:30 -0600 Subject: time.clock() or time.time() In-Reply-To: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> References: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> Message-ID: <42EF9F2E.3080205@hathawaymix.org> peterbe at gmail.com wrote: > What's the difference between time.clock() and time.time() > (and please don't say clock() is the CPU clock and time() is the actual > time because that doesn't help me at all :) > > I'm trying to benchmark some function calls for Zope project and when I > use t0=time.clock(); foo(); print time.clock()-t0 > I get much smaller values than when I use time.clock() (most of them > 0.0 but some 0.01) > When I use time.time() I get values like 0.0133562088013, > 0.00669002532959 etc. > To me it looks like time.time() gives a better measure (at least from a > statistical practical point of view). time.time() is very likely what you want. time.time() measures real time, while time.clock() measures the time the CPU dedicates to your program. For example, if your function spends 2 seconds doing pure I/O and 3 seconds doing pure computation, you should expect time.time() to show 5 that seconds elapsed, and time.clock() to show that the CPU was consumed by your program for 3 seconds. Shane From http Sun Aug 21 05:41:54 2005 From: http (Paul Rubin) Date: 21 Aug 2005 02:41:54 -0700 Subject: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: <7x7jeflj8d.fsf@ruckus.brouhaha.com> Bryan Olson writes: > seq[3 : -4] > > we write: > > seq[3 ; $ - 4] +1 > When square-brackets appear within other square-brackets, the > inner-most bracket-pair determines which sequence '$' describes. > (Perhaps '$$' should be the length of the next containing > bracket pair, and '$$$' the next-out and...?) Not sure. $1, $2, etc. might be better, or $ like in regexps, etc. > So really seq[-2] should be out-of-bounds. Alas, that would > break way too much code. For now, simple indexing with a > negative subscript (and no '$') should continue to index from > the high end, as a deprecated feature. The presence of '$' > always indicates new-style slicing, so a programmer who needs a > negative index to trigger a range error can write: > > seq[($ - $) + index] +1 > Commas are already in use to form tuples, and we let them do > just that. A slice is a subscript that is a tuple (or perhaps we > should allow any sequence). We could just as well write: > > index_tuple = (start, stop, step) > sequence[index_tuple] Hmm, tuples are hashable and are already valid indices to mapping objects like dictionaries. Having slices means an object can implement both the mapping and sequence interfaces. Whether that's worth caring about, I don't know. From spamsink42 at gmail.com Mon Aug 29 12:16:48 2005 From: spamsink42 at gmail.com (spamsink42 at gmail.com) Date: 29 Aug 2005 09:16:48 -0700 Subject: socket.gaierror from httplib Message-ID: <1125332208.810975.92280@g43g2000cwa.googlegroups.com> this code h=httplib.HTTPConnection('euronext.com') h.request('GET', 'http://www.euronext.com/home/0,3766,1732,00.html') fails with this message File "httplib.py", line 532, in connect socket.SOCK_STREAM): socket.gaierror: (-2, 'Name or service not known') what am i doing wrong? thanks eric From dek at scooby.lbl.gov Thu Aug 11 12:05:06 2005 From: dek at scooby.lbl.gov (David E. Konerding DSD staff) Date: Thu, 11 Aug 2005 16:05:06 +0000 (UTC) Subject: wxPython and threads again References: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> Message-ID: On 2005-08-10, Peter Hansen wrote: > David E. Konerding DSD staff wrote: >> Further, calling wx from a thread other than the one running the event > > loop is deep voodoo and should typically be avoided. > > "Typically"? Let's just say "always" and maybe use the phrase "certain > to corrupt wx and crash the app" instead of "deep voodoo". :-) At least > that way the OP won't waste time experimenting... Not really certain: http://wxwidgets.org/manuals/2.6.1/wx_threadfunctions.html#threadfunctions This strongly suggests you can arbitrarily grab the wx GUI lock and call GUI functions from any thread. It's still voodoo. But we're adults here, and practicing voodoo isn't proscribed. > >> You need another way to pass completion information between the downloader >> thread and the main thread; the simplest way is to define a custom wx >> Event, and wxPostEvent from the downloader thread when it completes ( >> and when the gauge should be updated). wxPostEvent is safe to call from non-eventloop threads. >> The main thread's wx event loop just spins, properly updating all other >> parts of the GUI, and receiving events from the downloader thread. > > Even simpler for some purposes is wx.CallAfter(), which provides the > asynchronous performance of wxPostEvent with the "beautifully general" > approach of passing callables through a Queue which Bryan Olson > described in his post. (That is, you don't need to do polling with a > non-blocking get() on the Queue this way.) Very good point. I wasn't aware CallAfter had those semantics; I always used it from the main thread. But won't wx.CallAfter cause a bit of a delay since it will wait until all pending events are processed and only handle the function afterwards, thus inducing an extra event loop cycle/redraw? Dave From steve at holdenweb.com Fri Aug 19 05:24:34 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Aug 2005 10:24:34 +0100 Subject: Python jobs (was Re: Python for Webscripting (like PHP)) In-Reply-To: References: Message-ID: Aahz wrote: > In article , > Steve Holden wrote: > >>There's informal evidence that the Python secret is getting out. Sharpen >>up your resumes, guys, you may not have to limit Python to home usage >>soon :-) > > > OTOH, the big sucking sound from Google and Yahoo (plus other places > like Ironport) is making it more difficult to hire Python programmers in > the Bay Area... Not to mention the large Python gravity field a few hundred miles South emanating from Industrial Light and Magic. But don;t expect "Google and Yahoo suck" to be a popular compaint ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kay.schluehr at gmx.net Mon Aug 1 14:46:04 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 1 Aug 2005 11:46:04 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> <3l6ej1F10vf3eU1@individual.net> Message-ID: <1122921964.869376.239020@g43g2000cwa.googlegroups.com> Reinhold Birkenfeld wrote: > > In practise any Python GUI is going to contain code from otyher > > languages since if it was coded all the way down in python it would > > be too slow. > > Oh, I could imagine that a MFC-like wrapper around win32gui, or another > one around Xlib wouldn't be slower that wxWidgets is today. > > Reinhold Hi Reinhold, did You have a look at 'venster'? http://venster.sourceforge.net/htdocs/index.html They even dropped win32gui and worked with ctypes and the Win32API reducing the C-footprint. For frameworks like Dabo, AnyGUI, PyGUI etc. this would be the right level to create an abstraction layer IMO. By the way the demo applications of venster run stable and fast on WinXP. Kay From richardlewis at fastmail.co.uk Sun Aug 28 06:47:21 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Sun, 28 Aug 2005 11:47:21 +0100 Subject: Dynamic image creation for the web... In-Reply-To: References: Message-ID: <1125226041.6362.241637673@webmail.messagingengine.com> On Sun, 28 Aug 2005 09:50:17 +0000 (UTC), "Tompa" said: > Hi, > > I would like to create images on the fly as a response to an http > request. > I can do this with PIL like this (file create_gif.py): > from PIL import Image, ImageDraw > > print 'Status: 200 OK' > print 'Content-type: text/html' > print > print 'Python Dynamic Image Creation > Test' > print '' > im = Image.new("P", (600, 400)) > draw = ImageDraw.Draw(im) > draw.rectangle((0, 0) + im.size, fill="blue") > im.save("images/tmp.gif"); > print '' > print '' > > > However, I would like to 1) avoid saving the image in a file on disk and > 2) separate the HTLM code from the python image creation code. > > Something like this is what I have in mind: > (file index.html): > > > Python Dynamic Image Creation > > Image created on the fly... > > > and in file create_image.py: > from PIL import Image, ImageDraw, ImageFont > im = Image.new("P", (600, 400)) > draw = ImageDraw.Draw(im) > draw.rectangle((0, 0) + im.size, fill="blue") > > > Unfortunately this does not work :-( > What is missing? > It would be useful to know what web server software you're using. With Apache you should be able to force it to tell clients that your scripts are returning images by using the AddType directive form mod_mime (http://httpd.apache.org/docs/2.0/mod/mod_mime.html.en#addtype). The other thing you may need to check is the HTTP header of the generated image. It should be possible to create an HTTP response from your create_image.py script (as opposed to just an image) with a MIME type of image/jpeg and manually insert the binary image data in the response body... Cheers, Richard From spe.stani.be at gmail.com Fri Aug 12 21:54:44 2005 From: spe.stani.be at gmail.com (spe.stani.be at gmail.com) Date: 12 Aug 2005 18:54:44 -0700 Subject: "Compile time" checking? In-Reply-To: <1123708379.036298.134210@g43g2000cwa.googlegroups.com> References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123708379.036298.134210@g43g2000cwa.googlegroups.com> Message-ID: <1123898084.217003.172000@z14g2000cwz.googlegroups.com> Hi, If you find something like that, please report it to the bug tracker of SPE with an easy example. Also mention that PyChecker is slow, I might have another look at it. Probably I need to update the version, as SPE ships with the 0.8.13 version. I don't think it's possible to get it already in the next release as now SVN is frozen for new features, as I probably will release sunday the new SPE. The screenshots are already updated. BTW, maybe a time for a poll: which checker is better? PyChecker or PyLint? Stani http://pythonide.stani.be (mind the new url!) http://pythonide.stani.be/screenshots http://developer.berlios.de/bugs/?group_id=4161 (SPE bugtracker) From amk at amk.ca Fri Aug 19 08:28:35 2005 From: amk at amk.ca (A.M. Kuchling) Date: Fri, 19 Aug 2005 07:28:35 -0500 Subject: Database of non standard library modules... References: Message-ID: On Fri, 19 Aug 2005 10:33:16 +0100, Steve Holden wrote: > While cheeseshop might resonate with the Monty Python fans I have to say > I think the name sucks in terms of explaining what to expect. If I ask > someone where I can find a piece of code and the direct me to the cheese > shop, I might look for another language. Point them at the Python Package Index: , which is just proxying for cheeseshop.python.org. Many names were brought up (I think all this discussion was on the catalog SIG), but none of them was widely liked. So Richard Jones, the maintainer, got to choose. --amk From theller at python.net Mon Aug 15 11:47:42 2005 From: theller at python.net (Thomas Heller) Date: Mon, 15 Aug 2005 17:47:42 +0200 Subject: Determining win32 dll dependency References: Message-ID: <8xz3jj6p.fsf@python.net> Robin Becker writes: > A client requested that I send MSVCR71.DLL along with the rest of an > application as it wasn't present on his machine. > > That is allowed as > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_c_run.2d.time_libraries.asp > > seems to explicitly allow for this. For a discussion about the rights (or not) to distribute msvcr71.dll you could read the py2exe-users lists archive. > I would like to automate my build script to include this file, but > cannot think of an automatic way to determine which of msvcr70/71.dlls > .... are needed. py2exe contains an extension module that determines binary dependencies: >>> from py2exe.py2exe_util import depends >>> impport pprint >>> pprint.pprint(depends(r"c:\windows\system32\notepad.exe").keys()) ['C:\\WINDOWS\\system32\\USER32.dll', 'C:\\WINDOWS\\system32\\SHELL32.dll', 'C:\\WINDOWS\\system32\\comdlg32.dll', 'C:\\WINDOWS\\WinSxS\\X86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\\COMCTL32.dll', 'C:\\WINDOWS\\system32\\ADVAPI32.dll', 'C:\\WINDOWS\\system32\\msvcrt.dll', 'C:\\WINDOWS\\system32\\WINSPOOL.DRV', 'C:\\WINDOWS\\system32\\GDI32.dll', 'C:\\WINDOWS\\system32\\KERNEL32.dll'] >>> Thomas From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 31 12:36:36 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 31 Aug 2005 18:36:36 +0200 Subject: What are new-style classes? In-Reply-To: References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> <3nk08hF1snjcU1@individual.net> Message-ID: <3nm4kkF26v7eU1@individual.net> Terry Hancock wrote: > On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote: >> The customary way is to use "class new_class(object):". There's no advantage in using >> __metaclass__ except that you can set it globally for all classes in that module >> (which can be confusing on its own). >> >> My comment mostly referred to "new-style classes must be declared as a subclass of >> a new-style class", which is not true. > > Nonsense. Given the rest of your post, I assume that this isn't meant as it sounds. Remember, I'm German, so please bear with my sense of humour. ;) > "__metaclass__" is simply an implementation detail. > > We know that because it begins with "__". > > Therefore it is invisible, and any delusion you may have that > you can see it is a complete non-issue. > > In Python we call that encapsulation. > > ;-D Reinhold From bob at greschke.com Thu Aug 4 22:37:31 2005 From: bob at greschke.com (Bob Greschke) Date: Thu, 4 Aug 2005 20:37:31 -0600 Subject: Setting a drive's volume label References: <2NmdnaO6zf9Q323fRVn-pQ@nmt.edu> <3lbahoF1143nqU1@individual.net> Message-ID: "Reinhold Birkenfeld" wrote in message news:3lbahoF1143nqU1 at individual.net... > Bob Greschke wrote: >> Looks like the "label" system command will do it in Windows. That's good >> enough for this exercise. So, in Linux...??? > > "mlabel" in the "mtools" package will do what you need. "mkfs.vfat" can > also > be given a volume label, but it will not allow you to set the label > without > creating a new filesystem :) > > Reinhold Perfect! (Never heard of them :) Thanks! Bob From rowen at cesmail.net Wed Aug 24 17:03:43 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Wed, 24 Aug 2005 14:03:43 -0700 Subject: How to get a unique id for bound methods? References: Message-ID: In article , "Fredrik Lundh" wrote: >Russell E. Owen wrote: > >> Having looked at it again, it is familiar. I copied it when I wrote my >> own code. I avoided using at the time both because the initial >> underscore suggested it was a private method and because it introduces >> an extra function call. >> >> _register has the same weakness that my code had when I used id(func) -- >> it uses the id of the function to generate the unique tk function name, >> but it keeps no reference to that function. >> >> Either Tkinter is clever about keeping a reference to each callable >> around, or else it has the same bug I was seeing and it just doesn't >> show up often enough to have been caught. I should take some time and >> look into that. > >of course it keeps a reference to it; how else do you expect >the Tcl command to find the right PyObjects? Right. Of course. I started out emulating the code for _register but over time made various incremental changes. Eventually I messed up and started taking the id of the wrong thing. I was able to fix that and all is well -- without having to use the mysterious hash function. I also now keep a reference to the tk function name so I can properly delete it when finished. That eliminates a small memory leak. Thanks for all your help. -- Russell From rowen at cesmail.net Fri Aug 19 19:33:22 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Fri, 19 Aug 2005 16:33:22 -0700 Subject: How to get a unique id for bound methods? References: Message-ID: In article , Benji York wrote: >Russell E. Owen wrote: >> The id of two different methods of the same object seems to be the >> same, and it may not be stable either. > >Two facts you're (apparently) unaware of are conspiring against you: > >1) the "id" of an object is consistent for the lifetime of the object, >but may be reused after the object goes away > >2) methods are bound on an as-needed basis and then normally discarded >(unless you do something to keep them around) Thank you and Bengt Richter. You both explained it very well. The current issue is associated with Tkinter. I'm trying to create a tk callback function that calls a python "function" (any python callable entity). To do that, I have to create a name for tk that is unique to my python "function". A hash-like name would be perfect, meaning a name that is always the same for a particular python "function" and always different for a different python "function". That would save a lot of housekeeping. Does the built-in hash function actually do the job? If I centralize all tk callback management and keep objects that represent the tk callback around then I can avoid the whole issue. I was hoping to avoid that, because it complicates housekeeping and adds a risk of memory leaks (at least I think so; right now tk deallocates its callback functions in the few cases I care about so I don't worry about it.) -- Russell P.S. Paolino: thank you also for your kind reply. Your suggestion sounds very useful if I only want a hash for a bound function, but in this case since I want a hash for any callable entity I'm not sure it'll work. From pinard at iro.umontreal.ca Thu Aug 4 14:50:18 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Thu, 4 Aug 2005 14:50:18 -0400 Subject: [ANN] pylint 0.7 In-Reply-To: <20050527105926.GC4750@logilab.fr> References: <20050527105926.GC4750@logilab.fr> Message-ID: <20050804185018.GA17068@phenix.progiciels-bpi.ca> [Sylvain Th?nault] > I'm pleased to announce a new release of PyLint. Bonjour Sylvain. J'ai la compulsion de dire bonjour, et merci! (On peut me tutoyer sans probl?me.) Ce logiciel `pylint', que je viens d'installer et d'essayer pour la premi?re fois ce matin (donc, j'?cris encore sur l'effet d'une premi?re impression), me semble vraiment excellent. Plaisir suppl?mentaire, `logilab.common' semble contenir de bien belles choses, int?ressantes pour moi, je vais regarder ?a de plus pr?s. ?tant moi-m?me plut?t tatillon sur les questions stylistiques, je suis heureux de trouver quelqu'un qui, en plus de parler ma langue, poss?de probablement le m?me d?faut. > Please send any bugs or comments on the mailing list. Dois-je vraiment passer par l?? Les discussions sont n?cessairement un petit peu plus impersonnelles sur une liste. Si oui, alors je le ferai, bien s?r. J'imagine qu'il faut alors s'y inscrire aussi? De petites choses qui m'ont tout de suite saut? aux yeux: * `pylint --version' devrait fournir l'adresse o? rapporter les probl?mes. * `pylint --generate-rcfile' engendre un fichier qui poss?de trop d'espace blanc intempestif, en particulier ? la fin de plusieurs lignes, et aussi, ? la toute fin du fichier. Il serait int?ressant aussi que le fichier engendr? se tienne dans 79 colonnes: pas toujours possible pour le code, j'en conviens, mais au moins faisable pour les commentaires. * `pylint --parseable=y' pourrait peut-?tre, sous option, ?viter les noms de fichiers absolus et garder une notation relative, cela ?liminerait passablement de bruit lorsque le r?pertoire courant est nich? profond?ment. * Malgr? son origine fran?aise, `pylint' n'est pas sensible ? un "locale" fran?ais. J'imagine que l'internationalisation n'est pas pr?vue? Merci bien pour PYLINTHOME et PYLINTRC, les variables d'environnement. J'en fait d?j? bon usage. :-) D'une certaine mani?re dans la m?me mentalit? de `pylint', j'ai produit une sorte de redresseur stylistique que j'utilise directement de l'int?rieur de Vim. J'ai probablement pens? un peu ? Emacs tout aussi bien en l'?crivant, mais je n'ai pas utilis? Emacs depuis un bon moment. Je d?sire bient?t replonger dans ce redresseur et le d?poussi?rer s?rieusement, pour un autre gros projet. Il vaudrait peut-?tre la peine de voir s'il m'est possible d'harmoniser mon outil au tien, et vice-versa peut-?tre, un peu. Du m?me jet, il m'intrigue de comparer le module `compiler' de Python 2.3, qui ne me satisfait plut?t bien, mais pas tout-?-fait, avec le module `astng' de Logilab. Donc, en bref, survole: http://fp-etc.progiciels-bpi.ca/showfile.html?name=pynits/pynits.txt&mode=vim pour "sentir" si nos approches ont quelques atomes crochus! :-) Si oui, cela peut ouvrir la porte ? quelques bonnes discussions sur l'art et la mani?re, en Python. Ma m?re disait parfois: "Des go?ts et des couleurs, on ne discute pas. Mais il y en a de meilleurs que d'autres." -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From jsaker at americanrelay.com Thu Aug 11 18:40:32 2005 From: jsaker at americanrelay.com (James Saker) Date: Thu, 11 Aug 2005 17:40:32 -0500 Subject: SSL postgresql & pgdb Message-ID: <200508111740.32367.jsaker@americanrelay.com> Just curious if anyone's aware of a good recipe for setting up SSL access to postgresql for pgdb (or another appropriate db-sig 2 compliant module). Or any good recommendations/considerations e.g. m2crypto with pgdb. jamie From pierre.barbier at cirad.fr Mon Aug 29 13:02:16 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 29 Aug 2005 19:02:16 +0200 Subject: GIL, threads and scheduling - performance cost In-Reply-To: <1125333120.069180.293360@g44g2000cwa.googlegroups.com> References: <1125329306.425235.210840@f14g2000cwb.googlegroups.com> <4313367d$0$1830$626a14ce@news.free.fr> <1125333120.069180.293360@g44g2000cwa.googlegroups.com> Message-ID: <43133ed2$0$9084$636a15ce@news.free.fr> adsheehan at eircom.net a ?crit : > Merci Pierre, > > Yes I agree and plan to move more to C/C++ and releasing the GIL when > entering C/C++. > > I also need to understand my original question re GIL and rescheduling. > I fear that lock/unlock too often is also causing delays due to context > switching. Well, concerning GIL and rescheduling, releasing a lock is very likely to induce rescheduling and context switch, but it won't if the system considers it worthless. But this is true that lock/unlock has a cost and so, doing it too much will slow down your app. > > BTW do you have any hints/comments on SWIG/BOOST etc to glue PY and > C/C++ ? Well, for C I would recommand SWIG. For C++, I personnaly use Boost.Python. However, you must know that SWIG did not support C++ well when I had to choose between the two, so there was no question for me. Then, somehow it depends on how you feel with the tools: SWIG depends on a specific language and has its own tools while Boost is entirely written in C++ and uses heavily templates. For performances, Boost generate better code that SWIG, mainly because SWIG relies on Python code that encapsulate the actual C functions while Boost does everything in C++. Also, at least with G++, compiling Boost extension is very time- and memory-consuming due to its heavy use of templates. As I don't use SWIG, I don't know about the community, but at least for Boost.Python it is quite active and questions on the mailing list are answered quickly enough. Well, this is very quick but if you need more detailed information, I recommend you to visit both websites. > > > Alan > Pierre From jack at performancedrivers.com Thu Aug 25 14:04:52 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Thu, 25 Aug 2005 14:04:52 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <797fe3d4050825103556f49018@mail.gmail.com> References: <797fe3d4050825103556f49018@mail.gmail.com> Message-ID: <20050825180452.GC5991@performancedrivers.com> On Thu, Aug 25, 2005 at 01:35:04PM -0400, Bill Mill wrote: > On 8/25/05, Erik Max Francis wrote: > > Mark Dickinson wrote: > > > > > Questions: > > > > > > (1) Can anyone else reproduce this behaviour, or is it just some quirk > > > of my setup? > > > (2) Any possible explanations? Is there some optimization that kicks > > > in at a certain number of lines, or at a certain length of > > > bytecode? > > > (3) If (2), is there some way to force the optimization, so that I can > > > get the speed increase without having to add the extra lines? > > > > I did find, though, that if I remove all print statements from the > program, the dummy and non-dummy variable versions take indentical > time. Can others reproduce this? > > I'm Investigating further... I'm getting similarly freakish results. I tried a little ghetto debugging by putting a printf in dictobject.c's resize method and recompiling python. Sadly I can't get the problem to reproduce itself with the new binary (with or without the printf). The Ubuntu default 2.4.1 is sometimes fast, my hand compiled one (./configure && make) is always slow. There are some very arcane low level things going on here. sprat:~/src/Python-2.4.1# time ./python /tmp/odd.py > /dev/null 7.876u 0.008s 0:07.91 99.4% 0+0k 0+0io 0pf+0w sprat:~/src/Python-2.4.1# time python /tmp/odd.py > /dev/null 1.813u 0.004s 0:01.77 102.2% 0+0k 0+0io 0pf+0w sprat:~/src/Python-2.4.1# ./python Python 2.4.1 (#5, Aug 25 2005, 13:55:44) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> sprat:~/src/Python-2.4.1# python Python 2.4.1 (#2, Mar 30 2005, 21:51:10) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> No-idea-ly, -jackdied From martin at v.loewis.de Mon Aug 15 01:31:25 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 15 Aug 2005 07:31:25 +0200 Subject: distutils on Win32 using .NET Framework SDK In-Reply-To: References: Message-ID: <430028AD.1050505@v.loewis.de> Jerry He wrote: > Hi, > I was trying to build a C++ extension on Win32 with > distutils. The extension worked on Cygwin but when I > tried it with the Win32-build python, it complained > that I don't have .NET Framework SDK installed. But > after I installed .NET Framework SDK 2.0, it still > complains > "error: The .NET Framework SDK needs to be installed > before building extensions for Python." (I also did > try restarting my computer) > > Does anyone know how to make the .NET Framework SDK > visible to Python? It looks in HKEY_{LOCAL_MACHINE,CURRENT_USER}\Software\Microsoft\.NETFramework\FrameworkSDKDir This registry key should be set automatically if you choose to install the SDK that comes with Microsoft Visual Studio 2003. Not sure why you are trying to install .NET 2.0, though. Regards, Martin From foo at bar.org Wed Aug 10 02:35:31 2005 From: foo at bar.org (stasz) Date: Wed, 10 Aug 2005 08:35:31 +0200 Subject: gettext again References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> <42f77cb6$0$25055$8fcfb975@news.wanadoo.fr> <42f9273d$0$22313$8fcfb975@news.wanadoo.fr> Message-ID: On Tue, 09 Aug 2005 23:59:26 +0200, cantabile wrote: > stas a ?crit : > >> As a reminder, make sure that you install gettext in the namespace >> of your toplevel module. [....] > Noticed something : > I must import test2.py AFTER gettext.install('test1') and even then, if > test3.py imports test2.py, messages won't be translated in test3.py. I > have to import test3.py in test1.py too. > Is this normal behaviour or is there something I'm missing (again) ? Hmm, perhaps I missed something, namespaces can be sometimes hard to get right. Let's see: test1 imports and installs gettext. Now test1 holds the gettext reference. test1 imports test2 and test3 and 'inherits' test1 namespace test2 and test3 have access to test1 namespace and the gettext. So in (pseudo) Python code test1 would looks like this: import gettext gettext.install(test)# assuming test.mo holds all the strings import test2, test3 Another approach would be to place the whole gettext install stuff in a separate module wrapped in a function which can be imported by every module that wants language support. (That's the approach I always use) Contents of utils.py (Code is not tested, it's to show the principals) import locale, gettext def set_gettext(mo_location='/usr/share/locale'): locale.setlocale(locale.LC_ALL) gettext.install('test1', mo_location) Now in your modules you could do this: In test1.py: from utils import set_gettext set_gettext()# remember gettext.install installs '_' in the # current namespace, in this case test1. import test2, test 3 In test4.py from utils import set_gettext set_gettext() .... .... Now test1 and test2 get their gettext from test1 while test4 import gettext from utils.py which installs the same mo file as it did in test1, test2 and test3. > PS : your project looks nice ! Thanks. BTW, the principal of gettext in utils.py is also implemented in the gvr project, so you have a real life example there :-) Stas From olekristianvillabo at gmail.com Thu Aug 25 08:11:26 2005 From: olekristianvillabo at gmail.com (olekristianvillabo at gmail.com) Date: 25 Aug 2005 05:11:26 -0700 Subject: MySQLdb module, method executemany with anything other than strings? In-Reply-To: References: <1124962000.842751.125710@g49g2000cwa.googlegroups.com> Message-ID: <1124971886.846812.238020@g43g2000cwa.googlegroups.com> I just realised that myself about two minutes ago, but thanks anyway! From tchur at optushome.com.au Fri Aug 12 20:48:30 2005 From: tchur at optushome.com.au (Tim Churches) Date: Sat, 13 Aug 2005 10:48:30 +1000 Subject: Cheese shop (was Re: python2.4/site-packages) In-Reply-To: References: <7sadneieT7f10mHfRVn-gw@speakeasy.net> Message-ID: <42FD435E.40607@optushome.com.au> Michael Hoffman wrote: >Ben Finney wrote: > > > >>Conversely, PyPI is a dull name with no obvious pronunciation, thus >>difficult to remember; whereas Cheese Shop is a short phrase (that can >>be translated), is easy to remember and has easy analogies to its >>actual function. >> >> > >A place you visit where you can never find what you want? > > Indeed. A place completely uncontaminated by cheese: http://www.minderella.com/words/cheeseshop.htm Tim C From fakeaddress at nowhere.org Sat Aug 27 04:00:45 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 27 Aug 2005 08:00:45 GMT Subject: Virtual Slicing Message-ID: I recently wrote a module supporting value-shared slicing. I don't know if this functionality already existed somewhere, but I think it's useful enough that other Pythoners might want it, so here it is. Also, my recent notes on Python warts with respect to negative indexes were based on problems I encoutered debugging this module, so I'm posting it partially as a concrete example of what I was talking about. -- --Bryan ---------------------------------------------------------------- """ vslice.py by Bryan G. Olson, 2005 This module is free software and may be modified and/or distributed under the same terms as Python itself. Virtual Slicing differs from normal Python slicing in that that the cells in the given sequence are not copied; they are shared between the underlying sequence and the VSlice. VSlices are themselves Python sequences. You can index VSlices, slice them, iterate over them, get their len(), test 'if val in', compare them, add them, and multiply them by integers. The 'vslice' function creates virtual slices of sequences: vslice(sequence, start, stop, step) returns an instance of VSlice that is much-the-same-as: sequence[start : stop : step] The default for start, stop and step is None, and passing None or omitting parameters works the same as in Python slicing. VSlices also have read-only properties 'sequence', 'start', 'stop' and 'step', in case you need to access the underlying sequence directly. Like Python's 'slice' object, the stop value will be negative if and only if step is negative and the slice includes the zero index. A VSlice of a VSlice will use the same underlying sequence. It will translate the start-stop-step values upon construction, so later access will go through only one layer of VSlicing. The sequence, start, stop, and step properties of the VSlice-of-a-VSlice will generally not be same as the parameters passed to the vslice factory function; they relate to the underlying sequence. >>> a = range(100) >>> from vslice import vslice >>> vs1 = vslice(a, 10, None, 2) >>> vs2 = vslice(vs1, 2, -2, 3) >>> >>> print vs2 == a[10 : None : 2][2 : -2 : 3] True >>> print vs2.sequence == vs1 False >>> print vs2.sequence == a True >>> print vs2.sequence is a True >>> print vs2.start, vs2.stop, vs2.step 14 96 6 >>> print vs2 == a[14 : 96 : 6] True If the underlying sequence is mutable, the VSlice is semi- mutable. You can assign to elements, but not insert nor delete elements; similarly, no append, push, pop and such. Slice assignments must have the same length slice on both sides. A slice of a VSlice is a regular Python slice; it is a copy made by slicing the underlying sequence with translated start-stop-step values. For sane sequence types, the slice of the VSlice will therefore have the same type as the underlying sequence. A VSlice's start-stop-step and len are set on construction. Adding or removing indices from the underlying sequence will not change them, and is usually a bad thing to do. VSlices support any positive or negative integer step value, but are most efficient in both time and space when the step value is one. Fortunately, the need for any other step value is rare. The vslice function will choose between two sub- classes of VSlice, depending on whether the step is one. The VxSlice can support any step size; the V1Slice is faster and smaller, but only supports a step of one. VxSlice instances store five slots; V1Slices, 3. """ def vslice(sequence, start=None, stop=None, step=None): """ Return a VSlice (virtual slice). See module's __doc__. """ start, stop, step = slice(start, stop, step).indices(len(sequence)) if isinstance(sequence, VSlice): start = sequence.start + start * sequence.step stop = sequence.start + stop * sequence.step step *= sequence.step sequence = sequence.sequence if step == 1: return V1Slice(sequence, start, stop) else: return VxSlice(sequence, start, stop, step) from itertools import islice _type_err_note = 'VSlice index must be integer or slice.' _module_doc = __doc__ class VSlice (object): __doc__ = _module_doc def __init__(self, *args): if self.__class__ == VSlice: raise RuntimeError("Attempt to instantiate abstract base " + "class VSlice. To create a VSlice, call vslice.vslice().") def get_sequence(self): return self._seq sequence = property(get_sequence, None, None, 'The underlying sequence, never itself a VSlice.') def get_start(self): return self._start start = property(get_start, None, None, 'Inclusive bound in the underlying sequence.') def get_stop(self): return self._stop stop = property(get_stop, None, None, 'Exclusive bound in the underlying sequence.') def get_step(self): return self._step step = property(lambda self: self.get_step(), None, None, 'Size of steps relative to the underlying sequence.') def __getitem__(self, key): if isinstance(key, (int, long)): return self._seq[self._translate(key)] elif isinstance(key, slice): (start, stop, step) = self._translate_slice(key) return self._seq[start : stop : step] else: raise TypeError(_type_err_note) def __setitem__(self, key, value): if isinstance(key, (int, long)): self._seq[self._translate(key)] = value elif isinstance(key, slice): (start, stop, step) = self._translate_slice(key) self._seq[start : stop : step] = value else: raise TypeError(_type_err_note) def __cmp__(self, other): # Compare progressively larger chunks. start, stop = 0, 4 while 1: me = self[start : stop] them = other[start : stop] if me != them: return cmp(me, them) if len(me) < stop - start: return 0 start, stop = stop, stop + stop def __repr__(self): return 'vslice(%s)' % repr(self[:]) def __add__(self, term): return self[:] + term def __mul__(self, term): return self[:] * term def __hash__(self): return hash(self[:]) # Various bad ideas for def __getattr__(self, name): # return getattr(self[:], name) # return getattr(self[0:0], name) # return getattr(self._seq, name) class V1Slice (VSlice): 'VSlice subclass for step == 1' __slots__ = '_seq', '_start', '_stop' def __init__(self, sequence, start, stop): self._seq, self._start, self._stop = sequence, start, stop def get_step(self): return 1 def __len__(self): return self._stop - self._start def __iter__(self): return islice(self._seq, self._start, self._stop) def _translate(self, i): length = self._stop - self._start if not -length <= i < length: raise IndexError return slice(i, i + 1).indices(length)[0] def _translate_slice(self, key): start, stop, step = key.indices(len(self)) stop = self._start + stop if stop < 0: stop = None return (self._start + start, stop, step) class VxSlice(VSlice): 'VSlice subclass for step of any integer' __slots__ = '_seq', '_start', '_stop', '_step', '_length' def __init__(self, sequence, start=None, stop=None, step=1): self._seq, self._start, self._stop, self._step = ( sequence, start, stop, step) self._length = max(0, (self._stop - self._start + self._step - (self._step / abs(self._step))) // self._step) def __len__(self): return self._length def __iter__(self): if self._step >= 0: return islice(self._seq, self._start, self._stop, self._step) else: def gen(): seq, i, stop, step = (self._seq, self._start, self._stop, self._step) while i > stop: yield seq[i] i += step return gen() def _translate(self, index): if index < 0: index = self._length + index if index < 0 or index > self._length: raise IndexError('VxSlice index %d out of range' % index) return self._start + (index * self._step) def _translate_slice(self, key): start, stop, step = key.indices(self._length) start, stop, step = ( self._start + (start * self._step), self._start + (stop * self._step), step * self._step) if stop < 0: stop = None return (start, stop, step) def test(): print __doc__ def assert_equal(vslice, target): assert len(vslice) == len(target) assert vslice == target assert vslice[:] == target assert vslice[: 7L] + vslice[7 :] == target assert vslice[::-1][::-1] == target assert [x for x in vslice] == [x for x in target] blist, clist, dlist = [], [], [] for i in range(len(vslice)): blist.append(vslice[i]) j = 0 - i - 1 clist.append(vslice[j]) dlist.append(vslice[long(i)]) assert blist == [x for x in target] clist.reverse() assert clist == [x for x in target] assert dlist == [x for x in target] assert vslice[2 : -3] == target[2 : -3] base = [1 + 2 * n for n in range(100)] a = base[:] # Test various copies va = vslice(a) assert_equal(va, a) assert_equal(vslice(a, None, None, -1), a[:: -1]) assert_equal(vslice(va, None, None, -3), a[:: -3]) assert_equal(vslice(a, 4L, 67, 5), a[4: 67 : 5]) assert_equal(vslice(va, -84, 67, 4), a[-84: 67 : 4]) assert_equal(vslice(va, 22, -12, 8), a[22: -12 : 8]) assert_equal(vslice(va, -91, -17, 7), a[-91: -17 : 7]) assert_equal(vslice(a, -97, -10, -6), a[-97: -10 : -6]) assert_equal(vslice(va, -83, -11, -3), a[-83: -11 : -3]) # Test some updates va[6 : 82 : 7] = [6 + x * 17 for x in range(4, 80, 7)] assert_equal(va, a) a[22] = 9427 assert_equal(va, a) b = base[:] vb = base[:] assert_equal(vb, b) b[37] = 61107 assert tuple(b) != tuple(vb) vb[37] = 61107 assert tuple(b) == tuple(vb) newjunk = [12 + x * 3 for x in range(4, 80, 7)] b[5 : 80 : 7] = newjunk assert tuple(b) != tuple(vb) vb[5 : 80 : 7] = newjunk assert tuple(b) == tuple(vb) print "Good." if __name__ == '__main__': test() From tjreedy at udel.edu Mon Aug 15 18:44:52 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Aug 2005 18:44:52 -0400 Subject: Bug on Python2.3.4 [FreeBSD]? References: <1123906696.459433@yasure> Message-ID: "Donn Cave" wrote in message news:donn-AD45A7.10101015082005 at gnus01.u.washington.edu... > In article , > "Terry Reedy" wrote: > ... >> If there is a hole in the standard, 'innovation' is required. > > I hope this perspective is a rarity. I think you over interpreted. The ''s were intentional. Let me reword. If one if implementing a standard and it is *silent* on an initial condition then one must *choose* something (or let it be complete accident, and even possibly invalid). If there is one accessible and known existing 'standard' practice that is at least as reasonable as anything else, and the hole seems to be an accident rather than intentional, then I too would want to be that choice made. But if there are two existing 'standard' practices, then there is a real choice to be made. (But either would be better than a third.) > In the present case, so far I see a strong Berkeley vs. everyone > else pattern, so GNU C probably wasn't the culprit after all. > Along with already documented FreeBSD, I find MacOS X, NetBSD 2 > and Ultrix 4.2 position the read stream to EOF. Linux, AIX and > DEC/OSF1 (or whatever it's called these days) position it to 0. The person I responded to gave almost none of this detail. With this info, and the knowledge that Berkeley got Unix from Bell Labs about 1975, I speculate that the hole of not specifying the initial read position was intentional due to divergent well-established prior arts that neither group wanted to give up. And yes, I also wish that someone had. I even wish the committee had at least specified 'either 0 or EOF' to preclude a Solomonic compromise like EOF//2. Terry J. Reedy From bdesth.quelquechose at free.quelquepart.fr Sun Aug 14 16:44:43 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 14 Aug 2005 22:44:43 +0200 Subject: How can I exclude a word by using re? In-Reply-To: References: <1124031736.367193.219920@g44g2000cwa.googlegroups.com> Message-ID: <42ffa598$0$23697$636a15ce@news.free.fr> could ildg a ?crit : > Thank you. > But what should I do if there are more than one hello and I only want > to extract what's before the first "hello". Read The Fine Manual ?-) > For example, the raw > string is "hi, how are you? hello I'm fine, thank you hello. that's it > hello", I want to extract all the stuff before the first hello? re.findall(r'^(.*)hello', your_string_full_of_hellos) From eric.pederson at gmail.com Mon Aug 8 14:02:56 2005 From: eric.pederson at gmail.com (eric.pederson at gmail.com) Date: 8 Aug 2005 11:02:56 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <42f78937.926582004@news.oz.net> References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <42f78937.926582004@news.oz.net> Message-ID: <1123524176.145676.320060@z14g2000cwz.googlegroups.com> That's it: got to get the PEEPs involved. Acronym of the year (AOTY). From sjmachin at lexicon.net Thu Aug 11 07:19:55 2005 From: sjmachin at lexicon.net (John Machin) Date: Thu, 11 Aug 2005 21:19:55 +1000 Subject: regex help In-Reply-To: References: Message-ID: <42fb345a$1@news.eftel.com> jeff sacksteder wrote: > Regex questions seem to be rather resistant to googling. > > My regex currently looks like - 'FOO:.*\n\n' > > The chunk of text I am attempting to locate is a line beginning with > "FOO:", followed by an unknown number of lines, terminating with a > blank line. Clearly the ".*" phrase does not match the single newlines > occuring inside the block. > > Suggestions are warmly welcomed. I suggest you read the manual first: """ "." (Dot.) In the default mode, this matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline. """ From gsakkis at rutgers.edu Mon Aug 1 10:15:02 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 1 Aug 2005 07:15:02 -0700 Subject: namespaces References: <42EC9690.2040301@tiscali.it> Message-ID: <1122905702.119539.192060@g44g2000cwa.googlegroups.com> Paolino wrote: > >>Even worse I get with methods and function namespaces. > > > > What is "even worse" about them? > > > For my thinking, worse is to understand how they derive their pattern > from generic namespaces. > Methods seems not to have a writeble one,while functions as George and > Rob remembered have one which is not read only.Why? I'm not sure I can parse this successfully, let alone understand it. George From cito at online.de Thu Aug 4 08:27:41 2005 From: cito at online.de (Christoph Zwerschke) Date: Thu, 04 Aug 2005 14:27:41 +0200 Subject: Art of Unit Testing In-Reply-To: <1123118470.749836.279610@g14g2000cwa.googlegroups.com> References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> <1123118470.749836.279610@g14g2000cwa.googlegroups.com> Message-ID: > Your own feature request for setUpOnce() and tearDownOnce() is > trivially coded using a global or class variable to restrict running to > a single occasion. If that seems unpleasant, then encapsulate the > logic in a subclass of TestCase, in a decorator, or in a metaclass. Ok, you can have a setUpOnce() at module level that way, but how do you realize tearDownOnce() that way? I think what you really have to do is to modify the TestSuite class, not the TestCase class. Then you don't have to fool around with global or class variables. -- Christoph import unittest class MyTestCase(unittest.TestCase): def setUp(self): print "setUp", def tearDown(self): print "tearDown", def test1(self): print "test1" def test2(self): print "test2" class MyTestSuite(unittest.TestSuite): def setUp(self): print "setUpAll", def tearDown(self): print "tearDownAll", def run(self, result): self.setUp() unittest.TestSuite.run(self, result) self.tearDown() if __name__ == '__main__': suite = unittest.makeSuite(MyTestCase, suiteClass=MyTestSuite) unittest.TextTestRunner().run(suite) From kay.schluehr at gmx.net Sun Aug 7 11:29:37 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 7 Aug 2005 08:29:37 -0700 Subject: Python -- (just) a successful experiment? References: <1123413907.572051.281140@g44g2000cwa.googlegroups.com> <42f62020$0$11068$e4fe514c@news.xs4all.nl> Message-ID: <1123428577.887011.283560@z14g2000cwz.googlegroups.com> Martin P. Hellwig wrote: > Kay Schluehr wrote: > > Eric Pederson wrote: > > > >>Raise your hand if you think the best technology wins! > > > > > > Who is interested in such a matter? Is this a forum dedicated to some > > programming language or a popularity contest? > > > > If Python dies in a few years / looses attention but the Python Zen > > survives in another language I have nothing to complain. > > > > Ave! > Although I think that the day that python is considerd dead is the same > day that unix is truly dead. > Ooh yes and I have heard for over two decades that unix-like systems are > obsolete, so why is the install base only growing and has never been bigger? > > -- > mph Of course "dead" has no absolute meaning for things that were never alive. May "infertile" be a better characterisation? If no new projects were started using a certain language the language ( more precisely it's runtime/libraries ) might become legacy and will be replaced continously. When the PyPy runtime becomes more mature and it's API somehow stable we might see what is possible in the dynamic language area beyond the current state of Python and also beyond Guidos projected Python3000. I guess it will sprawl into several dialects pronouncing different aspects: functional programming, concurrency, declarative programming a mainline Python3000 and a legacy Python 2.X which remains to be maintained. Thinking about this prospects I don't actually believe that Ruby-on-Rails will become a Python killer, just because it has a nice installer. Kay From bdesth.quelquechose at free.quelquepart.fr Mon Aug 22 15:51:16 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 22 Aug 2005 21:51:16 +0200 Subject: Decorator and Metaclasses Documentation In-Reply-To: References: <430980d6$0$4892$626a14ce@news.free.fr> Message-ID: <430a24f8$0$12402$626a14ce@news.free.fr> Mike C. Fletcher a ?crit : > bruno modulix wrote: > >> Mike C. Fletcher wrote: >> (snip) >> >> >>> Though the don't go into extreme detail on decorators (they are >>> basically syntactic sugar for a particular type of descriptor). >>> >>> >> >> Err... Could you elaborate on this ? Decorators are syntactic sugar for >> function wrapping, while descriptors are a 'protocol' to hook into >> attribute lookup, so I don't really see how one can describe the first >> in terms of the second... >> >> > There are two major types of descriptors, the elven and the dwarven. > > * Elven descriptors are things like property, BasicProperty, VRML97 > fields, Zope Field Properties, or PEAK's mechanisms. They mediate > access to an instance's attributes, (both setting and getting of > values) and are used primarily for domain modeling. > * Dwarven descriptors are things like staticmethod or classmethod; > function-like things that tend to look like a function and quack > like a function, but have some special property or functionality > attached when accessed as an attribute of a class/instance > (functions themselves return instance methods or class methods > depending on how they are retrieved). > Ok, I see... In fact, while reading your explanations, it reminded me of some experiments I made recently playing with descriptors, decorators and metaclasses to use callable objects implementing the descriptor protocol as instance methods of other objects (I don't know if I'll ever find a use case for this trick, but what, they're a lot of things in Python I never thought I could find a use case for at first and that I'd have hard time living without nowadays...). > > HTH, It did, thanks. From matt.hammond at rd.bbc.co.uk Mon Aug 15 04:18:29 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Mon, 15 Aug 2005 09:18:29 +0100 Subject: Permutation Generator References: Message-ID: Just satisfied my curiosity wrt this problem, so I might as well share :-) >>> def permute(list): ... if len(list) <= 1: ... yield list ... else: ... for i in xrange(0,len(list)): ... for tail in permute( list[:i] + list[i+1:] ): ... yield [ list[i] ] + tail ... >>> for o in permute([1,2,3]): ... print o ... [1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 1, 2] [3, 2, 1] regards Matt On Fri, 12 Aug 2005 20:48:38 +0100, Michael J. Fromberger wrote: > In article , > Talin wrote: > >> I'm sure I am not the first person to do this, but I wanted to share >> this: a generator which returns all permutations of a list: >> >> def permute( lst ): >> if len( lst ) == 1: >> yield lst >> else: >> head = lst[:1] >> for x in permute( lst[1:] ): >> yield head + x >> yield x + head >> return > > You're right that you're not the first person to do this: Many others > have also posted incorrect permutation generators. > > Have you tried your code on some simple test cases? > > list(permute([1, 2, 3])) > ==> [[1, 2, 3], [2, 3, 1], [1, 3, 2], [3, 2, 1]] > > Notably absent from this list are [2, 1, 3] and [2, 3, 1]. The problem > gets worse with longer lists. The basic problem is that x needs to be > able to occur in ALL positions, not just the beginning and the end. > > Cheers, > -M > -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From lycka at carmen.se Mon Aug 29 03:04:45 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 29 Aug 2005 09:04:45 +0200 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> Message-ID: Robert Kern wrote: > If I may digress for a bit, my advisor is currently working on a project > that is processing seafloor depth datasets starting from a few decades > ago. A lot of this data was orginally to be processed using FORTRAN > software, so in the idiom of much FORTRAN software from those days, 9999 > is often used to mark missing data. Unfortunately, 9999 is a perfectly > valid datum in most of the unit systems used by the various datasets. > > Now he has to find a grad student to traul through the datasets and > clean up the really invalid 9999's (as well as other such fun tasks like > deciding if a dataset that says it's using feet is actually using meters). I'm afraid this didn't end with FORTRAN. It's not that long ago that I wrote a program for my wife that combined a data editor with a graph display, so that she could clean up time lines with length and weight data for children (from an international research project performed during the 90's). 99cm is not unreasonable as a length, but if you see it in a graph with other length measurements, it's easy to spot most of the false ones, just as mistyped year part in a date (common in the beginning of a new year). Perhaps graphics can help this grad student too? It's certainly much easier to spot deviations in curves than in an endless line of numbers if the curves would normally be reasonably smooth. From kristian.zoerhoff at gmail.com Thu Aug 11 23:34:07 2005 From: kristian.zoerhoff at gmail.com (Kristian Zoerhoff) Date: Thu, 11 Aug 2005 22:34:07 -0500 Subject: Printing to printer In-Reply-To: References: Message-ID: <3511dc750508112034130ee789@mail.gmail.com> On 8/11/05, Steve M wrote: > Kristian Zoerhoff wrote: > > > On 8/11/05, Steve M wrote: > >> Hello, > >> > >> I'm having problems sending information from a python > >> script to a printer. I was wondering if someone might send me > >> in the right direction. I wasn't able to find much by Google > > > > Which platform? Directions will vary wildly. > > > Ooops, sorry forgot to mention I'm using Suse 9.0 and Python 2.3x Assuming a local printer, you could just open the appropriate device file (e.g. /dev/lp0) in write mode and write the text to it. Another option would be to create a temp file, and then feed that to the lpr or enscript commands via the subprocess module. -- Kristian kristian.zoerhoff(AT)gmail.com zoerhoff(AT)freeshell.org From benji at zope.com Tue Aug 2 15:32:14 2005 From: benji at zope.com (Benji York) Date: Tue, 02 Aug 2005 15:32:14 -0400 Subject: Fredericksburg, VA Zope and Python User Group Message-ID: <42EFCA3E.3040705@zope.com> Please join us August 10, 7:30-9:00 PM, for the third meeting of the Fredericksburg, VA Zope and Python User Group ("ZPUG"). This meeting has four features of note. - Brian Lloyd, the author of Python for .Net (http://www.zope.org/ Members/Brian/PythonNet/) and the Zope Corporation VP of Engineering, will discuss his .Net platform and give a brief .Net overview. - Benji York, Zope Corp Senior Software Engineer, will discuss current functional testing practices on Zope 3, including using Selenium on Zope 3, using demo storage for functional testing, and using his own compelling new functional test package. Note that the majority of this discussion has strong applicability to automated testing of all web frameworks and applications. - We will serve the now-usual geek-chic fruit, cheese, and soft drinks. - Fred Drake, Zope Corp Senior Software Engineer, Python core developer, Python documentation maintainer and editor, and co-author of the O'Reilly book Python & XML will give two of his books (http:// www.amazon.com/exec/obidos/tg/detail/-/0596001282/) to new attendees. Upon pressure, he admitted that he would be willing to autograph them if bribed with fruit, cheese, and soft drinks. Note that we are eager to have non-Zope-Corporation employees give presentations. :-) We had three new attendees last meeting, for a total of ten. Please come and bring friends! More information http://www.zope.org/Members/poster/ fxbgzpug_announce_3 and below. Hope to see you there! Gary General ZPUG information ------------------------------------ When: second Wednesday of every month, 7:30-9:00. Where: Zope Corporation offices. 513 Prince Edward Street; Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab). Parking: Zope Corporation parking lot; entrance on Prince Edward Street. Topics: As desired (and offered) by participants, within the constraints of having to do with Python. Contact: Gary Poster (gary at zope.com) From siona at chiark.greenend.org.uk Tue Aug 23 09:14:16 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 23 Aug 2005 14:14:16 +0100 (BST) Subject: Network performance References: Message-ID: Roland Hedberg wrote: > [ ... ] >The client sends a number of lines (each ending with \n) and ends one >set of lines with a empty line. >When the client sends a line with only a "." it means "I'm done close >the connection". > >Letting the client open the connection and sending a number of sets I >was surprised to find that the performance was equal to what Twisted/ >XMLRPC did. Around 200 ms per set, not significantly less. > >So what can be done to speed up things or is Python incapable of >supporting fast networking (just a teaser). That 200ms is a dead giveaway (if you've run into this issue before). If you've got a Linux box to hand, try sticking the server on there and see what happens. The key to what is going on is here: http://www.port80software.com/200ok/archive/2005/01/31/317.aspx The easy solutions are to either change: > def send( self, rdf ): > self.s.send( rdf ) > self.s.send( "\n" ) to def send( self, rdf ): self.s.send( rdf+"\n" ) or to self.s.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0) after connecting self.s . What's going on is something like this: 1. Client sends rdf 2. Server receives rdf. But it hasn't received the \n yet, so it doesn't have a response to send yet. And because of delayed ACK, it won't send the ACK without the DATA packet containing that response. 3. Meanwhile, the client tries to send \n, but because Nagle is on, it would make an underful packet, and it hasn't received the ACK from the last packet yet, so it holds on to the \n. 4. Eventually (after 200ms on Windows and, I believe, BSDs, hence OSX, but much less on Linux) the Server gives up waiting for a DATA packet and sends the ACK anyway. 5. Client gets this ACK and sends the \n. 6. At which point the Server has a complete line it can process, and sends its reponse in a DATA with the ACK to the \n "piggybacked". So the solutions are either send rdf+"\n" as a single packet in 1, and the exchange will skip straight to 6, avoiding the 200ms delay; or disable Nagle so 3 doesn't hold and the Client sends the \n immediately instead of waiting for the ACK in 5. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From jeremy at emperorlinux.com Wed Aug 10 01:17:03 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Wed, 10 Aug 2005 01:17:03 -0400 Subject: Adding and attribute to an instance In-Reply-To: <1123623524.732496.79460@g49g2000cwa.googlegroups.com> References: <1123623524.732496.79460@g49g2000cwa.googlegroups.com> Message-ID: <1123651023.9270.1.camel@localhost.localdomain> Hmmm--I would also be interested in knowing the answer to this. I get the exact same behavior as the OP (probably because it's the intended behavior?) On Tue, 2005-08-09 at 14:38 -0700, J wrote: > Hi, > > > I am trying to add new data attributes to my extension classes from > within a script. I am under the impression that python allows > that implicity > > > This is the definition of my class > > PyTypeObject CmdPlace::PyType = > { > PyObject_HEAD_INIT(NULL) > 0, /*ob_size*/ > "Place", /*tp_name*/ > sizeof(CmdPlace::PyStruct), /*tp_basicsize*/ > 0, /*tp_itemsize*/ > 0, /*tp_dealloc*/ > 0, /*tp_print*/ > 0, /*tp_getattr*/ > 0, /*tp_setattr*/ > 0, /*tp_compare*/ > 0, /*tp_repr*/ > 0, /*tp_as_number*/ > 0, /*tp_as_sequence*/ > 0, /*tp_as_mapping*/ > 0, /*tp_hash */ > 0, /*tp_call*/ > 0, /*tp_str*/ > PyObject_GenericGetAttr, /*tp_getattro*/ > PyObject_GenericSetAttr, /*tp_setattro*/ > 0, /*tp_as_buffer*/ > Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ > "CmdPlace", /* tp_doc */ > 0, /* tp_traverse */ > 0, /* tp_clear */ > 0, /* tp_richcompare */ > 0, /* tp_weaklistoffset */ > 0, /* tp_iter */ > 0, /* tp_iternext */ > CmdPlace::sPyMethods, /* tp_methods */ > CmdPlace::sPyMembers, /* tp_members */ > CmdPlace::sPyGetSeters, /* tp_getset */ > 0, /* tp_base */ > 0, /* tp_dict */ > 0, /* tp_descr_get */ > 0, /* tp_descr_set */ > 0, /* tp_dictoffset */ > 0, /* tp_init */ > 0, /* tp_alloc */ > 0, /* tp_new */ > }; > > I call > > PyType_Ready(&PyType); > Py_INCREF(&PyType); > > to initialize the type, and > > PyObject_INIT((PyObject*)&mPyObject, &CmdPlace::PyType); > > to initialize an object. Objects of this type are only ever > instantiated from C++. When I evaluate a sript I just add the object as > "MyObject" to the dicitonary passed to Py_Eval... All the > members and methods work fine, but when I do > > MyObject.aNewAttribue = 12 > > I get at an error saying > > object has no attribute "aNewAttribue". > > I have looked at some of the source code in PyObject_GenericGetAttr and > it turns out that the object has no dictionary. It seens that the > address of the dictionary is computed somehow via tp_dictoffset in the > type object. > > Basically my question is, how can I make this work. > > > Cheers > Jochen > From rowen at cesmail.net Tue Aug 23 18:58:16 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Tue, 23 Aug 2005 15:58:16 -0700 Subject: Sorta noob question - file vs. open? References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> Message-ID: In article <6a8ng1pjusft9cegb1cb1pvs9gfdknav16 at 4ax.com>, Peter A. Schott wrote: >Been reading the docs saying that file should replace open in our code, but >this >doesn't seem to work: > ># Open file for writing, write something, close file >MyFile = file("MyFile.txt", "w") >MyFile.write("This is a test.") >MyFile.close() This should work in a sufficiently recent version of python (I'm hedging because I don't recall when file was introduced -- python 2.2? 2.3?). What version are you using? What error do you see? -- Russell From geskerrett at hotmail.com Wed Aug 10 08:30:37 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 10 Aug 2005 05:30:37 -0700 Subject: Does any one recognize this binary data storage format In-Reply-To: <42f98217.1055829672@news.oz.net> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> <42f98217.1055829672@news.oz.net> Message-ID: <1123677037.339759.216980@g47g2000cwa.googlegroups.com> Thanks so much for this. It is exactly what I was looking for. If I am simply reading the bytes from disk, would I still need to convert the these values HEX characters first with Hexlify, or is there a more direct route ? ie. convert them to the double float directly from the byte values ? From sp1d3rx at gmail.com Wed Aug 3 15:08:05 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 3 Aug 2005 12:08:05 -0700 Subject: Windows command line problem In-Reply-To: References: <1121699051.059188.55640@g43g2000cwa.googlegroups.com> <1121726398.861595.31350@g43g2000cwa.googlegroups.com> <1121759914.689112.272530@z14g2000cwz.googlegroups.com> <1121762108.120184.201340@g47g2000cwa.googlegroups.com> <1121812275.374283.224000@g47g2000cwa.googlegroups.com> Message-ID: <1123096085.320143.268140@g14g2000cwa.googlegroups.com> considering that all the command lines are in sys.argv, it's very simple. From mwh at python.net Fri Aug 12 10:51:03 2005 From: mwh at python.net (Michael Hudson) Date: Fri, 12 Aug 2005 14:51:03 GMT Subject: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> Message-ID: Bryan Olson writes: > The Python slice type has one method 'indices', and reportedly: > > This method takes a single integer argument /length/ and > computes information about the extended slice that the slice > object would describe if applied to a sequence of length > items. It returns a tuple of three integers; respectively > these are the /start/ and /stop/ indices and the /step/ or > stride length of the slice. Missing or out-of-bounds indices > are handled in a manner consistent with regular slices. > > http://docs.python.org/ref/types.html > > > It behaves incorrectly In some sense; it certainly does what I intended it to do. > when step is negative and the slice includes the 0 index. > > > class BuggerAll: > > def __init__(self, somelist): > self.sequence = somelist[:] > > def __getitem__(self, key): > if isinstance(key, slice): > start, stop, step = key.indices(len(self.sequence)) > # print 'Slice says start, stop, step are:', start, > stop, step > return self.sequence[start : stop : step] But if that's what you want to do with the slice object, just write start, stop, step = key.start, key.stop, key.step return self.sequence[start : stop : step] or even return self.sequence[key] What the values returned from indices are for is to pass to the range() function, more or less. They're not intended to be interpreted in the way things passed to __getitem__ are. (Well, _actually_ the main motivation for writing .indices() was to use it in unittests...) > print range(10) [None : None : -2] > print BuggerAll(range(10))[None : None : -2] > > > The above prints: > > [9, 7, 5, 3, 1] > [] > > Un-commenting the print statement in __getitem__ shows: > > Slice says start, stop, step are: 9 -1 -2 > > The slice object seems to think that -1 is a valid exclusive > bound, It is, when you're doing arithmetic, which is what the client code to PySlice_GetIndicesEx() which in turn is what indices() is a thin wrapper of, does > but when using it to actually slice, Python interprets negative > numbers as an offset from the high end of the sequence. > > Good start-stop-step values are (9, None, -2), or (9, -11, -2), > or (-1, -11, -2). The later two have the advantage of being > consistend with the documented behavior of returning three > integers. I'm not going to change the behaviour. The docs probably aren't especially clear, though. Cheers, mwh -- (ps: don't feed the lawyers: they just lose their fear of humans) -- Peter Wood, comp.lang.lisp From MrJean1 at gmail.com Tue Aug 30 05:10:53 2005 From: MrJean1 at gmail.com (MrJean1) Date: 30 Aug 2005 02:10:53 -0700 Subject: File parser In-Reply-To: References: Message-ID: <1125393053.075866.243800@g14g2000cwa.googlegroups.com> Take a closer look at SimpleParse/mxTextTools We have used these to parse log files of several 100 MB with simple and complex grammars up to 250+ productions. Highly recommended. /Jean Brouwers PS) For an introduction see also this story From jcarlson at uci.edu Mon Aug 8 19:46:52 2005 From: jcarlson at uci.edu (Josiah Carlson) Date: Mon, 08 Aug 2005 16:46:52 -0700 Subject: [Python-Dev] PEP-343 - Context Managment variant In-Reply-To: <313379598.20050804110933@intercable.ru> References: <313379598.20050804110933@intercable.ru> Message-ID: <20050808162353.77FC.JCARLSON@uci.edu> falcon wrote: > It's idea was token from Ruby. But I think, good idea is good whatever it came from. > It can be not Pythonic. Just because something may be a good idea, doesn't mean that the idea is Pythonic. The only person who can truely say is Guido, but you can gain some insight by reading the zens (from the console, 'import this'). The fact is, context management has a syntax that has been accepted. Your first example: > def Synhronised(lock,func): > lock.acquire() > try: > func() > finally: > lock.release() > .... > lock=Lock() > def Some(): > local_var1=x > local_var2=y > local_var3=Z > def Work(): > global local_var3 > local_var3=Here_I_work(local_var1,local_var2,local_var3) > Synhronised(lock,Work) > return asd(local_var3) ... becomes ... def Synchronized(lock): lock.acquire() try: yield None finally: lock.release() def Some(): ... with Synchronized(lock): local_var3 = Here_I_work(local_var1,local_var2,local_var3) ... Which is quite close to what you offer: > Synhronised(lock,block) > local_var3=Here_I_work(local_var1,local_var2,local_var3) It is of my opinion that your proposal is destined to fail for at least two reasons; 1) context management already has an accepted syntax 2) ruby blocks were found (due to lack of evidence to the contrary) to gain Python users very little (if anything) over the accepted context management syntax. To note; unless your post is of the utmost importance, cross-posting to python-list and python-dev seems quite rude to me. Further, a variant of Ruby block syntax was offered way back in February and March (read the python-dev archives available at http://mail.python.org/pipermail/python-dev/ ). Reading what was already discussed may offer you insight into what (if any) open issues were remaining, and precisely why the context management syntax was supported over anonymous blocks/thunks/Ruby blocks. - Josiah From fakeaddress at nowhere.org Wed Aug 31 17:03:19 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 21:03:19 GMT Subject: Sockets: code works locally but fails over LAN In-Reply-To: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> Message-ID: n00m wrote: > import socket, thread > host, port = '192.168.0.3', 1434 Consider using INADDR_ANY instead of the specific host IP address. The empty string will resolve to INADDR_ANY if passed as the host to bind(). (Though that's not the problem.) > s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s2.connect((host, 1433)) > s1.bind((host, port)) > s1.listen(1) > cn, addr = s1.accept() You probably want the the accept() in a loop. > def VB_SCRIPT(): > while 1: > data = cn.recv(4096) > if not data: return > s2.send(data) Use sendall(), not send(). > print 'VB_SCRIPT:' + data + '\n\n' > > def SQL_SERVER(): > while 1: > data = s2.recv(4096) > if not data: return > cn.send(data) As above, use sendall(). > print 'SQL_SERVER:' + data + '\n\n' > > thread.start_new_thread(VB_SCRIPT,()) > thread.start_new_thread(SQL_SERVER,()) > > ============================================= > > The above code acts as an intermediator between a very simple VB script > and SQL Server. Like follows: > the vbs sends its requests to "fake" port 1434 and the python code > catches and re-sends them to sql server which listens to its DEFAULT > port = 1433... And vice versa. [...] > It works fine (I see all client/server data printed in IDLE window)but > only locally. I.e. if vbs, python and sql server run on the same > machine. [...] My first two guess are: The client is trying to make more than one connection. Putting accept in a loop and moving some stuff will support that. The send() call is not sending all the data. Using sendall() should fix that. Try the following, but *not in Idle*. The code doesn't yet have a clean stopping method, and the run-on threads will screw-up Idle. import socket, thread sqls_host, sqls_port = '192.168.0.3', 1443 proxy_host, proxy_port = '', 1434 # How I tested it: # sqls_host, sqls_port = 'www.google.com', 80 def VB_SCRIPT(): while 1: data = cn.recv(4096) if not data: return s2.sendall(data) print 'VB_SCRIPT:' + data + '\n\n' def SQL_SERVER(): while 1: data = s2.recv(4096) if not data: return cn.sendall(data) print 'SQL_SERVER:' + data + '\n\n' s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s1.bind((proxy_host, proxy_port)) s1.listen(5) while 1: cn, addr = s1.accept() s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((sqls_host, sqls_port)) thread.start_new_thread(VB_SCRIPT,()) thread.start_new_thread(SQL_SERVER,()) -- --Bryan From ptmcg at austin.rr.com Fri Aug 12 11:21:40 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 12 Aug 2005 08:21:40 -0700 Subject: Where can be a problem? In-Reply-To: <1123827773.392501.155760@z14g2000cwz.googlegroups.com> References: <1123827773.392501.155760@z14g2000cwz.googlegroups.com> Message-ID: <1123860100.893747.302700@g44g2000cwa.googlegroups.com> Try this, its a bit more readable than your re. from pyparsing import Word,nums,Literal,replaceWith data1='''''' # a number is a word composed of nums, that is, the digits 0-9 # your search string is looking for a number between an '=' and '&' EQUALS = Literal("=") AMPER = Literal("&") number = Word(nums) hrefNumber = EQUALS + number + AMPER # scanString is a generator, that returns matching tokens, start, # and end location for each occurrence in the input string - we # just care about the second token of each match print [ tokens[1] for tokens,s,e in hrefNumber.scanString(data1) ] # just for grins, here is how to convert the numbers to the # string "###" number.setParseAction( replaceWith("###") ) print number.transformString(data1) Prints: ['15015', '15016', '15017'] Download pyparsing at http://pyparsing.sourceforge.net. -- Paul From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 25 10:12:20 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 25 Aug 2005 16:12:20 +0200 Subject: overload builtin operator In-Reply-To: References: Message-ID: <3n61u4F1fg2U1@individual.net> Shaun wrote: > Hi, > > I'm trying to overload the divide operator in python for basic arithmetic. > eg. 10/2 ... no classes involved. > > I am attempting to redefine operator.__div__ as follows: > > # my divide function > def safediv(a,b): > return ... > > # reassign buildin __div__ > import operator > operator.__div__ = safediv > > The operator.__dict__ seems to be updated OK but the '/' operator still > calls buildin __div__ It won't work that way. You cannot globally modify the behaviour of an operator, but you can customize how an operator works for your type. Consider: class safeint(int): def __div__(self, other): return safediv(self, other) safeint(10)/2 Reinhold From martin at v.loewis.de Tue Aug 9 15:26:53 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 09 Aug 2005 21:26:53 +0200 Subject: PEP: Specialization Syntax In-Reply-To: References: <42F66FF2.7010901@v.loewis.de> Message-ID: <42f9037e$0$18078$9b622d9e@news.freenet.de> Nicolas Fleury wrote: > Well, I'm using the alternatives. Perhaps not to the full power. > __arrayTypes = {} > def makeArrayType(arg1, arg2=someDefault): > if (arg1, arg2) in __arrayTypes: > return __arrayTypes[arg1, arg2] > renamed_arg1 = arg1 > renamed_arg2 = arg2 > class Array: > arg1 = renamed_arg1 > arg2 = renamed_arg2 > ... > __arrayTypes[arg1, arg2] = Array > return Array > > Does it qualify as an "acceptable alternative"? when it could have been: > > class Array[arg1, arg2=someDefault]: So you don't want to write the makeArrayType function, right? How about this: # declaration class Array(object): __typeargs__ = ['arg1', ('arg2', someDefault)] ... # use t = specialize(Array, arg1=Int32) where specialize is defined as def specialize(ptype, *args): result = type(ptype.__name__, (ptype,), args) for t in result.__typeargs__: if isinstance(t, string): if not hasattr(result, t): raise TypeError("missing parameter "+t) else: name,val = t if not hasattr(result, name): setattr(result, val) return result Regards, Martin From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 5 16:56:52 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 05 Aug 2005 22:56:52 +0200 Subject: Do I need to have site.py available or not ? In-Reply-To: References: <1123257409.099201.114960@g49g2000cwa.googlegroups.com> Message-ID: <3li24kF11appjU1@individual.net> Terry Reedy wrote: > wrote in message > news:1123257409.099201.114960 at g49g2000cwa.googlegroups.com... >> Hi, >> on startup my embedded python comes up with "import site failed use >> -v". Later python crashes on Pyrun_file(). This is the first time I >> have used python and I would like to know does it require site.py to be >> read in, and has anyone got an idea how to pass in the -v without using >> the python -v command, ie the embedded way. Thanks very much. > > If by embedded you mean embedded in a C/C++ program, I would look to the > doc for the C API function that you use to start it up to see whether there > is a way to pass in argv flags or to have the same effect. Also note that '-v' doesn't do what you want here, it merely activates verbose mode so that you can find the cause for above error. You want '-S'. Reinhold From paschott at no.yahoo.spamm.com Wed Aug 24 16:41:56 2005 From: paschott at no.yahoo.spamm.com (Peter A. Schott) Date: Wed, 24 Aug 2005 20:41:56 GMT Subject: Sorta noob question - file vs. open? References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> <430b9cc0$1@nntp0.pdx.net> Message-ID: <6tmpg19aa138j4cv2s0k5j7ir1goercvb0@4ax.com> I'll have to try this again. I obviously did something wrong in my code. I was getting errors about not being able to write a string because it wasn't supported. It was driving me nuts for a while until I just gave up and went back to open(). I'll do some more playing and if I continue to get errors, I'll post the code I'm using at the time along with any errors I got. I apologize for not including the details. A thread I was reading reminded me about that odd behaviour from a couple of weeks ago and I wanted to see if I was way off base as I could consistently reproduce it then on Python 2.4.1. Thanks to all who replied. If open is still preferred, I will stick with that. :-) -Pete Scott David Daniels wrote: > Peter A. Schott wrote: > > Been reading the docs saying that file should replace open in our code, but this > > doesn't seem to work: > This was really a misstatement; open is still preferred. file is now > a built in class, and its constructor is the same as open. I think the > current docs have been fixed. > > > # Open file for writing, write something, close file > > MyFile = file("MyFile.txt", "w") > > MyFile.write("This is a test.") > > MyFile.close() > But you've given us no idea what went wrong. > > > However, using: > > MyFile = open("MyFile.txt", "w") > > MyFile.write("This is a test.") > > MyFile.close() > I cannot help you if you don't tell me what went wrong. > > Both bits of code seem to do the same thing for me. > > > --Scott David Daniels > Scott.Daniels at Acm.Org From martin at v.loewis.de Sat Aug 13 07:26:22 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 13 Aug 2005 13:26:22 +0200 Subject: How to find Python path in Visual C++ install wizard In-Reply-To: References: Message-ID: <42FDD8DE.9070104@v.loewis.de> Philippe C. Martin wrote: > I am trying to setup an .msi for my software (Python code (.pyc) + drivers) > to make installation easier for Windows users. > > I am using the installer that comes with V. C++ 7.1. > > I would like to find the way to make sure Python is installed and then copy > automatically my files into its hierarchy. You should look at (HKEY_LOCAL_MACHINE,HKEY_CURRENT_USER)/Software/Python. Regards, Martin From rtconner at gmail.com Wed Aug 10 16:57:03 2005 From: rtconner at gmail.com (Rob Conner) Date: 10 Aug 2005 13:57:03 -0700 Subject: providing arguments to base.__init__ In-Reply-To: References: Message-ID: <1123707423.615710.196290@g43g2000cwa.googlegroups.com> seems like you are not running the correct wavePlayer. make sure you don't have 2 wavePlayer vars. From mwh at python.net Tue Aug 30 16:29:40 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 30 Aug 2005 20:29:40 GMT Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh writes: > Hi > > I am using time.clock() to get the current time of the processor in seconds. > For my application, I need really high resolution but currently seem to be > limited to 0.01 second. Is there a way to specify the resolution (say 1-10 > microseconds) ? Not in standard Python. > My processor is a 1.4 MHz Intel processor. Mhz? :) > Surely, it should be able to report times a few (or at least 10) > microseconds apart. It's probably architecture and operating system dependent. The pentium has a timestamp counter that counts clock cycles and the PowerPC has a similar (but slower) counter. You may need to write a little C or asm. Cheers, mwh -- All of us in here are guilty as hell. Justified, yes, but guilty. "and that, your honour, was when I killed him" "Well, I see. That's all right then" -- Devin Rubia, asr From kristian.zoerhoff at gmail.com Thu Aug 11 20:46:45 2005 From: kristian.zoerhoff at gmail.com (Kristian Zoerhoff) Date: Thu, 11 Aug 2005 19:46:45 -0500 Subject: Printing to printer In-Reply-To: References: Message-ID: <3511dc7505081117461ac7bf6d@mail.gmail.com> On 8/11/05, Steve M wrote: > Hello, > > I'm having problems sending information from a python > script to a printer. I was wondering if someone might send me > in the right direction. I wasn't able to find much by Google Which platform? Directions will vary wildly. -- Kristian kristian.zoerhoff(AT)gmail.com zoerhoff(AT)freeshell.org From osv at javad.ru Tue Aug 23 14:52:35 2005 From: osv at javad.ru (Sergei Organov) Date: 23 Aug 2005 22:52:35 +0400 Subject: py-serial + CSV References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> <1124820032.854336.278790@f14g2000cwb.googlegroups.com> Message-ID: Steve Holden writes: > McBooCzech wrote: [...] > > $GPRMC,174525.617,A,5026.1080,N,01521.6724,E,0.0,005.8,230805,,*0A > > etc.... > > > [...] > > s = serial.Serial(port=0,baudrate=4800, timeout=20) > > while 1: > > line = s.readline() > > words = line.split(',') > > if words[0]=="$GPRMC": > > print words[1], words[3], words[5] > > I just wonder if there is some beter (or as you are saying "more > > > pythonic":) aproach how to write such a piece of code. > > That code is quite tidy. You could save yourself the split on lines > that weren't of interest, though frankly this isn't essential - this > task won't use 1% of CPU on almost any computer built in the last five > years. But, if you are interested in seeing other solutions you might > consider it, and it does avoid the split when it's not necessary. > > > while 1: > line = s.readline() > if line.startswith("$GPRMC"): "$GPRMC," would be better, -- not to match something like "$GPRMC174...". -- Sergei. From calfdog at yahoo.com Mon Aug 1 16:29:22 2005 From: calfdog at yahoo.com (calfdog at yahoo.com) Date: 1 Aug 2005 13:29:22 -0700 Subject: Using win32com for web automation In-Reply-To: <1122409338.810583.97610@z14g2000cwz.googlegroups.com> References: <1122399814.174328.63980@g43g2000cwa.googlegroups.com> <1122409338.810583.97610@z14g2000cwz.googlegroups.com> Message-ID: <1122928162.157140.183090@f14g2000cwb.googlegroups.com> ina wrote: > Look up pamie it should do all the work you need. If it dosn't I can > send you ishyBrowser but pamie has more comunity support. FYI #Imports from win32com.client import Dispatch from time import sleep # Create a new browser object ie = Dispatch('InternetExplorer.App?lication') # Make the browser visible ie.Visible = 1 # Navigate to the site ie.Navigate("http://ispds-sepsr.prv:7500/cs/welcome.jsp") # wait for the document to fully load while ie.ReadyState != 4: sleep(1) doc = ie.Document while doc.readyState != "complete": sleep(1) # set the textbox value for name to 'some_string' doc.loginForm.name.value = 'username' # set the textbox value for password to 'some_string' doc.loginForm.password.value = 'password' # submit the form doc.loginForm.submit() Added some comments to make it clearer You will now need another wait for the next document you load You can put the wait into a wait method or you could try PAMIE http://pamie.sourceforge.net Hope it helps Rob From lycka at carmen.se Fri Aug 19 11:10:33 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 19 Aug 2005 17:10:33 +0200 Subject: Some questions In-Reply-To: References: <21cet2-2hr.ln1@lairds.us> Message-ID: Thomas Ganss wrote: > My blind guess would have been that Tkinter was *not* the GUI of choice > for *J*ython. With Jython you'd probably use Swing or SWT. It's certainly less coding to get something working in Jython/Swing than with Java/Swing, but I suspect that there is a cost in runtime performance which might be a problem in some cases. From msoulier at digitaltorque.ca Mon Aug 15 12:17:00 2005 From: msoulier at digitaltorque.ca (Michael P. Soulier) Date: Mon, 15 Aug 2005 12:17:00 -0400 Subject: socket setdefaulttimeout In-Reply-To: References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> <8122246.VFEYWSAU@news.verizon.net> Message-ID: <20050815161659.GE6027@rabbit.digitaltorque.ca> On 13/08/05 Bryan Olson said: > The seperate thread-or-process trick should work. Start a deamon > thread to do the gethostbyname, and have the main thread give up > on the check if the deamon thread doesn't report (via a lock or > another socket) within, say, 8 seconds. Wouldn't an alarm be much simpler than a whole thread just for this? Mike -- Michael P. Soulier "Those who would give up esential liberty for temporary safety deserve neither liberty nor safety." --Benjamin Franklin -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From c.gillespie at ncl.ac.uk Thu Aug 25 09:15:37 2005 From: c.gillespie at ncl.ac.uk (Colin Gillespie) Date: Thu, 25 Aug 2005 14:15:37 +0100 Subject: Python 2.1 Bible Source In-Reply-To: <2SpNe.57$Hi.50@trnddc04> References: <2SpNe.57$Hi.50@trnddc04> Message-ID: <430DC479.2040802@ncl.ac.uk> SuppressedPen wrote: > Hi Everyone! > > Just started with Python 2 weeks ago and I can't put it down it's to easy > and to powerful, I'm sure the goons will be after us for having it soon, Hi > Hi. > > Was wondering if anyone might know where I can find the source code for > PYTHON 2.1 BIBLE book. Apparently it was online until the publisher sold > the company. I also understand it has been sold a second time since the > book was published. Maybe someone has a copy? Thanks. DOUG. you can access the web-site through the web.archive.org, e.g. http://web.archive.org/web/*/http://www.pythonapocrypha.com/ The site runs fairly slowly, but all the pages seem to be there. I even downloaded the source code to the book from http://web.archive.org/web/20040610022324/http://www.pythonapocrypha.com/PySource.tgz HTH Colin From ptmcg at austin.rr.com Tue Aug 23 17:39:39 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 23 Aug 2005 14:39:39 -0700 Subject: Nested Regex Conditionals References: Message-ID: <1124833179.533528.262290@g44g2000cwa.googlegroups.com> This works (note relocated right paren at (?(second) ): #!/usr/bin/env python import re original_pattern = re.compile(r""" (?P(first)) (?(first) (?P(second)) ) (?(second) (?P(third)) ) """, re.VERBOSE) pattern = re.compile(r""" (?P(first)) (?(first) (?P(second)) ) (?(second)) (?P(third)) """, re.VERBOSE) string = 'firstsecondthird' match = re.match(pattern,string) print match.group('first','second','third') Prints out: ('first', 'second', 'third') The pyparsing alternative looks like: first = Literal("first").setResultsName("first") second = Literal("second").setResultsName("second") third = Literal("third").setResultsName("third") # define line line = first + second + third print line.parseString("firstsecondthird") Prints out: ['first', 'second', 'third'] -- Paul From tjreedy at udel.edu Mon Aug 8 00:02:52 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 8 Aug 2005 00:02:52 -0400 Subject: Splitting a string into groups of three characters References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: wrote in message news:1123466304.304964.211380 at g49g2000cwa.googlegroups.com... > Is there a function that split a string into groups, containing an "x" > amount of characters? There have been previous threads giving various solutions (which generally are not specific to strings). You might find some some by searching the Google archive of this group. Some of the variations depend on what to do if len(s) % x != 0. Do you pad to x, drop the extras, or return a deficient group? Terry J. Reedy From cam.ac.uk at mh391.invalid Tue Aug 16 12:08:32 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Tue, 16 Aug 2005 17:08:32 +0100 Subject: [Python-Dev] implementation of copy standard lib In-Reply-To: References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: Simon Brunning wrote: > I think that copy is very rarely used. I don't think I've ever imported it. > > Or is it just me? It's just you. I use copy.deepcopy() fairly often. -- Michael Hoffman From kylotan at gmail.com Thu Aug 25 05:21:33 2005 From: kylotan at gmail.com (Ben Sizer) Date: 25 Aug 2005 02:21:33 -0700 Subject: Doubt C and Python References: <11gp046ko61rsa5@corp.supernews.com> Message-ID: <1124961693.820616.13530@f14g2000cwb.googlegroups.com> Grant Edwards wrote: > On 2005-08-23, praba kar wrote: > > What why it is more efficient. Kindly let me > > know with some details. > > Have you read _any_ of the thread? A number of people have > already explained in detail why programming in Pything is more > efficient. Please read the responses you've already gotten. Grant, Going by the Google Groups timestamps that I see, there's a good chance that none of the other responses were visible to the OP when the above followup was posted. -- Ben Sizer From lycka at carmen.se Mon Aug 15 14:04:55 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 15 Aug 2005 20:04:55 +0200 Subject: SOAP and XMLRPC In-Reply-To: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Message-ID: dcrespo wrote: > Hi to all... > Someone knows if is there possible to have a Python SOAP or XMLRPC > server that works with VB? I would like you to include the examples > clients and server programs. If you can write an XML-RPC client in VB, it will work with XML-RPC servers written in any language. This is the wrong forum to learn how to do that though. May I suggest that you google for "visual basic xml-rpc client" From jrastrick at student.usyd.edu.au Thu Aug 18 00:00:14 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 17 Aug 2005 21:00:14 -0700 Subject: question about binary and serial info In-Reply-To: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> Message-ID: <1124337614.259032.4970@g14g2000cwa.googlegroups.com> Sounds like you want the bitwise and operator, & >>> 2 & 3 2 >>> 32 & 16 0 >>> 31 & 12 12 etc. neph... at xit.net inquired: > i have an interesting project at work going on. here is the challenge. > i am using the serial module to read data from a serial input. > it comes in as a hex. i need to make it a binary and compare it bit by > bit to another byte. They have some weird way they set this up that i > have to compare these things with AND. in other words, if bit 1 is 1 > AND bit 1 is 1 then the real value is 1... > > long story short. is there a good way to compare bytes, bit by bit with > one of the modules of python. i want to know so i dont get halfway into > developing this and find that there is a much better way to do this > than by hand. > > thanks for any suggestions. > sk <>< From mynews44 at yahoo.com Sun Aug 14 16:22:02 2005 From: mynews44 at yahoo.com (googleboy) Date: 14 Aug 2005 13:22:02 -0700 Subject: cgi form validation problems Message-ID: <1124050921.941278.296970@f14g2000cwb.googlegroups.com> Hi. I am writing up my own web form. I'm a bit of a newb, and read up many different how-tos and examples and documentaion. I finally had it working just great until I decided that I wanted to add some extra logic because there's one form that submits a particular type of information. a little extra validation, and the creation of a list of the values to be mailed in to the site manager. The code below is where I am going wrong (edited for brevity): form=cgi.FieldStorage() rev_fields = { "param1":None, "param3":None, "param6":None, "param5":None, "param8":None, "param9":None, "param10":None, "param11":None } # Everything worked until I added the following if statement: if form.has_key("param8"): # Only one form has this param8 = form.getvalue("param8") if param8 == 0: # 0 is the default value print "Content-type: text/html" debug("You must give the item a rating") for field in form.keys(): value = form[field].value if rev_fields.has_key(field): rev_fields[field] = value for key in rev_fields: if rev_fields[key] == None: print "Content-type: text/html" debug("All fields must be filled in. Please check your %s submission." % key) else: #feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" % (form["param1"].value, form["param3"].value, form["param6"]. value, form["param5"].value, form["param8"].value, form["param9"].value, form["param10"].value, form["param11"].value) #feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" % (form.getvalue("param1"), form.getvalue("param3"), form.getvalue( "param6"), form.getvalue("param5"), form.getvalue("param8"), form.getvalue("param9"), form.getvalue("param10"), form.getvalue("param11")) feedback = ("%s, %s, %s, %s, %s, %s" % (rev_fields["param1"], rev_fields["param3"], rev_fields["param6"], rev_fields["param5"], rev_fields["param8"], rev_fields["param9"], rev_fields["param10"], rev_fields["param11"]) #feedback = form[ "score" ].value msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback: %s\r\n\r\n" % (rev_fields["param2"], rev_fields["param7"], rev_fields["param3"], rev_fields["param6"])) If I comment out the 'else:' logic, it works great. But then I don't get a list called feedback containing all teh bits I want, The error I get is really strange, too: [Mon Aug 15 05:54:58 2005] [error] [client 60.224.106.116] Premature end of script headers: /var/www/users/senta/html/gobooks/cgi/form.py File "/var/www/users/senta/html/gobooks/cgi/form.py", line 99 msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback: %s\r\n\r\n" % ^ SyntaxError: invalid syntax Just a simple assignation.... I did think it might have been an indentation error, but I changed that around and got a message telling me about an indentation problem, which this doesn't do. I have tried several different ways to assign the values, as you can see by the commented out lines. Tried getting the values directly from teh form, and also from the validated rev_fields dictionary. I'd be extremely grateful to anyone who helps me through this. TIA Googleboy From cbfalconer at yahoo.com Thu Aug 25 04:15:25 2005 From: cbfalconer at yahoo.com (CBFalconer) Date: Thu, 25 Aug 2005 08:15:25 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> Message-ID: <430D7366.C2126F6D@yahoo.com> Mike Schilling wrote: > "Mike Meyer" wrote in message >> "Mike Schilling" writes: >>> "l v" wrote in message >>>> Xah Lee wrote: >>>> >>>>> (circa 1996), and email should be text only (anti-MIME, circa 1995), >>>> >>>> I think e-mail should be text only. I have both my email and >>>> news readers set to display in plain text only. It prevents >>>> the marketeers and spammers from obtaining feedback that my >>>> email address is valid. A surprising amount of information >>>> can be obtained from your computer by allowing HTML and all >>>> of it's baggage when executing on your computer. Phishing >>>> comes to my mind first and it works because people click the >>>> link without looking to see where the link really takes them. >>> >>> A formatting-only subset of HTML would be useful for both e-mail >>> and Usenet posts. >> >> Used to be people who wanted to send formatted text via email >> would use rich text. It never really caught on. But given that >> most of the people sending around formatted text are using >> point-n-click GUIs to create the stuff, the main advantage of >> HTML - that it's easy to write by hand - isn't needed. > > But the other advantage, that it's an existing and popular > standard, remains. However, for both e-mail and news, it is totally useless. It also interferes with the use of AsciiArt, while opening the recipient to the dangers above. -- "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 zen19725 at zen.co.uk Wed Aug 3 08:49:25 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 13:49:25 +0100 Subject: Art of Unit Testing References: <87mzo0s25q.fsf@lucien.dreaming> <42efe1ec$0$3713$626a14ce@news.free.fr> <42efe330$0$3713$626a14ce@news.free.fr> Message-ID: On Wed, 03 Aug 2005 10:19:05 +0200, Christoph Zwerschke wrote: >rafi wrote: >> 'should' may be too strong, 'may' may be better. In the meantime I found: >> http://python-mock.sourceforge.net/ > >Thanks for the link. Bj?rn also pointed to http://pmock.sourceforge.net > >Using mock objects sounds like a good idea. > >A problem with mock objects may be that they make writing tests for the >occasional programmer yet another bit more difficult, and that you >always have to ensure your mock objects really mock the real objects >perfectly, so you have to write another test for that. The behavior and >the API of the real objects may change every now and then. > >Let me summarize some good answers in this thread: > >- unittest is deliberately intended to be a JUnit implementation >- unittest is for *unit* testing (only) ;-) I use regression testing (using my "lintest" module, which is functionally similar to unittest) on the whole application. I really see no reason why the concept should be limited to testing individual modules (or roughly similar-sized pieces). -- Email: zen19725 at zen dot co dot uk From peter at engcorp.com Wed Aug 3 09:37:42 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 03 Aug 2005 09:37:42 -0400 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> <42efe1ec$0$3713$626a14ce@news.free.fr> <42efe330$0$3713$626a14ce@news.free.fr> Message-ID: Christoph Zwerschke wrote: > - unittest is for *unit* testing (only) ;-) Why would you say that? We've used it extensively for a wide ranging of testing, not limited to unit tests. > - use mock objects to mimic the behaviour of external components like > databases ...when doing unit testing. If you mock while doing higher level testing, you'll eventually regret it in most cases. > Also, if one of the more pythonic unit testing modules will be mature > enough and widely accepted, I think it would be good to make it Python's > standard (lib) testing framework and rename the current unittest back to > pyunit or punit. What, and break all the code that currently does "import unittest"? -Peter From luismgz at gmail.com Tue Aug 2 14:41:38 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 2 Aug 2005 11:41:38 -0700 Subject: IronPython 0.9 Released Message-ID: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> IronPython 0.9 Released(8/2/2005 10:28:41 AM) http://www.microsoft.com/downloads/details.aspx?familyid=cf5ae627-5df1-4f8a-ba8b-d64f0676f43f&displaylang=en From mxywp at 126.com Tue Aug 2 19:21:37 2005 From: mxywp at 126.com (Xiangyi) Date: Tue, 2 Aug 2005 16:21:37 -0700 Subject: bug in python/numarray References: <5.1.1.5.2.20050802103138.04c79d50@are.berkeley.edu> Message-ID: <001201c597b8$f0e73cb0$c00a030a@PANDA> Robert and Terry- Thank you so much for helping me on this! Yes, it's a problem due to an old version of numarray. I didn't realize that my windows has a much newer version than the debian machine. Best, Xiangyi ----- Original Message ----- From: "Robert Kern" To: Sent: Tuesday, August 02, 2005 1:03 PM Subject: Re: bug in python/numarray > meng at are.berkeley.edu wrote: >> Hi, there, >> >> I got different results by running the same lines of code on windows and >> debian. Here is the code: >> >> a = kroneckerproduct(ones((4195,1)), identity(12)) >> print a.mean() >> >> This works perfectly well in windows but it gave the following error >> while >> running it in debian: >> Traceback (most recent call last): >> File "", line 1, in ? >> File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line >> 1137, in mean >> return self.sum()/(self.nelements()*1.0) >> File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line >> 1133, in sum >> return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat, >> type=type) >> IndexError: too many indices. >> >> But if I reduce the number 4195 to 419, it works. Is it a bug in Python >> or >> Numarray? Can someone help me figure it out? BTW, the python version is >> 2.4.1 > > It's almost certainly numarray. I don't get an error on OS X with the > latest CVS of numarray. Please try the latest CVS on your platforms, and > if you still get this error, then post it to the numarray mailing list. > Thanks! > > http://lists.sourceforge.net/lists/listinfo/numpy-discussion > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list > From godoy at ieee.org Mon Aug 1 18:24:26 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 01 Aug 2005 19:24:26 -0300 Subject: Dabo in 30 seconds? References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <8ur1s2-r5t.ln1@strongwill.g2ctech> <3l7dl2F111tulU1@uni-berlin.de> Message-ID: Daniel Dittmar wrote: > Jorge Godoy wrote: >> We can find several problems, almost all of them can be solved with the >> admin's creativity. > > You must distinguish between solving technical problems once a course > has ben set and choosing such a course in the first place. > > The latter has to deal also with the risks of the unknown. Of course > what is unknown can be influenced somewhat by getting information. I agree where you say that lack of information is a risk. But I don't see how it -- lack of information -- wouldn't affect both scenarios. At least, when I'm developing a solution, I have to present a deployment plan and cover the specified cases. If something was not specified or is an exception, then a new action plan is developed and the client is consulted again (after all, if it's his fault there will be extra costs for him; if it's my mistake, then I'll assume the costs). This repeats until all the needs are documented and the code works on them, or exceptions where the code won't work are also documented. Always there's the "OK" from the client. -- Jorge Godoy From gelios at rbcmail.ru Tue Aug 9 17:40:35 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Wed, 10 Aug 2005 01:40:35 +0400 Subject: MainThread blocks all others Message-ID: Hello All! I met some strange situation. In MainThread my program wating changes of some variable. This variable should be changed in another thread, but loop, which wait changing variable blocks all other threads. Code below: class class1: def __init__(self): self.counter = 0 result = doSomeJob() def increaseCounter(self): self.counter += 1 doSomeJob(self): ##### BLOCKING HERE ### while counter != 1: pass # ... continue... # this class subscribed to some observer which implements thread class monitor: def __init__(self, klass): #do some init self.c = klass def update(self): self.c.increaseCounter() if __name__ == "__main__": cl1 = class1() m = monitor(cl1) mo = MonitorObserver(m) I am very confused how to resolve this problem. Any help will be appreciated. Thanks in advance to All. Best regards, /Gelios From cito at online.de Wed Aug 3 03:52:43 2005 From: cito at online.de (Christoph Zwerschke) Date: Wed, 03 Aug 2005 09:52:43 +0200 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: Peter Hansen wrote: > What's wrong with using Python's existing "global" support, and just > having your test case setUp() call a global setup routine which checks > whether that global setup work has already been done and, if not, does > it once and sets a flag to say that it has now been done? I've done > this easily in the few cases where I've wanted this behaviour. It > doesn't seem complex enough to warrant adding to the standard unit test > support. Actually I already thought about doing it that way, but then I thought it is so ugly, there must be a simpler solution ;-) > If you're going to quote XP rules of thumb, the tests should be > independent and very fast, and if you have a setup code that is taking a > long time, it's likely a "code smell" of some kind, and you should be > fixing the design which prevents you writing these tests with minimal > and quick setup. Are these really like "acceptance" tests? If they > were unit tests, they should take only a few minutes to run, total, and > you should be running them all *many* times a day, not twice. You're right. I think wanting to have a more global initialization indicates that you are acutally not wanting to do a "unit" test, but a more global test of the overall system, something like an acceptance or integration test, i.e. you are trying to abuse unittest for something it was not intended to be used for. Maybe since unittest is the only testing framework included with the standard lib, people tend to use it for all testing purposes. If you only have a hammer, everything looks like a nail. -- Christoph From paddy3118 at netscape.net Fri Aug 12 01:30:27 2005 From: paddy3118 at netscape.net (Paddy) Date: 11 Aug 2005 22:30:27 -0700 Subject: list to tuple In-Reply-To: <1123819543.351623.324870@f14g2000cwb.googlegroups.com> References: <1123819543.351623.324870@f14g2000cwb.googlegroups.com> Message-ID: <1123824627.098676.132130@g43g2000cwa.googlegroups.com> Try this: >>> a,b,c = list('tab'),list('era'),list('net') >>> a,b,c (['t', 'a', 'b'], ['e', 'r', 'a'], ['n', 'e', 't']) >>> tuple(((x,y,z) for x,y,z in zip(a,b,c))) (('t', 'e', 'n'), ('a', 'r', 'e'), ('b', 'a', 't')) >>> - Paddy. From elcinturapartida at yahoo.es Thu Aug 18 08:06:38 2005 From: elcinturapartida at yahoo.es (elcinturapartida at yahoo.es) Date: 18 Aug 2005 05:06:38 -0700 Subject: Event objects Threading on Serial Port on Win32 Message-ID: <1124366798.903601.282650@g47g2000cwa.googlegroups.com> Hello all, I am not sure if this question is about threading or serial i/o - it has elements of both. I'm on WinXP (desktop) and WinNT (labtop), when I run miniterm.py there is no problem both writing, reading, opening the com port, no errors, etc. But if I run wxTerminal.py when read from it nothing happens. It ran without error and it seemed to write ok, If I run the code to do the write, then I connect to the device through hyperterminal or wxterm, I get the response, so it seems the write is working ok, just very strange. wxTerminal.py uses Event object to set the event of Threading module. However wxTerminal.py doesn't loop while alive event is true. class TerminalFrame(wxFrame): """Simple terminal program for wxPython"" def __init__(self, *args, **kwds): self.serial = serial.Serial() self.serial.timeout = 0.5 #make sure that the alive event can be checked from time to time self.settings = TerminalSetup() #placeholder for the settings self.thread = None self.alive = threading.Event() .... def StartThread(self): """Start the receiver thread""" self.thread = threading.Thread(target=self.ComPortThread) self.thread.setDaemon(1) self.thread.start() self.alive.set() .... def __attach_events(self): ... self.Bind(EVT_SERIALRX, self.OnSerialRead) self.Bind(EVT_CLOSE, self.OnClose) .... def ComPortThread(self): """Thread that handles the incomming traffic. Does the basic input transformation (newlines) and generates an SerialRxEvent""" while self.alive.isSet(): #loop while alive event is true print "Start self.alive.isSet" <----------------- Don't show in console. text = self.serial.read(1) #read one, with timout if text: #check if not timeout miniterm.py and wxTerminal.py are at http://pyserial.sourceforge.net/ Any advice will be much appreciated. Thanks David From ray_usenet at yahoo.com Thu Aug 11 23:00:46 2005 From: ray_usenet at yahoo.com (Ray) Date: 11 Aug 2005 20:00:46 -0700 Subject: How do these Java concepts translate to Python? Message-ID: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Hello, I've been learning Python in my sparetime. I'm a Java/C++ programmer by trade. So I've been reading about Python OO, and I have a few questions that I haven't found the answers for :) 1. Where are the access specifiers? (public, protected, private) 2. How does Python know whether a class is new style or old style? E.g.: class A: pass How does it know whether the class is new style or old style? Or this decision only happens when I've added something that belongs to new style? How do I tell Python which one I want to use? 3. In Java we have static (class) method and instance members. But this difference seems to blur in Python. I mean, when you bind a member variable in Python, is it static, or instance? It seems that everything is static (in the Java sense) in Python. Am I correct? Thanks in advance, Ray From Peter.Vandersteegen at gmail.com Wed Aug 3 03:59:10 2005 From: Peter.Vandersteegen at gmail.com (peter) Date: 3 Aug 2005 00:59:10 -0700 Subject: distutils package_dir newbie Message-ID: <1123055950.708133.66580@g49g2000cwa.googlegroups.com> Hello all, I've have following problem the layout of my program is the following: setup.py project_dev/__init__.py project_dev/someModule.py now I want to make a source-installer so python setup.py install will give the following directory stucture: site-packages/project_user/__init__.py site-packages/project_user/someModule.py notice the namechange from project_dev to project_user how do I achieve a namechange from project_dev to project_user??? I've tried several different versions of command package_dir options in the setup function: package_dir = {'project_user': 'project_dev'} also package_dir = {'project_dev':'project_user'} both without any success. (relatively unintuitive option this is) Can anybody give the correct way to achieve a directory-renaming when creating an installer? kind regards Peter keywords: renaming, directory, sdist, distutils, package_dir From fertig at cstreetsearch.com Mon Aug 15 11:53:00 2005 From: fertig at cstreetsearch.com (fertig at cstreetsearch.com) Date: 15 Aug 2005 08:53:00 -0700 Subject: seeking Python developers Message-ID: <1124121180.796627.105810@g44g2000cwa.googlegroups.com> I'm conducting a search for people with a background in Python for software development involving the web and large databases in greater Boston, MA. If anyone has ideas for how to find such people within this geographic area, I'd much appreciate suggestions... or, even better, referrals. Arnie Fertig fertig at streetsearch.com From onurb at xiludom.gro Thu Aug 11 10:01:41 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 11 Aug 2005 16:01:41 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <42fb5a47$0$27714$626a14ce@news.free.fr> Magnus Lycka wrote: > N.Davis wrote: > >> Functions existing in a module? Surely if "everything is an object" >> (OK thats Java-talk but supposedly Python will eventually follow this >> too) > > > int too? ;) Yes, int too. >>> i = 42 >>> i.__class__ >>> i.__class__.__name__ 'int' >>> dir(i) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] >>> (snip) > It seems to me that Java is designed > to make is difficult for programmers to write bad code, while > Python is designed to make it easy to write good code. +1 QOTW -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From sjmachin at lexicon.net Sun Aug 21 07:21:58 2005 From: sjmachin at lexicon.net (John Machin) Date: Sun, 21 Aug 2005 21:21:58 +1000 Subject: while c = f.read(1) In-Reply-To: <3mr0lbF1840unU1@individual.net> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> <3mr0lbF1840unU1@individual.net> Message-ID: <430863d4$1@news.eftel.com> Reinhold Birkenfeld wrote: > John Machin wrote: > > >>... AND it's about time that list is updated to include False explicitly >> -- save nitpicking arguments about whether False is covered by >>"numeric zero of all types" :-) > > > Done. Thanks -- those of us who actually read manuals salute you. > >w about >> for c in f.read(): > [snip] > Don't forget > > for line in f: > for c in line: > # do stuff > OK. I'll pay that one. From mwm at mired.org Wed Aug 10 22:16:26 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 10 Aug 2005 22:16:26 -0400 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <86irydi5fp.fsf@bhuda.mired.org> Peter Hansen writes: > Dan wrote: >> You might think of modules in Python as like packages in Java. However, >> putting classes in the same module doesn't give them any additional >> powers to interact with each other. (At least, not that I know of.) > > Use of "global" to rebind shared module-scope names... You can rebind module-scope names from outside the module. It's an ugly practice, and I wouldn't recommend it, but it *is* possible. But you're on the right track. If two consenting classes want to share _named module variables, it's best that they be in the same module. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From noreply at gcgroup.net Mon Aug 15 09:00:02 2005 From: noreply at gcgroup.net (William Gill) Date: Mon, 15 Aug 2005 13:00:02 GMT Subject: help with mysql cursor.execute() In-Reply-To: References: <8XMLe.878$Z%6.698@newssvr17.news.prodigy.com> <42ff9415$1@nntp0.pdx.net> Message-ID: Steve Holden wrote: > William Gill wrote: > >> I have been testing and it seems that: >> >> 1- Cursor.execute does not like '?' as a placeholder in sql >> > The particular format required by each DBI-compatible module should be > available as the module's "paramstyle" variable. mxODBC, for example, > uses the "qmark" style, but MySQLdb uses "format". > >> 2- Cursor.execute accepts '%s' but puts the quotation mark around the >> substitution. >> >> sql = 'select * from %s where cusid = ? ' % name >> Cursor.execute(sql, (recID,)) >> >> still fails, but: >> >> sql = 'select * from basedata where cusid = %s ' >> Cursor.execute(sql, (recID,)) >> >> works regardless of recID being a string or an int. Obviously this >> stems from trying to parameterize the table name. >> > That's correct, as Scott has pointed out (with a good explanation of why). > >> If I use: >> >> sql = 'select * from %s where cusid = %%s ' % name >> Cursor.execute(sql, (recID,)) >> >> It makes 1 substitution in the first line, and another in the execute() >> >> sql = 'select * from %s where cusid = %%s ' % name >> # sql now == 'select * from basedata where cusid = %s ' >> Cursor.execute(sql, (recID,)) >> >> and it works. >> > That's right: you are now building a table-dependent query (i.e. the > table name is hard-wired in the SQL string) parameterized to the > required value for cusid. > >> Between your comments re: column names and table names , and the notes >> in cursor.py, I was able to figure it out. >> >> FYI I wanted to create a tableHandler class that could be extended for >> individual tables. That's why the query needs to accept variables for >> tablename. > > > You might want to take a look at how some existing object-mappers > achieve this - Ian Bicking's sqlobject module might be a good place to > start. I also might want to take a tutorial on searching. This looks like it could have saved me lots of wheel re-inventing. Thanks, Bill > > regards > Steve > >> >> Thanks. >> >> Bill >> >> Scott David Daniels wrote: >> >>> William Gill wrote: >>> >>> >>>> I have been trying to pass parameters as indicated in the api. >>>> when I use: >>>> sql= 'select * from %s where cusid = %s ' % name,recID) >>>> Cursor.execute(sql) >>>> it works fine, but when I try : >>>> sql= 'select * from %s where cusid like %s ' >>>> Cursor.execute(sql,(name,recID)) >>>> or >>>> sql= 'select * from ? where cusid like ? ' >>>> Cursor.execute(sql,(name,recID)) >>>> it fails. >>>> Can someone help me with the semantics of using parameterized queries? >>> >>> >>> >>> Neither column names nor table names can be parameters to >>> fixed SQL. Values are what you fiddle with. This squares with >>> the DBMS being allowed to plan the query before looking at the >>> parameters (deciding which indices to use, which tables to join >>> first, ...), then reusing the plan for identical queries with >>> different values. MySQL may not take advantage of this two-step >>> approach, but the DB interface is designed to allow it, so >>> the parameterization is constrained. >>> >>> See if something like this works: >>> >>> sql = 'select * from %s where cusid like ? ' % name >>> Cursor.execute(sql, (recID,)) >>> >>> --Scott David Daniels >>> Scott.Daniels at Acm.Org > > > From sybrenUSE at YOURthirdtower.com.imagination Thu Aug 25 06:46:52 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Thu, 25 Aug 2005 12:46:52 +0200 Subject: RE Despair - help required References: <430d8883@news.bezeqint.net> Message-ID: Yoav enlightened us with: > I am trying the following: > > re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") > > and I get a return of NoneType, and I have no idea why. Because you don't match a carriage return "\r". > I know that I missing something here, but I really can't figure out > why (I bet it's something obvious). Use forward slashes instead of backward slashes. And go nag at Microsoft for using the most widely used escape character as a path separator... Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From noway at sorry.com Sun Aug 21 12:24:11 2005 From: noway at sorry.com (Giovanni Bajo) Date: Sun, 21 Aug 2005 16:24:11 GMT Subject: Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out) References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <8xWNe.24050$HM1.696102@twister1.libero.it> <430890f5$0$16648$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >> Out of curiosity, was this ever discussed among Python developers? >> Would something like scons qualify for this? OTOH, scons opens nasty >> self-bootstrapping issues (being written itself in Python). > > No. The Windows build system must be integrated with Visual Studio. > (Perhaps this is rather, "dunno: is it integrated with VS.NET 2003?") > When developing on Windows, you really want all the support you can > get from VS, e.g. when debugging, performing name completion, etc. > To me, this makes it likely that only VS project files will work. You seem to ignore the fact that scons can easily generate VS.NET projects. And it does that by parsing the same file it could use to build the project directly (by invoking your Visual Studio); and that very same file would be the same under both Windows and UNIX. And even if we disabled this feature and build the project directly from command line, you could still edit your files with the Visual Studio environment and debug them in there (since you are still compiling them with Visual C, it's just scons invoking the compiler). You could even setup the environment so that when you press CTRL+SHIFT+B (or F7, if you have the old keybinding), it invokes scons and builds the project. So, if the requirement is "integration with Visual Studio", that is not an issue to switching to a different build process. >> Before considering a patch (or even a PEP) for this, the basic >> requirements should be made clear. I know portability among several >> UNIX flavours is one, for instance. What are the others? > > Clearly, the starting requirement would be that you look at the build > process *at all*. I compiled Python several times under Windows (both 2.2.x and 2.3.x) using Visual Studio 6, and one time under Linux. But I never investigated into it in detail. > The Windows build process and the Unix build process > are completely different. But there is no technical reason why it has to be so. I work on several portable projects, and they use the same build process under both Windows and Unix, while retaining full Visual Studio integration (I myself am a Visual Studio user). > Portability is desirable only for the Unix > build process; however, you might find that it already meets your > needs quite well. Well, you came up with a maintenance problem: you told me that building more external modules needs more effort. In a well-configured and fully-automated build system, when you add a file you have to write its name only one time in a project description file; if you want to build a dynamic library, you have to add a single line. This would take care of both Windows and UNIX, both compilation, packaging and installation. -- Giovanni Bajo From future_retro at yahoo.co.uk Wed Aug 3 07:23:56 2005 From: future_retro at yahoo.co.uk (future_retro at yahoo.co.uk) Date: 3 Aug 2005 04:23:56 -0700 Subject: wmi addprinterdriver for remote PC Message-ID: <1123068236.071352.209680@g47g2000cwa.googlegroups.com> Hi all, cannot work this one out at all... import win32com.client WBEM = win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" + servername + r"\root\cimv2") WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege") drv = WBEM.Get("Win32_PrinterDriver") drv.Properties_('Name').Value = "HP Color LaserJet 8550 PCL 5C" drv.Properties_('SupportedPlatform').Value = "Windows NT x86" drv.Properties_('Version').Value = "3" drv.Properties_('DriverPath').Value = "C:\\Printdrivers\\clj8550pcl5cwin2kxp" drv.Properties_('InfName').Value = "C:\\Printdrivers\\clj8550pcl5cwin2kxp\\hpbf401i.inf" method = drv.Methods_('AddPrinterDriver') InParms = method.InParameters InParms.Properties_.Item('DriverInfo').Value = drv drv.ExecMethod_('AddPrinterDriver',InParms) If servername is "." the driver loads. If it is a remote machine the script runs without any errors but no printerdriver is created. As far as can tell its not a privilege issue and when running through pythonwin it looks like the object is created but it doesn't show up in server properties. It also runs too quickly so I'm pretty sure its not doing anything. I've tried different drivers but no joy. From dd55 at cornell.edu Thu Aug 11 19:27:55 2005 From: dd55 at cornell.edu (Darren Dale) Date: Thu, 11 Aug 2005 19:27:55 -0400 Subject: command line reports References: <67Cdnd00Bo62PWbfRVn-1w@powergate.ca> <42fbb12b.1198953554@news.oz.net> Message-ID: Bengt Richter wrote: > On Thu, 11 Aug 2005 15:43:23 -0400, Darren Dale wrote: > >>Peter Hansen wrote: >> >>> Darren Dale wrote: >>>> Is there a module somewhere that intelligently deals with reports to >>>> the command line? I would like to report the progress of some pretty >>>> lengthy simulations, and currently I have the new reports written on a >>>> new line rather rather than overwriting the previous report. >>> >>> You mean you want sys.stdout.write(report + '\r') instead of "print >>> report" ? >>> >>> It's not really clear what you want. What's a "report" to you? >>> >>> -Peter >> >>I am printing something like >> >>trial 1 of 100 >>trial 2 of 100 >>... > Peter's suggestion will work, but it's easy to get something like > > >>> import sys, time > >>> def test(): > ... for i in xrange(5): > ... sys.stdout.write(('trial %s of 5'%(i+1)) + '\r') > ... time.sleep(.25) > ... print "We're done!" > ... > >>> test() > We're done! Thanks, I didnt realize that \r is different from \n. From dont at spam.me Sun Aug 28 12:27:24 2005 From: dont at spam.me (Bugs) Date: Sun, 28 Aug 2005 09:27:24 -0700 Subject: py to exe: suggestions? In-Reply-To: <1125217143.451511.25310@g43g2000cwa.googlegroups.com> References: <1125217143.451511.25310@g43g2000cwa.googlegroups.com> Message-ID: If your users already have Python installed then you could just create a self-extracting, self-executing .exe that contains only your scripts and necessary files. I belive many of the popular zip utilities have the ability to do this. The free info-zip does this as well: http://www.info-zip.org (but you have to recompile it with the appropriate switch turned on). If they don't have Python installed then you have no choice but to include the python DLLs, libraries, etc. as that's your runtime environment necessary to run your Python application. HTH chris patton wrote: > I need to convert a python file to an '.exe'. I've tried py2exe, and I > don't like it because you have to include that huge dll and libraries. > > Thanks for the Help!! > From could.net at gmail.com Fri Aug 12 00:11:37 2005 From: could.net at gmail.com (could ildg) Date: Fri, 12 Aug 2005 12:11:37 +0800 Subject: Python Challenge on BBC In-Reply-To: References: Message-ID: <311b5ce105081121111e2ec7be@mail.gmail.com> But when I can't find a way for a long time, I'll be upset. On 8/12/05, Jeff Schwab wrote: > Magnus Lie Hetland wrote: > > Just saw this on the BBC World program Click Online: > > > > http://bbcworld.com/content/template_clickonline.asp?pageid=665&co_pageid=6 > > > > I must say, I think this is the first time I've heard Python discussed > > on TV at all... Cool :) > > > > (Now maybe I'll have to finish the rest of those P.C. levels... ;) > > > > Boy, Python Challenge is addictive! > -- > http://mail.python.org/mailman/listinfo/python-list > From lars at gustaebel.de Wed Aug 31 06:36:49 2005 From: lars at gustaebel.de (Lars =?utf-8?q?Gust=C3=A4bel?=) Date: Wed, 31 Aug 2005 12:36:49 +0200 Subject: change date format In-Reply-To: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> References: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> Message-ID: <200508311236.49648.lars@gustaebel.de> [Xah Lee] > Apache by default uses the following format for date: > 30/Aug/2005 > > is there a module that turn this directly into yyyymmdd? Use time.strptime() and time.strftime(). Not a single occurrence of the f**k word. You're making progress. Keep it up! -- Lars Gust?bel lars at gustaebel.de Truth is the invention of a liar. (Anonymous) From apardon at forel.vub.ac.be Wed Aug 24 04:52:20 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 24 Aug 2005 08:52:20 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-24, Magnus Lycka schreef : > Antoon Pardon wrote: >> Such a PEP would have no chance of being accepted, since >> it would break to much existing code. > > What's the point of this thread then? I only hope to impress people that the way python treats 'nothing' in a condional context is not so obvious as seems to be accepted here. >> But how can you do this when somewhere else '' is used as >> an indication for an EOF. > > If that's your problem, I guess that's what you should attack, > not that Python considers nothing to be nothing even it might > some time become something. IMO the two are linked. People use '' as an EOF because the call they are working with returns strings and they need a way to end a loop. Since "if var:" is considered beautifull they search for a nothing value and since they were working with strings, '' gets chosen. > Network programming with Python works pretty well though, so > it seems this is a non-issue too. > >>>I think the typical comment is to replace "if s != '':" with >>>"if s:" in contexts where s is always a string, >> >> And it is IMO this kind of comments that lead to '' being used >> as an EOF. > > Huh? Aren't the Python APIs just mirroring the behaviour of the > underlying C APIs? That may depend on how strict the meaning of mirroring is, you are using. I would say no. Even if the answer is yes I would say that chosing such values on that basis was a bad design choice. >>>or to replace >>>"if expr != False:" with "if expr": in cases where "expr" is an >>>expression that returns True or False etc. In some cases, obvious >>>bugs, such as "if (a and b) == True:" where the programmer >>>should have written "if (a and b):" are pointed out. >> >> This is not such an obvious bug. Because python allows non boolean >> operands with "and" the two don't behave the same. How do you know >> which behaviour the other person wants? > > I think you misread my text. If the programmer should have written > "if (a and b):", adding "==True" will cause different behaviour > unless True (or 1) is the only non-False value that b can have. > This would not be obvious for someone who expects that the results > of logical operations will return boolean values. So? How do you know what the writer of the code expects. You originaly wrote it was an obvious bug, how do you come to that conclusion. >> I have yet to see a mathematical work where 0, or any kind of >> empty sequence is treated as false. In mathematics accuracy >> is considered vitaly important and won't be sacrified to >> remove redundancy. Boolean expression are always written out >> fully. > > Dear Antoon. The "if" statement interprets the result of an > expression to determine whether or not to execute a block of > code. If "x" is an expression that returns True or False, then > "x==True" is an equivalent expression. It's just not written in > its minimal form. But we were talking about interpreting 0, '', (), [], and {} directly in a conditional context. No mathematical text will just contain a line like a => b > 10 when what is meant is: a != 0 => b > 10 > It's like writing "a / b * 100 %" instead of just "a / b" in a > mathematical equation. The first version contains some kind of > noise that just looks ugly for people who know that 100%==1. > Why multiply with 1? At least in my home town, the MBA students > write stuff like that, but mathematicians and engineers would > just think it was ugly. But you can't transfer this situation to python, because python allows non Boolean values to be interpreted in a conditional context. I have code somewhere that looks like this: if var is True: and that is exactly how it should be. The if branch should not be taken if var would be 5. I even have code that looks like: if var is not False: And although in a logical context those two would be equivallent to each other and to just "if var:", they are not equivallent in a python context. Yet I see a lot of suggestions here to change logical expressions in python code, seemingly based on the fact that they would be equivallent in a logical context. >> But you don't know if the logic expression are redundant. The >> suggestions made are usually not equivallent. > > I think I know. Please point out if I made some mistake. > > It's pretty common that people fail to reduce logical expressions. > I've seen C++ code checking for overlapping periods looking roughly > like this: > > if ((start1<=start2 and stop1>=start2 and stop1<=stop2) or > (start1<=start2 and stop1>=stop2) or > (start1>=start2 and stop1<=stop2) or > (start1>=start2 and start1<=stop2 and stop1>stop2)) > > For that person, his code might actually have been clearer than > the less cluttered version I changed it to: > > if (start1<=stop2 and start2<=stop1) > > At least he spent a few minutes staring at it before he could > accept that they were equivalent. (Maybe he just gave up.) I think he did, because both expression are not equivallent unless some implicite constraints make them so. Values where both expressions differ are: start1=67, stop1=9, start2=10, stop2=29 >> In that case you wouldn't return an empty sequence if you wanted >> a false value in a sequence context but would throw an exception. > > Huh? If I want False I use False. If a sequence is empty, it's empty. > It seems to me that you make things more complicated than they have > to be. You can't just decide to use False if you want False. What if you depend on a library that returns '', because '' behaves as false in a conditional context. So returning it was good enough for those who wrote it. -- Antoon Pardon From enleverlesO.OmcO at OmclaveauO.com Mon Aug 29 15:07:41 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Mon, 29 Aug 2005 21:07:41 +0200 Subject: python and ajax References: Message-ID: <43135dbd$0$990$8fcfb975@news.wanadoo.fr> Hi ! Here : http://wikipython.flibuste.net/moin.py/AJAX @-salutations Michel Claveau From exogen at gmail.com Sun Aug 7 11:03:23 2005 From: exogen at gmail.com (Brian Beck) Date: Sun, 07 Aug 2005 11:03:23 -0400 Subject: Python -- (just) a successful experiment? In-Reply-To: References: Message-ID: Eric Pederson wrote: > Raise your hand if you think the best technology wins! > > > For those of you with your hands in the air, tell me: if Python is so good, why has PHP achieved such greater adoption and mindshare? Why do web scripters still cling to their Perl, even in corporate environments? Why hasn't Python made inroads against Java? Why is Ruby, and Ruby on Rails, getting such strong play? > > Are these better programming languages, or is it other factors? You make some good points and I agree that more needs to be done to make python accessible, but you basically ruined the rest of your post right off the bat. Replace Python with, say, Linux and PHP with, say, Windows. How the respective technologies got where they are today is not important to the analogy (except maybe being in the right place at the right time). There is such a huge counter-example of "the best technology wins" staring everyone in the face every day, that the first part of your post doesn't really do anything for me. But ultimately I am on your side. Python has a long way to go, and it has nothing to do with the language design... -- Brian Beck Adventurer of the First Order From ironfroggy at gmail.com Mon Aug 1 11:12:46 2005 From: ironfroggy at gmail.com (Calvin Spealman) Date: Mon, 1 Aug 2005 11:12:46 -0400 Subject: Operator Overloading In-Reply-To: <20050801051247.10135.qmail@webmail29.rediffmail.com> References: <20050801051247.10135.qmail@webmail29.rediffmail.com> Message-ID: <76fd5acf0508010812586de3d7@mail.gmail.com> On 1 Aug 2005 05:12:47 -0000, Gurpreet Sachdeva wrote: > Hi, > > Is there any provision in python which allows me to make my own operators? > > My problem is that I need to combine two dictonaries with their keys and I > don't want to use any of the existing operators like '+','-','*'. > So is there a way I can make '**' or '~' as my operators to add two > dictonaries? If not which all operators can I overoad? > > Thanks, > Garry Why do you need to add operators for this? Why not use the dictionary's update method? it also has the benefit of being much clearer. # Get our two dictionaries d1 = foo() d2 = bar() # And merge them into a third d3 = {} d3.update(d1) d3.update(d2) From steve at holdenweb.com Mon Aug 22 08:29:12 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 13:29:12 +0100 Subject: network programming In-Reply-To: References: Message-ID: Tom Anderson wrote: > On Sun, 21 Aug 2005, John Walton wrote: > > >>Hello, everyone. I just began school, and they already assigned us >>science fair. Since I'm in 8th grade, I get to do demonstrations for >>our projects. I'm probably going to demonstrate Python's networking >>capabilities by writing a simple instant messenger program. I only have >>a few problems: >> >>1. I know squat about Python network Programming >> >>2. I know nothing about networks >> >>So if any of you know of a good Python Networking Tutorial or a website >>with lots of information on networks and networking, please reply. >>Thanks! > > > There are two sides to this problem. The first is understanding networks > in general, and the specific application protocols you're interested in. > When i say 'understanding networks in general', don't panic - i don't mean > you need to understand everything about how the internet works. In fact, > you don't really need to understand *anything* about how the internet > works, you just need to understand the interfaces it exposes to you. And, > helpfully, that interface is pretty simple: a program can get a connection > to another program, running on a different machine, which amounts ot a > pipe for bytes - both ends can write bytes to the pipe when they feel like > it, and those bytes become available for the other end to read. To open > one of these connections, you need to know the hostname or IP address of > the computer at the far end, and something called a 'port number', which > is basically a way of identifying which program on that machine you want > to talk to; if you want other programs to be able to open connections to > your program, you have to pick a port number and ask the system to give > you any connections that are made to it. > > That's pretty much it for the network fundamentals. There is more - > datagram sockets, looking up IP addresses, doing funky things with sockets > - but you can forget about that until you've mastered the basics. > I tried to cover those basics as briefly as possible in the tutorial I mentioned earlier. I'd appreciate your comments on how well I succeeded. > What you do need to understand beyond this, though, is about the > application protocol you're using. The network just gives you a way to > move streams of bytes; in order to actually do anything useful, you need > an agreement between the programs at either end of the connection about > what those bytes mean - that's an application protocol. It's basically a > file format as applied to a network connection instead of a file. Each > application protocol is completely different to every other one (well, > there are a lot of similarities, but they're mostly different), so you'll > need to read up on the one you want to use (or invent your own!) - the > documentation is (almost always) in the form of a document unhelpfully > called a Request For Comments, or RFC; the internet RFCs are published > here: > > http://www.rfc-editor.org/ > > For example, here's the RFC for HTTP version 1.0: > > http://www.rfc-editor.org/rfc/rfc1945.txt > > RFCs can be pretty heavy going, but they are *the* definitive > specifications, so they're worth reading. Once you're used to them, > they're often easier to read than tutorials, i find. > Not for newbies, though very useful for ensuring high levels of interoperability (and fascinating when you start to realize that real products bend the RFCs in various ways). > The second thing is understanding how to do network programming in python. > There's a well-established API in C for network programming - the socket > API - which comes from UNIX; python uses a fairly simple translation of > this as its network API (look in the 'socket' package). The good thing > about this is that this API is well-understood and well-documented. The > bad thing is that it's a bit of a mess (compare and contrast to the API in > Java if you don't believe me). There's detailed documentation for the > socket module here: > > http://docs.python.org/lib/module-socket.html > [...] But then Java's a bit of a mess as a language when compared with Python, I should say. While I know the language has many adherents, it also seems to have many programmers who only know enough to follow recipes. This latter feature is a symptom of the language's popularity, so I suppose we should expect the same problems in about twenty years when Python becomes more popular than Java. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From exogen at gmail.com Mon Aug 1 13:35:11 2005 From: exogen at gmail.com (Brian Beck) Date: Mon, 01 Aug 2005 13:35:11 -0400 Subject: Getting not derived members of a class In-Reply-To: <1122914771.387766.206260@g44g2000cwa.googlegroups.com> References: <1122914771.387766.206260@g44g2000cwa.googlegroups.com> Message-ID: George Sakkis wrote: >>>>z = Z() >>>>z.__class__.__mro__ > > (, , , > , ) > > Old style classes don't have __mro__, so you have to write it yourself; > in any case, writing old style classes in new code is discouraged. Notice also that George's __mro__ solution returns the bases in reverse order than what you requested (in your example, you said B should come last). So use list(reversed(z.__class__.__mro__)) or z.__class__.__mro__[::-1] -- Brian Beck Adventurer of the First Order From paolo_veronelli at tiscali.it Thu Aug 18 04:24:59 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Thu, 18 Aug 2005 10:24:59 +0200 Subject: An observer pattern application. Message-ID: <430445DB.5020406@tiscali.it> Lately I was needing to use multiple inheritance to split behaviour of a class and modularize it. But the problem raises when the need is to add operations to a method already present in one of them from another. I think the technical solution is the use of 'super'. Then I tried to write a decorator for automatize the 'super' call,but I failed. Next solution is implementing the observer pattern on methods call. I'm pretty sure there are bugs and ideas to be corrected in the next code,any help and comment appreciated. Regards Paolino ######################################################################################## ''' A module collecting classes for known patterns ''' import types class Observer(dict): ''' A class defining some decorators for function/methods to chain/link them when called .To do:implement pre event execution hooking''' def __call__(self,observed,args,kwargs): for reaction in self.get(observed,()): reaction(*args,**kwargs) def emit(self,method,observed=None): ''' A decorator for functions to signal their calling.Post hook cablated''' def wrapper(*args,**kwargs): if observed: if type(observed) is types.MethodType: event=observed.im_func else: event=observed else: event=wrapper result=method(*args,**kwargs) self(wrapper,args,kwargs) return result return wrapper def emitOther(self,observed): ''' A decorator facility to let the function/method emit another event (not itself)''' def wrapEmit(method): return self.emit(method,observed) return wrapEmit def reactOn(self,*observeds): ''' a decorator to set the function/method as a reaction to *observeds event. Remember to use __ name mangling when working on methods to be able to use same reaction name on multiple class inheritances''' def reaction(method): for observed in observeds: if type(observed) is types.MethodType: observed=observed.im_func self.setdefault(observed,set()).add(method) return method return reaction if __name__=='__main__': observer=Observer() class base(object): @observer.emit def method(self,*args,**kwargs): print '%s.method'%str(self),args,kwargs class extensionA(object): @observer.reactOn(base.method) def __methodReaction(self,*args,**kwargs): print 'A,%s.methodReaction'%str(self),args,kwargs class extensionB(object): @observer.reactOn(base.method) def __methodReaction(self,*args,**kwargs): print 'B,%s.methodReaction'%str(self),args,kwargs class applicable(base,extensionA,extensionB): @observer.reactOn(base.method) def __methodReaction(self,*args,**kwargs): print 'applicable,%s.methodReaction'%str(self),args,kwargs pass applicable().method('cucu') ___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com From dmqatpobox.com Fri Aug 26 21:26:09 2005 From: dmqatpobox.com (David MacQuigg) Date: Fri, 26 Aug 2005 18:26:09 -0700 Subject: Fighting Spam with Python References: Message-ID: On Fri, 26 Aug 2005 10:36:28 -0400, Fran?ois Pinard wrote: >[David MacQuigg] > >> Getting these methods widely and effectively used is our big >> challenge, and one that I hope to accomplish with my efforts. > >I wish one of these methods, either yours or one of these few others >which were developed and proposed in the recent years, will succeed. I don't have a method, and that is a key part of the strategy. The Registry is intended to support all methods. My main technical contribution, if you can call it that, is to figure out how we can tie these methods into a system where not all participants are using the same method. ( An inter-operability protocol, if you need a fancy name.) >It might be useful, for someone involved like you are (thanks for all of >us!), that you make a survey of those others, trying to understand why >they failed to acquire popularity, not repeating the same errors if any. The main reason for the current failure is that the effort to achieve a common authentication standard has degenerated into a war. I did try to find information on other attempts at setting up a Registry/Clearinghouse of reputation information. There has been an effort by Spamhaus to establish such a registry, but they were counting on senders to support it. That seems to me a fatal flaw. Our plans are to have *receivers* support the registry via subscription fees. Senders will need an incentive, and that will be provided by receivers who use the Registry to clear reputable mail, and send the rest to a spam filter. There are also some successful proprietary systems, like IronPort Senderbase, that I think are similar, but I don't know the details. You have to pay them big bucks for a "spam appliance". -- Dave From leszczynscyATnospam.yahoo.com.nospam Sun Aug 7 01:23:33 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Sun, 07 Aug 2005 00:23:33 -0500 Subject: Berkely DB =?windows-1252?Q?=96_many_writers=2C_many_?= =?windows-1252?Q?readers?= In-Reply-To: References: Message-ID: Eric S. Johansson wrote: > Andy Leszczynski wrote: > >> >> I need to now option I open the Berkley DB (both db and env) to have >> configuration for multiple writers and multiple readers. Via multiple >> processes and multiple threads. No trx needed. > > > the simple answer is you can't. bdbm is probably single writer multiple > reader. I believe if you use of the the most recent sleepy cat > database, you have support for multiple readers and writers in any context. [...] I have learned later that you can, just use Concurrent DB poruct (db.DB_INIT_CDB): ...envflags=db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_THREAD|db.DB_INIT_CDB ...env.open(file,envflags) A. From spam.csubich+block at block.subich.spam.com Tue Aug 9 21:15:43 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 21:15:43 -0400 Subject: Import question In-Reply-To: <1123634807.617032.271850@g14g2000cwa.googlegroups.com> References: <1123614152.482652.72900@g44g2000cwa.googlegroups.com> <1123634807.617032.271850@g14g2000cwa.googlegroups.com> Message-ID: ncf wrote: > Hmm...thanks for the replies. Judging by this, it looks like I might > still be in a slight perdiciment with doing it all, but time will tell. > I wish there were a way I could reference across multiple modules. > > Well, thanks for your help. Hopefully I'll be able to work out some > *simple* solution for all of this. What exactly is it that you're trying to do? You don't need access to the class definition (which would be in a module) if you just want to manipulate a particular _instance_. Advantage of dynamic typing and all. For example: module1: def function(x): x.method(1) module2: class foobar: def method(x): print 'I received', x, ', aren't I happy?!' import module1 obj = foobar() module1.function(obj) From kay.schluehr at gmx.net Thu Aug 11 17:06:06 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 11 Aug 2005 14:06:06 -0700 Subject: Python supports LSP, does it? In-Reply-To: References: Message-ID: <1123794366.239747.82720@f14g2000cwb.googlegroups.com> en.karpachov at ospaz.ru wrote: > On Thu, 11 Aug 2005 01:19:19 +0100 > phil hunt wrote: > > > According to Wikipedia, the Liskov substitution principle is: > > > > Let q(x) be a property provable about objects x of type T. Then > > q(y) should be true for objects y of type S where S is a subtype of T > > > > To me, this is nonsense. Under this definition any subtype must > > behave the same as its parent type, becausde if it doesn't there > > will be some q(y) that are different to q(x). > > > > But if it behaves the same, what's the point of having a subtype? > > It does not behave the same, it has the same properties. Doesn't it? "What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T." Barbara Liskov, "Data Abstraction and Hierarchy" SIGPLAN Notices, 23,5 (May, 1988). IOW if an arbitrary program P works with objects of type T and you replace each object of type T by an object of type S and each P works still the same way one can imply that S is a subtype of T. It is a funny aspect of this definition that it doesn't work for reflective programming languages. If you have access to properties AS properties ( on the meta-level ) it is easy to break LSP. Preserving LSP becomes a challenge or a requirement. Example: The statement if type(obj) == T: ... breaks LSP. One might say that that T has no subtypes at all. But since T is arbitrary chosen no type in Python has a subtype in a strict sense. On the other hand this statement preserves LSP: if isinstance(obj,T): ... Therefore one can write programs that work as if LSP was valid and subtypes indeed exist. Kay From news at NOwillmcguganSPAM.com Sun Aug 28 17:19:56 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Sun, 28 Aug 2005 22:19:56 +0100 Subject: aproximate a number In-Reply-To: References: Message-ID: <43122a7d$0$25903$db0fefd9@news.zen.co.uk> billiejoex wrote: > Hi all. I'd need to aproximate a given float number into the next (int) > bigger one. Because of my bad english I try to explain it with some example: > > 5.7 --> 6 > 52.987 --> 53 > 3.34 --> 4 > 2.1 --> 3 > Have a look at math.ceil >>> import math >>> math.ceil(5.7) 6.0 Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From michaels at rd.bbc.co.uk Mon Aug 1 13:50:11 2005 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Mon, 01 Aug 2005 19:50:11 +0200 Subject: ANN: Kamaelia 0.2.0 released! Message-ID: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Kamaelia 0.2.0 has been released! What is it? =========== Kamaelia is a collection of Axon components designed for network protocol experimentation in a single threaded, select based environment. Axon components are python generators are augmented by inbox and outbox queues (lists) for communication in a communicating sequential processes (CSP) like fashion. The architecture is specifically designed to try and simplify the process of designing and experimenting with new network protocols in real environments. More background on the motivations behind Kamaelia can be found here: http://kamaelia.sourceforge.net/Challenges/ The focus of this release adds in support for introspection, pygame based interfaces, 4 new examples using these, visualisation tools, as well as syntactic sugar to make building Kamaelia systems simpler. (Specifically Graphline and pipeline systems. This build upon the existing base allowing TCP and Multicast based client/server systems. Other additions and changes include updated examples, variety of bugfixes in existing components (some pre-emptively discovered by introspection), and a variety of utility components. It is now also possible to write components using threading as the concurrency model rather than generators - allowing integration with thread/blocking only based systems. The system is known to work under Linux, Mac OS X, Windows and a subset has been tested on Series 60 mobiles. General feedback is welcome either directly, mailing lists or via the project weblog which is here: * http://kamaelia.sourceforge.net/cgi-bin/blog/blog.cgi What's new in version 0.2.0 ? ============================= Lots! Full release notes can be found here: * http://kamaelia.sourceforge.net/Kamaelia-0.2.0-ReleaseNotes.html Editted highlights... Debian Packages! Many thanks are due to Gintautas Miliauskas, Programmers of Vilnius, for assistance in building Debian packages. (The current packages are based on his, and any errors are likely to be mine, not his) These have been tested successfully on Ubuntu 5.04. 4 new examples have been added showing of various new subsystem: * Example 5 : This creates a simple streaming system, and looks inside to see what components are running/active, and passes the resulting information an Axon Visualiser. * Example 6 : This is a simple/generic topology visualisation server. Accepts the following commands over the network ADD NODE id label auto - ADD LINK id id DEL NODE id DEL ALL As this stands this is pretty useful, but that's pretty much everything it does like this. * Example 7 : This shows how the visualisation subsystem can be extended to work in different ways. What this does by default when run is randomly create new nodes and new linkages quite quickly, allowing you to see how the system works. * Example 8 : Sample slideshow/presentation tool. Unlike traditional slideshow/presentation tools, you can modify this to run arbitrary components. An example of how this can work is provided - allowing stepping through some graph visualisations along with the presentation. A Tools directoy has been added with the following tools: * Axon Shell. (Requires IPython) Implements a simple command line shell which allows experimentation with Axon systems - the shell runs a scheduler as a background thread. For a tutorial of use, see: * http://kamaelia.sourceforge.net/AxonShell.html * Axon Visualiser. Implements a simple tool for looking inside (quite literally) running Axon/Kamaelia systems. This allows a very different style of debugging and can be extremely useful. Tutorial on its way! Graphlines and Pipelines These are probably the most useful additions to Kamaelia since 0.1.2. They are essentially syntactic sugar for building and working with systems of components, but make building interesting systems rapidly out of pre-existing components fun and easy. The pipelines follow the same sort of model as the Unix pipeline. Graphlines are something new, and like pipelines and all linkages may take any data along them. Please take a look at the release notes for a graphline example. A couple of simple pipelines looks like this: pipeline( ReadFileAdaptor(file_to_stream, readmode="bitrate", bitrate=400000, chunkrate=50), blockise(), # Ensure chunks small enough for multicasting! Multicast_transceiver("0.0.0.0", 0, "224.168.2.9", 1600), ).activate() pipeline( Multicast_transceiver("0.0.0.0", 1600, "224.168.2.9", 0), detuple(1), VorbisDecode(), AOAudioPlaybackAdaptor(), ).run() A selection of other subsystems have been added - targeted at visualisation of Kamaelia (and other graph structured) systems using pygame. The layout mechanism is a simple physics engine. Key packages of note added: Kamaelia.UI, Kamaelia.UI.Pygame, Kamaelia.Physics, Kamaelia.Visualisation.Axon, Kamaelia.Visualisation.PhysicsGraph Requirements ============ * Python 2.3 or higher recommended, though please do report any bugs with 2.2. * Axon (1.1.1 recommended) * vorbissimple (if you want to use the vorbis decode component/examples) (Both Axon and vorbissimple are separate parts of the Kamaelia project, and available at the same download location - see below) Platforms ========= Kamaelia has been used successfully under both Linux, Windows and Mac OS X (panther). A subset of Kamaelia has been successfully tested on Series 60 Nokia mobiles when used with the Axon SERIES 60 branch. Where can I get it? =================== Web pages are here: http://kamaelia.sourceforge.net/Docs/ http://kamaelia.sourceforge.net/ (includes info on mailing lists) ViewCVS access is available here: http://cvs.sourceforge.net/viewcvs.py/kamaelia/ Weblog * http://kamaelia.sourceforge.net/cgi-bin/blog/blog.cgi Licensing ========= Kamaelia is released under the Mozilla tri-license scheme (MPL1.1/GPL2.0/LGPL2.1). See http://kamaelia.sourceforge.net/Licensing.html Best Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk, http://kamaelia.sourceforge.net/ British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From alessandro.bottoni at infinito.it Sat Aug 27 05:04:07 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Sat, 27 Aug 2005 09:04:07 GMT Subject: Any projects to provide Javascript-style client-side browser access via Python? References: Message-ID: Kenneth McDonald wrote: > So anyone know if there are projects underway on this? As long as I know, Mozilla (as Firefox, Thunderbird and Sunbird) can host Python as an internal scripting language thanks to PyXPCOM (the Python binding to the XPCOM cross-platform COM technology used by Mozilla). In this case, you have to recompile Mozilla from source to enable the PyXPCOM support (that is: you will end up having a "custom" Mozilla to distribute to your users). Have a look at www.mozilla.org and www.mozdev.org and/or search for PyXPCOM on Google. (Most likely, something like that is available for Konqueror and others Linux browsers, as well) HTH ----------------------------------- Alessandro Bottoni From http Tue Aug 16 04:39:56 2005 From: http (Paul Rubin) Date: 16 Aug 2005 01:39:56 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <7x8xzcck9d.fsf@ruckus.brouhaha.com> <86wtmvlti7.fsf_-_@bhuda.mired.org> <7xoe87vl0i.fsf@ruckus.brouhaha.com> <42f8c2e2.1006880848@news.oz.net> <7xmznijn8v.fsf@ruckus.brouhaha.com> Message-ID: <7xek8ujmw3.fsf@ruckus.brouhaha.com> Paul Rubin writes: > So I think a (maybe not achievable) performance goal > is for the web app to use 50% of the available cycles making html, and > the other 50% go to gzipping the html. That means that the app should > make dynamic output as fast as gzip can compress it, It occurs to me that if the html pages are generated from templates with little bits of executable code, then maybe the static parts of the templates can be gzipped ahead of time, and a lot of the dynamic stuff is cacheable and can be gzipped ahead of time. (gzip is sort of a "linear operator" in that gzip(a)+gzip(b) is a valid though not maximally efficient gzip encoding for gzip(a+b)). That could save some cpu cycles at the expense of impaired compression ratio. Hmm. From jjreavis at gmail.com Fri Aug 19 13:53:02 2005 From: jjreavis at gmail.com (Jeff Reavis) Date: 19 Aug 2005 10:53:02 -0700 Subject: Python for Webscripting (like PHP) References: Message-ID: <1124473982.704284.136110@g43g2000cwa.googlegroups.com> You might want to check out spyce. It uses a server page model (like jsp and php) so you can embed python in html. It has the standard stuff you would need for making a web site (session support, etc) and also contains features like custom tags. http://spyce.sourceforge.net/ From matt at matt-darby.com Thu Aug 18 19:07:15 2005 From: matt at matt-darby.com (Matt Darby) Date: Thu, 18 Aug 2005 19:07:15 -0400 Subject: up to date books? In-Reply-To: References: Message-ID: <430514A3.9050705@matt-darby.com> John Salerno wrote: >Also, are Python and Ruby similar languages? Which would be better to learn? > > Knowing both, they are very similar. Python seems to be more mature and has better support. Threading is easier in Ruby, while Python is more intuitive across the board. I really like both, but it seems that you really can do more, easily, with Python. Very recently I was all about Ruby, then I rediscovered Python. It's really quite brilliant. From stas at tuxzilla.tuxhome Mon Aug 8 13:59:31 2005 From: stas at tuxzilla.tuxhome (stas) Date: Mon, 08 Aug 2005 19:59:31 +0200 Subject: gettext again References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> <42f773c1$0$25062$8fcfb975@news.wanadoo.fr> Message-ID: On Mon, 08 Aug 2005 17:01:21 +0200, cantabile wrote: > stasz a ?crit : > Whoooot ! Working at last, after three days... It wasn't the LANG param [...] > Anyways, you made my day my friend ! > Many many thanks ! Your welcome :-) Stas From gnb at itga.com.au Wed Aug 31 04:04:39 2005 From: gnb at itga.com.au (Gregory Bond) Date: Wed, 31 Aug 2005 18:04:39 +1000 Subject: Adding bound methods dynamically... In-Reply-To: <4o4ah1h2r53gll81jinueaugpqi7rq7hsj@4ax.com> References: <4o4ah1h2r53gll81jinueaugpqi7rq7hsj@4ax.com> Message-ID: Kevin Little wrote: > I want to dynamically add or replace bound methods in a class. I want I asked a seemingly-unrelated question a week or so ago, and learned something interesting: Python 2.3.4 (#2, Jul 12 2004, 12:46:36) [GCC 3.3] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> def foo(self): .. print "foo called" .. >>> class C(object): .. pass .. >>> type(foo) >>> C.foo = foo >>> type(C.foo) >>> c = C() >>> c.foo() foo called >>> type(c.foo) >>> I.e. assigning a normal function object to a class object turns it into a member function! You can read more in the thread with the subject 'keeping a ref to a non-member function in a class'. From alanmk at hotmail.com Tue Aug 23 10:54:40 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Tue, 23 Aug 2005 15:54:40 +0100 Subject: Sanitizing untrusted code for eval() In-Reply-To: References: Message-ID: [Jim Washington] > I'm still working on yet another parser for JSON (http://json.org). It's > called minjson, and it's tolerant on input, strict on output, and pretty > fast. The only problem is, it uses eval(). It's important to sanitize the > incoming untrusted code before sending it to eval(). I think that you shouldn't need eval to parse JSON. For a discussion of the use of eval in pyjsonrpc, between me and the author, Jan-Klaas Kollhof, see the content of the following links. A discussion of the relative time *in*efficiency of eval is also included: it is much faster to use built-in functions such str and float to convert from JSON text/tokens to strings and numbers. http://mail.python.org/pipermail/python-list/2005-February/265805.html http://groups.yahoo.com/group/json-rpc/message/55 Pyjsonrpc uses the python tokeniser to split up JSON strings, which means that you cannot be strict about things like double (") vs. single (') quotes, etc. JSON is so simple, I think it best to write a tokeniser and parser for it, either using a parsing library, or just coding your own. -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From benji at benjiyork.com Wed Aug 3 13:12:55 2005 From: benji at benjiyork.com (Benji York) Date: Wed, 03 Aug 2005 13:12:55 -0400 Subject: In-place decorate-sort-undecorate - best implementation? In-Reply-To: References: Message-ID: <42F0FB17.9060101@benjiyork.com> Tom Anderson wrote: > I don't have python 2.4; anyone care to check how they compare there? I > used the following timer function: I think on 2.4 the new "key" option to list.sort would be the fastest way to accomplish what you want. -- Benji York From tony.ha at philips.com Wed Aug 17 04:38:18 2005 From: tony.ha at philips.com (tony.ha at philips.com) Date: Wed, 17 Aug 2005 08:38:18 GMT Subject: PyPE 2.1 run problem Message-ID: <_HCMe.39$ea.3751@ns2.gip.net> Hello, I have downloaded the PyPE2.1-win-unicode.zip, after unzip it with winzip into PyPE2.1-win-unicode dierctory on window XP. I try to run "pype.exe" by double click on it, but nothing has happen, then when I run it with "run as..." using the right click button. I have the following Message in the pype.exe.log Traceback (most recent call last): File "pype.py", line 30, in ? File "configuration.pyc", line 129, in ? WindowsError: [Errno 267] The directory name is invalid: 'E:\\Downloads\\Python\\PyPE\\PyPE2.1-win-unicode\\library.zip/*.*' I also copy the "PyPE2.1-win-unicode" directory into "C:\Python24\Lib\site-packages" and run it, but it behaves the same !! Then I downloaded the source code and unzip it into "PyPe2.1-src", and run "python pype.py" in a command window. The progroam detected I have an older version of wxPython 2.5.5 and askes me do I want to download the newer version 2.6.1. Which I did. After downlowd the wxPython 2.6.1 (win-unicode" version). I installed it into Python 2.4.1, then re-run PyPE. i.e re-issue "python pype.py" in a command window." I have the following traceback Error message: [ Wed Aug 17 09:32:32 2005 ] Loading history from C:\Documents and Settings\gbr02333\.pype\history.txt Traceback (most recent call last): File "pype.py", line 3926, in ? main() File "pype.py", line 3916, in main filehistory.root = root = app.frame = MainWindow(None, -1, "PyPE", sys.argv[1+opn:]) File "pype.py", line 438, in __init__ self.loadHistory() File "pype.py", line 1152, in loadHistory self.config[nam][k] = dict(v) TypeError: iteration over non-sequence I wonder does anyone using PyPE2.1 on Windown XP SP2 and have the same problem? Can any one help with the problem? Thanks in advance ! Tony Ha. -------------- next part -------------- An HTML attachment was scrubbed... URL: From grante at visi.com Tue Aug 2 10:31:08 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 02 Aug 2005 14:31:08 -0000 Subject: py2exe windows apps path question Message-ID: <11ev0tcg9n2ndd@corp.supernews.com> I have several python apps (some wxPython, some plain text-mode stuff) that I distribute internally for installation on Win32 machines. They're bundled/installed using py2exe and inno setup. I followed what I think is the normal procedure of installing each app in its own directory under /Program Files//. The problem is that the apps only run if they're started with the install directory as the current working directory. Otherwise they can't find the .dll's they use from the install directory. Is there some way to temporarily add the app's install directory to the search path for .dll's? -- Grant Edwards grante Yow! .. I think I'd at better go back to my DESK visi.com and toy with a few common MISAPPREHENSIONS... From uche.ogbuji at gmail.com Wed Aug 17 19:35:59 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 17 Aug 2005 16:35:59 -0700 Subject: PyXML and xml.dom In-Reply-To: References: Message-ID: <1124321759.444972.327510@f14g2000cwb.googlegroups.com> > Is PyXML now part of the Python distribution, or is it still an add-on? Parts of PyXML have been migrated into Python core since Python 2.0, but there is still also a standalone PyXML package.,. See: http://www.xml.com/pub/a/2002/09/25/py.html -- Uche http://copia.ogbuji.net From gene.tani at gmail.com Tue Aug 23 06:12:41 2005 From: gene.tani at gmail.com (gene tani) Date: 23 Aug 2005 03:12:41 -0700 Subject: Eve from Adams' Ribs In-Reply-To: <0bheed.c46.ln@lightning.itga.com.au> References: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> <0bheed.c46.ln@lightning.itga.com.au> Message-ID: <1124791960.981976.43120@o13g2000cwo.googlegroups.com> ORM: Several to choose from: http://blogs.nuxeo.com/sections/blogs/florent_guillaume/2005_08_11_object_relational http://en.wikipedia.org/wiki/Object-relational_mapping#Python http://www.python.org/pypi?:action=browse&asdf=256 From deets at nospam.web.de Tue Aug 23 17:54:57 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Aug 2005 23:54:57 +0200 Subject: Sandboxes In-Reply-To: References: <3mog8aF17j66oU1@uni-berlin.de> Message-ID: <3n1k9hF19c12vU1@uni-berlin.de> > Basically I just want a language to allow users to write macros, > interact with application objects, set property values, sequence > operations, supporting loops and branch logic and so forth. > > Something along the lines of a drawing program that allowed uers to > write and/or download scripts to perform batches of arbitrary > (parameterized) operations. > > e.g.scripts along the lines of: > > function drawfan(x,y,r) > i=45 > while (i<90) > if i.isEven() > color=red; > else > color=blue; > PublishedInterface.Drawline(x,y, x+r*sin(i), y+r*cos(i),color) > i++ > end while > > I want the 'worst case' a malicious script to be able to accompish to be > a program crash or hang. The you migth want to think about not criplling the language, but the library - I'm not sure what has to be done to do that, but maybe these lines of thought help more - the "usual" thing for restricted execution was to provide it inside a otherwise fully working interpreter (like ZOPE). But I might be mistaken. Diez From steve at holdenweb.com Mon Aug 22 16:23:58 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 16:23:58 -0400 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> <7x8xyw2z17.fsf@ruckus.brouhaha.com> Message-ID: Robert Kern wrote: > Paul Rubin wrote: > >>Robert Kern writes: >> >> >>>>>http://www.catb.org/~esr/faqs/smart-questions.html >>>> >>>>Is it a *smart* way or *necessary* way? >>> >>>It's the polite way. And probably the only way you're going to get >>>your questions actually answered. >> >>I wonder if there's a way to killfile posts that contain that url. >>They are cluttering up the newsgroup much more than repeated newbie >>questions do. > > > You can get a good start by killfiling me. > *plonk* :-) > >>Sheesh people, if you see a question that you don't feel like >>answering, then don't answer. > > > Same goes to you. You don't like the "smart-questions.html" response, so > why do you respond? Because you want to change people's behavior. Or > perhaps because it pleases you to express your displeasure about it > (regardless of any effect that expression might have on other people). > > Coincidentally, those are exactly the reasons why I posted it in the > first place. I care not a whit about decluttering the newgroup, an > impossible task. > It's clear that you care not a whit about it. Unfortunately the only way to preserve bandwidth on this (or any other) chanell is for those with nothing to say to not say it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rafi at free.fr Mon Aug 15 15:23:16 2005 From: rafi at free.fr (rafi) Date: Mon, 15 Aug 2005 21:23:16 +0200 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: <4300eba6$0$7793$626a14ce@news.free.fr> Simon Brunning wrote: > On 8/15/05, Rocco Moretti wrote: > >>Which lead me to the question - what's the difference between a library >>and a framework? > > If you call its code, it's a library. If it calls yours, it's a framework. Trying to add my 2 cents (As I do not agree with the above sentence): You build applications "on top of / using" libraries while you build applications "in the context of" a framework. A framework is more like a piece of swiss cheese were you fill the holes. The framework provides an overall structure with particular rules for its use, while the library provide basic blocks that you may assemble in your own way (even if some constaints exist). -- rafi "Imagination is more important than knowledge." (Albert Einstein) From martin at v.loewis.de Wed Aug 10 04:01:04 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 10 Aug 2005 10:01:04 +0200 Subject: Adding and attribute to an instance In-Reply-To: <42F9AC1D.8020702@itga.com.au> References: <1123623524.732496.79460@g49g2000cwa.googlegroups.com> <42F9AC1D.8020702@itga.com.au> Message-ID: <42F9B440.9020402@v.loewis.de> Gregory Bond wrote: > Make sure you init this member to 0 (tp_init), and make sure you > PyXDECREF() it when the object is deleted (tp_dealloc). As this may cause your objects to appear in cycles, you may also have to add support for cyclic GC (unless you already did this before, and unless you can somehow rule out that your objects are in cycles). Regards, Martin From kay.schluehr at gmx.net Wed Aug 17 03:19:39 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 17 Aug 2005 00:19:39 -0700 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: <1124263179.916111.34960@g43g2000cwa.googlegroups.com> Simon Brunning wrote: > On 8/15/05, Rocco Moretti wrote: > > Which lead me to the question - what's the difference between a library > > and a framework? > > If you call its code, it's a library. If it calls yours, it's a framework. Pretty! I don't think it is an oversimplification. The crucial difference is that between interface and implementation. A framework forces the programmers code to conform certain interfaces and contracts. It does not restrict implementation in any way ( which might be empty ). The implementation part uses library functions that do not tell much about the implementation and nothing about interfaces. Libaries give you any freedom but sometimes ( and only sometimes ) people also like to structure their code ;) What are frameworks really good for - a very true success story. A colleague of mine used to spread all kinds of flags ( state- and property markers ) over the code that were used to glue everything together until I raised my tyranny of frameworks. It was a hard struggle for an OO warrier and took me almost a year or so to become the undebated projects architect/dictator who trashed all kind of misguided "freedom" ( i.e. bad code ): "What the fuck is this?" "I worked almost a week on it!" "It has to be reworked." "No, you don't do it!" I did it. Who claims that social life is easy? What is nice about this kind of cruelness is not only my colleague became finally happy and hopefully learned at least a little bit about programming but also our customers were gratefull about stable code, thight release schedules and just-in-time requirement dispatch. Now we have some bread-and-butter maintenance contract and true freedom to experiment with other more interesting things besides this. But the struggle just starts again with the new project ;) Kay From skip at pobox.com Wed Aug 10 12:37:26 2005 From: skip at pobox.com (skip at pobox.com) Date: Wed, 10 Aug 2005 11:37:26 -0500 Subject: Recommendations for CVS systems In-Reply-To: References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> Message-ID: <17146.11590.638488.565949@montanaro.dyndns.org> >> For a python newsgroup, you are required to consider mercurial. It's >> not ready for production use yet, but is making rapid progress, ... aahz> Why do you say "required" when the next sentence you say it's not aahz> ready for production? I believe "consider" != "adopt". Different people's needs are different, so the notion of how "production-ready" it has to be will vary. Skip From cantabile.03 at wanadoo.fr Mon Aug 8 11:39:34 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Mon, 08 Aug 2005 17:39:34 +0200 Subject: gettext again In-Reply-To: References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> Message-ID: <42f77cb6$0$25055$8fcfb975@news.wanadoo.fr> BTW stasz, Maybe you'll have still some time for the following question. Trying my luck :)) Suppose I have several units (.py files), say test.py test1.py tets2.py , test.py being my main file. I've read I can import gettext and install in the main unit. Then, must I create .po files for each unit or is there a way to make a single .po file for the whole app. ? From michele.simionato at gmail.com Mon Aug 22 02:42:49 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 21 Aug 2005 23:42:49 -0700 Subject: Decorator and Metaclasses Documentation In-Reply-To: References: Message-ID: <1124692969.769378.36690@g43g2000cwa.googlegroups.com> There are also my lectures at Oxford: http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_wondersofpython.zip Michele Simionato From kguan at corp.netease.com Fri Aug 12 00:22:17 2005 From: kguan at corp.netease.com (Kyo Guan) Date: Fri, 12 Aug 2005 12:22:17 +0800 Subject: How to Adding Functionality to a Class by metaclass(not by inherit) Message-ID: <20050812042235.EEFCB1E4005@bag.python.org> How to Adding Functionality to a Class by metaclass(not by inherit) #example: import inspect class Foo(object): def f(self): pass def g(self): pass class MetaFoo(type): def __init__(cls, name, bases, dic): super(MetaFoo, cls).__init__(name, bases, dic) for n, f in inspect.getmembers(Foo, inspect.ismethod): setattr(cls, n, f) #Bar want to achieve Foo's part/all functionality, but not by inherit class Bar(object): __metaclass__ = MetaFoo >>> b = Bar() >>> b.f() TypeError: unbound method f() must be called with Foo instance as first argument (got nothing instead) >>> Bar.f >>> b.f how can I set Bar.f as From mccutchen at gmail.com Fri Aug 19 16:17:25 2005 From: mccutchen at gmail.com (Will McCutchen) Date: 19 Aug 2005 13:17:25 -0700 Subject: Idempotent XML processing References: <2f66fb64f6cf531cca8b75576548283f@scl.ameslab.gov> Message-ID: <1124482645.617857.136700@g49g2000cwa.googlegroups.com> > Read up on XML canonicalization (abrreviated as c14n). lxml implements > this, also xml.dom.ext.c14n in PyXML. You'll need to canonicalize on > both ends before hashing. I said normalization but I think canonicalization is the word I was looking for. I wasn't aware that lxml implented it (or that it had an abbreviation), so that's good to know. Thanks! Will. From mwm at mired.org Thu Aug 25 23:59:31 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 25 Aug 2005 23:59:31 -0400 Subject: Static vs. dynamic checking for support of concurrent programming Message-ID: <8664ttmjq4.fsf@bhuda.mired.org> The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to help ensure correct behavior in a concurrent environment. That's impressive. That's *really* impressive. I know of no other language that does that - though they probably exist. I'd be interested in references to them. Normally, I think of static checking as something that's not critical, as a good test suite will cause exceptions on the things that static checking catches. But concurrency errors are a completely different class of critter entirely, and generally result in really nasty runtime errors. Which leads to the question - what would it take to get Python to throw exceptions in the cases where a compiler implementing SCOOP will emit an error message? There's two reasons for looking into this. One, wanting to continue to believe that static checking doesn't really buy anything. Two, wanting Python to have more powerful and robust tools for dealing with threads. If these can be made to work, then they're a candidate for addition. If not, then we need to look elsewhere. I'm not going to worry about how the semantics would be implemented at this point - I'm more interested in whether the static rules can be enforced in a dynamic environment. First, the rules. These are greatly simplified and mangled to describe a hypothetical Python-like language. If you want to see the formald definitions yourself, you can find them at . The new feature: a variable can be marked as "separate". This means the object it refers to is running on a different thread, and changes the semantics of accessing it in various ways: First, invoking a method and ignoring it's return value is run asynchronously. Likewise, an assigment to an attribute is run asynchronously. I'm going to call such actions a "command". Commands are queued by the object in question, and are guaranteed to run in the order they appear in the code. The execution order of the commands with respect to purely thread-local statements or commands on other separate objects is not guaranteed. Reading the value of an attribute is a synchronization point. All commands on the object will be execute before you are allowed to read the value of the attribute, and no following commands on the object will execute before the value is read. Note that this makes the Law of Demeter something your really want to pay attention to. Doing "so.addChild(newChild)" runs asynchronously, whereas doing "so.children.append(newChild)" causes a read of so.children, which will synchronize the object, then an update of children. Now, the constraints: 1) Any object assigned to a separate variable must really be separate. This applies to all the ways you can do an assignment. 2) The invocation of a command on a separate objects is only legal if the separate object is a formal argument of the enclosing function/method. The first one seems trivial, but avoids some nasty bugs. For instance, if you have a list of separate objects and you want to divide a workload up among them, you'd do something like: def divide(self, work, workers): for worker in workers: self.startWork(worker, work.getNextChunk) def startWork(self, separate worker, chunk): worker.process(chunk) Adding a deceleration seems to the the only way to handle this in Python. It's basically an assertion isinstance(object, Separate). startWork should throw an exception if it's called with an object that isn't separate. What happens if you call a routine with a separate object and the routine doesn't expect one? That's almost certainly bad - most functions expect all their statements to be executed in order. Does solving this requrie a check on every argument passed to a function to verify that it's not separate? The second rule is how locking is handled. If you invoke a function with one or more separate objects, the language processor waits until it has the locks on all the separate objects before running the body of the routine. This means that locking order when you need multiple locks is determined by the language processor, not the programmer, so you've eliminated locking order errors as a source of deadlocks. If you don't declare separate objects, then this would seem to require that every command be checked to see if it's on a separate object, and if so throw an exception if the object isn't a formal argument to the enclosing routine. If you have declarations and enforce them, you can limit the checks to objects declared separate. These solutions aren't very dynamic. Can anyone see how to do this without having to declare separate variables as such? Thanks, http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fakeaddress at nowhere.org Fri Aug 12 00:58:42 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 04:58:42 GMT Subject: MainThread blocks all others In-Reply-To: References: <42f9d4ef_2@news.isis.de> <42fa0457_2@news.isis.de> Message-ID: <60WKe.102$DV3.41@newssvr17.news.prodigy.com> Nodir Gulyamov wrote: > [...]I should show you real code [...] > Please find below real code. Sorry for amount of sources. Yeah, it's too much for me. Can you construct a minimal example that doesn't do what you think it should? -- --Bryan From hardikh2000 at yahoo.com Mon Aug 15 23:55:05 2005 From: hardikh2000 at yahoo.com (hardikh2000) Date: Tue, 16 Aug 2005 03:55:05 -0000 Subject: JOBs............JOBs............JOBs Message-ID: DON'T SEND YOUR CV TO ME PLEASE. DON'T SEND YOUR CV TO ME PLEASE. DON'T SEND YOUR CV TO ME PLEASE. 1 Windows NT or 2000 server 2 worked on active directory and exchange server 3 Unix/ Solaris/ HPUX/ AIX Admin 4 Exp in C++/VC++ 5 Exp in Operating system 6 Exp in Datastructure 7 Exp in SQL Query tuning 8 Exp in SQL Database 9 Exp in Datamodelling 10 EXP in Network Engineer 11 Technical expert 12 Technical Writer 13 Sales person 14 web designing 15 Other All Technical person Interested Candidates can send us your Updated CV with the following informations : 1.Present salary: 2.Expected Salary : 3.Notice Period : Also mention the post you are applying for. jobsexpert at yahoo.com jobsexpert at yahoo.com jobsexpert at yahoo.com Regards, JOBs Expert From lycka at carmen.se Mon Aug 22 04:22:21 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 22 Aug 2005 10:22:21 +0200 Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? In-Reply-To: References: Message-ID: Miernik wrote: > I noticed that all those files come in three "flavours": > *.py *.pyc *.pyo > > Is it possible that only one "flavour" of these files is needed, and I can > delete the remaining two, any my Python installation will still work? If you remove all *.pyc and *.pyo, they will be regenerated as needed. If your code only uses a small fraction of the standard library, you will save quite some space here. The only reason they are generated on installation is to save some runtime on first use of a module, and perhaps aviod the surprise of an installation that continues to grow after a completed installation... I'm not sure about this, but if you have plenty of RAM (you will trade HD noise for fan noise I guess) you might get the *.py[co] files to stay on a RAM disk. (If nothing else works, I guess you could have your system mirror your entire Python directory structure to RAM disk at boot time.) Then you should have a Python system which will get really fast once most modules have been recompiled--until you reboot... From renting at astron.nl Thu Aug 18 03:18:12 2005 From: renting at astron.nl (Adriaan Renting) Date: Thu, 18 Aug 2005 09:18:12 +0200 Subject: up to date books? Message-ID: I learned Python from the "Learning Python" book that's first on Alessandros list. If you have the Second Edition, that includes coverage for Python 2.3, I think you have quite a nice introductory book. As a reference book "Python in a Nutshell" and of course the Python documentation itself are quite good. Adriaan >>>Alessandro Bottoni 08/18/05 9:02 am >>> John Salerno wrote: >hi all. are there any recommendations for an intro book to python that >is up-to-date for the latest version? I do not know how much up-to-date they are but I have to suggest you these books: - Learning Python By Mark Lutz and David Ascher published by O'Reilly Most likely the best introductory book on Python - Python Cookbook By Alex Martelli and David Ascher published by O'Reilly By far the most useful book on Python after your first week of real use of this language Also, the fundamental - Programming Python (the 2nd edition ONLY) By Mark Lutz published by O'Reilly Is very useful for understanding the most inner details of Python >would reading a book from a year or two ago cause me to miss much? No. Python did not changed too much since rel. 1.5. You can still use a book published in 2001 as a introductory book (as I do). The changes are exhaustively described both in the official documentation and in the very fine "what's new in..." articles written by Andrew Kuchlin for every new release (see www.python.org). CU ----------------------------------- Alessandro Bottoni -- http://mail.python.org/mailman/listinfo/python-list From savvyside at aol.com Thu Aug 25 07:11:24 2005 From: savvyside at aol.com (michael) Date: Thu, 25 Aug 2005 11:11:24 GMT Subject: Doubt C and Python References: Message-ID: On Tue, 23 Aug 2005 06:15:03 +0100, praba kar wrote: > Dear All, > I want to know the link between c and python. > Some people with C background use Python instead > of programming in C.why? > > > > regards > Prabahar > > > > > > Just my $.02 I am a long time c/c++ programmer (by profession). I fell in love with python about 2 years ago. I use python for many things now, and I always have said, "When it is too slow, I will write it in c++". I have not hit that point yet. For some reasons that are hard to explain, even though python "should" be slower and maybe even is sometimes, it never is an issue. One reason is that python has so much better data structures built in, and THEY are written in C, I end up with faster code. For example, if I am doing a bunch of string compares in C, I would use a dictionary in python. Python ends up faster because I can get to a better algorithm FASTER. The other reason is that so many times, a hardware I/O device is really the limiting factor (such as a hard disc, or a serial/network connection, or waiting for the user). I have found that GUI programs written in python/wxpython to be every bit as fast as pure C++. I guess you could say that because the LIBRARIES of python are in C, and because you are never very far from a library call, you end up running C code a large percentage of the time, even when you are writing in Python. My advice is to just TRY python and resolve the "slow" speed if you ever hit it. I never have and I write a lot of code, even hardcore math and image processing (See PIL - python Imaging Library). Michael From zen19725 at zen.co.uk Fri Aug 26 16:50:24 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Fri, 26 Aug 2005 21:50:24 +0100 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> Message-ID: On Thu, 25 Aug 2005 00:56:10 -0400, Mike Meyer wrote: >> The issue here is whether to confuse reality with what one might >> wish reality to be. > >Let's see. Reality is that writing correct programs is hard. Writing >correct programs that use concurrency is even harder, because of the >exponential explosion of the order that operations can happen >in. Personally, I'm willing to use anything I can find that makes >those tasks easier. Indeed so. Use threading (or whatever) when one has to, use an asynchronous single-threaded process whenever you can. -- Email: zen19725 at zen dot co dot uk From berlin.brown at gmail.com Sat Aug 20 13:51:02 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Sat, 20 Aug 2005 13:51:02 -0400 Subject: Python Light Revisted? Message-ID: <6Jydnde_uvYa8JreRVn-gw@comcast.com> This is kind of funny, I posted earlier about a small, light python distro. The thing is, I did it in an hour or so, but amazingly, I got responses from everywhere asking for support on how to do this. To be honest, I don't have the time to investigate it more. My point, there seems to be a lot of interest for a lightweight python app, but no real resources on how to do it? The goal, build python(mainly for win32) so that the ENTIRE install is maybe less than 5MBs and includes possibly a GUI library, possibly TwistedMatrix, possibly install from just unzipping an archive like applications such as Eclipse. So, my question, has anybody done this similar to what I did? I can show you how I did it, but it was so quick, I didnt really think about what libraries I included. There are mini linuxes out there, I suggest mini pythons. Why? For example, I don't need an XML-RPC library, or zip library, or the other libraries. http://newspiritcompany.com/blog/article/167/python-lightweight-at-2mb-for-win32 -- Ramza from Atlanta http://www.newspiritcompany.com From rkern at ucsd.edu Fri Aug 5 01:51:15 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 04 Aug 2005 22:51:15 -0700 Subject: >time.strftime %T missing in 2.3 In-Reply-To: References: Message-ID: Andy Leszczynski wrote: > Python 2.2/Unix > > >>time.strftime("%T") > '22:12:15' > >>time.strftime("%X") > '22:12:17' > > Python 2.3/Windows > > >>time.strftime("%X") > '22:12:47' > >> time.strftime("%T") > '' From http://docs.python.org/lib/node252.html """The full set of format codes supported varies across platforms, because Python calls the platform C library's strftime() function, and platform variations are common.""" So I suggest that it's a platform issue, not a Python version issue. FWIW: Python 2.4.1 (#2, Mar 31 2005, 00:05:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.strftime("%T") '22:50:49' >>> time.strftime("%X") '22:50:59' -- 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 hancock at anansispaceworks.com Sun Aug 28 15:11:34 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sun, 28 Aug 2005 14:11:34 -0500 Subject: What are new-style classes? In-Reply-To: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> Message-ID: <200508281411.34576.hancock@anansispaceworks.com> On Sunday 28 August 2005 04:47 am, Vaibhav wrote: > I recently heard about 'new-style classes'. I am very sorry if this > sounds like a newbie question, but what are they? I checked the Python > Manual but did not find anything conclusive. Could someone please > enlighten me? Thanks! "New style" classes are becoming the standard in Python, and must always be declared as a subclass of a new style class, including built-in classes. The simplest is "object", so the simplest newstyle class is: class no_class(object): pass as opposed to the simplest "old style" object which didn't inherit at all: class really_no_class: pass I would regard the latter as deprecated now, since it basically doesn't buy you anything to use it. The only reason to hang on to old style classes would seem to be to avoid breaking older code that relied on details such as the order of multiple inheritence, which have changed. So if you're just learning, just use new style classes exclusively, and use the documentation that applies to them. I think it's fairly non- controversial that new style classes are an improved design. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From oriana.falco at thalesesec.com Mon Aug 22 12:24:06 2005 From: oriana.falco at thalesesec.com (oriana.falco at thalesesec.com) Date: 22 Aug 2005 09:24:06 -0700 Subject: How to print the name of a list? Message-ID: <1124727846.909693.129750@g43g2000cwa.googlegroups.com> Hi! I was wondering what can I do to print the name of a list that is inside a list. For example: exported = ['123','456'] imported = ['789','012'] client1 = ['cl1b','cl1a'] client2 = ['cl2a','cl2b'] host = ['imported','exported'] client = ['client1','client2'] list = ['host', 'client'] My goal is to print a string that reads: 'host imported 789' ...and subsequently print more strings that read: 'host imported 012' 'host exported 123' 'host exported 456' ..... Thanks in advance for the help.... Oriana From ed at leafe.com Mon Aug 1 08:17:29 2005 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Aug 2005 08:17:29 -0400 Subject: Wheel-reinvention with Python In-Reply-To: <7x3bpuxtwa.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <7x3bpuxtwa.fsf@ruckus.brouhaha.com> Message-ID: <200508010817.29171.ed@leafe.com> On Sunday 31 July 2005 22:39, Paul Rubin wrote: > > import dabo > > app = dabo.dApp() > > dApp.start() > > > > ?Sorry, I couldn't do it in 5. ?;-) Oh, and that includes a full menu, > > too. > > I get an ImportError exception when I try that. ?Any suggestions? ?Note > that I don't get that exception from Tkinter. > ? ? bash-3.00$ python > ? ? Python 2.3.4 (#1, Oct 26 2004, 16:42:40) > ? ? [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 > ? ? Type "help", "copyright", "credits" or "license" for more information. > ? ? >>> import dabo > ? ? Traceback (most recent call last): > ? ? ? File "", line 1, in ? > ? ? ImportError: No module named dabo > ? ? >>> import Tkinter > ? ? >>> Oh, c'mon now Paul, now you're trolling. You know exactly what the problem is, and try to make it look like a bug. Fine: you don't want to use anything that doesn't come standard with Python. You've made your point. We get it. There is no need to repeat yourself constantly. The only point of my post was that for those without your aversion to installing useful tools, Dabo provides a ton of functionality. Also, as my partner Paul McNett pointed out, I could have done it in *two* lines: import dabo dabo.dApp().start() ;-) -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From sklass at pointcircle.com Mon Aug 29 16:36:36 2005 From: sklass at pointcircle.com (rh0dium) Date: 29 Aug 2005 13:36:36 -0700 Subject: Using select on a unix command in lieu of signal Message-ID: <1125347796.648556.282610@g43g2000cwa.googlegroups.com> Hi all, Another newbie question. So you can't use signals on threads but you can use select. The reason I want to do this in the first place it I need a timeout. Fundamentally I want to run a command on another machine, but I need a timeout. I have to do this to a LOT of machines ( > 3000 ) and threading becomes necessary for timeliess. So I created a function which works with signals ( until you throw threading at it.. ) but I can't seem to modify it correctly to use select. Can some select ( pun intended ) experts out there point out the error of my way.. Not working RunCmd using select def runCmd( self, cmd, timeout=None ): starttime = time.time() child = popen2.Popen3(cmd) child.tochild.write("\n") child.tochild.close() child.wait() results = [] results = "".join(child.fromchild.readlines()) endtime = starttime + timeout r, w, x = select.select(results, [], [], endtime - time.time()) if len(r) == 0: # We timed out. prefix = ("TIMED OUT:" + " " * maxlen)[:maxlen] sys.stdout.write(prefix) space = "" os.kill(child.pid,9) child.fromchild.close() return results Working RunCmd using signal def handler(self, signum, frame): self.logger.debug("Signal handler called with signal %s" % signum) def runCmd( self, cmd, timeout=None ): self.logger.debug("Initializing function %s - %s" % (sys._getframe().f_code.co_name,cmd) ) # Set the signal handler and a 5-second alarm signal.signal(signal.SIGALRM, self.handler) signal.alarm(timeout) try: child = popen2.Popen3(cmd) child.tochild.write("y\n") child.tochild.close() child.wait() results = "".join(child.fromchild.readlines()) out = child.fromchild.close() self.logger.debug("command: %s Status: %s PID: %s " % (cmd, out, child.pid)) if out is None: out = 0 except: self.logger.warning( "command: %s failed!" % cmd) kill = os.kill(child.pid,9) self.logger.debug( "Killing command %s - Result: %s" % (cmd, kill)) out = results = None signal.alarm(0) # Disable the alarm return out,results Thanks much - Alternatively if anyone else has a better way to do what I am trying to get done always looking for better ways. I still want this to work though.. From timh at zute.net Mon Aug 22 19:41:40 2005 From: timh at zute.net (Tim Hoffman) Date: Tue, 23 Aug 2005 07:41:40 +0800 Subject: Python Light Revisted? In-Reply-To: References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: <430a62b5@news.highway1.com.au> Ramza Brown wrote: > Steve M wrote: > >> > Also, py2exe will work '100%' without a host python install. I have > never used it. I have my doubts though? > Yes it sure does. I have distributed at least 3 different standalone python programs using py2exe and I can absolutely garuntee that the people running them do not have a seperate python install. T From manojkumar_net at rediffmail.com Thu Aug 4 09:25:30 2005 From: manojkumar_net at rediffmail.com (manojkumar_net at rediffmail.com) Date: 4 Aug 2005 06:25:30 -0700 Subject: QFileDialog Message-ID: <1123161930.563831.66420@z14g2000cwz.googlegroups.com> I am using windows Qt3.3.4 and want to verify the selected file path on pressing the OK button of File Dialog. After checking I don't want to close the QFileDialog. Can anyone tell me how to stop closing the FileDialog after checking the file path on pressing ok button. From ed at leafe.com Mon Aug 1 09:35:48 2005 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Aug 2005 09:35:48 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <1122902924.784086.179440@o13g2000cwo.googlegroups.com> References: <1122902924.784086.179440@o13g2000cwo.googlegroups.com> Message-ID: <200508010935.48607.ed@leafe.com> On Monday 01 August 2005 09:28, Harald Armin Massa wrote: > it is not that you use twisted, but > you provide twisted with callbacks so that it uses you? +1 QOTW -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From steve at holdenweb.com Fri Aug 19 05:21:45 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Aug 2005 10:21:45 +0100 Subject: how do i add a new path into sys.path? In-Reply-To: References: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> Message-ID: <4305A4A9.1080705@holdenweb.com> James Sungjin Kim wrote: > Steve Holden wrote: > >>sys.path.append(r"C:\Temp") > > > In this case, do I need to save the refined path, i.e, the original > paths + the new path (r"C:\Temp"), by using some command in order to use > it permanently. if yes, it would be greatly appreciated to noitce the > correspoding command and the usage of it. > > -James The method I outlined works only for the duration of a single program run, because the sys.path variable is set up each time you run the Python interpreter. You need to look at the suggestions you've had for setting the PYTHONPATH environment variable to effect changes to all future Python execution. Essentially this is most usually done in the "My Computer -> Properties" dialog: click the "environment variables" button and create a new (all-users or private, depending on your needs) environment variable called PYTHONPATH containing a semicolon-separated list of directories the interpreter should add to the path. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pydecker at gmail.com Thu Aug 11 17:51:47 2005 From: pydecker at gmail.com (Peter Decker) Date: Thu, 11 Aug 2005 17:51:47 -0400 Subject: Python Wireless Extension Module (pyiw) In-Reply-To: <1123794171.4559.15.camel@localhost.localdomain> References: <1123794171.4559.15.camel@localhost.localdomain> Message-ID: On 8/11/05, Jeremy Moles wrote: > Anyway, I am just curious... we plan on using it, at any rate. It's > already made the code easier to read, faster, and more reliable. Looks pretty useful to me! -- # p.d. From bill.mill at gmail.com Thu Aug 25 13:30:32 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 25 Aug 2005 13:30:32 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: <797fe3d405082510307db4a76e@mail.gmail.com> On 8/25/05, Mark Dickinson wrote: > I have a simple 192-line Python script that begins with the line: > > dummy0 = 47 > > The script runs in less than 2.5 seconds. The variable dummy0 is never > referenced again, directly or indirectly, by the rest of the script. > > Here's the surprise: if I remove or comment out this first line, the > script takes more than 15 seconds to run. So it appears that adding a > redundant line produces a spectacular six-fold increase in speed! > > (Actually, I had to add 29 dummy lines at the beginning of the code to > get the speed increase; if any one of these lines is removed the > running time reverts to around 15 seconds again.) > > Questions: One of my own: what in the world made you think "maybe I'll add 29 dummy global variables to speed things up?" It seems to work (>19x speedup on my machine), I'm just curious what path you followed to get there. And, finally, you should forward this to the python-dev list, if somebody hasn't already. There are more people who know a ton about python internals there. Peace Bill Mill bill.mill at gmail.com From ms at cerenity.org Sun Aug 28 12:02:34 2005 From: ms at cerenity.org (Michael Sparks) Date: Sun, 28 Aug 2005 17:02:34 +0100 Subject: Socket Troubles References: <0ndQe.259$DV.23@trndny07> Message-ID: <4311dff6$0$22907$ed2619ec@ptn-nntp-reader01.plus.net> Chris Spencer wrote: > My code's ... at http://deadbeefbabe.org/paste/1525/0 ... > I've written a simple class to manage P2P socket connections. However, > whenever I try to receive data, the socket raises an exception with the > error message (11, 'Resource temporarily unavailable'). At one point in your code you do this: self._socket.setblocking(0) This says "if we can't recieve or send data without blocking, fail rather than succeed". One of the failure modes is to return error 11. This is infact normally defined as: #define EAGAIN 11 /* Try again */ What this means is "sorry, I couldn't do this without blocking right now, try again very shortly!". Looking at your code it continually loops (in BaseConnectionHandler_recv) receiving data - whether or not there's any data to receive: def _recv(self): while self.running: try: data = self._socket.recv(4096) if not len(data): time.sleep(0.1) continue except Exception, e: log('Recieve failed for handler',self.address,'because of',e) break Since you never actually check to see if the socket is ready to give you data, and you've set it non-blocking, seeing lots of EAGAIN errors is pretty much what you'd expect to see. (Simply sleeping is not sufficient!) I suppose the short answer though really is this: you set the socket non-blocking, you should therefore expect to see failures telling you to try again, and follow their advice! :) Regards, Michael. From thomas.weholt at gmail.com Sun Aug 7 12:11:04 2005 From: thomas.weholt at gmail.com (Thomas W) Date: 7 Aug 2005 09:11:04 -0700 Subject: WSGI-server in the standard distro? Message-ID: <1123431064.919065.10780@o13g2000cwo.googlegroups.com> Will there be a WSGI-server like BaseHTTPServer etc in the standard distro? I think that would increase the adoptation of the WSGI-standard. A new web-framework for python pops up every other week and more and more support WSGI. Why not focus on getting an optimized, production-grade fully documented WSGI-server into the distro? Right now the BaseHTTPServer seems to be usable for development and testing, not production environment. Perhaps if there was allready a working WSGI-server in the distro we could focus on that being ready for real heavy-loads in production environment instead of making a WSGI-server for each and every web-framework available ( CherryPy and Django each got their own WSGI-server written in python, think Twisted has one as well, but they all claim it's only suitable for testing/development.). The problem is perhaps the threads vs select ( vs fork? ) discussion/war?? If the distro contained a working thread-based WSGI-server the select/twisted-camp wouldn't use it anyway? The beauty of python is that it comes "with batteries included", with servers for CGI, HTML etc. but it doesn't seem like these are ready for real work. I don't care if some parts of the server has to be done in C for speed reasons, but it's bummer to allways have to install Apache to get a production-ready environment. Having a HTTP1.0/1.1-compliant production-grade WSGI-only server in the distro would be sweet :-) I might be demanding a bit much here, but still ... Any thoughts? Anyhow, even a test/development-only WSGI-server implementation should be in the standard distro IMHO. Thomas From me at privacy.net Sat Aug 6 21:40:52 2005 From: me at privacy.net (Dan Sommers) Date: Sat, 06 Aug 2005 21:40:52 -0400 Subject: Does FTPLIB have a 'local change directory' ? References: <3tdJe.1566$Z87.303@newssvr14.news.prodigy.com> Message-ID: On Sun, 07 Aug 2005 01:28:31 GMT, "python newbie" wrote: > I'd like to be able to first > ftplib.lcd( "c:\myfiles\morefiles" ) > and then just > storbinary( picture.gif .. ). > But the python doc doesn't show any LCD. Try os.chdir. HTH, Dan -- Dan Sommers From steve at holdenweb.com Tue Aug 30 13:35:44 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Aug 2005 12:35:44 -0500 Subject: variable hell In-Reply-To: References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> Message-ID: Fredrik Lundh wrote: > Steve Holden wrote: > > >>Yes. A large part of learning a language is discovering the many idioms >>that have already been established for doing certain things. These are a >>kind of shorthand, established by long convention, that allow one to >>avoid the "learning-by-use" curve. > > > it's not obvious that the OP has found the pydiomatic way to solve > his problem, though, given that most of this thread have been spent > on playing with exec, and that Robert Kern's question from the be- > ginning of this thread has still not been answered: > > "Again, why unpack them into separate variables when they are *already* > in the form that you want to use them?" > Fair enough. I was trying to advocate the use of the suggested idioms, but some people seem to insist on going their own way even when it leads to a collision wiht a bricj wall. You can lead an idiot to idioms, but you can't make him think ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From peter at engcorp.com Fri Aug 19 08:39:08 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 19 Aug 2005 08:39:08 -0400 Subject: Python on Palm?? In-Reply-To: <0001HW.BF2B7696000D3BB3F0407550@news.individual.de> References: <0001HW.BF2B7696000D3BB3F0407550@news.individual.de> Message-ID: Kalle Anke wrote: > Is there some implementation of Python that runs on Palm OS? > > I've found "Python to Palm Pilot Port" > and Pippy > which both seem to be based on Python > 1.5 > > Is there some implementation that implements later versions of Python? This is asked fairly frequently, and you can easily search the list archives using Google Groups to see more detailed answers than the following one: If you want to write real Palm applications (i.e. which have access to features provided by the operating system such as PDB files or GUI elements), the answer is "no, not yet, though people are still working on very early phases of projects that might someday get there". My personal advice after saying that is to investigate Plua (Palm version of Lua) which does provide pretty good access to the Palm OS and which has a similar enough feel to Python that I don't mind using it. -Peter From achrist at easystreet.com Mon Aug 8 00:00:55 2005 From: achrist at easystreet.com (Al Christians) Date: Sun, 07 Aug 2005 21:00:55 -0700 Subject: IronPython 0.9 Released In-Reply-To: References: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> Message-ID: <11fdm9caa2p3h84@corp.supernews.com> EP wrote: > > yes, my apologies to all things Iron and or Python. > > "language" and "version" can be confusing if one stays up late without coffee, or perhaps if one has not been debugging their English code properly. > Still, it's a bit of a PITB to me that it says XP and not Win2000. Al From fredrik at pythonware.com Wed Aug 31 14:15:15 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 20:15:15 +0200 Subject: aggdraw for PIL References: <1125510410.873991.285330@g47g2000cwa.googlegroups.com> Message-ID: Adam Endicott wrote: > Does anyone know anything about the aggdraw module for PIL? I think I > would like to use it because I need to do some drawing with > semi-transparent pen styles (I'm simulating using a highlighter). It > seems to be working great, but I think I'm running into a memory leak > that's noted in the documentation at > http://effbot.org/zone/pythondoc-aggdraw.htm#aggdraw.Draw-class > > "Note: The Draw(im) form leaks memory in aggdraw 1.1b1 and earlier. > Don't use this form in long-running program that creates multiple > drawings. The memory leak has been fixed in release 1.1b2." as a workaround, you can use the original constructor syntax instead, together with fromstring/tostring: d = Draw(im.mode, im.size) d.fromstring(im.tostring()) # draw your stuff im.fromstring(d.tostring()) > Sounds good, except I can't find 1.1b2 anywhere. Is it not released > yet? If so, does anyone know when it might be released? it has been delayed, but it should appear within a week or two. From gapp127 at hotmail.com Tue Aug 9 22:40:43 2005 From: gapp127 at hotmail.com (Aubrey Limerick) Date: Tue, 09 Aug 2005 22:40:43 -0400 Subject: problem with email Message-ID: everytime i log in to my email another site keeps popping up. the same site _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From sybrenUSE at YOURthirdtower.com.imagination Sat Aug 27 07:22:16 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Sat, 27 Aug 2005 13:22:16 +0200 Subject: Virtual Slicing References: Message-ID: Bryan Olson enlightened us with: > I recently wrote a module supporting value-shared slicing. Maybe I'm dumb, but could you explain this concept? Why would someone whant this? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From tjreedy at udel.edu Sat Aug 6 19:28:13 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 6 Aug 2005 19:28:13 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <42F4F2D3.80804@tiscali.it> Message-ID: "Paolino" wrote in message news:42F4F2D3.80804 at tiscali.it... > seberino at spawar.navy.mil wrote: > I don't think the global keyword is useful actually. > What's so special in a module nemespace to be priviledged like that. The specialness of globals and locals was part of Python's original simple namespace design, and is still reflected in exec statements and eval functions, as well as in nested functions. > The point IMO is accessing names defined somewhere in the enclosing > namespaces. Accessing such names is already possible, even *after* the outer function returns and the rest of its execution context is deleted. > def enclosing(): > var=2 > def enclosed(): > outer var=4 This is rebinding, rather than merely accessing. Similar, but even more problematical would be initial binding in outer from inner: def enclosing(): def enclosed(): outer var = 4 > this is the base of something useful. Actually, it is the reinvention of classes: class enclosing(object): def __init__(self): self.var = 2 def enclosed(self): self.var = 4 There was a long discussion on the pydev list a couple of years ago re adding rebinding in addition to access (of outer variables). I think, in the end, Guido concluded that there was no compelling reason, as of then, to add another general mechanism for private, sharable, rebindable variables. > I think there is only one or none possible solution to an outer statement There were lots of proposals for both the exact syntax and semantics of outer binding/rebinding. Terry J. Reedy From kay.schluehr at gmx.net Sat Aug 6 16:55:26 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 6 Aug 2005 13:55:26 -0700 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> Message-ID: <1123361726.592449.282750@o13g2000cwo.googlegroups.com> John Roth wrote: > Another thing that stands out: the explicit versus dynamic typing debate > has moved on from program correctness (which is a wash) to > other areas that explicit (or derived) type information can be used > for. I see this in PyFit: the languages where explicit type information > is available by reflection have cleaner implementations. What makes myself a fat and lazy Pythonista is simply motivated by not wanting Guido throwing any language feature that someone found accidentally in another language into Python. My personal attitude is that I have enough self-confidence that I can live with just the second most popular programming language in the world. And maybe I'm also fat because I like to feed myself ( my topics of interest ) and not people with consumerist attitudes. So you have recognized that dynamic languages don't support type reflections well. Surprise, surpise! Other wellinformed authors like Benjamin Pierce wouldn't even agree about Python as being typed but dynamically *tagged*. Now what do you recommend? Sacrificing __delattr__, __setattr__, decorators and metaclasses for having colorcoding editors and a Java-like language with indentation syntax? What do you believe to ensure with type-declarations extracted by tools in presence of magic methods that enable to rewrite your class on the fly? Of course some things become harder in Python because they are impossible to guarantee in general. The PyPy team spends a lot of effort in exploring the boundary between what can be inferred from Python code and translated into lower level languages before program execution and what has to be passed to some code specializer at runtime. That's where new insights about dynamic languages may come from. Kay PS. I don't have anything against Ruby. May it have many cheerleaders! It's just that Haskell is on top of my list of interesting PLs I didn't devote much time yet and Ruby is far away. From spam.csubich+block at block.subich.spam.com Wed Aug 10 14:08:25 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 10 Aug 2005 14:08:25 -0400 Subject: Does any one recognize this binary data storage format In-Reply-To: References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> <42f98255@news.eftel.com> <11fk0kg65rtfn72@corp.supernews.com> Message-ID: Calvin Spealman wrote: > > Original Poster should send this off to thedailywtf.com I absolutely agree. This is a terrible programming practice. From gene.tani at gmail.com Tue Aug 2 07:03:11 2005 From: gene.tani at gmail.com (gene tani) Date: 2 Aug 2005 04:03:11 -0700 Subject: Newer than a Newbe In-Reply-To: <42ef4563$0$7841$626a14ce@news.free.fr> References: <42ef4563$0$7841$626a14ce@news.free.fr> Message-ID: <1122980591.835483.276830@g43g2000cwa.googlegroups.com> Truthfully, the number of frameworks is staggering, tho some are specialized for blogs/wiki, search engine, PIM, etc. http://www.colorstudy.com/docs/shootout.html http://pythonology.org/howto http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=Web http://www.awaretek.com/tutorials.html#web http://www.personal.psu.edu/staff/i/u/iua1/python_reviews.html http://subway.python-hosting.com/ http://snakelets.sourceforge.net/ http://www.cherrypy.org/ http://spyce.sourceforge.net/ http://www.mems-exchange.org/software/quixote/ http://mail.python.org/pipermail/medusa-dev/2003/000843.html http://www.awaretek.com/tutorials.html#firedrop http://www.webwareforpython.org/ http://wiki.webwareforpython.org/thiswiki.html http://moinmoin.wikiwikiweb.de/ http://webservices.xml.com/pub/a/ws/2003/05/13/email.html http://www.oreillynet.com/pub/au/1099 http://www.divmod.org/Home/Projects/Lupy/ From rkern at ucsd.edu Thu Aug 4 02:28:11 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 03 Aug 2005 23:28:11 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <42F1B2DA.9070802@ulmcnett.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <86zms0ex85.fsf@bhuda.mired.org> <86acjzetfw.fsf@bhuda.mired.org> <86ek9a1ecf.fsf@bhuda.mired.org> <42F1B2DA.9070802@ulmcnett.com> Message-ID: Paul McNett wrote: > Mike Meyer wrote: > >>Mike Meyer writes: >> >>>>I think you'll find that wxPython installs perfectly on Tiger using >>>>the package provided. Indeed, the only really painful platform to >>>>install wxPython on is Linux, where you pretty much need to build from >>>>source if you want the latest and greatest. >> >>FWIW, Tiger ships with wxPython pre-installed. > > Yes, but it's an older version... isn't it 2.4? 2.5.something.pretty.close.to.2.6.but.not.quite. -- 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 accepted at ukr.net Mon Aug 1 13:14:51 2005 From: accepted at ukr.net (Michael Rybak) Date: Mon, 1 Aug 2005 20:14:51 +0300 Subject: need for speed In-Reply-To: References: <1122888516.815400.116220@f14g2000cwb.googlegroups.com> Message-ID: <3427422000.20050801201451@ukr.net> SDA> On Mon, 01 Aug 2005 02:28:36 -0700, borges2003xx at yahoo.it wrote: >> hi everyone >> can someone suggest me where find a lot programming tricks for >> achieving the top speed in python? SDA> There is only one programming trick you need to know about making code run SDA> fast. SDA> Never even waste one second on optimising code before it is working, SDA> or before you have tested it and profiled it and know (1) that it IS slow; SDA> and (2) WHERE it is slow. SDA> Why would you waste your valuable time making bugs run faster? Why waste SDA> time and effort to speed up something that is already fast enough? SDA> In other words: Make your code work. Make it work right. Then, and only SDA> then, make it run fast -- and only if it isn't already fast. SDA> Now that you have written your code, and you have made it work right, SDA> please tell us what the code is, and the results of profiling the code, SDA> and we will help you speed it up. Is there a way of profiling other than manual (debug output with measurements and all)? Some tools? And is there some kind of plugin for native Python's IDLE to trace scripts? I'm a bit tired of getting all info from debug output and exceptions SDA> -- SDA> Steven -- Best Regards, Michael Rybak mailto:accepted at ukr.net From mwm at mired.org Tue Aug 16 22:34:19 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 16 Aug 2005 22:34:19 -0400 Subject: open links in a html page References: <1124203925.920385.209450@f14g2000cwb.googlegroups.com> Message-ID: <86acjh2swk.fsf@bhuda.mired.org> "Ajar" writes: > Hi, > > Using urllib2,ClinetForm and ClinetCookie modules I have logged into my > ISPs web site and managed to fetch the first page. Now, on this page > there is this link: > > Service > Records > > I need to click this link from python code. How do I do it? check(4) is > the following javascript function: On way is to have a JavaScript interpreter in your Python program. Including correctly implementing the DOM to get your sample right. > ------------------------------------------------------------------------------- > > function check(parameter){ > if(parameter==1){ > parent.frames(0).location.href="userinfo.jsp" + "?" + new > Date().toString(); > }else if(parameter==2){ > parent.frames(0).location.href="modipswd.jsp" + "?" + new > Date().toString(); > }else if(parameter==3){ > parent.frames(0).location.href="cardrecharge.jsp" + "?" + > new Date().toString(); > }else if(parameter==4){ > parent.frames(0).location.href="serviceRecords.jsp" + "?" + > new Date().toString(); > }else if(parameter==5){ > parent.frames(0).location.href="rateSelectResult.jsp" + > "?" + new Date().toString(); > } > else if(parameter==6){ > parent.frames(0).location.href="stopService.jsp" + "?" + > new Date().toString(); > } > else if(parameter==7){ > if (confirm("Are you sure to exit?")){ > window.location="../logout.jsp"; > return true; > }else{ > return false; > } > }else if(parameter==8){ > parent.frames(0).location.href="cancelService.jsp" + "?" + > new Date().toString(); > }else{ > return false; > } The other alternative is to translate the above into Python, and run that code. JavaScript lets you do some really cool effects. It pretty much sucks for any program that wants to read the page, though - your parser, search engines, etc. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve at holdenweb.com Wed Aug 31 17:40:48 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Aug 2005 16:40:48 -0500 Subject: Calling ftp commands from python In-Reply-To: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> References: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> Message-ID: Thierry Lam wrote: > Is it possible to run an ftp command to connect to some remote computer > on the network. > > For example, if I want to retrieve some data from > \\remcomputer\datafiles on the network and copy it to my local > computer, how do I do it in python on the Unix side? > > I don't want to use mount since I don't have permission. > > Thanks > Thierry > http://www.holdenweb.com/Python/PDCode/ftpStream.py shows you how to drive a remote FTP server using an object-oriented approach. Don;t know whether it'll help. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From paolo_veronelli at tiscali.it Mon Aug 1 19:10:38 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 02 Aug 2005 01:10:38 +0200 Subject: namespaces In-Reply-To: <7x3bpvxlsr.fsf@ruckus.brouhaha.com> References: <42EC9690.2040301@tiscali.it> <7x3bpvxlsr.fsf@ruckus.brouhaha.com> Message-ID: <42EEABEE.803@tiscali.it> Paul Rubin wrote: > Paolino writes: > >>What I'm needing as a global (in globals() or at the module level or >>in the module namespace) is 'translate'.The rest of bindings >>(all,badcars and table) is something which is 'polluting' the module >>namespace. > > > do you want > __all__ = ['translate'] > ? No I don't want to use another feature of the module namespace. Well: good to know there is a hack in every corner.My point is now to understand similarities in python namespace types and why they present a different interface. What I notice is the '.' operator is used to switch to an inside namespace ,until an attribute is found.Can I assume this is a rule? Thanks anyway Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From dan at cellectivity.com Tue Aug 9 13:00:52 2005 From: dan at cellectivity.com (Dan) Date: Tue, 09 Aug 2005 18:00:52 +0100 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: <312cfe2b05080909324b1929db@mail.gmail.com> References: <312cfe2b05080909324b1929db@mail.gmail.com> Message-ID: <1123606852.25322.13.camel@localhost.localdomain> > Does that mean Python functions aren't always byref, > but are sometimes byval for nonmutables? Don't think of it as byref or byval (as they are used in Visual Basic). All parameters are passed the same way: by reference instead of by copy. It's a little difficult to get your head around, but I promise that once you understand it it will seem simple and intuitive. def reassign(x): x = ['foo'] "reassign" has no effect, even on a mutable type like a list. It simply changes what "x" refers to, which isn't very useful because the name "x" only exists inside the function. In Python everything is treated the same way. Even integers are objects: >>> n = 1 >>> n.__hex__() '0x1' What other programming languages do you know? Maybe we can draw a comparison to something you're familiar with. -- Presumably, we're all fully qualified computer nerds here, so we are allowed to use "access" as a verb. Be advised, however, that the practice in common usage drives English-language purists to scowling fidgets. - from Sybex's "Perl, CGI and JavaScript", p. 256 From cam.ac.uk at mh391.invalid Mon Aug 8 14:01:26 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Mon, 08 Aug 2005 19:01:26 +0100 Subject: Is there a better/simpler logging module? In-Reply-To: <5VKJe.9469$HM1.273456@twister1.libero.it> References: <5VKJe.9469$HM1.273456@twister1.libero.it> Message-ID: Alessandro Bottoni wrote: > I just tried to use the python standard logging module in a small program > and I found myself lost among all those features, all those configuration > options and so on. If you don't want to mess with all this stuff it's easy enough to do: import logging logging.warning("my warning") logging.debug("debug message") The configuration options are strictly optional. Personally I use a package I wrote called autolog, which sets up configuration from a dot-file in the home directory if it exists, and a basic logger for each module automagically. And it does this all using the stdlib logging module. :) -- Michael Hoffman From Scott.Daniels at Acm.Org Fri Aug 12 14:08:22 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 12 Aug 2005 11:08:22 -0700 Subject: simpli int/str problem In-Reply-To: References: <8c05f79c05081207443094dc67@mail.gmail.com> Message-ID: <42fcd9ee$1@nntp0.pdx.net> Paolino wrote: > sinan . wrote: > >> hi all, >> i have a string and int values in same dictionary like this >> dict = {'str_name': 'etc' , 'int_name' : 112 } Bad idea to call this "dict" -- that is a system-defined name for the dictionary type. I'll use "holder" below. >> the error occures when do this >> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + dict['str_name'] + "', >> '" + dict['int_name'] + "')" ^^ I suspect this should be: SQL = "INSERT INTO TABLENAME(AH, BH) VALUES (... >> cursor.execute(SQL) >> python does not accep dict['int_name'] in SQL variable but when i >> convert this variable to the str , python accepts but i cannot insert >> that into database because database only accept int in `BH ` >> thanks. > Try use: > SQL = "INSERT INTO (`AH`, `BH` ) VALUES > ('%s,%d)"%(dict['str_name'],dict['int_name']) This will work, but the DB interface allows you to leave the variable formatting to it. Depending on the parameter style your DB interface supports, you may use at least one of: cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(?, ?)", [(holder['str_name'], holder['int_name'])]) or cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(:1, :2)", [(holder['str_name'], holder['int_name'])]) ### I think, it _might_ be ...(0, :1)", or cursor.execute("INSERT INTO TABLENAME(AH, BH) " "VALUES(:str_name, :int_name)", holder) --Scott David Daniels Scott.Daniels at Acm.Org From jonhewer at gmail.com Wed Aug 3 03:58:28 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Wed, 3 Aug 2005 08:58:28 +0100 Subject: Ideas for Python project? In-Reply-To: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: Hi I'm pretty new to Python, and recently been working my way through Dive Into Python, and I'm currently writing a really simple rss reader purely to get familiarised with the language. I want to move onto something a little more challenging, but I'm stuck for ideas on what to do. I'm after a project that can start quite simple, but has lots of room for expansion when I get more confident with Python. Ideally something which would start as a command line program, and then when I feel adventurous I could build a GUI for it. I have just bought the Foundations of Python Network Programming book, so maybe something network related would be good? Cheers Jon From pydecker at gmail.com Mon Aug 1 16:34:25 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 1 Aug 2005 16:34:25 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <7x7jf5o2qn.fsf@ruckus.brouhaha.com> References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <7x7jf5o2qn.fsf@ruckus.brouhaha.com> Message-ID: On 01 Aug 2005 12:50:56 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > I seem to be in a minority here Wow, you finally said something that I agree with! > but I vote for avoiding such dependencies as much as possible. This isn't a contest here. Do what you like, and don't expect everyone to share your POV. > That's the best way to avoid problems in practice. That's also the best way to avoid benefitting from the creativity and hard work by others. Locking yourself in a room is also the best way to avoid catching illnesses, or having an automobile accident, or getting shot in a drive-by. Unfortunately, you'll miss out on most of what life has to offer. -- # p.d. From jgrahn-nntq at algonet.se Sun Aug 7 03:47:14 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 7 Aug 2005 07:47:14 GMT Subject: Python to C++ translation? References: <1121722762.525859.255890@g49g2000cwa.googlegroups.com> Message-ID: On 18 Jul 2005 14:39:22 -0700, Mangabasi wrote: > Hi there, > > I need to translate the following code (rather something similar) to > C++. I have been studying C++ for the last two days but I could not > find an easy way to do the following Python snippet. ... > How do I make this work for > > C c2 = C(b, a) > > as well? > > Thank you in advance, I know this is somehow offtopic in the Python > group but I would not dare asking this in the C++ groups. In general, it is not a good idea to try to make a straight translation from one language to another, especially between a very dynamic one like Python to a very static one like C++ [1]. You might be able to do a straight translation of some of the design, but soon you would find yourself working against the language and missing out on its good features. I think you'd be better off starting from scratch. (Or maybe not really from scratch; having done a working version of the program once and maybe having working tests is worth a lot.) /Jorgen [1] You might find C++ templates useful, though. -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From sheig222 at gmail.com Mon Aug 1 08:08:56 2005 From: sheig222 at gmail.com (Ira) Date: Mon, 1 Aug 2005 15:08:56 +0300 Subject: Changing interpreter's deafult output/error streams References: Message-ID: OK let me rephrase, the standard error stream (and if I'm not mistaken also the one that PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go ahead and write the following in python... SomeNewStreamOrFileOrWhateverItIs = new stream sys.stderr = SomeNewStreamOrFileOrWhateverItIs I can go ahead and do the exact same thing from the C source code. All I need to do is to figure out how to wrap a c-style FILE* with a PyObject, And PySys_SetObjet("stderr", newstream); I'm very new to python so that might be nonsense but it appeals to my programmer's common sense. Can anyone tell me how to do this? "Michael Hudson" wrote in message news:m24qaa95m3.fsf at 82-33-185-193.cable.ubr01.azte.blueyonder.co.uk... > "Ira" writes: > > > Using an embedded interpreter, how do I change it's default output > > streams (specifically the one used by PyErr_Print() which I'm > > guessing is the default error stream)? > > It looks as though it writes to stderr unconditionally. But most of > the reasons for ended up in PyErr_Print can be intercepted at a higher > level (I think -- I mean sys.excepthook & co here). > > Cheers, > mwh > > -- > ARTHUR: Yes. It was on display in the bottom of a locked filing > cabinet stuck in a disused lavatory with a sign on the door > saying "Beware of the Leopard". > -- The Hitch-Hikers Guide to the Galaxy, Episode 1 > -- > http://mail.python.org/mailman/listinfo/python-list > From roccomoretti at hotpop.com Tue Aug 9 14:39:08 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Tue, 09 Aug 2005 13:39:08 -0500 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: Christopher Subich wrote: > Rocco Moretti wrote: > >> Variables in Python are names. They aren't the cubbyholes into which >> you put values, they are sticky notes on the front of the cubby hole. > > > +1 MOTW (Metaphor of the Week) Thanks, but please note it's not really mine - I've seen it somewhere else before. I thought it was from the website I linked earlier[1], but now I'm a little embarrased to find out that isn't, and I have no clue where it's from. [1] http://starship.python.net/crew/mwh/hacks/objectthink.html From steven.bethard at gmail.com Mon Aug 29 12:23:24 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 29 Aug 2005 10:23:24 -0600 Subject: trictionary? In-Reply-To: References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> Message-ID: Randy Bush wrote: > Steven Bethard wrote: >> It would probably help if you explained what the real problem is >> you're trying to solve. > > actually, that code fragment was meant to do that. it's pretty much > what i needed to do at that point, just the variable names made > simple. Yeah, I gathered that. Sometimes though, you may not ever need to get to "that point" if the surrounding code can be properly reorganized. But I can't tell if that's possible unless you explain what the goal of the program is, not just how your current code tries to approach that goal. So I'm going to try to pump you for a little more information here. Is your goal to count, for each week, how many times it's "full" and how many times it's "not full"? What do you use the counts for? What does "full" mean? Is it always a 0 or 1? What's the importance of the output formatting? > so, to do this using the real names, it looks like > > for [start, end, AS, full] in heard: > week = int((start-startDate)/aWeek) > if week in bin: > if full: > bin[week][0] += 1 > else: > bin[week][1] += 1 > else: > if full: > bin[week] = [1, 0] > else: > bin[week] = [0, 1] > ... > for i, (j, k) in bin.iteritems(): > if j == 0: > print str(i) + ",," + str(k) > elif k == 0: > print str(i) + "," + str(j) > else: > print str(i) + "," + str(j) + "," + str(k) For the current code, I'd probably go with something like: for start, end, AS, full in heard: week = int((start-startDate)/aWeek) if week in bin: bin[week][not full] += 1 else: # I'm assuming "full" takes the values 0 or 1 # but if not, you can coerce it with bool() bin[week] = [full, int(not full)] ... for i, (j, k) in bin.iteritems(): result = [str(i), j and str(j) or ''] # special-case k because if it's zero, the reference # code drops a comma if k: result.append(str(k)) print ','.join(result) But if you're just trying to count the number of times a week is full or not full, I'd probably do something like: for start, end, AS, full in heard: week = int((start-startDate)/aWeek) if week in bin: bin[week].append(full) else: bin[week] = [full] ... for i, fulls in bin.iteritems(): j = sum(fulls) k = len(fulls) - j ... STeVe From rowen at cesmail.net Tue Aug 23 15:58:43 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Tue, 23 Aug 2005 12:58:43 -0700 Subject: High Level FTP library References: <7NGOe.6737$Nb2.115820@news1.nokia.com> Message-ID: In article <7NGOe.6737$Nb2.115820 at news1.nokia.com>, "Paulo Pinto" wrote: >Hello, > >Is there any Python library similar to NET::FTP from Perl? >ftplib seems too lowlevel. > >I already found a few, but would like to get one that is >endorsed by the community. Try urllib or urllib2; these are included with python. urllib2 is newer but only works for anonymous ftp. Caveat: I ran into trouble doing multiple simultaneous ftp using urllib. I have not used urllib2. Another possibility is Twisted Framework. It has a bit of a learning curve but is well regarded. If you plan to do a lot with networking you should definitely check it out. -- Russell From matt.hammond at rd.bbc.co.uk Fri Aug 12 04:17:45 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Fri, 12 Aug 2005 09:17:45 +0100 Subject: Why is this? References: Message-ID: On Fri, 12 Aug 2005 00:10:08 +0100, John Hazen wrote: >> >>>> [[], []] is [[]]*2 >> > True > > Just curious, did you actually cut and paste this from a real > interactive session? (I think not.) My interpreter (yes, I know it's > old) gives: Ooops - you're absolutely right. I was cutting and pasting, but it seems I was a little overzealous with my editing! I've still got that in my terminal's history buffer, and it does indeed read: >>> [[], []] is [[]]*2 False -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From peter at engcorp.com Wed Aug 31 09:18:31 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 31 Aug 2005 09:18:31 -0400 Subject: .pth files in working directory In-Reply-To: References: Message-ID: Peter Maas wrote: > Peter Hansen schrieb: >> generally such non-standard sys.path and .pth manipulations are best >> handled by a sitecustomize.py file, possibly which makes its own calls >> to site.addsitedir() and such. Try "help(site)" for more. > > But sitecustomize.py changes the Python installation, doesn't it? > This wouldn't be an advantage over putting a .pth file into > .../site-packages. You can have a local sitecustomize.py in the current directory, which wouldn't change the Python installation. Would that help? As far as I can tell, the current directory isn't added to the sys.path until after site.py executes, so I don't believe you can rely on .pth files to do anything like what you want. Sitecustomize.py is it, with appropriate smarts inside. -Peter From yxxxxlxxxxx at gmail.com Thu Aug 4 14:54:38 2005 From: yxxxxlxxxxx at gmail.com (yaffa) Date: 4 Aug 2005 11:54:38 -0700 Subject: sample code for parsing html file to get contents of td fields Message-ID: <1123181678.144557.93100@g49g2000cwa.googlegroups.com> does anyone have sample code for parsting an html file to get contents of a td field to write to a mysql db? even if you have everything but the mysql db part ill take it. thanks yaffa From roy at panix.com Tue Aug 9 23:15:51 2005 From: roy at panix.com (Roy Smith) Date: Tue, 09 Aug 2005 23:15:51 -0400 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> <20050810021120.GA25296@alcyon.progiciels-bpi.ca> Message-ID: Mike Meyer wrote: > Well, the only thing that subversion does that I'd call bad is leave > turds in my development directory. I'm tired of having to tell > commands to ignore .svn files. Of course, Perforce is the only source > control system I know of that doesn't do this. My recollection is that Clearcase is turd-free. From billiejoex at fastwebnet.it Sat Aug 27 05:51:16 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Sat, 27 Aug 2005 11:51:16 +0200 Subject: Closing programs that use sockets References: Message-ID: Awesome. :-) Thank you. > You may find that CTRL/Break works even when CTRL/C doesn't. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > From theller at python.net Tue Aug 23 06:19:11 2005 From: theller at python.net (Thomas Heller) Date: Tue, 23 Aug 2005 12:19:11 +0200 Subject: Revised PEP 349: Allow str() to return unicode strings References: <20050822213142.GA5702@mems-exchange.org> Message-ID: Neil Schemenauer writes: > [Please mail followups to python-dev at python.org.] > > The PEP has been rewritten based on a suggestion by Guido to change > str() rather than adding a new built-in function. Based on my > testing, I believe the idea is feasible. It would be helpful if > people could test the patched Python with their own applications and > report any incompatibilities. > I like the fact that currently unicode(x) is guarateed to return a unicode instance, or raises a UnicodeDecodeError. Same for str(x), which is guaranteed to return a (byte) string instance or raise an error. Wouldn't also a new function make the intent clearer? So I think I'm +1 on the text() built-in, and -0 on changing str. Thomas From benji at benjiyork.com Mon Aug 22 10:14:39 2005 From: benji at benjiyork.com (Benji York) Date: Mon, 22 Aug 2005 10:14:39 -0400 Subject: Sanitizing untrusted code for eval() In-Reply-To: References: Message-ID: <4309DDCF.1050005@benjiyork.com> Jim Washington wrote: > I'm still working on yet another parser for JSON (http://json.org). Hi, Jim. > The only problem is, it uses eval(). It's important to sanitize the > incoming untrusted code before sending it to eval(). > Does anyone know of any other "gotchas" with eval() I have not found? Or > is eval() simply too evil? I'd say that eval is just too evil. I do wonder if it would be possible to use eval by working from the other direction. Instead of trying to filter out dangerous things, only allow a *very* strict set of things in. For example, since your doing JSON, you don't even need to allow multiplication. If you only allowed dictionaries with string keys and a restricted set of types as values, you'd be pretty close. But once you're at that point you might as well use your own parser and not use eval at all. -- Benji York From Majordomo at cs.ubc.ca Mon Aug 1 09:04:28 2005 From: Majordomo at cs.ubc.ca (Majordomo at cs.ubc.ca) Date: Mon, 1 Aug 2005 06:04:28 -0700 (PDT) Subject: Majordomo results: [UBCCS:VIRUS] Was: Returned mail: Data f Message-ID: <200508011304.j71D4S7l016303@pedigree.cs.ubc.ca> -- >>>> This is a multi-part message in MIME format... **** Command 'this' not recognized. >>>> >>>> ------=_NextPart_000_0009_87A2270A.AF343686 **** Command '------=_nextpart_000_0009_87a2270a.af343686' not recognized. >>>> Content-Type: text/plain; **** Command 'content-type:' not recognized. >>>> charset=us-ascii **** Command 'charset=us-ascii' not recognized. >>>> Content-Transfer-Encoding: 7bit **** Command 'content-transfer-encoding:' not recognized. >>>> Content-Disposition: inline **** Command 'content-disposition:' not recognized. >>>> >>>> The message was undeliverable due to the following reason(s): **** Command 'the' not recognized. >>>> >>>> Your message could not be delivered because the destination server was **** Command 'your' not recognized. >>>> unreachable within the allowed queue period. The amount of time **** Command 'unreachable' not recognized. >>>> a message is queued before it is returned depends on local configura- **** Command 'a' not recognized. >>>> tion parameters. **** Command 'tion' not recognized. >>>> >>>> Most likely there is a network problem that prevented delivery, but **** Command 'most' not recognized. >>>> it is also possible that the computer is turned off, or does not **** Command 'it' not recognized. >>>> have a mail system running right now. **** Command 'have' not recognized. >>>> >>>> Your message was not delivered within 4 days: **** Command 'your' not recognized. >>>> Mail server 152.167.191.138 is not responding. **** Command 'mail' not recognized. >>>> >>>> The following recipients did not receive this message: **** Command 'the' not recognized. >>>> **** Command '' not recognized. >>>> >>>> Please reply to postmaster at cs.ubc.ca **** Command 'please' not recognized. >>>> if you feel this message to be in error. **** Command 'if' not recognized. >>>> >>>> >>>> ------=_NextPart_000_0009_87A2270A.AF343686 **** Command '------=_nextpart_000_0009_87a2270a.af343686' not recognized. >>>> Content-Type: text/plain; charset=UTF-8 **** Command 'content-type:' not recognized. >>>> Content-Transfer-Encoding: 8bit **** Command 'content-transfer-encoding:' not recognized. >>>> >>>> The original content of this message part has been replaced **** Command 'the' not recognized. >>>> by this text because it tested positive for the following **** Command 'by' not recognized. >>>> virus(es): **** Command 'virus(es):' not recognized. >>>> >>>> W32/MyDoom-O **** Command 'w32/mydoom-o' not recognized. >>>> >>>> The original message has been quarantined pending further **** Command 'the' not recognized. >>>> action by the mail administrator. For further information **** Command 'action' not recognized. >>>> about the message and its delivery status, please contact **** Command 'about' not recognized. >>>> the undersigned, and include the full content of this **** Command 'the' not recognized. >>>> message. The identifier for this message is **** Command 'message.' not recognized. >>>> 'j71D4OFr001489'. **** Command ''j71d4ofr001489'.' not recognized. >>>> >>>> This notification is being sent to you and any other **** Command 'this' not recognized. >>>> original envelope recipient(s). To avoid creating a **** Command 'original' not recognized. >>>> nuisance and to keep mail traffic under control, the **** Command 'nuisance' not recognized. >>>> original sender of the message has NOT been notified. **** Command 'original' not recognized. >>>> However, you may want to notify the sender at your **** Command 'however,' not recognized. >>>> discretion. **** Command 'discretion.' not recognized. >>>> >>>> >>>> The Management **** Command 'the' not recognized. >>>> PureMessage Admin **** Command 'puremessage' not recognized. >>>> >>>> ------=_NextPart_000_0009_87A2270A.AF343686 **** Command '------=_nextpart_000_0009_87a2270a.af343686' not recognized. >>>> Content-Type: text/plain; name="SpamAssassinReport.txt" **** Command 'content-type:' not recognized. >>>> Content-Disposition: inline; filename="SpamAssassinReport.txt" **** Command 'content-disposition:' not recognized. >>>> Content-Transfer-Encoding: 7bit **** Command 'content-transfer-encoding:' not recognized. >>>> MIME-Version: 1.0 **** Command 'mime-version:' not recognized. >>>> X-Mailer: MIME-tools 5.411 (Entity 5.404) **** Command 'x-mailer:' not recognized. >>>> >>>> Spam detection software, running on the system "badenpowell.cs.ubc.ca", has **** Command 'spam' not recognized. >>>> identified this incoming email as possible spam. The original message **** Command 'identified' not recognized. >>>> has been attached to this so you can view it (if it isn't spam) or block **** Command 'has' not recognized. >>>> similar future email. If you have any questions, see **** Command 'similar' not recognized. >>>> postmaster at cs.ubc.ca for details. **** Command 'postmaster at cs.ubc.ca' not recognized. >>>> >>>> Content preview: The message was undeliverable due to the following **** Command 'content' not recognized. >>>> reason(s): Your message could not be delivered because the destination **** Command 'reason(s):' not recognized. >>>> server was unreachable within the allowed queue period. The amount of **** Command 'server' not recognized. >>>> time a message is queued before it is returned depends on local **** Command 'time' not recognized. >>>> configura- tion parameters. [...] **** Command 'configura-' not recognized. >>>> >>>> Content analysis details: (7.5 points, 5.0 required) **** Command 'content' not recognized. >>>> >>>> pts rule name description **** Command 'pts' not recognized. >>>> ---- ---------------------- -------------------------------------------------- **** Command '----' not recognized. >>>> 0.3 NO_REAL_NAME From: does not include a real name **** Command '0.3' not recognized. >>>> 3.3 MSGID_FROM_MTA_SHORT Message-Id was added by a relay **** Command '3.3' not recognized. >>>> 2.3 RCVD_IN_XBL RBL: Received via a relay in Spamhaus XBL **** Command '2.3' not recognized. >>>> [69.84.39.146 listed in sbl-xbl.spamhaus.org] **** Command '[69.84.39.146' not recognized. >>>> 1.6 FORGED_MUA_OUTLOOK Forged mail pretending to be from MS Outlook **** Command '1.6' not recognized. >>>> >>>> >>>> >>>> ------=_NextPart_000_0009_87A2270A.AF343686-- **** Command '------=_nextpart_000_0009_87a2270a.af343686--' not recognized. **** No valid commands found. **** Commands must be in message BODY, not in HEADER. **** Help for Majordomo at cs.ubc.ca: This help message is being sent to you from the Majordomo mailing list management system at Majordomo at cs.ubc.ca. This is version 1.94.5 of Majordomo. If you're familiar with mail servers, an advanced user's summary of Majordomo's commands appears at the end of this message. Majordomo is an automated system which allows users to subscribe and unsubscribe to mailing lists, and to retrieve files from list archives. You can interact with the Majordomo software by sending it commands in the body of mail messages addressed to "Majordomo at cs.ubc.ca". Please do not put your commands on the subject line; Majordomo does not process commands in the subject line. You may put multiple Majordomo commands in the same mail message. Put each command on a line by itself. If you use a "signature block" at the end of your mail, Majordomo may mistakenly believe each line of your message is a command; you will then receive spurious error messages. To keep this from happening, either put a line starting with a hyphen ("-") before your signature, or put a line with just the word end on it in the same place. This will stop the Majordomo software from processing your signature as bad commands. Here are some of the things you can do using Majordomo: I. FINDING OUT WHICH LISTS ARE ON THIS SYSTEM To get a list of publicly-available mailing lists on this system, put the following line in the body of your mail message to Majordomo at cs.ubc.ca: lists Each line will contain the name of a mailing list and a brief description of the list. To get more information about a particular list, use the "info" command, supplying the name of the list. For example, if the name of the list about which you wish information is "demo-list", you would put the line info demo-list in the body of the mail message. II. SUBSCRIBING TO A LIST Once you've determined that you wish to subscribe to one or more lists on this system, you can send commands to Majordomo to have it add you to the list, so you can begin receiving mailings. To receive list mail at the address from which you're sending your mail, simply say "subscribe" followed by the list's name: subscribe demo-list If for some reason you wish to have the mailings go to a different address (a friend's address, a specific other system on which you have an account, or an address which is more correct than the one that automatically appears in the "From:" header on the mail you send), you would add that address to the command. For instance, if you're sending a request from your work account, but wish to receive "demo-list" mail at your personal account (for which we will use "jqpublic at my-isp.com" as an example), you'd put the line subscribe demo-list jqpublic at my-isp.com in the mail message body. Based on configuration decisions made by the list owners, you may be added to the mailing list automatically. You may also receive notification that an authorization key is required for subscription. Another message will be sent to the address to be subscribed (which may or may not be the same as yours) containing the key, and directing the user to send a command found in that message back to Majordomo at cs.ubc.ca. (This can be a bit of extra hassle, but it helps keep you from being swamped in extra email by someone who forged requests from your address.) You may also get a message that your subscription is being forwarded to the list owner for approval; some lists have waiting lists, or policies about who may subscribe. If your request is forwarded for approval, the list owner should contact you soon after your request. Upon subscribing, you should receive an introductory message, containing list policies and features. Save this message for future reference; it will also contain exact directions for unsubscribing. If you lose the intro mail and would like another copy of the policies, send this message to Majordomo at cs.ubc.ca: intro demo-list (substituting, of course, the real name of your list for "demo-list"). III. UNSUBSCRIBING FROM MAILING LISTS Your original intro message contains the exact command which should be used to remove your address from the list. However, in most cases, you may simply send the command "unsubscribe" followed by the list name: unsubscribe demo-list (This command may fail if your provider has changed the way your address is shown in your mail.) To remove an address other than the one from which you're sending the request, give that address in the command: unsubscribe demo-list jqpublic at my-isp.com In either of these cases, you can tell Majordomo at cs.ubc.ca to remove the address in question from all lists on this server by using "*" in place of the list name: unsubscribe * unsubscribe * jqpublic at my-isp.com IV. FINDING THE LISTS TO WHICH AN ADDRESS IS SUBSCRIBED To find the lists to which your address is subscribed, send this command in the body of a mail message to Majordomo at cs.ubc.ca: which You can look for other addresses, or parts of an address, by specifying the text for which Majordomo should search. For instance, to find which users at my-isp.com are subscribed to which lists, you might send the command which my-isp.com Note that many list owners completely or fully disable the "which" command, considering it a privacy violation. V. FINDING OUT WHO'S SUBSCRIBED TO A LIST To get a list of the addresses on a particular list, you may use the "who" command, followed by the name of the list: who demo-list Note that many list owners allow only a list's subscribers to use the "who" command, or disable it completely, believing it to be a privacy violation. VI. RETRIEVING FILES FROM A LIST'S ARCHIVES Many list owners keep archives of files associated with a list. These may include: - back issues of the list - help files, user profiles, and other documents associated with the list - daily, monthly, or yearly archives for the list To find out if a list has any files associated with it, use the "index" command: index demo-list If you see files in which you're interested, you may retrieve them by using the "get" command and specifying the list name and archive filename. For instance, to retrieve the files called "profile.form" (presumably a form to fill out with your profile) and "demo-list.9611" (presumably the messages posted to the list in November 1996), you would put the lines get demo-list profile.form get demo-list demo-list.9611 in your mail to Majordomo at cs.ubc.ca. VII. GETTING MORE HELP To contact a human site manager, send mail to Majordomo-Owner at cs.ubc.ca. To contact the owner of a specific list, send mail to that list's approval address, which is formed by adding "-approval" to the user-name portion of the list's address. For instance, to contact the list owner for demo-list at cs.ubc.ca, you would send mail to demo-list-approval at cs.ubc.ca. To get another copy of this help message, send mail to Majordomo at cs.ubc.ca with a line saying help in the message body. VIII. COMMAND SUMMARY FOR ADVANCED USERS In the description below items contained in []'s are optional. When providing the item, do not include the []'s around it. Items in angle brackets, such as
, are meta-symbols that should be replaced by appropriate text without the angle brackets. It understands the following commands: subscribe [
] Subscribe yourself (or
if specified) to the named . unsubscribe [
] Unsubscribe yourself (or
if specified) from the named . "unsubscribe *" will remove you (or
) from all lists. This _may not_ work if you have subscribed using multiple addresses. get Get a file related to . index Return an index of files you can "get" for . which [
] Find out which lists you (or
if specified) are on. who Find out who is on the named . info Retrieve the general introductory information for the named . intro Retrieve the introductory message sent to new users. Non-subscribers may not be able to retrieve this. lists Show the lists served by this Majordomo server. help Retrieve this message. end Stop processing commands (useful if your mailer adds a signature). Commands should be sent in the body of an email message to "Majordomo at cs.ubc.ca". Multiple commands can be processed provided each occurs on a separate line. Commands in the "Subject:" line are NOT processed. If you have any questions or problems, please contact "Majordomo-Owner at cs.ubc.ca". From jstroud at mbi.ucla.edu Fri Aug 5 01:51:14 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 4 Aug 2005 22:51:14 -0700 Subject: Idiots guide to fonts with tKinter In-Reply-To: <1123146134.391156.258760@g43g2000cwa.googlegroups.com> References: <1123146134.391156.258760@g43g2000cwa.googlegroups.com> Message-ID: <200508042251.14741.jstroud@mbi.ucla.edu> No doubt you have found Fredrik Lundh's intro: http://www.pythonware.com/library/tkinter/introduction/ You can get a long way with that and experimenting. Also, check out Tk: http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tk8.0a1/contents.html If you can figure out how to translate the Tk documentation into Tkinter, you open a lot of doors for yourself. The best easily available Tkinter tutorial I have found is in the Programming Python book by Mark Lutz (O'Reilly): http://www.oreilly.com/catalog/python2/toc.html Its $55 bucks, but is full of good examples, so it is worth it. The price of course is not the money, but the fact that some parts of the book (not necessarily the Tkinter part) can get pretty tedious to work through. But its worth the investment in time and money. I don't recommend learning Tkinter with just a reference manual (like Lundh's page). You'll waste far more money's worth of time than just $55 trying to figure out how to do things that are already clearly described in Programming Python. James On Thursday 04 August 2005 02:02 am, import newbie wrote: > Hi all, > > I'm a programming dabbler trying learn Python, and I've got a few > questions. > > Mainly: Where can I find a good open-source library or tutorial > (preferably free) that explains how to easily manipulate text in a > tKinter window? Basically, I want to be able to do anything that HTML > can do (or close to it) but without the HTML. :-) > > My "newbie dream project" is to piece together a functional, WYSIWYG > text editor that can handle at least three fonts: Times New Roman, > Arial and Courier (bold, italics and underlined). > > I know, I know. That's pretty ambitious. But that's my goal for Python. > So....what's the easiest way to get there? What steps should I take? > I'm not in any rush, I just want some help along the way... -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From rkern at ucsd.edu Mon Aug 29 11:26:33 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 29 Aug 2005 08:26:33 -0700 Subject: Robust statistics and optimmization from Python In-Reply-To: <1125328346.738915.102990@z14g2000cwz.googlegroups.com> References: <1125328346.738915.102990@z14g2000cwz.googlegroups.com> Message-ID: tkpmep at hotmail.com wrote: > I use Python to generate a huge amount of data in a .csv file which I > then process using Excel. In particular, I use Excel's solver to solve > a number of non-linear equation, and then regress the results of > hundreds of calls to Solver against a set of known values, enabling me > to calibrate my model. This is a pain: i'd much rather perform all the > computations in Python and improve on Excels' regression as well. > > Questions: > 1. Is there a way to perform (or make a call to) a non-linear > optimization from Python? Look at scipy. http://www.scipy.org In [1]: from scipy import optimize In [2]: optimize? ... Optimization Tools ================== A collection of general-purpose optimization routines. fmin -- Nelder-Mead Simplex algorithm (uses only function calls) fmin_powell -- Powell's (modified) level set method (uses only function calls) fmin_cg -- Non-linear (Polak-Rubiere) conjugate gradient algorithm (can use function and gradient). fmin_bfgs -- Quasi-Newton method (can use function and gradient) fmin_ncg -- Line-search Newton Conjugate Gradient (can use function, gradient and hessian). leastsq -- Minimize the sum of squares of M equations in N unknowns given a starting estimate. Constrained Optimizers (multivariate) fmin_l_bfgs_b -- Zhu, Byrd, and Nocedal's L-BFGS-B constrained optimizer (if you use this please quote their papers -- see help) fmin_tnc -- Truncated Newton Code originally written by Stephen Nash and adapted to C by Jean-Sebastien Roy. fmin_cobyla -- Contrained Optimization BY Linear Approximation > 2. Do Python packages for robust statistics (robust regression in > particular) exist. If so, which one would you recommend/ Offhand, I can't think of any, but it's easy enough to do maximum likelihood with Laplacians and the functions above. If you find suitable FORTRAN or C code that implements a particular "robust" algorithm, it can probably wrapped for scipy relatively easily. -- 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 jeffrey.schwab at rcn.com Fri Aug 12 00:39:04 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Fri, 12 Aug 2005 00:39:04 -0400 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123817945.783409.158810@g47g2000cwa.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123817414.665062.282500@g49g2000cwa.googlegroups.com> <1123817945.783409.158810@g47g2000cwa.googlegroups.com> Message-ID: Ray wrote: > Devan L wrote: > >>Fausto Arinos Barbuto wrote: >> >>>Ray wrote: >>> >>> >>>>1. Where are the access specifiers? (public, protected, private) >>> >>> AFAIK, there is not such a thing in Python. >>> >>>---Fausto >> >>Well, technically you can use _attribute to mangle it, but technically >>speaking, there are no public, protected, or private things. > > > OK, thanks. How about static members and instance members? Seems that > in Python everything is class-wide? You can define instance data in the __init__ method. def __init__(self): self.instance_member = 0; From googlenews at tooper.org Wed Aug 24 08:01:45 2005 From: googlenews at tooper.org (tooper) Date: 24 Aug 2005 05:01:45 -0700 Subject: Inheritance problem ? In-Reply-To: <1124884087.421461.153190@g43g2000cwa.googlegroups.com> References: <1124879676.525583.14390@g44g2000cwa.googlegroups.com> <1124884087.421461.153190@g43g2000cwa.googlegroups.com> Message-ID: <1124884905.546603.236110@g43g2000cwa.googlegroups.com> Thanks, at least makes it running ! I'll have to teach myself to move to this new style classes by default anyway... From sjmaster at gmail.com Fri Aug 26 17:20:52 2005 From: sjmaster at gmail.com (Steve M) Date: 26 Aug 2005 14:20:52 -0700 Subject: Problem with Pythoncard In-Reply-To: References: Message-ID: <1125091251.942633.301230@g49g2000cwa.googlegroups.com> There are some Python packages that I prefer to get from the developer instead of from my Linux distribution (Debian). Usually it is because I intend to upgrade the package before, or more often than, my distribution releases a new version. (A likely scenario if you use Debian - zing!) So I download the source.tar.gz from the developer. I extract it into ~/src, change to the directory and run "python setup.py build". (Here you might recursively detour to install a dependency.) Then I change to the build/lib directory and in there is all of the modules. In build/scripts will be any included scripts. I copy the contents of build/lib to ~/python/lib and the scripts to ~/python/scripts. (Alternatively I could make symbolic links.) My PYTHONPATH environment variable includes ~/python/lib. (Alternatively you can modify sitecustomize.py to insert that directory into the sys.path but this could have system-wide implications.) You can also add ~/python/scripts to your command path. (I tend to manually type the path whenever I want to run something in there.) Now the package is available for import from any python program that I run. I can reproduce this on a system that I do not have root for but only a user shell account. It is easy to transfer the whole library to another computer just by copying the relevant directories. And if I want to upgrade I can download the new source tarball, build it, and change the symlinks or overwrite the old directory contents. I find this is a reasonably convenient way to have up-to-date packages from the Python world on my stable-but-not-entirely-state-of-the-art Debian system. I'm sure as time goes by I'll refine this system. Or maybe Python Eggs will solve most of the problems... From borges2003xx at yahoo.it Thu Aug 4 10:36:03 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 4 Aug 2005 07:36:03 -0700 Subject: substring and regular expression In-Reply-To: <42f21930$1_2@newspeer2.tds.net> References: <1123140231.118099.4890@g43g2000cwa.googlegroups.com> <42f21930$1_2@newspeer2.tds.net> Message-ID: <1123166163.109766.297420@g43g2000cwa.googlegroups.com> but in general is there a way to include in a re, in this example something like...matches iff p , and q in which p==q[::-1] ? A way to putting a small part of code of python in re? Thanx for your many helps From grig.gheorghiu at gmail.com Tue Aug 16 18:24:00 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 16 Aug 2005 15:24:00 -0700 Subject: stopping a python windows service References: <1124230320.593335.288650@g44g2000cwa.googlegroups.com> Message-ID: <1124231040.813925.246880@g47g2000cwa.googlegroups.com> Here are 2 recipes from the online Python Cookbook. I've used this one very successfully: . This one seems simpler: Grig From sjmachin at lexicon.net Sun Aug 14 23:06:30 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Aug 2005 13:06:30 +1000 Subject: python-Excel: Chinese Characters In-Reply-To: <1124073601.970100.322480@o13g2000cwo.googlegroups.com> References: <1124073601.970100.322480@o13g2000cwo.googlegroups.com> Message-ID: <430006b5@news.eftel.com> zxo102 wrote: > Hi there, > I am trying to put data including Chinese Characters into Excel > through python. But I got some problems. Here is my sample code: > > ################################################## > # > import win32com.client > xlapp = win32com.client.DispatchEx("Excel.Application") > xlbook = xlapp.Workbooks.Open("test.xls") > sht = xlbook.Worksheets("Sheet1") > > # data is provided in case 1 and case 2 below > ... > sht.Range(sht.Cells(1, 1), sht.Cells(2,4)).Value = data > # > ################################################## > > Using the above code, I tested two cases for "data". The "data" from > both two cases are same: tuple basically. But in case 1, only 2222 and > 3333 are inserted into Excel. All other cells are blank. in case2, all > data including Chinese Characters are inserted into Excel and > everything is fine. My real data is like case 1. > > > > #case 1 ------------------------------------------ > rp = {'r1':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'], > 'r2':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'], > 'r3':[2222,3333], > 'r4':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'] > } > > b = () > for k in range(len(rp['r1'])): > a = rp['r1'][k],rp['r2'][k],rp['r3'][k],rp['r4'][k] > if len(b) == 0: > b = a > else: > b = b,a > data = b > > #case 2 ------------------------------------------ > data =(('\xd6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 2222, > '\xd6\xd7\xc1\xf6'), > ('\xd6\xd7\xc1\xf6", '\xd6\xd7\xc1\xf6", 3333, Bulldust alert! Syntax error caused by starting 2 strings with ' and ending with " > '\xd6\xd7\xc1\xf6')) > > Anybody knows what is going on with it? No. How could we know??? Try showing us *EXACTLY* what code you ran. FWIW, correcting the " to ' above shows no difference in the two cases: C:\junk>type ouyang.py rp = {'r1':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'], 'r2':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'], 'r3':[2222,3333], 'r4':['\xd6\xd7\xc1\xf6','\xd6\xd7\xc1\xf6'] } b = () for k in range(len(rp['r1'])): a = rp['r1'][k],rp['r2'][k],rp['r3'][k],rp['r4'][k] if len(b) == 0: b = a else: b = b,a data1 = b #case 2 ------------------------------------------ data2 =(('\xd6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 2222, '\xd6\xd7\xc1\xf6'), ('\xd6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 3333,'\xd6\xd7\xc1\xf6')) print print "data1", repr(data1) print "data2", repr(data2) print data1 == data2 C:\junk>ouyang.py data1 (('\xd6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 2222, '\xd6\xd7\xc1\xf6'), ('\xd 6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 3333, '\xd6\xd7\xc1\xf6')) data2 (('\xd6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 2222, '\xd6\xd7\xc1\xf6'), ('\xd 6\xd7\xc1\xf6', '\xd6\xd7\xc1\xf6', 3333, '\xd6\xd7\xc1\xf6')) True From sjmachin at lexicon.net Thu Aug 18 20:02:55 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 10:02:55 +1000 Subject: Bitwise operations in Python? In-Reply-To: References: Message-ID: <430521af@news.eftel.com> Carl wrote: > Dear friends, > > I am currently porting a fortran program to Python but am stuck on the > intrinsic IBITS function. > > Does anyone know about a replacement function for IBITS in Python? > > Yours, Carl > > IBITS(I, POS, LEN) > > Extracts a sequence of bits. > > I > must be of type integer. > > POS > must be of type integer. It must be nonnegative and POS + LEN must be > less than or equal to BIT_SIZE (I). > > LEN > must be of type integer and nonnegative. > > Class > > Elemental function > > Result Type and Attributes > > Same as I. > > Result Value > > The result has the value of the sequence of LEN bits in I beginning at bit > POS, right-adjusted and with all other bits zero. > > The bits are numbered from 0 to BIT_SIZE(I)-1, from right to left. > > Examples > > IBITS (14, 1, 3) has the value 7. > No, don't know, but you could write one yourself PDQ. Something like this: def ibits(arg, pos, len): return (arg >> pos) & ((1 << len) - 1) if __name__ == "__main__": def testit(arg, pos, len, reqd): result = ibits(arg, pos, len) print arg, pos, len, reqd, result, "* "[result == reqd] testit(14, 1, 3, 7) for pos in range(6): testit(4095, pos, 3, 7) for pos in range(6): testit(-1, pos, 3, 7) for pos in range(6): testit(0, pos, 3, 0) for pos in range(0, 32, 4): testit(0x12345678, pos, 4, 8-pos/4) for pos in range(0, 32, 4): testit(0x87654321, pos, 4, 1+pos/4) From mcfletch at rogers.com Tue Aug 30 13:00:42 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Tue, 30 Aug 2005 13:00:42 -0400 Subject: File parser In-Reply-To: <1125416411.098740.111590@g44g2000cwa.googlegroups.com> References: <1125416411.098740.111590@g44g2000cwa.googlegroups.com> Message-ID: <431490BA.6080300@rogers.com> infidel wrote: >Angelic Devil wrote: > > ... >Some time ago I was toying around with writing a tool in python to >parse our VB6 code (the original idea was to write our own .NET >conversion tool because the Wizard that comes with VS.NET sucks hard on >some things). I tried various parsing tools and EBNF grammars but VB6 >isn't really an EBNF-esque syntax in all cases, so I needed something >else. > ... You may find this project interesting to play with: http://vb2py.sourceforge.net/index.html Have fun, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From mike.seeley at sbcglobal.net Mon Aug 1 16:18:33 2005 From: mike.seeley at sbcglobal.net (Michael Seeley) Date: Mon, 01 Aug 2005 20:18:33 GMT Subject: Short term project Message-ID: I have a client in Fort Worth, TX that needs a Python programmer for a short project. This could be a telecommuting position. Please email me at mseeley at msxi.com if interested. From cpl.19.ghum at spamgourmet.com Mon Aug 22 08:29:35 2005 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Mon, 22 Aug 2005 12:29:35 +0000 (UTC) Subject: Python dutch References: Message-ID: Sybren Stuvel , > I'd suggest learning English. The programming language is based on > English anyway. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. To be even more exact, it would help to learn or even be Dutch to program in Python, as those quoted lines out of the ZEN might suggest. Harald From steve at holdenweb.com Fri Aug 26 22:04:47 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Aug 2005 22:04:47 -0400 Subject: Closing programs that use sockets In-Reply-To: References: Message-ID: billiejoex wrote: > Hi all. I got a problem when using socket modules. > By using them I can't stop my program by pressing ctrl+c. > The only way to doit is by killing the python.exe process manually. > Is there a solution to avoid this? > > Regards > > You may find that CTRL/Break works even when CTRL/C doesn't. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From peter at engcorp.com Wed Aug 24 22:12:09 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 24 Aug 2005 22:12:09 -0400 Subject: Newbie question: Sub-interpreters for CAD program In-Reply-To: References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: Terry Hancock wrote: >>I have a strong EE and hardware background (hence my need to write a >>CAD program that doesn't piss me off), but not a CS background. > > Cool. If you do write it and release it, I'd be interested in finding out > about it. > > You probably ought to consider starting with something existing like > the Gnu EDS project -- but I'm assuming you probably already know > about that. Or even http://www.pythoncad.org/ which, although probably for mechanical CAD work (I haven't looked at it, don't really know), is surely a good place to get ideas of what Python can do in this area. -Peter From moranar at alice.it Wed Aug 3 11:57:05 2005 From: moranar at alice.it (Adriano Varoli Piazza) Date: Wed, 03 Aug 2005 15:57:05 GMT Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <1122912406.19618.333.camel@localhost.localdomain> Message-ID: Tom Anderson ha scritto: > On Mon, 1 Aug 2005, Benji York wrote: > >> Cliff Wells wrote: >> >>> As I mentioned earlier, programming is half brains and half >>> tenacity. >> >> >> +1 QOTY (quote of the year) > > > Personally, i'd say it was 50% brains, 40% tenacity and 20% basic > arithmetic. > > 8) > > tom > The famed 110% efficiency/commitment/etc every manager wants and talks about comes from this? -- Adriano Varoli Piazza The Inside Out: http://moranar.com.ar MSN: adrianomd at hotmail.com ICQ: 4410132 From sjmachin at lexicon.net Tue Aug 16 00:04:09 2005 From: sjmachin at lexicon.net (John Machin) Date: Tue, 16 Aug 2005 14:04:09 +1000 Subject: How to obtain GMT offset? In-Reply-To: References: Message-ID: <430165b9$1@news.eftel.com> new pip wrote: > I'm using Windows os. If the current system date time is '28 Jun 2001 > 14:17:15 +0700', how can I obtain the value '+0700' using python? If the current system date is in 2001, obtaining "GMT offset" is the least of your concerns :-) Have you read the section on the time module in the Python manual? If so, what didn't you understand? One or more of the following might assist: >>> import time >>> time.gmtime(), time.localtime() ((2005, 8, 16, 3, 59, 3, 1, 228, 0), (2005, 8, 16, 13, 59, 3, 1, 228, 0)) >>> time.timezone -36000 >>> Looks like it's '-1000' (hours) for me at the moment. Daylight saving saving isn't operating here at the moment, so I can't tell whether that makes a difference. I haven't tried to understand the bits about DST in the manual, but maybe you should. HTH, John From Shoeshine at bronx.com Thu Aug 25 12:28:28 2005 From: Shoeshine at bronx.com (Shoeshine) Date: Thu, 25 Aug 2005 18:28:28 +0200 Subject: Just a thank... (ignore) References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <3n688aF2fp4U1@uni-berlin.de> <1124986050.757959.307630@o13g2000cwo.googlegroups.com> Message-ID: <430df112$0$7618$ba624c82@nntp02.dk.telia.net> Thanx for sharing... -it was of use. ------- -Linux- -Becouse PC is a terible thing to waste... From eddie at holyrood.ed.ac.uk Fri Aug 26 11:34:26 2005 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Fri, 26 Aug 2005 15:34:26 +0000 (UTC) Subject: need a little help with time References: <1125065840.477157.43290@g47g2000cwa.googlegroups.com> Message-ID: nephish at xit.net writes: >Hey there. >i have a time string (created with strftime) then read from a file, >i am having some trouble understanding how to get the difference >between times. >i know i can structime(timestring) and get a time value, but i dont >know how to manipulate it. >basically, if i have string 2005-08-24 09:25:58 >and another string 2005-08-24 09:28:58 >how can i tell how many minutes, hours, seconds, days, months etc.. >have passed between the first string and the second ? >or, if there is a good tutorial on this kind of thing, please post a >url. Either the datetime module or mxDateTime from http://www.egenix.com/files/python/mxDateTime.html which is more extensive. From Scott.Daniels at Acm.Org Thu Aug 18 15:56:03 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 18 Aug 2005 12:56:03 -0700 Subject: determine variable type In-Reply-To: References: Message-ID: <4304dbff$1@nntp0.pdx.net> MCollins at seminolecountyfl.gov wrote: > trying to determine a variable type, specifically that a variable is an > integer. > > i tried using type(var) but that only seemed to produce a response in the > command line. > > is there a built in python function to determine if a variable is an > integer? if isinstance(var, (int, long)): print 'var (%r) is an integer' % var elif isinstance(var, float) and int(var) == var: print 'var (%r) is a float that could be an integer' % var else: print 'var (%r) is not an integer' % var --Scott David Daniels Scott Daniels at Acm.Org From tomi.kyostila at gmail.com Mon Aug 1 14:16:08 2005 From: tomi.kyostila at gmail.com (=?ISO-8859-1?Q?Tomi_Ky=F6stil=E4?=) Date: Mon, 01 Aug 2005 21:16:08 +0300 Subject: Python Programming Contest: First results In-Reply-To: References: <1121838061.749455.44630@g14g2000cwa.googlegroups.com> <42DE18B2.903@sweetapp.com> Message-ID: Brian Quinlan wrote: > Here are the results for the first problem in the Python Programming > Contest. > > I haven't been able to find as much time as I excepted, so my analysis > is not very in depth. > > You can find the results here: > http://www.sweetapp.com/pycontest/contest1/results.html > > And the problem definition here: > http://www.sweetapp.com/pycontest/contest1/ > > Kudos to everyone who participated but especially to Raymond Hettinger > and Thomas Lotze, whose solutions were nearly 50 times faster than mine. > > I'd also like to point out that Thomas Guettler's solution, which is the > slowest, was completed in less than 3 hours after the contest was > announced. That's impresive for a correct solution. > > Cheers, > Brian Why don't I see my solution (__author__ = "dOb") in the results? I'm sure that you got it as you replied to my mail. Where do the timing results come from? Is it the number that fly_test.main(['fly']) outputs? I don't think it is that because with my solution that would be ~0.06 seconds. Great competition anyway, I want to see more of these :) -- dOb From jolafix at gmail.com Sun Aug 7 05:34:38 2005 From: jolafix at gmail.com (Atila Olah) Date: 7 Aug 2005 02:34:38 -0700 Subject: Some newbie cgi form questions... In-Reply-To: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> Message-ID: <1123407278.841972.113690@g44g2000cwa.googlegroups.com> >for key in form.keys(): > if not form.has_key(key): # it will always be True try this: for key in form.keys(): if not form.keys()[key]: # True if it's a value is None Well, I don't exactly know the methods of the CGI module, but there are ways to access form data in Apache's mod_python module. There you have a method to access the data from the form, (and it does exactly whet the CGU module does), and you have an option flag wheter to ignore empty fields or not. From peter at hardy.dropbear.id.au Tue Aug 23 21:29:39 2005 From: peter at hardy.dropbear.id.au (peter at hardy.dropbear.id.au) Date: 23 Aug 2005 18:29:39 -0700 Subject: Sequential XML parsing with xml.sax In-Reply-To: References: <1124823628.332677.73660@o13g2000cwo.googlegroups.com> Message-ID: <1124846979.208384.299510@g14g2000cwa.googlegroups.com> Hi. Fredrik Lundh wrote: > peter at hardy.dropbear.id.au wrote: > > > The API reference isn't clear on whether parseString can only handle > > discrete bits of valid XML > > the documentation says that "parse" expects an XML document, > and that "parseString" is the same thing, but parses from a buffer. OK, so it sounded a lot more ambiguous at 4am. :-) > it's probably easier to pass a BZ2File instance to "parse", It is easier to retrieve a remote file, and decompress and parse as separate steps. But I've been wondering if it would be faster / more efficient to do it without caching. > but if you > insist on doing incremental SAX parsing, the IncrementalParser class > might be what you need: That'll do the trick nicely. Thanks. Cheers, -- Pete From randy at psg.com Wed Aug 24 07:01:12 2005 From: randy at psg.com (Randy Bush) Date: Wed, 24 Aug 2005 04:01:12 -0700 Subject: list insertion References: Message-ID: <17164.21368.425911.649567@roam.psg.com> >> hold = self.next >> self.next = DaClass(value) >> self.next.next = hold > shouldn't that last line be this? > self.next.prev = hold single threaded list > What did you expect, and what did you ovserve? i will try to distill a case randy From paschott at no.yahoo.spamm.com Fri Aug 12 12:57:04 2005 From: paschott at no.yahoo.spamm.com (Peter A. Schott) Date: Fri, 12 Aug 2005 16:57:04 GMT Subject: Text/IDE Python Editor? References: Message-ID: Also, it depends on what you're trying to do. GUI, Web, Service-type apps, etc. I have started using Stan's Python Editor (www.stani.be) because I like the general features it offers. It does require wxpython to run, though. I've also used Boa Constructor and DrPython - both pretty good environments. I believe that they are both dependent on wxpython as well. Some people like Eric - now available for XP using PyQt under the Qt GPL'd version. I had a little trouble with it running correctly - probably due to a config issue on my part. I will admit to not spending a lot of time with it, though. If you don't need the GUI IDE, there are a whole bunch of options available. More than I'm able to delve into properly. Best answer is to play around a little with the different IDE's and find the one that works for your coding style. Also, check the archives for this group. This topic has come up quite a bit recently. -Pete Simon Brunning wrote: > On 8/12/05, djanvk at gmail..com wrote: > > Any recommendations on a editior/IDE for programming in python? > > http://wiki.python.org/moin/PythonEditors From roy at panix.com Tue Aug 9 23:02:59 2005 From: roy at panix.com (Roy Smith) Date: Tue, 09 Aug 2005 23:02:59 -0400 Subject: Bizarre error from help() Message-ID: Can anybody explain this bizarre behavior: --------------------- Roy-Smiths-Computer:play$ py Python 2.3.4 (#3, Jun 29 2004, 21:48:03) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> help (isinstance) foos bars bazes Foo Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.3/site.py", line 307, in __call__ import pydoc File "/usr/local/lib/python2.3/pydoc.py", line 49, in ? from string import expandtabs, find, join, lower, split, strip, rfind, rstrip ImportError: cannot import name expandtabs >>> --------------------- From news at NOwillmcguganSPAM.com Tue Aug 30 10:55:38 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Tue, 30 Aug 2005 15:55:38 +0100 Subject: how to join two Dictionary together? In-Reply-To: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> Message-ID: <4314736b$0$3556$da0feed9@news.zen.co.uk> DENG wrote: > dict1={...something...} > > dict2={...somethind else ..} > > dict1 + dict2 > > > that's does works ..:(, it's not like List... I think you want.. dict1.update(dict2) Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From cantabile.03 at wanadoo.fr Sat Aug 6 05:56:51 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Sat, 06 Aug 2005 11:56:51 +0200 Subject: about coding Message-ID: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-' directive. I'm using an accented characters language. Some of them are correctly displayed while one doesn't. I've written : -*- coding: utf-8 -*- Is this wrong ? Where can I find a pratical explanation about these encodings ? Thanks. From onurb at xiludom.gro Sat Aug 20 06:40:53 2005 From: onurb at xiludom.gro (bruno modulix) Date: Sat, 20 Aug 2005 12:40:53 +0200 Subject: python classes taught In-Reply-To: <1124476622.522386.166050@g14g2000cwa.googlegroups.com> References: <1124476622.522386.166050@g14g2000cwa.googlegroups.com> Message-ID: <430708b6$0$13292$626a14ce@news.free.fr> araki at hotmail.com wrote: > anyone know of any college/school that is teaching the python language? > Bordeaux University (France) uses Python in a "programming 101" course. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From steven.bethard at gmail.com Fri Aug 12 13:19:39 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 12 Aug 2005 11:19:39 -0600 Subject: How do these Java concepts translate to Python? In-Reply-To: <42fc640e$0$22461$626a14ce@news.free.fr> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123817414.665062.282500@g49g2000cwa.googlegroups.com> <42fc640e$0$22461$626a14ce@news.free.fr> Message-ID: <_aGdneNZYpK1R2HfRVn-qQ@comcast.com> bruno modulix wrote: >>but technically >>speaking, there are no public, protected, or private things. > > Yes there are: > object.name is public > object._name is protected > object.__name is private The double-underscore name-mangling is almost never worth it. It's supposed to stop name collisions, but, while it does in some cases, it doesn't in all cases, so you shouldn't rely on this. For example: ---------- mod1.py ---------- class C(object): __x = 'mod1.C' @classmethod def getx(cls): return cls.__x ----------------------------- ---------- mod2.py ---------- import mod1 class C(mod1.C): __x = 'mod2.C' ----------------------------- py> import mod1, mod2 py> mod1.C.getx() 'mod1.C' py> mod2.C.getx() 'mod2.C' If double-underscore name-mangling worked like private variables, setting C.__x in mod2.C should not affect the value of C.__x in mod1.C. STeVe From benn at cenix-bioscience.com Wed Aug 10 07:27:08 2005 From: benn at cenix-bioscience.com (Neil Benn) Date: Wed, 10 Aug 2005 13:27:08 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <42F9E48C.7070903@cenix-bioscience.com> Tito wrote: >N.Davis wrote: > > >>Functions existing in a module? Surely if "everything is an object" (OK >>thats Java-talk but supposedly Python will eventually follow this too) >>then there should be nothing in a module thats not part of a class. >> >> > >Well, all data in a Python program are objects, in the sense that they >have an identity on their own, and variables are only references to them. > >Why is it necessary to have all code into classes for meeting the >"everything is an object" panacea? > > If you don't have a class how can you combine functionality with data and hold state - that is one of the points of a class. Python has the added concept that if you don;t need this you can create functions with no associations - lots of languages do that but Java, Eiffel, C#, etc don't have that concept. You need to make a difference between everything is an object and everything is a class here. A programmer coming from Java/C# wouldn't think about that. > > >>Even >>a static method is simply a class function that operates on the >>"collection of all instances" rather than a single instance. >> >> > >That is not true. A static method knows nothing about the instances of a > class, unless you do it your own. Besides, it will work whether you >have created instances of the class or not. > >So, a static method is just a global method declared withing a class, >which just serves as a namespace for it. > > In java, a static method is the same as a class method in Python, you can then use the cls param to access class attributes (that is what teh OP implied). However a static method can help with namespacing. What looks better : initialise_local_message_router() objPublisher = get_publisher_from_local_router('bob') or LocalRouter.initialise() objPublisher = LocalRouter.getPublisher('bob') IMHO, the second case makes much more sense that a floating function which makes things less expressive. > > >>Related classes in the same file? Be careful. Doesn't anything "knowing" >>about anything else compromise encapsulation? Why would >>properly-designed classes have such a close relationship? >> >> > >Question back: why do you think having classes defined in the same file >compromises encapsulation? Classes don't know more about each other for >the fact of being written into the same file. Anyway, in Python, classes >know always too much from each other, don't they?, as there are no >access modifiers for class attributes. > > If I want to change one class and replace the file on the install then I need to put a whole bunch of classes on - increasing the change of making a mistake. Module scoping exists with globals, also you have the convetnion of creating classes with the name of _XXX to mean module level only. > > >>Having back in the day worked on big real-time systems where being very >>strict about encapsulation was a god-send for fighting complexity, I >>feel unnerved by Perl and Python's laid-back OO culture of "you can do >>it if you feel like it but don't have to". >> >> > >Well, that is the case with whatever general-purpose programming >language. You have virtually an infinite number of ways to do things, >and most of them are not appropriate. > > Some languages are more strict than others - yes you need covnentions but you will need more conventions in a less strict language. The upside is that, if you are careful, you can leverage the added oosness to implement features which would be a pain in other languages. Enterprise systems have different objectives than a cgi script or single client install stuff. It's a judgement call. >The thing with Python is, in my opinion, that it wants to put all the >power in your hands to do whatever you want in the fastest way possible. >If I want to do something, I don't declare a class that knows how to do >it, then create it and invoke the right method, I just put the code to >do what I want to do. If, in between, I find that one class would make >my life easier, I declare it just in place and go on. If I find >repetitive tasks I can declare functions, but I won't go for a class >immediately. Why do you think putting code into functions is not >encapsulating? > > > >>While you could do all manner >>of nasty hacks in C++ I worked with people who carefully avoided this. >> >> > >Well done, but messes you can do in whatever language. > > Agreed but in some languages you can cause more havoc than in others, look at the distinction .NET makes between managed and unmanaged code to get a handle on this. >Regards, >Tito > > Cheers, Neil -- 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 twic at urchin.earth.li Wed Aug 3 12:58:58 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 3 Aug 2005 17:58:58 +0100 Subject: In-place decorate-sort-undecorate - best implementation? Message-ID: Subtitle: the war on temporary objects continues! The page on python performance tips on the python.org wiki () suggests the following code for sorting a list using decorate-sort-undecorate, but doing it in-place: def sortby_inplace(somelist, n): somelist[:] = [(x[n], x) for x in somelist] somelist.sort() somelist[:] = [val for (key, val) in somelist] Doesn't the use of list comps there generate two temporary lists? Isn't that quite inefficient? Wouldn't it be better to use a good old fashioned loop? def sortby_inplace(somelist, n): for i in xrange(len(somelist)): somelist[i] = (somelist[i][n], somelist[i]) somelist.sort() for i in xrange(len(somelist)): somelist[i] = somelist[i][1] Testing this on a 10k-element list of (float, float, float, float) tuples gives me a speedup of 35%. On a million-element list it's only 4%, but hey, who sorts million-element lists anyway? I don't have python 2.4; anyone care to check how they compare there? I used the following timer function: import time import random n = 10000 r = random.random l = [(r(), r(), r(), r()) for i in xrange(n)] def time(sorter): l2 = [] l2.extend(l) t0 = time.time() sorter(l2, 2) t1 = time.time() return t1 - t0 tom -- No hay banda From http Sun Aug 7 11:13:33 2005 From: http (Paul Rubin) Date: 07 Aug 2005 08:13:33 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> Message-ID: <7xhde1pyoy.fsf@ruckus.brouhaha.com> Robert Kern writes: > As a maintainers of a convenient unified distro, I have to say that > it's a losing strategy. No matter how much you include, for every > person that tells you, "Thank you, you've made my Python experience > better," there are three who say, "Thanks, but could you also include > Package X?" or "Thanks, but Package Y is much better at doing foo than > Package Z? Could you include it next time?" or "When are you going to > update Package W to the latest version?" It doesn't appear to be a losing strategy for Java, Fedora, GCC, or for that matter Ruby on Rails. Maybe it's more work, but those distros are able to attract enough community effort and/or corporate bucks to get the work done. > You can't satisfy everyone or even a whole lot of people with a single > massive installer. People want different things. I want VTK installed > because I need 3D visualization; I couldn't care less about web > applications. But lots of other people care very deeply about web > applications and don't want to waste 100 MB of disk space on 3D > visualization libraries. If I have a 400GB hard disk in my computer, why should I care whether it's 99.5% empty instead of 99 empty after I get done installing software? > When "one-click installation" entails downloading 150 MB of compressed > data for every update, the convenience begins to pall a bit. Fedora Core is around 4GB and I installed it from a DVD-ROM pretty easily. > Fortunately, there's a better approach, and it's coming soon. The next > iteration of MacEnthon, at least, is going to be based on Python eggs > and easy_install.py. Python eggs are, more or less, Python's answer to > Ruby's gems. > > http://peak.telecommunity.com/DevCenter/PythonEggs Cool. That doc page compares them to .jar files, but I don't see any provision for signatures on them like jars have. I hope that can be added sometime. From rafi at free.fr Tue Aug 2 17:13:08 2005 From: rafi at free.fr (rafi) Date: Tue, 02 Aug 2005 23:13:08 +0200 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: <42efe1ec$0$3713$626a14ce@news.free.fr> Christoph Zwerschke wrote: > Bj?rn Lindstr?m wrote: > > I already gave the example of creating database connections > or even creating/importing whole databases. My question was, how do I > handle these cases with the standard lib unittest? I do not get why a unit test whould create/import a whole database. In order to unit test a function / method one should use mock objects, otherwise you may not be sure that your code is faulty. A mock object is an object that let the object uder test think it is connected to a database, but it is not really connected to one. This object is programmed to return well know values (correct, incorrect and exceptional ones). What you are talking about is more related to interaction / load tests and not unit tests (at least to me who am not an expert of unit testing). > According to the "extreme programming" paradigm, testing should be done > several times a day. So a requirement for extreme programm is that tests > are fast enough. If the testing needs too much time, people are > discouraged to test often. Well as I said above, a unit test is dedicated to a single function or method. So wehn you update a function / method, you should test the whole class or module, but maybe not the whole application (or the development task may have not been properly organized --splited between several developers). As someones may not write several thousand lines a day, unit tests should not be that long to run (well from my point of view, which is again not the one of an expert of unit testing). I do agree with Benjamin Niermann when he says: "Or because it is already close to perfection (at least in what it is intended to do)." unittest is for unittesting :-) my 2 cents -- rafi "Imagination is more important than knowledge." (Albert Einstein) From paolo_veronelli at tiscali.it Fri Aug 12 07:09:45 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Fri, 12 Aug 2005 13:09:45 +0200 Subject: How to Adding Functionality to a Class by metaclass(not by inherit) In-Reply-To: <42fc24cd.5258bb48.52c3.3f05@mx.gmail.com> References: <42fc24cd.5258bb48.52c3.3f05@mx.gmail.com> Message-ID: <42FC8379.9060204@tiscali.it> Dont' know where are you going with that but if what you need is cancelling some attributes when inheriting then probably this is a cleaner approach: class Meta(type): def __init__(cls, name, bases, dic): def attributeError(*_): raise AttributeError for base in bases: for dont in base.privates: setattr(cls,dont,attributeError) #override private methods class Foo(object): privates=('f',) def f(self): pass def g(self): pass class Bar(Foo): __metaclass__ = Meta b=Bar() b.g() b.f() and it implies writing only one metaclass. ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From kyle.tk at gmail.com Sat Aug 27 19:28:54 2005 From: kyle.tk at gmail.com (kyle.tk) Date: 27 Aug 2005 16:28:54 -0700 Subject: network mapper Gui question Message-ID: <1125185334.419134.288720@g43g2000cwa.googlegroups.com> I am trying to make a program much like cheops that will make a graphical representation of my network. What would be the best language to make the actuall interface in, Tkinter, wxPython, PyGtk? And in those what module would work for something like this. It needs to be able to redraw it self about every half minute or so without being to heavy on the processor. Any ideas? From tjreedy at udel.edu Wed Aug 10 00:43:51 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Aug 2005 00:43:51 -0400 Subject: Passing arguments to function - (The fundamentals are confusingme) References: <312cfe2b05080909324b1929db@mail.gmail.com> Message-ID: "Gregory Pi?ero" wrote in message news:312cfe2b05080909324b1929db at mail.gmail.com... >Ahh, so it's a mutable thing. That makes sense that I can't change a >mutable object and thus can't affect it outside of the function. You of course meant immutable, but this is still confused. It is a name-binding versus object mutation thing. > Does that mean Python functions aren't always byref, > but are sometimes byval for nonmutables? No, neither. Python functions calls are always by name binding. See my first response. You are only about the 1000th or maybe 10000th person confused by trying to apply inapplicable concepts to Python. Terry J. Reedy From jonhewer at gmail.com Fri Aug 26 08:13:51 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Fri, 26 Aug 2005 13:13:51 +0100 Subject: ideas for university project ?? In-Reply-To: References: <000801c5aa30$743e28b0$0301a8c0@Mesa.com> Message-ID: On 8/26/05, bruce wrote: > 1st question, can this be part of a startup? > 2nd question, does your university expect to own the rights/IP of your > efforts > 3rd question, are you serious, or just looking for a 'project' for a grade I am pretty sure the university will hold any rights. I am not just looking for a project for a grade, I want to do something interesting and useful, and I also need to start thinking about the future, and if I really enjoy my project then maybe it's something I'd consider focusing on in the future. > if you're serious, we can use your help! we're starting a project to create > a business dealing with used texbooks for universities on US/Canadian > college campuses. think ebay/craigslist meets the college campus. > > the project will invlove a great deal of distributed/parallel processing as > we build the grid/spidering functionality to create the underlying > databases.. I don't think my university would be too keen on this, because any work I do will, I expect, largely depend on the work of others....if something falls through then I'd be a bit screwed. But thanks anyway for the suggestion. It would, however, be perfectly acceptable to build upon a well established piece of open source software - this is very common. Thanks for all of the other suggestions, I'll research them a little bit more, and I may email some of you directly for more info if that's ok. Keep the ideas rolling :-) From rowen at cesmail.net Tue Aug 23 18:55:44 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Tue, 23 Aug 2005 15:55:44 -0700 Subject: How to get a unique id for bound methods? References: <43067d0e.1906448017@news.oz.net> Message-ID: In article , "Fredrik Lundh" wrote: >Russell E. Owen wrote: > >>>>The current issue is associated with Tkinter. I'm trying to create a tk >>>>callback function that calls a python "function" (any python callable >>>>entity). >>>> >>>>To do that, I have to create a name for tk that is unique to my python >>>>"function". A hash-like name would be perfect, meaning a name that is >>>>always the same for a particular python "function" and always different >>>>for a different python "function". That would save a lot of housekeeping. > >have you tried Tkinter's built-in _register method? > >>>> import Tkinter >>>> w = Tkinter.Tk() >>>> help(w._register) >Help on method _register in module Tkinter: > >_register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk >instance > Return a newly created Tcl function. If this > function is called, the Python function FUNC will > be executed. An optional function SUBST can > be given which will be executed before FUNC. Having looked at it again, it is familiar. I copied it when I wrote my own code. I avoided using at the time both because the initial underscore suggested it was a private method and because it introduces an extra function call. _register has the same weakness that my code had when I used id(func) -- it uses the id of the function to generate the unique tk function name, but it keeps no reference to that function. Either Tkinter is clever about keeping a reference to each callable around, or else it has the same bug I was seeing and it just doesn't show up often enough to have been caught. I should take some time and look into that. It's a frustrating problem. There should be some simple way to get a unique hash-like identifier for any callable entity. If one were just using functions then id() would be fine. But bound methods are too different. I'll use "hash" for now, but given that I"m not sure what hash is even doing, I should recode to something that I know works. -- Russell From nomail at nomail.com Wed Aug 17 09:27:20 2005 From: nomail at nomail.com (Nx) Date: Wed, 17 Aug 2005 21:27:20 +0800 Subject: Need better way to unpack a list References: Message-ID: <43033b51@127.0.0.1> > for index, value in enumerate(mylinelist): > getattr(self,?"line%d"?%?(index?+?1)).setText(value) Thanks ! This was the line which did it .... The correct code snippet now reads : # set the lineedits of the QT gui for index,value in enumerate(self.mylinelist): getattr(self, "lineEdit%d" % (index + 1)).setText(self.tr(value)) Nx From bokr at oz.net Wed Aug 24 05:41:50 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 24 Aug 2005 09:41:50 GMT Subject: Anyone recognize this numeric storage format - similar to "float", but not quite References: <1124849085.656718.97720@g43g2000cwa.googlegroups.com> Message-ID: <430c3fc2.2283972098@news.oz.net> On 23 Aug 2005 19:04:45 -0700, geskerrett at hotmail.com wrote: >We are working on a project to decipher a record structure of an old >accounting system that originates from the late80's mid-90's. >We have come across a number format that appears to be a "float" but >doesn't match any of the more standard implementations. >so we are hoping this is a recognizable number storage format with an >identifiable name AND pre-built conversion method >similiar to the "struct" modules available in python. > >Here is what we have determined so far. > >Example Number: 1234567890 > >This get stored on disk as 8 bytes, resulting in the following HEX >characters; >00 00 00 A4 05 2c 13 9f > >If we changed the order so that it is "little Endian" we get; >9F 13 2c 05 A4 00 00 00 > >If the HEX is converted to binary it looks like; >10011111 00010011 00101100 00000101 10100100 00000000 000000000 >00000000 > >If the example number 1234567890 is converted to binary it looks like; > >10010011 00101100 00000101 1010010 > >To extract the example number, you need to do the following; >1) take the decimal value of the first byte and subtract 128 >2) This tells you how many of the following bits to are significant and >must be read >3) Once the remaining bits are read, reverse the first bit of that >group (ie if it is a 0 make it a 1) >4) convert the result to decimal >... and presto, the example number ! > >Using a fixed width font it is easy to see the match at the bit level; > >10011111 00010011001011000000010110100100000000000000000000000000 >-------- 1001001100101100000001011010010 > > >If you are interested, the following are three other examples; > > Orig Hex: 00 00 00 60 92 96 72 A0 >Actual Value: 4069954144 > > Orig Hex: 00 00 80 22 A3 26 3C A1 >Actual Value: 6313297477 > > >So ... does anyone recognize this ?? >Is there a "built-in" conversion method in Python ?? > >Thanks in advance. > Not looking too closely, but I recall something similar (although I suspect that the bit you are "reversing" is a sign bit that shadows a known constant MSB 1 for non-zero numbers, and shouldn't just be reversed): http://groups.google.com/group/comp.lang.python/browse_thread/thread/42150ccc20a1d8d5/4aadc71be8aeddbe#4aadc71be8aeddbe Regards, Bengt Richter From tjreedy at udel.edu Sat Aug 6 20:04:28 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 6 Aug 2005 20:04:28 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com><11f84j8elj07271@news.supernews.com><861x57wrui.fsf@bhuda.mired.org><11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> Message-ID: "John Roth" wrote in message news:11f9u843r0fts5b at news.supernews.com... > Maybe "fat and happy" wasn't the best choice of words Depends on the reaction you wanted ;-) > However. I see nothing in the existing Python 3000 PEP that does > anything other than inspire a yawn. Sure, it's a bunch of cleanup, and > some of it is definitely needed. What I don't see is the inspired leap > forward that will once again put Python in the forefront rather than > simply being one choice among many. My response is more than a yawn, but yes, the most exciting thing that I see is completion of the generator revolution started a few years ago. > What I want to see in Python 3000 is an AST based language [much more > snipped] I presume you mean AST as in human-comprehension oriented AST as in http://docs.python.org/lib/module-compiler.ast.html. If I understand correctly, you are proposing that the essence of a Python program be its logical tree structure rather than its surface presentation. And this would be understood even if the developers also promoted a particular presentation as the 'preferred', 'official', or 'commonly shared' presentation. And this might include a tree serialization format different from the presentation test format. Yes, this is an interesting idea. Perhaps, if you can flesh it out a bit and leave out stuff like 'fat and happy', you could write and submit a PEP. Some of the developers are trying to finish the AST compiler before 2.5. If this means what I think it does, compiling ASTs direct to bytecode, it would be an essential component of your proposal and make it more possible. But I don't know much more about it. I also know little about what intermediate forms PyPy used to compile Python code. Terry J. Reedy From opengeometry at yahoo.ca Mon Aug 8 16:30:23 2005 From: opengeometry at yahoo.ca (William Park) Date: Mon, 08 Aug 2005 16:30:23 -0400 Subject: Splitting a string into groups of three characters References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: lemon97 at gmail.com wrote: > Hi, > > Is there a function that split a string into groups, containing an "x" > amount of characters? > > Ex. > TheFunction("Hello World",3) > > Returns: > > ['Hell','o W','orl','d'] > > > Any reply would be truly appreciated. Look into 're' module. Essentially, split using '...', but return the separator as well. Then, remove empty items. In Bash shell, you would do a="Hello World" set -- "${a|?...}" # extract '...' separators pp_collapse # remove null items printf '{%s}\n' "${@}" Translating to Python is left as homework. -- William Park , Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From bronger at physik.rwth-aachen.de Sat Aug 6 02:52:35 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Sat, 06 Aug 2005 08:52:35 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <87wtn245qo.fsf@wilson.rwth-aachen.de> <86slxpyxp2.fsf@bhuda.mired.org> <873bporhgm.fsf@wilson.rwth-aachen.de> <86mznvyge7.fsf@bhuda.mired.org> Message-ID: <87oe8bblqk.fsf@wilson.rwth-aachen.de> Hall?chen! Mike Meyer writes: > Torsten Bronger writes: > >> [...] > > I notice that the Wikipedia doesn't have a definition for "special > purpose language", instead preferring the phrase "Domain Specific > Langauge". That matches the definition that agrees with what I > think is common usage, which is: > > Trade some of the flexibility of a general purpose language > for capabilities that are more tailored to a specific task > > Fortran certainly meets the requirements the wikipedia has for > being a general purpose language. As does TeX. I don't think that this adds anything to the argumentation. >>> [...] Just like some C/C++ applications are legacy code, and some >>> aren't. Which contradicts your earlier assertion that C/C++ >>> applications were all legacy code. >> >> Reference? > > See http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/c52d3c17f1ea9ec5/d2013c3f1eef49b9?q=wheel+reinvention&rnum=1#d2013c3f1eef49b9 >>, where you dismiss all C applications a legacy code. This URL points to an article by Paul McNett. Probably you mean >>> [...] By which measure C is still immensely popular, because of >>> the large number of older applications that are written in it >>> that are available - Python being one such. > > Legacy code is not a sign of success IMO because it implies a > difficult future. Calling "older applications" "legacy code" is very different from calling C/C++ a legacy code language. > [...] > >> [...] I just want to use a popular langauge amongst the ones >> that have free success ("free" in the sense of Free Software). > > These leaves me with three questions for you: > > Is there a free language you consider successful? Before the quibbling starts again: What do you mean with "free language"? For me, that's every language that I can use using exclusively Free Software tools. > [...] > > Are there any free language that have the GUI/IDE toolkit you > want? I don't know. I haven't seen it yet. Maybe Eclipse + SWT? > Have you noticed that languages with really cool features aren't > very popular? This is probably true, but "really cool features" tend to become "exotic features". I don't need them, neither the masses. A good GUI toolkit is a nice "cool thing" to have. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From dcrespo at gmail.com Mon Aug 15 10:11:18 2005 From: dcrespo at gmail.com (dcrespo) Date: 15 Aug 2005 07:11:18 -0700 Subject: SOAP and XMLRPC In-Reply-To: References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Message-ID: <1124115078.926129.285880@f14g2000cwb.googlegroups.com> Hi... Thanks for your answer, but can you give me his contact or tell him to post here the answer I'm looking for? I'm needing it seriously. From uomart at ihug.co.nz Mon Aug 15 21:38:36 2005 From: uomart at ihug.co.nz (Mulac) Date: Tue, 16 Aug 2005 13:38:36 +1200 Subject: Is Tkinter compatible with GNOME? References: <1124151250.604911.64920@g14g2000cwa.googlegroups.com> Message-ID: <002701c5a203$39fa8c50$5700a8c0@rmse> ----- Original Message ----- From: Newsgroups: comp.lang.python To: Sent: Tuesday, August 16, 2005 12:14 PM Subject: Re: Is Tkinter compatible with GNOME? > Have you tried starting it in a .xsession file with something like: > exec gnome-session & > button_prog.py > Doesnt .xsession only get invoked after someone has successfully logged into an account? I need the button_prog to be running in the background before anyone logs into the system. Ultimately, I want the person logging in to be able to press a button instead of having to enter a username and password. From jitendran at productdossier.com Thu Aug 18 00:11:58 2005 From: jitendran at productdossier.com (jitya) Date: 17 Aug 2005 21:11:58 -0700 Subject: As Simple As Possible? Message-ID: <1124338318.133726.304370@g49g2000cwa.googlegroups.com> Chuck Allison says: After three years of study, I have concluded that Python is about as simple as a full-powered object-oriented language can get. My inner programmer just loves it. In a recent interview Scott Meyers was asked which language he thought would be ideal for introducing programming to novices. He replied: "... a first language should foster a feeling of power and accomplishment out of the box - it should get people excited about the limitless things that can be accomplished in software. Among other things, such a language would offer an extensive and powerful library..." [1] I know of no language to which these words apply more than Python. LINK: http://www.artima.com/cppsource/simple.html From lycka at carmen.se Fri Aug 5 12:29:10 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 05 Aug 2005 18:29:10 +0200 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <42f37b5a$0$11075$e4fe514c@news.xs4all.nl> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <42f37b5a$0$11075$e4fe514c@news.xs4all.nl> Message-ID: Martin P. Hellwig wrote: > Kevin wrote: > > > Well, for some strange reason I have never found that to be a problem. If you develop software for an external customer, and they have an existing web site run by some ISP that you have no control over, this might well be a problem. Even if the customer is in control of their web servers, it might be difficult to convince them to install and maintain something like Python on them. I find it a bit surprising that so many people on comp.lang.python don't realize what kind of practical complications most commercial software developers have to struggle with if they don't just follow the mainstream and use PHP or Java for all web apps. My ISP (FS Data in Sweden) has Python installed, and always upgraded it when I asked them (but only then, so I suspect I'm the only user-- and this is one of the biggest ISPs in Sweden). Even if I have access to Python, they don't allow me to have my own long running processes, so I'm stuck with CGI, which wouldn't work very well with a much higher load than my moin has. (Actually, I didn't really need more, so I haven't asked for mod_python support etc.) Colocation is certainly getting much cheaper, my ISP charges much less than 95EUR/month.(295 SEK). Still, it would certainly be great if mod_python, twisted and zope support etc would be as common as mod_perl or PHP support. We can only get that if we actively ask for it, and if we really favour vendors that provide this support when we can. From mwm at mired.org Thu Aug 4 20:37:05 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 04 Aug 2005 20:37:05 -0400 Subject: Python IDE's References: <20050731205901.53A6E1E4005@bag.python.org> <1122915471.559698.231740@g43g2000cwa.googlegroups.com> <42f0a19b$0$15707$626a14ce@news.free.fr> Message-ID: <861x591aoe.fsf@bhuda.mired.org> bruno modulix writes: > Jon Hewer wrote: >> I do use Vim a lot. I am currently using it for some PHP development >> i'm doing. I'm been using it so much recently that i keep pressing >> ESC and typing vi commands out of vi. >> >> But, if i use Vi, then whenever i want to test some code i have to >> open up python, import the necessary modules and run it - I like the >> idea of developing python in an IDE and just hitting a run button. > > the Emacs + python-mode combo solve this problem - and in fact gives > much more than the common "run and print results" feature of most IDEs, > since you can run either the whole script or any part of it in an > (embedded) interactive python shell - just as if you had copy/pasted the > code in the python shell... This is very useful for exploring/quick > testing. You may want to use Emacs VI mode as well, so that when you press ESC and type vi commands, it has a chance of working. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jonny.longrigg at gmail.com Wed Aug 24 11:40:44 2005 From: jonny.longrigg at gmail.com (jonny.longrigg at gmail.com) Date: 24 Aug 2005 08:40:44 -0700 Subject: Default function arguments behaving badly Message-ID: <1124898044.569156.217700@g49g2000cwa.googlegroups.com> Hi I'm having some trouble with a function I've written in Python: def myFunction(l1,l2,result=[]): index=0 for i in l1: result.append([]) if type(i)==list: myFunction(i,l2,result[index]) else: for j in l2: result[index].append(i*j) index+=1 return result l1 and l2 are lists and the function multiplies every element of l1 with every element of l2. l1 is (possibly) multi-dimensional, and the recursive bit is in there to cope with that. For example, if l1=[[1,2],[3,4]] and l2=[5,6] the result is [[[5,6],[10,12]],[[15,18],[20,40]]]. The problem is that it works if I run it once, but then on repeated runs the value for 'result' doesn't seem to set itself to my default of [], but instead uses the state it was in last time the function was run. I've had a problem like this in the past and ended up rewriting the function as a class and using something like self.result, but I don't really like this solution as the code becomes considerabley more difficult to read (and I suspect less efficient). Also, I suppose I could feed in an empty array every time but that doesn't provide a very intuitive interface to the function. Does anyone know what is going on here? Is there an easy solution? Thanks for your help! From peter at engcorp.com Mon Aug 29 09:04:46 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 29 Aug 2005 09:04:46 -0400 Subject: close failed: [Errno 0] No error goes to stdout In-Reply-To: <4312c4bc$1@news.bezeqint.net> References: <4311b9bf@news.bezeqint.net> <4312c4bc$1@news.bezeqint.net> Message-ID: <-LednS5S7qlxmo7eRVn-sw@powergate.ca> (Please don't top-post. It makes quoting difficult and it's hard for people to follow the conversation.) Yoav wrote: > I run a Java command line program. The point is, that it's not the > program that output this error message for sure. Okay. Since you don't provide any proof, we'll have to take you at your word. In that case, please provide the *complete traceback*, cut and pasted from your console window. Don't just retype the error message. Generally people leave out crucial information when they do that. The traceback (which Python will always print when it raises an exception) shows the failing line of code and the stack trace. With it we can help you troubleshoot the problem. Without it, you haven't provided enough information yet for anyone to do more than guess. -Peter From lbates at syscononline.com Wed Aug 24 19:02:17 2005 From: lbates at syscononline.com (Larry Bates) Date: Wed, 24 Aug 2005 18:02:17 -0500 Subject: Exploring outlook using python In-Reply-To: <1124911125.270274.291090@g47g2000cwa.googlegroups.com> References: <1124911125.270274.291090@g47g2000cwa.googlegroups.com> Message-ID: <430CFC79.1060807@syscononline.com> You should download source for spambayes plug-in for Outlook (written in Python) located at: http://spambayes.sourceforge.net/windows.html You might finds LOTS of good information for your project. -Larry Bates Subir wrote: > Hi, > > I am new to this group. I am trying to build an application to see > all the contents of the outlook accounts (USING MAPI). Does anyone has > any information regarding this ? > From newsgroups at jhrothjr.com Sat Aug 6 13:58:53 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 6 Aug 2005 11:58:53 -0600 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <11f9uj0mbltfsd0@news.supernews.com> "Paolino" wrote in message news:mailman.2782.1123345903.10512.python-list at python.org... > seberino at spawar.navy.mil wrote: >> I've heard 2 people complain that word 'global' is confusing. >> >> Perhaps 'modulescope' or 'module' would be better? >> >> Am I the first peope to have thought of this and suggested it? >> >> Is this a candidate for Python 3000 yet? >> >> Chris > > I don't think the global keyword is useful actually. > > What's so special in a module nemespace to be priviledged like that. > The point IMO is accessing names defined somewhere in the enclosing > namespaces. The issue isn't _accessing_ the module namespace. It's binding to identifiers in the module namespace. The reason is that _assigning_ to an identifier in a function or method makes that identifier local, so there needs to be a simply way of saying that you want to be able to assign to an identifier in the module namespace. (There's already a more complicated way: use the global() built-in function.) John Roth > Regards Paolino From http Sun Aug 7 05:46:00 2005 From: http (Paul Rubin) Date: 07 Aug 2005 02:46:00 -0700 Subject: Some newbie cgi form questions... References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> <1123407278.841972.113690@g44g2000cwa.googlegroups.com> Message-ID: <7xk6iy6pwn.fsf@ruckus.brouhaha.com> "Atila Olah" writes: > for key in form.keys(): > if not form.keys()[key]: # True if it's a value is None Ugh! I think you mean for key, value in form.items(): if not value: These days you can also say iteritems instead of items and avoid building a potentially large list in memory. From rowen at cesmail.net Fri Aug 19 16:29:19 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Fri, 19 Aug 2005 13:29:19 -0700 Subject: How to get a unique id for bound methods? Message-ID: I have several situations in my code where I want a unique identifier for a method of some object (I think this is called a bound method). I want this id to be both unique to that method and also stable (so I can regenerate it later if necessary). I thought the id function was the obvious choice, but it doesn't seem to work. The id of two different methods of the same object seems to be the same, and it may not be stable either. For instance: class cls(object): def __init__(self): print id(self.meth1) print id(self.meth2) def meth1(self): pass def meth2(self): pass c = cls() 3741536 3741536 print id(c.meth1) 3616240 print id(c.meth2) 3616240 I guess that just means bound methods aren't objects in their own right, but it surprised me. The "hash" function looks promising -- it prints out consistent values if I use it instead of "id" in the code above. Is it stable and unique? The documentation talks about "objects" again, which given the behavior of id makes me pretty nervous. Any advice would be much appreciated. -- Russell From zarnovican at gmail.com Fri Aug 19 06:58:15 2005 From: zarnovican at gmail.com (BranoZ) Date: 19 Aug 2005 03:58:15 -0700 Subject: Implementing class methods in C References: Message-ID: <1124449094.968629.117400@g47g2000cwa.googlegroups.com> nmichaud at jhu.edu wrote: > Am I misunderstanding the purpose of PyObject* self? No. I think you do everything right, but it still doesn't work. I have tried to implement it in Python: ---------------------------------------------------- _test.py: def func2(self, *args): print type(self) print args then all of this works: ---------------------------------------------------- import _test class Test1: func2 = _test.func2 class Test2: pass Test2.func2 = _test.func2 class Test3: pass import new Test3.func2 = new.instancemethod(_test.func2, None, Test3) del new Test1().func2(1, 2, 3) Test2().func2(1, 2, 3) Test3().func2(1, 2, 3) If you implement _test in C, works none of the above. The only difference I can see is that: type(_test.func2) is for Python implemented function and type(_test.func2) for C implementation I would really like to know the answer too. How do you implement some methods in C without subclassing ? BranoZ From kenneth.m.mcdonald at sbcglobal.net Tue Aug 30 22:36:20 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Tue, 30 Aug 2005 21:36:20 -0500 Subject: suggestion for Python graphing package, please In-Reply-To: References: Message-ID: <88A5C539-59BF-4E80-94AB-61F3D0C1FF30@sbcglobal.net> I haven't looked at it for a while, but when I was looking at it, MatPlotLib was great (though the API was still in flux). I'd assume it's become even better since then and I certainly hope so, because I'm planning on using it again soon :-). Ken On Aug 29, 2005, at 3:36 PM, Robert Kern wrote: > Stewart Midwinter wrote: > >> I need a graphing library that I can access from within a Tkinter >> application running on Windows. >> > > http://matplotlib.sourceforge.net > From skip at pobox.com Tue Aug 9 11:56:21 2005 From: skip at pobox.com (skip at pobox.com) Date: Tue, 9 Aug 2005 10:56:21 -0500 Subject: sqlobject vs mysqldb module In-Reply-To: <1123602281.268415.288590@o13g2000cwo.googlegroups.com> References: <1123602281.268415.288590@o13g2000cwo.googlegroups.com> Message-ID: <17144.53797.920058.393600@montanaro.dyndns.org> yaffa> i have a python script that scrapes contents from an html file yaffa> and i would like to have the script write values to a mysql db. yaffa> do you recommend i go with the sqlobject or the mysqldb module? They are really quite different beasts. You'll have to consider your requirements to decide which to use. -- Skip Montanaro skip at pobox.com From peter at somewhere.com Wed Aug 31 09:35:08 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 15:35:08 +0200 Subject: module not found in IIS virtual dir In-Reply-To: References: Message-ID: Peter Maas schrieb: > I'm trying to call python scripts from IIS in the following tree: [...] > If I run selectFiles.py from the command line everything is ok. But > if I call it via IIS (http://localhost/vselect/selectFiles.py) there > is an error "No module named util" [...] Forget it. It was an ACL issue. Silly mistake. -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From gelios at rbcmail.ru Tue Aug 16 12:48:36 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Tue, 16 Aug 2005 20:48:36 +0400 Subject: MainThread blocks all others References: <42f9d4ef_2@news.isis.de> <42fa0457_2@news.isis.de> <42fb151d_1@news.isis.de> <1hrmf1hs9lss8m9sb44o6ik1trturj9jil@4ax.com> Message-ID: Thank you very much to all. I found out solution. I created separate thread from GUI and everything is working correct. Best Regards, /Gelios From spam.csubich+block at block.subich.spam.com Thu Aug 4 00:47:23 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Thu, 04 Aug 2005 00:47:23 -0400 Subject: Python's CSV reader In-Reply-To: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> Message-ID: Stephan wrote: > Can the CSV module be coerced to read two line formats at once or am I > better off using read and split? Well, readlines/split really isn't bad. So long as the file fits comfortably in memory: fi = open(file) lines = fi.readlines() evens = iter(lines[0::2]) odds = iter(lines[1::2]) csv1 = csv.reader(evens) csv2 = csv.reader(odds) The trick is that the "csvfile" in the CSV object doesn't have to be a real file, it just has to be an iterator that returns strings. If the file's too big to fit in memory, you could piece together a pair of iterators that execute read() on the file appropriately. From renzoPUNTOgiust at email.it Thu Aug 11 05:27:56 2005 From: renzoPUNTOgiust at email.it (Renzo) Date: Thu, 11 Aug 2005 11:27:56 +0200 Subject: zipfile library - problem.. Message-ID: Hi, I'm working to create a backup function for a software; in particular, from a directory with 12300 files (Jpg, medium size = 250KB / total size = 2.90GB), i have to create a zip file. I've decided to use the standard "zipfile" library to do that. This is the code: zipName = path.join(config.get('server.xbakPath'), 'backup.zip') fileExport = zipfile.ZipFile(zipName,'w',zipfile.ZIP_DEFLATED) #Insert images listaImg = listdir( config.get('server.iPath') ) for file in listaImg: if not path.isdir(path.join(config.get('server.iPath'), file)): fileExport.write(path.join(config.get('server.iPath'), file), \ file) #close ZIP fileExport.close() Unfortunately, after few minutes, i see this error message: Traceback (most recent call last): File "C:\Python24\Lib\site-packages\cherrypy\_cphttptools.py", line 256, in run main() File "C:\Python24\Lib\site-packages\cherrypy\_cphttptools.py", line 452, in main body = func(*(virtualPathList + cherrypy.request.paramList), File "C:\pagine\utilities.py", line 162, in exportdati fileExport.close() File "C:\Python24\lib\zipfile.py", line 503, in close zinfo.header_offset) OverflowError: long int too large to convert to int Reading the error I've known that the error is generated calling "fileExport.close()", that calls the zipfile module, and into that module there is an exception. For information: when code stops, the zip file has size = 3.177.950.237 byte, but this size doesn't exceed ZIP limits: the limits of ZIP files according to the folks who make info-zip: http://www.info-zip.org/pub/in fozip/FAQ.html#limits statistic limit number of files 65,536 uncompressed size of a single file 4 GB compressed size of a single file 4 GB total size of archive 256 TB maximum path/filename length 64 KB Have you any idea? Oh, the O.S. is WinXP Pro Thank you!. Renzo From rafi at free.fr Tue Aug 23 07:58:17 2005 From: rafi at free.fr (rafi) Date: Tue, 23 Aug 2005 13:58:17 +0200 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: <430b0f50$0$10086$626a14ce@news.free.fr> Antoon Pardon wrote: > In that case you wouldn't return an empty sequence if you wanted > a false value in a sequence context but would throw an exception. > So this would be fine by me, I just don't understand how this > would support the use of empty sequences as false. > > I also don't see how a read from a network connection returning > either: > > a bytestring when data is available, > '' when no data is available > None when the connection was closed I do not get why returning '' when no data is available? If no data is available then nothing is returned, the function hangs. (Which is the cas for receive) -- rafi "Imagination is more important than knowledge." (Albert Einstein) From http Sat Aug 20 03:32:42 2005 From: http (Paul Rubin) Date: 20 Aug 2005 00:32:42 -0700 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> Message-ID: <7xvf2183mt.fsf@ruckus.brouhaha.com> Mike Meyer writes: > > I don't see much point in trying to convince programmers that > > they don't really want concurrent threads. They really do. Some > > don't know how to use them, but that's largely because they > > haven't had them. I doubt a language for thread-phobes has much > > of a future. > > The real problem is that the concurrency models available in currently > popular languages are still at the "goto" stage of language > development. Better models exist, have existed for decades, and are > available in a variety of languages. But Python's threading system is designed to be like Java's, and actual Java implementations seem to support concurrent threads just fine. One problem with Python is it doesn't support synchronized objects nearly as conveniently as Java, though. You need messy explicit locking and unlocking all over the place. But it's not mysterious how to do those explicit locks; it's just inconvenient. From peter at engcorp.com Mon Aug 22 17:15:59 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 17:15:59 -0400 Subject: Sandboxes In-Reply-To: References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: 42 wrote: > I was planning on "sanitizing" the language instead of relying on rexec > and bastion so issues with them shouldn't be relevant. I think in dealing with security, deciding what might be relevant before you fully understand the problem is somewhat premature... but it's your neck. :-) > I'm curious about the 'other' stuff that was alluded to, that could > still occur in a python with all its __import__, import, exec, eval, and > various reflection/metadata builtins prohibited (e.g. getattr)... Okay, but are you saying that combining those keywords with "security" when searching comp.lang.python in Google Groups produced no useful results? When I do it, I generally get to threads where somebody rushes in with suggestions about how to add security where the core Python people fear to tread (so to speak), and after a short period of back and forth where each idea is quickly shot down, the thread sort of dies out as (I suspect) the OP realizes the problems are fundamental and probably can't be fixed without changes to the Python core itself, or at least can't be fixed *with confidence* without a thorough security audit which so far nobody has valued enough to actually do. -Peter From deets at web.de Thu Aug 18 17:44:44 2005 From: deets at web.de (Diez B. Roggisch) Date: 18 Aug 2005 14:44:44 -0700 Subject: Really virtual properties In-Reply-To: <87slx7c4g5.fsf@wilson.rwth-aachen.de> References: <87slx7c4g5.fsf@wilson.rwth-aachen.de> Message-ID: <1124401484.266696.217420@f14g2000cwb.googlegroups.com> I don't think so - the reason is that property() is evaluated in the baseclass, and stores a callable, not a name. the only thing you could do is either - create a level of indirection, using lambda, to force the lookup: x = property(lamda self: self.get_x()) - use a metaclass, that tries to scan the baseclass for properties that uise functionnames which are redefined in the current class, and recrerate a new property for those. Diez From i.dont.like.spam at invalid.com Fri Aug 12 08:05:14 2005 From: i.dont.like.spam at invalid.com (Thomas Fritsch) Date: Fri, 12 Aug 2005 12:05:14 GMT Subject: Jargons of Info Tech industry In-Reply-To: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <1123848314.548169@igate1.ops.de> Xah Lee wrote: > [...] > My time is limited, so i'll just give a brief explanation of my thesis > [...] This is what psychology calls a disordered self-perception. -- "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@') From skip at pobox.com Sun Aug 21 18:57:06 2005 From: skip at pobox.com (skip at pobox.com) Date: Sun, 21 Aug 2005 17:57:06 -0500 Subject: Python Light Revisted? In-Reply-To: <6Jydnde_uvYa8JreRVn-gw@comcast.com> References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> Message-ID: <17161.1730.979635.420811@montanaro.dyndns.org> Ramza> The goal, build python(mainly for win32) so that the ENTIRE Ramza> install is maybe less than 5MBs and includes possibly a GUI Ramza> library, possibly TwistedMatrix, possibly install from just Ramza> unzipping an archive like applications such as Eclipse. ... Ramza> Why? For example, I don't need an XML-RPC library, or zip Ramza> library, or the other libraries. Let's suppose I decided to take your bait and build a python-lite distribution (fyi, I'm not biting). How would I know what to remove and what to retain? Some choices would be simple. If I was targeting Win32 I could clearly leave out Mac- or Unix-Specific stuff. I could probably dispense with the docs on the premise that you could read them online. How would I decide whether to keep or toss xmlrpclib or zipfile? If I keep xmlrpclib should I also keep SimpleXMLRPCServer? What about unicodedata (it's a biggie)? What about compatibility? If someone installs the python-lite distro then downloads, let's say, Tailor, a version control converter. What are the chances that it will croak with an ImportError? Put another way, are you really willing to trade off a few megs of disk space against almost certain breakage at some point in the near future? I can understand that distributions for some platforms (PalmOS, OS/2, Amiga, Jython) might contain fewer modules simply because not everything has been ported to them, but given the cost of disk space today I don't understand why a distribution for a mainstream platform should be hobbled. Skip From jaywgraves at gmail.com Thu Aug 25 13:31:03 2005 From: jaywgraves at gmail.com (jay graves) Date: 25 Aug 2005 10:31:03 -0700 Subject: Speed quirk: redundant line gives six-fold speedup References: Message-ID: <1124991063.207887.266560@g14g2000cwa.googlegroups.com> Mark Dickinson wrote: > Questions: > (1) Can anyone else reproduce this behaviour, or is it just some quirk > of my setup? yes. I get 7 sec vs 1 sec on my laptop. > (2) Any possible explanations? Is there some optimization that kicks > in at a certain number of lines, or at a certain length of > bytecode? I don't think there are any optimizations at play here. > (3) If (2), is there some way to force the optimization, so that I can > get the speed increase without having to add the extra lines? When I start a python interpreter and import the module the speed difference disappears and it actually gets about two times faster. YMMV. I don't have a solution but I admire the problem. [1] ... jay [1] Google tells me that this is probably attributable to Ashleigh Brilliant. From zen19725 at zen.co.uk Wed Aug 3 14:13:11 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 19:13:11 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: On Wed, 03 Aug 2005 16:57:34 +0100, Michael Sparks wrote: >I've reordered the q's slightly to avoid repetition... Also by answering >this question first, it may put the rest of the answer into context >better. > >phil hunt wrote: > >> At what stage of completion is it? > >This is something we deliberately try to reflect in the version number. >Yes, you can build network servers and new protocols relatively simply >at the moment. Yes, you can integrate with pygame in a limited useful >fashion at present. Yes we have audio playback. > >However we don't have yet... (some examples) > * Decent GUI integration yet. > * /Full/ pygame integration. > * Nice integration with pymedia > * Direct support for Dirac. >Which aside from other things means you can't build (say) a video >& SMIL playback system trivially, yet. Isn't SMIL something that's goinhg to go into web browsers? In which case, you'd presumably not want to build one yourself, I imagine? >> There's plenty of software that facilitates networking, for example >> Python already has software for tcp and http clients/servers, and >> for xmlrpc remote procedure calls. > >There is indeed. > >> So what does Kamaelia do that's extra? I imagine it's to to with >> streaming large amounts of data. For example, a streaming video or >> audio player. Or VoIP, perhaps. > >It's designed to make bolting things together to make these sorts of >system simpler and easier. What you say "bolting things together" do you mean writing Python code? Or will there be some other way? What I have in mind is something like a project I worked on some time ago, where a program could be written by drawing boxes on a GUI application, and drawing lines (representing data flow) to connect the boxes. So one half of a VoIP application might look like: +----------+ +------------+ +-----------+ | listen | | convert to | | volume | | on udp |====>| audio |====>| control + | | port 600 | | stream | | output | +----------+ +------------+ +-----------+ With something like this novel multimedia apps could be prototyped quickly (though making them into useful apps would take extra work -- in the case of a VoIP application you'd want a phonebook, for example). >At the same time it's designed to encourage >writing code in a way that makes it simpler. Examples would be useful here. Both of what it can do now, and what it will be able to do eventually. >The natural side effect of >this is the system might make it easier to take advantage of multiple >CPU systems as they come online, since it makes a system naturally >concurrent. As the original announcement said "Kamaelia is designed as >a testbed". And by testbed I mean testbed as it testing out new ideas, >see if they work and see if they pan out. (Not as in a testing suite) So what it will eventually do is not cast in stone? >Probably the best way of describing the difference is this... After my >talk about Kamaelia at Europython, I had an long chat with Tommi >Virtinan about integration between Kamaelia and Twisted. I haven't had >a chance to follow up with him yet regarding how this would work, though >I have set a line in the sand aiming to have easy integration between >Kamaelia and Twisted before Kamaelia hits version 1.0.0. The impression >I got from Tommi was that he was most interested in the communications >aspect - the fact we can bolt together systems in a manner directly >akin to Unix pipelines, though I suspect he found the graphines aspect >more interesting. > >Or as someone asking a similar question at Open Tech exclaimed after >I finally managed to explain it better to them "Ooooh - you're trying >to make concurrency EASY!". > >> OK, so what do the components in the pipelines do? What sort of data >> do they hold? Unix pipelines act on ascii files; I assume you are >> do this on audio and visual data. What langauage will the ele,ments >> in thne pipelines be written it? I assume some will be in C/C++ for >> speed. > >Components are object instances of python classes. The data passed >between components are object instances. What sort of objects? For example, if an application is audio straming, what sort of objects will be passed? Will there be onre object passed for each 10 ms or so of sound, or will there be a continuously-set-up object that passes the data throught it a byte at a time? And if it's written in Python, will it run fast enough? >Clearly these python classes >can be written in python, C, C++, pyrex etc. Currently all of Kamaelia's >components are python based. Some existing components make calls >into some related C libraries via python bindings.. An example of >writing a component using Pyrex can be found here: > * http://kamaelia.sourceforge.net/PyrexComponents.html My thought on this example: cdef class test(Axon.Component.component): def mainBody(self): if self.dataReady("inbox"): data = self.recv("inbox") self.send(data, "outbox") return 1 My first impressions are that it seems obvious to me what this does: it merely passes its input throught to its output (no doubt there are places where such a null component is useful). Hopefully all code written with Kamaelia will be so clear. Now I have some questions. 1. mainBody() is evidently being called at intervals. At what frequency are these intervals? For example, if the data stram is video data, will mainBody() get called once for each frame? 2. what data type is (data) in the code? Or can it be any type? -- Email: zen19725 at zen dot co dot uk From zen19725 at zen.co.uk Mon Aug 1 03:53:24 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 1 Aug 2005 08:53:24 +0100 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> Message-ID: On Sun, 31 Jul 2005 08:02:43 -0400, Ed Leafe wrote: >On Sunday 31 July 2005 01:02, phil hunt wrote: > >> You mightn't have, but I suspect more Python programers who've >> written GUI apps have used Tkinter than any of the other APIs. >> >> Not that I'm a particular fan of it, it's just I like >> standardisation, because then you get network effects. > > At PyCon DC 2004, Guido was asked about wxPython: "wxPython is the best and >most mature cross-platform GUI toolkit, given a number of constraints. The >only reason wxPython isn't the standard Python GUI toolkit is that Tkinter >was there first." I was under the impression -- from reading this ng -- that wx was buggy on some platforms and less portable than Tkinter. Not true? -- Email: zen19725 at zen dot co dot uk From peter at engcorp.com Mon Aug 29 17:20:53 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 29 Aug 2005 17:20:53 -0400 Subject: python and ajax In-Reply-To: References: Message-ID: Steve Young wrote: > Hi, I was wondering if anybody knew of any good > tutorial/example of AJAX/xmlhttprequest in python. > Thanks. I can't say if it's "good" since I haven't looked at it yet, but it's certainly timely: this was just posted to the c.l.p.announce group: ---------------------------- A simple server which enables Python regular expression tests in a webbrowser. Uses SimpleHTTPServer and AJAX. You need: Python, a modern webbrowser like Firefox, IE (from 5.5), Safari) which handles XMLHttpRequests. Currently works best with Firefox, any feedback is welcome. download -------- retest-0.3.zip - 050828 http://cthedot.de/retest/retest-0.3.zip ----------------------------- -Peter From mwm at mired.org Fri Aug 5 21:59:28 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 05 Aug 2005 21:59:28 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <87wtn245qo.fsf@wilson.rwth-aachen.de> <86slxpyxp2.fsf@bhuda.mired.org> <873bporhgm.fsf@wilson.rwth-aachen.de> Message-ID: <86mznvyge7.fsf@bhuda.mired.org> Torsten Bronger writes: > Hall??chen! > Mike Meyer writes: >> Torsten Bronger writes: >>> Mike Meyer writes: >>>> Torsten Bronger writes: >>>>> Mike Meyer writes: >>>>>> Torsten Bronger writes: >>>>>> [...] You didn't answer the question about how you define >>>>>> agile project. Please do so if you expect a comment on this. >>>>> Projects with a high Sourceforge activity index. >>>> That doesn't seem to match the common defintion of "agile" when >>>> it comes to programming. Then again, you have a habit of using >>>> words to mean whatever you want, without much reference to how >>>> they're used by the rest of the industry. >>> I'm not part of the industry. >> That's no excuse for not learning the terminology, or at least >> avoiding using phrases which already have a common meaning. > Granted, I didn't pay enough attention to the fact that for industry > people "agile" has a much stronger connotation. Nevertheless, it's > an ordinary English word, too, so that's no excuse for not trying to > understand what I *mean*. Since nobody has any chance to see which > programming strategy the projects uses, you must deliberatly > misunderstand me for assuming that I meant "agile programming". No, I didn't (mis)understand you to mean "agile programming." I didn't understand what you said at all - which is why I asked how you define an agile project. >> [...] The difference is ther are a lot of other choices, so it >> gets chosen less often. But I note that at least one of the 155 >> projects on SourceForge that list FORTRAN as a language is a GUI >> application for Windows. > I see no difference to special-purpose language then. Difference to what? I notice that the Wikipedia doesn't have a definition for "special purpose language", instead preferring the phrase "Domain Specific Langauge". That matches the definition that agrees with what I think is common usage, which is: Trade some of the flexibility of a general purpose language for capabilities that are more tailored to a specific task Fortran certainly meets the requirements the wikipedia has for being a general purpose language. >> [...] Just like some C/C++ applications are legacy code, and some >> aren't. Which contradicts your earlier assertion that C/C++ >> applications were all legacy code. > Reference? See , where you dismiss all C applications a legacy code. >> Earlier, you said you wanted a popular language because they get >> cool features faster. You hold up two proprietary VC++ (which is >> just an development environment) and VB as "popular" languages. If >> you've been watching software development long enough, you'd >> realize that "cool things" usually come from open source projects >> first. > That's right (or rather, I believe you). I just want to use a > popular langauge amongst the ones that have free success ("free" in > the sense of Free Software). These leaves me with three questions for you: Is there a free language you consider successful? I can't think of any that are a lot more (i.e. - an order of magnitude) successful than Python that aren't derived from C. Are there any free language that have the GUI/IDE toolkit you want? Have you noticed that languages with really cool features aren't very popular? Unification, prototypes, real macros, and dataflow variables all come to mind. Some of the languages that sport these features even come with an integrated GUI/IDE, but they have at most 99 projects mentioning them on sourceforge - assuming they are listed at all. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From cliff at develix.com Mon Aug 1 18:20:38 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 15:20:38 -0700 Subject: Wheel-reinvention with Python In-Reply-To: References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <7xd5ozv1ng.fsf@ruckus.brouhaha.com> <7xek9e5ywq.fsf@ruckus.brouhaha.com> <7xek9djr76.fsf@ruckus.brouhaha.com> Message-ID: <1122934839.19618.411.camel@localhost.localdomain> On Mon, 2005-08-01 at 17:54 -0400, Mark Roseman wrote: > > I'll point out that this has been done (in fact, many times). For > example: > http://tkhtml.hwaci.com > > (Integrating Gecko in has also been done, as a side note). Interesting. Your later point about hard to find is certainly correct as my searches (albeit not as in-depth as they could have been) turned up little in this regard. > While I certainly don't begrudge anyone their choice of tools, it's no > surprise that someone who's become more familiar with wxPython would > have an unduly low opinion of Tk. They've obviously spent more time > overcoming the warts in wxPython, and wouldn't have spent comparable > effort learning what it would take to overcome the warts in Tk - it just > looks hopelessly flawed in comparison. Well, as was mentioned earlier (by Paul I believe), "life is too short", in this case, to become expert in more than one GUI toolkit (which as a whole, are a wart on the face of programming in general, IMHO). They are highly complex and require a large investment of time regardless of which you choose. People often cite one kit as being "more pythonic" than another, but frankly I've yet to see one that even remotely meets that (admittedly vague) criteria. I've made my choices based on my own criteria, and certainly I would not hesitate to recommend my choices to others. Frankly most of my ire in this thread has been over things tertiary to the toolkits themselves: 1) the idea of demanding that one toolkit be "the preferred" way 2) dismissing without due consideration the hard work of others who have volunteered their code without demand for recompense, and 3) what I've taken (rightly or wrongly) to be deliberate obtuseness on the part of some of the participants. Aside from that, I consider the choice of GUI toolkits to be a pretty benign issue and hardly one qualifying for the level of heat we've had for the last day or so. > Switch "wxPython" and "Tk" around in the above argument and I think the > statements equally hold of course. Agreed. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From denis.kasak at gmail.com Fri Aug 26 09:33:11 2005 From: denis.kasak at gmail.com (Denis Kasak) Date: Fri, 26 Aug 2005 15:33:11 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: John Bokma wrote: > > You can't be sure: errors in the handling of threads can cause a buffer > overflow, same for spelling checking :-D Yes, they can, provided they are not properly coded. However, those things only interact locally with the user and have none or very limited interaction with the user on the other side of the line. As such, they can hardly be exploitable. > Some people never use them, and hence they use memory and add risks. On a good newsreader the memory use difference should be irrelevantly small, even if one does not use the features. I would call that a nitpicky argument. Also, the risk in question is not comparable because of the reasons stated above. The kind of risk you are talking about happens with /any/ software. To stay away from that we shouldn't have newsreaders (or any other software, for that matter) in the first place. > Of course can HTML be useful on Usenet. The problem is that it will be much > more often abused instead of used. No, you missed the point. I am arguing that HTML is completely and utterly /useless/ on Usenet. Time spent for writing HTML in Usenet posts is comparable to that spent on arguing about coding style or writing followups to Xah Lee. It adds no further insight on a particular subject, but _does_ add further delays, spam, bandwidth consumation, exploits, and is generally a pain in the arse. It's redundant. -- Denis From pydecker at gmail.com Mon Aug 1 10:21:04 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 1 Aug 2005 10:21:04 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <1122901170.19618.296.camel@localhost.localdomain> References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <1122901170.19618.296.camel@localhost.localdomain> Message-ID: On 8/1/05, Cliff Wells wrote: > Personally, all I expect is an obvious pointer to a mailing list and a > helpful community willing to suffer NB questions (fast bugfixes is a big > plus too). If that's available, I'm happy. But then I'm willing to > actually work a little to get what I want. For other it seems they > won't be happy unless you drive to their house and install it for them > (which only seems fair, cause if you hadn't volunteered to write such > crap then they wouldn't have had to be bothered with it in the first > place, damn you). Maybe you wouldn't mind tidying up a bit and washing > a few dishes while you're at it? ROFLMAO! Yep, it's their fault for not charging us for their work! How evil can people get? Sharing their work and asking for nothing in return? What bastards!! -- # p.d. From weekender_ny at yahoo.com Mon Aug 8 00:14:01 2005 From: weekender_ny at yahoo.com (John) Date: 7 Aug 2005 21:14:01 -0700 Subject: zipped socket Message-ID: <1123474441.944938.165170@g49g2000cwa.googlegroups.com> Is there anyway open a socket so that every send/listen/recv goes thru a zipping/unzipping process automatically? Thanks, --j From devlai at gmail.com Wed Aug 31 00:22:10 2005 From: devlai at gmail.com (Devan L) Date: 30 Aug 2005 21:22:10 -0700 Subject: Adding bound methods dynamically... CORRECTED References: <4o4ah1h2r53gll81jinueaugpqi7rq7hsj@4ax.com> <7s5ah1t7t2qvseneigb6p1jv9igcl4diri@4ax.com> Message-ID: <1125462130.670127.206220@g44g2000cwa.googlegroups.com> Kevin Little wrote: > I want to dynamically add or replace bound methods in a class. I want > the modifications to be immediately effective across all instances, > whether created before or after the class was modified. I need this > to work for both old ('classic') and new style classes, at both 2.3 > and 2.4. I of course want to avoid side effects, and to make the > solution as light-weight as possible. > > Question for the experts: Is the solution coded in AddBoundMethod() > acceptable to the Pythonian Gods? :) It does seem to work -- tested > at 2.3.5 (RH Linux) and 2.4.1 (WinXP) > > [Code] I'm not an expert, but why do you need to dynamically add or replace bound methods? From mwm at mired.org Sun Aug 28 19:25:55 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 28 Aug 2005 19:25:55 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> Message-ID: <861x4dy77g.fsf@bhuda.mired.org> Bryan Olson writes: phil hunt wrote: > > What's important is *predictability*, e.g. which instruction will > > the computer execute next? > > > > If you only have one thread, you can tell by looking at the code > > what gets executed next. It's very simple. > Not really. Trivially, an 'if' statement that depends upon input > data is statically predictable. Use of async I/O means makes the > programs execution dependent upon external timing. Yes, but that depenency is tied to a single point - the select call. The paths after that are statically predictable. This makes the code very managable. > > If you have 2 threads you can easily have a timing-based situation > > that occurs rarely but which causes your program to behave wierdly. > > This sort of bug is very hard to reproduce and therefore to fix. > So we need to learn to avoid it. No, we need tools that make it impossible to write codde that triggers it. Async I/O is one such tool, but it has lots of other limitations that make it unsuitable for many applications. > [...] > > Yes, find solutions. Don't find dangerous dead-ends that look like > > solutions but which will give you lots of trouble. > If concurrency is a dead end, why do the programs that provide > the most sophisticated services of any in the world rely on it > so heavily? I don't know what Phil is saying, but I'm not calling concurrency a dead end. I'm calling the tools available in most programming languages for dealing with it primitive. We need better tools. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From pythonic at seehart.com Tue Aug 2 19:44:02 2005 From: pythonic at seehart.com (pythonic at seehart.com) Date: Tue, 2 Aug 2005 18:44:02 -0500 (CDT) Subject: Python for embedded linux? Message-ID: <4995.69.107.18.38.1123026242.squirrel@www.seehart.com> Where can I find a minimal version of python (less than 2 MB) suitable for a web server on an embedded linux system? The small size is required because the system lives on flash memory. Thanks, Ken Seehart From spammers-go-here at spam.invalid Wed Aug 31 15:18:08 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 31 Aug 2005 15:18:08 -0400 Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk> <4314ce74$0$18648$14726298@news.sunsite.dk> Message-ID: <43160228$0$18646$14726298@news.sunsite.dk> Fernando Perez wrote: > Madhusudan Singh wrote: > >> Madhusudan Singh wrote: >> >>> Hi >>> >>> I am using time.clock() to get the current time of the processor in >>> seconds. For my application, I need really high resolution but currently >>> seem to be limited to 0.01 second. Is there a way to specify the >>> resolution (say 1-10 microseconds) ? My processor is a 1.4 MHz Intel >>> processor. Surely, it should be able to report times a few (or at least >>> 10) microseconds apart. >>> >>> Thanks. >> >> Correcting a typo (1.4GHz, not 1.4 MHz). >> >> And I am using Linux. > > Then, this may be handy to give you an idea of the resolution you can > expect at > the python level (i.e., without writing extension code). Feel free to add > fancier statistics if you actually need them: > > planck[python]> cat tdelta.py > #!/usr/bin/env python > """quick and dirty test for time deltas. Under Linux, this is best done > using time.time() instead of time.clock()""" > > import commands > from time import time > > npts = 50 > times = [-(time()-time()) for i in xrange(npts)] > > print commands.getoutput('egrep "MHz|model name" /proc/cpuinfo') > print 'Min. time delta :',min(times),'s' > print 'Max. time delta :',max(times),'s' > print 'Avg. time delta :',sum(times)/float(npts),'s' > print 'Num. of timings :',npts > > # > For example, on my system: > > planck[python]> ./tdelta.py > model name : Intel(R) Pentium(R) 4 CPU 2.80GHz > cpu MHz : 2794.365 > Min. time delta : 2.86102294922e-06 s > Max. time delta : 9.05990600586e-06 s > Avg. time delta : 3.38554382324e-06 s > Num. of timings : 50 > > Cheers, > > f Thanks. From jeffrey.schwab at rcn.com Fri Aug 12 22:21:31 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Fri, 12 Aug 2005 22:21:31 -0400 Subject: Running one Python program from another as a different user In-Reply-To: <1123886672.906472.322360@z14g2000cwz.googlegroups.com> References: <1123885309.455560.220670@z14g2000cwz.googlegroups.com> <1123886672.906472.322360@z14g2000cwz.googlegroups.com> Message-ID: dwelch91 at gmail.com wrote: > Thanks, that looks very promising... > Is there a solution for pre-Python v2.4? I have to have code that works > on 2.x, 0<=x<=4. Do I just use the os.popen instead? import os def run_as(username): pipe = os.popen("su %s" % username, 'w') pipe.write("whoami") if __name__ == "__main__": import sys for user in sys.argv[1:]: run_as(user) From phillip.watts at anvilcom.com Mon Aug 15 17:43:33 2005 From: phillip.watts at anvilcom.com (phil) Date: Mon, 15 Aug 2005 16:43:33 -0500 Subject: GUI tookit for science and education References: Message-ID: <43010C85.9040306@anvilcom.com> > > Tkinter is the default GUI for Python, it runs on lots of platforms > and often comes already installed (on Linux or Unix distributions). > I use Tkinter for a geometry course. I think it is fairly easy to learn, much easier than say VB. VERY portable and pretty well documented and very well supported on this list. It doesn't have much math built in. For functions you have to plot points. From p at ulmcnett.com Tue Aug 2 01:30:32 2005 From: p at ulmcnett.com (Paul McNett) Date: Mon, 01 Aug 2005 22:30:32 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <86zms0ex85.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <86zms0ex85.fsf@bhuda.mired.org> Message-ID: <42EF04F8.7050501@ulmcnett.com> Mike Meyer wrote: > Paul McNett

writes: > >>On Windows and Mac, you download the package and run through the wizard. > > Which package? I'm looking at the sourceforge download site, and don't > see any packages for Python 2.4 on OS X 10.4. In fact, I don't see any > packages for 10.4 at all. IIRC, they didn't have a 2.4 package last > time I looked. I may download the 10.3 one and see if it works. I can confirm that the 10.3 one works on Tiger. I think that Robin doesn't have a Tiger machine to build on yet, which is why there's no package for it. Perhaps more information is at the wxPython download site (not the Sourceforge one) at: http://wxpython.org/download.php >>Admittedly, installing from source is more difficult than any other >>project I've found, but still doable. > > Well, I've got a long history of installing things from source - going > back to v6. On OS X, I like the darwin ports stuff, so I tried that: > > % sudo port install wxpython > > It blew up trying to compile wxpython. The multitude of dependencies > all seemed to build find. Building wxpython from the source > distribution by hand doesn't seem to fair any better. To build wxPython from source, you really need to follow Robin's detailed instructions in BUILD.txt, located somewhere in the source tree (I have to look for it every time, but I think it is in wxSrc/wxPython/docs/BUILD.txt). It isn't difficult but there's more to it than the standard ./configure;make;make install. > P.S. - no, this isn't just a theoretical exercise. I want to play with > THE, and that's been rewritten from it's Mac-only version to use the > Python wxWidgets wrapper. It's mostly curiosity, so I'm not willing to > work very hard on it. If the dependencies will build out of the box - > cool. If not - I have lots of other things to do. I think you'll find that wxPython installs perfectly on Tiger using the package provided. Indeed, the only really painful platform to install wxPython on is Linux, where you pretty much need to build from source if you want the latest and greatest. -- Paul McNett http://paulmcnett.com From mwm at mired.org Mon Aug 8 22:43:44 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 08 Aug 2005 22:43:44 -0400 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <7x8xzcck9d.fsf@ruckus.brouhaha.com> Message-ID: <86wtmvlti7.fsf_-_@bhuda.mired.org> Well, I tried sending this via email, but I can't derive a valid address from Paul's anti-spammed address. My apologies to the rest of you for this. Paul Rubin writes: > Should that bother me? I should say, my interest in Ocaml or Haskell > is not just to try out something new, but also as a step up from both > Python and C/C++ for writing practical code. That is, I'm looking for > something with good abstraction (unlike Java) and type safety (unlike > C/C++), but for the goal of writing high performance code (like > C/C++). I'm even (gasp) thinking of checking out Ada. If you're thinking about checking out Ada, you might want to take a look at D. I haven't gotten very far into it myself (I was attracted by DbC), but it looks like a modern redesign of C: GC, OO, and typedefs that actually define new types, while still being something it's possible to generate reasonably fast code for. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From kay.schluehr at gmx.net Sun Aug 7 07:25:07 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 7 Aug 2005 04:25:07 -0700 Subject: Python -- (just) a successful experiment? References: Message-ID: <1123413907.572051.281140@g44g2000cwa.googlegroups.com> Eric Pederson wrote: > Raise your hand if you think the best technology wins! Who is interested in such a matter? Is this a forum dedicated to some programming language or a popularity contest? If Python dies in a few years / looses attention but the Python Zen survives in another language I have nothing to complain. > For those of you with your hands in the air, tell me: if Python is so good, > why has PHP achieved such greater adoption and mindshare? PHP, Ruby and all this stuff is just the fashion of the day. If the flow of money takes another direction away from Web programming I believe there will still be C, some successor of Python, some members of the ML/Haskell family rooted in CS, a deviation of C++/Java/C# and some Lisp offspring and of course the new fashion of the day. And in the end if the success of any language becomes dangerous somehow it will be cloned and *improved* by Microsoft. Kay From yxxxxlxxxxx at gmail.com Tue Aug 9 11:44:41 2005 From: yxxxxlxxxxx at gmail.com (yaffa) Date: 9 Aug 2005 08:44:41 -0700 Subject: sqlobject vs mysqldb module Message-ID: <1123602281.268415.288590@o13g2000cwo.googlegroups.com> dear group, i have a python script that scrapes contents from an html file and i would like to have the script write values to a mysql db. do you recommend i go with the sqlobject or the mysqldb module? thank you yaffa From skip at pobox.com Tue Aug 9 11:45:48 2005 From: skip at pobox.com (skip at pobox.com) Date: Tue, 9 Aug 2005 10:45:48 -0500 Subject: What are modules really for? In-Reply-To: <42F8CC8F.7020500@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> Message-ID: <17144.53164.459850.806623@montanaro.dyndns.org> Nick> One thing I find weird about python is the idea of a module. Why Nick> is this needed when there are already the ideas of class, file, Nick> and package? A module is a namespace object that maps one-to-one to a file (ignoring the new module's features). A file by itself is just a collection of bytes and has no features to interpret the structure of its contents as a namespace. Nick> Python seems to let you group classes together in one file and Nick> call it a module, but what for? You can define many other types of objects in modules besides classes. Nick> With Python an inherited method could be in one of many base Nick> classes and/or mixins and there seems no particular logic as to Nick> what the filename would be. I agree mixins can be troublesome. That's a problem peculiar to multiple inheritance, not strictly to Python. I'm sure you can create file/class relationships in Java or C++ that make it challenging to find the definition of a mixin. I don't view multiple inheritance as a gotta-have feature of OOP and avoid it when I can. Smalltalk has lived happily without multiple inheritance for a few decades now. Skip From fuzzyman at gmail.com Mon Aug 1 09:50:23 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 1 Aug 2005 06:50:23 -0700 Subject: Printing Docstrings Without Importing In-Reply-To: <42ed90cf.273165611@news.oz.net> References: <1122746909.441941.226760@o13g2000cwo.googlegroups.com> <42ed90cf.273165611@news.oz.net> Message-ID: <1122904223.528701.55420@f14g2000cwb.googlegroups.com> This seems to scratch several people's itches. Care to develop/maintain it ? Regards, Fuzzball http://www.voidspace.org.uk/python From cliff at develix.com Mon Aug 1 08:50:05 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 05:50:05 -0700 Subject: The state of OO wrappers on top of wxPython (was Re: Wheel-reinvention with Python) In-Reply-To: <8r4w9olxni3k.141eg8nfvy7s0$.dlg@40tude.net> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87slxwqp32.fsf@wilson.rwth-aachen.de> <7xmzo4nmf0.fsf@ruckus.brouhaha.com> <8r4w9olxni3k.141eg8nfvy7s0$.dlg@40tude.net> Message-ID: <1122900605.19618.286.camel@localhost.localdomain> On Mon, 2005-08-01 at 14:20 +0200, Marek Kubica wrote: > If you already tried GIMP on Windows, better try Inkscape on Windows.. that > piece of GTK software is really good. I don't do any actual work under Windows any more. My Windows VMware session is purely for testing Windows apps and websites under Exploder. However my girlfriend, while hating the Gimp (she prefers Photoshop, to put it mildly), loves Inkscape and claims it is better in many ways than Illustrator. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From sjmachin at lexicon.net Thu Aug 11 17:47:53 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 07:47:53 +1000 Subject: len(sys.argv) in (3,4) In-Reply-To: <42fb7498$0$11771$626a14ce@news.free.fr> References: <42fb7498$0$11771$626a14ce@news.free.fr> Message-ID: <42fbc789$1@news.eftel.com> bruno modulix wrote: > Daniel Sch?le wrote: > >>Hello >> >>I wrote a simple module, which is also supposed to be used as standalone >>program >>after considering how to avoid multiple if's I came up with this idea >> >>if __name__ == "__main__": >> if len(sys.argv) not in (3,4): >> print "usage: prog arg1 argv2 [-x]" >> # etc ... >> >>while develeoping I had my interpeter running and reloaded module >>now since I am ready, I wanted to run it from cmd windows shell >>but it always prints "usage ..." >>I added print len(sys.arg) and it prints 1 though I am provinding more >>than 1 value >> >> >>C:\pool\vhd2h\python>vhd2h.py vhd.vhd vhd.h -o >>1 >>usage: vhd2h.py vhdlFile hFile [-o] >> >>Someone got an idea what may be wrong? > > > Nope. But since you're running this on a very peculiar OS, I just can > guess that this very peculiar OS consider all args to be one same string... NOT SO: C:\junk>python -i - foo /bar -zot Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.argv ['-', 'foo', '/bar', '-zot'] NO REASON TO GUESS SO: For *any* OS: More than one CLI (command line interpreter) a.k.a. shell may be available. What they do with the remainder of the command line after the pathname of the executable (binary program or script or whatever) is up to them, but I have never seen any which would lump space-separated tokens into one arg without some quoting convention having to be used. > > Try this: > if __name__ == "__main__": > for num, arg in enumerate(sys.argv): > print "arg %d is %s" % (num, arg) > > This should art least give you some hints... > > BTW, isn't the DOS syntax for command line args something like : > >>myprog /arg1 /arg2 Which DOS do you mean? IBM DOS/VS? AmigaDOS? MS-DOS? The likelihood is that the OP is not running any of these, but is running a recent version of Windows. The standard CLI (cmd.exe) does use a syntax for built-in commands where '/' is used for options where a *x shell would use '-'; however this is sublimely irrelevant. Python scripts get their args on Windows just like anywhere else. C programs (like the excellent collection of GnuWin32 utilities) likewise just do main(argc, argv) {blah; blah} and carry on regardless just as K&R intended. From rkern at ucsd.edu Tue Aug 2 16:03:11 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 02 Aug 2005 13:03:11 -0700 Subject: bug in python/numarray In-Reply-To: <5.1.1.5.2.20050802103138.04c79d50@are.berkeley.edu> References: <5.1.1.5.2.20050802103138.04c79d50@are.berkeley.edu> Message-ID: meng at are.berkeley.edu wrote: > Hi, there, > > I got different results by running the same lines of code on windows and > debian. Here is the code: > > a = kroneckerproduct(ones((4195,1)), identity(12)) > print a.mean() > > This works perfectly well in windows but it gave the following error while > running it in debian: > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line > 1137, in mean > return self.sum()/(self.nelements()*1.0) > File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line > 1133, in sum > return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat, > type=type) > IndexError: too many indices. > > But if I reduce the number 4195 to 419, it works. Is it a bug in Python or > Numarray? Can someone help me figure it out? BTW, the python version is 2.4.1 It's almost certainly numarray. I don't get an error on OS X with the latest CVS of numarray. Please try the latest CVS on your platforms, and if you still get this error, then post it to the numarray mailing list. Thanks! http://lists.sourceforge.net/lists/listinfo/numpy-discussion -- 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 usenet at isbd.co.uk Thu Aug 25 15:31:31 2005 From: usenet at isbd.co.uk (usenet at isbd.co.uk) Date: 25 Aug 2005 19:31:31 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> Message-ID: <3n6kkjF4qppU1@individual.net> In comp.lang.perl.misc John Bokma wrote: > > > the argument that usenet should never change seems a little > > heavy-handed and anachronistic. > > No, simple since there *are* alternatives: web based message boards. Those > alternatives *do* support HTML formatting (often the subset mentioned ... and generally these "web based message boards" (i.e. forums I assume you mean) have none of the useful tools that Usenet offers and are much, much slower. > earlier). However, Usenet is a stranger to most people on the Internet, > even with Usenet access, and hence, there is no real reason to see it > changed into something that is "available" for years and years to more > people: www. > > -- > John Small Perl scripts: http://johnbokma.com/perl/ > Perl programmer available: http://castleamber.com/ > Happy Customers: http://castleamber.com/testimonials.html > -- Chris Green From timr at probo.com Sat Aug 13 02:10:09 2005 From: timr at probo.com (Tim Roberts) Date: Fri, 12 Aug 2005 23:10:09 -0700 Subject: win32com: use not possible as normal user References: <3m36qpF14jsl9U1@news.dfncis.de> Message-ID: Sibylle Koczian wrote: > >I've installed Python 2.4 and the win32 extensions, using administrator >rights, under Windows XP in "C:\Programme". As this is a directory >without spaces I didn't expect any problems. But now I can't _use_ >win32com as a normal user, because normal users can't write there: Right. To use win32com, the site-packages\win32com\gen_py directory must be writable. You shouldn't have to change the whole c:\Programme tree; you should be able to make just that one subdirectory writable by all. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mscottschilling at hotmail.com Thu Aug 25 14:30:41 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Thu, 25 Aug 2005 18:30:41 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: wrote in message news:m3ll2qx73f.fsf at invalid.address... > "Mike Schilling" writes: > >> "Rich Teer" wrote in message >> news:Pine.SOL.4.58.0508250932360.5888 at zen.rite-group.com... >> > On Thu, 25 Aug 2005, Mike Schilling wrote: >> > >> >> Another advantage is that evewry internet-enabled computer today >> >> already comes with an HTML renderer (AKA browser), so that a >> >> message saved to a file can be read very easily. >> > >> > I think you're missing the point: email and Usenet are, >> > historically have been, and should always be, plain text mediums. >> >> Gosh, if you say they should be, there's no point trying to have an >> intelligent discussion, is there? > > Errm, isn't that what you're doing as well then? Rich just gave an > opinion, you've been giving an opinion. Rich's opinion happens to have > a lot of history and good reasons behind it. I don't see why it should > be viewed as some kind of discussion ending dogmatism. I see a difference between "X would be useful for A, B, and C" and "Y will always be the only proper way." Don't you? From zxo102 at gmail.com Thu Aug 4 01:51:44 2005 From: zxo102 at gmail.com (zxo102) Date: 3 Aug 2005 22:51:44 -0700 Subject: Python-Excel: How to paste selected cells (range) to different location on the same sheet in Excel In-Reply-To: <1123133763.524077.205640@f14g2000cwb.googlegroups.com> References: <1123133763.524077.205640@f14g2000cwb.googlegroups.com> Message-ID: <1123134704.795764.94110@g43g2000cwa.googlegroups.com> I found the solution for this. It needs to select a new location and paste from "sh". Thank you for your reading this. import win32com.client xl=win32com.client.Dispatch("E?xcel.Application") xl.Visible=1 wb = xl.Workbooks.Add( ) sh=wb.Worksheets(1) sh.Cells(1,1).Value = "Hello World!" sh.Cells(3,3).Value = "Hello World!" sh.Range(sh.Cells(1,1),sh.Cell?s(3,3)).Select() sh.Range(sh.Cells(1,1),sh.Cell?s(3,3)).Copy() sh.Cells(4,1).Select() sh.Paste() Ouyang From rickvandermeiden at gmail.com Tue Aug 23 08:23:49 2005 From: rickvandermeiden at gmail.com (Kwikrick) Date: 23 Aug 2005 05:23:49 -0700 Subject: str() representation of sequences and dicts Message-ID: <1124799829.184333.275660@g14g2000cwa.googlegroups.com> When calling str() on a sequence or dict object, the elements of the sequence/dict will be represented as if their __repr__ method was called. Why is this? Wouldn't it be more consistent when calling str() on sequence to use the __str__ method of the elements in the sequence? As it is now, I often find myself typing something like: print map(str, alist) instead of just print str(alist) For dicts, it's more eleborate still. Is there a better way to deal with this? Rick. From python-url at phaseit.net Thu Aug 18 09:31:23 2005 From: python-url at phaseit.net (Cameron Laird) Date: Thu, 18 Aug 2005 13:31:23 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 18) Message-ID: QOTW: "It seems to me that Java is designed to make it difficult for programmers to write bad code, while Python is designed to make it easy to write good code." -- Magnus Lycka "Code attracts people that like to code. Tedious, repetitive c.l.py threads attract people that like to write tedious, repetitive c.l.py threads." -- Robert Kern Yes, commercial Python training *is* available: http://groups.google.com/group/comp.lang.python.announce/msg/f1bd9b8deac1cb39 You know how essential the Cookbook is. Filling a slightly different role is the Grimoire: http://the.taoofmac.com/space/Python/Grimoire The latest SPE "features a remote, encrypted and embedded ... debugger ...": http://pythonide.stani.be Paul Dale convincingly advertises O'Reilly's Safari service: http://groups.google.com/group/comp.lang.python/browse_thread/thread/115a242dc77b0057/ Python is a superb vehicle for several niches generally thought exclusive to other languages, such as automation of Windows processes. Another too-little-known such strength is Python's adeptness with native Mac OS X applications: http://developer.apple.com/cocoa/pyobjc.html mensanator introduces enough of bit arithmetic to explain popcount and Hamming distance: http://groups.google.com/group/comp.lang.python/browse_thread/thread/e0716ffcf80af3a2/ PEP editors David Goodger and Barry Warsaw refine PEP organization: http://mail.python.org/pipermail/python-list/2005-August/294467.html ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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. del.icio.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/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 mark at markroseman.com Mon Aug 1 15:21:57 2005 From: mark at markroseman.com (Mark Roseman) Date: Mon, 01 Aug 2005 15:21:57 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <7xvf2rync2.fsf@ruckus.brouhaha.com> Message-ID: Ed Leafe wrote: > On Sunday 31 July 2005 12:03, Paul Rubin wrote: >> > How on earth did you decide that, since tkinter actually runs out of > > the box when you install Python on most platforms, and wxPython doesn't? > > Because Tkinter looked like crap on OS X. Sorry, but it's hard to sell an > application that looks bad. Our target for the framework is to build > cross-platform apps that look native on each platform. Tkinter didn't measure > up in that regard. FWIW, some people may find this page interesting, which gives you an idea what "standard" Tk looks like on OS X, and then with adopting the "tile" extension to Tk and a few other tweaks, which is on its way to becoming a standard part of Tk: http://wiki.tcl.tk/14522 There's other info and various screenshots at: http://tktable.sourceforge.net/tile/index.html I think the message is, Tk has been moving forward in a coherent and focused way (finally) in terms of look and feel, which will certainly be of great benefit to Tkinter. Mark From tdelaney at avaya.com Tue Aug 9 23:30:19 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Wed, 10 Aug 2005 13:30:19 +1000 Subject: Recommendations for CVS systems Message-ID: <2773CAC687FD5F4689F526998C7E4E5F05CBF5@au3010avexu1.global.avaya.com> Roy Smith wrote: > Mike Meyer wrote: >> Well, the only thing that subversion does that I'd call bad is leave >> turds in my development directory. I'm tired of having to tell >> commands to ignore .svn files. Of course, Perforce is the only source >> control system I know of that doesn't do this. > > My recollection is that Clearcase is turd-free. Except for .keep and .contrib files. .keep are often useful (they're left over when you undo a checkout unless you select not to), but personally I think the .contrib files should be cleaned up once the merge is complete ... Tim Delaney From michele.petrazzo at unipex.it Wed Aug 31 06:07:30 2005 From: michele.petrazzo at unipex.it (Michele Petrazzo) Date: Wed, 31 Aug 2005 12:07:30 +0200 Subject: [ANN] FreeImagePy 1.0.0 Message-ID: <43158162$0$8480$5fc30a8@news.tiscali.it> What is? It' a python wrapper for FreeImage, Open Source library for developers who would like to support popular graphics image formats. How work? It use a binary freeimage library present on the system and ctypes. It 's released with the two public license GPL/FIPL: GPL: GNU GENERAL PUBLIC LICENSE - freeimagepy.sf.net/license-gpl.txt FIPL: FreeImage Public License - freeimagepy.sf.net/license-fi.tx More informations can be found here: http://freeimagepy.sf.net/ Michele Petrazzo From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 17 15:41:04 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 17 Aug 2005 21:41:04 +0200 Subject: String functions deprication In-Reply-To: References: Message-ID: <3mhi6gF177i17U1@individual.net> Dan wrote: >> http://www.python.org/doc/2.4.1/lib/node110.html >> >> These methods are being deprecated. What are they being replaced >> with? > > They're being made methods of the string class itself. > > For example: > >>> s = 'any old string' > >>> string.split(s, ' ') # Old way > ['any', 'old', 'string'] > >>> s.split() # New way s.split(' '), if we want to be equivalent. > ['any', 'old', 'string'] Reinhold From spammers-go-here at spam.invalid Wed Aug 17 12:08:22 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 17 Aug 2005 12:08:22 -0400 Subject: Testing for presence of arguments References: <430353e1$0$18641$14726298@news.sunsite.dk> Message-ID: <430360d8$0$18639$14726298@news.sunsite.dk> Dan Sommers wrote: > On Wed, 17 Aug 2005 11:13:03 -0400, > Madhusudan Singh wrote: > >> I know how to set optional arguments in the function definition. Is >> there an intrinsic function that determines if a certain argument was >> actually passed ? Like the fortran 95 present() logical intrinsic ? > > def f(**kw): > if kw.has_key('required_argument'): > print "require_argument was present" > else: > print "require_argument was not present" > >> My required functionality depends on whether a certain argument is >> specified at all. (Setting default values is *not* good enough.). > > You can very nearly achieve this with carefully planned default > arguments. Put this into a module: > > class _SemiPrivateClass: > pass > > def f(required_argument=_SemiPrivateClass): > if required_argument == _SemiPrivateClass: > print "required_argument was probably not present" > else: > print "required_argument was present" > > It's not impossible fool f, but an external module has to try very hard > to do so. > > (All code untested.) > > Regards, > Dan > Thanks for the suggestion, but seems needlessly complicated for something very simple. From dimitri.pater at gmail.com Mon Aug 15 09:32:58 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Mon, 15 Aug 2005 15:32:58 +0200 Subject: tuple assign variables In-Reply-To: <8c7f10c605081504405bf33260@mail.gmail.com> References: <8c7f10c605081504405bf33260@mail.gmail.com> Message-ID: hi, I'm fond of Greg Stein's dtuple module[1]. I've never used it with > MySQL, so YMMV, but using it might look something like: thanks for pointing that out, works like a breeze self.cursor.execute( "SELECT * FROM customer WHERE name ='sarah'") descriptor = dtuple.TupleDescriptor(self.cursor.description) for row in (dtuple.DatabaseTuple(descriptor, row) for row in self.cursor.fetchall()): name, pet, modified = row thanks! -- All truth passes through three stages. First, it is ridiculed. Second, it is violently opposed. Third, it is accepted as being self-evident. Arthur Schopenhauer ----- Please visit dimitri's website: www.serpia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From paolo_veronelli at tiscali.it Thu Aug 18 18:32:14 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Fri, 19 Aug 2005 00:32:14 +0200 Subject: dict duplicity In-Reply-To: References: Message-ID: <43050C6E.3020204@tiscali.it> Randy Bush wrote: > a dict written as > > pKey = (prefix, pLen, origin) > > val = dict.get(pKey) > if val == None: > dict[pKey] = (timeB, timeB) > else: > if val[0] > timeB: val[0] = timeB > if val[1] < timeB: val[1] = timeB > dict[pKey] = val > > and read back as > > for pKey, pVal in dict.iteritems(): > print \ > pKey[0], hash(pKey[0]), \ > pKey[1], hash(pKey[1]), \ > pKey[2], hash(pKey[2]), \ > "hash=", hash(pKey), \ > pVal[0], hash(pVal[0]), \ > pVal[1], hash(pVal[1]) > > when run with | sort, produces > > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 > > not that there are two entries with the same hash= > > i am utterly confused > > randy > I'm not sure I got your question but having the same hash(key) is not having the same key for a dict. >>> {-1:0,-2:0} {-2: 0, -1: 0} >>> hash(-1)!=hash(-2) False A key lookup in a dict involve real keys comparisons via '==' among the keys of the bin identified by the hash of the key. Regard Paolino ___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com From vincent at visualtrans.de Tue Aug 2 13:29:26 2005 From: vincent at visualtrans.de (vincent wehren) Date: Tue, 2 Aug 2005 19:29:26 +0200 Subject: py2exe windows apps path question References: <11ev0tcg9n2ndd@corp.supernews.com> Message-ID: "Grant Edwards" schrieb im Newsbeitrag news:11ev0tcg9n2ndd at corp.supernews.com... |I have several python apps (some wxPython, some plain text-mode | stuff) that I distribute internally for installation on Win32 | machines. They're bundled/installed using py2exe and inno | setup. | | I followed what I think is the normal procedure of installing | each app in its own directory under /Program | Files//. | | The problem is that the apps only run if they're started with | the install directory as the current working directory. | Otherwise they can't find the .dll's they use from the install | directory. AFAIK, Windows normally *does* search the directory where the executable module for the current process lives in for dlls. What sort of dlls are given you trouble? -- Vincent Wehren | | Is there some way to temporarily add the app's install | directory to the search path for .dll's? | | -- | Grant Edwards grante Yow! .. I think I'd | at better go back to my DESK | visi.com and toy with a few common | MISAPPREHENSIONS... From km at mrna.tn.nic.in Fri Aug 19 21:47:32 2005 From: km at mrna.tn.nic.in (km) Date: Sat, 20 Aug 2005 07:17:32 +0530 Subject: global interpreter lock Message-ID: <20050820014732.GA7647@mrna.tn.nic.in> Hi all, is true parallelism possible in python ? or atleast in the coming versions ? is global interpreter lock a bane in this context ? regards, KM From pink at odahoda.de Wed Aug 31 16:44:23 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 31 Aug 2005 22:44:23 +0200 Subject: time.strptime() for different languages References: <1125519061.261802.285840@o13g2000cwo.googlegroups.com> Message-ID: Adam Monsen wrote: > Anyone know of something that works like time.strptime(), but for > other languages? Specifically, Dutch (ex: "31 augustus 2005, 17:26") > and German? > > Thinking out loud... since "31 augustus 2005, 17:26" is only different > by month name, I suppose I could just substitute the month name using > a translation table for English to Dutch month names. Have you tested it with the proper locale setting and strptime(dateString, "%c")? I have not ;) -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From nospam at here.com Tue Aug 9 08:03:10 2005 From: nospam at here.com (Matt Feinstein) Date: Tue, 09 Aug 2005 08:03:10 -0400 Subject: Gotchas in user-space matplotlib install? Message-ID: <626hf1lp7k492cbcq4o1mqhe3hnaqpbhf5@4ax.com> Hi all-- I'm planning to try to do a completely local install of matplotlib (in Fedora Core 1)-- the system administrator isn't going to stop me-- but he isn't going to cooperate either. I've got the tarballs for python, numeric, numarray, matplotlib, ipython, wxpython and freetype-- which I think covers the various pre-requisites and post-requisites. One semi-obvious question is where to put the freetype library (the system version in FC1 is not up to the required level)-- but I can only wonder what other trouble I'm going to get into. Any advice before I take the plunge would be appreciated. TIA... Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From mynews44 at yahoo.com Sun Aug 14 17:03:57 2005 From: mynews44 at yahoo.com (googleboy) Date: 14 Aug 2005 14:03:57 -0700 Subject: Parsing a log file In-Reply-To: <1124030311.912414.110300@g49g2000cwa.googlegroups.com> References: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> <42ff409b$1@news.eftel.com> <1124030311.912414.110300@g49g2000cwa.googlegroups.com> Message-ID: <1124053437.558870.237710@g49g2000cwa.googlegroups.com> I am similarly not a programmer but am trying to learn python to do tasks like this. I would read through the regular expressions tutorial. You could probably easily read in all teh lines of the log file, and then split them up by " " (spaces).. If you're right about the lines all being consistent, that should easily handle each line. >From there you could amost certainly drop off the trailling milliseconds on the timestamps and do the simple data manipulation you'd like. here are a couple of links: http://www.amk.ca/python/howto/regex/ http://gnosis.cx/publish/programming/regular_expressions.html HTH googleboy From fakeaddress at nowhere.org Wed Aug 10 08:45:12 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 12:45:12 GMT Subject: Catching stderr output from graphical apps In-Reply-To: References: Message-ID: Peter Hansen wrote: > Bryan Olson wrote: > >> Here's a module to show stderr output from console-less Python >> apps, and stay out of the way otherwise. I plan to make a ASPN >> recipe of it, but I thought I'd run it by this group first. > > For what it's worth, I believe you've basically duplicated the > functionality available in wxPython in the standard App object. I'm not a wxPython user, but what I've heard is that it tries to write stderr to a regular window within the process. Crashing apps vanish from the screen, taking their error windows with them. Most any GUI toolkit has to return to its event-loop before it will update the screen, preventing it from showing messages of fatal errors. -- --Bryan From billiejoex at fastwebnet.it Fri Aug 26 14:15:47 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Fri, 26 Aug 2005 20:15:47 +0200 Subject: Closing programs that use sockets Message-ID: Hi all. I got a problem when using socket modules. By using them I can't stop my program by pressing ctrl+c. The only way to doit is by killing the python.exe process manually. Is there a solution to avoid this? Regards From richardlewis at fastmail.co.uk Tue Aug 30 06:17:25 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Tue, 30 Aug 2005 11:17:25 +0100 Subject: DOM text In-Reply-To: <1125052998.4951.241536021@webmail.messagingengine.com> References: <3n889kFb1liU1@uni-berlin.de> <1125052998.4951.241536021@webmail.messagingengine.com> Message-ID: <1125397045.8198.241769418@webmail.messagingengine.com> On Fri, 26 Aug 2005 11:43:18 +0100, "Richard Lewis" said: > > I'm implementing a Cursor class now which keeps track of the current > parent Element, text node and character position so that I can easily (I > hope ;-) work out where the splitting and inserting needs to occur. Wish > me luck!! > Sorry to revive this thread, but there's something else thats causing me confusion now! My cursor class is going quite well and I can insert text and element nodes. It also has methods to 'move' the 'cursor' forward and backward by a node at a time. It keeps the current_node in an instance variable which is initially assigned an element from a DOM tree instance created elsewhere. The problem I've come up against is when I use the next_node() method, and the current_node is a (leaf) Text node, the nextSibling property of current_node is None, where I know (from the document structure) that it shouldn't be. To make matters more confusing, if I manually create an instance of my DOM tree (interactively) and check the nextSibling of the same Text node, it is the correct value (another Element node) while the nextSibling property of the SectionCursor instance's current_node property (referring to the same node) is None. I *think* it only applies to leaf Text nodes. Here is the *complete* code for my SectionCursor class: (note that 'sections' are large(ish) document fragments from the main document) ========================================== class SectionCursor: def __init__(self, section_element): """Create a SectionCursor instance using the 'section_element' as the parent element.""" self.section_element = section_element self.current_node = self.section_element.firstChild self.char_pos = 0 def forward(self, skip=1): """Move the cursor forward 'skip' character positions.""" if self.current_node.nodeType == Node.TEXT_NODE: self.char_pos += skip if self.char_pos > len(self.current_node.data): self.next_node() else: self.next_node() def backward(self, skip=1): """Move the cursor backward 'skip' character positions.""" if self.current_node.nodeType == Node.TEXT_NODE: self.char_pos -= skip if self.char_pos < 0: self.previous_node() else: self.previous_node() def next_node(self): """Move the cursor to the next node; either the first child or next sibling.""" if self.current_node.hasChildNodes(): self.current_node = self.current_node.firstChild elif self.current_node.nextSibling is not None: self.current_node = self.current_node.nextSibling else: return False self.char_pos = 0 return True def previous_node(self): """Move the cursor to the previous node; either the previous sibling or the parent.""" if self.current_node.previousSibling is not None: self.current_node = self.current_node.previousSibling elif self.current_node.parentNode != self.section_element: self.current_node = self.current_node.parentNode else: return False if self.current_node.nodeType == Node.TEXT_NODE: self.char_pos = len(self.current_node.data) - 1 else: self.char_pos = 0 return True def jump_to(self, node, char_pos=0): """Jump to a node and character position.""" self.current_node = node self.char_pos = char_pos def insert_node(self, ref_doc, new_node): """Insert a node (new_node); ref_doc is an instance of the Document class.""" if self.current_node.nodeType == Node.TEXT_NODE: parent_node = self.current_node.parentNode text_node = self.current_node next_node = text_node.nextSibling preceeding_portion = ref_doc.createTextNode(text_node.data[:self.char_pos]) proceeding_portion = ref_doc.createTextNode(text_node.data[self.char_pos:]) parent_node.replaceChild(preceeding_portion, text_node) parent_node.insertBefore(new_node, next_node) parent_node.insertBefore(proceeding_portion, next_node) # where is the cursor? else: parent_node = self.current_node.parent_element parent_node.insertBefore(new_node, self.current_node) # where is the cursor? def append_child_node(self, ref_doc, new_node): pass def insert_element(self, ref_doc, tag_name, attrs=None): """Insert an element called tag_name and with the attributes in the attrs dictionary; ref_doc is an instance of the Document class.""" new_element = ref_doc.createElement(tag_name) if attrs is not None: for name, value in attrs.items(): new_element.setAttribute(name, value) self.insert_node(ref_doc, new_element) def insert_text(self, ref_doc, text): """Insert the text in 'text'; ref_doc is an instance of the Document class.""" new_text = ref_doc.createTextNode(text) self.insert_node(ref_doc, new_text) def remove_node(self): """Remove the current node.""" condemned_node = self.current_node if not self.next_node(): self.previous_node() parent_node = condemned_node.parentNode old_child = parent_node.removeChild(condemned_node) old_child.unlink() def remove_text(self, ref_doc, count=None): """Remove count (or all) characters from the current cursor position.""" if self.current_node.nodeType != Node.TEXT_NODE: return False text = self.current_node.data new_text = text[:self.char_pos] if count is not None: new_text += text[self.char_pos + count:] new_text_node = ref_doc.createTextNode(new_text) parent_node = self.current_node.parentNode self.current_node = parent_node.replaceChild(new_text_node, self.current_node) #self.char_pos = 0 ========================================== I've noticed that when you print any minidom node (except a Text node) it shows the node's memory address. But it doesn't do this with Text nodes. Does anyone know why this is? If I assign a Text node from one DOM tree to a variable, I don't get a copy do I? I hope I just get another reference to the original node. Cheers, Richard From cgusenetmail at hotmail.com Sun Aug 14 10:31:46 2005 From: cgusenetmail at hotmail.com (CG) Date: 14 Aug 2005 07:31:46 -0700 Subject: Parsing a log file In-Reply-To: References: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> Message-ID: <1124029906.297105.200680@o13g2000cwo.googlegroups.com> Thanks Andreas, In your first paragraph, you ask about incorrect input. I guess it is possible, but without that information, my collection of the data is useless, so I really don't know what I would do with that. As for the other stuff, I can hack the data in other ways, such as with VBA and MSAccess, which I am more familiar with, but I am trying to move to Linux and want to do it right the first time. I figure Perl is the more common language for this kind of stuff, but I did want to try to learn some Python while I am at it. I have started the tutorial, but being a businessman, time is an issue, which, if I had an example script that did a similar thing, I can learn by doing that (I am looking for something similar now). I do live in a low-labor cost country, so I can hire someone to do it for a small amount of money, but Python people are a little harder to find. Thanks for the comments, Clint From pydecker at gmail.com Tue Aug 16 22:32:44 2005 From: pydecker at gmail.com (Peter Decker) Date: Tue, 16 Aug 2005 22:32:44 -0400 Subject: Library vs Framework In-Reply-To: <86ek8t2tfn.fsf@bhuda.mired.org> References: <200508161031.26507.hancock@anansispaceworks.com> <86ek8t2tfn.fsf@bhuda.mired.org> Message-ID: On 8/16/05, Mike Meyer wrote: > Well, they may have created a library class that does the job for > them. Figuring out which is which seemed to be the point of this > thread. I guess my summary of the thread was that a library is built to do one thing, while a framework is built to tie many libraries together to do a series of connected things. If you end up using libraries in the same way all of the time, that's the beginning of a framework. Neither is better, IMO. They exist at completely different levels in completely different domains. -- # p.d. From onurb at xiludom.gro Wed Aug 24 08:53:03 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 24 Aug 2005 14:53:03 +0200 Subject: how to deal with space between numbers In-Reply-To: References: Message-ID: <430c6db0$0$24393$636a15ce@news.free.fr> Mohammed Altaj wrote: > > Thanks a lot for your valuable answer, i like the way you code , Thanks. > but i > would like to use my own, so if it is possible for you and if you have > time, please could you fix my code, so that i can do what i want. > Because i am using the this out put to another one , and i have the same > problem. I will really appreciate it !!! No problem, it's 500 euro a day. Please give me your snailmail and the whole code and spec, so I can send you back a contract. I'll start as soon as I'll receive the contract signed and the first check. best regards, -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From bokr at oz.net Wed Aug 10 00:29:27 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 10 Aug 2005 04:29:27 GMT Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> Message-ID: <42f98217.1055829672@news.oz.net> On Wed, 10 Aug 2005 03:47:06 GMT, bokr at oz.net (Bengt Richter) wrote: >On Tue, 09 Aug 2005 21:50:06 -0000, Grant Edwards wrote: > >>On 2005-08-09, Scott David Daniels wrote: >>> Grant Edwards wrote: >>>>>Ex #1) 333-3333 >>>>>Hex On disk: 00 00 00 80 6a 6e 49 41 >>>>> >>>>>Ex #2) 666-6666 >>>>>Hex On disk: 00 00 00 80 6a 6e 59 41 >>>> >>>> So there's only a 1-bit different between the on-disk >>>> representation of 333-3333 and 666-6666. >>>> >>>> That sounds pretty unlikely. Are you 100% sure you're looking >>>> at the correct bytes? >>> >>> Perhaps the one bit is an exponent -- some kind of floating point >>> based format? That matches the doubling of all digits. >> >>That would just be sick. I can't imagine anybody on an 8-bit >>CPU using FP for a phone number. >> >>-- >>Grant >> > >>> def double_binary_lehex_to_double(dhex): > ... "convert little-endian hex of ieee double binary to double" > ... assert len(dhex)==16, ( > ... "hex of double in binary must be 8 bytes (hex pairs in little-endian order") > ... dhex = ''.join(reversed([dhex[i:i+2] for i in xrange(0,16,2)])) > ... m = int(dhex, 16) > ... x = ((m>>52)&0x7ff) - 0x3ff - 52 > ... s = (m>>63)&0x1 > ... f = (m & ((1<<52)-1))|((m and 1 or 0)<<52) > ... return (1.0,-1.0)[s]*f*2.0**x > ... > >>> double_binary_lehex_to_double('000000806a6e4941') > 3333333.0 > >>> double_binary_lehex_to_double('000000806a6e5941') > 6666666.0 > >>> double_binary_lehex_to_double('0000108777F9Fc41') > 7777777777.0 > >;-) > Now the easy way ;-) >>> import struct >>> def d2d(h): ... return struct.unpack('d',''.join(chr(int(h[i:i+2],16)) for i in xrange(0,16,2)))[0] ... >>> d2d('000000806a6e4941') 3333333.0 >>> d2d('000000806a6e5941') 6666666.0 >>> d2d('0000108777F9Fc41') 7777777777.0 Regards, Bengt Richter From python at rcn.com Sat Aug 13 01:17:22 2005 From: python at rcn.com (Raymond Hettinger) Date: 12 Aug 2005 22:17:22 -0700 Subject: Dictionary inheritance References: Message-ID: <1123910242.206373.82790@g43g2000cwa.googlegroups.com> [Talin] > I want to make a dictionary that acts like a class, in other words, > supports inheritance: If you attempt to find a key that isn't present, > it searches a "base" dictionary, which in turn searches its base, and so on. Perhaps the chainmap() recipe will meet your needs: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305268 Raymond From michaels at rd.bbc.co.uk Tue Aug 23 04:14:08 2005 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Tue, 23 Aug 2005 09:14:08 +0100 Subject: Network performance References: Message-ID: Roland Hedberg wrote: > What the protocol has to accomplish is extremely simple; the client > sends a number of lines (actually a RDF) and the server accepts or > rejects the packet. That's all ! ... > Now, presently I'm using ( why so is a long > history which I will not go into here) and that is a bit to slow for > my needs. On my present setup [Twisted and XMLRPC ]it takes close to > 200 ms to perform one transfer. But since that includes setting up and > tearing down the connection I thought I'd try doing something simpler > so I wrote a server and a client using socket. > I was surprised to find that the performance was equal to what > Twisted/XMLRPC did. Around 200 ms per set, not significantly less. That should tell you two things: * Twisted/XMLRPC is as efficient as you can hand craft. (which is a good use reason for using it). * That what you're measuring is overhead - and most likely of setup. I'd measure the ping time between your two hosts. Why? TCP is not the fastest protocol in the world. If you're measuring the whole connection, you're dealing with a number of TCP messages: * Client -> SYN * Server -> SYN ACK * Client -> ACK * Client -> DATA (Assume data fits inside one message) * Server -> ACK * Client -> FIN * Server -> FIN ACK * Server -> FIN * Client -> FIN ACK (Based on Fig 18.3, Steven TCP/IP Ill, Vol 2) That's 9 round trips. 200ms / 9 == 22.2 ms *IF* your ping time is close to this, then what you're really measuring is TCP setup/teardown latency, not python latency. (*IF* you're on a LAN and the latency is around that I'd suggest that you may have discovered a local network problem) If your ping time is significantly lower - eg you're running on localhost - I'd suggest you translate your code to C (and/or post your code), and repeat the same tests. So far you haven't shown that python is slow here, just that something that you're measuring causes it to be 200ms whether you use Twisted or not. (So you HAVE shown that twisted isn't slow :-) Another issue might be how you're measuring the latency - especially whether if you're including startup of python in the 200ms or not! Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk, http://kamaelia.sourceforge.net/ British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From jeffrey.schwab at rcn.com Fri Aug 19 10:12:01 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Fri, 19 Aug 2005 10:12:01 -0400 Subject: Database of non standard library modules... In-Reply-To: References: Message-ID: Steve Holden wrote: > Robert Kern wrote: > >> Jon Hewer wrote: >> >>> Is there an online database of non standard library modules for Python? >> >> >> >> http://cheeseshop.python.org/pypi >> > While cheeseshop might resonate with the Monty Python fans I have to say > I think the name sucks in terms of explaining what to expect. If I ask > someone where I can find a piece of code and the direct me to the cheese > shop, I might look for another language. I think it's just meant to be a handy moniker. An acronym like CPAN doesn't exactly clear everything up in one shot, either, but at least other Perl users know what you mean when you say it. From http Mon Aug 8 04:44:38 2005 From: http (Paul Rubin) Date: 08 Aug 2005 01:44:38 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> Message-ID: <7xpsso3jih.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > Hypothesis 1: someone learned Python and Tkinter, felt dissatisfied with > Tkinter, went searching the universe for an alternative, found GTK, and > wrote PyGTK, perhaps learning C in the process. > > Hypothesis 2: a C-programmer who is a satisfied user of GTK (on *nix, > presumably) learns Python. "Neat, but I also want to keep using GTK." > Which he can because it is relatively easy. > > Repeat H1 and H2 for every wrapping. You believe in H1. I suspect H2 is > more often true, but admit I have no data. I dunno about PyGTK but one of the more common complaints about wxPython is that it's not Pythonic enough. And wxPython is probably the most popular Python GUI toolkit after Tkinter. So people don't want C wrappers. I think what they mostly want is a wide choice of good looking widgets. They don't like Tkinter because its widget set is limited and what widgets it does have, look like crap. > I have an alternate interpretation. There is a Python wrapping for > as many C libraries as there are because Python is neat and wrapping > is fairly easy and the rewards great. I think Python outgrew this "glue" orientation years ago and its main failings today are where it holds onto that orientation instead of trying to stand as a language in its own right. The Python docs should specify what Python code actually does, not simply that Python wraps the C library. > When I learned Python several years ago, being able to interactively drive > and easily script foreign libraries was touted as one of its killer > applications. Numerical Python, wrapping BLAS, LINPACK, and FTPPACK was a > prime example. So in a sense, you are criticizing Python for being > successful at what I believe was one of its design goals. Having a good FFI is certainly an important feature but Python programs should first and foremost be Python programs. Compare the situation with Java or Common Lisp for example. Both of those languages have better FFI's than Python in every serious implementation (consider why SWIG is popular--because Python's C API is so clumsy), and yet the specs for those languages are far more thorough than the Python docs. From bkhl at stp.lingfil.uu.se Tue Aug 2 13:02:09 2005 From: bkhl at stp.lingfil.uu.se (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) Date: Tue, 02 Aug 2005 19:02:09 +0200 Subject: Art of Unit Testing References: Message-ID: <87mzo0s25q.fsf@lucien.dreaming> Christoph Zwerschke writes: > Would it make sense to add "globaleSetup" and "globalTearDown" methods > to the TestCase class? I think at least it would not harm > anybody. Where should such proposals be submitted? In general that's not such a good idea. If you build your tests like that, it gets hard to know which test really went wrong, and you might get the situation where the whole set of tests works, but depend on each other in some way. (This can also happen for more obscure reasons, and is worth looking out for whichever way you do it.) So, rebuilding the environment for the each before every single test is generally worth the overhead. -- Bj?rn Lindstr?m Student of computational linguistics, Uppsala University, Sweden From ray_usenet at yahoo.com Fri Aug 12 10:28:10 2005 From: ray_usenet at yahoo.com (Ray) Date: 12 Aug 2005 07:28:10 -0700 Subject: Python's Exception, and Capitalization Message-ID: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> Hello guys, OK, I've been reading some more about Python. There are some things about Python exception that I haven't been able to grasp: 1. This is a small thing, but why is object spelled "object", and the mother of all exception "Exception" (with capital E)? Why is not object spelled "Object" then? Especially since Exception's descendants are named with the first letter of each word capitalized? I mean, in Java, it's Object. Whereas in C++, they're quite consistent, standard stuff are usually all lowercaps (basic_string, iostream, etc.). Python seems to have a mix of both. Am I right in assuming that object is object (with lower case 'o') because it is built-in, and Exception is not? So when we write our own classes, exceptions, etc., we should capitalize it like in Java or C#? By the way, what's the convention for functions? It's a bit confusing because when I see Python builtins, it seems that they follow C++ style (e.g.: has_key, readline). So... does it mean that when I write my own function, customarily I'd say myFunction() (or MyFunction()?) 2. I'm quite baffled that you either have try/except, or try/finally. In Java, it is quite common to do this: try { // something } catch(AException e) { // handle } catch(BException e) { // handle } catch(CException e) { // handle } finally { // whatever happens, execute this } It seems that since except and finally are mutually exclusive I can't do this. So... what's the usual idiom for this? Thanks! Ray From pinard at iro.umontreal.ca Tue Aug 9 22:11:20 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Tue, 9 Aug 2005 22:11:20 -0400 Subject: Recommendations for CVS systems In-Reply-To: <861x52lg10.fsf@bhuda.mired.org> References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> Message-ID: <20050810021120.GA25296@alcyon.progiciels-bpi.ca> [Mike Meyer] > [...] I generally wind up cursing at [subversion] at least once a day. Would you accept elaborating a bit on the motivations of the cursing? Your message says Perforce does nice things, one might fuzzily imply that Subversion is bad or misbehaves on the same, but I do not read any definite assertion against Subversion. Having Perforce better does not necessarily makes Subversion bad. So my question. :-) -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From richie at entrian.com Wed Aug 31 08:51:33 2005 From: richie at entrian.com (Richie Hindle) Date: Wed, 31 Aug 2005 13:51:33 +0100 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: <1125490472.670850.247240@g49g2000cwa.googlegroups.com> References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125425945.667967.181000@g49g2000cwa.googlegroups.com> <1125478316.530781.315540@g44g2000cwa.googlegroups.com> <1125490472.670850.247240@g49g2000cwa.googlegroups.com> Message-ID: [n00m] > Funnily but I still can't get the code working... WITHOUT IDLE. > I think it's because of "import thread" line. Seems something > wrong with "opening" this module. In IDLE it works OK. It's difficult to diagnose your problem with so little information. Please post: o The command you're typing into the command prompt o The error message you're getting o The full traceback o The code you're trying to run, or if it's too big then the piece that the last line of the traceback refers to Thanks, -- Richie Hindle richie at entrian.com From haraldarminmassa at gmail.com Mon Aug 1 09:28:44 2005 From: haraldarminmassa at gmail.com (Harald Armin Massa) Date: 1 Aug 2005 06:28:44 -0700 Subject: Dabo in 30 seconds? In-Reply-To: References: <20050730171613.1839738924.EP@zomething.com> <200507302029.34011.jstroud@mbi.ucla.edu> <5e1qe19sflih44nvmso90hnsbgbpef7mjp@4ax.com> Message-ID: <1122902924.784086.179440@o13g2000cwo.googlegroups.com> Cliff (who has a love/hate relationship with Twisted) wrote: > Twisted, for one, can't be used without knowing Python. In fact, > without knowing Python quite well. For that matter, it can't easily be > used . Is "using" really a verb that is fitting for working with twisted? As much as I read and tried to learn, it is not that you use twisted, but you provide twisted with callbacks so that it uses you? So it is more something about devotion or digestion then simply "use", or? Harald From mhenry1384 at gmail.com Tue Aug 16 17:48:01 2005 From: mhenry1384 at gmail.com (mhenry1384) Date: 16 Aug 2005 14:48:01 -0700 Subject: Read from stdouton Popen on WinXP? Message-ID: <1124228881.128382.118050@g47g2000cwa.googlegroups.com> I am trying to run a program and filter the output on Windows XP. Since I want to filter the output, I'd like to read it a line at a time and only print the lines I care about. p = subprocess.Popen(["doxygen.exe", r"Doxyfile.cfg"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while 1: line = p.stdout.readline() if not line: break print line The problem is that readline() only returns after the whole process has completed. I have tried various permutations such as using os.read() and changing the bufsize parameter and using popen4. To no avail. Obviously, it should be possible to read stdout before the process completes, since if I leave off the "stdout=" parameter, the full output shows up in stdout in "realtime" as you'd expect. About the only thing I can come up with is to pipe the .exe to another python script which could communicate to the main script via TCP/IP, but that seems ridiculous. I searched the newsgroup and didn't see anything particularly helpful. Anyone have a non-ridiculous solution? From spam-trap-095 at at-andros.demon.co.uk Thu Aug 4 08:36:40 2005 From: spam-trap-095 at at-andros.demon.co.uk (Andrew McLean) Date: Thu, 4 Aug 2005 13:36:40 +0100 Subject: Python's CSV reader References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> Message-ID: In article <1123130181.767413.109340 at z14g2000cwz.googlegroups.com>, Stephan writes >I'm fairly new to python and am working on parsing some delimited text >files. I noticed that there's a nice CSV reading/writing module >included in the libraries. > >My data files however, are odd in that they are composed of lines with >alternating formats. (Essentially the rows are a header record and a >corresponding detail record on the next line. Each line type has a >different number of fields.) > >Can the CSV module be coerced to read two line formats at once or am I >better off using read and split? > >Thanks for your insight, >Stephan > The csv module should be suitable. The reader just takes each line, parses it, then returns a list of strings. It doesn't matter if different lines have different numbers of fields. To get an idea of what I mean, try something like the following (untested): import csv reader = csv.reader(open(filename)) while True: # Read next "header" line, if there isn't one then exit the loop header = reader.next() if not header: break # Assume that there is a "detail" line if the preceding # "header" line exists detail = reader.next() # Print the parsed data print '-' * 40 print "Header (%d fields): %s" % (len(header), header) print "Detail (%d fields): %s" % (len(detail), detail) You could wrap this up into a class which returns (header, detail) pairs and does better error handling, but the above code should illustrate the basics. -- Andrew McLean From john at hazen.net Wed Aug 31 17:57:05 2005 From: john at hazen.net (John Hazen) Date: Wed, 31 Aug 2005 14:57:05 -0700 Subject: To the python-list moderator In-Reply-To: References: Message-ID: <20050831215705.GB18004@gate2.hazen.net> > > This is probably a fairly bad way of contacting the python-list > > admins... > > Perhaps. Feel free to forward if you know a better way. I tried sending a question to python-list-owner at python.org, and got another 'don't call us, we'll maybe call you'. Maybe postmaster at python.org? > But public posting allows comments by others > as to similar problems, like Gregory's. And mine. FWIW, I'm posting direct to the mailing list with mutt/postfix. Since I *do* have concrol over my headers, it would be nice to see what header is 'suspicious', so I could possibly modify it. It'll be interesting to see if this post makes it to the list... -John From hancock at anansispaceworks.com Wed Aug 24 01:52:06 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 24 Aug 2005 00:52:06 -0500 Subject: loop in python In-Reply-To: <430afc09$0$30445$636a15ce@news.free.fr> References: <20050823065501.GA24558@mrna.tn.nic.in> <430afc09$0$30445$636a15ce@news.free.fr> Message-ID: <200508240052.06556.hancock@anansispaceworks.com> On Tuesday 23 August 2005 05:35 am, bruno modulix wrote: > km wrote: > >>If you want a fast language, try Holden. I've just invented it. > >>Unfortunately it gets the answer to every problem wrong unless the > >>answer is 42, but boy it runs quickly. The code for the whole > >>interpreter (it's written in Python) follows: > > > >>print 42 > > > > great ! u can use it for ur own projects. but pls donot suggest it to > anyone else. > > > If you hope to be taken seriously, please abandon the sms-talk style here. > I think it's reasonably clear that neither poster hoped "to be taken seriously". :-D -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From fakeaddress at nowhere.org Wed Aug 31 18:47:03 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 22:47:03 GMT Subject: OpenSource documentation problems In-Reply-To: References: Message-ID: Fredrik Lundh wrote: > Bryan Olson wrote: >>[...] >> > What additions to that string would you suggest? >> >>Since "help *is* pydoc.help, or at least...", the call could >>show the same thing as help(pydoc.help) > > >>>>import pydoc >>>>help is pydoc.help > > False Say Fredrik, if you're going to proclaim "False", I'd ask that you include the " wrote:" that notes the writer who made the false claim. Your current style almost looks as though you're saying I wrote something that isn't true. -- --Bryan From could.net at gmail.com Thu Aug 4 05:33:16 2005 From: could.net at gmail.com (could ildg) Date: Thu, 4 Aug 2005 17:33:16 +0800 Subject: Does pyparsing support UNICODE strings? In-Reply-To: <20050804172923.A763.SADDLE@gmail.com> References: <311b5ce105080401495341f43d@mail.gmail.com> <311b5ce1050804022415ecc1f8@mail.gmail.com> <20050804172923.A763.SADDLE@gmail.com> Message-ID: <311b5ce10508040233b76e550@mail.gmail.com> So what's you code? and what's you system default encoding? On 8/4/05, saddle wrote: > hello, but i can't run the script. could u told me what's the trick pls? > here is the error output. > > D:\python\test>pyp > sys:1: DeprecationWarning: Non-ASCII character '\xce' in file D:\python\test\py > .py on line 3, but no encoding declared; see http://www.python.org/peps/pep-026 > .html for details > Traceback (most recent call last): > File "D:\python\test\pyp.py", line 9, in ? > greeting = greet.parseString(text) > File "C:\Python24\Lib\site-packages\pyparsing.py", line 616, in parseString > loc, tokens = self.parse( instring.expandtabs(), 0 ) > File "C:\Python24\Lib\site-packages\pyparsing.py", line 558, in parse > loc,tokens = self.parseImpl( instring, loc, doActions ) > File "C:\Python24\Lib\site-packages\pyparsing.py", line 1387, in parseImpl > loc, exprtokens = e.parse( instring, loc, doActions ) > File "C:\Python24\Lib\site-packages\pyparsing.py", line 562, in parse > loc,tokens = self.parseImpl( instring, loc, doActions ) > File "C:\Python24\Lib\site-packages\pyparsing.py", line 873, in parseImpl > raise exc > pyparsing.ParseException: Expected "," (at char 5), (line:1, col:6) > On Thu, 4 Aug 2005 17:24:23 +0800 > could ildg ??????: > > could.net> OK, I make it. > could.net> It's right, it can work fine with unicode. > could.net> pyparsing is great. > could.net> Thanks. > could.net> > could.net> On 8/4/05, could ildg wrote: > could.net> > I want to parse some Chinese words. > could.net> > It seems that pyparsing doesn't work for me. > could.net> > Thank you. > could.net> > I have to use re directly, although it's harder, but it'll always work. > could.net> > > could.net> > On 8/4/05, Robert Kern wrote: > could.net> > > could ildg wrote: > could.net> > > > pyparsing is very convenient to use. But I want to find some a py tool > could.net> > > > to parse non-English strings. Does pyparsing support UNICODE strings? > could.net> > > > If not, can someone tell me what py tool can do it? Thanks in advance. > could.net> > > > could.net> > > Try it! > could.net> > > > could.net> > > # vim:fileencoding=utf-8 > could.net> > > > could.net> > > from pyparsing import Word > could.net> > > > could.net> > > text = "????????, ?????!".decode('utf-8') > could.net> > > alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce)) > could.net> > > > could.net> > > greet = Word(alphas) + u',' + Word(alphas) + u'!' > could.net> > > greeting = greet.parseString(text) > could.net> > > print greeting > could.net> > > > could.net> > > -- > could.net> > > Robert Kern > could.net> > > rkern at ucsd.edu > could.net> > > > could.net> > > "In the fields of hell where the grass grows high > could.net> > > Are the graves of dreams allowed to die." > could.net> > > -- Richard Harter > could.net> > > > could.net> > > -- > could.net> > > http://mail.python.org/mailman/listinfo/python-list > could.net> > > could.net> -- > could.net> http://mail.python.org/mailman/listinfo/python-list > > > From deets at web.de Thu Aug 25 09:34:26 2005 From: deets at web.de (Diez B. Roggisch) Date: 25 Aug 2005 06:34:26 -0700 Subject: variable hell In-Reply-To: <430dc538@127.0.0.1> References: <430dc538@127.0.0.1> Message-ID: <1124976866.259664.265280@g49g2000cwa.googlegroups.com> Nx wrote: > I am unpacking a list into variables, for some reason they need to be > unpacked into variable names like a0,a1,a2....upto aN whatever is > in the list. Explain this "some reason". This smells, and the way to go would be to use a dict mapping a_n to whatever is in the list - not creating variables. How do you want to access generated variables anyway - especially when you don't have the faintest idea how many of them there are? Obviously there can't be code written based on that. Regards, Diez From lycka at carmen.se Tue Aug 30 11:56:57 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 30 Aug 2005 17:56:57 +0200 Subject: Problem with select.poll and popen2 In-Reply-To: References: Message-ID: Magnus Lycka wrote: > I'm trying to read standard out in a process started with popen2 > in a non-blocking way. (Other good ways of doing this than the > one I tried are appreciated.) I'm starting to get on top of this. First of all, I was confused by POLLIN and POLLOUT, since it's IN or OUT of the polling process, so we want the POLLIN filter for the output of the spawned process... Secondly, I thought that I'd get a fd, event pair for each kind of event, but events are bitwise ORed together, and in my dumb downed version I had used a command (date) that ends quickly, and then there is a stream of POLLHUP that comes out of poll, even though I didn't register for that. (Is it supposed to be like that?) The following pair of programs (sender.py first) seems to behave as I intended. Perhaps they can be of use for someone. After all, it's not only sockets that we might want to read in an unblocking way, but it seems most examples are geared towards that. import time, sys while 1: print 'HELLO' sys.stdout.flush() time.sleep(2) .... import sys import select import os CMD = 'python sender.py' fi, fo = os.popen2(CMD) fi.close() p = select.poll() p.register(fo, select.POLLIN) while 1: l = p.poll(500) for (o, evt) in l: if o == fo.fileno() and evt & select.POLLIN: c = fo.read(10) print c, else: print "Timeout!" From beliavsky at aol.com Mon Aug 29 12:43:51 2005 From: beliavsky at aol.com (beliavsky at aol.com) Date: 29 Aug 2005 09:43:51 -0700 Subject: Robust statistics and optimmization from Python References: <1125328346.738915.102990@z14g2000cwz.googlegroups.com> Message-ID: <1125333831.414123.314500@f14g2000cwb.googlegroups.com> Robert Kern wrote: > If you find suitable > FORTRAN or C code that implements a particular "robust" algorithm, it > can probably wrapped for scipy relatively easily. An alternative would be to call R (a free statistical package) from Python, using something like the R/SPlus - Python Interface at http://www.omegahat.org/RSPython/ . Many statistical algorithms, including those for robust statistics, have been implemented in R, usually by wrapping C or Fortran 77 code. From stefan.rank at ofai.at Thu Aug 4 02:31:58 2005 From: stefan.rank at ofai.at (Stefan Rank) Date: Thu, 04 Aug 2005 08:31:58 +0200 Subject: Advanced concurrancy In-Reply-To: <42f154fd$0$14656$ed2619ec@ptn-nntp-reader02.plus.net> References: <42ea98a2$0$1185$ed2619ec@ptn-nntp-reader01.plus.net> <42f154fd$0$14656$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <42F1B65E.9060206@ofai.at> on 04.08.2005 00:36 Michael Sparks said the following: > Peter Tillotson wrote: >>I'm quite interested in the mini version and also using the modules as >>mobile code rather than installing it formally. > > I'll document it slightly better and post up on the website in the next 48 > hours or so. In the meantime, the optimisation test which includes a > slightly modified mini-axon can be found here: > > http://cvs.sourceforge.net/viewcvs.py/kamaelia/Sketches/OptimisationTest/ > > Specifically the file "simplegame.py". Hi, sorry to intrude here. I looked at Kamaelia (Axon actually) recently and I liked it, what I did miss in the code (maybe I just did not find it) is a blocking way for send-ing and recv-ing from in/outboxes that the scheduler is aware of. It seems as though all components basically have to do busy waiting now. So do you plan on including a kind of scheduler-aware blocking communication (like the `channels` of the `tasklets` in stackless)? (as you have a postman already - not a bad idea i think if you compare with multi-agent-systems theory (see jade) - it could be responsible for alerting the scheduler of box.has_data) Cheers, Stefan From ed at leafe.com Mon Aug 1 08:30:27 2005 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Aug 2005 08:30:27 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <200507311709.18243.jstroud@mbi.ucla.edu> References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> Message-ID: <200508010830.27322.ed@leafe.com> On Sunday 31 July 2005 20:09, James Stroud wrote: > Incidentally, I'm not really interested in knowing what is wrong here, > frankly I haven't even looked at the output except that I notice that it is > a stack trace, so don't bother telling me how simple it is to fix and that > I should know this or that. You might be right, but I simply don't care at > this point. > > Sorry dabo guys. You are only one of many. No problem. But let me ask you what would *not* have disappointed you. As others have pointed out, you didn't compile the wxWidgets part of your wxPython install so as to include the stylized text control (yes, it seems silly that you should have to specify that, but that's another thread...) Should we have defensive code for every possible broken installation? We use a lot of the Python standard library modules, many dbapi-compliant modules, and, of course, wxPython. If someone mis-installs one of the pre-requisites, do you expect Dabo to catch that and present you with a diagnostic message? I'm serious here: I want to know what people consider acceptable for a software package that relies on other packages. -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From kevin_little at comcast_net.com Tue Aug 30 22:39:50 2005 From: kevin_little at comcast_net.com (Kevin Little) Date: Tue, 30 Aug 2005 22:39:50 -0400 Subject: Adding bound methods dynamically... CORRECTED References: <4o4ah1h2r53gll81jinueaugpqi7rq7hsj@4ax.com> Message-ID: <7s5ah1t7t2qvseneigb6p1jv9igcl4diri@4ax.com> #!/usr/bin/env python # Sorry... :} cut/paste error fixed... ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or after the class was modified. I need this to work for both old ('classic') and new style classes, at both 2.3 and 2.4. I of course want to avoid side effects, and to make the solution as light-weight as possible. Question for the experts: Is the solution coded in AddBoundMethod() acceptable to the Pythonian Gods? :) It does seem to work -- tested at 2.3.5 (RH Linux) and 2.4.1 (WinXP) Is there a more pythonic way that's as straight forward? ''' def AddBoundMethod( cls, name, method ): ''' Dynamically add to the class 'cls' a bound method. Invoking this method instantly adds (or overwrites) the bound method identified by 'name' with the code contained in 'method', EVEN FOR PRE-EXISTING INSTANCES OF THE CLASS. The 'method' parameter should be a non-class function that has 'self' as its first parameter. ''' try: types except NameError: import types # # this is the crux of this example, short and sweet... # exec "%s.%s = types.MethodType( method, None, %s )" \ % ( cls.__name__, name, cls.__name__ ) # # The remainder (50x longer than the solution!) is test code... # # one new-style class... class NewStyleClass( object ): def __init__ ( self, objname ): print "Created a NewStyleClass, id %d, %s" % \ ( id( self ), objname ) self.objname = objname def ExistingMethod( self, msg ): print "Original ExistingMethod, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) # one 'classic' style class... class OldStyleClass: def __init__ ( self, objname ): print "Created a OldStyleClass, id %d, %s" % \ ( id( self ), objname ) self.objname = objname def ExistingMethod( self, msg ): print "Original ExistingMethod, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) # two non-class functions that *look* like bound methods in a class; # one returns a value, the other just outputs a string... def NeverInOriginalClass( self, msg ): return "Never in original class, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) def NewExistingMethod( self, msg ): print "REPLACED ExistingMethod, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) # a test routine... def Test( cls ): print "--- %s ----------------------------------------------" % \ cls.__name__ print "type of class %s is '%s'" % ( cls.__name__, type( cls ) ) before_change = cls('instance created before change') print "type of object before_change is '%s'" % type(before_change) # 'A' shows that we start with an existing method.... before_change.ExistingMethod( 'A' ) print "*** Replacing bound method 'ExistingMethod'..." AddBoundMethod( cls, "ExistingMethod", NewExistingMethod ) after_change = cls( 'instance created AFTER change' ) print "type of after_change is '%s'" % type( after_change ) # 'B' and 'C' show we've replaced an existing method, both on # pre-existing instances and instances created after using # AddBoundMethod() before_change.ExistingMethod( 'B' ) after_change.ExistingMethod( 'C' ) print "*** Adding new bound method 'AddedMethod'..." AddBoundMethod( after_change.__class__, "AddedMethod", NeverInOriginalClass ) # 'D' and 'E' show we've added a brand new method, both on # pre-existing instances and instances created after using # AddBoundMethod() print "%s" % before_change.AddedMethod( 'D' ) print "%s" % after_change.AddedMethod( 'E' ) if __name__ == '__main__': Test( OldStyleClass ) Test( NewStyleClass ) From peter at somewhere.com Wed Aug 17 05:17:33 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 17 Aug 2005 11:17:33 +0200 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: Simon Brunning schrieb: > On 8/15/05, Rocco Moretti wrote: > >>Which lead me to the question - what's the difference between a library >>and a framework? > > > If you call its code, it's a library. If it calls yours, it's a framework. IOW Apache with modpython is a framework for web apps because it calls your Python handlers. According to Andy Smith the Apache/ modpython combo sucks because it takes away the freedom to call a HTTP library and write your own HTTP server ;) -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From miernik at ffii.org Sat Aug 20 09:49:54 2005 From: miernik at ffii.org (Miernik) Date: Sat, 20 Aug 2005 15:49:54 +0200 Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? Message-ID: <20050820134954.3750.4.NOFFLE@localhost.localdomain.local> On my Debian GNU/Linux system I have Python 2.3 installed in /usr/lib/python2.3/ where most Python system files like /usr/lib/python2.3/gzip.py /usr/lib/python2.3/gzip.pyc /usr/lib/python2.3/gzip.pyo live, besides of course /usr/bin/python2.3 I noticed that all those files come in three "flavours": *.py *.pyc *.pyo Is it possible that only one "flavour" of these files is needed, and I can delete the remaining two, any my Python installation will still work? The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting two "flavours" would save about 10 MB on my system, and that would help me much as I am trying to fit my system on a 256 MB SD card, to make it quiet (hard disks are noisy). Can I just do cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc for example, and everything will still work as before? -- Miernik _________________________ xmpp:miernik at amessage.info ___________________/_______________________/ mailto:miernik at ffii.org Protect Europe from a legal disaster. Petition against software patents http://www.noepatents.org/index_html?LANG=en From mritty at gmail.com Fri Aug 26 06:05:45 2005 From: mritty at gmail.com (Paul Lalli) Date: 26 Aug 2005 03:05:45 -0700 Subject: minimalist regular expression In-Reply-To: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> Message-ID: <1125050745.833419.120910@o13g2000cwo.googlegroups.com> borges2003xx at yahoo.it wrote: > Exists some tool, programs or some able to compute the minimal regular > expression, namely ,taking a series of regular exoression, the minimal > one that makes the same matching? > thanx in advance m//; it matches everything. Perhaps you need to better define your problem statement. Sample input, desired output... Paul Lalli From rkern at ucsd.edu Fri Aug 26 11:00:41 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 26 Aug 2005 08:00:41 -0700 Subject: question on "import __main__" In-Reply-To: References: Message-ID: wen wrote: > i have written some code in test.py as below: > import __main__ > if __name__!='__main__': > print 1 > > print 2 > > when i run test.py, i got > 2 > on the screen. > > now, i have some question about the code, 1. since no __main__ module at > all, why it's legal to write "import __main__"? Because a module object is created for the running script. It is placed in sys.modules with the name "__main__". When you "import __main__", the import mechanism looks in sys.modules first for a module with the name "__main__" and uses that if it's there. > 2. since if running a script independently, the __name__ should be > '__main__', why it's not in the above code? It is. However, you wrote "!=" instead of "==". -- 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 pwatson at redlinepy.com Mon Aug 29 11:56:11 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 29 Aug 2005 10:56:11 -0500 Subject: Python port on Palm Treo? Message-ID: <3ngpgqF1fdulU1@individual.net> Has anyone done or worked on a port of Python to the Treo? From matt.hammond at rd.bbc.co.uk Tue Aug 23 10:47:16 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Tue, 23 Aug 2005 15:47:16 +0100 Subject: Convert float to string ... References: Message-ID: > How can i convert a float value into a string value? Try: string_value1 = str(float_value) + ' abc' or: string_value1 = repr(float_value) + ' abc' Type in an interactive python session. help(str) or: help(repr) regards Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From tjreedy at udel.edu Wed Aug 17 05:10:18 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Aug 2005 05:10:18 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <4302228e.1621136831@news.oz.net> <43028fd5.1649111246@news.oz.net> Message-ID: "Bengt Richter" wrote in message news:43028fd5.1649111246 at news.oz.net... > Yes, the roster model works for me too, but I'm not sure I understand > your > concept of "container/room" ;-) I only meant that if collective objects were containers of objects like rooms are containers of people, then an object could be in only 1 collective at a time. But that is importantly not true. Therefore collectives are not containers. I once mistakenly thought of mathematical sets as being like boxes. Don't know if someone else said so or if I just thought up that error on my own. But then I realized that the box model leads to the the same counterfactual conclusion. Therefore 'box' is a bad metaphor. Sets are rosters. The very term 'member of' is a clue that I missed for years ;-) I hope to help other avoid the same mistake. The roster idea also explains how a set can be a 'member' of itself, and how a list can include itself. Weird, perhaps, but easily possible. The underlying problem is that 'contains' has two meanings: a room contains people by actual presence and hence is a container. A club roster metaphorically contains people by name (reference) as members, but not actually, and hence is not a container even though we may speak of it as 'containing'. Terry J. Reedy From geskerrett at hotmail.com Wed Aug 3 07:30:47 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 3 Aug 2005 04:30:47 -0700 Subject: Python for embedded linux? In-Reply-To: References: Message-ID: <1123068647.605304.53060@g47g2000cwa.googlegroups.com> I think this is what you are looking for. http://www.voidspace.org.uk/python/movpy/ From finite.automaton at gmail.com Mon Aug 8 17:33:54 2005 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 8 Aug 2005 14:33:54 -0700 Subject: Why does __init__ not get called? References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> Message-ID: <1123536834.629449.154790@g44g2000cwa.googlegroups.com> Uh... are you actually trying to instantiate this class? mydate = DateTime(2005, 8, 8) The reason I ask is that __init__ /is/ called when I run your code on Python 2.4, provided that the above line is added to the end. From donn at u.washington.edu Mon Aug 22 14:40:27 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 22 Aug 2005 11:40:27 -0700 Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Before leaving this topic, I wanted to make a rare visit to the ruins of Google's USENET archive and pull out this giant post on the subject of True and False, when they were being considered for adoption into Python. There is some stuff to ignore, where she addresses questions that didn't go anywhere, but she goes on to write a well articulated case that makes very interesting reading, and possibly has had some effect on how people think about it around here. http://groups-beta.google.com/group/comp.lang.python/msg/2de5e1c8384c0360 Donn Cave, donn at u.washington.edu From onurb at xiludom.gro Fri Aug 12 04:55:40 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 12 Aug 2005 10:55:40 +0200 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123817414.665062.282500@g49g2000cwa.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123817414.665062.282500@g49g2000cwa.googlegroups.com> Message-ID: <42fc640e$0$22461$626a14ce@news.free.fr> Devan L wrote: > Fausto Arinos Barbuto wrote: > >>Ray wrote: >> >> >>>1. Where are the access specifiers? (public, protected, private) >> >> AFAIK, there is not such a thing in Python. >> >>---Fausto > > > Well, technically you can use _attribute to mangle it, __attribute would work better !-) > but technically > speaking, there are no public, protected, or private things. Yes there are: object.name is public object._name is protected object.__name is private You don't need the language to enforce this, it's just a matter of conventions. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From bokr at oz.net Wed Aug 10 09:23:22 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 10 Aug 2005 13:23:22 GMT Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> <42f98217.1055829672@news.oz.net> <1123677037.339759.216980@g47g2000cwa.googlegroups.com> Message-ID: <42f9fb59.1086871718@news.oz.net> On 10 Aug 2005 05:30:37 -0700, geskerrett at hotmail.com wrote: >Thanks so much for this. It is exactly what I was looking for. > >If I am simply reading the bytes from disk, would I still need to >convert the these values HEX characters first with Hexlify, or is there >a more direct route ? >ie. convert them to the double float directly from the byte values ? Yes. Use struct.unpack ;-) BTW, my second post was doing ''.join(chr(int(h[i:i+2],16)) for i in xrange(0,16,2)) to undo the hexlify you had done (I'd forgotten that there's a binascii.unhexlify ;-) Regards, Bengt Richter From sxanth at ceid.upatras.gr Thu Aug 25 14:23:09 2005 From: sxanth at ceid.upatras.gr (Stelios Xanthakis) Date: Thu, 25 Aug 2005 21:23:09 +0300 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: <430E0C8D.5000506@ceid.upatras.gr> Mark Dickinson wrote: > I have a simple 192-line Python script that begins with the line: > > dummy0 = 47 > > The script runs in less than 2.5 seconds. The variable dummy0 is never > referenced again, directly or indirectly, by the rest of the script. > > Here's the surprise: if I remove or comment out this first line, the > script takes more than 15 seconds to run. So it appears that adding a > redundant line produces a spectacular six-fold increase in speed! > > (Actually, I had to add 29 dummy lines at the beginning of the code to > get the speed increase; if any one of these lines is removed the > running time reverts to around 15 seconds again.) > > Questions: > > (1) Can anyone else reproduce this behaviour, or is it just some quirk > of my setup? > (2) Any possible explanations? Is there some optimization that kicks > in at a certain number of lines, or at a certain length of > bytecode? > (3) If (2), is there some way to force the optimization, so that I can > get the speed increase without having to add the extra lines? > Hi. I haven't been able to reproduce this but I had a similar case before (a program that some times crashed and some times worked perfectly and the difference was whitespace in the comments!!!). After lots of wondering and thinking that I must be dreaming (luckily I had pyvm which also crashed but for different amounts of whitespace), it was solved. The explanation is this: hash and comparison of objects depends on the state of the memory allocator. A sample case is this: class A: pass dummy0=47 # comment this to get a different result for min a=A() b=A() print min (a, b) the result of 'min' is not only non-deterministic but also depends on whether other things have been allocated before. The same thing can happen for 'dictionary.keys()' if the keys are objects and 'iterate-over-set' when the set contains objects. In the sudoku solver, there is a min (number, object) which is probably what's affected by the extistance of the dummy variable. Now, in sudoku puzzles some times the algorithm has to suppose that in a box the right solution is one of the possible, try it and if it fails then try the other one. I guess that the result of from the different 'min' leads the solver to first try the correct solution in the fast case and therefore need not attempt the wrong one. Or at least this is what I think that happens. By the way, since we started posting code, here is a more pythonic sudoku solver. #----The 'man with scissors runs around shifting barrels algorithm' from sys import argv SEMANTIC = 1'SEM' in argv class Impossible: pass Patterns = [] for r in range (9): for c in range (9): p = 27*(r/3) + 3*(c/3) pl = set (range (9*r, 9*r+9) + range (c, 81, 9) + [p+x for x in (0,1,2,9,10,11,18,19,20)]) pl.remove (9*r+c) Patterns.append (tuple (sorted (list (pl)))) def initboard (): x = range (1, 10) return [ x [:] for i in xrange (9*9) ] def printboard (board): if not SEMANTIC: return print 30*'-' for i in range (9): for j in board [9*i:9*(i+1)]: if type (j) is list: #print 'X', print ''.join (map (str, j)), else: print j, print print 30*'-' def dupboard (board): B = [] for i in board: if type (i) is list: B.append (i [:]) else: B.append (i) return B def solve (board, coords): while coords: p, v = coords.pop () board [p] = v for i in Patterns [p]: if type (board [i]) is list: if v in board [i]: board [i].remove (v) if len (board [i]) == 1: board [i] = board [i][0] coords.append ((i, board [i])) else: if board [i] == v: raise Impossible for p, i in enumerate (board): if type (i) is list: for j in i: try: return solve (dupboard (board), [(p, j)]) except Impossible: pass raise Impossible return board PP = [ [ "7xxxxxx19", "46x19xxxx", "xxx6827x4", "x9xxxxxx7", "xxx3xx4x5", "xx67xxxxx", "xx1xxxxxx", "2xxx74xxx", "xxx2xx3xx", ] ] def puz2coord (P): if len (P) != 9: print "P must have 9 rows" raise SystemExit coords = [] for r, i in enumerate (P): if len (i) != 9: print "Row [%s] doesn't have 9 columns" %i raise SystemExit for c, j in enumerate (list (i)): if j != 'x': coords.append ((9*r + c, int (j))) return coords try: if SEMANTIC: for i in xrange (10): for P in PP: printboard (solve (initboard (), puz2coord (P))) else: for i in xrange (TIMES): for P in PP: printboard (solve (initboard (), puz2coord (P))) except Impossible: print "IMPOSSIBLY IMPOSSIBLE" From berlin.brown at gmail.com Sun Aug 14 22:15:30 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Sun, 14 Aug 2005 22:15:30 -0400 Subject: Loading classes dynamically Message-ID: What is the most pythonic way to load a class and instaniate an object dynamically. Right now, I am using eval: try: load = eval('%s(props)' % (props['plugin.generate'])) except: It works, doesnt seem very safe. Where props['plugin.generate'] is a class name string. And 'props' is the first arg in the constructor. What do you think? -- Ramza from Atlanta http://www.newspiritcompany.com From pydecker at gmail.com Mon Aug 1 16:52:12 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 1 Aug 2005 16:52:12 -0400 Subject: Wheel-reinvention with Python In-Reply-To: <7xirypjsua.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <7x1x5do2da.fsf@ruckus.brouhaha.com> <7xirypjsua.fsf@ruckus.brouhaha.com> Message-ID: On 01 Aug 2005 13:38:21 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Peter Decker writes: > > We were discussing your 'enormous pain' installing wxPython. I find it > > interesting that you selectively quoted part of one line of my post, > > Yes, the one line I quoted was the one that said most people have > wxPython installed, which is a preposterous claim. OK, troll, the above is an actual quote. Now how about if I selectively quote part of one of your sentences instead? > most people have wxPython installed Wow, how could you make such a claim!? Gee, isn't it interesting how you can distort someone's intent by leaving out certain parts of what they wrote? Well, I think you've adequately displayed your integrity here in your desperate attempt to convert everyone to your One True Purist Faith. I'm done feeding the troll. -- # p.d. From tjreedy at udel.edu Sat Aug 6 18:38:24 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 6 Aug 2005 18:38:24 -0400 Subject: Some simple performace tests (long) References: <1123334835.548075.129430@z14g2000cwz.googlegroups.com> Message-ID: "TPJ" wrote in message news:1123334835.548075.129430 at z14g2000cwz.googlegroups.com... > "The advantage of xrange() over range() is minimal (since xrange() > still has to create the values when asked for them) except when a very > large range is used on a memory-starved machine or when all of the > range's elements are never used (such as when the loop is usually > terminated with break)." - from Python Library Reference. Nothing in your results, properly interpreted, contradicts this. > I decided to measure the performance of range and xrange. On one machine, with one binary. Relative performance on different systems can vary by, say, 10%. But of course, if you are optimizing a program to run on just one machine, then the results on that machine are all that matters. > I did it with the following functions: > > def rprint( n ): > a = time.time() > for i in range(n): print i > print time.time() - a > > def xrprint( n ): > a = time.time() > for i in xrange(n): print i > print time.time() - a To compare two things, one wants to remove all possible noise factors. If one wants relative performance (ratios, percentages) then constant factors should also be removed, when possible, to make the apparent difference as close to the real difference as possible. Print is a large constant + large noise factor that you *DO NOT* want for the stated comparison. It requires a call through lots of OS code with variable execution times. > def rpass( n ): > a = time.time() > for i in range(n): pass > print time.time() - a > > def xrpass( n ): > a = time.time() > for i in xrange(n): pass > print time.time() - a This is the right comparison for the reasons noted. > The results were as follows: > > n rprint xrprint > > 10^4 0.37 s 0.34 s <- (1) > 10^5 4.26 s 4.25 s > 10^6 42.57 s 42.57 s > 10^7 431.94 s 438.32 s <- (2) These times with print are about 300x the results below without print. They are useless for comparing range and xrange. The differences above are differences in printing (display) times and not in range versus xrange. Think about it. When the differences between runs with print are several times as large as the total time without, then those large differences cannot have anything to do with the minor difference in looping method. > n rpass xpass > > 10^4 0.0012 s 0.0011 s > 10^5 0.0220 s 0.0139 s > 10^6 0.1463 s 0.1298 s > 10^7 1.4818 s 1.1807 s The looks more coherent. > The values are the average times printed by tested functions. > > Conclusions: > > 1) According to (1) I could say that xrange might be somewhat faster > than range with lower numbers of iterations. > 2) According to (2) I could say that xrange might be slower than range > with higher number of iterations. You could, but you would be wrong. The second table shows that xrange is slightly faster on your machine over the range tested. > The test with pass is not so important as the test with print (because > we usually do something inside of loops). This is completely backwards for the reasons already given. The point about doing something inside loops in relevant in so far as it says the that the minor difference between range and xrange, whichever way it goes on a particular system, will matter relatively even less in application. So the choice hardly matters unless space is a considerations. Which is what the quoted docs more or less said. > import array, random, time To reduce random noise from random, the generator should be reinitialized with the seed(someint) at the beginning of each function. This is the purpose of seed(x). But for the comparisons you are making, randomness is irrelevance and the time for calls to random a nuisance. > def test1( n, size ): > a = time.time() > for i in xrange(n): > l = [] > for i in xrange(size): > l.append( random.randint( 1,10 ) ) > e = sum(l) / float(size) # just for taking some time This is exactly what you DO NOT WANT TO DO for comparing anything else. > print time.time() - a > def test2( n, size ): > a = time.time() > l = [] > for i in xrange(n): > del l[:] > for i in xrange(size): > l.append( random.randint( 1,10 ) ) > e = sum(l) / float(size) > print time.time() - a This is trivially different. To test 'l = []' versus 'del l[:]', test just that. > def test3( n, size ): > a = time.time() > l = range(size) > for i in xrange(n): > for i in xrange(size): > l[i] = random.randint( 1,10 ) > e = sum(l) / float(size) > print time.time() - a It is not surprising that allocating a list just once and filling it in is faster than starting empty and expanding and copying multiple times. In any case, if you want to test that, test just that without all the noise and masking of other stuff. I did not look at the slicing stuff. Terry J. Reedy From sysfault at scrpy.org Sun Aug 21 20:36:04 2005 From: sysfault at scrpy.org (sysfault) Date: Sun, 21 Aug 2005 20:36:04 -0400 Subject: Decorator and Metaclasses Documentation References: <1124668873.380249.119630@f14g2000cwb.googlegroups.com> Message-ID: On Sun, 21 Aug 2005 17:01:13 -0700, Jeffrey E. Forcier wrote: > Amusingly, I was just perusing these links earlier today. Go go Firefox > history search! > > http://www.python.org/2.2/descrintro.html > http://users.rcn.com/python/download/Descriptor.htm Are descriptors the same thing as decorators? -- A wise man knows he knows nothing. From tjreedy at udel.edu Thu Aug 11 15:31:58 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Aug 2005 15:31:58 -0400 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com><42F9BC7D.1050300@le.ac.uk> <42FB55BC.70608@sweetapp.com> Message-ID: "Brian Quinlan" wrote in message news:42FB55BC.70608 at sweetapp.com... > There is a difference between everything being an object and everything > being an instance of a class. In Python, every runtime entity is an > object but not everything is a class instance. However, everything is an instance of a class or type. And once old-style classes are dropped, all classes will be user-defined types and types will be built-in classes. And it seems that for instances of such unified type-classes, type(x) == x.__class__: >>> type(int) >>> int.__class__ >>> class c(object): pass ... >>> c1 = c() >>> type(c1) >>> c1.__class__ # don't know if user metaclasses can change this or not So the distinction, if kept, will be pretty thin. Terry J. Reedy From robin at reportlab.com Mon Aug 15 09:52:05 2005 From: robin at reportlab.com (Robin Becker) Date: Mon, 15 Aug 2005 14:52:05 +0100 Subject: SOAP and XMLRPC In-Reply-To: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Message-ID: <43009E05.5040402@chamonix.reportlab.co.uk> dcrespo wrote: > Hi to all... > Someone knows if is there possible to have a Python SOAP or XMLRPC > server that works with VB? I would like you to include the examples > clients and server programs. > > My examples are: > ...... > > These programs work perfect. The thing is that I need to access the > server from VB (like does SOAPpy accessing google's services) > > Many thanks > > Daniel > A student whom I helped recently did a project on the various web service protocols. Interoperability for SOAP was not very good. XMLRPC was much better and he got java -- python etc etc pretty easily. -- Robin Becker From accepted at ukr.net Tue Aug 2 12:31:55 2005 From: accepted at ukr.net (Michael Rybak) Date: Tue, 2 Aug 2005 19:31:55 +0300 Subject: 2-player game, client and server at localhost In-Reply-To: References: Message-ID: <5137720739.20050802193155@ukr.net> CS> Michael Rybak wrote: >> That's the problem - "or a player input comes in". As I've explained, >> this happens a dozen of times per second :(. I've even tried not >> checking for player's input after every frame, but do it 3 times more >> rare (if framecount % 3 == 0 : process_players_input()). Well, I've >> already got it that I shouldn't tie this around framerate, but >> nevertheless... CS> There's the key. How are you processing network input, specifically CS> retrieving it from the socket? A "sock" class has a socket with 0.00001 timeout, and every time I want anything, I call it's read_command() method until it returns anything. read_command() and send_command() transfer user's actions in special format so that it takes 10 bytes per transfer. I believe this should be rewritten to be done in a separate thread, and that *current* user input should be processed as *next* one: while 1: render() inp = get_player_input() thread.start_new(send_inp, (inp,)) thread.start_new(accept_opponents_inp, ()) while still_no_opponents_input_from_previous_iteration() time.sleep(0.05) process_previous_player_input() physics.make_step I will try writing it that way, but I doubt it shall make things much better... You see, I've tried the normal 1-server-2-clients approach with Pyro (and today with simulating RMI proxy via UDP), and resulted with nothing comforting. Please read the "using Pyro for network games" topic here for details. -- Best Regards, Michael Rybak mailto:accepted at ukr.net Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! P.S. here's the sock class. My server_sock and client_sock are derived from it, with additional accept_connection and establish_connection methods respectively. #sock.py import socket import com_network import constants as c_ class sock: def __init__(self, host): self.host = host self.port = c_._PORT self.sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sockobj.settimeout(0.00001) self.curcon = None #connection will be created and saved here self.connected = False def read_command(self): """format: command_id - 1 byte command_size - CMD_LEN_BIT_SIZE bytes command_text - command_size bytes returns a triple (int id, int size, str text)""" if not self.connected: return (None, None) cmd = com_network.read_fixed(self.curcon, 1) if len(cmd) < 1: #no cmd return (None, None) sz = com_network.read_fixed(self.curcon, CMD_LEN_BIT_SIZE) cmd, sz = str_to_cmd(cmd + sz) text = com_network.read_fixed(self.curcon, sz) return (cmd, text) def send_command(self, cmd, obj): send_text(self.curcon, com_network.cmd_to_str(cmd, str(obj))) def close(self): if self.connected: self.connected = False self.curcon.close self.curcon = None self.sockobj.close() From esleben at gmail.com Thu Aug 4 08:45:52 2005 From: esleben at gmail.com (Jan-Ole Esleben) Date: Thu, 4 Aug 2005 14:45:52 +0200 Subject: Metaclasses and class variables Message-ID: <3756d97505080405455abbc38b@mail.gmail.com> Hi! I am new to this list, and maybe this is a stupid question, but I can't seem to find _any_ kind of answer anywhere. What I want to do is the following: I want to insert a class variable into a class upon definition and actually use it during definition. Manually, that is possible, e.g.: class A: classvar = [] classvar.append(1) classvar.append(2) I don't want to explicitly set the variable, though. My idea was to write the following: class Meta(type): def __new__(cls, name, bases, d): d['classvar'] = [] return type.__new__(cls, name, bases, d) class Test: __metaclass__ = Meta classvar.append(1) classvar.append(2) However, Python complains that the variable isn't defined; it can be found in the class dictionary _after_ definition, though, and then it can also be used. But where's the conceptual difference (to the manual approach)? Thanks in advance, Ole From steven.bethard at gmail.com Mon Aug 29 11:48:14 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 29 Aug 2005 09:48:14 -0600 Subject: trictionary? In-Reply-To: References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> <17170.32358.268677.962644@roam.psg.com> Message-ID: Adam Tomjack wrote: > I'd write it like this: > > bin = {} > for start, end, AS, full in heard: > week = int((start-startDate)/aWeek) > counters = bin.setdefault(week, [0, 0]) > if full: > counters[0] += 1 > else: > counters[1] += 1 > > for week, (times_full, times_not_full) in bin.iteritems(): > print ... > > Seriously, use setdefault() as often as you can. It may be a little > awkward at first, but after a little bit, you instantly know what it > means. It takes out a whole if/else statement which will make your code > smaller and more readable at the same time. However, you should be aware that it can make your code slower. If the default value is expensive to create, value = dct.setdefault(key, expensive_func()) will often be slower and/or more memory intensive than try: value = dct[key] except KeyError: value = expensive_func() or if key in dct: value = dct[key] else: value = expensive_func() Personally, I waver back and forth between using setdefault. It's kind of handy, but it never reads quite right. While I've used it often enough to grok it pretty quickly, it's still consumes more of my mental processing than some other approaches. I also tend to agree with the assessment[1] (I believe due to Raymond Hettinger) that setdefault is poorly designed, and should instead set a default value for the entire dictionary, e.g. so that you could do: counts = {} counts.setdefault(value=0) for elem in data: counts[elem] += 1 Unfortunately, this is pretty badly backwards incompatible, so I can only really hope for this change in Python 3.0 which is still a number of years off. STeVe [1]http://wiki.python.org/moin/Python3%2e0Suggestions#head-b384410f8b2dc16fd74c9eec764680e428643d73 From benn at cenix-bioscience.com Fri Aug 12 07:32:20 2005 From: benn at cenix-bioscience.com (Neil Benn) Date: Fri, 12 Aug 2005 13:32:20 +0200 Subject: pywin32 from network install In-Reply-To: <1123843217.146107.302100@g44g2000cwa.googlegroups.com> References: <1123843217.146107.302100@g44g2000cwa.googlegroups.com> Message-ID: <42FC88C4.5020002@cenix-bioscience.com> agostino.russo at gmail.com wrote: >I managed to make pywin32 work from a network installation (not really >hard work: a shared folder + copying some dlls + setting PYTHONPATH). >PythonWin amd COM seem to be working fine from the network install, BUT >when I need to pass PyTime to a COM object expecting a Date I get the >following error: > >Python24\Lib\site-packages\win32com\client\dynamic.py", line 251, in >_ApplyTypes_ > result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, >argTypes) + args) >TypeError: Objects of type 'time' can not be converted to a COM VARIANT > >Note 1: The same code works when using the local installation of >python/pywin, it only happens when executing the code from a network >"installation". > >Note 2: As mentioned other COM components seem to be working when >running them via pywin from the network install > >Note 3: I am passing pywintipes.Time(datetime.datetime.today()) to a >COM object method which expects a Date argument. > >Do I need to change some environment variable/registry settings/other >hack to fix this? > > > Simply moving the win32 install and setting the python path isn't all you need to do to get a network install working. In addition, you need to remove the win32 from your local install (or piss around with sys.path to strip out those local references) as that will automatically be included. In addition, there is a registry setting you need to delete which automagically adds to the python path - it's in HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE. That's probably won't solve your problem but it's somethng to be aware of anyways. Neil -- 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 look-on at mindprod.com.invalid Mon Aug 22 16:44:44 2005 From: look-on at mindprod.com.invalid (Roedy Green) Date: Mon, 22 Aug 2005 20:44:44 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: On 22 Aug 2005 11:43:09 -0700, "Xah Lee" wrote or quoted : >the unix morons, think that the world should truncate lines just like >their incompetent operating system silently truncate lines (and it >still DOES, folks! e.g. ps, tar, tcsh.) Around 1998 when i was using >Outlook Express or Eudora before that, i remember i can set lines to >not hard-wrap, and i did. The telephone did not evolve, other than touch tone dialing. It took cellphones to let people start over several times to get any changes. Communications are slow to evolve because they require both ends to change. This is almost impossible to accomplish politically. This is why email and newsgroups will have to die and be replaced with something entirely new that lets you transmit richer content, prevents spam, verifies authorship, tracks attributions, does instant delivery notification etc. The problem is it will be very difficult for anything no matter how cheap or technologically brilliant to get a foothold against the quite wonderful entrenched distributed delivery of newsgroups. Perhaps at some point will at least allow program listing that don't wrap inappropriately, and HTML for displaying tables. From rafi at free.fr Mon Aug 22 16:53:40 2005 From: rafi at free.fr (rafi) Date: Mon, 22 Aug 2005 22:53:40 +0200 Subject: split function In-Reply-To: References: Message-ID: <430a3b4a$0$11971$636a15ce@news.free.fr> Mohammed Altaj wrote: > Dear All > > What i want to do is , my input is like > 0 2 > 0 3 > 0 4 > 1 2 > 1 4 > 2 3 > 3 4 > > I am comparing and put the number in group , like ,the first three lines > , all has zero as first input for each line, so the out put should look > like > 0 2 3 4 > and so on > 1 2 4 > 2 3 > 3 4 > > I managed to do what i need , but i did in this case , there is no space > between numbers , like > 02 > 03 > 04 > 12 > 14 > 23 > 34 > > so , how can i do this with spaces between numbers with a two pass processing (one for building the output, one for its printing), using a dict to make lists for each index (everything is treated as strings as you do not compare nor compute them) results = dict () input = file ('input.dat') for line in input: idx, value = line.split () if idx in results: results [idx] .append (value) else: results [idx] = [value] input.close () output = open ('output.dat', 'w') for idx, values in results.items (): output.write ('%s %s\n' % (idx, ' '.join (values))) output.close () you can define two function, in case of your output may vary in the future. > [snip your code] 8 levels of indentation seems really to much for a good ppiece of code from my point of view. my 2 cents -- rafi "Imagination is more important than knowledge." (Albert Einstein) From max at alcyone.com Thu Aug 18 22:10:15 2005 From: max at alcyone.com (Erik Max Francis) Date: Thu, 18 Aug 2005 19:10:15 -0700 Subject: Python jobs (was Re: Python for Webscripting (like PHP)) In-Reply-To: References: Message-ID: Peter Decker wrote: > Then start looking for telecommuting people. There are lots of us who > can use work and have excellent telecommuting references, but who > don't happen to live in a major metro area! And then there's some in the Bay Area who wouldn't mind telecommuting, either ... :-) -- 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 is no present or future; only the past, happening over and over again, now. -- Eugene O'Neill From zarnovican at gmail.com Thu Aug 18 13:51:13 2005 From: zarnovican at gmail.com (BranoZ) Date: 18 Aug 2005 10:51:13 -0700 Subject: extending: new type instance In-Reply-To: References: <1124206969.965729.290240@g43g2000cwa.googlegroups.com> Message-ID: <1124387473.626483.285880@g49g2000cwa.googlegroups.com> Michael Hudson wrote: > PyObject_New is the usual way, although there are others -- Thanks for an answer ! > MyType.tp_new, PyObject_Call ... Does this mean, that I can call my newly defined MyType_new, MyType_init directly ?? I was afraid that Python might do some pretty important housekeeping stuff around them. BranoZ From rkern at ucsd.edu Tue Aug 30 08:24:55 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 30 Aug 2005 05:24:55 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> < Message-ID: Bryan Olson wrote: > Robert Kern wrote: > > from Numeric import * > > A = array([[0, 1], [2, 3], [4, 5]]) > > A[$-1, $-1] > > > > The result of len(A) has nothing to do with the second $. > > I think you have a good observation there, but I'll stand by my > correctness. len() cannot be used to determine the value of $ in the context of multiple dimensions. > My initial post considered re-interpreting tuple arguments, but > I abandoned that alternative after Steven Bethard pointed out > how much code it would break. Modules/classes would remain free > to interpret tuple arguments in any way they wish. I don't think > my proposal breaks any sane existing code. What it does do is provide a second way to do indexing from the end that can't be extended to multiple dimensions. > Going forward, I would advocate that user classes which > implement their own kind of subscripting adopt the '$' syntax, > and interpret it as consistently as possible. How? You haven't proposed how an object gets the information that $-syntax is being used. You've proposed a syntax and some semantics; you also need to flesh out the pragmatics. > For example, they > could respond to __len__() by returning a type that supports the > "Emulating numeric types" methods from the Python Language > Reference 3.3.7, and also allows the class's methods to tell > that it stands for the length of the dimension in question. I have serious doubts about __len__() returning anything but a bona-fide integer. We shouldn't need to use incredible hacks like that to support a core language feature. -- 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 uche.ogbuji at gmail.com Thu Aug 25 17:10:08 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 25 Aug 2005 14:10:08 -0700 Subject: Limited XML tidy In-Reply-To: References: Message-ID: <1125004208.581551.205680@g44g2000cwa.googlegroups.com> > The problem is that when the sax handler raises an exception, I can't see how to find out why. What I want to do is for DodgyErrorHandler to do something different depending on where we are in the course of parsing. Is there anyway to get that information back from xml.sax (or indeed from any other sax handler?) You can get raw location information, yes. See: http://www.xml.com/pub/a/2004/11/24/py-xml.html But I don't think this is enough for you. You also need recovery, which you're implementing in crude form. I tend to agree with Magnus that using an SGML parser might be your best bet. You might even be able to turn that SGML into XML using a tool such as James Clark's SX: http://www.jclark.com/sp/sx.htm -- Uche http://copia.ogbuji.net From ptmcg at austin.rr.com Tue Aug 23 17:54:36 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 23 Aug 2005 14:54:36 -0700 Subject: Reading just a few lines from a text file In-Reply-To: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> References: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> Message-ID: <1124834076.521797.60180@z14g2000cwz.googlegroups.com> Are you sure this is really slowing down your program? "Many hundreds of lines" is not nearly enough to start Python breathing hard. I have been really impressed with just how quickly Python is able to do file input and processing, zipping through whole megs of data in just seconds. How are you currently reading the file in? A character at a time? That *will* be slow. Try file.readlines(), or xreadlines(), and spin off the last 20 in the list. -- Paul From sjmaster at gmail.com Wed Aug 3 12:30:51 2005 From: sjmaster at gmail.com (Steve M) Date: 3 Aug 2005 09:30:51 -0700 Subject: trying to parse non valid html documents with HTMLParser In-Reply-To: <42f0e5d0$0$20055$636a15ce@news.free.fr> References: <42efc9ae$0$12924$636a15ce@news.free.fr> <42f0e5d0$0$20055$636a15ce@news.free.fr> Message-ID: <1123086651.355459.83160@f14g2000cwb.googlegroups.com> >You were right, the HTMLParser of htmllib is more permissive. He just ignores the bad tags ! The HTMLParser on my distribution is a she. But then again, I am using ActivePython on Windows... From s_david_rose at hotmail.com Fri Aug 19 09:26:41 2005 From: s_david_rose at hotmail.com (GMane Python) Date: Fri, 19 Aug 2005 09:26:41 -0400 Subject: Netware Python? Message-ID: Hello all. Looking, I have not found a version of Python which runs on Netware by Novell. I wonder, since Java there is a Java for Netware, is this where Jython would come in as useful, to be able to use a Python script where Java is installed? I'm interested in the threaded heartbeat program in the cookbook for my Netware environment, to be connected to a nice graphical front end on my Win32 station, to know when servers are up or down (well, since Netware is hardly ever down, when the WAN links are up or down) -dave From jdennett at acm.org Sun Aug 14 14:56:26 2005 From: jdennett at acm.org (James Dennett) Date: Sun, 14 Aug 2005 11:56:26 -0700 Subject: Euclid's Algorithm in Python? In-Reply-To: References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> <1123461062.574511.278540@g43g2000cwa.googlegroups.com> <42f6aef7.870709213@news.oz.net> Message-ID: Antoon Pardon wrote: > On 2005-08-08, Bengt Richter wrote: > >>On 7 Aug 2005 17:31:02 -0700, "Jordan Rastrick" wrote: >> >> >>>Good point. I suppose I'd only ever seen it implemented with the if >>>test, but you're right, the plain while loop should work fine. Silly >>>me. >>> >>>def gcd(a,b): >>> while b != 0: >>> a, b = b, a%b >>> return a >>> >>>Even nicer. >>> >> >>what is the convention for handling signed arguments? E.g., > > > As far as I understand the convention is it doesn't make > sense to talk about a gcd if not all numbers are positive. > > I would be very interested if someone knows what the gcd > of 3 and -3 should/would be. Within the integers, common definitions of gcd don't distinguish positive from negative numbers, so if 3 is a gcd of x and y then -3 is also a gcd. That's using a definition of gcd as something like "g is a gcd of x and y if g|x and g|y and, for any h such that h|x and h|y, h|g", i.e., a gcd is a common divisor and is divisible by any other common divisor. The word "greatest" in this context is wrt the partial ordering imposed by | ("divides"). (Note that "|" in the above is the mathematical use as a|b if there is an (integral) c such that ac=b, i.e., b is divisible by a. These definitions generalize to rings other than the integers, without requiring a meaningful < comparison on the ring.) All of that said, it would be reasonable when working in the integers to always report the positive value as the gcd, to make gcd a simpler function. For some applications, it won't matter if you choose positive or negative, so going positive does no harm, and others might be simplified by assuming gcd>0. -- James From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 3 03:37:27 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 03 Aug 2005 09:37:27 +0200 Subject: Setting a drive's volume label In-Reply-To: <2NmdnaO6zf9Q323fRVn-pQ@nmt.edu> References: <2NmdnaO6zf9Q323fRVn-pQ@nmt.edu> Message-ID: <3lbahoF1143nqU1@individual.net> Bob Greschke wrote: > Looks like the "label" system command will do it in Windows. That's good > enough for this exercise. So, in Linux...??? "mlabel" in the "mtools" package will do what you need. "mkfs.vfat" can also be given a volume label, but it will not allow you to set the label without creating a new filesystem :) Reinhold From cliff at develix.com Wed Aug 3 16:46:26 2005 From: cliff at develix.com (Cliff Wells) Date: Wed, 03 Aug 2005 13:46:26 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <86r7db16a9.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <8664uqhkfj.fsf@bhuda.mired.org> <86hde9f172.fsf@bhuda.mired.org> <86r7dbeuvq.fsf@bhuda.mired.org> <86r7db16a9.fsf@bhuda.mired.org> Message-ID: <1123101986.7189.12.camel@localhost.localdomain> On Wed, 2005-08-03 at 09:47 -0400, Mike Meyer wrote: > Cliff Wells writes: > > > On Tue, 2005-08-02 at 20:17 -0400, Mike Meyer wrote: > > > >> Um - you're not answering the question I asked. I asked "What app do I > >> use to bundle my applications for Unix, ala py2exe (or whatever it is) > >> for Windows?" You're telling me how to install wxPython on those > >> platforms. > >> I know how to install wxPython. What I want to know is how to build an > >> application bundle for all those Unix systems for a Python app I use > >> that includes wxPython - or any other third party libraries I may be > >> using. > > > > Sorry, I assumed you'd know about distutils: > > Cliff, please quit being an ass. You keep assuming that because some > tool isn't the answer to my question that I don't know about > it. That's simply rude. It would be *much* more polite to ask "What's > wrong with distutils" rather than saying "So you don't know about > distutils." Since you said "please". I'll try to forget about "the wonders of X" comment you made that I found just as rude. > > http://www.python.org/doc/current/dist/ > > http://www.python.org/doc/current/dist/built-dist.html > > > > distutils can go so far as to build an rpm for you, but you'll need to > > package things like .debs yourself. > > I've very familiar with distutils. It doesn't do what I asked for, in > that it only bundles up *my* code. It doesn't bundle the things I > depend on the way py2exe does. It's patently *not* the answer to the > question I asked. It can. It isn't terrifically easy, but distutils can be used to package up 3rd party libraries, including binary libs. It can, in fact, package up any file you so desire. > For those who want .deb's out of distutils, there's a PR on > sourceforge that includes a patch to make it generate .debs that works > quite well. I wasn't aware of that. Nice. > Of course, anyone who built a .deb (or an RPM, or a port, or whatever) > that bundled up everything it needed would be doing *the wrong > thing*. Those formats are designed for packaging single distributions, > not applications. They include dependency information that is used to > fetch the dependencies and install them. From my standpoint, the > problem here is that you then have to get the dependencies into the > repository before you can put your application there and have it > work. For instance, my port of bicyclerepairman is stuck at an old > version because I haven't gotten a port PyMac accepted yet (it also > has to do with bugs in the xemacs port, but that's another story). > > I'm surprised you haven't mentioned eggs yet. Those work across all > the platforms I named. Of course, they aren't the answer to my > question either, because, like PRMs et al, they only reference > external dependencies, they don't include them. While this describes the general use case of RPM, you can most certainly include external dependencies. You do it by not making them external. If you need wxPython included with your app, you can build wxPython as a subtree of your project and package it that way. While wasteful of space, it is also the only sure way to make sure that your app has the correct version and all needed dependencies. This is how py2exe does it on Windows and py2app does it on Mac (they just make it automatic). People find Linux more difficult to distribute binary apps on because they try to follow the typical Linux pattern for distributing packages versus using the one used elsewhere. For binaries this doesn't work very well. Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From jepler at unpythonic.net Sat Aug 6 07:59:52 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sat, 6 Aug 2005 06:59:52 -0500 Subject: How to get ScrollRegion to adjust w/ window-size? In-Reply-To: <1123273803.296673.38540@o13g2000cwo.googlegroups.com> References: <1123273803.296673.38540@o13g2000cwo.googlegroups.com> Message-ID: <20050806115949.GG19009@unpythonic.net> The ScrollRegion of the canvas gives the area that should be "available" for scrolling. If this is larger than the visible area of the canvas, then associated scrollbars will allow scrolling. If this is smaller than the visible area of the canvas, then the scrollbar will fill with the "thumb" and no scrolling is possible. Here is an application that creates a 5000x5000 canvas and allows scrolling. The scrollbars react appropriately when the window is resized. from Tkinter import * t = Tk() c = Canvas(t) hsb = Scrollbar(t, orient="h", command=c.xview) vsb = Scrollbar(t, orient="v", command=c.yview) c.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) c.grid(row=0, column=0, sticky="nsew") hsb.grid(row=1, column=0, stick="ew") vsb.grid(row=0, column=1, sticky="ns") t.grid_rowconfigure(0, weight=1) t.grid_columnconfigure(0, weight=1) c.configure(scrollregion = (0, 0, 5000, 5000)) for x in range(100, 5000, 100): for y in range(100, 5000, 100): c.create_text((x,y), anchor=CENTER, text="%d,%d" % (x,y)) t.mainloop() -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From aisaac0 at verizon.net Wed Aug 10 16:49:23 2005 From: aisaac0 at verizon.net (David Isaac) Date: Wed, 10 Aug 2005 20:49:23 GMT Subject: FTP over SSL (explicit encryption) References: Message-ID: "Eric Nieuwland" wrote in message news:mailman.2951.1123698786.10512.python-list at python.org... > Do you want SFTP or FTP/S? The latter. > I'm having a look at FTP/S right now. That's a little > more complicated, but it seems doable. > If I succeed, I guess I'll donate the stuff as an extension to ftplib. Great! Please post a link as soon as it is usable! Thanks, Alan Isaac From ivanlan at pauahtun.org Mon Aug 8 16:30:45 2005 From: ivanlan at pauahtun.org (Ivan Van Laningham) Date: Mon, 08 Aug 2005 14:30:45 -0600 Subject: OT: World's largest Python caught!:) References: <87EFF7FC7B6D46479AF451B4326EF876361599@newplymth.tegel.co.nz> <200508081138.11238.jstroud@mbi.ucla.edu> Message-ID: <42F7C0F5.A20B73C8@pauahtun.org> Hi All-- James Stroud wrote: > > http://www.afghania.com/News-article-sid-4792-mode-thread.html > > 3rd hit in google with "world's largest python". The first two hits were your > email below to the newsgroups. > This hit says it's not the world's largest: http://www.reptilia.org/NEWS.htm And this one offers a better picture: http://www.clubavalanche.com/forums/index.php?showtopic=2837& Metta, Ivan > James > > On Sunday 07 August 2005 09:15 pm, Ashok Rajasingh wrote: > > Hi > > > > > > > > Can I please get some information on this python? I saw a brief news > > clip last year & am very keen to know more. > > > > > > > > Thanks > > > > Ashok Rajasingh > > > > 21 Cumberland street > > > > New Plymouth > > > > New Zealand > > > > +646 7575698 (home) > > > > 7599592 (work) > > > > > > > > > > ###################################################################### > > Attention: > > The information contained in this message and or attachments is intended > > only for the person or entity to which it is addressed and may contain > > confidential and/or privileged material. Any review, retransmission, > > dissemination or other use of, or taking of any action in reliance upon, > > this information by persons or entities other than the intended recipient > > is prohibited. If you received this in error, please contact the sender and > > delete the material from any system and destroy any copies. Please note > > that the views or opinions expressed in this message may be those of the > > individual and not necessarily those of Tegel Foods Ltd. > > > > This email was scanned and cleared by NetIQ MailMarshal. > > ###################################################################### > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ > -- > http://mail.python.org/mailman/listinfo/python-list -- ---------------------------------------------- Ivan Van Laningham God N Locomotive Works http://www.pauahtun.org/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours From peter at engcorp.com Sat Aug 13 17:12:16 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 13 Aug 2005 17:12:16 -0400 Subject: thread limit in python In-Reply-To: References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> <1123859196.289006.200380@g44g2000cwa.googlegroups.com> Message-ID: Bryan Olson wrote: > Peter Hansen wrote: > > My question was in the context of the OP's situation. What possible use > > for 1000 OS threads could he have? > > Is this a language thing? Surely you realize that "what possible > use could be" carries an insinuation that is not > such a good idea. Obviously. Is it no longer permissible to question someone's approach to doing something? You're questioning my approach to inquiring after the OP's requirements, and clearly you believe there is a better way to do it. Wonderful. You may even be right. It's also off-topic. I'm questioning why the OP thinks he needs more than 1000 threads, and I'm genuinely interested in his answer. Not your answer, unless you have personal knowledge of his actual situation. If it's merely a contrived example, I have no further interest in the thread, as I'm interested in practical matters. If he thinks he has a real need, then I happen to believe there's very likely a better way to do it. And _my_ question happens to be on topic... -Peter From benji at benjiyork.com Tue Aug 16 13:14:41 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 16 Aug 2005 13:14:41 -0400 Subject: [Python-Dev] implementation of copy standard lib In-Reply-To: <8c7f10c605081607305068cad6@mail.gmail.com> References: <1124059680.11612.9.camel@localhost.localdomain> <8c7f10c605081607305068cad6@mail.gmail.com> Message-ID: <43021F01.6020009@benjiyork.com> Simon Brunning wrote: > I think that copy is very rarely used. I don't think I've ever imported it. > > Or is it just me? I rarely use copy, and almost always regret it when I do. -- Benji York From syed_saqib_ali at yahoo.com Fri Aug 5 16:30:03 2005 From: syed_saqib_ali at yahoo.com (syed_saqib_ali at yahoo.com) Date: 5 Aug 2005 13:30:03 -0700 Subject: How to get ScrollRegion to adjust w/ window-size? Message-ID: <1123273803.296673.38540@o13g2000cwo.googlegroups.com> Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the original canvas-size, then the scrollregion adjusts properly. How can I make it such that the Scrollregion fills the entire space avaialable to it. I tried all permutations of setting expand=Tkinter.YES and fill=Tkinter.BOTH in the pack command?? -Saqib ---------------------------------------------------- import Tkinter class testApp2: def _setupCanvas(self): self._canvasFrame = Tkinter.Frame(self._overallFrame, bd=1, relief=Tkinter.SUNKEN) self._canvasFrame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) self._canvas = Tkinter.Canvas(self._canvasFrame, background="white", width=self._canvasWidth, height=self._canvasHeight,) # Scroll Bars vScrollbar = Tkinter.Scrollbar(self._canvasFrame) hScrollbar = Tkinter.Scrollbar(self._canvasFrame) # Scroll Bars vScrollbar = Tkinter.Scrollbar(self._canvasFrame) vScrollbar.pack(side=Tkinter.LEFT, expand=Tkinter.NO, fill=Tkinter.NONE) hScrollbar = Tkinter.Scrollbar(self._canvasFrame) hScrollbar.pack(side=Tkinter.TOP, expand=Tkinter.NO, fill=Tkinter.NONE) # Configure self._parent.rowconfigure(0, weight=1) self._parent.columnconfigure(0, weight=1) # self._scrollX0 = self._scrollY0 = 0 # self._scrollX1 = self._canvasWidth # self._scrollY1 = self._canvasHeight print "self._canvasWidth = %s" % self._canvasWidth print "self._canvasHeight = %s" % self._canvasHeight # print "self._scrollX1 = %s" % self._scrollX1 # print "self._scrollY1 = %s" % self._scrollY1 self._canvas.config( width=self._canvasWidth, height=self._canvasHeight, scrollregion=(0,0, self._canvasWidth, self._canvasHeight), yscrollcommand=vScrollbar.set, xscrollcommand=hScrollbar.set, ) vScrollbar.config(orient=Tkinter.VERTICAL, command=self._canvas.yview) hScrollbar.config(orient=Tkinter.HORIZONTAL, command=self._canvas.xview) self._canvasFrame.pack() self._canvas.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) vScrollbar.pack(side=Tkinter.RIGHT, expand=Tkinter.YES, fill=Tkinter.Y) hScrollbar.pack(side=Tkinter.BOTTOM, expand=Tkinter.YES, fill=Tkinter.X) def __init__(self, parent): self._parent = parent self._overallFrame = Tkinter.Frame(self._parent, bd=1, relief=Tkinter.SUNKEN) self._overallFrame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) self._canvasWidth = 300 self._canvasHeight = 250 self._setupCanvas() self._setCallBacks() def _setCallBacks(self): # Function Bindings self._canvas.bind("", self._b1PressEvt) def _b1PressEvt(self, event): print self._canvas.config('scrollregion') print self._canvas.config('width') print self._canvas.config('height') print "=" * 50 print "\n" root = Tkinter.Tk() app = testApp2(root) root.mainloop() From steve at holdenweb.com Sun Aug 21 18:09:08 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Aug 2005 23:09:08 +0100 Subject: while c = f.read(1) In-Reply-To: <7xd5o7a9dg.fsf@ruckus.brouhaha.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> <3mr0lbF1840unU1@individual.net> <7xd5o7a9dg.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Reinhold Birkenfeld writes: > >>Don't forget >> >>for line in f: >> for c in line: >> # do stuff > > > As mentioned before, that's careless programming, since it can read > the whole file into memory if the file contains no newlines. I agree that there may be circumstances where this naiive approach is sub-optimal. However, calling this careless programming is a bit over the top. Reading files into memory is often the preferred approach nowadays, and on a modern laptop (say) files several megabytes in size will be processed perfectly happily. Efficiency is good, but remember Kernighan and Plauger (elements of Programming Style): First, make it work. Then (if it doesn't work fast enough) make it work faster. Most times the simple solution works for the problem under consideration, and useless optimization work is avoided. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From nospam at nospam.com Sat Aug 20 06:21:06 2005 From: nospam at nospam.com (42) Date: Sat, 20 Aug 2005 10:21:06 GMT Subject: Sandboxes Message-ID: Hi, I'm extremely new to python, and am looking at using it as an embedded script engine in a dotnet project I'm working on. I'm currently playing with the "Python for Net" (http://www.zope.org/Members/Brian/PythonNet) stuff, and it seems to work well. Googling for information on securing Python in a "sandbox" seems indicate that there are some built in features, but they aren't really trustworthy. Is that correct? For my purposes, I really just want to let users run in a sandbox, with access to only the language, manipuate a few published objects in the application (and perhaps give them some string and math libraries if applicable). I was wondering if it would be effective to pre-parse incoming scripts and reject those containing "import"? I'd also have the application inject the (short) list of trusted imports to the script before passing it to the interpreter. In theory I'm hoping this would mean script writers would have access to the stuff they need and no way to add in anything else. Would this sufficient? Are there any drawbacks or giant gaping holes? I'm anticipating that I'd also need to block 'exec' and 'eval' to prevent an import from being obfuscated past the pre-parse. Or is this a hopeless cause? Finally, either way, would anyone recommend a different script engine that might be more suitable for what I'm trying to accomplish that I might not have looked at. I don't need much; it needs to work with C#, and be able to easily interact with 'published' interface. I'd also like to leverage a "popular" language instead of something obscure. I also looked at Javascript, but couldn't find a way to embed an interpreter into a C# app. There's some CodeDom stuff with JScript, but that seemed backwards...overkill; I don't really want to compile temporary assemblies for hundreds of 2 and 3 line scripts... and the VSA stuff has been marked deprecated with no apparent successor... seems like I jumped into this at precisely the wrong time. :) Any thoughts, insights, or comments welcome. Forgive my lack of Python savvy... I've only been playing with it for a few hours now; after bumping into the "python for net" link. -regards, Dave From steven.bethard at gmail.com Fri Aug 19 12:08:53 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 19 Aug 2005 10:08:53 -0600 Subject: stdin -> stdout In-Reply-To: <1124466661.390473.127030@g49g2000cwa.googlegroups.com> References: <1124466661.390473.127030@g49g2000cwa.googlegroups.com> Message-ID: <7bydncm3ev6ImZveRVn-tA@comcast.com> gry at ll.mit.edu wrote: > import sys > for l in sys.stdin: > sys.stdout.write(l) This is fine if you don't need the reads and writes of lines to run in lockstep. File iterators read into a buffer, so you'll probably read 4096 bytes from stdin before you ever write a line to stdout. If that's okay, this is a good solution. OTOH, if you want the reads and writes to run in lockstep, you should probably use this idiom: import sys for line in iter(sys.stdin.readline, ''): sys.stdout.write(line) STeVe P.S. You may also be able to get your version working using the -u (unbuffered) option to Python, but I couldn't. From andy at mkaeurope.com Fri Aug 19 10:22:16 2005 From: andy at mkaeurope.com (Andy W) Date: Fri, 19 Aug 2005 14:22:16 GMT Subject: Adobe COM with Python In-Reply-To: References: Message-ID: I wanting to print the PDF to a printer which is set to print to file, so efectively i end up with a ps file. so 1 pdf becomes 1 ps file Tim Golden wrote: > [Andy W] > > | What i want to do is use, python COM to fireup Adobe and > | print the pdf > | file to a printer. > > If that's all you want to do, have a look at this: > > http://timgolden.me.uk/python/win32_how_do_i/print.html > > Or you could try for a Ghostscript solution. > > (Additionally, I seem to remember that the Acrobat COM object is > really only designed to work in Internet Explorer. That was a version > or so ago -- of both -- so I may be off beam). > > 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 max2 at fisso.casa Tue Aug 23 16:03:57 2005 From: max2 at fisso.casa (max(01)*) Date: Tue, 23 Aug 2005 20:03:57 GMT Subject: pipes like perl In-Reply-To: <1124819825.156716.72400@z14g2000cwz.googlegroups.com> References: <1124819825.156716.72400@z14g2000cwz.googlegroups.com> Message-ID: infidel wrote: > Here's one technique I use to run an external command in a particular > module: > > stdin, stdout, stderr = os.popen3(cmd) > stdin.close() > results = stdout.readlines() > stdout.close() > errors = stderr.readlines() > stderr.close() > if errors: > raise Exception(''.join(errors)) > > Maybe this will get you going in a better direction? > yeah thanks! i translated as: .... import os .... CMD_STDIN, CMD_STDOUT, CMD_STDERR = \ os.popen3("*some_system_command*", "r") if not CMD_STDERR.readlines(): ... *do_something* ... for answer in CMD_STDOUT: print answer, ... *do_something_more* ... else: ... *do_something_else* ... CMD_STDIN.close() CMD_STDOUT.close() CMD_STDERR.close() .... bye max From zen19725 at zen.co.uk Thu Aug 11 06:42:11 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Thu, 11 Aug 2005 11:42:11 +0100 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123697696.506898.66580@z14g2000cwz.googlegroups.com> <1123723974.522483.92740@o13g2000cwo.googlegroups.com> Message-ID: On 10 Aug 2005 18:32:54 -0700, Qopit wrote: > >> if debug: print "v=%s" % (v,) > >Not that important, but I assume the first one was supposed to be: > > if debug: print "v=", s > >right? No, I'm trying to print (v) not (s). -- Email: zen19725 at zen dot co dot uk From bokr at oz.net Mon Aug 29 20:40:23 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 30 Aug 2005 00:40:23 GMT Subject: overload builtin operator References: <3n61u4F1fg2U1@individual.net> <431116ef.2601201920@news.oz.net> <431227bd.7666734@news.oz.net> Message-ID: <4313a8c1.106230711@news.oz.net> On Sun, 28 Aug 2005 23:27:07 -0400, "Terry Reedy" wrote: >I suspect that PyPy, when further alone, will make it easier to do things >like develop a customized interpreter that has alternate definitions for >builtin operators. So maybe the OP should ask again in a year or two. > OTOH, did you notice that I provided (although I didn't post the underlying walker framework) a way (that works now) of importing a module with the / operator effectively converted to a safediv call, as the OP apparently wanted? ;-) BTW, I posted an update that handles non-simple-name-target /= augassigns as well, but though it shows on google groups, I can't see it yet. Still some news server problem, apparently. Or maybe it's just slogging to catch up after previous problem... Regards, Bengt Richter From gnb at itga.com.au Tue Aug 16 03:57:39 2005 From: gnb at itga.com.au (Gregory Bond) Date: Tue, 16 Aug 2005 17:57:39 +1000 Subject: keeping a ref to a non-member function in a class Message-ID: I'm building a class hierarchy that needs to keep as a class variable a reference to a (non-member) function, so that different subclasses can use different generator functions. But it seems Python is treating the function as a member function because the reference to it is in class scope.... Here's a simple case of what I'm trying (in the real code, fn is a function that returns a database connection relevant to that subclass): > def foo(): > print "foo called" > > class S(object): > fn = foo > > def bar(cls): > cls.fn() > bar = classmethod(bar) > > def foo2(): > print "foo2 called" > > class D(S): > fn = foo2 > > D.bar() [I'm on python 2.3.4 so no @classmethod decorator! ] When I run this: > Traceback (most recent call last): > File "t_o.py", line 19, in ? > D.bar() > File "t_o.py", line 10, in bar > cls.fn() > TypeError: unbound method foo2() must be called with D instance as first argument (got nothing instead) This shows it is trying to do what I expect (call foo2()) but somehow the type is all wrong. I've tried playing with staticmethod() but I can't quite get it all worked out... From alessandro.bottoni at infinito.it Sat Aug 13 08:44:40 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Sat, 13 Aug 2005 12:44:40 GMT Subject: Running one Python program from another as a different user References: <1123885309.455560.220670@z14g2000cwz.googlegroups.com> <1123886672.906472.322360@z14g2000cwz.googlegroups.com> Message-ID: Jeff Schwab wrote: > dwelch91 at gmail.com wrote: >> Thanks, that looks very promising... >> Is there a solution for pre-Python v2.4? I have to have code that works >> on 2.x, 0<=x<=4. Do I just use the os.popen instead? > > import os > > def run_as(username): > pipe = os.popen("su %s" % username, 'w') > pipe.write("whoami") > > > if __name__ == "__main__": > import sys > for user in sys.argv[1:]: > run_as(user) Jeff, may I suggest you to write down a new recipe for the ASPN Python Cookbook based on these code snippets? This is exactly the kind of thing the people is happy to find at ASPN. CU ----------------------------------- Alessandro Bottoni From peter at engcorp.com Mon Aug 22 18:19:11 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 18:19:11 -0400 Subject: Best way to 'touch' a file? In-Reply-To: References: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Message-ID: Fredrik Lundh wrote: > Peter Hansen wrote: >>from path import path >>path('myfile').touch() > > import os > os.utime('myfile', None) > > is a bit shorter, of course. And, depending on your needs, quite ineffective: >>> import os >>> os.utime('missing.file', None) Traceback (most recent call last): File "", line 1, in ? OSError: [Errno 2] No such file or directory: 'missing.file' >>> from path import path >>> path('missing.file').touch() >>> path('missing.file').exists() True I guess it depends on whether "touch" implies creation-when-missing, as with the command line version, or just updating the time. -Peter From martin at v.loewis.de Sun Aug 7 16:32:50 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 07 Aug 2005 22:32:50 +0200 Subject: PEP: Specialization Syntax In-Reply-To: References: Message-ID: <42F66FF2.7010901@v.loewis.de> Nicolas Fleury wrote: > Hi everyone, I would to know what do you think of this PEP. Any comment > welcomed (even about English mistakes). -1. I don't see the point of this PEP. Apparently, you want to define parametrized types - but for what purpose? I.e. what are the specific use cases for the proposed syntax, and why do you need to change the language to support these use cases? I very much doubt that there are no acceptable alternatives for each case. IOW, whatever it is that you could do with this PEP, it seems you could do this today easily. Regards, Martin From notanlinesgirly4 at yahoo.com Thu Aug 25 00:29:28 2005 From: notanlinesgirly4 at yahoo.com (Casse) Date: Thu, 25 Aug 2005 04:29:28 -0000 Subject: wanna stop by my homemade glory hole? Message-ID: my husband is installing an extra bathroom poolside. there is a perfect size hole (unless you have a huge cock) to stick your dick through into the adjoing room. come around the side of my house(perfect if you look like a repair man) enter into the unfisnished bathroom and I'll service you from the other side. you can leave when your done, no talking or small talk. i want to do this before the hole gets patched up. its been a huge fantasy of mine ever since I've seen a glory hole online. you can email me for a time convienient for you. im home all-day most days so my schedule is open. do you prefer a certain color of lipstick? check out my pic and email here under suzzette www.no-strings-fun.net/suzzette ready and waiting, me ;o) From mwm at mired.org Thu Aug 18 22:50:18 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 18 Aug 2005 22:50:18 -0400 Subject: creating/modifying sparse files on linux References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> <4303e125.1735463644@news.oz.net> <1124375502.322338.149620@g47g2000cwa.googlegroups.com> Message-ID: <86slx6d4id.fsf@bhuda.mired.org> "draghuram at gmail.com" writes: > My goal is very simple. Have a mechanism to create sparse files and > modify them by writing arbitratry ranges of bytes at arbitrary offsets. > I did get the information I want (xrange instead of range, and a simple > way to generate 1Mb string in memory). Thanks for pointing out about > using "len" as variable. It is indeed silly. > > My only assumption from underlying OS/file system is that if I seek > past end of file and write some data, it doesn't generate blocks for > data in between. This is indeed true on Linux (I tested on ext3). This better be true for anything claiming to be Unix. The results on systems that break this aren't pretty. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From pierre.barbier at cirad.fr Mon Aug 29 09:39:17 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 29 Aug 2005 15:39:17 +0200 Subject: using common lisp with python. In-Reply-To: <1125264907.656465.106900@g44g2000cwa.googlegroups.com> References: <1125264907.656465.106900@g44g2000cwa.googlegroups.com> Message-ID: <43130f30$0$17711$626a14ce@news.free.fr> levicc00123 at gmail.com a ?crit : > is there a way to embed common lisp programs in python? > It depends on what you call "embedding" ... can you be more specifiv about what you want ? From jmtapio at verkkotelakka.net Sat Aug 20 05:44:17 2005 From: jmtapio at verkkotelakka.net (Juha-Matti Tapio) Date: Sat, 20 Aug 2005 09:44:17 +0000 (UTC) Subject: Coin-operated kiosk written in python -- need some help... References: <777056A4A8F1D21180EF0008C7DF75EE03317587@sunbelt.org> Message-ID: Jon Monteleone wrote: > The OS I am using is linux distro fedora core 4 (RH, version 10 I think). The first > question I have is exactly as you mention in 1. I need to have the gui running from > machine bootup to shutdown. I wrote a bash daemon init script to turn my program into a > daemon, but it doesnt seem to work. I used the standard bash daemon init script that > exists in /usr/local/docs as a template. The script doesnt work correctly, so that is my > first problem. But, assuming I get the script spawning my program as a daemon, the > question becomes...will my Tkinter gui show up on the gnome presession screen (login > screen) or do I need to add special code in .xinitrc or some other file to make it > display? > So, currently my specific questions are: > 1) How do I make my gui display at the login screen (we can assume I get the program > spawning as a daemon) Assuming Gnome and GDM as a display manager, you can access the login display by setting the environment variable XAUTHORITY=/var/lib/gdm/:0.Xauth before starting your Tkinter-script. That environment variable specifies the file where the MIT authorization cookie for the X11-session is stored. If Gdm is not used, the file is going to be somewhere else. > 2) How do I get a push of the start button on my gui to login the user to the Internet > account I think there is some kind of support in Gdm to support auto-login, but personally I would suggest not using Gdm at all. You could start X11 separately from your script, then open your Gui on the display, and start gnome-session (with a proper userid) on the same display after the user has paid. (Though you need to be careful with security so that the user can't bypass your system.) You would propably get better advice from some Linux or Gnome -specific forums. From a Python viewpoint you basically just need to know that the python-process running your Gui can access the X authority file specified in the above mentioned environment variable. From clever.developer at gmail.com Mon Aug 29 13:26:15 2005 From: clever.developer at gmail.com (Subir) Date: 29 Aug 2005 10:26:15 -0700 Subject: Exploring outlook contents Message-ID: <1125336375.499390.276520@g44g2000cwa.googlegroups.com> Hi, I am trying to build an application to explore the contents of an outlook .pst files. All the reference that I have seen uses the registry to do so. Does any one know any other way of doing this. Also, is anyone has any code which does something related to this, please let me know. -Subir From flavell at ph.gla.ac.uk Thu Aug 25 14:01:15 2005 From: flavell at ph.gla.ac.uk (Alan J. Flavell) Date: Thu, 25 Aug 2005 19:01:15 +0100 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: On Thu, 25 Aug 2005, Mike Schilling wrote: [Off Topic discussion of netiquette, seen on comp.lang.perl.misc:] > Gosh, if you say they should be, there's no point trying to have an > intelligent discussion, is there? Discussion about netiquette on any of these cross-posted groups cannot by definition be "intelligent": there are proper places to discuss the netiquette (they'd have "news" as their top hierarchy, not "comp"), and your posting was cross-posted to none of them. [f'ups set] [I have been trolled, mea culpa] From dejan.wirusrodiger at ck.t-com.hr Tue Aug 9 17:30:34 2005 From: dejan.wirusrodiger at ck.t-com.hr (Dejan Rodiger) Date: Tue, 09 Aug 2005 23:30:34 +0200 Subject: Does any one recognize this binary data storage format In-Reply-To: References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <1123620352.605259.228860@o13g2000cwo.googlegroups.com> Message-ID: Dejan Rodiger said the following on 9.08.2005 23:28: > geskerrett at hotmail.com said the following on 9.08.2005 22:45: > >>Yes I double checked as I appreciate any help, but that is what is >>stored on disk. >> >>If it helps, we modified Ex#3. to be 777-777-7777 >>On disk this is now 00 00 10 87 77 F9 Fc 41 >> >>All the input fields are filled in this new example. >> > > > So for number with 10 digit numbers you could say that it is: > 7777777777(10)=1CF977871(16) > 1CF977871 SHL 4 bits = 1C F9 77 87 10 > write them from right to left and shift left for 8 bits > 10 87 77 f9 1C 00 > And then add F0 41 And add E041 (not F0 41) -- Dejan Rodiger - PGP ID 0xAC8722DC Delete wirus from e-mail address From n00m at narod.ru Wed Aug 31 04:51:56 2005 From: n00m at narod.ru (n00m) Date: 31 Aug 2005 01:51:56 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125425945.667967.181000@g49g2000cwa.googlegroups.com> Message-ID: <1125478316.530781.315540@g44g2000cwa.googlegroups.com> Richie Hindle wrote: > Because you have a socket.py in d:\python23\00 which is being picked up > instead of Python's own socket module. You shouldn't give your modules > the same name as Python's own modules. Yes, Richie! YOU are dmndly RIGHT! Thanks. From steve at holdenweb.com Tue Aug 30 13:30:36 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Aug 2005 12:30:36 -0500 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: Antoon Pardon wrote: > Op 2005-08-29, Steve Holden schreef : > >>Antoon Pardon wrote: >> >>>Op 2005-08-27, Steve Holden schreef : >>> >>> >>>>If you want an exception from your code when 'w' isn't in the string you >>>>should consider using index() rather than find. >>> >>> >>>Sometimes it is convenient to have the exception thrown at a later >>>time. >>> >>> >>> >>>>Otherwise, whatever find() returns you will have to have an "if" in >>>>there to handle the not-found case. >>> >>> >>>And maybe the more convenient place for this "if" is in a whole different >>>part of your program, a part where using -1 as an invalid index isn't >>>at all obvious. >>> >>> >>> >>>>This just sounds like whining to me. If you want to catch errors, use a >>>>function that will raise an exception rather than relying on the >>>>invalidity of the result. >>> >>> >>>You always seem to look at such things in a very narrow scope. You never >>>seem to consider that various parts of a program have to work together. >>> >> >>Or perhaps it's just that I try not to mix parts inappropriately. > > > I didn't know it was inappropriately to mix certain parts. Can you > give a list of modules in the standard list I shouldn't mix. > > >>>So what happens if you have a module that is collecting string-index >>>pair, colleted from various other parts. In one part you >>>want to select the last letter, so you pythonically choose -1 as >>>index. In an other part you get a result of find and are happy >>>with -1 as an indictation for an invalid index. Then these >>>data meet. >>> >> >>That's when debugging has to start. Mixing data of such types is >>somewhat inadvisable, don't you agree? > > > The type of both data is the same, it is a string-index pair in > both cases. The problem is that a module from the standard lib > uses a certain value to indicate an illegal index, that has > a very legal value in python in general. > Since you are clearly feeling pedantic enough to beat this one to death with a 2 x 4 please let me substitute "usages" for "types". In the case of a find() result -1 *isn't* a string index, it's a failure flag. Which is precisely why it should be filtered out of any set of indexes. once it's been inserted it can no longer be distinguished as a failure indication. > >>I suppose I can't deny that people do things like that, myself included, > > > It is not about what people do. If this was about someone implementing > find himself and using -1 as an illegal index, I would certainly agree > that it was inadvisable to do so. Yet when this is what python with > its libary offers the programmer, you seem reluctant find fault with > it. > I've already admitted that the choice of -1 as a return value wasn't smart. However you appear to be saying that it's sensible to mix return values from find() with general-case index values. I'm saying that you should do so only with caution. The fact that the naiive user will often not have the wisdom to apply such caution is what makes a change desirable. > >>but mixing data sets where -1 is variously an error flag and a valid >>index is only going to lead to trouble when the combined data is used. > > > Yet this is what python does. Using -1 variously as an error flag and > a valid index and when people complain about that, you say it sounds like > whining. > What I am trying to say is that this doesn't make sense: if you want to combine find() results with general-case indexes (i.e. both positive and negative index values) it behooves you to strip out the -1's before you do so. Any other behaviour is asking for trouble. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mohammed at aims.ac.za Wed Aug 17 08:07:33 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Wed, 17 Aug 2005 14:07:33 +0200 Subject: Lists of list Message-ID: <43032885.7050908@aims.ac.za> Hi All I am having problem with delete line if its belong to another one , example ['0132442\n', '13\n', '24\n'] the 2nd and 3rd are already in the first line , how can do this !!! Thanks From 12 at 12.com Wed Aug 24 15:32:56 2005 From: 12 at 12.com (Make12) Date: Wed, 24 Aug 2005 19:32:56 GMT Subject: Earn 12% daily of your investment!!! Message-ID: I'm going to tell you about a TOP RATED AUTOSURF program that takes 5 mins of your day and then instantly credits your account 12% of what you put in. Its that easy and everyone is going crazy about it. I have personally done this and been paid. This is how it works. You have to have/get your free Stormpay or E-gold account and then you put in a multiple of 6. So the minimum is $6 and maximum is $6000. Everyday you login and click the autosurf button and it will have a timer and switch pages for you. After 12 pages you will be credited INSTANTLY your 12%. Start small and keep rolling it in, or go big and make some cash. They have NOT FAILED yet to pay. After 12 days of surfing your account expires and they process the money you have made. It goes to your Stormpay or E-gold account which ever you used in 1-7 business days... THATS IT!! Examples Start Small. with just $6 dollars. 12% is .72 cents. Everyday for 12 days = 8.64 cents. Thats 2.64 PROFIT!!!. Go big $6000. 12% is 720.00. for 12 days.. thats 8640 = 2640 PROFIT!!!... Or go in between any multiple of 6. Thank you for looking at this all I ask is thta you use my referral link. This is not a pyramid so I don't get anything from anyone you refer. Thats how this program stays alive. They don't give you money to sign up. Its FREE to sign up, but if you don't put any money within 7 days then your account is deleted. Thanks here is the link. If you like it please refer your friends with YOUR referall link. Remeber I don't get anything from anybody you refer. If you don't believe me then just email their 24 hour techsupport, or their techsupport Forum where the people who pay you are the ones who answer you. Its AWESOME.. some may already be members. Just ask them. http://www.12dailypro.com/?ref=11295 From fredrik at pythonware.com Fri Aug 26 04:28:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 26 Aug 2005 10:28:07 +0200 Subject: file access dialog References: <430ec9b1.1708219820@news.xs4all.nl> Message-ID: Wouter van Ooijen wrote: >I have a tool in Python to which I want to add a small GUI. The tools > currently runs everywhere PySerial is supported. I need a file-access > dialog. What is the preffered way to to this? Is there a > platform-independent file-access dialog available, or should I use the > windows native version when running on windows (and how do I do that)? depends on what GUI toolkit you prefer to use. for Tkinter (which is available on most modern platforms), see "File Dialogs" on this page: http://www.pythonware.com/library/tkinter/introduction/x1164-data-entry.htm the following thread may also be helpful: http://tinyurl.com/b2zxb From googlenews at tooper.org Wed Aug 24 06:34:36 2005 From: googlenews at tooper.org (tooper) Date: 24 Aug 2005 03:34:36 -0700 Subject: Inheritance problem ? Message-ID: <1124879676.525583.14390@g44g2000cwa.googlegroups.com> Hello all, I'm trying to implement a common behavior for some object that can be read from a DB or (when out of network) from an XML extract of this DB. I've then wrote 2 classes, one reading from XML & the other from the DB, both inheritating from a common one where I want to implement several common methods. Doing this, I've come to some behaviour I can't explain to myself, which I've reproduced in the example bellow : ----- class myfather: def __repr__(self): return "\t a="+self.a+"\n\t b="+self.b class mychilda(myfather): def __init__(self,a): self.a= a def __getattr__(self,name): return "Undefined for mychilda" class mychildb(myfather): def __init__(self,b): self.b= b def __getattr__(self,name): return "Undefined for mychildb" a= mychilda("a") b= mychildb("b") print "a:\n"+str(a) print "b:\n"+str(b) ----- I was expecting to get : a: a= a b= Undefined for mychilda b: a= Undefined for mychildb b= b but I get the following error : File "/home/thierry/mytest.py", line 20, in ? print "a:\n"+str(a) TypeError: 'str' object is not callable Could someone explain me what I missed ? Thanks in advance ! From mohammed at aims.ac.za Tue Aug 23 13:20:15 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Tue, 23 Aug 2005 19:20:15 +0200 Subject: how to deal with space between numbers In-Reply-To: References: Message-ID: <430B5ACF.6070509@aims.ac.za> Dear All This is my problem again , I tried to sort it out , but i couldn't , I am reading data from file using readlines , my input like : 0 1 2 4 1 2 4 2 3 3 4 What i am doing is , starting with the first element in the first line ( which is 0 in this case )and do search in the other lines , if i found another 0 , i will save (print out) all the elements except 0 , (in this is case i have no 0 elsewhere) so i will print only 0. Now do search by the 2nd element in the first line (which is 1 in this case) , in the 2nd line we have 1 , so i should save(print out) all elements except 1 which are 2 4 , and so on for the rest of the first line , and for the rest of the file , my out put should be 0 1 2 4 2 1 4 3 4 1 2 3 1 2 3 4 3 2 3 4 3 4 I managed to do all these things , but i did it in the way that i am reading my data as strings ( no space between numbers) something like 0124 124 23 34 what i would like to know or to do is , how can i deal with my data after reading it as strings(i need the space between numbers) because i had problem when dealing with number larger than 9 , example : 0 1 5 9 1 12 10 4 6 7 10 9 so , when i remove the space between numbers , i loose all my data , i mean it will look like 0159 11210 467 509 This is my code : def belong_to(x,a): c=-1 for i in range(len(a)-1): if x==int(a[i]): c=i return c def list_belong(x,a): # This function to check if this line c=-1 # line has been searched before or not for i in range(len(a)): if a[i]==x: c=1 break return c x=0 occur=[] in_file=open('data.dat','r') out_file=open('result.dat','w') fileList = in_file.readlines() for k in fileList: v=k occur.append(k) n=len(v)-1 for i in range(n): temp=int(v[i]) print temp, out_file.write(str(temp)) for line in fileList: if v!=line: if list_belong(line,occur)!=1: if belong_to(temp,line) != -1: j=belong_to(temp,line) for i in range(len(line)-1): if i!=j: print line[i], out_file.write(line[i]) print out_file.write("\n") out_file.close() in_file.close() Thank you all From sp1d3rx at gmail.com Fri Aug 12 18:03:00 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 12 Aug 2005 15:03:00 -0700 Subject: pickle.load not working? Message-ID: <1123884180.348659.247960@z14g2000cwz.googlegroups.com> I have the following code for controlling access: ---------------------- #check login credentials... def cklogin(ipaddy, user, authcoded): try: print "Opening file:", user f = file(user,'r+') #load in the user from the file cusr = pickle.load(f) print "User Authcode:", cusr.authcode print "Supplied:", authcoded print "Login:", cusr.login if cusr.authcode == authcoded: print "User", user, "successfully logged in." cusr.loggedin=TRUE cusr.invalid_logins = 0 cusr.ip = ipaddy pickle.dump(cusr, f) # save the new status... del cusr f.close() return mkcookie(ipaddy) else: print "Invalid login attempt." del cusr f.close() except IOError: print "User does not exist!" return FALSE ---------------------- it reads a file saved this way: ---------------------- import pickle class chatuser: #container for storing user information... login = "" authcode = "" cookie = "" ip = "" loggedin = 0 invalid_logins = 0 allow_login = 1 status = "" realname = "" phone = "" email = "" derek = chatuser derek.login = "username" derek.authcode = "password" derek.cookie = "123456" derek.ip = "127.0.0.1" derek.loggedin = 0 derek.invalid_logins = 0 derek.allow_login = 1 derek.status = "here" derek.realname = "Derek W." derek.phone = "480-XXX-XXXX" derek.email = "XXX.YYY at BBB.com" f = file(derek.login, 'w') pickle.dump(derek, f) f.close() ---------------------- When I try to read it via the interpreter, it works like this... ---------------------- >>> import pickle >>> f = file("spiderx", 'r') >>> c = pickle.load(f) >>> c >>> c.login 'username' >>> c.authcode 'password' ---------------------- With the code above, the login and authcode fields are blank... so, I don't understand why it doesn't work. Is there anything wrong with my code? From jgrahn-nntq at algonet.se Sun Aug 7 04:36:38 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 7 Aug 2005 08:36:38 GMT Subject: Sample code to build rfc822 mail message building References: Message-ID: On Sat, 6 Aug 2005 08:45:30 +0100 (BST), praba kar wrote: > Dear All, > > I am new to python world. I have pasted my code > which I used it to build rfc822 format mails for ... > Still What way I can improve this code. If anyone find > error kindly let me know how to correct it. ... > #This function base I try to build email message > def create_mail(domain, user, form, from_name): > to = cc = bcc = subject = body = '' > attachments = [] Document methods with proper grammar, as doc strings, and use more direct wording: def create_mail(domain, user, form, from_name): """Build and return an RFC 2822 message with (something about what the parameters do) and an empty body. (More details.) """ to = cc = bcc = subject = body = '' attachments = [] If you feed your code to the 'pydoc' utility, the output should be readable. Somewhere you also might need to describe what subset of RFC 2822 and MIME you implement, or what your "mail metaphor" is. Different people think differently about mails. I, for example, don't know what you mean by "attachment" -- the MIME RFCs use much richer concepts. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Aug 16 02:49:50 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 16 Aug 2005 06:49:50 +0000 (UTC) Subject: get a list of mounted filesystems under MacOSX References: <4300bd95$0$11586$636a15ce@news.free.fr> Message-ID: rafi wrote: > garabik-news-2005-05 at kassiopeia.juls.savba.sk wrote: >> Hi all, >> I am trying to port my (linux) program to MacOSX, and I need to get a >> list of mounted filesystems. Under linux, it was easy, I was parsing >> /etc/mtab (or /proc/mounts), this works also on some other unices. >> But I have no idea how to do it on MacOSX, apart from calling "mount" as >> an external program and parsing the output - but I prefer "cleaner" >> solutions. Is there one? > > why not looking at the content of the /Volumes folder? because the filesystem could be mounted elsewhere (in fact, the Mac Mini I have across the table has a big network storage nfs-mounted on /data) -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From oh_no_you_don't at noSPAM.com Sun Aug 21 03:09:55 2005 From: oh_no_you_don't at noSPAM.com (m7b52000) Date: Sun, 21 Aug 2005 16:39:55 +0930 Subject: passing arguments from scale widget to function Message-ID: <430828c4$1@duster.adelaide.on.net> Some time ago I wrote a little program in Tcl/Tk that took the values from 3 sliders and performed a calculation using these values. The calculation was of course automatically repeated each time a slider was moved. It is proving most difficult in Python. How do I pass the .get() values to my calculating function? Do I use the command option for each slider? e.g command = Calc(a.get()). Obviously not cos it doesn't work. I am not a real programmer and do not wish to get involved in classes and objects.... From spammers-go-here at spam.invalid Thu Aug 11 13:36:49 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Thu, 11 Aug 2005 13:36:49 -0400 Subject: Supressing argument renaming in the Qt Designer -> pyuic workflow Message-ID: <42fb8ca3$0$18647$14726298@news.sunsite.dk> Hi Some of the functions I defined inside Qt Designer need to have some values passed to them. For instance : Code : void Form3::runningplot(n,plottitle,xname,x,y1name,y1,y2name,y2) is translated by pyuic to Python code : def runningplot(self,a0,a1,a2,a3,a4,a5,a6,a7): Now, while I understand that the first argument of the function has to be "self", the change in the names of the parameters in the function definition (and no corresponding change in the function body - which I would not expect anyways) messes up everything. Is there a way to tell pyuic to not translate plottitle -> a0, xname -> a1, etc., but keep the names as they are ? Thanks. From jonhewer at gmail.com Fri Aug 19 07:46:01 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Fri, 19 Aug 2005 12:46:01 +0100 Subject: Python for Webscripting (like PHP) In-Reply-To: <1124449823.428290.206950@g47g2000cwa.googlegroups.com> References: <1124449823.428290.206950@g47g2000cwa.googlegroups.com> Message-ID: I like the look of cheeryPy - snyone know if its easy to get it running on top of Apache? Thanks On 19 Aug 2005 04:10:23 -0700, paron wrote: > Yes the stdlib offers all the basic functions, but why work so hard? > Get CherryPy (http://www.cherrypy.org) and relax a bit. You'll be able > to concentrate on Python for the backend, HTML for the frontend, > without a lot of directory-diddling. > > Also, check out > http://www-128.ibm.com/developerworks/opensource/library/os-cherrypy/index.html#main > for a nice, fresh slice. > > Ron > > -- > http://mail.python.org/mailman/listinfo/python-list > From rich.teer at rite-group.com Sat Aug 27 14:55:12 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Sat, 27 Aug 2005 18:55:12 GMT Subject: Writing portable applications (Was: Jargons of Info Tech industry) In-Reply-To: <86acj3ut2e.fsf_-_@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> Message-ID: On Sat, 27 Aug 2005, Mike Meyer wrote: > I think you're right - a web standard designed for writing real > applications probably wouldn't start life as a markup for text. The > only thing I can think of that even tries is Flash, but it's What about Java? -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From renting at astron.nl Mon Aug 8 09:59:45 2005 From: renting at astron.nl (Adriaan Renting) Date: Mon, 08 Aug 2005 15:59:45 +0200 Subject: Embedding a runtime graph in Qt3 designer generated UI Message-ID: I find Eric3 very easy to work with when using Qt+Python. It will generate a Python wrapper for your Qt (Designer designed) form, that you can the sub-class and use as if it was a Python object. I'm hoping it will be available (together with PyQt, etc.) for Qt4 soon, but as I'm not paying a dime for it, I can only hope... Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ >>> "Phil Thompson" 08/08/05 9:21 AM >>> > Hi > > Two questions : > > 1. Is it possible to use an import command in a qt3 designer code ? (I > know > that it is possible to write python inside the braces -- but is it > possible > to use an import command for some rather large libraries I wrote that I > need to access ?). You can include import statements in Designer's comment dialog by prefixing them with "Python: ". This is covered in the PyQt documentation. > 2. In the same vein, how does one embed a runtime plot in a qt3 UI ? It > will > need to be a python solution since I am using python libraries to acquire > the data. Have a look at PyQwt which is a set of Python bindings for the Qt-based Qwt plotting library. Phil -- http://mail.python.org/mailman/listinfo/python-list From phleum_nospam at chello.se Thu Aug 18 15:06:44 2005 From: phleum_nospam at chello.se (Carl) Date: Thu, 18 Aug 2005 21:06:44 +0200 Subject: Bitwise operations in Python? References: <7x8xyz884o.fsf@ruckus.brouhaha.com> Message-ID: Incredible, Paul! Thanks a thousand times! /Carl From u.hobelmann at web.de Tue Aug 23 18:05:22 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Wed, 24 Aug 2005 00:05:22 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <8764twuyv9.fsf@hardknott.home.whinlatter.ukfsn.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <3mv4c2F18so93U1@individual.net> <8764twuyv9.fsf@hardknott.home.whinlatter.ukfsn.org> Message-ID: <3n1kt2F190kt9U1@individual.net> Roger Leigh wrote: >> At least he noticed that tar sucks. There's nothing better than tarring >> your backup back to disk, only to notice that the pathnames were "too >> long." Great! > > That's been fixed for quite some time, though. The current GNU tar > (1.15.1) writes POSIX.1-2001 (PAX) archives, and has read them for > quite a long time before. Don't remember where it bit me. Either Free- or NetBSD, or Mac OS 10.3, but it was sometime after 2002... probably not GNU tar, though. -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From uomart at ihug.co.nz Mon Aug 15 18:23:48 2005 From: uomart at ihug.co.nz (Mulac) Date: Tue, 16 Aug 2005 10:23:48 +1200 Subject: Is Tkinter compatible with GNOME? Message-ID: <001001c5a1e8$03b44e80$5700a8c0@rmse> Is Tkinter also compatible wih GNOME? I wrote a program in python that displays 2 buttons for starting and stopping the execution of a program. I used Tkinter for the gui. I want the program to run as a daemon when linux is booted. I want the buttons to be displayed at the presession login screen. I am using Fedora core 4 with GNOME I cannot seem to get the buttons to display at the presession screen. I figure it is either that the init script I wrote to make the python program a daemon isnt working right OR Tkinter cant do the job. Any thoughts? From googlenews at tooper.org Wed Aug 24 09:21:09 2005 From: googlenews at tooper.org (tooper) Date: 24 Aug 2005 06:21:09 -0700 Subject: Inheritance problem ? In-Reply-To: References: <1124879676.525583.14390@g44g2000cwa.googlegroups.com> Message-ID: <1124889669.502937.109310@g14g2000cwa.googlegroups.com> Not always easy to follow but great ! Using __str__ instead of __repr__ makes it work also with old style (thanks to Simon Brunning for suggesting it, and with your link I even now understand why !) From fredrik at pythonware.com Tue Aug 30 18:33:53 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 00:33:53 +0200 Subject: Problem with string -> int conversion ? References: <4314dbd0$0$18648$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > I am working with an application that I designed with the Designer > pyuic > workflow and I get the following error on trying to process the contents > of > a combobox : > > Traceback (most recent call last): > File "measure.py", line 908, in acquiredata > np=self.getNPrange() > File "measure.py", line 1167, in getNPrange > signalrange=int(signalrangestr) > TypeError: int() argument must be a string or a number > > The code is : > > void Form3::getNPrange() > { what language is this? > signalrangestr=self.NPcombobox.currentText() > signalrange=int(signalrangestr) > if globaldebug : print 'NP Signal range = ',signalrange > return signalrange > } > Isn't signalrangestr above a string ? Or at the very least, a number. if the callback code is Python, you should be able to add a print statement to the line just before the failing "int" call: print repr(signalrangestr), type(signalrangestr) signalrange = int(signalrangestr) that print statement should be all you need to figure out what signalrangestr really is. From petr at tpc.cz Tue Aug 30 08:13:17 2005 From: petr at tpc.cz (McBooCzech) Date: 30 Aug 2005 05:13:17 -0700 Subject: micro-python - is it possible? In-Reply-To: <431440bb$1@news.orcon.net.nz> References: <431440bb$1@news.orcon.net.nz> Message-ID: <1125403997.225481.152690@z14g2000cwz.googlegroups.com> Check Lua programing language. Maybe this can fit your requirements. HTH Petr Jakes From martin at v.loewis.de Thu Aug 25 05:00:26 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 25 Aug 2005 11:00:26 +0200 Subject: How to start PEP process? In-Reply-To: References: Message-ID: <430d88aa$0$13034$9b622d9e@news.freenet.de> Kenneth McDonald wrote: > Should I just put a "Proposed PEP" message here? Or is there a more > formal way? See PEP 1. Regards, Martin From could.net at gmail.com Sun Aug 14 11:26:09 2005 From: could.net at gmail.com (could ildg) Date: Sun, 14 Aug 2005 23:26:09 +0800 Subject: How can I exclude a word by using re? In-Reply-To: <1124031736.367193.219920@g44g2000cwa.googlegroups.com> References: <1124031736.367193.219920@g44g2000cwa.googlegroups.com> Message-ID: <311b5ce1050814082694024c4@mail.gmail.com> Thank you. But what should I do if there are more than one hello and I only want to extract what's before the first "hello". For example, the raw string is "hi, how are you? hello I'm fine, thank you hello. that's it hello", I want to extract all the stuff before the first hello? On 14 Aug 2005 08:02:16 -0700, Christoph Rackwitz wrote: > re.findall('(.*)hello|(.*)', 'hi, how are you. hello') > re.findall('(.*)hello|(.*)', 'hi, how are you. ello') > take a look at the outputs of these. > > -- > http://mail.python.org/mailman/listinfo/python-list > From cito at online.de Fri Aug 5 15:57:51 2005 From: cito at online.de (Christoph Zwerschke) Date: Fri, 05 Aug 2005 21:57:51 +0200 Subject: Art of Unit Testing In-Reply-To: References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> <1123118470.749836.279610@g14g2000cwa.googlegroups.com> Message-ID: I had tested the above only with Python 2.4 but I just noticed it does not work with Python 2.3. The following works also with Python 2.3: import unittest class MyTestCase(unittest.TestCase): def setUp(self): print "setUp", def tearDown(self): print "tearDown", def test1(self): print "test1" def test2(self): print "test2" class MyTestSuite(unittest.TestSuite): def setUp(self): print "setUpAll", def tearDown(self): print "tearDownAll", def __call__(self, result): self.setUp() unittest.TestSuite.__call__(self, result) self.tearDown() if __name__ == '__main__': suite = unittest.makeSuite(MyTestCase, suiteClass=MyTestSuite) unittest.TextTestRunner().run(suite) From peter at engcorp.com Mon Aug 15 07:57:48 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 15 Aug 2005 07:57:48 -0400 Subject: sniffer in python In-Reply-To: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> References: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> Message-ID: <0KmdncVnD80_Hp3eRVn-rw@powergate.ca> billiejoex wrote: > For python exist a porting called pcapy: > http://oss.coresecurity.com/projects/pcapy.html > ...that I'd like to use BUT... all the examples reported on the sites don't > works!! It usually helps to describe *in what way* things don't work. Do they crash? If so, provide the full traceback. Do they not install? If so, provide error messages. Do they appear to run but without visible signs of activity? If so, say so... and describe exactly what options you were using, what platform and version of platform, Python, and library you are using, and any other conditions relevant to the situation. Help us help you... (Alternative suggestion: use whatever mailing list is provided for that specific project, if there is one, so you get access to more people with direct knowledge of what might go wrong.) -Peter From mauriceling at acm.org Sun Aug 14 20:29:40 2005 From: mauriceling at acm.org (Maurice LING) Date: Mon, 15 Aug 2005 10:29:40 +1000 Subject: Standalone applications ? References: <42feba84$0$18644$14726298@news.sunsite.dk> <42feca21$0$18650$14726298@news.sunsite.dk> <42ff1813$0$16029$9b622d9e@news.freenet.de> Message-ID: henne wrote: > > I should have added that my platform is Linux. > > http://davidf.sjsoft.com/mirrors/mcmillan-inc/install1.html > > Squeeze works on Linux too. It tells me that the installer files are not found. M From sjmachin at lexicon.net Tue Aug 23 18:39:12 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Aug 2005 08:39:12 +1000 Subject: while c = f.read(1) In-Reply-To: <1124705414.704694.241960@f14g2000cwb.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> <1124705414.704694.241960@f14g2000cwb.googlegroups.com> Message-ID: <430ba590@news.eftel.com> Greg McIntyre wrote: > John Machin wrote: > >>How about >> for c in f.read(): >>? >>Note that this reads the whole file into memory (changing \r\n to \n on >>Windows) ... performance-wise for large files you've spent some memory >>but clawed back the rather large CPU time spent doing f.read(1) once per >>character. The "more nicely" factor improves outasight, IMHO. > > > I would if only I had any kind of guarrantee on the file size but I > don't - this code is for reading a header out of a binary file which > uses delimiters and escape characters to mark out its fields. I didn't > design the format, but after cleaning up the code that deals with it, I > may *re*design it. ;) > > > >>Mild curiosity: what are you doing processing one character at a time >>that can't be done with a built-in function, a standard module, or a >>3rd-party module? > > > Our company is designing a new file type. *sigh*. Sigh indeed. If you need to read it a character at a time to parse it, the design is f***ed. > Confidentiality > prevents me from saying any more, too. If that bugs you because it's > not open source, sorry I need a job. Don't be so sensitive; it has strong Biblical precedent. You can believe in the one true god but still bow down in the house of Rimmon or Redmond. From paragate at gmx.net Tue Aug 23 04:05:28 2005 From: paragate at gmx.net (wolf) Date: 23 Aug 2005 01:05:28 -0700 Subject: Revised PEP 349: Allow str() to return unicode strings References: Message-ID: <1124784328.771887.98930@g43g2000cwa.googlegroups.com> neil, i just intended to worry that returning a unicode object from ``str()`` would break assumptions about the way that 'type definers' like ``str()``, ``int()``, ``float()`` and so on work, but i quickly realized that e.g. ``int()`` does return a long where appropriate! since the principle works there one may surmise it will also work for ``str()`` in the long run. one point i don't seem to understand right now is why it says in the function definition:: if type(s) is str or type(s) is unicode: ... instead of using ``isinstance()``. Testing for ``type()`` means that instances of derived classes (that may or may not change nothing or almost nothing to the underlying class) when passed to a function that uses ``str()`` will behave in a different way! isn't it more realistic and commonplace to assume that derivatives of a class do fulfill the requirements of the underlying class? -- which may turn out to be wrong! but still... the code as it stands means i have to remember that *in this special case only* (when deriving from ``unicode``), i have to add a ``__str__()`` method myself that simply returns ``self``. then of course, one could change ``unicode.__str__()`` to return ``self``, itself, which should work. but then, why so complicated? i suggest to change said line to:: if isinstance( s, ( str, unicode ) ): ... any objections? _wolf From devlai at gmail.com Mon Aug 29 22:31:17 2005 From: devlai at gmail.com (Devan L) Date: 29 Aug 2005 19:31:17 -0700 Subject: aproximate a number References: Message-ID: <1125369077.295227.8540@g14g2000cwa.googlegroups.com> Thomas Bartkus wrote: > On Sun, 28 Aug 2005 23:11:09 +0200, billiejoex wrote: > > > Hi all. I'd need to aproximate a given float number into the next (int) > > bigger one. Because of my bad english I try to explain it with some example: > > > > 5.7 --> 6 > > 52.987 --> 53 > > 3.34 --> 4 > > 2.1 --> 3 > > > > The standard way to do this is thus: > > def RoundToInt(x): > """ Round the float x to the nearest integer """ > return int(round(x+0.5)) > > x = 5.7 > print x, '-->', RoundToInt(x) > x = 52.987 > print x, '-->', RoundToInt(x) > x = 3.34 > print x, '-->', RoundToInt(x) > x = 2.1 > print x, '-->', RoundToInt(x) > > 5.7 --> 6 > 52.987 --> 53 > 3.34 --> 4 > 2.1 --> 3 RoundToInt(2.0) will give you 3. From fakeaddress at nowhere.org Tue Aug 30 04:53:27 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 30 Aug 2005 08:53:27 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> Message-ID: Terry Reedy wrote: > "Paul Rubin" wrote: > >>Really it's x[-1]'s behavior that should go, not find/rfind. > > I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely > useful, especially when 'x' is an expression instead of a name. Hear us out; your disagreement might not be so complete as you think. From-the-far-end indexing is too useful a feature to trash. If you look back several posts, you'll see that the suggestion here is that the index expression should explicitly call for it, rather than treat negative integers as a special case. I wrote up and sent off my proposal, and once the PEP-Editors respond, I'll be pitching it on the python-dev list. Below is the version I sent (not yet a listed PEP). -- --Bryan PEP: -1 Title: Improved from-the-end indexing and slicing Version: $Revision: 1.00 $ Last-Modified: $Date: 2005/08/26 00:00:00 $ Author: Bryan G. Olson Status: Draft Type: Standards Track Content-Type: text/plain Created: 26 Aug 2005 Post-History: Abstract To index or slice a sequence from the far end, we propose using a symbol, '$', to stand for the length, instead of Python's current special-case interpretation of negative subscripts. Where Python currently uses: sequence[-i] We propose: sequence[$ - i] Python's treatment of negative indexes as offsets from the high end of a sequence causes minor obvious problems and major subtle ones. This PEP proposes a consistent meaning for indexes, yet still supports from-the-far-end indexing. Use of new syntax avoids breaking existing code. Specification We propose a new style of slicing and indexing for Python sequences. Instead of: sequence[start : stop : step] new-style slicing uses the syntax: sequence[start ; stop ; step] It works like current slicing, except that negative start or stop values do not trigger from-the-high-end interpretation. Omissions and 'None' work the same as in old-style slicing. Within the square-brackets, the '$' symbol stands for the length of the sequence. One can index from the high end by subtracting the index from '$'. Instead of: seq[3 : -4] we write: seq[3 ; $ - 4] When square-brackets appear within other square-brackets, the inner-most bracket-pair determines which sequence '$' describes. The length of the next-outer sequence is denoted by '$1', and the next-out after than by '$2', and so on. The symbol '$0' behaves identically to '$'. Resolution of $x is syntactic; a callable object invoked within square brackets cannot use the symbol to examine the context of the call. The '$' notation also works in simple (non-slice) indexing. Instead of: seq[-2] we write: seq[$ - 2] If we did not care about backward compatibility, new-style slicing would define seq[-2] to be out-of-bounds. Of course we do care about backward compatibility, and rejecting negative indexes would break way too much code. For now, simple indexing with a negative subscript (and no '$') must continue to index from the high end, as a deprecated feature. The presence of '$' always indicates new-style indexing, so a programmer who needs a negative index to trigger a range error can write: seq[($ - $) + index] Motivation From-the-far-end indexing is such a useful feature that we cannot reasonably propose its removal; nevertheless Python's current method, which is to treat a range of negative indexes as special cases, is warty. The wart bites novice or imperfect Pythoners by not raising an exceptions when they need to know about a bug. For example, the following code prints 'y' with no sign of error: s = 'buggy' print s[s.find('w')] The wart becomes an even bigger problem with more sophisticated use of Python sequences. What is the 'stop' value for a slice when the step is negative and the slice includes the zero index? An instance of Python's slice type will report that the stop value is -1, but if we use this stop value to slice, it gets misinterpreted as the last index in the sequence. Here's an example: class BuggerAll: def __init__(self, somelist): self.sequence = somelist[:] def __getitem__(self, key): if isinstance(key, slice): start, stop, step = key.indices(len(self.sequence)) # print 'Slice says start, stop, step are:', start, stop, step return self.sequence[start : stop : step] print range(10) [None : None : -2] print BuggerAll(range(10))[None : None : -2] The above prints: [9, 7, 5, 3, 1] [] Un-commenting the print statement in __getitem__ shows: Slice says start, stop, step are: 9 -1 -2 The slice object seems to think that -1 is a valid exclusive bound, but when using it to actually slice, Python interprets the negative number as an offset from the high end of the sequence. Steven Bethard offered the simpler example: py> range(10)[slice(None, None, -2)] [9, 7, 5, 3, 1] py> slice(None, None, -2).indices(10) (9, -1, -2) py> range(10)[9:-1:-2] [] The double-meaning of -1, as both an exclusive stopping bound and an alias for the highest valid index, is just plain whacked. So what should the slice object return? With Python's current indexing/slicing, there is no value that just works. 'None' will work as a stop value in a slice, but index arithmetic will fail. The value 0 - (len(sequence) + 1) will work as a stop value, and slice arithmetic and range() will happily use it, but the result is not what the programmer probably intended. The problem is subtle. A Python sequence starts at index zero. There is some appeal to giving negative indexes a useful interpretation, on the theory that they were invalid as subscripts and thus useless otherwise. That theory is wrong, because negative indexes were already useful, even though not legal subscripts, and the reinterpretation often breaks their exiting use. Specifically, negative indexes are useful in index arithmetic, and as exclusive stopping bounds. The problem is fixable. We propose that negative indexes not be treated as a special case. To index from the far end of a sequence, we use a syntax that explicitly calls for far-end indexing. Rationale New-style slicing/indexing is designed to fix the problems described above, yet live happily in Python along-side the old style. The new syntax leaves the meaning of existing code unchanged, and is even more Pythonic than current Python. Semicolons look a lot like colons, so the new semicolon syntax follows the rule that things that are similar should look similar. The semicolon syntax is currently illegal, so its addition will not break existing code. Python is historically tied to C, and the semicolon syntax is evocative of the similar start-stop-step expressions of C's 'for' loop. JPython is tied to Java, which uses a similar 'for' loop syntax. The '$' character currently has no place in a Python index, so its new interpretation will not break existing code. We chose it over other unused symbols because the usage roughly corresponds to its meaning in the Python library's regular expression module. We expect use of the $0, $1, $2 ... syntax to be rare; nevertheless, it has a Pythonic consistency. Thanks to Paul Rubin for advocating it over the inferior multiple-$ syntax that this author initially proposed. Backwards Compatibility To avoid braking code, we use new syntax that is currently illegal. The new syntax more-or-less looks like current Python, which may help Python programmers adjust. User-defined classes that implement the sequence protocol are likely to work, unchanged, with new-style slicing. 'Likely' is not certain; we've found one subtle issue (and there may be others): Currently, user-defined classes can implement Python subscripting and slicing without implementing Python's len() function. In our proposal, the '$' symbol stands for the sequence's length, so classes must be able to report their length in order for $ to work within their slices and indexes. Specifically, to support new-style slicing, a class that accepts index or slice arguments to any of: __getitem__ __setitem__ __delitem__ __getslice__ __setslice__ __delslice__ must also consistently implement: __len__ Sane programmers already follow this rule. Copyright: This document has been placed in the public domain. From aisaac0 at verizon.net Sun Aug 14 15:01:25 2005 From: aisaac0 at verizon.net (David Isaac) Date: Sun, 14 Aug 2005 19:01:25 GMT Subject: FTP over SSL (explicit encryption) References: Message-ID: <9yMLe.3072$%K4.581@trnddc09> > > http://www.lag.net/paramiko/ "Alan Isaac" wrote in message news:S04Le.303$Rp5.100 at trnddc03... > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > sock.settimeout(20) > sock.connect((hostname, port)) > my_t = paramiko.Transport(sock) > my_t.connect(hostkey=None ,username=username, password=password, pkey=None) > my_chan = my_t.open_session() > my_chan.get_pty() > my_chan.invoke_shell() > my_sftp = paramiko.SFTP.from_transport(my_t) > > Now my_sftp is a paramiko sftp_client. > See paramiko's sftp_client.py to see what it can do. When it rains it pours. wxSFTP http://home.gna.org/wxsftp/ uses paramiko and provides a GUI. Cheers, Alan Isaac From lists at nomis52.net Wed Aug 17 05:53:16 2005 From: lists at nomis52.net (Simon Newton) Date: Wed, 17 Aug 2005 17:53:16 +0800 Subject: Embedding Python in C, undefined symbol: PyExc_FloatingPointError In-Reply-To: <4302ecb2$0$16020$9b622d9e@news.freenet.de> References: <4302ecb2$0$16020$9b622d9e@news.freenet.de> Message-ID: <1124272396.5033.21.camel@localhost.localdomain> On Wed, 2005-08-17 at 09:52 +0200, "Martin v. L?wis" wrote: > Simon Newton wrote: > > gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 > > -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes > > gcc main.o -L/usr/lib -lpthread -ldl -lutil > > -lm /usr/lib/python2.4/config/libpython2.4.a -o main > > No. You need to export the Python symbols from your executable to > extension modules. IOW, you need to pass > > -Xlinker -export-dynamic > > to the gcc invocation. Thanks Martin, -export-dynamic fixed it. Simon From paddy3118 at netscape.net Sat Aug 6 15:00:28 2005 From: paddy3118 at netscape.net (Paddy) Date: 6 Aug 2005 12:00:28 -0700 Subject: Decline and fall of scripting languages ? In-Reply-To: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> Message-ID: <1123354828.386017.17100@g14g2000cwa.googlegroups.com> Do you know anyone who has dropped LAMP for a proprietary Web solution? Or vice versa? Know any sys-admins that have dropped their use of scripting languages for something else? What are the alternatives that are supposedly driving scripting languages out? - I'm unconvinced. From sheig222 at gmail.com Mon Aug 1 08:09:07 2005 From: sheig222 at gmail.com (Ira) Date: Mon, 1 Aug 2005 15:09:07 +0300 Subject: Changing interpreter's deafult output/error streams References: Message-ID: OK let me rephrase, the standard error stream (and if I'm not mistaken also the one that PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go ahead and write the following in python... SomeNewStreamOrFileOrWhateverItIs = new stream sys.stderr = SomeNewStreamOrFileOrWhateverItIs I can go ahead and do the exact same thing from the C source code. All I need to do is to figure out how to wrap a c-style FILE* with a PyObject, And PySys_SetObjet("stderr", newstream); I'm very new to python so that might be nonsense but it appeals to my programmer's common sense. Can anyone tell me how to do this? "Michael Hudson" wrote in message news:m24qaa95m3.fsf at 82-33-185-193.cable.ubr01.azte.blueyonder.co.uk... > "Ira" writes: > > > Using an embedded interpreter, how do I change it's default output > > streams (specifically the one used by PyErr_Print() which I'm > > guessing is the default error stream)? > > It looks as though it writes to stderr unconditionally. But most of > the reasons for ended up in PyErr_Print can be intercepted at a higher > level (I think -- I mean sys.excepthook & co here). > > Cheers, > mwh > > -- > ARTHUR: Yes. It was on display in the bottom of a locked filing > cabinet stuck in a disused lavatory with a sign on the door > saying "Beware of the Leopard". > -- The Hitch-Hikers Guide to the Galaxy, Episode 1 > -- > http://mail.python.org/mailman/listinfo/python-list > From donn at u.washington.edu Fri Aug 5 14:29:11 2005 From: donn at u.washington.edu (Donn Cave) Date: Fri, 05 Aug 2005 11:29:11 -0700 Subject: socket and os.system References: Message-ID: In article , Peter Hansen wrote: > mfaujour wrote: > > I HAVE THIS PYTHON PROGRAMM: > [snip] > > > socket.error: (98, 'Address already in use') > > > > DOES SOMEONE HAS AN IDEA ? > > PLEASE learn to format your questions more appropriately! Your post is > simply _awful_ to read. At the very least, ALL CAPS is considered to be > "shouting", though I can see why you had to use them since it would have > been impossible to see the questions amongst all the code. > > In any case, assuming I've been able to guess at the specific problem > based on the above lines, which isn't certain, you need to use a line > something like this in your code to allow your server socket to bind to > an address that was previously in use: > > server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > > For more background, I suggest a Google search on "python so_reuseaddr". For heaven's sake, it wasn't that hard to read. Of course the upper case text was an unpardonable violation of people's tender sensibilities, but in this case it does have the virtue of a strong visible distinction between his code and his comments. The good thing is that he did provide example that clearly illustrates the problem. Which is not really that he can't reuse the socket address. I mean, it's usually good to take care of that, but ordinarily for reasons having to do with shutdown latency. In the present case, his application is holding the socket open from a fork that inherited it by accident. I think the current stock answer is "use the subprocess module." If that's not helpful, either because it doesn't provide any feature that allows you to close a descriptor in a fork (I seem to recall it does), or it isn't supported in your version of Python (< 2.4), then you have your choice of two slightly awkward solutions: 1. fcntl F_SETFD FD_CLOEXEC (see man 2 fcntl) 2. implement your own spawn command (see os.py's spawnv()) and close the socket FD in the fork. Donn Cave, donn at u.washington.edu From peter at engcorp.com Sun Aug 28 16:05:03 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Aug 2005 16:05:03 -0400 Subject: Yielding a chain of values In-Reply-To: References: Message-ID: <3_adnQyx8IpwhY_eRVn-rQ@powergate.ca> Talin wrote: > I'm finding that a lot of places within my code, I want to return the > output of a generator from another generator. Currently the only method > I know of to do this is to explicitly loop over the results from the > inner generator, and yield each one: > > for x in inner(): > yield x > > I was wondering if there was a more efficient and concise way to do > this. And if there isn't, then what about extending the * syntax used > for lists, i.e.: > > yield *inner() It's not the first time it's been suggested. You can check the archives perhaps for past discussions. I think syntax like that could be a good idea too, for readability reasons perhaps, but I don't think it's really important for efficiency reasons. If you think about it, this involves one stack frame being set up for the call to the generator, and then a series of quick context switches (or whatever they're called in this situation) between the current stack frame and the inner() one, as each yielded value is produced, yield, then re-yielded up to the calling frame (with another quick context switch). No additional stack frames are generated, and very few byte codes are involved: >>> def f(): ... for x in inner(): ... yield x ... >>> dis.dis(f) 2 0 SETUP_LOOP 21 (to 24) 3 LOAD_GLOBAL 0 (inner) 6 CALL_FUNCTION 0 9 GET_ITER >> 10 FOR_ITER 10 (to 23) 13 STORE_FAST 0 (x) 3 16 LOAD_FAST 0 (x) 19 YIELD_VALUE 20 JUMP_ABSOLUTE 10 ... Yes, that is some overhead, but unless you are going many levels deep (and that's usually a design smell of some kind) this isn't likely to be noticed amongst the rest of the code which is presumably doing something non-trivial to produce the values in the first place, and to consume them ultimately. The basic loop could be handled entirely from C with an appropriate syntax addition as you suggest, but executing those four byte code instructions is very quick, and there is no repeated (Python) function call overhead as you would expect if inner() were not a generator. -Peter From R.Brodie at rl.ac.uk Tue Aug 9 11:44:40 2005 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 9 Aug 2005 16:44:40 +0100 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> Message-ID: "N.Davis" wrote in message news:42F8CC8F.7020500 at le.ac.uk... > To my mind, although one CAN put many classes in a file, it is better to > put one class per file, for readability and maintainability. Zero classes in a file works well too ;) From spam.csubich+block at block.subich.spam.com Wed Aug 10 21:13:57 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 10 Aug 2005 21:13:57 -0400 Subject: wxPython and threads again In-Reply-To: References: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> Message-ID: David E. Konerding DSD staff wrote: > The easiest approach, though, is to use the threadedselectreactor in Twisted (you need > to check the HEAD branch out with subversion, because that reactor isn't included in any releases). > With threadedselectreactor, it's easy to incorporate both the GUI event loop and the twisted reactor. > Twisted already includes lots of code for doing asynchronous callback-style IO for > IO bound processes like downloading. Further, you don't even think in an explicitly threaded way- > createing a whole thread just to manage a download process which is motly IO and a little bookkeeping is > silly. Twisted's approach just makes a lot more sense and simplifies the code too. Or, don't use threadedselectreactor, but instead just use normal threading and reactor.callFromThread. From pydecker at gmail.com Mon Aug 1 10:24:33 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 1 Aug 2005 10:24:33 -0400 Subject: Wheel-reinvention with Python In-Reply-To: <7xvf2rync2.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> Message-ID: On 31 Jul 2005 09:03:41 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > How on earth did you decide that, since tkinter actually runs out of > the box when you install Python on most platforms, and wxPython doesn't? > I can't even think about trying out Dabo unless I'm willing to go through > some enormous pain of getting wxPython to work. Geez, can you whine some more? Most people are running wxPython just fine, and since you "don't care enough" to bother to follow instructions, and have some oddball religious rule about installing binaries, it's everyone else's fault that you experience "enormous pain". Gimme a break. -- # p.d. From python-list at d1z1.de Fri Aug 26 05:34:20 2005 From: python-list at d1z1.de (Dirk Zimmermann) Date: Fri, 26 Aug 2005 11:34:20 +0200 Subject: classes and list as parameter, whats wrong? Message-ID: <20050826093420.GC23815@hep.physik.uni-siegen.de> Hi! I have a problem in a program. And I don't understand what is going on. I can code something, that the "error" doesn't occur anymore. But I still don't know the reason and this is unsatisfactory: Did I understood something wrong or is there a bug? To make it short, I boiled down the program to the crucial part. It looks like this: ----------- START ------------ #!/usr/bin/env python class cClass: """ Base class to handle playlists, i.e. the files, the name, etc. """ def __init__(self, LL=[]): self.list=LL def addFile(self,L): self.list.append(L) def main(): l1 = ['a','b','c'] lNames=['n1','n2','n3'] for name in lNames: objC=cClass() for each in l1: objC.addFile(each) print objC.list del objC if __name__ == "__main__": main() ----------- END ---------------- If I start it, I get the following output: ['a', 'b', 'c'] ['a', 'b', 'c', 'a', 'b', 'c'] ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c'] Why does this list grow? I thought, with every new instance the list LL is set to []? How can bring light in this? Best, Dirk From jeffrey.schwab at rcn.com Sun Aug 21 16:09:49 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sun, 21 Aug 2005 16:09:49 -0400 Subject: last line chopped from input file In-Reply-To: <1124603622.204380.256560@g47g2000cwa.googlegroups.com> References: <1124603622.204380.256560@g47g2000cwa.googlegroups.com> Message-ID: Eric Lavigne wrote: > Here is a shell command (MS-DOS): > debug\curve-fit output.txt > > And here is a Python script that *should* do the same thing (and almost > does): Python equivalent is roughly: import os import subprocess subprocess.Popen([os.path.join("debug", "curve-fit")], stdin=file("input.txt"), stdout=file("output.txt", 'w')).wait() > import os > > inputfilename = 'input.txt' > outputfilename = 'output.txt' > > inputfile = open(inputfilename,'r') > outputfile = open(outputfilename,'w') > inputstream,outputstream = os.popen2("debug\\curve-fit") > inputstream.write(inputfile.read()) > inputfile.close() > inputstream.close() > outputfile.write(outputstream.read()) > outputstream.close() > outputfile.close() > > In the shell command, my curve-fit program processes the entire input > file. In the Python script, my curve-fit program processes all except > for the last line. Adding an extra newline to the end of my input file > fixes this problem. What did I do wrong that led to this small > difference? No idea. Your version works fine for me. From cam.ac.uk at mh391.invalid Fri Aug 5 06:51:20 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Fri, 05 Aug 2005 11:51:20 +0100 Subject: >time.strftime %T missing in 2.3 In-Reply-To: References: Message-ID: Andy Leszczynski wrote: > I accept that, but still pain. Took me a while to filter out the problem > in the code running on the Unix and not on M$. This is one of the reasons I usually use Cygwin Python when I can. Stuff is much less likely to mysteriously break when moving from UNIX to Cygwin then from UNIX to Windows. -- Michael Hoffman From mal at egenix.com Tue Aug 23 06:39:03 2005 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 23 Aug 2005 12:39:03 +0200 Subject: [Python-Dev] Revised PEP 349: Allow str() to return unicode strings In-Reply-To: References: <20050822213142.GA5702@mems-exchange.org> Message-ID: <430AFCC7.9030402@egenix.com> Thomas Heller wrote: > Neil Schemenauer writes: > > >>[Please mail followups to python-dev at python.org.] >> >>The PEP has been rewritten based on a suggestion by Guido to change >>str() rather than adding a new built-in function. Based on my >>testing, I believe the idea is feasible. It would be helpful if >>people could test the patched Python with their own applications and >>report any incompatibilities. >> > > > I like the fact that currently unicode(x) is guarateed to return a > unicode instance, or raises a UnicodeDecodeError. Same for str(x), > which is guaranteed to return a (byte) string instance or raise an > error. > > Wouldn't also a new function make the intent clearer? > > So I think I'm +1 on the text() built-in, and -0 on changing str. Same here. A new API would also help make the transition easier from the current mixed data/text type (strings) to data-only (bytes) and text-only (text, renamed from unicode) in Py3.0. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 23 2005) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From peter at engcorp.com Mon Aug 22 17:04:59 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 17:04:59 -0400 Subject: combining namespaces when importing two modules In-Reply-To: References: Message-ID: Donnal Walter wrote: > I would like to be able to write something like: > > import dcw as dw > import xyz as dw > > such that the 'dw' namespace includes definitions from both dcw and xyz, > but in the script above names from dcw1 are lost. How can I combine the > two? (I'd rather not use 'import *'.) Thanks. This sounds really gross and dangerous, but you could do this, and it might even work. I wouldn't recommend it, but without knowing your use case I can't say what I'd recommend instead. import dcw as dw import xyz as _ dw.__dict__.update(_.__dict__) del _ -Peter From matt.hammond at rd.bbc.co.uk Tue Aug 30 06:36:59 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Tue, 30 Aug 2005 11:36:59 +0100 Subject: time.mktime problem References: <1125397106.854442.227120@g44g2000cwa.googlegroups.com> Message-ID: I don't get the same results: >>> import datetime, time >>> ta1=(time.strptime('000001', '%H%M%S')) >>> ta2=(time.strptime('230344', '%H%M%S')) >>> t1=time.mktime(ta1) >>> t2=time.mktime(ta2) >>> print t1, t2 -2208988799.0 -2208905776.0 >>> print t1-t2 -83023.0 Suse 9.3, python 2.4 (all 64bit) Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From alessandro.bottoni at infinito.it Mon Aug 22 03:13:56 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Mon, 22 Aug 2005 07:13:56 GMT Subject: Network Programming Information References: Message-ID: John Walton wrote: > Hello. It's me again. Thanks for all the help with > the Python Networking Resources, but does anyone know > what I'll need to know to write a paper on Network > Programming and Python. Like terminology and all > that. Maybe I'll have a section on socketets, TCP, > Clients (half of the stuff I don't even know what it > means). So, does anyone know any good websites with > Network Programming information. Thanks! John, I think this book contains everything you need to know both for writing a paper and for writing code: Foundations of Python Network Programming by John Goerzen http://www.amazon.com/exec/obidos/tg/detail/-/1590593715/qid=1124694590/sr=2-1/ref=pd_bbs_b_2_1/103-4249885-5594254?v=glance&s=books It is a fine book and a good investement. CU ----------------------------------- Alessandro Bottoni From elmo13 at jippii.fi Sat Aug 13 17:55:45 2005 From: elmo13 at jippii.fi (=?iso-8859-1?q?Elmo_M=E4ntynen?=) Date: Sun, 14 Aug 2005 00:55:45 +0300 Subject: Dictionary inheritance References: Message-ID: On Fri, 12 Aug 2005 12:44:11 -0700, Talin wrote: > I want to make a dictionary that acts like a class, in other words, > supports inheritance: If you attempt to find a key that isn't present, > it searches a "base" dictionary, which in turn searches its base, and so on. > > Now, I realize its fairly trivial to code something like this using > UserDict, but given that classes and modules already have this behavior, > is there some built-in type that already does this? > > (This is for doing nested symbol tables and such.) > > --- You could always do: class nestedDict(dict): ... From kbchung at hongik.ac.kr Fri Aug 12 20:42:49 2005 From: kbchung at hongik.ac.kr (KB) Date: 12 Aug 2005 17:42:49 -0700 Subject: How to quit a Windows GUI program gracefully with Python under Cygwin? References: <1123761153.401824.43040@g49g2000cwa.googlegroups.com> <1123791622.954340.74930@o13g2000cwo.googlegroups.com> <1123841222.202745.259280@f14g2000cwb.googlegroups.com> Message-ID: <1123893769.374705.258110@z14g2000cwz.googlegroups.com> Of course, I downloaded the source of 'SendKeys' and installed it under both Cygwin and Python Windows with $ python setup.py install although this did not help me. KB From nospam at nospam.com Sat Aug 20 18:30:17 2005 From: nospam at nospam.com (42) Date: Sat, 20 Aug 2005 22:30:17 GMT Subject: Sandboxes References: Message-ID: In article , eurleif at ecritters.biz says... > 42 wrote: > > I was wondering if it would be effective to pre-parse incoming scripts > > and reject those containing "import"? > > getattr(__builtins__, '__imp' + 'ort__')('dangerousmodule') > See that's sort of thing I'm talking about. :) Earlier I mentioned that I figured I'd be ok to pre-parse the script to sanitize the langauge a bit. There are what 30 odd built in functions? And a dozen or so keywords? Basically if I turn off anything that deals with 'executable code', 'meta data', or 'reflection' I'm hoping I'd be in the clear. e.g.: looking at the built in function list these would be suspect... probably not all of them are dangerous, but I beleive I could get by without any of them: first the keywords: exec, import and then the built in functions: type, super, setattr, reload, property, open, locals, issubclass, isinstance, hasattr, globals, getattr, file, execfile, eval, dir, dict, delattr, compile, classmethod, callable, __import__ I'd also filter: raw_input, input, and help (as they don't make sense in the application) context anyway. Sure I might be seriously crippling the power of python by doing this, but that's rather the point :), and it should be fine for my purposes. Thoughts? Still gaping holes? thanks in advance, Dave From godwinburby at gmail.com Wed Aug 24 00:32:41 2005 From: godwinburby at gmail.com (Godwin) Date: 23 Aug 2005 21:32:41 -0700 Subject: Eve from Adams' Ribs In-Reply-To: References: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> Message-ID: <1124857961.863169.173770@f14g2000cwb.googlegroups.com> www.devx.com/dbzone/Article/22093 U've made a point and i have seen that approach in the above article. But i was curious about creating python classes and code on fly. The only way i could do it was by using exec function. Is there a standard way of doing it. What are the plus points of such kind of programming? Is it only done by hackers? Sorry for asking the wrong question for getting the right answer! From pinard at iro.umontreal.ca Sun Aug 21 08:52:10 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Sun, 21 Aug 2005 08:52:10 -0400 Subject: Binary Trees in Python In-Reply-To: References: Message-ID: <20050821125210.GA7230@phenix.progiciels-bpi.ca> [Jorgen Grahn] > Neither C++ nor Python has tree structures in their standard > libraries. I assume that's because there is no single interface that > is proven to suit everybody's needs. It is already easy writing "tree constants" using recursive tuples or lists. To process simple trees in Python, I usually subclass some Node type from list, and write the traversal methods that suit the application. The sub-classing already allow for indexing sub-nodes by "self[index]", and iterating over all by "for subnode in self:", etc. In my experience, it all goes pretty easily, while staying simple. However, things related to balancing, finding paths between nodes, or searching for patterns, etc. may require more work. There are surely a flurry of tree algorithms out there. What are the actual needs you have, and would want to see covered by a library? -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From tdelaney at avaya.com Mon Aug 22 18:46:58 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Tue, 23 Aug 2005 08:46:58 +1000 Subject: Well, another try Re: while c = f.read(1) Message-ID: <2773CAC687FD5F4689F526998C7E4E5F05CC5F@au3010avexu1.global.avaya.com> Robert Kern wrote: > James asked a question in such a way that I didn't think it would get > answered. Judging from the other non-responses to his post, I was > right. I showed him the way to ask questions such that they *will* get > answered, and he came back, did so, and got his questions answered. FWIW, I agree with you, but then I'm another one who directs people to smart-questions. I also direct co-workers to it, and even myself on a semi-regular basis. Tim Delaney From http Sat Aug 20 15:01:58 2005 From: http (Paul Rubin) Date: 20 Aug 2005 12:01:58 -0700 Subject: Sandboxes References: <3mog8aF17j66oU1@uni-berlin.de> Message-ID: <7xd5o8bffd.fsf@ruckus.brouhaha.com> 42 writes: > I want the 'worst case' a malicious script to be able to accompish to be > a program crash or hang. You should not rely on Python to provide any kind of security from malicious users who can run Python scripts. From peter at monicol.co.uk Fri Aug 12 12:06:45 2005 From: peter at monicol.co.uk (Peter Mott) Date: Fri, 12 Aug 2005 17:06:45 +0100 Subject: Why is this? In-Reply-To: References: <42fc8eb4$0$38045$bed64819@news.gradwell.net> Message-ID: <42fcc918$0$38043$bed64819@news.gradwell.net> Matt Hammond wrote: > On Fri, 12 Aug 2005 12:57:38 +0100, Peter Mott wrote: > >> If I use concatenation + instead of multiplication * then I get the >> result that Jiri expected: >> >> >>> L = [[]] + [[]] >> >>> L[1].append(1) >> >>> L >> [[], [1]] >> >> With * both elements are changed: >> >> >>> L = [[]] * 2 >> >>> L[1].append(1) >> >>> L >> [[1], [1]] >> >> Alex Martelli says in his excellent Nutshell book that + is >> concatenation and that "n*S is the concatenation of n copies of S". >> But it seems not so. Surely, from a logical point of view, S + S >> should be the same as S * 2? > > > S+S is the same as S*2, but L= [[]] + [[]] is not S+S. The two terms > being added are different instances of an empty list. You are > adding/concatenating two different object instances. But it is still true that [[]] + [[]] is not the same as [[]] * 2. In my usage anyway this means that "S+S is the same as S*2" is false. Because there are Python expressions for which it is falsfied. The problem I have is pretty philosophical I admit, but I don't think you do it justice. It's really about identity. Logically speaking identity is a congruence relation of a language, which means that if x=y is true then C(x) = C(y) will be true for any context C of the lanuage. Python is so regular that most of the time it follows this. But not with *. If you define C(x): def C(x): ... x[1].append(1) ... return x[0] then although [[]]+[[]] == [[]]*2 evaluates true C([[]]+[[]]) is different from C([[]]*2). So == is not a congruence in Python. Inbteresting that Phil Hunt just posted about 'Unify' which, if I understand it right, has the feature that provided expressions S and T are in the canonical "Storage Manager" format then == will be a congruence and hence an idenity. Cheers Peter From km at mrna.tn.nic.in Tue Aug 23 02:55:01 2005 From: km at mrna.tn.nic.in (km) Date: Tue, 23 Aug 2005 12:25:01 +0530 Subject: loop in python Message-ID: <20050823065501.GA24558@mrna.tn.nic.in> Hi all, Why is it that the implementation of empty loop so slow in python when compared to perl ? #i did this in python (v 1.5) for x in xrange(1000): print x # this took 0.017 seconds -------------------------- #similar code in perl (v 5.6): for $x (0..1000) { print $x; } # this took 0.005 seconds only !!! Is python runtime slow at all aspects when compared to perl ? I really wonder what makes python slower than perl ? Is there any proposal to make python faster in future versions ? curious to know all these ... regards, KM From steven.bethard at gmail.com Fri Aug 12 00:55:12 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 11 Aug 2005 22:55:12 -0600 Subject: How to Adding Functionality to a Class by metaclass(not by inherit) In-Reply-To: References: Message-ID: kyo guan wrote: > How to Adding Functionality to a Class by metaclass(not by inherit) > [snip] > > class MetaFoo(type): > def __init__(cls, name, bases, dic): > super(MetaFoo, cls).__init__(name, bases, dic) > > for n, f in inspect.getmembers(Foo, inspect.ismethod): > setattr(cls, n, f) ^^^^^^^^^ f.im_func See if that works. I think it should. But the real question is why you want to do this. Why can't you just inherit from Foo? STeVe From xah at xahlee.org Sat Aug 27 17:59:34 2005 From: xah at xahlee.org (Xah Lee) Date: 27 Aug 2005 14:59:34 -0700 Subject: OpenSource documentation problems In-Reply-To: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: <1125179974.483320.116780@g49g2000cwa.googlegroups.com> previously i've made serious criticisms on Python's documentations problems. (see http://xahlee.org/perl-python/re-write_notes.html ) I have indicated that a exemplary documentation is Wolfram Research Incorporated's Mathematica language. (available online at http://documents.wolfram.com/mathematica/ ) Since Mathematica is a proprietary language costing over a thousand dollars and most people in the IT industry are not familiar with it, i like to announce a new discovery: this week i happened to read the documentation of Microsoft's JavaScript. See http://msdn.microsoft.com/library/en-us/script56/html/js56jsconjscriptfundamentals.asp This entire documentary is a paragon of technical writing. It has clarity, conciseness, and precision. It does not abuse jargons, it doesn't ramble, it doesn't exhibit author masturbation, and it covers its area extremely well and complete. The documentation set are very well organized into 3 sections: Fundamentals, Advanced, Reference. The tutorial section ?fundamentals? is extremely simple and to the point. The ?advanced? section gives a very concise yet easy to read on some fine details of the language. And its language reference section is complete and exact. I would like the IT industry programers and the OpenSource fuckheads to take note of this documentation so that you can learn. Also, this is not the only good documentation in the industry. As i have indicated, Mathematica documentation is equally excellent. In fact, the official Java documentation (so-called Java API by Sun Microsystems) is also extremely well-written, even though that Java the language is unnecessarily very complex and involves far more technical concepts that necessitate use of proper jargons as can be seen in their doc. A additional note i like to tell the OpenSource coding morons in the industry, is that in general the fundamental reason that Perl, Python, Unix, Apache etc documentations are extremely bad in multiple aspects is because of OpenSource fanaticism. The fanaticism has made it that OpenSource people simply became UNABLE to discern quality. This situation can be seen in the responses of criticisms of OpenSource docs. What made the situation worse is the OpenSource's mantra of ?contribution? ? holding hostile any negative criticism unless the critic ?contributed? without charge. Another important point i should point out is that the OpenSource morons tend to attribute ?lack of resources? as a excuse for their lack of quality. (when they are kicked hard to finally admit that they do lack quality in the first place) No, it is not lack of resources that made the OpenSource doc criminally incompetent. OpenSource has created tools that take far more energy and time than writing manuals. Lack of resource of course CAN be a contribution reason, along with OpenSource coder's general lack of ability to write well, among other reasons, but the main cause as i have stated above, is OpenSource fanaticism. It is that which have made them blind. PS just to note, that my use of OpenSource here do not include Free Software Foundation's Gnu's Not Unix project. GNU project in general has very excellent documentation. GNU docs are geeky in comparison to the commercial entity's docs, but do not exhibit jargon abuse, rambling, author masturbation, or hodgepodge as do the OpenSource ones mentioned above. Xah xah at xahlee.org ? http://xahlee.org/ From google at phaedro.com Tue Aug 30 04:19:49 2005 From: google at phaedro.com (google at phaedro.com) Date: 30 Aug 2005 01:19:49 -0700 Subject: Writing Multithreaded Client-Server in Python. In-Reply-To: <7x3bos55vb.fsf@ruckus.brouhaha.com> References: <1125376325.572881.163770@g44g2000cwa.googlegroups.com> <7x3bos55vb.fsf@ruckus.brouhaha.com> Message-ID: <1125389989.030999.172080@g47g2000cwa.googlegroups.com> Paul Rubin schreef: > "Sidd" writes: > > I tried finding and example of multithreaded client-serve program in > > python. Can any one please tell me how to write a multithreaded > > client-server programn in python such that > > 1.It can handle multiple connections > > 2.It uses actual threads and not select() or some other function > > If you mean multiple threads on the server side, see the SocketServer > module and its ThreadingMixin class. You may have to look at the > source code since up until recently the docs were incomplete. There > is a big helpful comment at the top of SocketServer.py which recently > got merged into the library reference manual. Yes, however the term 'ThreadingMixIn' is a bit confusing (at least it was to me). What it does do, is handle each request (from the same client too) in a new separate thread. Convenient if your processing intensive handle may otherwise slow down the main server process becoming less responsive to other requests. What it doesn't do (and what Sidd seems to search as is suggested by his 'select()' remark) is handle each client in a separate thread. This is in fact listed in the (scarce) doc as a 'ToDo' of the SocketServer if my memory serves me right. If you want to apply SocketServer such that each client corresponds to one thread that handles its' requests (and maintains its state), don't use ThreadingMixIn - only the thread-selection will be executed in a separate thread. You could maintain a dictionary of Threads running RequestHandlers for each client in the server class. I use a new Handler for each incoming request, parse a username parameter from the message and select the thread-handler from the server dict. Each handler in the dict contains an open outgoing socket, so I can also e.g. broadcast and notify clients. Alternatively, you can (probably) keep the client2server socket open as well (on both client and server). Thread selection should then (hopefully :-) happen magically by calling the handle() method in each thread directly. HTH Thijs From tjreedy at udel.edu Sun Aug 28 23:27:07 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2005 23:27:07 -0400 Subject: overload builtin operator References: <3n61u4F1fg2U1@individual.net> <431116ef.2601201920@news.oz.net> <431227bd.7666734@news.oz.net> Message-ID: I suspect that PyPy, when further alone, will make it easier to do things like develop a customized interpreter that has alternate definitions for builtin operators. So maybe the OP should ask again in a year or two. TJR From tiang_ono at yahoo.com Thu Aug 18 01:37:34 2005 From: tiang_ono at yahoo.com (Titi Anggono) Date: Wed, 17 Aug 2005 22:37:34 -0700 (PDT) Subject: Tkinter and gnuplot module Message-ID: <20050818053734.46422.qmail@web30705.mail.mud.yahoo.com> Hi all, I have some questions: 1. Can we use Tkinter for web application such as Java ? 2. I use gnuplot.py module for interfacing with gnuplot in linux. Can we make the plot result shown in web ? I tried using cgi, and it didn't work. Thanks ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From jepler at unpythonic.net Mon Aug 8 07:59:15 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 8 Aug 2005 06:59:15 -0500 Subject: How to determine that if a folder is empty? In-Reply-To: <311b5ce1050807221323f7436e@mail.gmail.com> References: <311b5ce1050807221323f7436e@mail.gmail.com> Message-ID: <20050808115914.GC13847@unpythonic.net> On standard Unix fileystems, one way to check for this is to check that the st_nlink of the directory is 2. However, even on Unix systems this isn't guaranteed for all filesystem types. Of course, finding whether a directory is empty is inherently racy: a file could be created between the time you decide it's empty and take whatever action is appropriate for the empty directory... I'll side with those who say to use 'not os.listdir()' as the test for emptyness, until you are certain it's not fast enough. os.listdir("/"): 10000 loops, best of 3: 39.3 usec per loop os.stat("/").st_nlink: 100000 loops, best of 3: 7.27 usec per loop Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From gry at ll.mit.edu Wed Aug 10 14:09:00 2005 From: gry at ll.mit.edu (gry at ll.mit.edu) Date: 10 Aug 2005 11:09:00 -0700 Subject: Catching stderr output from graphical apps References: Message-ID: <1123697339.925135.161200@g47g2000cwa.googlegroups.com> Python 2.3.3, Tkinter.__version__'$Revision: 1.177 $' Hmm, the error window pops up with appropriate title, but contains no text. I stuck an unbuffered write to a log file in ErrorPipe.write and got only one line: Traceback (most recent call last):$ Any idea what's wrong? -- George From steve at holdenweb.com Thu Aug 25 08:08:21 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Aug 2005 08:08:21 -0400 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon wrote: > Op 2005-08-24, Magnus Lycka schreef : > >>Antoon Pardon wrote: >> >>>I think he did, because both expression are not equivallent >>>unless some implicite constraints make them so. Values where >>>both expressions differ are: >>> >>> start1=67, stop1=9, start2=10, stop2=29 This is just too fatuous to ignore, sorry. >> >>Ouch! That didn't occur to me. How sloppy to just assume that >>time periods can't end before they start. > > > I have no trouble that you assume a time period starts before > it ends. > > But two pieces of code that only give the same result under > particular assumptions are not equivallent. For all I know > his code might work without this assumption and thus be > usefull in circumstances where yours is not. > > Maybe someone uses a convention where time intervals that > stop before they start can have some meaning. > > Equivallent code IMO always gives the same results, not > only under the particular constraints you are working with. > > >>I'll shut up now. You win, >>I'm obviously the idiot here, and Python's must be >>redesigned from ground up. Pyrdon maybe? > > > If I ever design a language it'll be called: 'Queny' > ...and you will regard it as perfect and be completely unable to understand why nobody likes it. Could we possibly reduce the number of arguments about ridiculous postulates such as , and try to remember that most people on this list are dealing with real life? Magnus gave you a perfectly reasonable example of some code that could be simplified. You say the two pieces of code aren't equivalent. While you may be (strictly) correct, your assertion signally fails to add enlightenment to the discussion. I continue to look forward to the first post in which you actually accept someone else's point of view without wriggling and squirming to justify your increasingly tenuous attempts to justify every opinion you've ever uttered on this group :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From projecktzero at yahoo.com Tue Aug 2 11:46:19 2005 From: projecktzero at yahoo.com (projecktzero) Date: 2 Aug 2005 08:46:19 -0700 Subject: Python IDE's References: Message-ID: <1122997579.511303.16770@o13g2000cwo.googlegroups.com> The thing that nudged me into trying VIM was the book, The Pragmatic Programmer. It mentioned Emacs and VIM and the value of learning a powerful editor and sticking with it. I had tried Emacs three times long ago, and it didn't click with me. I decided to try VIM, and it made a lot more sense to me. Yep, there's a steep learning curve. I learned a lot of the basic command in a day or so, then gradually learned more and more. I'm always finding something new about it. There's tons of scripts, plug-ins, and tips at the vim.org site. A couple of important things to me are: Cross platform: I work with Windows, Linux, VMS, and Mac Works with mulitple languages: I write Python, Perl, XHTML/HTML, CSS, Javascript, SQL, COBOL, DCL, and occasionally VBScript. I will point out that both Emacs and VIM do their best to keep your hands on the keyboard which supposedly keeps you more productive since you don't have to waste time grabbing the mouse to perform many tasks. That philosophy is alien to many people and does take some getting used to. I think both of these editors have their roots in the pre-mouse days. http://brianray.chipy.org//Python/pythonandvim.html has a blog about VIM with Python built in. You can script VIM with Python. http://www.vim.org/scripts/script.php?script_id=910 is a script that allows you to use PyDoc from within VIM, so you can look up documentation on modules while coding. http://www.vim.org/scripts/script.php?script_id=850 pydiction is a special dictionary file of Python modules for use with vim's completion feature. http://www.vim.org/scripts/script.php?script_id=127 is a plug in for running Python scripts from within VIM. http://www.vim.org/scripts/script.php?script_id=1096 allows you to run PyChecker from within VIM. Code folding, auto indentation, syntax highlighting are standard features in VIM. Anyway, it's worth checking out VIM. If it doesn't click with you, look at Emacs. I'd imagine that it has as many plug-ins/scripts for Python as VIM. From jolafix at gmail.com Fri Aug 5 20:30:11 2005 From: jolafix at gmail.com (Atila Olah) Date: 5 Aug 2005 17:30:11 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <1123288211.484110.301970@g43g2000cwa.googlegroups.com> I think D H is right. Or even if you'd find out that most of the people would better like 'modulescope' or 'module', (what is, i think, imposible), you'd destroy the backward-compatibility with older versions of Puthon if you implement it. But it won't be implemented. Trust me. From cipherpunk at gmail.com Thu Aug 25 17:54:53 2005 From: cipherpunk at gmail.com (cipherpunk at gmail.com) Date: 25 Aug 2005 14:54:53 -0700 Subject: a dummy python question In-Reply-To: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> References: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> Message-ID: <1125006893.676671.149550@g14g2000cwa.googlegroups.com> This is not reproducible under either Python 2.3.4 (UNIX), Python 2.4.1 (UNIX) or Python 2.4.1 (Windows). If you still need help, we need to know precisely what you're doing. ===== scope_test.py ===== #!/usr/bin/env python # # (insert his code, verbatim...) # if __name__=='__main__': outer(3) ===== end scope_test.py ===== [rjhansen at serv16 ~]$ ./scope_test.py 3 2 1 0 [rjhansen at serv16 ~]$ python Python 2.3.4 (#1, Feb 2 2005, 11:44:13) [GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from scope_test import outer >>> outer(3) 3 2 1 0 From exogen at gmail.com Mon Aug 1 21:35:23 2005 From: exogen at gmail.com (Brian Beck) Date: Mon, 01 Aug 2005 21:35:23 -0400 Subject: Application Error (referenced error) In-Reply-To: References: Message-ID: David Blomstrom wrote: > This is my first post on this list, and I'm new to > Python. Oh, and I forgot to mention: welcome to Python and our community! -- Brian Beck Adventurer of the First Order From googlenews at tooper.org Mon Aug 29 12:38:07 2005 From: googlenews at tooper.org (tooper) Date: 29 Aug 2005 09:38:07 -0700 Subject: python xml DOM? pulldom? SAX? In-Reply-To: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> References: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> Message-ID: <1125333487.725839.79300@g49g2000cwa.googlegroups.com> Hi, I'd advocate for using SAX, as DOM related methods implies loading the complete XML content in memory whereas SAX grab things on the fly. SAX method should therefore be faster and less memory consuming... By the way, if your goal is to just "combine the text out of page:title and page:revision:text for every single page element", maybe you should also consider an XSLT filter. Regards, Thierry From nochiel at gmail.com Mon Aug 1 05:17:22 2005 From: nochiel at gmail.com (yoda) Date: 1 Aug 2005 02:17:22 -0700 Subject: Standard Threads vs Weightless Threads Message-ID: <1122887842.555209.208860@o13g2000cwo.googlegroups.com> Recently I read Charming Python: Implementing Weightless Threads (http://www-128.ibm.com/developerworks/linux/library/l-pythrd.html) by David D. I'm not an authority on threading architectures so I'd like to ask the following: 1)What is the difference (in terms of performance, scalability,[insert relevant metric here]) between microthreads and "system" threads? 2)If microthreads really are superior then why aren't they the standard Python implementation (or at least within the standard library)? (where my assumption is that they are not the standard implementation and are not contained within the standard library). ps. I fear that my questions and assumptions about threading may be rather naive. If they are, it's because I haven't yet done any significant research. From yendor at arcticmail.com Tue Aug 16 18:09:26 2005 From: yendor at arcticmail.com (Ert Ert) Date: Tue, 16 Aug 2005 17:09:26 -0500 Subject: Help! Message-ID: <20050816220927.A0C7B16415C@ws1-4.us4.outblaze.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: -------------- next part -------------- An HTML attachment was scrubbed... URL: From pwatson at redlinepy.com Sun Aug 14 23:39:55 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Sun, 14 Aug 2005 22:39:55 -0500 Subject: Spaces and tabs again In-Reply-To: <43000838@news.eftel.com> References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> <6spsf1hr7i0ho9fa0ptauhst1s61jkig13@4ax.com> <43000262.7050209@redlinepy.com> <43000838@news.eftel.com> Message-ID: <43000E8B.4030603@redlinepy.com> John Machin wrote: > Paul Watson wrote: > >> Dan Sommers wrote: >> >>> On Sun, 14 Aug 2005 01:04:04 GMT, >>> Dennis Lee Bieber wrote: >>> >>> >>>> On 13 Aug 2005 13:18:21 -0700, sigzero at gmail.com declaimed the >>>> following >>>> in comp.lang.python: >>> >>> >>> >>> >>>>> Are you kidding? You are going to MANDATE spaces? >>>>> >>>> >>>> After the backlash, Python 4.0 will ban leading spaces and require >>>> tabs >>> >>> >>> >>> >>> Why not petition the unicode people to include PYTHON INDENT and PYTHON >>> DEDENT code points, and leave the display up to the text editors? ;-) >>> >>> Regards, >>> Dan >> >> >> >> The Unicode people will correctly point out that there is already a >> Unicode codepoint assignment which can be used for this purpose. It >> is even in the BMP portion of the C0 controls group. >> >> 0009 = HORIZONTAL TABULATION > > > and how do you use this to get the DEDENT effect? Use something out of > the bidirectional kit? E.g. RLO then tab then PDF ;-) The use of one less HORIZONTAL TABULATION on a line in relation to the number of HORIZONTAL TABULATION codepoints used by the pervious line indicated "dedent" as you call it. :-) There are things about your suggestion that would be great! It would require a language aware editing tool to be used. Like HTML was intended, the rendering of the program source would be managed by the tool. Everyone could choose the style in which they would like to interact with the code. This is also the biggest problem. It would mean that a specialized editor tool would be required. One could not just use a POTE (Plain Old Text Editor). Using U+0009 HORIZONTAL TABULATION would provide both user selectable rendering style as well as access through most existing tools. Of course, there is always 'expand' and 'unexpand' if you are really desparate. From gh at ghaering.de Fri Aug 26 05:09:54 2005 From: gh at ghaering.de (Gerhard Haering) Date: Fri, 26 Aug 2005 11:09:54 +0200 Subject: Setting the encoding in pysqlite2 In-Reply-To: <1124957755.392563.197910@z14g2000cwz.googlegroups.com> References: <1124957755.392563.197910@z14g2000cwz.googlegroups.com> Message-ID: <20050826090954.GA22741@thea.w-koerting.de> On Thu, Aug 25, 2005 at 01:15:55AM -0700, Michele Simionato wrote: > An easy question, but I don't find the answer in the docs :-( > I have a sqlite3 database containing accented characters (latin-1). > How do I set the right encoding? For instance if I do this: [...] You cannot set the encoding directly, because TEXT data in SQLite3 databases is expected to be in UTF-8 encoding. If you store "weird" TEXT, you can work around it by using a custom converter in pysqlite2, like in the following example: #-*- encoding: latin-1 -*- from pysqlite2 import dbapi2 as sqlite # Register an additional converter for plain bytestrings sqlite.register_converter("bytestring", str) con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) cur = con.cursor() cur.execute("create table test(t)") testdata = "H?ring" # bytestring in ISO-8859-1 encoding cur.execute("insert into test(t) values (?)", (testdata,)) # Try to retrieve the test data, will fail try: cur.execute("select t from test") except UnicodeDecodeError: print "Could not decode latin1 as utf-8 (as expected)" # Via the PARSE_COLNAMES trick, explicitly choose the bytestring converter # instead of the default unicode one: cur.execute('select t as "t [bytestring]" from test') result = cur.fetchone()[0] assert testdata == result print "Correctly retrieved test data" HTH, -- Gerhard From CantankerousOldGit at gmail.com Mon Aug 8 15:54:46 2005 From: CantankerousOldGit at gmail.com (Cantankerous Old Git) Date: Mon, 08 Aug 2005 20:54:46 +0100 Subject: Making a timebomb In-Reply-To: References: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> Message-ID: Peter Hansen wrote: > Cantankerous Old Git wrote: > >> Peter Hansen wrote: >> >>> Cantankerous Old Git wrote: >>> >>>> The dirty way, which can leave corrupt half-written files and other >>>> nasties, is something like sys.exit(). >>> >>> >>> sys.exit() won't help you if your server is running in the main >>> thread, nor if your server thread is not marked as a daemon, but that >>> does raise another possibility. >> >> >> I assume you know that I actually meant System.exit(). Why do you >> think that won't help? > > > No, I didn't know that, but if you were confused the first time, I think > you're getting even more confused now. What is System.exit()? I don't > have one, and have never seen it mentioned. Perhaps you meant > SystemExit, the exception that's raised when you call sys.exit()? If > so, I still don't see your point, because there's no difference between > the two in this context. > > Maybe you meant os._exit()? Now *that* one is messy, and will work as > you described. > > -Peter Yup - I guess you're not interested in java.lang.System.exit() at all, are you. You're right about me getting confused! Perhaps I should take a break between reading the two newsgroups. Doh! sys.exit() docs (for Python) say it raises a SystemExit exception. A quick test shows that: * You can catch this to prevent being killed * It only gets raised on the calling thread - not the others So you're right - sys.exit is not very helpful in this case. os._exit is the one I was thinking of - equivalent to java's System.exit(). And to the OP, Bill - sorry for messing you around. As you see - I got confused. From francois.perche at gmail.com Tue Aug 16 05:30:03 2005 From: francois.perche at gmail.com (perchef) Date: 16 Aug 2005 02:30:03 -0700 Subject: get a list of mounted filesystems under MacOSX In-Reply-To: References: <4300bd95$0$11586$636a15ce@news.free.fr> Message-ID: <1124184603.470460.123090@g43g2000cwa.googlegroups.com> maybe you can catch the result of /bin/df and parse it. From jaumedominguez at airtel.net Tue Aug 23 13:42:55 2005 From: jaumedominguez at airtel.net (jau) Date: Tue, 23 Aug 2005 19:42:55 +0200 Subject: DeprecationWarning: Non-ASCII character '\xf3' Message-ID: Hi co-listers! I have been off Python for 2 years and now, that i'm used to Eclipse and Java, I decided to start a project with Python to refresh skills this time using Eclipse and TrueStudio. But now, two things can be occured since the last time i used it. the first one, something concerning to the encoding has changed and i haven't noticed it. the other one, when using Python from Eclipse i have to add any special config lines at the begining of my Python files. if i have this hello world python "program" (i have to call it by someway, hahaha) print "hello world" i get this output hello world sys:1: DeprecationWarning: Non-ASCII character '\xf3' in file C:\Workspace\J&J\src\es\jau\main.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details the article mentioned above didn't explain so much for me. i doesn't look to be an error, but curiosity is bitting me... what's really happening here? Do I need to do any special thing to avoid this? Thanks everyone! Salut i rep?blica From sjmaster at gmail.com Thu Aug 11 23:46:13 2005 From: sjmaster at gmail.com (Steve M) Date: 11 Aug 2005 20:46:13 -0700 Subject: Psyco & Linux In-Reply-To: <2EUKe.193369$5V4.19467@pd7tw3no> References: <2EUKe.193369$5V4.19467@pd7tw3no> Message-ID: <1123818373.058442.138240@g49g2000cwa.googlegroups.com> > First, I tried the usual "python setup.py install" but that did not work. How exactly did it fail? Perhaps you can paste the error output from this command. From dek at scooby.lbl.gov Thu Aug 11 11:56:30 2005 From: dek at scooby.lbl.gov (David E. Konerding DSD staff) Date: Thu, 11 Aug 2005 15:56:30 +0000 (UTC) Subject: wxPython and threads again References: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> Message-ID: On 2005-08-10, Bryan Olson wrote: > > The easiest approach, though, is to use the threadedselectreactor in > Twisted (you need > > to check the HEAD branch out with subversion, because that reactor > isn't included in any releases). > > With threadedselectreactor, it's easy to incorporate both the GUI > event loop and the twisted reactor. > > Twisted already includes lots of code for doing asynchronous > callback-style IO for > > IO bound processes like downloading. Further, you don't even think > in an explicitly threaded way- > > createing a whole thread just to manage a download process which is > motly IO and a little bookkeeping is > > silly. Twisted's approach just makes a lot more sense and simplifies > the code too. > > I couldn't disagree more about that being easier and simplifying > the code. "Creating a whole thread" is trivial. > > I've done both styles. Actually, I greatly prefer the single threaded approach now; conceptually, the threaded approach is very simple, but your program ends up getting complex because the data-passing infrastructure. And you end up structuring your logic in somewhat more convoluted ways. And most people have such a hard time dealing with data synch between threads... Dave From rkern at ucsd.edu Wed Aug 31 17:08:43 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 31 Aug 2005 14:08:43 -0700 Subject: Calling ftp commands from python In-Reply-To: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> References: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> Message-ID: Thierry Lam wrote: > Is it possible to run an ftp command to connect to some remote computer > on the network. If the remote computer is running an ftp server, yes. If not, no. > For example, if I want to retrieve some data from > \\remcomputer\datafiles on the network and copy it to my local > computer, how do I do it in python on the Unix side? > > I don't want to use mount since I don't have permission. http://miketeo.net/projects/pysmb/ -- 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 deets at web.de Thu Aug 4 14:56:03 2005 From: deets at web.de (Diez B.Roggisch) Date: Thu, 4 Aug 2005 18:56:03 +0000 (UTC) Subject: substring and regular expression References: <1123140231.118099.4890@g43g2000cwa.googlegroups.com> <42f21930$1_2@newspeer2.tds.net> <1123166163.109766.297420@g43g2000cwa.googlegroups.com> Message-ID: borges2003xx yahoo.it yahoo.it> writes: > > but in general is there a way to include in a re, in this example > something like...matches iff p , and q in which p==q[::-1] ? A way to > putting a small part of code of python in re? Thanx for your many helps What you are after is a parser - there are plenty available. I prefer spark, but pyparsing has gained lots of attention lately and is AFAIK the quasi-standard. The problem you described is a classical instance of a so-called context-free grammar. There is absolutely _no_ way to teach regular expressions how to detect words created based on a grammar of that kind. Really. It won't work. So - either use a parser, or write a simple one yourself - the code above qualifies as an attempt to do so. Regards, Diez From steve at holdenweb.com Sun Aug 21 18:20:58 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Aug 2005 23:20:58 +0100 Subject: Related To Threads In-Reply-To: <1124602823.281311.32710@g44g2000cwa.googlegroups.com> References: <1124602823.281311.32710@g44g2000cwa.googlegroups.com> Message-ID: Sidd wrote: > Hello, > I want to write a thread in python which can be invoked for say 5 > sec, within that the threads function would be to take input,is it > possible because i tried it and found that raw_input() is blocking > threads. > There isn't really a convenient solution to this problem, since a thread can't easily be stopped "from the outside". Various solutions you might dream up using signals are likely to be either unreliable or non-portable or possibly both. You m ay have to poll the keyboard directly to gather input and time out if it doesn't arrive. http://www.python.org/doc/faq/windows.html#how-do-i-check-for-a-keypress-without-blocking will be some help in the windows environment, select() is your friend under *nix. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From paolo_veronelli at tiscali.it Wed Aug 10 10:51:55 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Wed, 10 Aug 2005 16:51:55 +0200 Subject: help in algorithm Message-ID: <42FA148B.4040303@tiscali.it> I have a self organizing net which aim is clustering words. Let's think the clustering is about their 2-grams set. Words then are instances of this class. class clusterable(str): def __abs__(self):# the set of q-grams (to be calculated only once) return set([(self+self[0])[n:n+2] for n in range(len(self))]) def __sub__(self,other): # the q-grams distance between 2 words set1=abs(self) set2=abs(other) return len(set1|set2)-len(set1&set2) I'm looking for the medium of a set of words, as the word which minimizes the sum of the distances from those words. Aka:sum([medium-word for word in words]) Thanks for ideas, Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From twic at urchin.earth.li Tue Aug 16 07:42:23 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Tue, 16 Aug 2005 12:42:23 +0100 Subject: __del__ pattern? In-Reply-To: References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: On Mon, 15 Aug 2005, Peter Hansen wrote: > Tom Anderson wrote: > >> Only one socket can be bound to a given port at any time, so the second >> instance of SpecialClass will get an exception from the bind call, and >> will be stillborn. This is a bit of a crufty hack, though - you end up >> with an open port on your machine for no good reason. If > > If you bind with self.sock.bind(('localhost', 4242)) instead, at least > you don't have much of a security risk since the port won't be available > for connections from outside the same machine. Excellent suggestion, thanks! > Using '' instead of 'localhost' means bind to *all* interfaces, not just > the loopback one. Doesn't '' mean 'bind to the *default* interface'? tom -- All we need now is a little energon and a lotta luck From donn at u.washington.edu Fri Aug 19 13:04:02 2005 From: donn at u.washington.edu (Donn Cave) Date: Fri, 19 Aug 2005 10:04:02 -0700 Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: In article , Antoon Pardon wrote: ... > But '', {}, [] and () are not nothing. They are empty containers. Oh come on, "empty" is all about nothing. > And 0 is not nothing either it is a number. Suppose I have > a variable that is either None if I'm not registered and a > registration number if I am. In this case 0 should be treated > as any other number. > > Such possibilities, make me shy away from just using 'nothing' > as false and writing out my conditionals more explicitly. Sure, if your function's type is "None | int", then certainly you must explicitly check for None. That is not the case with fileobject read(), nor with many functions in Python that reasonably and ideally return a value of a type that may meaningfully test false. In this case, comparison (==) with the false value ('') is silly. Donn Cave, donn at u.washington.edu From krzychu at bmpg.pl Fri Aug 12 09:44:39 2005 From: krzychu at bmpg.pl (krzychu at bmpg.pl) Date: 12 Aug 2005 06:44:39 -0700 Subject: Zope, Python 2.4 pythonScripts import problem Message-ID: <1123854279.041291.39000@g44g2000cwa.googlegroups.com> Hi, I have installed brand new platform - Zope-2-7-6, Python 2.4.1, Plone 2.0.5, OS Debian 1:3.3.6-2. After import a old Plone site from the following platform Zope-2-7-4, Python 2.3.3, Plone 2.0.3 to the new one, I get error when I visit PuthonScript in the ZMI. "invalid syntax (Script (Python), line 1)" There 2 are examples of 1 line: from DateTime import DateTime and request = container.REQUEST There is no syntax error! When I just save this script in ZMI then error disappers :) What is the reason??? KK p.s I have the same problem when I import to the same platform but with Python 2.4.0 From roland at catalogix.se Tue Aug 23 06:01:39 2005 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 23 Aug 2005 12:01:39 +0200 Subject: Network performance In-Reply-To: References: Message-ID: 23 aug 2005 kl. 10.14 skrev Michael Sparks: > Roland Hedberg wrote: > >> I was surprised to find that the performance was equal to what >> Twisted/XMLRPC did. Around 200 ms per set, not significantly less. >> > > That should tell you two things: > * Twisted/XMLRPC is as efficient as you can hand craft. (which is a > good use reason for using it). I already gathered that much :-) > * That what you're measuring is overhead - and most likely of > setup. Not necessarily! If the number of client - server queries/responses are large enough the effect of the setup time should be negligible. Or making testes with different numbers of queries you should be able to deduce the setup time. > I'd measure the ping time between your two hosts. > > If your ping time is significantly lower - eg you're running on > localhost - I'd suggest you translate your code to C (and/or post > your code), I did the tests on localhost! And I did post the code! So, I made another test. I used a server I have already written in C and which I know quite well how fast it is. Using a python client I've written that talks to this server, it takes 0.8 s for the python client to start, connect and send 1000 queries. A C client is a bit faster but not a lot. This is more in the order of what I'd like to have. Hmm, not surprising this makes me suspect my python server implementation :-/ -- Roland From kowald at molgen.mpg.de Sat Aug 13 14:10:53 2005 From: kowald at molgen.mpg.de (kowald at molgen.mpg.de) Date: 13 Aug 2005 11:10:53 -0700 Subject: COM access sooo slow !? Message-ID: <1123956653.745700.220980@g49g2000cwa.googlegroups.com> Hi everybody, I'm using win32com.client.Dispatch() to access a COM object (a database) from Python and in principle is works fine. However, it is unbelievably slow :-( It is 70 times slower than a C++ version of the same program ! Is this a well known problem of the Python COM interface or could it be specific to this special COM object? Any ideas? Many thanks, Axel From http Sun Aug 7 04:52:38 2005 From: http (Paul Rubin) Date: 07 Aug 2005 01:52:38 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> Message-ID: <7xmznuxh61.fsf@ruckus.brouhaha.com> Robert Kern writes: > No it's not wrong to want these things. The problem is that we're not > lacking in people posting this *same exact complaint* every month or > so. We *are* lacking in people implementing these things. Eh? Nah, we keep getting lame excuses on why those things aren't needed and users should just supply tenacity and expect to suffer and they should stop being wimps, and having to locate, download, and figure out how to use a dozen packages from all over the internet really isn't more hassle than a one-click install with unified documentation for everything. > If you want to see these nice accoutrements, *stop posting here and > get to work*! Eh again--says who? You? Most of those functions for Python are already floating around the net. It's simply a matter in many cases of deciding to include them in the distro. The problem is an attitude that making things too easy for users is un-Pythonic. If you think it's just a matter of writing code, you're not on the side you think you're on. From jmeile at hotmail.com Sat Aug 13 18:59:20 2005 From: jmeile at hotmail.com (Josef Meile) Date: Sun, 14 Aug 2005 00:59:20 +0200 Subject: Zope, Python 2.4 pythonScripts import problem In-Reply-To: <1123854279.041291.39000@g44g2000cwa.googlegroups.com> References: <1123854279.041291.39000@g44g2000cwa.googlegroups.com> Message-ID: <42FE7B48.9020409@hotmail.com> Hi, > I have installed brand new platform - Zope-2-7-6, Python 2.4.1, Plone > 2.0.5, OS Debian 1:3.3.6-2. You may then ask in a zope or plone list. This is a python specific list. But I will answer you any way. > After import a old Plone site from the following platform > Zope-2-7-4, Python 2.3.3, Plone 2.0.3 to the new one, I get error when > I visit PuthonScript in the ZMI. > "invalid syntax (Script (Python), line 1)" > > There 2 are examples of 1 line: > from DateTime import DateTime > and > request = container.REQUEST > > There is no syntax error! > > When I just save this script in ZMI then error disappers :) So, you are exporting the plone site, then importing it? I had once some problem like that and the solution was to call an script that compiled all python scripts again. I'm not sure if this solves your problem, but you may look at the first script here: http://www.zope.org/Members/goppelt/2-4-3Upgrade > What is the reason??? As I said, you may ask in a zope or plone list for a better answer. My best guess is that somewhere there is some old compiled version of your script. > p.s I have the same problem when I import to the same platform but with > Python 2.4.0 I just have to warn you that some persons in the zope list are going to tell you "Python 2.4 isn't a supported option for zope". So, you may use it only for testing and not in a production environment. Regards, Josef From cito at online.de Tue Aug 2 15:11:52 2005 From: cito at online.de (Christoph Zwerschke) Date: Tue, 02 Aug 2005 21:11:52 +0200 Subject: Art of Unit Testing In-Reply-To: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> Message-ID: Thanks for the link, Grig. I wasn't aware of the py lib so far. The possibility to create fixtures at the three different scopes is exactly what I was looking for. Anyway, I think it would be nice to have that feature in the standard lib unittest as well. It should not be too hard to add setUpOnce and tearDownOnce methods in addition to setUp and tearDown. Actually, I am wondering that there doesn't seem to be any development progress since unittest was included in the standard lib of Python 2.1 in August 2001. I had expected that such an important module would be continually improved and maintained. How come? So few people using unit tests? Or do most people write their own testing code or use py.test? -- Christoph From percivall at gmail.com Sun Aug 28 12:17:33 2005 From: percivall at gmail.com (Simon Percivall) Date: 28 Aug 2005 09:17:33 -0700 Subject: Release of PyPy 0.7.0 In-Reply-To: References: Message-ID: <1125245853.581340.203660@z14g2000cwz.googlegroups.com> That's great! Congratulations! From fabioz at esss.com.br Thu Aug 4 06:58:47 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Thu, 04 Aug 2005 07:58:47 -0300 Subject: pyunit and Eclipse In-Reply-To: <3d03f1pqvhggm0lafpglc9bom33dfm8cc5@4ax.com> References: <3d03f1pqvhggm0lafpglc9bom33dfm8cc5@4ax.com> Message-ID: <42F1F4E7.9010906@esss.com.br> Steve Jorgensen wrote: >I was working with a friend on a project Monday night, and tried to run a >pyunit test from Eclipse, and nothing seemed to happen. We finally figured >out that the test is doing exactly what it's supposed to do, but the pyunit >output isn't making it to the Eclipse console window. We get the same result >if I run the module as a pyunit test using Eclipse, or if we simply have the >program call unittest.main, and run that. > >As a workaround, we just ran the tests from a command prompt which worked well >enough, but it would be nice to fix the problem. > > Which pydev version? How did you do the run? Guessing those... Just a single file, yes, it would be just unittest.main()... Anyway, there is an issue in Eclipse (happens in java too) that is the following: if you do a run and it is too fast, sometimes the output does not show (usually if you re-run it --Ctrl+F11 -- , it works, but not always). If you are running the unit-test for a folder, you don't need the unittest.main(), as it should auto-import the test-cases in the files below the folder (recursively) and run them. Cheers, Fabio -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From florent.newsgroups at kynesthesy.org Wed Aug 3 11:43:09 2005 From: florent.newsgroups at kynesthesy.org (florent) Date: Wed, 03 Aug 2005 17:43:09 +0200 Subject: trying to parse non valid html documents with HTMLParser In-Reply-To: References: <42efc9ae$0$12924$636a15ce@news.free.fr> Message-ID: <42f0e5d0$0$20055$636a15ce@news.free.fr> > AFAIK not with HTMLParser or htmllib. You might try (if you haven't done > yet) htmllib and see, which parser is more forgiving. You were right, the HTMLParser of htmllib is more permissive. He just ignores the bad tags ! From billiejoex at fastwebnet.it Fri Aug 26 09:47:16 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Fri, 26 Aug 2005 15:47:16 +0200 Subject: Integrate C source in a Python project References: <1125063243.748286.117800@g47g2000cwa.googlegroups.com> Message-ID: Than you James. I'll take a look as soon as possible. It is possible do the contrary (integrates python source in a C project)? "James" ha scritto nel messaggio news:1125063243.748286.117800 at g47g2000cwa.googlegroups.com... > billiejoex wrote: >> Hi all. >> I was wondering if it ispossible to integrate C source in a python >> project. > > There is ofcourse Python/C API > http://docs.python.org/api/api.html > > But you will probably be easier off with Pyrex or Swig. > > Good summary on when to use which > http://www.rexx.com/~dkuhlman/python_201/python_201.html#SECTION006500000000000000000 > > James > From rrr at ronadam.com Wed Aug 31 10:16:28 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 31 Aug 2005 14:16:28 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> <43156165.219034725@news.oz.net> Message-ID: <0ZiRe.67733$Oy2.39610@tornado.tampabay.rr.com> Antoon Pardon wrote: > Op 2005-08-31, Bengt Richter schreef : > >>On 31 Aug 2005 07:26:48 GMT, Antoon Pardon wrote: >> >> >>>Op 2005-08-30, Bengt Richter schreef : >>> >>>>On 30 Aug 2005 10:07:06 GMT, Antoon Pardon wrote: >>>> >>>> >>>>>Op 2005-08-30, Terry Reedy schreef : >>>>> >>>>>>"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message >>>>>>news:7xy86k3r7n.fsf at ruckus.brouhaha.com... >>>>>> >>>>>> >>>>>>>Really it's x[-1]'s behavior that should go, not find/rfind. >>>>>> >>>>>>I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely >>>>>>useful, especially when 'x' is an expression instead of a name. >>>>> >>>>>I don't think the ability to easily index sequences from the right is >>>>>in dispute. Just the fact that negative numbers on their own provide >>>>>this functionality. >>>>> >>>>>Because I sometimes find it usefull to have a sequence start and >>>>>end at arbitrary indexes, I have written a table class. So I >>>>>can have a table that is indexed from e.g. -4 to +6. So how am >>>>>I supposed to easily get at that last value? >>>> >>>>Give it a handy property? E.g., >>>> >>>> table.as_python_list[-1] >>> >>>Your missing the point, I probably didn't make it clear. >>> >>>It is not about the possibilty of doing such a thing. It is >>>about python providing a frame for such things that work >>>in general without the need of extra properties in 'special' >>>cases. >>> >> >>How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ? >>That would give a consitent interpretation of seq[-1] and no errors >>for any value ;-) > > > But the question was not about having a consistent interpretation for > -1, but about an easy way to get the last value. > > But I like your idea. I just think there should be two differnt ways > to index. maybe use braces in one case. > > seq{i} would be pure indexing, that throws exceptions if you > are out of bound > > seq[i] would then be seq{i%len(seq)} The problem with negative index's are that positive index's are zero based, but negative index's are 1 based. Which leads to a non symmetrical situations. Note that you can insert an item before the first item using slices. But not after the last item without using len(list) or some value larger than len(list). >>> a = list('abcde') >>> a[len(a):len(a)] = ['end'] >>> a ['a', 'b', 'c', 'd', 'e', 'end'] >>> a[-1:-1] = ['last'] >>> a ['a', 'b', 'c', 'd', 'e', 'last', 'end'] # Second to last. >>> a[100:100] = ['final'] >>> a ['a', 'b', 'c', 'd', 'e', 'last', 'end', 'final'] Cheers, Ron From spam.csubich+block at block.subich.spam.com Mon Aug 1 09:46:16 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Mon, 01 Aug 2005 09:46:16 -0400 Subject: Standard Threads vs Weightless Threads In-Reply-To: <1122887842.555209.208860@o13g2000cwo.googlegroups.com> References: <1122887842.555209.208860@o13g2000cwo.googlegroups.com> Message-ID: yoda wrote: > 1)What is the difference (in terms of performance, scalability,[insert > relevant metric here]) between microthreads and "system" threads? System-level threads are relatively heavyweight. They come with a full call stack, and they take up some level of kernel resources [generally less than a process]. In exchange, they're scheduled by the OS, with the primary benefit (on uniprocessor systems) that if one thread executes a blocking task (like IO writes) another thread will receive CPU attention. The primary disadvantage is that they're scheduled by the CPU. This leads to the concurrency nightmare, where the developer needs to keep track of what blocks of code (and data) need locks to prevent deadlock and race conditions. > > 2)If microthreads really are superior then why aren't they the standard > Python implementation (or at least within the standard library)? (where > my assumption is that they are not the standard implementation and are > not contained within the standard library). Microthreads are very different; they're entirely internal to the Python process, and they're not seen at all by the operating system. Scheduling is done explicitly by the microthread implementation -- multitasking is not preemptive, as with system threads. They're not in the standard library because implementing microthreads has thus far required a very large rewrite of the CPython architecture -- see Stackless Python. From mynews44 at yahoo.com Thu Aug 18 13:32:38 2005 From: mynews44 at yahoo.com (googleboy) Date: 18 Aug 2005 10:32:38 -0700 Subject: Confused newbie needs help with "__init__() takes exactly 11 arguments (1 given)" Message-ID: <1124386358.398762.313260@g14g2000cwa.googlegroups.com> Mostly I posted to try to find out more about the arguments being passed to __init__, and why they'd be 13 one second and 1 the next. I also was hoping to get a little more background on what is happening under the hood of the csv function I've plagiarised. I haev read the online python doco on it, but I am not really entirely sure in my own head how it is breaking down that csv entry. I am actually quite familiar with handling strings and lists in python, though less so with dictionaries. I did like your trick with telling splut to stop after 9 times. I hadn't seen that before. Thanks for the response. :-) Googleboy From u.hobelmann at web.de Mon Aug 22 19:10:58 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Tue, 23 Aug 2005 01:10:58 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: <3mv4c2F18so93U1@individual.net> Keith Thompson wrote: > "Xah Lee" writes: > [the usual] At least he noticed that tar sucks. There's nothing better than tarring your backup back to disk, only to notice that the pathnames were "too long." Great! -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From u.hobelmann at web.de Fri Aug 26 07:40:34 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Fri, 26 Aug 2005 13:40:34 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> Message-ID: <3n8ddiFbhg7U1@individual.net> John Bokma wrote: > usenet at isbd.co.uk wrote: > >> In comp.lang.perl.misc John Bokma wrote: > > [ web based boards ] > >>> And which useful tools do you require? >>> >> A choice of news readers to suit different people with different >> interfaces, > > - different browsers, different stylesheets, different board styles > (themes). But the UI is still *forced* on you by the website; no choice. There's only a very limited choice, and it invariably *includes* the UI. With NNTP *you* choose how to interpret and display the data you get. > http://www.phpbb.com/mods/ Great. How can I, the user, choose, how to use a mod on a given web server? What if the web server runs another board than PHPBB? >> A forum provides a >> single, usually rather limited, interface for the user with no way for >> the user to change it radically. > > Does the user want this? And with a user stylesheet you can change it > quite radically :-) The look, not the feel. > And in return the user gets: colors, fonts, font sizes, embedding of > images, flash, you name it. Moving avatars, even sounds. As I wrote earlier, you *could* run a web forum over NNTP, and use HTML posts instead of plain text. It would have the advantages of NNTP. > Oh, yes, I would love to see an XML interface on the board I use. Maybe > I can just install a mod, or write one myself. What would that XML be for? Any particular *use*? -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From u.hobelmann at web.de Thu Aug 25 15:40:33 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Thu, 25 Aug 2005 21:40:33 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <3n6kkjF4qppU1@individual.net> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: <3n6l5jF4t1cU1@individual.net> usenet at isbd.co.uk wrote: > In comp.lang.perl.misc John Bokma wrote: >>> the argument that usenet should never change seems a little >>> heavy-handed and anachronistic. >> No, simple since there *are* alternatives: web based message boards. Those >> alternatives *do* support HTML formatting (often the subset mentioned > > ... and generally these "web based message boards" (i.e. forums I > assume you mean) have none of the useful tools that Usenet offers and > are much, much slower. That is because NNTP and its applications didn't evolve to feed the glitzy need lots of users have. Sadly web forums (esp. the ugly, sloooow PHPBB, and the unspeakable Google groups) are increasingly replacing usenet, but there are exceptions (DragonflyBSD). On the information side (in contrast to the discussion side) RSS is replacing Usenet, with some obvious disadvantages: go on vacation, return after a week, and -- yahoo! -- all your RSS feeds only turn of the, say, most recent 30 articles, while your newsgroups all show everything you missed. There is no real reason why NNTP couldn't be used like RSS (i.e. contain a small description and a web link as message text), or why a newsgroup shouldn't we written in HTML and contain a (default, or user-provided) CSS sheet. If things were that way, suddenly people *would* use Outlook and Thunderbird for news-reading, while today everything is just Browser+HTTP. Oh, yes: -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From mwh at python.net Wed Aug 17 12:23:38 2005 From: mwh at python.net (Michael Hudson) Date: Wed, 17 Aug 2005 16:23:38 GMT Subject: Urgent: Embedding Python problems - advice sought References: <1124236492.970194.270970@g47g2000cwa.googlegroups.com> Message-ID: adsheehan at eircom.net writes: > Hi, > > > I am embedding Python into a multi-threaded C++ application running on > Solaris and need urgent clarification on the embedding architecture and > its correct usage (as I am experience weird behaviors). What version of Python are you using? > Can anyone clarify: > > > - if Python correctly supports multiple sub-interpreters > (Py_NewInterpreter) ? It's supposed to but it's not often used or tested and can get a bit flaky. > - if Python correctly supports multiple thread states per > sub-interpreter (PyThreadState_New) ? There are bugs in 2.3.5 and 2.4.1 in this area (they are fixed in CVS -- I hope -- and will be in 2.4.2). > and the "real" question: > > > - what is the rationale for choosing one of: > > > [a] one sub-interpreter with many thread states This is the best tested and understood (it's what the core Python interpreter does, after all). > [b] many sub-interpreters with one thread state each > [c] many sub-interpreters with many threas states each These are probably somewhat broken in recent Python's, I'm afraid. Can you try CVS? Cheers, mwh -- ARTHUR: Yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying "Beware of the Leopard". -- The Hitch-Hikers Guide to the Galaxy, Episode 1 From jeffrey.schwab at rcn.com Sun Aug 21 16:20:41 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sun, 21 Aug 2005 16:20:41 -0400 Subject: Binary Trees in Python In-Reply-To: References: Message-ID: Jorgen Grahn wrote: > On Sat, 20 Aug 2005 15:19:55 -0400, Roy Smith wrote: > >>In article , >> [diegueus9] Diego Andr?s Sanabria wrote: >> >> >>>Hello!!! >>> >>>I want know if python have binary trees and more? >> >>Python does not come with a tree data structure. The basic data structures >>in Python are lists, tuples, and dicts (hash tables). >> >>People who are used to C++'s STL often feel short-changed because there's >>not 47 other flavors of container, but it turns out that the three Python >>gives you are pretty useful. Many people never find a need to look beyond >>them. > > > Uh, the STL has seven flavors: > - vector > - deque > - list > - set > - map > - multimap > - multiset There are others, e.g. std::valarray. There are also adapters that use the above templates to implement other structures, adding or limiting functionality as appropriate; e.g., std::heap and std::stack. > so that's not too bad for a static language. Each of them > is vital for some purpose, but vector and map are by far the > most commonly used. > > Neither C++ nor Python has tree structures in their standard libraries. I > assume that's because there is no single interface that is proven to suit > everybody's needs. Hmmm... I guess I never noticed the lack. C++ has structures or language features that represent most of the common things trees are typically used to implement. Of course, a "tree" can be represented in so many ways, it's more of a design pattern than a data structure. :) From lbates at syscononline.com Fri Aug 19 10:58:22 2005 From: lbates at syscononline.com (Larry Bates) Date: Fri, 19 Aug 2005 09:58:22 -0500 Subject: Save Binary data. In-Reply-To: References: Message-ID: <4305F38E.7020905@syscononline.com> Images are binary data, don't do anything to them just save them to files on disk in their binary format. The extra processing of pickling them isn't going to help. Directories with large numbers of files was a problem in FAT16 and FAT32 filesystems but not really a problem in NTFS or Linux (at least that I've found). Appending 100-200 images together into a single file will surely cut down on the number of files. A lot depends on what the next step in the process is expecting (e.g. individual files or a a stream of data). If it is individual files, you will have to split them back apart anyway so keeping them as individual files is a benefit. Larry Bates GMane Python wrote: > Hello All. > I have a program that downloads 'gigabytes' of Axis NetCam photos per day. > Right now, I set up the process to put the images into a queue, and every 30 > or so seconds, 'pop' them from the queue and save them to disc. I save > them as individual files. > > I think that I'd like to modify it to save into one file 100-200 images, > so that I don't have directories with 50,000-90,000 frames before handing > that off to a DivX Encoder. > > I don't know if I need to use something like cPickle, or maybe just save > them as a binary data file (which would be a temp file until later in the > day when I open it to begin the encoding process.) > > Can someone please help me with some direction? > > > Thank you! > Dave > > > From maxm at mxm.dk Thu Aug 25 15:02:08 2005 From: maxm at mxm.dk (Max M) Date: Thu, 25 Aug 2005 21:02:08 +0200 Subject: Unix diff command under Window. In-Reply-To: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> References: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> Message-ID: <430e15ad$0$37083$edfadb0f@dread12.news.tele.dk> TonyHa wrote: > Hello, > > Does any one have using Python to write a Unix "diff" command for > Window? I generally just us the diff built into tortoiseSVN. That way it's only a rightclick away. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From beowulf40 at lycos.com Mon Aug 29 15:06:22 2005 From: beowulf40 at lycos.com (Beowulf TrollsHammer) Date: 29 Aug 2005 12:06:22 -0700 Subject: Exploring outlook contents In-Reply-To: <1125336375.499390.276520@g44g2000cwa.googlegroups.com> References: <1125336375.499390.276520@g44g2000cwa.googlegroups.com> Message-ID: <1125342382.482460.153670@o13g2000cwo.googlegroups.com> Subir wrote: > Hi, > > I am trying to build an application to explore the contents of an > outlook .pst files. All the reference that I have seen uses the > registry to do so. Does any one know any other way of doing this. Also, > is anyone has any code which does something related to this, please let > me know. > > -Subir Check this out: http://www.boddie.org.uk/python/COM.html HTH From steven.bethard at gmail.com Mon Aug 1 13:47:46 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 01 Aug 2005 11:47:46 -0600 Subject: Comparison of functions In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > You are confusing mathematical ordering with sorting a list. Here, I will > sort some mixed complex and real numbers for you. If you look at them > closely, you will even be able to work out the algorithm I used to sort > them. > > 1 > 1+0j > 1+7j > 2 > 2+3j > 3+3j > 3-3j > 3+4j > 4 > 4+2j It's clear which algorithm you used to sort these: py> lst = [3+3j, 3+4j, 1+7j, 2, 3-3j, 4, 4+2j, 1, 1+0j, 2+3j] py> def complex2tuple(c): ... c = complex(c) ... return c.real, c.imag ... py> for item in sorted(lst, key=complex2tuple): ... print item ... 1 (1+0j) (1+7j) 2 (2+3j) (3-3j) (3+3j) (3+4j) 4 (4+2j) What isn't clear is that this should be the default algorithm for sorting complex numbers. STeVe From t.deconinck at gmail.com Thu Aug 11 07:57:42 2005 From: t.deconinck at gmail.com (Tom Deco) Date: 11 Aug 2005 04:57:42 -0700 Subject: Regular expression to match a # References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> Message-ID: <1123761462.309338.228290@g44g2000cwa.googlegroups.com> Thanks, That did the trick... From torched_smurf at yahoo.com Thu Aug 18 20:10:15 2005 From: torched_smurf at yahoo.com (torched_smurf at yahoo.com) Date: 18 Aug 2005 17:10:15 -0700 Subject: Module Name Conflicts In-Reply-To: <1124408324.310617.198340@z14g2000cwz.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> <1124408324.310617.198340@z14g2000cwz.googlegroups.com> Message-ID: <1124410215.293331.188720@g47g2000cwa.googlegroups.com> ncf wrote: > Maybe what you're looking for is __import__()? > > >>> help(__import__) > Help on built-in function __import__ in module __builtin__: > > __import__(...) > __import__(name, globals, locals, fromlist) -> module > > Import a module. The globals are only used to determine the > context; > they are not modified. The locals are currently unused. The > fromlist > should be a list of names to emulate ``from name import ...'', or > an > empty list to emulate ``import name''. > When importing a module from a package, note that __import__('A.B', > ...) > returns package A when fromlist is empty, but its submodule B when > fromlist is not empty. Using this doesn't appear to work any better than regular old import. -Smurf From joe at invalid.address Thu Aug 25 13:59:49 2005 From: joe at invalid.address (joe at invalid.address) Date: 25 Aug 2005 12:59:49 -0500 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> Message-ID: "T Beck" writes: > Mike Schilling wrote: > > "Rich Teer" wrote in message > > news:Pine.SOL.4.58.0508250932360.5888 at zen.rite-group.com... > > > On Thu, 25 Aug 2005, Mike Schilling wrote: > > > > > >> Another advantage is that evewry internet-enabled computer > > >> today already comes with an HTML renderer (AKA browser), so > > >> that a message saved to a file can be read very easily. > > > > > > I think you're missing the point: email and Usenet are, > > > historically have been, and should always be, plain text > > > mediums. > > > > Gosh, if you say they should be, there's no point trying to have an > > intelligent discussion, is there? > > Not to mention that e-mail is practically to the point where it is > {not} a plain text medium. I notice this especially in a corporate > environment (where, at least where I work, I get at least 10 times the > number of e-mails at work than I do on my private account) HTML e-mail > is the de-facto standard. I have a tendancy to send out plain text > e-mail, and I'm practically the only one, as HTML formatting is the > default for the mail client on every corporate machine at my job. If you're using exchange for email servers it might be reformatting mail sent as plain text anyway. Waste of bandwidth. > But let's not forget that most people which send me e-mail personally > also have HTML tags in e-mail... So if e-mail {is} a plain text > medium, somebody needs to tell the general public, because I think they > must've missed a memo. > > If we argue that people are evolving the way e-mail is handled, and > adding entire new feature sets to something which has been around since > the earliest days of the internet, then that's perfectly feasable. > HTML itself has grown. We've also added Javascript and Shockwave. The > websites of today don't even resemble the websites of 10 years ago, > e-mail of today only remotely resembles the original, so the argument > that usenet should never change seems a little heavy-handed and > anachronistic. That's a good point, but just because things are evolving doesn't mean they're making more sense. Html does waste bandwidth, it does open up avenues for malware that text mail doesn't, etc. It seems to me that any intelligent person has to turn off so many "features" in html mail clients that they lose many of what are seen of as advantages. I suspect I either missed some of this thread or I'm misunderstanding some of it. If what the OP was trying to suggest was a more confined form of html, say, something that doesn't allow links, I'd consider that a good thing. I doubt anyone will use it though, I think MS wants all the bells and whistles, and all the embracing and extending it can do. If they don't support such an html subset for email I suspect it won't go anywhere. But why bother? An html subset that takes everything away but formatting sounds pretty much like what I'm doing right now with gnus. Joe From mensanator at aol.com Sun Aug 14 11:58:54 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 14 Aug 2005 08:58:54 -0700 Subject: Euclid's Algorithm in Python? References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> <1123461062.574511.278540@g43g2000cwa.googlegroups.com> <42f6aef7.870709213@news.oz.net> Message-ID: <1124035134.663245.35610@g14g2000cwa.googlegroups.com> Antoon Pardon wrote: > On 2005-08-08, Bengt Richter wrote: > > On 7 Aug 2005 17:31:02 -0700, "Jordan Rastrick" wrote: > > > >>Good point. I suppose I'd only ever seen it implemented with the if > >>test, but you're right, the plain while loop should work fine. Silly > >>me. > >> > >>def gcd(a,b): > >> while b != 0: > >> a, b = b, a%b > >> return a > >> > >>Even nicer. > >> > > what is the convention for handling signed arguments? E.g., > > As far as I understand the convention is it doesn't make > sense to talk about a gcd if not all numbers are positive. That may well be the convention but I don't know why you say it doesn't make sense. -3/3 still has a remainder of 0. So does -3/-3, but 3 is greater than -3 so it "makes sense" that the GCD will be positive. > > I would be very interested if someone knows what the gcd > of 3 and -3 should/would be. Someone has already decided what it should be. >>> from gmpy import * >>> help(gcd) Help on built-in function gcd: gcd(...) gcd(a,b): returns the greatest common denominator of numbers a and b (which must be mpz objects, or else get coerced to mpz) >>> gcd(3,-3) mpz(3) What would really be interesting is whether this conflicts with any other implementation of GCD. > > -- > Antoon Pardon From noreply at gcgroup.net Thu Aug 4 12:04:49 2005 From: noreply at gcgroup.net (William Gill) Date: Thu, 04 Aug 2005 16:04:49 GMT Subject: cut & paste text between tkinter widgets In-Reply-To: References: Message-ID: handy. Thanks, Bill jepler at unpythonic.net wrote: > Here's some code that gives a cut-copy-paste pop-up window on all Entry widgets > in an application. > > This code is released into the public domain. > > Jeff Epler > #------------------------------------------------------------------------ > import Tkinter > > def make_menu(w): > global the_menu > the_menu = Tkinter.Menu(w, tearoff=0) > the_menu.add_command(label="Cut") > the_menu.add_command(label="Copy") > the_menu.add_command(label="Paste") > > def show_menu(e): > w = e.widget > the_menu.entryconfigure("Cut", > command=lambda: w.event_generate("<>")) > the_menu.entryconfigure("Copy", > command=lambda: w.event_generate("<>")) > the_menu.entryconfigure("Paste", > command=lambda: w.event_generate("<>")) > the_menu.tk.call("tk_popup", the_menu, e.x_root, e.y_root) > > t = Tkinter.Tk() > make_menu(t) > > e1 = Tkinter.Entry(); e1.pack() > e2 = Tkinter.Entry(); e2.pack() > e1.bind_class("Entry", "", show_menu) > > t.mainloop() > #------------------------------------------------------------------------ From tim.golden at viacom-outdoor.co.uk Tue Aug 2 07:53:29 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue, 2 Aug 2005 12:53:29 +0100 Subject: ANN: Kamaelia 0.2.0 released! Message-ID: <9A28C052FF32734DACB0A288A3533991044D2178@vogbs009.gb.vo.local> [Michael Sparks] | Phil Hunt wrote: | | > Kamaelia seems it might be an interesting project. However, I don't | > think the project is well served by this announcement -- which I | > find vague and hard to understand. Which is a shame, because it | > means that other people probably don't understand it very well | > either, which means less people will use it. | | It is a shame, and thanks for mentioning this. Let me have another | go :-) (ripping to shreds welcome :) | | OK, here's a better go. (It's always difficult to think where to pitch | this sort of thing) [... snip ...] I just wanted to say that I find the ideas behind Kamaelia interesting, and I only wish I had an application for it! Because I'm not especially into media-streaming, I'm more interested in it from the point of view of the generator-based architecture. What prompted me to write now was in appreciation of Michael's taking the effort to recast his words into a form which might well be understood better by others (including me) when he might well have simply huffed a bit and told the other poster to read the words on the site and stop complaining about the HTML! Thanks, Michael. Hope the project continues apace and if I can ever find a need for it, I'll know where to look. Tim Golden ________________________________________________________________________ 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 roy at panix.com Tue Aug 9 23:12:45 2005 From: roy at panix.com (Roy Smith) Date: Tue, 09 Aug 2005 23:12:45 -0400 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > My current client uses subversion, and I generally wind up cursing at it > at least once a day. What makes you curse at it? I've never actually used it, just been watching the project for several years. I'd be interested to hear your experiences. From maxerickson at gmail.com Fri Aug 12 19:03:00 2005 From: maxerickson at gmail.com (Max Erickson) Date: Fri, 12 Aug 2005 23:03:00 -0000 Subject: UCALC equivalent References: <42FCDCA7.7030107@syscononline.com> <42fcea4a$1@nntp0.pdx.net> Message-ID: Scott David Daniels wrote in news:42fcea4a$1 at nntp0.pdx.net: > max wrote: >> Larry Bates wrote in >> news:42FCDCA7.7030107 at syscononline.com: >>>Python has built in eval function and doesn't require a library. >> >> Are you kidding? Read the original post a little more closely. >> The o.p. is looking for a library that evaluates mathematical >> expressions and is callable from python code. > > He is absolutely correct. > From the web page referenced: > > ucDefineFunction("area(length,width) = length*width"); > ucDefineFunction("frac(x)=abs(abs(x)-int(abs(x)))"); > ucDefineFunction("test() = 5"); > ucDefineFunction("abc(x, y=10) = x + y"); > ucDefineFunction("shl[x, y] = x * 2^y"); > > cout.precision(16); > cout << ucEval("frac(150/17) * area(20,30)") << endl; > cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)") > << endl; > > > The python equivalent: > > exec "def area(length,width): return length*width" > exec "def frac(x): return abs(abs(x) - int(abs(x)))" > exec "def test(): return 5" > exec "def abc(x, y=10): return x + y" > exec "def shl(x, y): return x * 2^y" > > print eval("frac(150/17) * area(20,30)") > print eval("abc(5) - abc(3,4) * shl(0x0E, 1)") > > --Scott David Daniels > Scott.Daniels at Acm.Org > Ouch, I sure was wrong. You did such a good job making me look foolish that it was mentioned in Python-URL!. At least Larry Bates had the grace not to call me an idiot. max From fredrik at pythonware.com Tue Aug 16 08:49:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 16 Aug 2005 14:49:05 +0200 Subject: base64.encode and decode not correct References: <4301D507.3070509@agg.astranet.ru> Message-ID: Damir Hakimov wrote: > I found a strange bug in base64.encode and decode, when I try to encode > - decode a file 1728512 bytes lenth. does this work on your machine? >>> import base64 >>> x = base64.encodestring(1728512 * "*") >>> len(base64.decodestring(x)) 1728512 does it work also if you change it to >>> import base64 >>> data = open(FILENAME, "rb").read() >>> x = base64.encodestring(data) >>> len(base64.decodestring(x)) (where FILENAME is the name of your file) ? From jzgoda at gazeta.usun.pl Mon Aug 1 15:09:49 2005 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Mon, 01 Aug 2005 21:09:49 +0200 Subject: On fighting fire with fire... In-Reply-To: References: Message-ID: skip at pobox.com napisa?(a): > Twice today I responded to rude messages (once here, once on the SpamBayes > list) whose authors didn't deserve the benefit of my time. In both cases, > other people rightfully responded with some small amount of return venom > (but provided useful responses nonetheless). > > Let me suggest that there is only one "correct" way to respond (if you are > going to respond at all) to such messages. That's to focus on the substance > of their message and completely ignore the rancor. I've been the chief > technical guy (including user support) for Musi-Cal for over ten years and > for Mojam for about seven years. During that time I've received lots of > thanks from people for the service those sites provide. Every once in > awhile though, I get a message out of the blue from someone who is either > simply an asshole or is having the mother of all bad days. I've found there > is nothing so satisfying as responding politely to such messages and then to > have their authors come virtually crawling back later with an apology for > having been so out-of-line. Did you read this article on online discussions in Hacknot? http://www.hacknot.info/hacknot/action/showEntry?eid=72 One of the most usable, I think. ;) -- Jarek Zgoda http://jpa.berlios.de/ From berlin.brown at gmail.com Fri Aug 12 00:44:53 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Fri, 12 Aug 2005 00:44:53 -0400 Subject: Lightweight Python distribute it in under 2MBs for Win32 Message-ID: I am sorry if I think like this, but sometimes(keyword sometimes) I like distributing my interpreters. Anyway, I found the absolute minimum libraries needed for Python to work with Win32. And, I included FLTK for the GUI toolkit. Sorry, but wxPython didn't fit my <30MB requirement. You can basically download it and find out what libraries are needed. Some of the core included string.py, stat.py, for example. http://www.newspiritcompany.com/PyLight.zip http://newspiritcompany.com/blog/article/167/python-lightweight-at-2mb-for-win32 -- Ramza from Atlanta http://www.newspiritcompany.com From richard at nospam.com Wed Aug 10 14:47:37 2005 From: richard at nospam.com (Richard Townsend) Date: Wed, 10 Aug 2005 19:47:37 +0100 Subject: Putting function references in a Queue References: <1mh1u4qoeju2f.1suxwcnapp086$.dlg@40tude.net> Message-ID: <1d5w8nmhoaf82$.1gvd7namdwtjl.dlg@40tude.net> On Tue, 09 Aug 2005 23:46:22 GMT, Bryan Olson wrote: > I think that's a good thing to do. The tricky part is getting an > event loop to wait on both the queue and other kinds of events. > Periodic polling works, but kind of sucks. > > What's the 'done' argument? A lock maybe? 'done' is just a boolean for the child thread to indicate it has finished. The main thread keeps a dictionary of references to the child threads so the app can send then 'abort' messages via their input Queues. When a child thread sets 'done' to True, the main thread deletes its reference from the dictionary. Periodic polling triggered by a timer in the X-app main loop was the only way I could think of checking for feedback from the child threads, not very neat though... Thanks to everyone for their input! -- Richard From sylvain.thenault at logilab.fr Tue Aug 9 05:48:11 2005 From: sylvain.thenault at logilab.fr (Sylvain Thenault) Date: Tue, 09 Aug 2005 11:48:11 +0200 Subject: .pth files References: Message-ID: On Tue, 09 Aug 2005 09:37:47 +0000, Adriano Varoli Piazza wrote: > Sylvain Thenault ha scritto: >> Hi there ! >> >> I've some questions regarding pth files (which btw are undocumented in >> the python reference, is this intentional ?) >> >> I thought that I could use a .pth file to be able to import zope >> products from both INSTANCE_HOME/Products and >> ZOPE_HOME/lib/python/Products from outside zope: >> >> >> syt at musca:~$ cat cvs_work/Products.pth >> /home/syt/local/Zope-2.8.1-b1/Products >> /home/syt/local/Zope-2.8.1-b1/lib/python/Products syt at musca:~$ >> syt at musca:~$ python >> Python 2.3.5 (#2, Jun 19 2005, 13:28:00) [GCC 3.3.6 (Debian 1:3.3.6-6)] >> on linux2 Type "help", "copyright", "credits" or "license" for more >> information. >> >>>>>import sys >>>>>print sys.path >> >> ['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft', >> '/home/syt/local/lib/python2.3/site-packages', >> '/home/syt/local/lib/python', '/usr/lib/python23.zip', >> '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2', >> '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload', >> '/usr/local/lib/python2.3/site-packages', >> '/usr/lib/python2.3/site-packages', >> '/usr/lib/python2.3/site-packages/Numeric', >> '/usr/lib/python2.3/site-packages/PIL', >> '/usr/lib/python2.3/site-packages/gtk-2.0', >> '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python'] >> >> But as you can see, >> 1. the Products.pth file isn't considered at all, while for example >> PIL.pht in the site-packages is correctly detected >> 2. I'm not even sure that I can put several paths in a .pth file >> >> Is there a restriction on .pth location ? Is it possible to have >> multiple path in a pth file ? >> >> > From Learning Python, 2nd Ed: > "a relatively new feature of Python allows users to add valid directories > to the module search path by simply listing them, one per line, in a text > file whose name ends in a .pth suffix. > > See also the docs for the site module in the Python Library reference. ha, so that's where it's documented ! so answer are: 1. Products.pth are only considered in standard site-packages and site-python directories 2. yes, it's possible Now, the question become: why can't we use pth files in other path specified by the PYTHONPATH environement variable ? -- Sylvain Th?nault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From nephish at xit.net Thu Aug 18 14:35:00 2005 From: nephish at xit.net (nephish at xit.net) Date: 18 Aug 2005 11:35:00 -0700 Subject: question about binary and serial info In-Reply-To: References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <1124386952.353027.93050@g47g2000cwa.googlegroups.com> Message-ID: <1124390100.475368.48790@o13g2000cwo.googlegroups.com> all apologies, gentlemen, i feel like an idiot. the ord() is what is returning what i need. the manufacturer of the unit i am reading from told me that it puts out a "string that represents a hex" been thumping my head. sorry for the confusion, and thanks for your help shawn From jsgaarde at gmail.com Wed Aug 17 13:51:41 2005 From: jsgaarde at gmail.com (Jakob Simon-Gaarde) Date: 17 Aug 2005 10:51:41 -0700 Subject: win32pipe.popen3 Message-ID: <1124301101.559487.283280@o13g2000cwo.googlegroups.com> Follow-up on a thread from 1999 (see below) Well now it is 2005 and the operating system I'm using is Windows Server 2003, and I can still see that the same problem persists with: win32pipe.popen2() win32pipe.popen3() win32pipe.popen4() while win32pipe.popen() does almost what you want. >>> import win32pipe >>> win32pipe.popen('cmd') >>> r=win32pipe.popen('cmd') >>> r.readline() 'Microsoft Windows XP [Version 5.1.2600]\n' >>> r.readline() '(C) Copyright 1985-2001 Microsoft Corp.\n' >>> r.readline() '\n' >>> r.readline() 'C:\\backup\\TRPython241\\trpython>' Although I think the last readline ought to return None since no carriage return has been issued yet, it is better than popen2,popen3 and popen4, which all just block the parent process. The current behaviour of win32pipe.popen2(), win32pipe.popen3() and win32pipe.popen4() would be acceptable for me if I knew a way to test if there was something ready for reading, but I can't see how to do that test, therfore I don't know when to stop reading from output :( Is there a solution for this, can I poll/test for ready-read on popen3 I/O objects. Best regards Jakob Simon-Gaarde --------------------------- >From a thread in 1999 High Arpard, thanx for help but I got probs with that popen3 under Win95: 'o.readlines()' doesn't return anymore. To find out I checked it line per line: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import win32pipe >>> i,o,e=win32pipe.popen3('ver', 'b') >>> o.readline() '\015\012' >>> o.readline() 'Windows 95. [Version 4.00.1111]\015\012' >>> o.readline() '\015\012' >>> o.readline() Don't know why, but it never;-) returns. Perhaps it may be a bug in win32pipe, that it doesn't return becourse readline couldn't find CarriageReturn/EOF? I took win32pipe.popen('ver','r') for a better solution. That works fine. greetings, Holger From bokr at oz.net Fri Aug 26 17:21:19 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 26 Aug 2005 21:21:19 GMT Subject: overload builtin operator References: <3n61u4F1fg2U1@individual.net> Message-ID: <430ee1bc.2456509954@news.oz.net> On Thu, 25 Aug 2005 16:12:20 +0200, Reinhold Birkenfeld wrote: >Shaun wrote: >> Hi, >> >> I'm trying to overload the divide operator in python for basic arithmetic. >> eg. 10/2 ... no classes involved. >> >> I am attempting to redefine operator.__div__ as follows: >> >> # my divide function >> def safediv(a,b): >> return ... >> >> # reassign buildin __div__ >> import operator >> operator.__div__ = safediv >> >> The operator.__dict__ seems to be updated OK but the '/' operator still >> calls buildin __div__ > >It won't work that way. You cannot globally modify the behaviour of an operator, >but you can customize how an operator works for your type. > >Consider: > >class safeint(int): > def __div__(self, other): > return safediv(self, other) > >safeint(10)/2 > You are right that you cannot globally modify the behaviour of an operator in the sense the OP seems to be envisioning, but with some trouble I think it would be possible to interfere with the translation of '/' to become 'safediv(, )' by transforming the AST during a custom import process, such that wherever a Div node is found, a CallFunc node is substituted. E.g., for a node like Div((Name('numerator'), Name('denominator'))) substitute another node like CallFunc(Name('safediv'), [Name('numerator'), Name('denominator')], None, None) where the Name('numerator') and Name('denominator') in the latter are actually the Div node's .left and .right, so as to operate on the same args (which can be abitrary expression-representing subtrees). Of course, you probably also want to replace AugAssign(Name('a'), '/=', Name('b')) with Assign([AssName('a', 'OP_ASSIGN')], CallFunc(Name('safediv'), [Name('a'), Name('b')], None, None)) Unfortunately, the AST tree does not seem to be designed to be edited easily wrt _replacing_ nodes found by walking via flattened lists vs. just _using_ them in order. I think I can create special walker that can do replacements of nodes found anywhere, and calling node-type-specific or default supplied callbacks to supply replacements for original nodes passed to them, but this will require a number of specialized visitors etc., so I will have to get back to this later. But at least the OP and you nudged me into thinking about AST rewriting again ;-) (also affects my @@sourcedeco ideas ;-) Regards, Bengt Richter From mwm at mired.org Fri Aug 26 20:56:48 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 26 Aug 2005 20:56:48 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: <86acj4w627.fsf@bhuda.mired.org> John Bokma writes: > Chris Head wrote: >> I mean, the way >> Webmail works, you're at the message list and click on a message to >> view. This causes a whole new page, user-interface and all, to be >> loaded. In comparison, that's like shutting down and re-opening your >> e-mail program for every single message you want to view! > This can be designed much better by using iframes, maybe even Ajax. Definitely with Ajax. That's one of the things it does really well. >> Why can't we use the Web for what it was meant for: viewing hypertext >> pages? Why must we turn it into a wrapper around every application >> imaginable? > Because it works? Because you can - if you know how to use HTML properly - distribute your application to platforms you've never even heard of - like the Nokia Communicator. I started writing web apps when I was doing internal tools development for a software development company that had 90+ different platform types installed inhouse. It was a *godsend*. By deploying one well-written app, I could make everyone happy, without having to do versions for the Mac, Windows, DOS (this was a while ago), getting it to compile on umpteen different Unix version, as well as making it work on proprietary workstation OS's. Of course, considering the state of most of the HTML on the web, I have *no* idea why most of them are doing this. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From bryanjugglercryptographer at yahoo.com Tue Aug 16 12:22:17 2005 From: bryanjugglercryptographer at yahoo.com (bryanjugglercryptographer at yahoo.com) Date: 16 Aug 2005 09:22:17 -0700 Subject: base64.encode and decode not correct In-Reply-To: References: Message-ID: <1124209337.896652.139170@g49g2000cwa.googlegroups.com> Damir Hakimov wrote: > I found a strange bug in base64.encode and decode, when I try to encode > - decode a file 1728512 bytes lenth. > Is somebody meet with this? I don't attach the file because it big, but > can send to private. I agree the file is too big, but can you show a small Python program that does the encode, decode, and problem detect? -- --Bryan From tjreedy at udel.edu Wed Aug 3 23:02:54 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 3 Aug 2005 23:02:54 -0400 Subject: quetion about "+=" and "runtime" References: <1123123359.768132.112990@g47g2000cwa.googlegroups.com> Message-ID: wrote in message news:1123123359.768132.112990 at g47g2000cwa.googlegroups.com... > 1.i saw "+=" in a program code,but i haven't see it before,neither can > i find it in a cook,who can tell me the usage of "python0" It probably is in the tutorial and certainly is in the reference manual. I don't understand "usage of 'python0'". > 2.how can i know how long does a program run? time module tjr From http Mon Aug 1 15:58:57 2005 From: http (Paul Rubin) Date: 01 Aug 2005 12:58:57 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> Message-ID: <7x1x5do2da.fsf@ruckus.brouhaha.com> Peter Decker writes: > Geez, can you whine some more? Most people are running wxPython just > fine, Most people? What percentage of actual Python users do you think have wxPython installed? If you're really claiming it's over 50%, you're out of your mind. From zsolt-google1 at mailblocks.com Tue Aug 2 17:53:19 2005 From: zsolt-google1 at mailblocks.com (pythonUser_07) Date: 2 Aug 2005 14:53:19 -0700 Subject: Script for generating WSDL In-Reply-To: References: Message-ID: <1123019599.169025.274880@g14g2000cwa.googlegroups.com> Is that possible? In order to access a web service it seems like you need to know how it is defined (IE through the WSDL) From jack at performancedrivers.com Thu Aug 25 14:29:36 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Thu, 25 Aug 2005 14:29:36 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <430E0C8D.5000506@ceid.upatras.gr> References: <430E0C8D.5000506@ceid.upatras.gr> Message-ID: <20050825182936.GE5991@performancedrivers.com> On Thu, Aug 25, 2005 at 09:23:09PM +0300, Stelios Xanthakis wrote: > The explanation is this: hash > and comparison of objects depends on the state of the memory > allocator. A sample case is this: > > class A: pass > dummy0=47 # comment this to get a different result for min > a=A() > b=A() > print min (a, b) > > the result of 'min' is not only non-deterministic but also depends > on whether other things have been allocated before. The same > thing can happen for 'dictionary.keys()' if the keys are objects > and 'iterate-over-set' when the set contains objects. > > In the sudoku solver, there is a min (number, object) which is > probably what's affected by the extistance of the dummy variable. > Now, in sudoku puzzles some times the algorithm has to suppose Doh, I feel silly. Without an 'import random' in the program I assumed it was deterministic. I would have also expected the comparison to be a TypeError, and it sometimes is. >>> mynum = 7 >>> myob = object() >>> cmp(mynum, myob) -1 >>> mynum.__cmp__(myob) Traceback (most recent call last): File "", line 1, in ? TypeError: int.__cmp__(x,y) requires y to be a 'int', not a 'object' Thanks for the explanation, -jackdied From python at rcn.com Thu Aug 4 14:24:16 2005 From: python at rcn.com (Raymond Hettinger) Date: 4 Aug 2005 11:24:16 -0700 Subject: Reliable destruction References: <1123153847.649321.235450@z14g2000cwz.googlegroups.com> Message-ID: <1123179856.655471.278630@g14g2000cwa.googlegroups.com> [Pierre-Eric.Melchy at uni-konstanz.de] > My questions are: > 1) under normal conditions (no exceptions) is there a guarantee, that > __del__ of > all instruments is called at the end of measurement()? > > 2) if an exception is thrown, will all instruments be deleted if the > error > occurs in run() ? > (only the instruments already initialized if the error occurs > in setup() )? > > I am using CPython (on WinXP) and there are no reference cycles between > the instruments. > > I have to stress again that a reliable finalization is important and > cannot wait > until the interpreter shuts down. > > I have tried this and it seems to work but this is of course no > guarantee. On the plus side, Python does guarantee destruction in the absence of cycles when the last reference disappears. If there is a cycle, you have to wait for GC. If you can't wait, then schedule a gc.collect() to run periodically. On the minus side, this is a somewhat brittle and error-prone design strategy. A single, accidental persistent reference is sufficient to cause failure -- that is a land-mine for all future maintainers of your code. It is better to make explicit tear-down calls and to wrap finalization is a try/finally suite. The simplified code in your post suggests that the instrument shut-off can be placed at the end of the run() method -- loosely translated as turn-off the lights when you're done. An alternative strategy is to periodically poll resources and shut them off if they are not in use -- loosely translated as having a security guard turn-off any coffee-pots that were left on by frazzled programmers as they leave at odd hours of the night. Raymond From jgrahn-nntq at algonet.se Sat Aug 20 06:18:16 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 20 Aug 2005 10:18:16 GMT Subject: up to date books? References: Message-ID: On Thu, 18 Aug 2005 11:58:23 +0200, Magnus Lycka wrote: > John Salerno wrote: >> hi all. are there any recommendations for an intro book to python that >> is up-to-date for the latest version? > > It depends on what kind of books you like, and of course on your > previous experience. ... > If you like a high density book, Alex Martelli's "Python in a Nutshell" > is great, That one is my first choice. FYI, it is based on Python 2.2, but discusses most (all?) interesting 2.3 features too. That has been very acceptable to me. I wouldn't buy a book that didn't discuss 'yield' or list comprehensions. > Probably not. Most recent changes to Python, such as decorators, are > things that beginners might want to leave until later... New standard > modules, such as datetime, are covered in the standard library manual. Exactly. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 5 16:02:44 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 05 Aug 2005 22:02:44 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: <3lhuv4F12u3phU1@individual.net> Erik Max Francis wrote: > Daniel Sch?le wrote: > >> maybe I confuse, in german one would say "45 Grad" >> I took a freedom to translate it directly :) >> well, my calculator shows a "D" >> which most likely stands for Degree, I cannot tell for sure > > Probably. In English, you have degrees and gradians, which aren't the > same thing; gradians are defined so that there are 400 gradians in a > circle (so 100 gradians in a right angle). In German, they're "Altgrad" (degrees) and "Neugrad" or "Gon" (gradians). Reinhold From rkern at ucsd.edu Thu Aug 4 22:11:23 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 04 Aug 2005 19:11:23 -0700 Subject: Parallel arithmetic? In-Reply-To: <42f2c81a$1_3@alt.athenanews.com> References: <42f298d6$1_5@alt.athenanews.com> <42f2c81a$1_3@alt.athenanews.com> Message-ID: Terrance N. Phillip wrote: > Thank-you very much for all the excellent replies. I'm thinking of using > this to determine if a sequence is a "run" (as in a card game). If I've > got a sorted hand [3, 4, 5, 6, 7], then I know I've got a 5-card run > because [4, 5, 6, 7] - [3, 4, 5, 6] == [1, 1, 1, 1]. I want to avoid > something like > if h[0] == h[1]-1 and h[1] == h[2]-1 ... In that case: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/415504 -- 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 Sat Aug 6 09:47:43 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 06 Aug 2005 09:47:43 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) In-Reply-To: <11f9f9u2enfsi58@news.supernews.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> Message-ID: John Roth wrote: > It's not going to happen because the Python community is fat and happy, > and is not seeing the competition moving up on the outside. Characteristics > that make a great language one day make a mediocre one a few years > later, and make a has-been a few years after that. And here I thought that was the point of Python 3000. To let the community produce a much improved language while avoiding the problems caused by too much change occurring while people are trying to get useful things done with what the language is _now_. The competition (and let's see a description of just what that means, too) probably has the dual advantage of newness and a small, hackerish community that is more than happy to see rapid and radical change. You're right -- as with the stereotypical large/slow vs. small/agile company motif -- that smaller and more agile will pass larger and slow "on the outside", but you're wrong if you think that means the larger-slower entity should drop what it's been doing so well and try to compete entirely on the smaller-faster entity's own ground. BTW, I think "large and stable" would have been less offensive than "fat and happy", but perhaps you meant to imply we're both lazy and complacent, rather than just satisfied with something that works and not inclined to shoot for moving targets every working day. If so, I'm not sure why you'd say that, since the evidence doesn't support it. -Peter From aahz at pythoncraft.com Wed Aug 10 11:34:33 2005 From: aahz at pythoncraft.com (Aahz) Date: 10 Aug 2005 08:34:33 -0700 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <1123609818.770605.267740@g14g2000cwa.googlegroups.com> Message-ID: In article , Terry Reedy wrote: >"Jeffrey E. Forcier" wrote in message >news:1123609818.770605.267740 at g14g2000cwa.googlegroups.com... >> >> Thirding the Subversion/SVN suggestions. It's generally a newer, better >> CVS with some new features and a lot less of the negative features/lack >> thereof, of the older system. > >For what it is worth, the Python developers are discussing moving the >Python codebase to subversion, though other options were discussed. The >result so far is PE 347 Migrating the Python CVS to Subversion. While you're technically correct, at this point it's closer to "planning the move to Subversion". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From martin at v.loewis.de Tue Aug 9 15:31:45 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 09 Aug 2005 21:31:45 +0200 Subject: Build errors for Objects/complexobject.c In-Reply-To: <1123606282.872534.214330@g47g2000cwa.googlegroups.com> References: <1123606282.872534.214330@g47g2000cwa.googlegroups.com> Message-ID: <42F904A1.2070606@v.loewis.de> peter.havens at gmail.com wrote: > I'm attempting to build Python 2.4.1 on Solaris 10 using gcc 3.4.3. I > get the following build error: This is a GCC bug, which I think got fixed in gcc 4.0.1. You can work around it by removing the definition of _XOPEN_SOURCE, POSIX_SOURCE, XOPEN_SOURCE_EXTENDED from pyconfig.h. Regards, Martin From jonhewer at gmail.com Fri Aug 19 08:06:00 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Fri, 19 Aug 2005 13:06:00 +0100 Subject: Python for Webscripting (like PHP) In-Reply-To: <1124452266.755404.197360@z14g2000cwz.googlegroups.com> References: <1124449823.428290.206950@g47g2000cwa.googlegroups.com> <1124452266.755404.197360@z14g2000cwz.googlegroups.com> Message-ID: Ah cool, thanks, i hadn't spotted that page :) On 19 Aug 2005 04:51:06 -0700, paron wrote: > Yes, there's a tutorial about that -- there are several options > depending on the URL structure you want to expose, and your version of > Apache. None of them are torturous, though. > > Start at http://www.cherrypy.org/wiki/CherryPyProductionSetup and > follow the links down. > > Ron > > -- > http://mail.python.org/mailman/listinfo/python-list > From pwatson at redlinepy.com Thu Aug 11 14:11:24 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Thu, 11 Aug 2005 13:11:24 -0500 Subject: about coding In-Reply-To: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> References: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> Message-ID: <42FB94CC.6040205@redlinepy.com> cantabile wrote: > Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-' > directive. > > I'm using an accented characters language. Some of them are correctly > displayed while one doesn't. I've written : > -*- coding: utf-8 -*- > > Is this wrong ? > > Where can I find a pratical explanation about these encodings ? > > Thanks. You must know the encoding produced by your editor. If you want to experiment, you could save a small file and run od -Ax -tx1 thefile.py to see exactly what codepoints appear. Compare those with the charts at http://www.unicode.org/ and you can probably surmize a good guess. From ksenia.marasanova at gmail.com Wed Aug 10 06:15:13 2005 From: ksenia.marasanova at gmail.com (Ksenia Marasanova) Date: Wed, 10 Aug 2005 12:15:13 +0200 Subject: sorting question In-Reply-To: <1123662644.955191.93570@g47g2000cwa.googlegroups.com> References: <1123662644.955191.93570@g47g2000cwa.googlegroups.com> Message-ID: <130df1930508100315522b369f@mail.gmail.com> > class Node: > def __init__(self, name, url, order, pid, id): > self.name = name > self.url = url > self.order = order > self.pid = pid > self.id = id > def __repr__(self): > return self.url > def mycmp(x,y): > if x.pid == y.pid: > if x.order != y.order: > return cmp(x.order,y.order) > return cmp(x.url,y.url) > return cmp(x.pid,y.pid) > a = Node('ham','/test/ham/',1,0,1) > b = Node('eggs','/test/ham/eggs/',1,1,2) > c = Node('bacon','/test/ham/bacon/',1,1,3) > d = Node('spam','/test/ham/bacon/spam/',1,3,4) > > Does this work for you? I haven't tested it much. Thank you for help :) It doesn't work yet. The id's are not sequentional, so it fails when id of the child is lower than id of the parent. If I change the last line in mycmp from return cmp(x.pid,y.pid) to return cmp(x.url,y.url) # almost the same cmp function I use than your example work and I can't break it. But the real code (hunderds of nodes) doesn't, and I can't yet find the node(s) that cause it :( -- Ksenia From cliff at develix.com Mon Aug 1 08:59:30 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 05:59:30 -0700 Subject: Dabo in 30 seconds? In-Reply-To: <200508010830.27322.ed@leafe.com> References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> Message-ID: <1122901170.19618.296.camel@localhost.localdomain> On Mon, 2005-08-01 at 08:30 -0400, Ed Leafe wrote: > On Sunday 31 July 2005 20:09, James Stroud wrote: > No problem. But let me ask you what would *not* have disappointed you. As > others have pointed out, you didn't compile the wxWidgets part of your > wxPython install so as to include the stylized text control (yes, it seems > silly that you should have to specify that, but that's another thread...) > > Should we have defensive code for every possible broken installation? We use > a lot of the Python standard library modules, many dbapi-compliant modules, > and, of course, wxPython. If someone mis-installs one of the pre-requisites, > do you expect Dabo to catch that and present you with a diagnostic message? > I'm serious here: I want to know what people consider acceptable for a > software package that relies on other packages. Personally, all I expect is an obvious pointer to a mailing list and a helpful community willing to suffer NB questions (fast bugfixes is a big plus too). If that's available, I'm happy. But then I'm willing to actually work a little to get what I want. For other it seems they won't be happy unless you drive to their house and install it for them (which only seems fair, cause if you hadn't volunteered to write such crap then they wouldn't have had to be bothered with it in the first place, damn you). Maybe you wouldn't mind tidying up a bit and washing a few dishes while you're at it? Can't *quite* get this spoon to my mouth'ly yours, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From adamtj at adamtj.org Sun Aug 28 18:49:30 2005 From: adamtj at adamtj.org (Adam Tomjack) Date: Sun, 28 Aug 2005 17:49:30 -0500 Subject: trictionary? In-Reply-To: <17169.16176.556417.938640@roam.psg.com> References: <17169.16176.556417.938640@roam.psg.com> Message-ID: <43123F7A.5030707@adamtj.org> Randy, I'd probably use a two element list. Instead of using an if/else to check if an element is in your dict and initialize it, you can use the setdefault() function. The docs for dictionaries explain it pretty well. bin = {} for whatever: for [a, b] in foo: x = 42 - a bin_item = bin.setdefault(x, [1, 0]) bin_item[0] += 1 for x, (y, z) in bin.iteritems(): print x, y, z You could also use a class like a C-style struct if you want named items: class BinItem: def __init__(self, s=0, t=0): self.s = s self.t = t bin = {} for a, b in foo: x = 42 - a bin_item = bin.setdefault(x, BinItem(1, 0)) bin_item.s += 1 for x, item in bin.iteritems(): print x, item.s, item.t Luck in battle, Adam Randy Bush wrote: > i have some code which looks kinda like > > bin = {} > for whatever: > for [a, b] in foo: > x = 42 - a > y = 42 - b > if bin.has_key(x): > bin[x] += 1 > else: > bin[x] = 1 > for i, j in bin.iteritems(): > print i, j > > now i want to add a second count column, kinda like > > bin = {} > for whatever: > for [a, b] in foo: > x = 42 - a > if bin.has_key(x): > bin[x.b] += 1 > else: > bin[x.b] = 1 > bin[x.not b] = 0 > for x, y, z in bin.iteritems(): > print x, y, z > > should the dict value become a two element list, or is > there a cleaner way to do this? > > randy > From bryanjugglercryptographer at yahoo.com Mon Aug 15 22:54:42 2005 From: bryanjugglercryptographer at yahoo.com (bryanjugglercryptographer at yahoo.com) Date: 15 Aug 2005 19:54:42 -0700 Subject: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> Message-ID: <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Michael Hudson wrote: > Bryan Olson writes: > In some sense; it certainly does what I intended it to do. [...] > I'm not going to change the behaviour. The docs probably aren't > especially clear, though. The docs and the behavior contradict: [...] these are the /start/ and /stop/ indices and the /step/ or stride length of the slice [emphasis added]. I'm fine with your favored behavior. What do we do next to get the doc fixed? -- --Bryan From yux at sdf-eu.org Wed Aug 24 13:10:11 2005 From: yux at sdf-eu.org (Jonas Geiregat) Date: Wed, 24 Aug 2005 17:10:11 +0000 Subject: Email client in Pyhton In-Reply-To: References: Message-ID: <430c8d7c$0$6573$ba620e4c@news.skynet.be> knaren at midascomm.com wrote: > Hi grp, > I new to this grp and python too. > i have started writing few python scripts myself. > > now i am planning to write a bear minimum email client in > pyhton. i found the smtp module of python could serve my > pupose. I can send message using mails using the smtp lib. > Now i'm looking for some modules which can help me in > fetching the mails from the mailserver and managing folders. > > I also look for some existing mail client, written in python > which wud serve my cause. > > i searched google for no avail. > Maybe start by reading some email related rfc's From franz.steinhaeusler at gmx.at Thu Aug 11 07:16:11 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Thu, 11 Aug 2005 13:16:11 +0200 Subject: new python debugger References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> <1123740657.066728.39080@g43g2000cwa.googlegroups.com> Message-ID: On Thu, 11 Aug 2005 13:09:08 +0200, Franz Steinhaeusler wrote: >> >>Winpdb is still a BETA despite the version number which is 1.0.1 >>so I will appreciate feedback on bugs, unexpected behavior, or >>suggestions. List of current breakpoints (VC Alt-F9), where you can quickly switch on/off them with a list of checkboxes. -- Franz Steinhaeusler From mwh at python.net Tue Aug 16 20:21:34 2005 From: mwh at python.net (Michael Hudson) Date: Wed, 17 Aug 2005 00:21:34 GMT Subject: __del__ pattern? References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> <1124232686.973363.317640@z14g2000cwz.googlegroups.com> Message-ID: bryanjugglercryptographer at yahoo.com writes: > Chris Curvey wrote: >> I need to ensure that there is only one instance of my python class on >> my machine at a given time. (Not within an interpreter -- that would >> just be a singleton -- but on the machine.) These instances are >> created and destroyed, but there can be only one at a time. >> >> So when my class is instantiated, I create a little lock file, and I >> have a __del__ method that deletes the lock file. Unfortunately, there >> seem to be some circumstances where my lock file is not getting >> deleted. Then all the jobs that need that "special" class start >> queueing up requests, and I get phone calls in the middle of the night. > > For a reasonably portable solution, leave the lock file open. > On most systems, you cannot delete an open file, Uh, you can on unix -- what else did you have in mind for "most systems"? Cheers, mwh -- Well, yes. I don't think I'd put something like "penchant for anal play" and "able to wield a buttplug" in a CV unless it was relevant to the gig being applied for... -- Matt McLeod, asr From http Tue Aug 30 15:04:33 2005 From: http (Paul Rubin) Date: 30 Aug 2005 12:04:33 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314a1bd.169970023@news.oz.net> Message-ID: <7x1x4bnt4u.fsf@ruckus.brouhaha.com> bokr at oz.net (Bengt Richter) writes: > What about if when brackets trail as if attributes, it means > your-style slicing written with colons instead of semicolons? > > sequence.[start : stop : step] This is nice. It gets rid of the whole $1,$2,etc syntax as well. From max at alcyone.com Fri Aug 5 15:35:08 2005 From: max at alcyone.com (Erik Max Francis) Date: Fri, 05 Aug 2005 12:35:08 -0700 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: Daniel Sch?le wrote: > what do you think about it? > maybe there exists some proposals aiming this goal? Derive your own subclass of complex and define those methods. -- 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 am not afraid / To be a lone Bohemian -- Lamya From fakeaddress at nowhere.org Wed Aug 24 11:21:22 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 24 Aug 2005 15:21:22 GMT Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: Steven Bethard wrote: > Bryan Olson wrote: > >> Steven Bethard wrote: >> > Well, I couldn't find where the general semantics of a negative stride >> > index are defined, but for sequences at least[1]: >> > >> > "The slice of s from i to j with step k is defined as the sequence of >> > items with index x = i + n*k such that 0 <= n < (j-i)/k." >> > >> > This seems to contradict list behavior though. [...] >> >> The conclusion is inescapable: Python's handling of negative >> subscripts is a wart. > > > I'm not sure I'd go that far. Note that my confusion above was the > order of combination of points (3) and (5) on the page quoted above[1]. > I think the problem is not the subscript handling so much as the > documentation thereof. Any bug can be pseudo-fixed by changing the documentation to conform to the behavior. Here, the doc clearly went wrong by expecting Python's behavior to follow from a few consistent rules. The special-case handling of negative indexes looks handy, but raises more difficulties than people realized. I believe my PPEP avoids the proliferation of special cases. The one additional issue I've discovered is that user-defined types that are to support __getitem__ and/or __setitem__ *must* also implement __len__. Sensible sequence types already do, so I don't think it's much of an issue. > This is already valid syntax, and is used > heavily by the numarray/numeric folks. Yeah, I thought that variant might break some code. I didn't know it would be that much. Forget that variant. -- --Bryan From mwm at mired.org Mon Aug 29 20:19:11 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 29 Aug 2005 20:19:11 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> Message-ID: <864q98b7k0.fsf@bhuda.mired.org> Bryan Olson writes: > Mike Meyer wrote: > > Bryan Olson writes: > > phil hunt wrote: > >> > What's important is *predictability*, e.g. which instruction will > >> > the computer execute next? > >> > If you only have one thread, you can tell by looking at the code > >> > what gets executed next. It's very simple. > >>Not really. Trivially, an 'if' statement that depends upon input > >>data is statically predictable. Use of async I/O means makes the > >>programs execution dependent upon external timing. > > Yes, but that depenency is tied to a single point - the select > > call. The paths after that are statically predictable. This makes the > > code very managable. > Wow -- I could not disagree more. Returning back to some single > point for every possibly-blocking operation is painful to manage > even for simple GUIs, and humanly intractable for sophisticated > services. I'd be interested in what you're trying to do that winds up as unmanagable. There are clearly things select+async IO is unsuitable for. You may be running into problems because you're trying to use it in such an environment. For instance, it's not clear to me that it will work well for any kind of GUI programming, though I've had good look with it for command line interfaces. > Select is certainly useful, but it scales badly and isn't as > general as better tools. It can't take advantage of multiple CPUs. I've not run into scaling problems on single-CPU systems. > > [...] I'm calling the tools available in most programming > > languages for dealing with it primitive. > > We need better tools. > Agreed, but if 'select' is someone's idea of the state of the > art, they have little clue as to the tools already available. Well, share! If you know of tools that make dealing with concurrent code more manageable than an async I/O loop and have fewer restrictions, I'm certainly interested in hearing about them. > Bringing the tools to Python remains a bit of challenge, largely > because so many Pythoners are unaware. Well, the way to fix that is to talk about them! http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From davefickbohm at yahoo.com Tue Aug 23 12:01:58 2005 From: davefickbohm at yahoo.com (David Fickbohm) Date: Tue, 23 Aug 2005 09:01:58 -0700 (PDT) Subject: How to execute python script in Windows Message-ID: <20050823160158.65445.qmail@web80007.mail.yahoo.com> People, Can someone please tell me how to execute a python script in windows? Thanks Dave Dave Fickbohm Use Technology to the Fullest 1250 45th st suite 200 Emeryville, CA, 94608 510 594 4151 voice -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Aug 27 23:43:55 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Aug 2005 23:43:55 -0400 Subject: Experience regarding Python tutorials? In-Reply-To: References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <1125072815.753219.62420@g47g2000cwa.googlegroups.com> <17169.12062.87650.520472@roam.psg.com> Message-ID: Sorry, that email address is tutor at python.org. Steve Holden wrote: > Randy Bush wrote: > >>>There is also a python tutor newsgroup at gmane >>>(gmane.comp.python.tutor). >> >> >>is there a mailing list to which it is gated? >> >>randy >> > > It's actually primarily a mailing list (tutor-list at python.org, IIRC). > See http://mail.python.org/mailman/listinfo/tutor > > regards > Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Bur at jwamalls.com Fri Aug 19 06:55:38 2005 From: Bur at jwamalls.com (Xavier Burger) Date: Fri, 19 Aug 2005 05:55:38 -0500 Subject: =?iso-8859-1?Q?VIAGRR=C1-Good_for_your_life?= Message-ID: <002b01c5a4ac$886b7100$0048a8c0@eluvium> Hello, even Stravinsky, a psychiatrist of genius, did not, of course, believe you.the way up the mountain was open and from where it would have been mostdo. The mechanism of this forced adjustment is revealed in the chapterintact were flung open, peoples heads appeared in them and hid at once, He, for example, the present procurator of Judea and former tribune of Why? the procurator asked, his face darkening. `Am I disagreeable toare surprised theres no light? Economy, so you think, of course? Unh-unh!went and sold her to a brothel... I beg you not to teach me, replied Behemoth, `I have sat at table,Margarita, blown upon by the cool wind, opened her eyes, she saw how theoh, no, he did not blame her! Margarita said, with a crooked and bitter smile:hoarse voice, and pounding the table with her fist, she said she wouldeyes of Niza, which now seemed black. It could be seen that the broken line especially upset him for some `I see youre somewhat surprised, my dearest Stepan Bogdanovich? -------------- next part -------------- An HTML attachment was scrubbed... URL: From limodou at gmail.com Fri Aug 19 11:36:17 2005 From: limodou at gmail.com (limodou) Date: Fri, 19 Aug 2005 23:36:17 +0800 Subject: stdin -> stdout In-Reply-To: References: Message-ID: <505f13c050819083631225051@mail.gmail.com> 2005/8/19, max(01)* : > hi. > > i was wondering, what's the simplest way to echo the standard input to > the standard output, with no modification. > > i came up with: > > ... > while True: > try: > raw_input() > except EOFError: > break > ... > > but i guess there must be a simpler way. > > using bash i simply do 'cat', *sigh*! > > bye > > max > > ps: in perl you ca do this: > > ... > while ($line = ) > { > print STDOUT ("$line"); > } > ... Try this. import sys line = sys.stdin.readline() while line: sys.stdout.write(line) line = sys.stdin.readline() -- I like python! My Donews Blog: http://www.donews.net/limodou From grante at visi.com Mon Aug 22 10:46:59 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 22 Aug 2005 14:46:59 -0000 Subject: sending binary files to a 16 micro controller. References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <11gjn8k74pb6uc0@corp.supernews.com> <1124720924.939114.96950@g43g2000cwa.googlegroups.com> Message-ID: <11gjpb3slchkq73@corp.supernews.com> On 2005-08-22, johnny.karlsson at gmail.com wrote: > aaah, well i believe that in Windows XPSP2 has disabled raw socket > support (yes i sadly have to use windows) so that's no option. But I'll > try to put a time delay and check what happens. Or otherwise perhaps i > could do a socket.close each time, but that's a terrible waste of > packets. I doubt the other end is expecting you to close the socket after each packet. Unless it was designed to tolerate that, it might not work. A time delay of a few hundred ms will probably work. I once wrote a Linux driver that could be used to wait until the TCP out queue was empty, but that won't do you much good on Windows. -- Grant Edwards grante Yow! Is this ANYWHERE, at USA? visi.com From me at privacy.net Thu Aug 18 19:39:19 2005 From: me at privacy.net (Dan Sommers) Date: Thu, 18 Aug 2005 19:39:19 -0400 Subject: Module Name Conflicts References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: On 18 Aug 2005 16:06:46 -0700, torched_smurf at yahoo.com wrote: > I have a java program in a package called 'cmd'. This of course > conflicts with the builtin python package of the same name. The thing > is, I need to be able to import from both of these packages in the same > script. I can import either one first, but any future attempt to import > from cmd.* will look up the first cmd that was imported, so the second > package is essentially eclipsed. I've tried fiddling with sys.path and > sys.packageManager.searchPath, to no avail. To answer the obvious first > suggestion, no I can't rename the java package to 'Cmd' or anything > like that. Any ideas? Assuming you can fiddle with sys.path at the right times, you can call an imported module anything you want: fix_sys_path_to_find_java_cmd_first() import cmd as java_cmd fix_sys_path_to_find_python_cmd_first() import cmd as python_cmd Obviously, then, 'cmd' does not reference either module; you'd have to use java_cmd and python_cmd as appropriate. HTH, Dan -- Dan Sommers From tdelaney at avaya.com Tue Aug 9 23:14:11 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Wed, 10 Aug 2005 13:14:11 +1000 Subject: Bizarre error from help() Message-ID: <2773CAC687FD5F4689F526998C7E4E5F05CBF2@au3010avexu1.global.avaya.com> Roy Smith wrote: > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.3/site.py", line 307, in __call__ > import pydoc > File "/usr/local/lib/python2.3/pydoc.py", line 49, in ? > from string import expandtabs, find, join, lower, split, strip, > rfind, rstrip > ImportError: cannot import name expandtabs Looks most likely that there something messed up with your python install. What happens if you do: >>> from string import expandtabs ? Do you get a similar error? The lines: foos bars bazes Foo look very suspicious - you should instead get: Help on built-in function isinstance in module __builtin__: isinstance(...) You may want to see if there's something strange in sitecustomize.py. Alternatively, since this is in the interactive interpreter, is it possible that something you'd done before could have caused this? Tim Delaney From rkern at ucsd.edu Sat Aug 6 22:14:58 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 19:14:58 -0700 Subject: Proposed new collection methods In-Reply-To: References: <86d5oqvfqf.fsf@bhuda.mired.org> Message-ID: Christopher Subich wrote: > Dear Zeus no. Find can be defined as: > def find(self, test=lambda x:1): > try: > item = (s for s in iter(self) if test(s)).next() > except StopIteration: > raise ValueError('No matching items in list') I would prefer that a find() operation return as soon as it locates an item that passes the test. This generator version tests every item. -- 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 fakeaddress at nowhere.org Fri Aug 12 00:44:17 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 04:44:17 GMT Subject: Regular expression to match a # In-Reply-To: <42fbda18@news.eftel.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> <42fbb9a9$1@news.eftel.com> <1123799252.257355.158320@f14g2000cwb.googlegroups.com> <42fbd1a1$1@news.eftel.com> <42fbda18@news.eftel.com> Message-ID: John Machin wrote: [...] > Observation: factoring out the compile step makes the difference much > more apparent. > > >>> ["%.3f" % t.timeit() for t in t3, t4, t5, t6] > ['1.578', '1.175', '2.283', '1.174'] > >>> ["%.3f" % t.timeit() for t in t3, t4, t5, t6] > ['1.582', '1.179', '2.284', '1.172'] > >>> To make it even more apparent, try: import re import profile startsz = re.compile('^z') for s in ('x' * 1000, 'x' * 100000, 'x'*10000000): profile.run('startsz.search(s)') Profile report is below. > Conclusion: search time depends on length of searched string. > > Meta-conclusion: Either I have to retract my > based-on-hope-rather-than-on-experimentation assertion, or redefine "not > dopey" to mean "surely nobody would search for ^x when match x would do, > so it would be dopey to optimise re for that" :-) No question, there's some dopiness to searching for the beginning of the string at places other than beginning of the string. The tricky part would be optimizing '$'. -- --Bryan 4 function calls in 0.003 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 :0(search) 1 0.003 0.003 0.003 0.003 :0(setprofile) 1 0.000 0.000 0.000 0.000 :1(?) 0 0.000 0.000 profile:0(profiler) 1 0.000 0.000 0.003 0.003 profile:0(startsz.search(s)) 4 function calls in 0.002 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.002 0.002 0.002 0.002 :0(search) 1 0.000 0.000 0.000 0.000 :0(setprofile) 1 0.000 0.000 0.002 0.002 :1(?) 0 0.000 0.000 profile:0(profiler) 1 0.000 0.000 0.002 0.002 profile:0(startsz.search(s)) 4 function calls in 0.228 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.228 0.228 0.228 0.228 :0(search) 1 0.000 0.000 0.000 0.000 :0(setprofile) 1 0.000 0.000 0.228 0.228 :1(?) 0 0.000 0.000 profile:0(profiler) 1 0.000 0.000 0.228 0.228 profile:0(startsz.search(s)) From hancock at anansispaceworks.com Wed Aug 24 21:05:50 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 24 Aug 2005 20:05:50 -0500 Subject: Newbie question: Sub-interpreters for CAD program In-Reply-To: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: <200508242005.50719.hancock@anansispaceworks.com> On Wednesday 24 August 2005 03:48 pm, sonicSpammersGoToHellSmooth wrote: > In my case I'd like to write a CAD program which allows the user to > write Python scripts, and to provide an API to do CAD stuff, manipulate > parameters, circuits, layouts, simulations, etc. The user should not > have access to the internals of the CAD program itself. The CAD > program is written primarily in Python, with possibly C++ extensions > for speed critical stuff. This is a straightforward case of "embedding Python". You'll want to google for that and do some research on it. You could also choose to make your CAD program a library, and use Python to control it, accessing the C/C++ layer via something like Pyrex. That's a fundamental design decision obviously. > There is another posting currently asking about how many interpreters > are needed with how many thread states each. Since this is new to me, > can someone please explain how this sort of thing is "supposed" to > work, from a high level? Frankly, I can't imagine why a script in a CAD program would need to use threads at all. Keep it simple (here I'm assuming that the heavy-lifting is done by your C++ code, so Python wouldn't have need of such optimizations). > I have a strong EE and hardware background (hence my need to write a > CAD program that doesn't piss me off), but not a CS background. Cool. If you do write it and release it, I'd be interested in finding out about it. You probably ought to consider starting with something existing like the Gnu EDS project -- but I'm assuming you probably already know about that. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From torched_smurf at yahoo.com Thu Aug 18 21:12:32 2005 From: torched_smurf at yahoo.com (torched_smurf at yahoo.com) Date: 18 Aug 2005 18:12:32 -0700 Subject: Module Name Conflicts In-Reply-To: <1124408324.310617.198340@z14g2000cwz.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> <1124408324.310617.198340@z14g2000cwz.googlegroups.com> Message-ID: <1124413952.401306.168240@g47g2000cwa.googlegroups.com> ncf wrote: > Maybe what you're looking for is __import__()? Okay, actually this does work, but only in one direction. That is, I can import the python package first, and then the java package, but not the other way around. -------------------------------------------------------------- Importing the python cmd first: $~> jython Jython 2.2a1 on java1.4.2_08 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> __import__('cmd') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ python package >>> import sys >>> sys.path.insert(0, java_classpath) >>> sys.modules.clear() >>> __import__('cmd') ^^^^^^^^^^^^^^^^^^^^ java package -------------------------------------------------------------- Importing the java cmd first: $~> jython Jython 2.2a1 on java1.4.2_08 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, java_classpath) >>> __import__('cmd') ^^^^^^^^^^^^^^^^^^^^ java package >>> sys.path = sys.path[1:] >>> sys.modules.clear() >>> __import__('cmd') ^^^^^^^^^^^^^^^^^^^^ java package, again -------------------------------------------------------------- Very odd. -Smurf From fredrik at pythonware.com Thu Aug 11 04:08:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 11 Aug 2005 10:08:24 +0200 Subject: Unicode regular expressions -- buggy? References: <8ACKe.1469$Rm3.756@bignews4.bellsouth.net> Message-ID: Christopher Subich wrote: > I don't think the python regular expression module correctly handles > combining marks; it gives inconsistent results between equivalent forms > of some regular expressions: > Is this a limitation-by-design, or a bug? limitation by design. if you want correct results, make sure to use early normalization everywhere. cf. http://www.w3.org/TR/charmod-norm/ From nd51 at le.ac.uk Wed Aug 10 04:32:40 2005 From: nd51 at le.ac.uk (N.Davis) Date: Wed, 10 Aug 2005 09:32:40 +0100 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> Message-ID: <42F9BBA8.1060800@le.ac.uk> Thanks very much for your helpful replies. I totally accept my C++/Java background is a lot of this, and I need to make the shift to Python's way of thinking. As for multiple inheritance, yes I've always been aware of it being available in C++, but I learned C++ at a company which banned multiple inheritance in their coding standards, with comments about "The GOTO of the 1990s". Like people here, I've no complaints about not using multiple inheritance. ;-) But Zope/Plone uses it therefore I have to understand it... Functions existing in a module? Surely if "everything is an object" (OK thats Java-talk but supposedly Python will eventually follow this too) then there should be nothing in a module thats not part of a class. Even a static method is simply a class function that operates on the "collection of all instances" rather than a single instance. Related classes in the same file? Be careful. Doesn't anything "knowing" about anything else compromise encapsulation? Why would properly-designed classes have such a close relationship? Having back in the day worked on big real-time systems where being very strict about encapsulation was a god-send for fighting complexity, I feel unnerved by Perl and Python's laid-back OO culture of "you can do it if you feel like it but don't have to". While you could do all manner of nasty hacks in C++ I worked with people who carefully avoided this. Maybe that was just luck.... Thanks again. Python is great anyway. :-) Nick > > > One reason is that functions need a place to exist too. In Java, every > function, even "static" ones has to be a class method. In Python, > "static" functions are best kept in a module. Another thing is that > packages were a later addition to the language. > > >>To my mind, although one CAN put many classes in a file, it is better to >>put one class per file, for readability and maintainability. > > > Personally I find it easier to maintain a set of related classes when > they're all in the same file. I've got a few modules that I'm > currently hacking on, each of which contains a handful of classes. > Maybe it's just a matter of scale, since these are both fairly small > libraries, but I just don't see any advantage to splitting them up into > multiple files. > > >>One can then create packages and libraries, using groups of files, one >>class per file. > > > Since Java's compiler enforces this, perhaps you've just come to accept > it as "normal". > > >>Python seems to let you group classes together in one file and call it a >>module, but what for? > > > What if one of your classes creates/manipulates other classes. If > they're in the same module then they all exist in the same namespace > and you don't have to have modules importing each other or such things. > > >>I find that this, combined with mixins, makes it difficult to find out >>where code is inherited from. > > > Perhaps you are relying too much on inheritance, then? > > >>With single inheritance in C++ or Java, if you wanted to see what a >>method did and it appeared to be inherited, you would simply look in the >>base class's file, and if necessary recurse up the inheritance hierarchy >>until you found the method. >> >>With Python an inherited method could be in one of many base classes >>and/or mixins and there seems no particular logic as to what the >>filename would be. > > > It shouldn't be too hard to figure out, unless someone was being > intentially vague. You could always fire up the interpreter, import > your class, and check it's .mro property (method resolution order), > which lists the classes in the order they will be examined to find a > method named at runtime. > > >>Am I missing something? > > > I just think you're thinking in terms of Java. You'll pick things up > quickly, though :-) > From wenming_hu2002 at hotmail.com Fri Aug 12 07:07:53 2005 From: wenming_hu2002 at hotmail.com (Wen) Date: Fri, 12 Aug 2005 19:07:53 +0800 Subject: how do i make exteranl module work under debug session? Message-ID: Hi guys! I'm writing a small DLL thingy that requieres the use of loading the Python interpreter and executing a series of scripts. I have generated an interface to my dll with SWIG and put it in. It works like this: 1) a small .exe loads the .dll and calls the main init() function 2) the dll starts up some services, among them Py_Initialize () 3) i tell python to execute: execfile("kikura.py") (kikura.py is the file that SWIG generates for the shadow classes) All this works in the release version, but in the debug version i get this error message along with an assert failure: Fatal Python error: Interpreter not initialized (version mismatch?) Now, this might due to a fault of mine, but... The thing is that the windows installer of python didn't come with debug libraries or .dll, so i downloaded the python source, and compiled those, and am using those for the debug, but the original instalation ones for release version. Can anyone help? Thanx From uval at rz.uni-karlsruhe.de Fri Aug 5 16:50:16 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-15?Q?Daniel_Sch=FCle?=) Date: Fri, 05 Aug 2005 22:50:16 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: [...] > I am aware of the usage of argument to mean the angle in polar > representation, but I don't like it. The word argument already has two > other meanings, one in common English, the other in math/CS. The latter > meaning is the inputs to a function, and that is how the word is used in > Python (though the former applies more to many c.l.p threads ;-) To me, > the polar angle has no connection with either meaning and so the usage is > 'like Greek' to me. Whereas angle is exactly what it is. .angle() would be also alright, as it is easy to grasp > As for Greek: I first learned r(adius),theta (versus x,y or real,imag) as > the names for polar coordinates or the polar representation for complex > numbers and only ran into arg much later in some contexts. And I have seen > complex number implementations that use the equivalent of c.r() and > c.theta(). But I did not suggest that for one of the reasons I don't like > 'lambda': its fine if you already know it and arbitrary if you don't. (Is > theta used in Germany?) yes, of course the entire mathematic is full of them :) as for the complex numbers, in our lessons we used R(adius) and Phi for the angle for polar representation I guess it's more a question of teacher's preference than a national norm From mekstran at scl.ameslab.gov Wed Aug 31 09:14:30 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Wed, 31 Aug 2005 08:14:30 -0500 Subject: .pth files in working directory In-Reply-To: References: Message-ID: <20050831081430.0a070e67.mekstran@scl.ameslab.gov> On Wed, 31 Aug 2005 15:07:41 +0200 Peter Maas wrote: > I want a tree > > top/ > install.py > sub1/ > __init__.py > mod1.py > sub2/ > mod2.py > > where I can do "from sub1 import mod1" in mod2.py no matter what the > absolute path of top is. To achieve this I start install.py once to > retrieve the absolute dir of itself (= abspath of top/) and creates > .pth files with its absolute dir in every subdirectory. If top/ is the working directory for your Python interpreter, the problem is solved automatically. Python puts the current working directory in the default search path. So, if you run python sub2/mod2.py then it would work. HTH, -Michael From kuljo at freemail.hu Mon Aug 29 20:56:43 2005 From: kuljo at freemail.hu (Kuljo) Date: Tue, 30 Aug 2005 02:56:43 +0200 Subject: new line References: Message-ID: Kuljo wrote: > Dear friends > I'm so sorry to bore you with this trivial problem. Allthou: I have string > having 0x0a as new line, but I should have \n instead. > How should I solve it? > I've tried >>>>text_new=tex_old.replace(str(0x0a), '\n') > and other things, but none of them worked. > Thanks in advance I have found this in the meantime: >>>nl="\\"+"n" >>>text_new=replace(text_old, chr(10), nl) It works. From geskerrett at hotmail.com Sun Aug 28 09:22:24 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 28 Aug 2005 06:22:24 -0700 Subject: Converting from Microsoft Binary Format floats to Python Float In-Reply-To: <430faf6d.2509167041@news.oz.net> References: <1125068126.386967.194750@o13g2000cwo.googlegroups.com> <430faf6d.2509167041@news.oz.net> Message-ID: <1125235344.653081.286880@g44g2000cwa.googlegroups.com> Well, thank-you again. It's a bit embarassing, but you are correct ... It was a typo on in the sample data. A bit frustrated with myself as I checked, and double checked, but I guess became a bit blinded to the problem. Sorry to waste your time, and appreciate your assistance and patience. Geoff. From Aiwass333 at gmail.com Sat Aug 6 11:03:59 2005 From: Aiwass333 at gmail.com (RunLevelZero) Date: 6 Aug 2005 08:03:59 -0700 Subject: How to use DrPython plugins References: Message-ID: <1123340639.474121.17060@g14g2000cwa.googlegroups.com> Well I think you should post in this forum and you will get your answer more quickly. http://sourceforge.net/forum/?group_id=83074 I'm not sure which version you are using? The developer for DrPython is rather busy right now but someone else there might be able to help you a bit more than me. Have you tried using the period for code completion? That works fine for me. I use alt enter for find and complete. It almost sounds like you should manually remove the plugins you have installed and reinstall them. Did you download the plugins manually or did you use the plugin installer? From geskerrett at hotmail.com Tue Aug 9 16:45:52 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 9 Aug 2005 13:45:52 -0700 Subject: Does any one recognize this binary data storage format In-Reply-To: <11fi4piovsrgoe1@corp.supernews.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> Message-ID: <1123620352.605259.228860@o13g2000cwo.googlegroups.com> Yes I double checked as I appreciate any help, but that is what is stored on disk. If it helps, we modified Ex#3. to be 777-777-7777 On disk this is now 00 00 10 87 77 F9 Fc 41 All the input fields are filled in this new example. From resolve at repose.REMOVE.cx Wed Aug 24 15:40:41 2005 From: resolve at repose.REMOVE.cx (Damien Elmes) Date: Thu, 25 Aug 2005 04:40:41 +0900 Subject: setlocale() in a module/extension library References: <873bp0pif9.fsf@mobile.repose.cx> <430b9798$0$20386$9b622d9e@news.freenet.de> Message-ID: <87ll2rnmx2.fsf@mobile.repose.cx> "Martin v. L?wis" writes: > IOW: feel free to invoke setlocale in your library. It will likely > work in many cases, but may break in some. So you should atleast > document that this is what your library does. Thanks for the advice. I ended up implementing it in the library, with an option to disable it and a note in the documentation directing people to call setlocale() manually if they run a threaded application, or if they wish to set up their own locale. Thanks again, Damien From renting at astron.nl Thu Aug 25 11:06:54 2005 From: renting at astron.nl (Adriaan Renting) Date: Thu, 25 Aug 2005 17:06:54 +0200 Subject: variable hell Message-ID: You might be able to do something along the lines of for count in range(0,maxcount): value = values[count] exec(eval("'a%s=%s' % (count, value)")) But I am also wonder: why? Peter Maas wrote: > >>>suffix = 'var' > >>>vars()['a%s' % suffix] = 45 > >>>avar >45 From aahz at pythoncraft.com Thu Aug 11 20:08:23 2005 From: aahz at pythoncraft.com (Aahz) Date: 11 Aug 2005 17:08:23 -0700 Subject: The python license model References: Message-ID: In article , Ramza Brown wrote: > >Can you distribute a python system with only a couple of libraries that >you plan to use. For example, I generally avoid having a system with >hundreds of loose scripts(ie python library). So, I have considered >only taking the libraries I need. My question, is python license >friendly for doing this? Dunno what you mean by "friendly", but aside from some little gotchas having to do with its storied history, you can consider Python's license functionally equivalent to BSD/MIT/Apache. IOW, do whatever you want, as long as you keep the copyright around. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From peter at somewhere.com Wed Aug 31 05:47:02 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 11:47:02 +0200 Subject: Python doc problems example: gzip module In-Reply-To: <1125477977.072146.298670@g47g2000cwa.googlegroups.com> References: <1125477977.072146.298670@g47g2000cwa.googlegroups.com> Message-ID: Xah Lee schrieb: > today i need to use Python to decompress gzip files. > > since i'm familiar with Python doc and have 10 years of computing > experience with 4 years in unix admin and perl, i have quickly located > the official doc: > > http://python.org/doc/2.4.1/lib/module-gzip.html > > but after a minute of scanning, please someone tell me what the fuck is > it talking about? > > Fuck the Python programing morons. > > Thanks. > > I just need to decompress files. Is it: > > import gzip; > gzip.GzipFile("/Users/xah/access_log.1.gz"); > > can someone put a example into that fucking doc so that people don't > have to wade thru whatever fuck it is trying to sound big? Here's the example: import gzip # read fucked fuckedfile = gzip.GzipFile('somefile.gz') content = fuckedfile.read() fuckedfile.close() # write unfucked unfuckedfile = file('somefile','w') unfuckedfile.write(content) unfuckedfile.close() Please feel free to insert this fucking example into the fucking docs. Have a nice ... eh fucking day :) -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From eurleif at ecritters.biz Tue Aug 9 23:26:46 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Wed, 10 Aug 2005 03:26:46 GMT Subject: Bizarre error from help() In-Reply-To: References: Message-ID: Roy Smith wrote: > No, that works fine. But, now I can't even reproduce the error I reported > earlier (when I try, I get the help message as expected). And, yes, that > was with a brand new interpreter session. Strange. Perhaps you were running Python from a directory with a file called string.py? From apardon at forel.vub.ac.be Tue Aug 23 04:03:32 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 Aug 2005 08:03:32 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-22, Magnus Lycka schreef : > Antoon Pardon wrote: >>>Python doesn't guess. There are a range of values that will be treated, >>>in a Boolean context (how perlish) as equivalent to False. >> >> Yes it does. > > No it doesn't! > >> Python has no way to know what would be the most >> usefull Boolean interpretation of these values in a particular >> context. > > It's hardly the task of the interpreter to try to do that. Indeed ir is not, so the interpreter should not pretend it can by providing a Boolean interpretation. >> That it picks one out is guessing. > > No, it simply follows a well defined specification. > See http://docs.python.org/ref/Booleans.html > There is no guessing involved in that. Following a well defined specification is not contradictory to guessing. It may just mean that the guess was formalized into the specification. >> Lisp imterprets >> an empty list as false, scheme interprets it as true. So >> both seem usable interpretations. > > You might argue that *Guido* was guessing when he decided what > the most useful behaviour of Python would be in this case, and > there's probably some truth in that, just as there is some > guesswork involved in most programming language design decisions, > but that's another thing. That's not Python guessing, it's > Guido using his excellent lanugage design skills. It seems most > Python programmers agree that he "guessed" right here, as usual. I don't see a big difference. Guessing plays its roles when different people can have different expectations in cases where not all the details are known/specified. Whether that is in the language design or in program design doesn't make a big difference and I would expect that a language that discourages guessing in the software that its written in it, would follow its own rules in its design. > (Perhaps you thought that "Python" was the name of the language > designer. It's not. Python's design is led by Guido van Rossum, > and the name Python comes from a (mostly) British comedy group.) > > You might also argue that this behaviour is counter to the > Python dogma of "explicit is better than implicit". Python also > allows you to get a float out of an expression such as "2*3.1" > without forcing an explicit cast, as in "float(2)*3.1". > > You should note that the first Python tenet is "Beautiful is > better than ugly" and that's probably what we have to blame here. > > There seems to be close to a consensus, that "if users:" is more > beautiful than e.g. "if len(users) > 0:" or > "if (len(users)==0)==False" or for that matter > "if ((len(users)==0)==False)==True" or > "if (((len(users)==0)==False)==True)==True" etc. Well then I must say people here give beauty too high a priority. Because there seems a tendency to beautify others code when snippets are posted here. Often enough such snippets don't give enough inoformation to know whether "if var is True:" can be replaced by "if var:" or whether other beautifications are appropiate. > What's true and false for Python, belongs to the few things you > actually have to learn, and I can appreciate that it's annoying > for a frequent schemer to remember that it's not the same in > Python, but it seems that very few people argue with the way > Python behaves in this respect. I care very little for what someone with experience in an other language can expect. I care about the consistence of the language and the programs written in it. I just mentioned scheme to show that [] interpreted as false is not so obvious as a lot of people seem to think. Since there are situations where using '', (), [] or 0 as false would be not appropiate I advise against using them as such, because you never know when your software that does has to cooperate with software that doesn't. -- Antoon Pardon From zen19725 at zen.co.uk Wed Aug 3 08:31:33 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 13:31:33 +0100 Subject: Art of Unit Testing References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: On Tue, 02 Aug 2005 21:26:28 +0200, Christoph Zwerschke wrote: >Bj?rn Lindstr?m wrote: >>>Would it make sense to add "globaleSetup" and "globalTearDown" methods >>>to the TestCase class? >> In general that's not such a good idea. > >I completely agree and I think it makes a lot of sense that unittest >calls setUp and tearDown for every single test. However, the fact that >this is *generally* the best way doesn't exclude the fact that there are >*exceptions* when it makes sense to setUp and tearDown not for every >test, e.g. when it is absolutely sure that the fixture cannot be >destroyed by the individual tests or when creating the fixture takes too >much time. I already gave the example of creating database connections >or even creating/importing whole databases. My question was, how do I >handle these cases with the standard lib unittest? > >According to the "extreme programming" paradigm, testing should be done >several times a day. So a requirement for extreme programm is that tests >are fast enough. If the testing needs too much time, people are >discouraged to test often. Indeed. Running the tests should ideally take less than a few seconds. Any longer, and people won't use them so often. -- Email: zen19725 at zen dot co dot uk From varghjarta at gmail.com Thu Aug 4 03:50:55 2005 From: varghjarta at gmail.com (=?ISO-8859-1?Q?Varghj=E4rta?=) Date: Thu, 4 Aug 2005 15:50:55 +0800 Subject: Invoke a method to a specific thread In-Reply-To: References: Message-ID: On 25/07/05, Diez B.Roggisch wrote: > Varghj?rta gmail.com> writes: > > > If I have "GUIClass":... > > And start another thread and from that thread I want to call the > > method "PaintSomething()" in "GUIClass" _in_ the same thread that > > "GUIClass" lives in. > > There is no such thing in python, or any programming language for that matter. Not exactly sure what you mean, what would you call the ability to sort of, push a method call onto a thread like Invoke() in C# for example. Even if underneath the clean surface it posts the call into the message loop it gets the job done. > However, in GUIs there is usually some so called event-loop. And for the > task you have in mind you need a way to insert a custom event into that loop > that will be executed the next time that gui thread is idle. > Qt uses QCustomEvents for this. Swing has it's SwingUtilities.invokeLater > > http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html#invokeLater > > and others have different means. So - whatever GUI you use, > it depends on that what to do. Yeah, I've been playing around with WX and find it to be the best GUI layer for python, I belive it has some way of dealing with it. But lets say i'm not using a GUI. Or rather, for example in my WxPython application I have classes which needs to perform time consuming operations. I would _really_ not want to include lots of WX-stuff in an otherwise purely python class. I don't like mixing GUI code with other code, it feels very dirty. How would a python programmer(more experienced then I currently am) solve this? Should I implement some kind of message-loop-system in the class which the different threads "posts" to, and then the class(which is in the right thread) deals with any events "posted"? I'm spoiled from C# having everything delivered to me, so I'm confused as to how much I need to implement myself. Thinking perhaps there was some cute special python command I could use to do it for me :) P.S. Currently traveling far from home(but still I have programming on me brain), sorry for the delayed reply. From benji at benjiyork.com Tue Aug 2 15:13:51 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 02 Aug 2005 15:13:51 -0400 Subject: a pickle's pickle In-Reply-To: <1123003411.326539.300220@g47g2000cwa.googlegroups.com> References: <1122998518.750304.191860@g44g2000cwa.googlegroups.com> <1123003411.326539.300220@g47g2000cwa.googlegroups.com> Message-ID: <42EFC5EF.505@benjiyork.com> temposs at gmail.com wrote: > So basically trainer always gets an existing TrainingMatrix(the class) > pickled object if there is a file to read from, otherwise it just makes > a new instance. Either way, the instance trainer is pickled at the end. Right, but the data you're interested in is contained in the class, not the instance. You need to move the mutable class attributes into the instance. Like so: class TrainingMatrix: totalWordsProcessed = 0 numWords = 0 numContexts = 0 matrixWords = 0 def __init__(self): self.matrix = [] self.estimator = {} self.wordInfo = {} self.contextInfo = {} -- Benji York From martin at v.loewis.de Thu Aug 11 02:01:39 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 11 Aug 2005 08:01:39 +0200 Subject: Python-2.4.1 Build error on AIX In-Reply-To: References: Message-ID: <42fae9c3$0$14036$9b622d9e@news.freenet.de> Srinivasan TK wrote: > I get the below error when trying to build python on > AIX. > > Is there a way to ignore _tkinter. Yes. Just ignore these error messages. Regards, Martin From en.karpachov at ospaz.ru Wed Aug 10 14:04:05 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Wed, 10 Aug 2005 22:04:05 +0400 Subject: "Compile time" checking? In-Reply-To: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: <20050810220405.1ea058cb.jk@ospaz.ru> On 10 Aug 2005 08:53:15 -0700 Qopit wrote: > def tester(a,b,c): > print "bogus test function",a,b,c > tester(1,2,3) #this runs fine > tester(1,2) #this obviously causes a run-time TypeError exception /tmp% cat >a.py def tester(a,b,c): print "bogus test function",a,b,c tester(1,2,3) #this runs fine tester(1,2) #this obviously causes a run-time TypeError exception /tmp% pychecker a.py Processing a... bogus test function 1 2 3 Caught exception importing module a: File "/usr/lib/site-python/pychecker/checker.py", line 587, in setupMainCode() module = imp.load_module(self.moduleName, file, filename, smt) File "a.py", line 4 tester(1,2) #this obviously causes a run-time TypeError exception TypeError: tester() takes exactly 3 arguments (2 given) Warnings... a:1: NOT PROCESSED UNABLE TO IMPORT /tmp% pychecker -V 0.8.14 -- jk From python at hope.cz Fri Aug 12 02:22:53 2005 From: python at hope.cz (Lad) Date: 11 Aug 2005 23:22:53 -0700 Subject: Where can be a problem? Message-ID: <1123827773.392501.155760@z14g2000cwz.googlegroups.com> I use the following ############### import re Results=[] data1='' ID = re.compile(r'^.*=(\d+)&.*$',re.MULTILINE) Results=re.findall(ID,data1) print Results ############# to extract from data1 all numbers such as 15015,15016,15017 But the program extracts only the last number 15017. Why? Thank you for help La. From pinard at iro.umontreal.ca Fri Aug 26 10:36:28 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Fri, 26 Aug 2005 10:36:28 -0400 Subject: Fighting Spam with Python In-Reply-To: References: Message-ID: <20050826143628.GA11591@phenix.progiciels-bpi.ca> [David MacQuigg] > Getting these methods widely and effectively used is our big > challenge, and one that I hope to accomplish with my efforts. I wish one of these methods, either yours or one of these few others which were developed and proposed in the recent years, will succeed. It might be useful, for someone involved like you are (thanks for all of us!), that you make a survey of those others, trying to understand why they failed to acquire popularity, not repeating the same errors if any. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From peter at engcorp.com Tue Aug 30 21:23:39 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 30 Aug 2005 21:23:39 -0400 Subject: Yielding a chain of values In-Reply-To: <4314e9fe.188467011@news.oz.net> References: <4314bf65.177562962@news.oz.net> <3nk0e4F1snjcU2@individual.net> <4314e9fe.188467011@news.oz.net> Message-ID: Bengt Richter wrote: > On Tue, 30 Aug 2005 23:12:35 +0200, Reinhold Birkenfeld wrote: >>Bengt Richter wrote: >>>Maybe >>> yield in inner() >>> >>>could be sugar for the above and become something optimized? >> >>The problem here is that yield isn't a statement any more. It's now an >>expression, so it is not easy to find new syntax around it. > > No, the idea was that it's still a statement, but what it > yields is "in inner()" which UIAM is illegal now, and would > signify "whatever sequence of elements is in inner()" -- > really yield in seq -- I don't know what inner() was, but I assumed > an iterable. I believe he was referring indirectly to http://www.python.org/peps/pep-0342.html (see item #1 in the "Specification Summary" section), where yield will become an expression. This PEP has been accepted, thus his use of present tense, confusing though it is when it's not in the released version of Python yet. Or I might be wrong. ;-) -Peter From s4somesh at gmail.com Mon Aug 8 08:47:13 2005 From: s4somesh at gmail.com (Somesh) Date: 8 Aug 2005 05:47:13 -0700 Subject: listing users in Plone In-Reply-To: <1123176326.920163.20610@g43g2000cwa.googlegroups.com> References: <1123164257.211224.66710@g14g2000cwa.googlegroups.com> <1123176326.920163.20610@g43g2000cwa.googlegroups.com> Message-ID: <1123505233.002217.61570@g49g2000cwa.googlegroups.com> plz let me know the proper google group From geskerrett at hotmail.com Tue Aug 9 15:57:02 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 9 Aug 2005 12:57:02 -0700 Subject: Does any one recognize this binary data storage format In-Reply-To: References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> Message-ID: <1123617422.783846.62590@g44g2000cwa.googlegroups.com> the extension on the files is *.mas but I a pretty sure it is not relevant. I beleive it used by the application. I can posted records as it will take up to much space. But all three phone numbers are stored in 8 bytes with null bytes (ie. 00) stored in the leading positions (ie. the left hand side) I do have some more examples; I have inserted the leading null bytes and seperated with spaces for clarity. Ex #1) 333-3333 Hex On disk: 00 00 00 80 6a 6e 49 41 Ex #2) 666-6666 Hex On disk: 00 00 00 80 6a 6e 59 41 Ex#3) 777-7777 Hex On Disk: 00 00 00 40 7C AB 5D 41 Ex#4) 123-4567 Hex On Disk: 00 00 00 00 87 D6 32 41 Ex#5) 000-0001 Hex On disk: 00 00 00 00 00 00 F0 3F Ex#6) 999-9999 Hex On disk: 00 00 00 E0 CF 12 63 41 From gnb at itga.com.au Tue Aug 23 01:40:51 2005 From: gnb at itga.com.au (Gregory Bond) Date: Tue, 23 Aug 2005 15:40:51 +1000 Subject: loop in python In-Reply-To: References: Message-ID: <3tceed.d55.ln@lightning.itga.com.au> km wrote: > Is python runtime slow at all aspects when compared to perl ? And in addition to all that everyone else has said.... most of this is startup time. The python interpreter is a fair bit slower to start up (i.e. does much more at startup time) than the perl one: > lenford$ time python -c "pass" > > real 0m0.298s > user 0m0.030s > sys 0m0.030s > lenford$ time perl -e "0" > > real 0m0.037s > user 0m0.000s > sys 0m0.000s [on a fairly fast Solaris box]. This is mainly because much more of python is written in python and needs to be loaded / dynamically linked when the process starts up. On my system, python loads 14 .so files and 13 .pyc files. Perl loads 7 .so files. From reinout at cs.vu.nl Wed Aug 3 05:21:26 2005 From: reinout at cs.vu.nl (Reinout van Schouwen) Date: Wed, 3 Aug 2005 11:21:26 +0200 Subject: pygettext ? In-Reply-To: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: Hi, On Wed, 3 Aug 2005, cantabile wrote: > Hi, I'm trying to write an internationalized app. I'm learning python and > read that pygettext would help me, but I found elsewhere it was obsolete (??) > So, what's the correct and up to date tool to i18n python ? Short answer: the functionality of pygettext has been incorporated in the main gettext tool, so pygettext is obsolete. regards, -- Reinout van Schouwen *** student of Artifical Intelligence email: reinout at cs.vu.nl *** mobile phone: +31-6-44360778 www.vanschouwen.info *** help mee met GNOME vertalen: nl.gnome.org From mrosenstihl at t-online.de Tue Aug 16 15:09:47 2005 From: mrosenstihl at t-online.de (Markus Rosenstihl) Date: Tue, 16 Aug 2005 21:09:47 +0200 Subject: GUI tookit for science and education References: <11g23l4mq5ftvcb@corp.supernews.com> Message-ID: >> It doesn't have much math built in. For functions you have to >> plot points. > > If you want to plot stuff, the gnuplot-py module is very easy > to use. http://sourceforge.net/projects/gnuplot-py/ > > The one feature that I'd really like to add is the ability to > plot a python function object. Currently you can plot a > function specified by a string (e.g. "sin(x) * sin(x)**2"), or > a sequence of data points. It would be nice to be able to pass > an actual function. matplotlib is also ver good possibility From could.net at gmail.com Mon Aug 29 22:59:33 2005 From: could.net at gmail.com (could ildg) Date: Tue, 30 Aug 2005 10:59:33 +0800 Subject: [Jython-users] Re: [Jython-dev] Parsing grammar for jython available (compatible with python 2.4) In-Reply-To: <4dab5f7605082917112bbdf0a7@mail.gmail.com> References: <43130287.7030200@esss.com.br> <4dab5f7605082917112bbdf0a7@mail.gmail.com> Message-ID: <311b5ce105082919592d4b0099@mail.gmail.com> thanks. pydev is very nice, I like it. But sometimes the code completion will not work. On 8/30/05, Frank Wierzbicki wrote: > > > The code, as well as the files for javacc and asdl (both were changed) > > are available in the pydev cvs at sourceforge, in the > > org.python.pydev.parser module (the packages should be the same jython > > uses -- org.python.parser and org.python.parser.ast). > > > > The tests I used are available in the tests source folder > > (org.python.pydev.parser.PyParserTest) > > Hey -- that's great! > Unfortunately we probably will not be able to integrate 2.4 features in > until after we get a 2.3 version stable... But I hope you can remind us of > this work (or I can remember it) when we do get to that point. If you want > to leave a strong reminder you could submit your changes as a patch -- but I > mean this as only the gentlest of nudges since it will likely be quite a > while before we could really look at it. > > Thanks, > Frank > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Aug 31 00:37:27 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Aug 2005 23:37:27 -0500 Subject: Jargons of Info Tech industry In-Reply-To: References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: <43153407.8070500@holdenweb.com> [Top-posted to try and stop this nonsense]. Two things: Firstly, you are both playing right into Xah Lee's stupid game by continuing to bicker at each other on a thread that shouldn't have lasted more than two posts. Secondly, if you don't both shut up I'll come over there and knock your bloody heads together. This kind of unpleasant nonsense is so far away from the norm on c.l.py that you are both creating a nuisance. Either start acting like grown-ups or kindly take this squabble to email and give the rest of us a break. Or you'll have to stay inside for the rest of playtime. And before either of you asks, yes, I am speaking for the group even though nobody has given me the right (or even asked me) to do so. When will Thunderbird get kill files, I wonder? you're-a-troll-no-you're-a-troll-ly y'rs - steve John Bokma wrote: > Mark McIntyre wrote: > > >>On 30 Aug 2005 18:06:48 GMT, in comp.lang.c , John Bokma >> wrote: >> >> >>>Mark McIntyre wrote: >>> >>> >>>>Its a complete mystery. Just as is the reason why you are x-posting >>>>complete garbage to comp.lang.c... >>> >>>A similar mystery as in why Mark clueless n00b II McIntyre thinks it's >>>a good idea to cross post to all other groups except comp.lang.c? >> >>I see you felt it appropriate to RE-post this offtopic garbage back >>into clc. >> >>You sir, are a troll, > > > No clueless n00b, you are a troll, or either too stupid to have a Usenet > account. > > >>and I'd claim my fiver if I could be arsed. >> >> > > > Exactly, you and your clueless buddy think you can make smart ass > statements. > > Either add something not brain dead to this thread, or let it go. As I > already explained to that other n00b, threads like this *can't* be > stopped, moved, controlled or what. The harder you try the longer it > takes for it to stop. Either ignore the whole thing, or make a useful > contribution which might make setting the FollowUp-To: header work (but > don't get angry if it's ignored). > > Now lets hope that the rest gets the point. Thanks. > -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From daniel.dittmar at sap.corp Tue Aug 2 04:27:34 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Tue, 02 Aug 2005 10:27:34 +0200 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <8ur1s2-r5t.ln1@strongwill.g2ctech> <3l7dl2F111tulU1@uni-berlin.de> Message-ID: Jorge Godoy wrote: > I agree where you say that lack of information is a risk. But I don't see > how it -- lack of information -- wouldn't affect both scenarios. At least, Because you put different probabilities on different outcomes. One easy 'risk markup' would be to assume that parts of the standard Python distribution like TkInter have a higher chance of working with the next release than external libraries like wxPython. Of course, there are lots of other possible criteria: - which has been under more active development in the last releases - which source code is easier to understand so that I don't have to rely on external help Daniel From john at castleamber.com Fri Aug 26 17:33:33 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 21:33:33 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> Message-ID: Rich Teer wrote: > On Fri, 26 Aug 2005, John Bokma wrote: > >> people from www to Usenet or vice versa is beyond me. If 80% of the >> current Usenet users stop posting, Usenet is not going to die :-D > > Heh. Quite the opposite, I reckon: it would get much better (higher > SNR)! :-) :-D. I recently contributed to a thread in which someone was afraid that Usenet was going to die, because he had the impression there where less people on it. There are more people on it compared to 20 years ago, when it was about to die (like every 2 years). -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From nospam at nospam.nospam Mon Aug 22 02:04:26 2005 From: nospam at nospam.nospam (Steve Jorgensen) Date: Sun, 21 Aug 2005 23:04:26 -0700 Subject: Sandboxes References: Message-ID: Clearly, Pyton does not directly offer any kind of useful security sandbox capability, but since Java does, I suppose JPython is an option. I know there are a lot of downsides to JPython, but it should be a genuine solution to the sandbox problem. On Sat, 20 Aug 2005 10:21:06 GMT, 42 wrote: >Hi, > >I'm extremely new to python, and am looking at using it as an embedded >script engine in a dotnet project I'm working on. I'm currently playing >with the "Python for Net" (http://www.zope.org/Members/Brian/PythonNet) >stuff, and it seems to work well. > >Googling for information on securing Python in a "sandbox" seems >indicate that there are some built in features, but they aren't really >trustworthy. Is that correct? > >For my purposes, I really just want to let users run in a sandbox, with >access to only the language, manipuate a few published objects in the >application (and perhaps give them some string and math libraries if >applicable). > >I was wondering if it would be effective to pre-parse incoming scripts >and reject those containing "import"? I'd also have the application >inject the (short) list of trusted imports to the script before passing >it to the interpreter. > >In theory I'm hoping this would mean script writers would have access to >the stuff they need and no way to add in anything else. > >Would this sufficient? Are there any drawbacks or giant gaping holes? >I'm anticipating that I'd also need to block 'exec' and 'eval' to >prevent an import from being obfuscated past the pre-parse. > >Or is this a hopeless cause? > >Finally, either way, would anyone recommend a different script engine >that might be more suitable for what I'm trying to accomplish that I >might not have looked at. I don't need much; it needs to work with C#, >and be able to easily interact with 'published' interface. I'd also like >to leverage a "popular" language instead of something obscure. > >I also looked at Javascript, but couldn't find a way to embed an >interpreter into a C# app. There's some CodeDom stuff with JScript, but >that seemed backwards...overkill; I don't really want to compile >temporary assemblies for hundreds of 2 and 3 line scripts... and the VSA >stuff has been marked deprecated with no apparent successor... seems >like I jumped into this at precisely the wrong time. :) > >Any thoughts, insights, or comments welcome. Forgive my lack of Python >savvy... I've only been playing with it for a few hours now; after >bumping into the "python for net" link. > >-regards, >Dave From newsgroups at jhrothjr.com Sat Aug 6 20:14:33 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 6 Aug 2005 18:14:33 -0600 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> <86br4avf5t.fsf@bhuda.mired.org> Message-ID: <11fakjctean9u8a@news.supernews.com> "Mike Meyer" wrote in message news:86br4avf5t.fsf at bhuda.mired.org... > "John Roth" writes: >> However. I see nothing in the existing Python 3000 PEP that does >> anything other than inspire a yawn. Sure, it's a bunch of cleanup, and >> some of it is definitely needed. > > Actually, that's pretty much *all* it is. I always figured it was a > warning about things that were liable to break, rather than a list of > new features that Python 3000 would incorporate. > > For those - well, if a change won't break existing code, why put it > off until Python 3000? I don't think I've seen *any* new features > proposed for Python 3000. It's to far in the future, so new features > are proposed in such a way that don't break current code. Interfaces > come to mind. > >> What I want to see in Python 3000 is an AST based language >> that lets the editors do the pretty printing. Do you want automatic >> indenting or would you prefer end statements? It's an editor formatting >> option. The AST neither knows or cares. Don't want to see self? >> Editor formatting option. The AST knows what scope each >> identifier belongs to because it's right there in the text. No need >> for rules that you have to learn, sometimes the hard way. > > I'm not sure what you mean by "AST based language". Google wasn't much > help, even in finding a definition for AST - it gets swamped by time > zones and company names. I think you mean abstract syntax tree, but > I'm not sure how you would go about basing a language on that. Care to > provide pointers? You got it. http://martinfowler.com/articles/languageWorkbench.html This shows one reason _why_ designing a language with the basic AST representation as primary may become a big deal. Maybe not, too. > >> Talk to people who've moved from Python to Ruby, or to >> some other language. Ask them why, if Python is so great, >> what's even greater in that other language. If you still don't >> understand, you might want to read this: >> >> http://martinfowler.com/bliki/CollectionClosureMethod.html > > I read it. I don't see what the big deal is. He praises collections > and closurs. Python has both. Ok, the closures are sucky, but you can > fake real one with classes. He likes anonymous blocks. There are a > couple of proposals floating around to add those to Python. There have been proposals to add them to Python for as long as I can remember. They have always been shot down. Vigorously. The basic issue here is neither the collection methods nor the closures. It's a compact yet readable syntax that puts them together. That's what one should get out of the Fowler piece: how nice it is to be able to do some rather common things compactly. All steps in that direction have always been resisted. > What I do see are a couple of collection methods (find and inject) > that would maken nice additions to the language. I've already posted a > suggestion to add them. > >> I find the notion that there should be one obviously right way >> to do something to be a good design principle, so why isn't >> there a single supported GUI library? If I'm over in Java-land, >> just about everything comes with a GUI. Python ships with a >> lot of little demonstration and utility scripts - none of which has >> a GUI. > > The standard library documentation only documents one GUI library. The > Python distribution includes one *large* example of GUI programming > with that library - IDLE. I agree that more examples and documentation > would be usefull, but I'm *not* the person to write them. And I never suggested you were. >> Why the jihad (and I'm using the word advisedly) >> against the map, filter and reduce operators? > > I'd say that LCs and GEs make map and filter redundant, thus violating > the principle of there being one obviously right way to do something > that you like. Reduce isn't as clear. Maybe we can get it replaced by > inject. You've got the horse harnessed backwards. The jihad against the "functional" operators was being conducted long before list comprehensions were in sight. The first action on that was to replace apply() with the * and ** notations in function/method definitions and calls. Guido has said (Python Regrets) that he regrets ever allowing them into the language. It's a jihad. > >> It seems to be completely irrational from my >> viewpoint. I've seen the arguements, and they >> make no sense. > > They make perfect sense to me. Either you like there's only one way > (obvious) to do it, or you don't. I've already explained that, if you want to invoke "only one way" then list and generator comprehensions are the violation since there were other ways of doing it. >> I'm not suggesting shooting at a moving target. I'm suggesting >> getting the head out of the sand, looking at trends, and figuring >> out the _large_ steps to take next, not the nickle and dime fixups >> that are the only things I see in PEP 3000. (Not to say that some >> of them aren't going to be a lot of work. Some of them are.) > > There are some large steps on the horizon. Interfaces (or maybe > Abstract Base Classes) are being considered for addition to the > language. http://www.artima.com/weblogs/viewpost.jsp?thread=92662 >. He just blogged on that yesterday; I'm going to have to look at it in detail. Not something to look at in the middle of composing a response. Please note that it's in terms of the Python 3000 framework, which should be noted in context of your first point at the top of this post. >> Another thing that stands out: the explicit versus dynamic typing debate >> has moved on from program correctness (which is a wash) to >> other areas that explicit (or derived) type information can be used >> for. I see this in PyFit: the languages where explicit type information >> is available by reflection have cleaner implementations. The languages >> with dynamic typing all have to deal with the fact that they can't get >> type information by reflection, and it's a diverse mess. > > There are people who strongly disagree that the programm correctness > issue is a wash. If you've got research to back that up, I'd love to > see it. It seems to be the concensus on this group anyway: declarative typing does not give enough improvement in program correctness to override more concise programs and TDD. That may, of course, be wishful thinking on the Python community's part. >> The world is moving on, in ways that I think you're not seeing. >> And Python is standing still in many of those same ways. > > I find it hilarious that this arrived at my news server the same day > that Peter Hansens rant (look for the subject "Syntax error after > upgrading to Python 2.4") about Python changing to fast did. You may find it hilarious. I find it kind of sad - painting oneself into a corner so that upgrades become a pain for the customer base is not a laughing matter. You might, by the way, find it equally amusing to look at what your arguements are supporting rather than just sniping at whatever happens to attract your attention. "I don't want it to change too fast" is the same as "Fat and happy", just in different words. John Roth > > -- > Mike Meyer http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more > information. From cam.ac.uk at mh391.invalid Sat Aug 20 04:52:05 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sat, 20 Aug 2005 09:52:05 +0100 Subject: Please Criticize My Code In-Reply-To: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> Message-ID: Ray wrote: > I just wrote a short script that generates look and say sequence. What > do you Python guys think of it? Too "Java-ish"? Yes, but that's beside the point. :) I think your basic design was sound enough for this application (presumably this isn't something that needs to run at high speed). I found it a little hard to understand what was going on. Part of this was due to variable and function naming choices. Converting between strs and ints all the time is confusing too. I think this version might be a little easier to understand, and describe() should work for any string, not just integers. I think your original version does as well: def describe(string): last_char = "" last_count = "" res = [] for char in string: if char == last_char: last_count += 1 else: res.extend([str(last_count), last_char]) last_char = char last_count = 1 res.extend([str(last_count), last_char]) return "".join(res) def describe_generator(start, count): string = str(start) for index in xrange(count): yield string string = describe(string) print list(describe_generator(1, 30)) As requested, here's a more concise, but difficult to understand version of describe() using regexes: import re re_describe = re.compile(r"(.)\1*") def describe(string): runs = re_describe.finditer(str(string)) return "".join("".join([str(len(run.group(0))), run.group(0)[0]]) for run in runs) While it is fewer lines of code, it's not as easy to see what this *thing* does immediately upon looking at it. So I'd try to avoid this version, really. -- Michael Hoffman From cyril.bazin at gmail.com Mon Aug 8 16:04:44 2005 From: cyril.bazin at gmail.com (Cyril Bazin) Date: Mon, 8 Aug 2005 22:04:44 +0200 Subject: Splitting a string into groups of three characters In-Reply-To: <1123524271.644157.52580@o13g2000cwo.googlegroups.com> References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> <1123524271.644157.52580@o13g2000cwo.googlegroups.com> Message-ID: Another solution derived from an old discussion about the same problem? def takeBy(s, n): import itertools list(''.join(x) for x in itertools.izip(*[iter(s)]*n)) (Hoping len(s) % n = 0) Cyril On 8 Aug 2005 11:04:31 -0700, lemon97 at gmail.com wrote: > > Yes i know i made a mistake, > >['Hell','o W','orl','d'] > but you know what I mean lol, > > I'll probly use > John Machin's > > def nsplit(s, n): > return [s[k:k+n] for k in xrange(0, len(s), n)] > > It seems fast, and does not require any imports. > > But anyways, thank you for all your help, you rock! :) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Tue Aug 30 14:30:35 2005 From: http (Paul Rubin) Date: 30 Aug 2005 11:30:35 -0700 Subject: micro-python - is it possible? References: <431440bb$1@news.orcon.net.nz> Message-ID: <7x1x4bz390.fsf@ruckus.brouhaha.com> Evil Bastard writes: > Has anyone done any serious work on producing a subset of python's > language definition that would suit it to a tiny microcontroller > environment? We just had this thread a few weeks ago and you decided to use FORTH that time. The answers are the same this time. From prabapython at yahoo.co.in Mon Aug 29 03:23:19 2005 From: prabapython at yahoo.co.in (praba kar) Date: Mon, 29 Aug 2005 08:23:19 +0100 (BST) Subject: Python built email message doesn't support OutLook Express Message-ID: <20050829072319.91227.qmail@web8409.mail.in.yahoo.com> Dear All, I am working in web based email system project. Here I try to build email message from scratch. I used below code to build email message msg = email.MIMEBase('text','html') msg['Return-Path'] = user+'@'+domain msg['Date'] = formatdate(localtime=1) msg['Subject'] = subject msg['From'] = from_name msg['To'] = to msg['Cc'] = cc msg.set_payload("Body of the email messagge") fh = os.popen('/bin/sendmail %s'% (eachid),'w') fh.write(msg.as_string()) fh.close() This code will build plain email message properly. But after building the message. If a email user download this mail through out look express then this email message will display without any alignment. If a user type 3 paragraph message outlook express display as a single line. What could be problem?. Kindly let me know ASAP regards Prabahar _______________________________________________________ Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE! http://in.mail.yahoo.com From cliff at develix.com Mon Aug 1 12:47:23 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 09:47:23 -0700 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <8ur1s2-r5t.ln1@strongwill.g2ctech> Message-ID: <1122914843.19618.343.camel@localhost.localdomain> On Mon, 2005-08-01 at 13:28 -0300, Jorge Godoy wrote: > > We can find several problems, almost all of them can be solved with the > admin's creativity. >>> import creativity Traceback (most recent call last): File "", line 1, in ? ImportError: No module named creativity >>> Nope. Not included with Python. Can't be used. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From http Sun Aug 7 09:29:04 2005 From: http (Paul Rubin) Date: 07 Aug 2005 06:29:04 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> Message-ID: <7x64uhx4db.fsf@ruckus.brouhaha.com> bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: > > I haven't used Ruby on Rails but from the description I saw, its distro > > includes everything needed, which I assume includes Ruby itself. > > Hm... did you read my posting before you answered? That's exactly the > kind of distro I suggested that you would make. Ruby on Rails is not > Ruby itself, you know. I'm going by another post earlier up. I'm not sure if it was from you. The distro in question was the Ruby on Rails distro. The person said he downloaded and installed it and it did everything in one click. That would imply that it included the Ruby language. Nothing stops the Ruby on Rails packagers from making the Ruby on Rails distro a superset of the Ruby distro, after all. > > I have the impression that Zope is ungodly complex, and revolves around > > a weird and nonstandard database instead of having an SQL interface. > > That's why you would put something together "to compete on more equal > terms with Ruby on Rails". Yes, it sounds like we agree that Zope isn't the answer. There's probably Python code around that does similar stuff to most of what RoR does, though it might be that RoR uses Ruby language features to do some things more conveniently than Python can. > > Anyway, I'm a Python user, not an evangelist. As a user I'm happy > > to have Python and am thankful to its authors, even though (like > > anything else) it's a long way from being perfect. But I do get > > annoyed by evangelists who make unsupportable claims that the > > product doesn't live up to. > > I made no such claims. Again, did you actually read my posting? Your claims are not the ones I have such trouble with. From agostino.russo at gmail.com Fri Aug 12 06:40:17 2005 From: agostino.russo at gmail.com (agostino.russo at gmail.com) Date: 12 Aug 2005 03:40:17 -0700 Subject: pywin32 from network install Message-ID: <1123843217.146107.302100@g44g2000cwa.googlegroups.com> I managed to make pywin32 work from a network installation (not really hard work: a shared folder + copying some dlls + setting PYTHONPATH). PythonWin amd COM seem to be working fine from the network install, BUT when I need to pass PyTime to a COM object expecting a Date I get the following error: Python24\Lib\site-packages\win32com\client\dynamic.py", line 251, in _ApplyTypes_ result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args) TypeError: Objects of type 'time' can not be converted to a COM VARIANT Note 1: The same code works when using the local installation of python/pywin, it only happens when executing the code from a network "installation". Note 2: As mentioned other COM components seem to be working when running them via pywin from the network install Note 3: I am passing pywintipes.Time(datetime.datetime.today()) to a COM object method which expects a Date argument. Do I need to change some environment variable/registry settings/other hack to fix this? From jmdeschamps at cvm.qc.ca Mon Aug 15 11:56:36 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 15 Aug 2005 08:56:36 -0700 Subject: SOAP and XMLRPC In-Reply-To: <1124119605.147443.227920@z14g2000cwz.googlegroups.com> References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> <1124115078.926129.285880@f14g2000cwb.googlegroups.com> <4300A5DF.4080903@chamonix.reportlab.co.uk> <1124119605.147443.227920@z14g2000cwz.googlegroups.com> Message-ID: <1124121396.635607.47260@z14g2000cwz.googlegroups.com> why isn't this good? http://www.enappsys.com/backend.jsp Seems to be what you're looking for... (second entry of a googled 'xml-rpc visual basic' search!) JM PS Tell us why the refered *.dll don't do, so I won't refer to it again if it's of no value. From luismgz at gmail.com Thu Aug 25 16:47:28 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 25 Aug 2005 13:47:28 -0700 Subject: New Arrival to Python In-Reply-To: <1BkPe.304848$5V4.169335@pd7tw3no> References: <1BkPe.304848$5V4.169335@pd7tw3no> Message-ID: <1125002848.703468.285100@g47g2000cwa.googlegroups.com> Windows Apps: Since you said "professional looking" applications, I assume you mean graphical interfaces (windows - GUI): If so, I recomend PythonCard ( http://pythoncard.sourceforge.net/ ). It is very easy to use, very similar to Visual Basic or Delphi (drag and drop widgets on a form...). Web Development: An excellent choice for simple (and complex, but easy) web development in Python is Karrigell ( http://pythoncard.sourceforge.net/ ). It is not an IDE, but a web framework. The coding can de made with the standard IDLE or simply notepad. Books: Learning Python 2nd Edition. Very good and complete introduction to python. Online resources: A byte of Python (google this) Dive into Python (for more experienced programmers) Hope this helps... Luis From fred.dixon at gmail.com Fri Aug 12 19:19:00 2005 From: fred.dixon at gmail.com (fred.dixon) Date: 12 Aug 2005 16:19:00 -0700 Subject: Lightweight Python distribute it in under 2MBs for Win32 In-Reply-To: References: Message-ID: <1123888740.907184.38670@f14g2000cwb.googlegroups.com> 30meg for wx ? mine is under 3meg, compressed From accepted at ukr.net Tue Aug 2 04:39:29 2005 From: accepted at ukr.net (Michael Rybak) Date: Tue, 2 Aug 2005 11:39:29 +0300 Subject: using Pyro for network games In-Reply-To: References: Message-ID: <1969374650.20050802113929@ukr.net> gn20kjss> Do not use pyro, use simple UDP protocol. gn20kjss> I've written networked tetris in python, communicating via gn20kjss> UDP protocol, and used it successfully on very congested lines. Would you please be so kind to share that with me? That would be greatly helpful, because 1) I'd run it together with my friend to see what speed I can get from UDP 2) I'd grasp the networking part of your code and reuse it. gn20kjss> If all you need is to transfer pointer coordinates, UDP is perfect since gn20kjss> you do not need feedback. gn20kjss> use something like this for server: gn20kjss> import socket gn20kjss> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) gn20kjss> s.bind(('', port)) gn20kjss> while 1: gn20kjss> data, addr = s.recvfrom(1024) gn20kjss> print `data` gn20kjss> and for client: gn20kjss> import socket gn20kjss> outsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) gn20kjss> outsock.bind(('', 0)) gn20kjss> outsock.sendto('message', ('server-hostname', server_port)) Would you recommend some reading on this? I have some immediate questions to your code, but don't want to flood here. OK, I will flood here a bit: what's the print `` syntax? P.S. I loved your virus alert ;) gn20kjss> -- gn20kjss> ----------------------------------------------------------- gn20kjss> | Radovan Garabik http://kassiopeia.juls.savba.sk/~garabik/ | gn20kjss> | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | gn20kjss> ----------------------------------------------------------- gn20kjss> Antivirus alert: file .signature infected by signature virus. gn20kjss> Hi! I'm a signature virus! Copy me into your signature file to help me spread! -- Best Regards, Michael Rybak mailto:accepted at ukr.net Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From grante at visi.com Tue Aug 30 11:51:38 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 30 Aug 2005 15:51:38 -0000 Subject: micro-python - is it possible? References: <431440bb$1@news.orcon.net.nz> <11h8r5f3r8gs7dd@corp.supernews.com> <431472a9.242312356@news.xs4all.nl> Message-ID: <11h904ae6e7dr9a@corp.supernews.com> On 2005-08-30, Wouter van Ooijen (www.voti.nl) wrote: >>No, not a tiny microcontroller environment. In the >>microcontroller world, "tiny" means 100 bytes of ram and 4KB of >>code space. > > That's medium :) > > PIC10F200: 256 12-bit instructions, 16 bytes RAM. Touch? -- Grant Edwards grante Yow! I HAVE a towel. at visi.com From roy at panix.com Tue Aug 30 11:22:10 2005 From: roy at panix.com (Roy Smith) Date: Tue, 30 Aug 2005 15:22:10 +0000 (UTC) Subject: how to join two Dictionary together? References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> Message-ID: In article <1125413088.326703.64590 at g43g2000cwa.googlegroups.com>, DENG wrote: > >dict1={...something...} > >dict2={...somethind else ..} > >dict1 + dict2 > > >that's does works ..:(, it's not like List... > > >anyone can tell me how to get it? > >thanks in advance First, you have to tell us what you want to happen when the two dictionaries have overlapping keys. Let's say I have: d1 = {1: 'one', 2: 'two'} d2 = {1: 'uno', 3: 'tres'} if I do d3 = addDicts (d1, d2), what do you want d3 to have in it? More specifically, what do you want the value of d3[1] to be? From mscottschilling at hotmail.com Fri Aug 12 11:31:33 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Fri, 12 Aug 2005 15:31:33 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: "J?rgen Exner" wrote in message news:BATKe.19727$0d.11740 at trnddc07... > Xah Lee wrote: >> Jargons of Info Tech industry >> >> (A Love of Jargons) >> >> Xah Lee, 2002 Feb >> >> People in the computing field like to spur the use of spurious >> jargons. The less educated they are, the more they like extraneous > [...] > > Just for the records at Google et.al. in case someone stumbles across > Xah's > masterpieces in the future: > Xah is very well known as the resident troll in many NGs and his > 'contributions' are less then useless. He sent a lovely one to some of the language groups the other day, explaining why Jonathan Swift was a poor writer. From donn at drizzle.com Sat Aug 13 00:18:17 2005 From: donn at drizzle.com (Donn Cave) Date: Sat, 13 Aug 2005 04:18:17 -0000 Subject: Bug on Python2.3.4 [FreeBSD]? References: Message-ID: <1123906696.459433@yasure> Quoth "Terry Reedy" : | "Donn Cave" wrote in message | news:donn-BC56BC.16011812082005 at gnus01.u.washington.edu... | > I don't think Python pretends to have any intentions here, | > it has to take what it gets from the C library fopen(3) | > function. BSD man pages generally say a+ positions the | > stream at end of file (period.) They claim conformance | > with the ISO C90 standard. I couldn't dig up a (free) copy | > of that document, so don't know what it says on this matter. | | STandard C, by Plauger & Brodie says that 'a' plus whatever else means all | writes start at the current end-of-file. Of course, but the question was, where do reads start? I would guess the GNU C library "innovated" on this point. But in the end it doesn't really matter unless Python is going to try to square that all up and make open() consistent across platforms. Donn Cave, donn at drizzle.com From mwm at mired.org Wed Aug 17 22:18:45 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 17 Aug 2005 22:18:45 -0400 Subject: Library vs Framework References: <200508161031.26507.hancock@anansispaceworks.com> <86ek8t2tfn.fsf@bhuda.mired.org> Message-ID: <86fyt8ng1m.fsf@bhuda.mired.org> Peter Decker writes: > On 8/16/05, Mike Meyer wrote: > >> Well, they may have created a library class that does the job for >> them. Figuring out which is which seemed to be the point of this >> thread. > > I guess my summary of the thread was that a library is built to do one > thing, while a framework is built to tie many libraries together to do > a series of connected things. If you end up using libraries in the > same way all of the time, that's the beginning of a framework. Having read the thread, it seems that most of the suggested definitions don't agree with yours. > Neither is better, IMO. They exist at completely different levels in > completely different domains. I think everyone would agree with that. They're obviously different things, and you can generally tell which is which when you're looking at one, but defining them? That's hard. I like the concise "Your code calls a library. A framework calls your code", but I'm not sure it's right. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From nid_oizo at yahoo.com_removethe_ Sun Aug 7 21:47:51 2005 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Sun, 07 Aug 2005 21:47:51 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <42f690ab.862953731@news.oz.net> References: <42F66FF2.7010901@v.loewis.de> <42f690ab.862953731@news.oz.net> Message-ID: <3OyJe.5040$651.432921@weber.videotron.net> Bengt Richter wrote: > I don't understand why you wouldn't give the function arg a different name > in the first place instead of via a temporary intermediary binding, e.g., > > def makeType(someArgument_alias): > class MyObject: > someArgument = someArgument_alias > return MyObject Because that would affect documentation and keyword arguments. Both the constructed class *and* the function are exposed to the user, so it needs to be coherent. >>__arrayTypes = {} >>def makeArrayType(arg1, arg2=someDefault): >> if (arg1, arg2) in __arrayTypes: >> return __arrayTypes[arg1, arg2] >> renamed_arg1 = arg1 >> renamed_arg2 = arg2 >> class Array: >> arg1 = renamed_arg1 >> arg2 = renamed_arg2 >> ... >> __arrayTypes[arg1, arg2] = Array >> return Array >> > > Or (untested, using new style class): > > def makeArrayType(arg1, arg2=someDefault): > try: return __arrayTypes[arg1, arg2] > except KeyError: > __arrayTypes[arg1, arg2] = Array = type('Array',(),{'arg1':arg1, 'arg2':arg2}) > return Array > > (just re-spelling functionality, not understanding what your real use case is ;-) Well, of course, but I didn't wrote the rest of the class definition;) So I need a place to put the class definition. In the end, it looks very much like the mess in the example. Maybe I'm missing a solution using decorators. I've defined a few classes like that, and I can live with it, but having a syntax to do it more easily, I would use it right away. I guess it can also be useful for people interfacing with COM or typed contexts. Regards, Nicolas From nospam at nospam.com Mon Aug 22 14:37:42 2005 From: nospam at nospam.com (42) Date: Mon, 22 Aug 2005 18:37:42 GMT Subject: Sandboxes References: Message-ID: In article , no at spam says... > 42 wrote: > > Or is this a hopeless cause? > > > > Finally, either way, would anyone recommend a different script engine > > that might be more suitable for what I'm trying to accomplish that I > > might not have looked at. I don't need much; it needs to work with C#, > > and be able to easily interact with 'published' interface. I'd also like > > to leverage a "popular" language instead of something obscure. > > You need a scripting language that is completely implemented in .NET > (i.e. "managed"). Try Boo: http://boo.codehaus.org/ > And then from your C# host, use the .NET security API for restricting > what the script is allowed to do. See the example below, as well as > msdn docs on SecurityPermissionFlag, PermissionSet, SetAppDomainPolicy... > http://www.gamedev.net/community/forums/topic.asp?topic_id=264462&whichpage=1� > And here are docs on using boo as an embedded scripting language: > http://boo.codehaus.org/Boo+as+an+embedded+scripting+language > I was also looking at IronPython 0.9 and it might do longer term; I don't need a lot of 'complicated' functionality so its alpha status might not even really be a problem. But its targeted at .net2 beta. I did bump into boo, but I'd never heard of it... I was hoping to use a fairly mainstream language. I guess I should look a little harder at boo. From Scott.Daniels at Acm.Org Sat Aug 13 10:55:48 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 13 Aug 2005 07:55:48 -0700 Subject: UCALC equivalent In-Reply-To: <42fd7aec@news.eftel.com> References: <42FCDCA7.7030107@syscononline.com> <42fcea4a$1@nntp0.pdx.net> <42fd7aec@news.eftel.com> Message-ID: <42fdfe46@nntp0.pdx.net> John Machin wrote: > Scott David Daniels wrote: >> max wrote: >>> Larry Bates wrote in >> The python equivalent: >> ... >> exec "def shl(x, y): return x * 2^y" > > Perhaps this should be: > exec "def shl(x, y): return x * 2 ** y" > or > exec "def shl(x, y): return x << y" Exactly. Demonstrating the problems of not actually running a test case with known results. --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Tue Aug 23 20:05:01 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 23 Aug 2005 20:05:01 -0400 Subject: Machine Name In-Reply-To: <1124838929.732444.175410@g47g2000cwa.googlegroups.com> References: <1124838929.732444.175410@g47g2000cwa.googlegroups.com> Message-ID: Harlin Seritt wrote: > How does one get the machine name with Python that the actual script is > running on? Obviously, one could parse the hosts file but I was > wondering if there was a quick way to get it done? > > thanks, > > Harlin Seritt > >>> from socket import gethostname >>> gethostname() 'bigboy' >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bill.mill at gmail.com Thu Aug 25 13:35:04 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 25 Aug 2005 13:35:04 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: <797fe3d4050825103556f49018@mail.gmail.com> On 8/25/05, Erik Max Francis wrote: > Mark Dickinson wrote: > > > Questions: > > > > (1) Can anyone else reproduce this behaviour, or is it just some quirk > > of my setup? > > (2) Any possible explanations? Is there some optimization that kicks > > in at a certain number of lines, or at a certain length of > > bytecode? > > (3) If (2), is there some way to force the optimization, so that I can > > get the speed increase without having to add the extra lines? > > I see no difference in execution times, as expected. The most likely > explanation is simply that other things were going on on your system > when you ran the first test, but not the second test, resulting in the > discrepancy. In other words, the speed change had nothing to do with > your dummy lines. > Unlikely; 2 people have confirmed these results already. I did find, though, that if I remove all print statements from the program, the dummy and non-dummy variable versions take indentical time. Can others reproduce this? I'm Investigating further... Peace Bill Mill bill.mill at gmail.com From sp1d3rx at gmail.com Fri Aug 26 13:38:37 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 26 Aug 2005 10:38:37 -0700 Subject: telnet.read_until() from telnetlib In-Reply-To: <1125075800.736986.28480@g43g2000cwa.googlegroups.com> References: <1125075800.736986.28480@g43g2000cwa.googlegroups.com> Message-ID: <1125077917.603113.195050@o13g2000cwo.googlegroups.com> after doing some research, I would suggest trying self.telnet.expect(). This will give you more data about the cause of the failures. From mwm at mired.org Fri Aug 26 20:46:15 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 26 Aug 2005 20:46:15 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> <3n8di6Fbhg7U2@individual.net> <3n8sqaFch6kU1@individual.net> Message-ID: <86ek8gw6js.fsf@bhuda.mired.org> Ulrich Hobelmann writes: > No, the few sites where I actually have to log in to do anything > useful, when they're well-coded, tell me that they need cookies, and > if I think I like that website I make an exception entry for that > site, allowing cookies. Most sites just bombard you with useless, > crap cookies (maybe advertising), so they are silently ignored by my > browser. I believe (but I'm not sure) that some releases of apache could be configured in such a way that they would start using cookies without you having to turn them on. > The only thing I hate is when I am directed to some website that needs > cookies, but doesn't tell me. A couple times I did a survey, wasting > maybe 10 minutes of my life for a good cause, and then there was an > error. Great! I guess that page needed cookies, but didn't bother to > tell me. Back button didn't work, either, so I just left that website. Try turning off JavaScript (I assume you don't because you didn't complain about it). Most of the sites on the web that use it don't even use the NOSCRIPT tag to notify you that you have to turn the things on - much less use it to do something useful. Sturgeon's law applies to web sites, just like it does to everything else. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From dejan.wirusrodiger at ck.t-com.hr Wed Aug 24 10:42:09 2005 From: dejan.wirusrodiger at ck.t-com.hr (Dejan Rodiger) Date: Wed, 24 Aug 2005 16:42:09 +0200 Subject: Unix diff command under Window. In-Reply-To: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> References: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> Message-ID: TonyHa said the following on 24.08.2005 15:50: > Hello, > > Does any one have using Python to write a Unix "diff" command for > Window? http://gnuwin32.sourceforge.net/ http://gnuwin32.sourceforge.net/packages.html Under Diffutils -- Dejan Rodiger - PGP ID 0xAC8722DC Delete wirus from e-mail address From spam.csubich+block at block.subich.spam.com Tue Aug 9 14:18:37 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 14:18:37 -0400 Subject: Does any one recognize this binary data storage format In-Reply-To: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com wrote: > I am hoping someone can help me solve a bit of a puzzle. > > We are working on a data file reader and extraction tool for an old > MS-DOS accounting system dating back to the mid 80's. > > In the data files, the text information is stored in clearly readable > ASCII text, so I am comfortable that this file isn't EBCIDIC, however, > the some of the numbers are stored in a format that we can't seem to > recognize or unpack using the standard python tools (struct, binascii) > ... or or atleast our understanding of how these tools work ! > > > Any assistance would be appreciated. > > Here are a few examples of telephone numbers; > > Exmaple 1: > > Phone 1: 5616864700 > Hex On Disk: C0DBA8ECF441 > > Phone 2: 5616885403 > Hex on Disk: B0E9ADECF4F1 Is this value a typo instead of ...F441? From fakeaddress at nowhere.org Sun Aug 28 16:48:53 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sun, 28 Aug 2005 20:48:53 GMT Subject: global interpreter lock In-Reply-To: References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> Message-ID: Piet van Oostrum wrote: >>>>>>Paul Rubin (PR) wrote: >>PR> Really, the essence of programming is to find ways of organizing the >>PR> program to stay reliable and maintainable in the face of that >>PR> combinatorial explosion. That means facing the problem and finding >>PR> solutions, not running away. The principle is no different for >>PR> threads than it is for if statements. > > The principle is (more or less) similar, but for parallel programs it is an > order of magnitude more complicated. Compare the correctness proofs of > parallel programs with those of sequential programs. That's an artifact of what the research community is trying to accomplish with the proof. Proving non-trivial programs correct is currently beyond the state of the art. -- --Bryan From en.karpachov at ospaz.ru Thu Aug 11 02:51:51 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Thu, 11 Aug 2005 10:51:51 +0400 Subject: Python supports LSP, does it? In-Reply-To: References: Message-ID: <20050811105151.736450c8.jk@ospaz.ru> On Thu, 11 Aug 2005 01:19:19 +0100 phil hunt wrote: > According to Wikipedia, the Liskov substitution principle is: > > Let q(x) be a property provable about objects x of type T. Then > q(y) should be true for objects y of type S where S is a subtype of T > > To me, this is nonsense. Under this definition any subtype must > behave the same as its parent type, becausde if it doesn't there > will be some q(y) that are different to q(x). > > But if it behaves the same, what's the point of having a subtype? It does not behave the same, it has the same properties. In other words, if there is some true assertion about _any_ object of type x, then it's true about any object of type y, if y is derived from x. Quick-and-dirty example: any object of type "list" is iterable, and it is true as well for any object of some type derived from list. -- jk From accepted at ukr.net Tue Aug 2 03:16:13 2005 From: accepted at ukr.net (Michael Rybak) Date: Tue, 2 Aug 2005 10:16:13 +0300 Subject: 2-player game, client and server at localhost In-Reply-To: References: Message-ID: <1174379367.20050802101613@ukr.net> sorry for emailing privately, pressed the wrong "reply" button >> Each player controls a snake, which is 2 to 12 balls connected to each >> other with ropes; by mouse motions you move the snake's head, and the >> rest of the body moves adhering normal physics. The objective/gameplay DLB> For purposes of the motion this snake -- the game rendering side DLB> (the client) probably should handle the physics. The only part being DLB> actively controlled is the head, and only the head movement needs to be DLB> sent -- the clients respond to head movement and compute the effect on DLB> the rest of the body. IOW, the head and /attached/ balls are ONE object DLB> for purposes of server I/O, not "2 to 12". Well, that's exactly how I think of it. >> is unimportant here, but if you're curios - all the balls of your >> snake are bullets, and right-clicking releases current tail. So, you >> have to spin around, and release the tail in appropriate moment so it DLB> At this point, you've added another object to track -- but it DLB> sounds like all you need to send is a vector (start position, direction, DLB> speed). The server, on each "input" can compute -- based on the DLB> situation at that moment -- if an intersect will occur, and when. That DLB> state doesn't change unless on or the other player inputs some new DLB> command (the target player, most likely, trying to avoid impact). But that happens all the time, and lots of times per second! If you played Quake, CS or even UT :), you know that you hold your "forward" key pressed all the time, and you also move your mouse aiming on target almost all the time. And when I play Quake, I *see* how my opponent's model aims at me, I mean, his mouse motions are transferred to me. Well, I suppose that Quake doesn't send mouse motion, clients probably retrieve the resulting aiming direction from server, but in my case, as you said yourself, client side should do physics' computations. DLB> Upon the new input, the server interpolates all moving objects -- that is, DLB> its prior update (time T0) says an intersect will occur at time T0+t, DLB> and the player response came in at t/2 (halfway, for simplicity). The DLB> server would compute positions for tracked objects at (T0+t/2), then DLB> apply the new motion vectors (player changed heading), transmit all this DLB> to all clients, and determine the next intersect time. The server DLB> doesn't have to do anything until either this intersect time or a play DLB> input comes in. That's the problem - "or a player input comes in". As I've explained, this happens a dozen of times per second :(. I've even tried not checking for player's input after every frame, but do it 3 times more rare (if framecount % 3 == 0 : process_players_input()). Well, I've already got it that I shouldn't tie this around framerate, but nevertheless... >> So, you see - server will have to send current status as much time per >> second, as much fps I want, and that's quite a lot of data. >> DLB> No... Frame rate is independent. Each client should perform some DLB> tests to determine what frame rate they can support, and adjust their DLB> internal time-steps to that. The server should probably send a DLB> time-stamp so clients can adjust for running over (might result in small DLB> jerks on slow machines, say). Of course, the server will need to check DLB> its clock speed to determine what size a time step will be (and maybe DLB> send that to clients so clients can compute a clock factor for internal DLB> calculations -- especially if the server is using a "simulation clock" DLB> for speed rather than wall clock time) I'm afraid I'm loosing it. Let's consider your example: DLB> Say the "snake" is moving left to right at 100 pixels (or some DLB> game internal unit) per second, and client one can only run 5FPS; that DLB> means each rendering pass uses the head position as: DLB> P(f) = P(T0) + (100/5)*f. DLB> {P(f) is Position(frame); P(T0) is the position at the start, the last DLB> status received from the server; 100/5 is the speed divided by the frame DLB> rate = speed per frame} DLB> The other client may be running 50FPS... For that client, the DLB> same status turns into: DLB> P(f) = P(T0) + (100/50)*f DLB> The first player sees the snake move 20 pixels per frame. The DLB> second player will see it move 2 pixels per frame, but will see 10 DLB> frames in the time the first player sees one. This sounds transparent, but my slow client isn't able to process networking fast enough, so even if it's able to work at 30 fps, it can't draw those 30 frames, because input from other player comes instantly, about 10 times per second, and server tries sending this to all clients. So my slow client simply can't know current true status, thus has nothing to draw, because it can't handle 10 transfers per second. And if server doesn't send user motions equal number of times to all clients, while they compute the world's status, they will happen to have different pictures :( -- Best Regards, Michael Rybak mailto:accepted at ukr.net From hancock at anansispaceworks.com Thu Aug 18 16:15:37 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 18 Aug 2005 15:15:37 -0500 Subject: Creating watermark with transparency on jpeg using PIL? In-Reply-To: <1124377623.599745.17750@g44g2000cwa.googlegroups.com> References: <1124377623.599745.17750@g44g2000cwa.googlegroups.com> Message-ID: <200508181515.37126.hancock@anansispaceworks.com> On Thursday 18 August 2005 10:07 am, tvmaly at gmail.com wrote: > I have been trying to add a watermark to a jpeg using PIL, but the > watermark has a black box around it. I looked at [...] > but I think these only refer to gif or png. I know jpegs really do not > support transparency, but is there some way to take a watermark in a > non jpeg format and add it to a jpeg without that box appearing around > it? Jpeg is a lossy compression format. You shouldn't do image processing in such a format at all. Convert the data to PNG, do your processing, and convert back to JPG for delivery. PIL can do that. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From wilberforce at gmail.com Mon Aug 1 09:38:09 2005 From: wilberforce at gmail.com (xtian) Date: 1 Aug 2005 06:38:09 -0700 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> Message-ID: <1122903489.007897.283550@f14g2000cwb.googlegroups.com> I think this is the kind of thing that Phillip J Eby's PythonEggs/setuptools project is supposed to manage - you can declare your dependencies, and it can manage (to some extent) download and installation of the correct versions of dependencies, without clobbering existing package versions. It's at http://peak.telecommunity.com/DevCenter/PythonEggs I haven't heard much about it recently, but it looks brilliant. xtian From mhellwig at xs4all.nl Thu Aug 4 07:07:55 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Thu, 04 Aug 2005 13:07:55 +0200 Subject: Secure email In-Reply-To: References: <42f1ecd3$0$11079$e4fe514c@news.xs4all.nl> Message-ID: <42f1f719$0$11062$e4fe514c@news.xs4all.nl> Michael Str?der wrote: > Martin P. Hellwig wrote: > >>I think you want this more common approach for mail encryption: >> >>server: >>https CGI form --> mail wrapper --> PGP encryption/signing --> send >> >>client: >>recieve mail --> pgp decryption/verification --> read > > > This would require an additional PGP-plugin for Outlook. Outlook can > decrypt S/MIME messages out-of-the-box. > > Ciao, Michael. Yes indeed, although I personaly find pgp a bit more elegant your solution would be the best for the OP. -- mph From max2 at fisso.casa Tue Aug 23 18:53:34 2005 From: max2 at fisso.casa (max(01)*) Date: Tue, 23 Aug 2005 22:53:34 GMT Subject: pipes like perl In-Reply-To: References: <1124819825.156716.72400@z14g2000cwz.googlegroups.com> Message-ID: max(01)* wrote: > infidel wrote: > >> Here's one technique I use to run an external command in a particular >> module: >> >> stdin, stdout, stderr = os.popen3(cmd) >> stdin.close() >> results = stdout.readlines() >> stdout.close() >> errors = stderr.readlines() >> stderr.close() >> if errors: >> raise Exception(''.join(errors)) >> >> Maybe this will get you going in a better direction? >> > > yeah thanks! > > i translated as: > > ..... > import os > ..... > CMD_STDIN, CMD_STDOUT, CMD_STDERR = \ > os.popen3("*some_system_command*", "r") > if not CMD_STDERR.readlines(): > ... > *do_something* > ... > for answer in CMD_STDOUT: > print answer, > ... > *do_something_more* > ... > else: > ... > *do_something_else* > ... > CMD_STDIN.close() > CMD_STDOUT.close() > CMD_STDERR.close() > ..... but... i see it doesn't work for some commands, like "man python" (it gets stuck on the "if" line)... how come? From spam at me.please Mon Aug 8 17:20:41 2005 From: spam at me.please (Evil Bastard) Date: Tue, 09 Aug 2005 09:20:41 +1200 Subject: python for microcontrollers In-Reply-To: References: <42f7c8d4$1@news.orcon.net.nz> Message-ID: <42f7ce06$1@news.orcon.net.nz> Benji York wrote: > Perhaps porting Pyrex would be easier. Pyrex takes a python-like syntax > (plus type information, etc.) and emits C, which is then compiled. Pyrex totally rocks. But for the PIC targetting, no can do: - pyrex generates a **LOT** of code, which makes extensive use of the python-C api, which is inextricably tied to dynamic objects - PIC program memory is 32kbytes max Thanks all the same. Any other suggestions? -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From jepler at unpythonic.net Mon Aug 8 08:10:23 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 8 Aug 2005 07:10:23 -0500 Subject: issues with doctest and threads In-Reply-To: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> References: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> Message-ID: <20050808121023.GD13847@unpythonic.net> I don't see the problem with your doctest usage, but what makes you believe that the code you show below produces exactly 9 dots? strangely enough, re-working the code to this >>> import time, threading >>> def example(): ... thread.out = [] ... for i in range(9): thread.out.append(".") >>> thread = threading.Thread(None, example) >>> thread.running = True; thread.start() >>> time.sleep(.1) >>> thread.running = False >>> print thread.out ['.', '.', '.', '.', '.', '.', '.', '.', '.'] makes the test "succeed" (though it can fail for some of the same reasons the original test isn't guaranteed to give 9 dots either). Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From della at toglimi.linux.it Fri Aug 12 02:45:02 2005 From: della at toglimi.linux.it (Matteo Dell'Amico) Date: Fri, 12 Aug 2005 06:45:02 GMT Subject: set of sets In-Reply-To: References: <42FB2CDA.2040106@tiscali.it> Message-ID: Paolo Veronelli wrote: > Yes this is really strange. > > from sets import Set > class H(Set): > def __hash__(self): > return id(self) > > s=H() > f=set() #or f=Set() > > f.add(s) > f.remove(s) > > No errors. > > So we had a working implementation of sets in the library an put a > broken one in the __builtins__ :( > > Should I consider it a bug ? Looks like the builtin "set" implicitly converts sets arguments to remove to frozensets. That way, remove looks for "frozenset()" instead of "H()", so it won't work. Doesn't look like a documented behaviour to me, though. -- Ciao, Matteo From roy at panix.com Sat Aug 20 15:19:55 2005 From: roy at panix.com (Roy Smith) Date: Sat, 20 Aug 2005 15:19:55 -0400 Subject: Binary Trees in Python References: Message-ID: In article , [diegueus9] Diego Andr?s Sanabria wrote: > Hello!!! > > I want know if python have binary trees and more? Python does not come with a tree data structure. The basic data structures in Python are lists, tuples, and dicts (hash tables). People who are used to C++'s STL often feel short-changed because there's not 47 other flavors of container, but it turns out that the three Python gives you are pretty useful. Many people never find a need to look beyond them. If you do need to go beyond them, it's easy enough to build your own. Here's one example of a binary ordered tree that you might find useful: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286239 From rkern at ucsd.edu Wed Aug 31 10:16:03 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 31 Aug 2005 07:16:03 -0700 Subject: dynamicly updating an objects fields In-Reply-To: References: <1125465620.219693.187500@g47g2000cwa.googlegroups.com> Message-ID: Uwe Lauth wrote: > kyle.tk wrote: > >>I want to make a function that will work like this: >> >>def updateField(object, fieldName, newValue): >> object.fieldName = newValue > > This function already exists in python. > It is called settattr. Or rather setattr. -- 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 zen19725 at zen.co.uk Mon Aug 1 03:57:16 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 1 Aug 2005 08:57:16 +0100 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> Message-ID: On Sun, 31 Jul 2005 12:09:48 -0700, Cliff Wells wrote: >On Sun, 2005-07-31 at 10:07 -0700, Kay Schluehr wrote: > >> Some other people already abandoned Python not for the worst reasons: >> >> http://www.kevin-walzer.com/pivot/entry.php?id=69 > >Being a developer requires not only a bit of brains, but quite a bit of >tenacity as well. Apparently Kevin lacks the second. > >> My objection with wrappers around wrappers around wrappers is that I >> have no hope ever watching the ground. If some error occurs, which >> layer has to be addressed? Which developing group is reponsible? My own >> or that of team A, team B, team C ... ? The baroque concept is >> repulsive to me and only acceptable in case of legacy code that gets >> wrapped around old one and is dedicated to substitute it continously. > >Of course, Tkinter is still a wrapper around a third party library (Tk) >borrowed from a different language (Tcl) and written again in a third >language (C), much the same as wxPython. In practise any Python GUI is going to contain code from otyher languages since if it was coded all the way down in python it would be too slow. -- Email: zen19725 at zen dot co dot uk From maksim.kasimov at gmail.com Tue Aug 9 09:39:51 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Tue, 09 Aug 2005 16:39:51 +0300 Subject: don't understand instanse creation Message-ID: Hello, i have a class, such as below. when i try to make instances of the class, fields __data1 and __data2 gets different values: __data1 behaves like private field, __data2 - like static which is the thing i've missed? thanks for help. ==================================================== import time class my: __data1 = [] __data2 = [] def __init__(self): print "__data1: ", self.__data1 print "__data2: ", self.__data2 for i in time.localtime(): self.__data2.append(i) self.__data1 = self.__data2[:] print "__data1: ", self.__data1 print "__data2: ", self.__data2 ==================================================== Python 2.2.3 FreeBSD >>> m1 = my.my() __data1: [] __data2: [] __data1: [2005, 8, 9, 16, 25, 18, 1, 221, 1] __data2: [2005, 8, 9, 16, 25, 18, 1, 221, 1] >>> >>> >>> m2 = my.my() __data1: [] __data2: [2005, 8, 9, 16, 25, 18, 1, 221, 1] __data1: [2005, 8, 9, 16, 25, 18, 1, 221, 1, 2005, 8, 9, 16, 25, 25, 1, 221, 1] __data2: [2005, 8, 9, 16, 25, 18, 1, 221, 1, 2005, 8, 9, 16, 25, 25, 1, 221, 1] -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From grante at visi.com Wed Aug 10 09:35:12 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 10 Aug 2005 13:35:12 -0000 Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> <42f98255@news.eftel.com> Message-ID: <11fk0kg65rtfn72@corp.supernews.com> On 2005-08-10, John Machin wrote: >>>>Perhaps the one bit is an exponent -- some kind of floating point >>>>based format? That matches the doubling of all digits. >>> >>>That would just be sick. I can't imagine anybody on an 8-bit >>>CPU using FP for a phone number. >> >>> double_binary_lehex_to_double('000000806a6e4941') >> 3333333.0 >> >>> double_binary_lehex_to_double('000000806a6e5941') >> 6666666.0 >> >>> double_binary_lehex_to_double('0000108777F9Fc41') >> 7777777777.0 >> >> ;-) > > Well done, Scott & Bengt!! > I've just verified that this works with all 12 corrected examples posted > by the OP. > > Grant, MS-DOS implies 16 bits at least; You're right. For some reason I was thinking you had said CP/M. > and yes there was an FPU (the 8087). I never met an MS-DOS box that had an 8087 (though I did write firmware for an 8086+8087 fire-control computer once upon a time). > And yes there are a lot of sick people who store things as > numbers (whether integer or FP) when the only arithmetic > operations that can be applied to them stuff them up mightily > (like losing leading zeroes off post-codes, having NEGATIVE > tax file numbers, etc) and it's still happening on the best > OSes and 64-bit CPUS. Welcome to the real world :-) I've been in the real world for a long time, and the dumb things people (including myself) do still surprise me. -- Grant Edwards grante Yow! Hello, GORRY-O!! I'm at a GENIUS from HARVARD!! visi.com From peter at engcorp.com Tue Aug 2 23:11:17 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 02 Aug 2005 23:11:17 -0400 Subject: Python for embedded linux? In-Reply-To: References: Message-ID: pythonic at seehart.com wrote: > Where can I find a minimal version of python (less than 2 MB) suitable for > a web server on an embedded linux system? The small size is required > because the system lives on flash memory. Such things have been discussed in this list/newsgroup before. I suggest trying a Google Groups search with some relevant keywords, such as "embedded" (though this occurs in several other contexts), "flash", or "small footprint". -Peter From michele.petrazzo at TOGLIunipex.it Tue Aug 23 06:51:23 2005 From: michele.petrazzo at TOGLIunipex.it (Michele Petrazzo) Date: Tue, 23 Aug 2005 12:51:23 +0200 Subject: Library and real path name In-Reply-To: References: <430af2d2$0$8495$5fc30a8@news.tiscali.it> Message-ID: <430affb4$0$8482$5fc30a8@news.tiscali.it> Fredrik Lundh wrote: > Michele Petrazzo wrote: > >>I want to redistribute the library that I create. >>I create a project, its setup.py that when launched copy all files into >>the "site-packages/library" directory. And here it's all ok. >>When I call my library with: >> >>import library >>library.class() >> >>I want that my library know where are its real path >>(site-packages/library/) > > > you can use the __file__ or __path__ variables to determine this. > e.g. > > # get this module's directory > import os > prefix = os.path.dirname(__file__) > > or, inside a package __init__.py file: > > # get package's main directory > prefix = __path__[0] > > > > > Thanks, it work Michele From nmichaud at jhu.edu Fri Aug 19 10:44:22 2005 From: nmichaud at jhu.edu (nmichaud at jhu.edu) Date: Fri, 19 Aug 2005 10:44:22 -0400 (EDT) Subject: Implementing class methods in C In-Reply-To: References: Message-ID: > If you implement _test in C, works none of the above. > The only difference I can see is that: > type(_test.func2) > > is for Python implemented function and > type(_test.func2) > > for C implementation > I would really like to know the answer too. > How do you implement some methods in C without subclassing ? But the strange thing is if I use new.instancemethod the c function becomes bound (using my previous code for _test.c) import _test class Test: def func1(self): print "In class "+repr(self.__class__.__namd__) import new Test.func2 = new.instancemethod(_test.func2, None, Test) del new t = Test type(_test.func2) # returns type(T.func1) # returns type(t.func1) # returns > type(T.func2) # returns type(t.func2) # returns > So is seems like it is bound appropriately, but when called across the C/Python api the first argument (self) of func2 is not separated from the other arguments (and thus is not sent into the c function as PyObject* self, but instead as part of PyObject* args) From paul at boddie.org.uk Sun Aug 7 11:18:04 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 7 Aug 2005 08:18:04 -0700 Subject: Python -- (just) a successful experiment? References: <1123422959.086345.76190@g49g2000cwa.googlegroups.com> <7xll3dpz8t.fsf@ruckus.brouhaha.com> Message-ID: <1123427884.740555.255930@z14g2000cwz.googlegroups.com> Paul Rubin wrote: > Come on, this is silly, Java is a lot more cumbersome for doing small, > quick projects, but Python doesn't have the language discipline or the > library support to do heavyweight projects that Java can. I'm not necessarily arguing that Python goes all the way up to the upper echelons of enterprise application development, but there seem to be a lot of people grabbing the chainsaw in order to snap a twig, and then justifying that choice by mentioning all the chainsaw vendors by name. > There is nothing like JSSE in Python. There is no JDBC replacement unless you > get a third party module from somewhere. There is no MQ. I won't doubt that there are pieces missing, although JDBC is something of a red herring, given that Python does have a half-decent API standard for database access and that you still need JDBC drivers (cf. third party modules) to connect to actual database systems. What I've argued for all along, in contrast to the endless advocacy of language microfeatures that save ten seconds of typing in an average working day, is increased attention to library support for actual applications and solutions. So I don't disagree with everything you're saying here. ;-) [...] > Python is great for recreational projects and prototyping. It's not yet mature > enough for deploying complex, critical applications, though maybe it's getting there > (PyPy will be an important step). I'd be interested to hear an amplification of the last statement. Paul From nomail at nomail.com Sat Aug 20 10:27:28 2005 From: nomail at nomail.com (Viper Jack) Date: Sat, 20 Aug 2005 14:27:28 GMT Subject: [newbie]search string in tuples Message-ID: Hi all, i'm new to python programming so excuseme if the question is very stupid. here the problem. this code work list=["airplane"] select=vars while select != list[0]: select=raw_input("Wich vehicle?") but i want check on several object inside the tuple so i'm trying this: list=["airplane","car","boat"] select=vars while select != list[0] or list[1] or list[2]: select=raw_input("Wich vehicle?") but loops and doesn't want work. I have tried with other methods (for) but nothings. I haven't find nothing on this topic, so i asked here. Thanks in advance. From see.my at signature.net Tue Aug 16 18:54:12 2005 From: see.my at signature.net (=?UTF-8?B?TWF0ZXVzeiDFgW9za290?=) Date: Wed, 17 Aug 2005 00:54:12 +0200 Subject: GUI tookit for science and education In-Reply-To: References: <11g23l4mq5ftvcb@corp.supernews.com> Message-ID: Markus Rosenstihl napisa?(a): >>> It doesn't have much math built in. For functions you have to >>> plot points. >> >> >> If you want to plot stuff, the gnuplot-py module is very easy >> to use. http://sourceforge.net/projects/gnuplot-py/ >> [...] > > matplotlib is also ver good possibility > Thanks, I'll try it. Cheers -- Mateusz ?oskot, mateusz (at) loskot (dot) net Registered Linux User #220771 From kst-u at mib.org Mon Aug 22 18:24:39 2005 From: kst-u at mib.org (Keith Thompson) Date: Mon, 22 Aug 2005 22:24:39 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: "jan V" writes: >> +-------------------+ .:\:\:/:/:. >> | PLEASE DO NOT | :.:\:\:/:/:.: >> | FEED THE TROLLS | :=.' - - '.=: >> | | '=(\ 9 9 /)=' >> | Thank you, | ( (_) ) >> | Management | /`-vvv-'\ >> +-------------------+ / \ >> | | @@@ / /|,,,,,|\ \ >> | | @@@ /_// /^\ \\_\ >> @x@@x@ | | |/ WW( ( ) )WW >> \||||/ | | \| __\,,\ /,,/__ >> \||/ | | | jgs (______Y______) >> /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ > > Please don't use ASCII art... not everyone uses a fixed-width font for his > newsreader............... > (your picture looks all mangled here) If "PLEASE DO NOT" and "FEED THE TROLLS" are legible, even if they aren't aligned as intended, the message has gotten through. -- Keith Thompson (The_Other_Keith) kst-u at mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. From newsgroups at jhrothjr.com Fri Aug 5 21:29:06 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 5 Aug 2005 19:29:06 -0600 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <11f84j8elj07271@news.supernews.com> wrote in message news:1123270841.195692.21470 at g47g2000cwa.googlegroups.com... > I've heard 2 people complain that word 'global' is confusing. > > Perhaps 'modulescope' or 'module' would be better? > > Am I the first peope to have thought of this and suggested it? > > Is this a candidate for Python 3000 yet? > > Chris A much better idea would be to fix the underlying situation that makes the global statement necessary. I doubt if this is going to happen either, though. John Roth > From bokr at oz.net Wed Aug 10 22:35:40 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 11 Aug 2005 02:35:40 GMT Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123697696.506898.66580@z14g2000cwz.googlegroups.com> Message-ID: <42fab7d0.1135118033@news.oz.net> On Wed, 10 Aug 2005 20:39:03 +0100, zen19725 at zen.co.uk (phil hunt) wrote: [...] > >I've not personally had problems with the wrong number of argumnets >to a function call -- they get caught at run-time and are easy >enough to fix -- but I do sometimes get errors because a varialbe is >the wrong time, e.g. a string when it should be an int. > >One problem I once encountered was wit this and I waasn't picking it >up because my debugging code looked like this: > > if debug: print "v=%s" % (v,) > >Which of course prints the same output whether v is '2' or 2. > >For this reason I tend to debug print statements like this now: > > if debug: print "v=%s" % (v,) I usually prefer %r over %s for debug prints if debug: print "v=%r" % (v,) since it represents (repr's ;-) the v thing better >>> print 'v=%r' % 2 v=2 >>> print 'v=%r' % '2' v='2' Regards, Bengt Richter From pierre.barbier at cirad.fr Mon Aug 29 12:25:50 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 29 Aug 2005 18:25:50 +0200 Subject: GIL, threads and scheduling - performance cost In-Reply-To: <1125329306.425235.210840@f14g2000cwb.googlegroups.com> References: <1125329306.425235.210840@f14g2000cwb.googlegroups.com> Message-ID: <4313367d$0$1830$626a14ce@news.free.fr> adsheehan at eircom.net a ?crit : > Hi all, > > Wondering if a GIL lock/unlock causes a re-schedule/contect swap when > embedding Python in a multi-threaded C/C++ app on Unix ? > > If so, do I have any control or influence on this re-scheduling ? > > The app suffers from serious performance degradation (compared to pure > c/C++) and high context switches that I suspect the GIL unlocking may > be aggravating ? Well, where do you observe this degradation ? When replacing part of the C++ code by Python's code ? Or on C++ code running parallel to your Python code ? Because in the first case, well, this is just something natural ! Python runtime overhead is much greater than C++ because of its dynamic nature (it has to resolve all the symbols at runtime ...). And given the policy for locking/releasing the GIL, I doubt it has serious performance issues compared to the Python interpreter itself. If current performance is an issue, consider implementing more in C/C++ ! This will be mainly true if you currently have some heavy looping in Python. Python is very neat to put together processor-intensive functions written in other languages, but not to implement them. (as an exemple looh at that: http://www.python.org/doc/essays/list2str.html ) > > Thanks for any help. > > Alan > Pierre From rtconner at gmail.com Mon Aug 8 17:12:48 2005 From: rtconner at gmail.com (Rob Conner) Date: 8 Aug 2005 14:12:48 -0700 Subject: Why does __init__ not get called? Message-ID: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> I'm still working on my DateTime class from last week... Why does __init__ not get called? The docs at http://www.python.org/dev/doc/devel/ref/customization.html read "If __new__() returns an instance of cls, then the new instance's __init__() method will be invoked" and as far as I can tell cls is very much an instance of DateTime ************ import datetime _datetime = datetime.datetime class DateTime(_datetime): """ Identical to builtin datetime.datetime, except it accepts invalid dates and times as input. """ _valid = True __dict__ = _datetime.__dict__ def __init__(self, year, month, day, *args, **kw): print "init called" _valid = False self.year = year self.month = month self.day = day self.args = args self.kw = kw def throwError(): raise ValueError, 'Invalid Date' for method in _datetime.__dict__.keys(): if method!='__doc__': setattr(self, method, throwError) def __new__(cls, year, month, day, *args, **kw): print "new called" try: return _datetime.__new__(cls, year, month, day, *args, **kw) except ValueError: return cls ************* From alanmk at hotmail.com Sat Aug 20 09:30:26 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Sat, 20 Aug 2005 14:30:26 +0100 Subject: global interpreter lock In-Reply-To: References: Message-ID: [km] > is true parallelism possible in python ? cpython: no. jython: yes. ironpython: yes. > or atleast in the coming versions ? cpython: unknown. pypy: don't have time to research. Anyone know? > is global interpreter lock a bane in this context ? beauty/bane-is-in-the-eye-of-the-beholder-ly y'rs -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From gregpinero at gmail.com Sun Aug 28 13:29:38 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Sun, 28 Aug 2005 13:29:38 -0400 Subject: Embedding Python in other programs In-Reply-To: <1125208540.068217.10960@z14g2000cwz.googlegroups.com> References: <312cfe2b050826084036db598f@mail.gmail.com> <1125134294.509755.64030@g43g2000cwa.googlegroups.com> <1125208540.068217.10960@z14g2000cwz.googlegroups.com> Message-ID: <312cfe2b05082810296b988cc5@mail.gmail.com> Thanks Ravi, I'll take a look On 27 Aug 2005 22:55:40 -0700, Ravi Teja wrote: > http://www.python.org/windows/win32com/QuickStartServerCom.html > > If you are using ActivePython, that tutorial is included (PyWin32 > documentation -> Python COM -> Overviews) along with the needed > win32all module. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From rubbishemail at web.de Mon Aug 29 09:19:17 2005 From: rubbishemail at web.de (rubbishemail at web.de) Date: 29 Aug 2005 06:19:17 -0700 Subject: Pointers and ctypes Message-ID: <1125321557.883310.41490@g43g2000cwa.googlegroups.com> Hello, i've got a problem with pointers in the following function which i want to use: I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value) The function is supposed to read out the status of a digital port of analog digital interface card. I got this function from Dask.h which came with the card. The relevant lines concerning this function are the following: typedef short I16; typedef unsigned short U16; typedef unsigned long U32; I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value) I tried to implement this function into python: # I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value); ReadOPort = dask.DO_ReadPort ReadOPort.argtypes = [c_ushort, c_ushort, c_ulong] ReadOPort.restype = c_short I can't handle the pointer "Value" which should be an unsigned long pointer. I'd be very happy, if u could give me a hint how to implement this pointer into python. Thanks a lot Carlo and Pierre From webdev at chaosmedia.org Sat Aug 6 05:32:09 2005 From: webdev at chaosmedia.org (webdev) Date: Sat, 06 Aug 2005 11:32:09 +0200 Subject: minidom xml & non ascii / unicode & files In-Reply-To: <42F3FDED.8050108@v.loewis.de> References: <42f38284$0$5314$636a15ce@news.free.fr> <42F3FDED.8050108@v.loewis.de> Message-ID: <42F48399.6070904@chaosmedia.org> Thx Martin for your comments. indeed the charset of the web document is set in the meta tag, it's iso-8859-1 so i'll decode it to unicode using something like: html = html.decode('iso-8859-1') html then contains the unicode version of the html document As i've finally managed to make this work i'll post here my comments on the few things i still don't understand, maybe you can explain why it works that way with more technical terms than i can provide myself.. So the whole thing is to regex parse some html document, and store the results inside an xml file that can be parsed again by python minidom for further use.. ############### CODE START ############### import urllib, string, codecs, types import sys, traceback, os.path, re, shutil import cachedhttp from xml.dom.minidom import parse, parseString NODE_ELEMENT=1 NODE_ATTRIBUTE=2 NODE_TEXT=3 NODE_CDATA_SECTION=4 httpFetcher=cachedhttp.CachedHTTP() # Fetch Menu Links Page, httpFetcher is from the cachedhttp lib developped by someone for another script, it returns a bytestring from the local cached file, once downloaded of the internet, using a simple f = open(file,'r') & f.read() data = httpFetcher.urlopen('http://www.canalplus.fr/pid6.htm') data = data.decode('iso-8859-1') # at that point i have my html document in unicode # utf8bin.xml is an utf-8 encoded xml file, "bin" is because of the way i have to use to save it back to file, see at bottom dom = parse('utf8bin.xml') # find the data we need from the html document # title contains the text and so some special chars x = re.compile(']*>[^<]*]*>(?:)?(?P[^<]+)(?:</b>)?</a>[^<]*</li>', re.DOTALL|re.IGNORECASE|re.UNICODE) for match in x.finditer(data): urlid = match.group('url') url = match.expand('http://www.canalplus.fr/\g<url>') title = match.expand('\g<title>') # everything here is still unicode objects match = None nodes = dom.getElementsByTagName('page') for node in nodes: if GetNodeValue(node,'title') == title: print 'Found Match: ' + title + ' == ' + GetNodeValue(node,'title') match = node break if match is None: # create page node and set attributes newnode = dom.createElement('page') att = dom.createAttribute('id') newnode.setAttributeNode(att) newnode.setAttribute('id',urlid) # create title childnode and set CDATA section vnode = dom.createElement('title') newnode.appendChild(vnode) dnode = dom.createCDATASection(title) vnode.appendChild(dnode) # create value childnode and set CDATA section vnode = dom.createElement('value') newnode.appendChild(vnode) dnode = dom.createCDATASection(url) vnode.appendChild(dnode) root = dom.documentElement root.appendChild(newnode) f = open('utf8bin.xml', 'wb') f.write(dom.toxml(encoding="utf-8")) f.close() # just to make sure we can still parse our xml file print '\nParsing utf8bin.xml and Printing titles' dom = parse('utf8bin.xml') nodes = dom.getElementsByTagName('page') for node in nodes: print GetNodeValue(node,'title') # Some xml helper functions # GetNodeText returns a unicode object def GetNodeText(node): dout='' for tnode in node.childNodes: if (tnode.nodeType==NODE_TEXT)|(tnode.nodeType==NODE_CDATA_SECTION): dout=dout+tnode.nodeValue return dout # GetNodeValue returns a unicode object or None def GetNodeValue(node,tag=None): if tag is None: return GetNodeText(node) nattr=node.attributes.getNamedItem(tag) if not (nattr is None): return nattr.value for child in node.childNodes: if child.nodeName == tag: return GetNodeText(child) return None ############### CODE END ############### Now the comments : so what i understood of all this, is that once you're using unicode objects you're safe ! At least as long as you don't use statements or operators that will implicitely try to convert the unicode object back to bytestring using your default encoding (ascii) which will most certainly result in codec Errors... Also, minidom seems to use unicode object what was not really documented in the python 2.3 doc i've read about it.. so passing the unicode object from my regex matches to minidom elements will make minidom behave nicely.. If you start to pass encoded bytestrings to minidom elements it may fail when you call "toxml()".. I know i managed to do that once or twice i don't remember exactly what kind of bytestrings i passed to the minidom element but one thing's for sure it made "toxml()" fail whatever encoding you specify.. So if you stick to unicode, it will then encode all that unicode content to whatever encoding you've specified when calling "dom.toxml(encoding="utf-8")" then you just have to store the output of that as it is without any further encoding As a matter of fact using the following sequence will most certainly fail : f = codecs.open('utf8codecs.xml', 'w', 'utf-8') f.write(dom.toxml(encoding="utf-8")) f.close() then again maybe this will work, i just thought of it.. f = codecs.open('utf8codecs.xml', 'w', 'utf-8') f.write(dom.toxml()) f.close() I didn't understand at first that once you're using unicode object and as long as you've properly decoded your bytestring source, then unicode is unicode and you can forget about encodings "ascii", "iso-", "utf-".. The next important thing is to make sure to use functions and objects that support unicode all the way, like minidom seems to do.. my original script has another function "FindDataNode" that will do a more sofisticated loop, into the dom object you provide, in order to check if there's already a node with the same title, and i use there some .lower() methods and a another "Sanitize" function that replaces a few chars.. So i guess i'll have to make sure that none of those manipulations converts my unicode obect back to bytestrings.. Thx for reading, let me know if you see really really weird (bad?) things in my code, or if you have further comments to add on the unicode topic.. Marc Martin v. L?wis wrote: > webdev wrote: > >>1. when fetching a web page from the net, how am i supposed to know how >>it's encoded.. And can i decode it to unicode and encode it back to a >>byte string so i can use it in my code, with the charsets i want, like >>utf-8.. ? > > > It depends on the content type. If the HTTP header declares a charset= > attribute for content-type, then use that (beware: some web servers > report the content type incorrectly. To deal with that gracefully, > you have to implement very complex algorithms, which are part of > any recent web browser). > > If there is no charset= attribute, then > - if the content type is text/html, look at a meta http-equiv tag > in the content. If that declares a charset, use that. > - if the content type is xml (plain, or xhtml+xml), look at the > XML declaration. Alternatively, pass it to your XML parser. > > >>2. in the same idea could anyone try to post the few lines that would >>actually parse an xml file, with non ascii chars, with minidom >>(parseString i guess). > > > doc = xml.dom.minidom.parse("foo.xml") > > >>Then convert a string grabbed from the net so parts of it can be >>inserted in that dom object into new nodes or existing nodes. > > > doc..documentElement.setAttribute("bar", text_from_net.decode("koi-8r")) > > >>And finally write that dom object back to a file in a way it can be used >>again later with the same script.. > > > open("/tmp/foo.txt","w").write(doc.toxml()) > > >>I've been trying to do that for a few days with no luck.. >>I can do each separate part of the job, not that i'm quite sure how i >>decode/encode stuff in there, but as soon as i try to do everything at >>the same time i get encoding errors thrown all the time.. > > > It would help if you would state what precise code you are using, > and what precise error you are getting (for what precise input). > > >>3. in order to help me understand what's going on when doing >>encodes/decodes could you please tell me if in the following example, s >>and backToBytes are actually the same thing ?? >> >>s = "hello normal string" >>u = unicode( s, "utf-8" ) >>backToBytes = u.encode( "utf-8" ) >> >>i knwo they both are bytestrings but i doubt they have actually the same >>content.. > > > They do have the same content. There is nothing to a byte string except > for the bytes. If the byte string is meant to represent characters, > they are the same "thing" only if the assumed encoding is the same. > Since the assumed encoding is "utf-8" for both s and backToBytes, > they are the same thing. > > >>4. I've also tried to set the default encoding of python for my script >>using the sys.setdefaultencoding('utf-8') but it keeps telling me that >>this module does not have that method.. i'm left no choice but to edit >>the site.py file manually to change "ascii" to "utf-8", but i won't be >>able to do that on the client computers so.. > > > Don't do that. It's meant as a last resort for backwards compatibility, > and shouldn't be used for new code. > > Regards, > Martin From rtconner at gmail.com Tue Aug 9 14:26:45 2005 From: rtconner at gmail.com (Rob Conner) Date: 9 Aug 2005 11:26:45 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123601386.567072.111240@o13g2000cwo.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> Message-ID: <1123612005.889760.226150@z14g2000cwz.googlegroups.com> Not takers? This is my attempt to get some attention by bumping my own post. From paolo_veronelli at yahoo.it Fri Aug 12 16:12:51 2005 From: paolo_veronelli at yahoo.it (paolino) Date: Fri, 12 Aug 2005 22:12:51 +0200 Subject: Bug on Python2.3.4 [FreeBSD]? In-Reply-To: <ddioc3$evr$1@news2.rz.uni-karlsruhe.de> References: <ddioc3$evr$1@news2.rz.uni-karlsruhe.de> Message-ID: <42FD02C3.7010907@yahoo.it> Uwe Mayer wrote: > <posted & mailed> > > Hi, > > AFAICT there seems to be a bug on FreeBSD's Python 2.3.4 open function. The > documentation states: > > >>Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' >>truncates the file). Append 'b' to the mode to open the file in binary >>mode, on systems that differentiate between binary and text files (else it >>is ignored). If the file cannot be opened, IOError is raised. > > > Consider: > > $ cat test > lalala > > $ python2.3 > Python 2.3.4 (#2, Jan 4 2005, 04:42:43) > [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 > Type "help", "copyright", "credits" or "license" for more information. > >>>>f = open('test', 'r+') >>>>f.read() > > 'lalala\n' > >>>>f.write('testing') >>>>f.close() >>>> > > [1]+ Stopped python2.3 > $ cat test > lalala > > -> write did not work; ok > This worked here on freebsd 5.4 / python 2.4 > $ fg > python2.3 > >>>>f = open('test', 'a+') >>>>f.read() > > '' > > -> append mode does not read from file, *not ok* > > This is right IMO 'a' is appending so seek(-1) Ciao From snail at objmedia.demon.co.uk Fri Aug 19 18:28:02 2005 From: snail at objmedia.demon.co.uk (Stephen Kellett) Date: Fri, 19 Aug 2005 23:28:02 +0100 Subject: wanna stop by my homemade glory hole? References: <mailman.3294.1124485950.10512.python-list@python.org> Message-ID: <4vzwO9AyzlBDFwKG@objmedia.demon.co.uk> >wanna stop by my homemade glory hole? I don't think anyone on this group will be interested in trying their Python with that. Take it somewhere else. -- Stephen Kellett Object Media Limited http://www.objmedia.demon.co.uk/software.html Computer Consultancy, Software Development Windows C++, Java, Assembler, Performance Analysis, Troubleshooting From jasondrew72 at gmail.com Wed Aug 10 16:27:26 2005 From: jasondrew72 at gmail.com (Jason Drew) Date: 10 Aug 2005 13:27:26 -0700 Subject: What is Python?! In-Reply-To: <roy-8911D7.08041710082005@reader2.panix.com> References: <ddcnbf$aen$02$1@news.t-online.com> <roy-8911D7.08041710082005@reader2.panix.com> Message-ID: <1123705646.155750.282910@g43g2000cwa.googlegroups.com> Roy Smith wrote: "there's a system called Jython, which lets you compile Java source to Python byte code." Don't you have that the wrong way 'round? From the Jython website: "Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform." In the case of Jython you could perhaps say that Python bytecode is "exactly like Java". However, in the case of regular Python, it's closer to say that Python bytecode is much the same _idea_ as Java bytecode. Jason From en.karpachov at ospaz.ru Thu Aug 25 02:45:59 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Thu, 25 Aug 2005 10:45:59 +0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <dejg0q$4qc$1@sea.gmane.org> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <m2ek8zqkax.fsf@ 82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <1124160882.554543.75730@g 43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte .blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRV n-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <WZaPe.1953 $eQ.899@newssvr30.news.prodigy.com> <dejg0q$4qc$1@sea.gmane.org> Message-ID: <20050825104559.1ec1a99f.jk@ospaz.ru> On Thu, 25 Aug 2005 00:05:18 -0400 Steve Holden wrote: > What on earth makes you call this a bug? And what are you proposing that > find() should return if the substring isn't found at all? please don't > suggest it should raise an exception, as index() exists to provide that > functionality. Returning -1 looks like C-ism for me. It could better return None when none is found. index = "Hello".find("z") if index is not None: # ... Now it's too late for it, I know. -- jk From bronger at physik.rwth-aachen.de Thu Aug 4 01:43:11 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Thu, 04 Aug 2005 07:43:11 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> Message-ID: <87wtn245qo.fsf@wilson.rwth-aachen.de> Hall?chen! Mike Meyer <mwm at mired.org> writes: > Torsten Bronger <bronger at physik.rwth-aachen.de> writes: > >> Mike Meyer <mwm at mired.org> writes: >> >>> Torsten Bronger <bronger at physik.rwth-aachen.de> writes: >>> >>> [...] >>> >>> You didn't answer the question about how you define agile >>> project. Please do so if you expect a comment on this. >> >> Projects with a high Sourceforge activity index. > > That doesn't seem to match the common defintion of "agile" when it > comes to programming. Then again, you have a habit of using words > to mean whatever you want, without much reference to how they're > used by the rest of the industry. I'm not part of the industry. Sorry, but now the arguments are getting destructive. Agile programming is a fixed phase, which I've never used. (And which makes no sense in this discussion.) > [...] > > Sorry, but you're wrong. FORTRAN is very much a general purpose > language. [...] It's not about the potential use of a language, but its actual use. > [...] > >>> You can't have it both ways. Either C/C++ is all legacy code, or >>> it's not. >> >> ... is wrong in my opinion. Why should this be? > > Because any given proposition is either true or false. If I say "most people are right-handed", then this means neither that all people are right-handed nor that none is. > [...] > >>> There are *lots* of applications areas that don't need GUIs, and >>> don't run on Windows. >> >> This becomes a discussion about estimates we both don't know >> exactly, and weight differently, so I'll leave it here. > > No, it's not a discussion about estimates. The average household > in a G8 country has more computers that don't run Windows - and in > fact don't have GUIs at all - than otherwise. [...] However, it's about the types of software which is being produced today. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From dcrespo at gmail.com Mon Aug 22 16:33:38 2005 From: dcrespo at gmail.com (dcrespo) Date: 22 Aug 2005 13:33:38 -0700 Subject: Can I send files through xmlrpc connections? Message-ID: <1124742818.840010.59710@g44g2000cwa.googlegroups.com> ...If the answer is Yes, can you give me an example either in the server side and the client side? I googled a lot, but I can't find nothing regarding this. A lot of thanks. Daniel From pwatson at redlinepy.com Thu Aug 4 18:28:36 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Thu, 04 Aug 2005 17:28:36 -0500 Subject: 2.3 or 2.4 on linux In-Reply-To: <mailman.2728.1123187154.10512.python-list@python.org> References: <mailman.2728.1123187154.10512.python-list@python.org> Message-ID: <3lfj4mF12gsk1U1@individual.net> Sells, Fred wrote: > We are in the process of standardizing ~10 Linux servers on Lineox 4.x, > which is a variant of RedHat Enterprise server I'm told. Part of that > process is to standardize python. > > The baseline install includes python 2.3 which is adequate, but I would like > to standardize on 2.4.1, because it is the latest and greatest and has a few > modules that would be nice to have. I installed python 2.4.1 ok, creating > a python24 directory alongside the pyhton23 directory. The problems started > when I tried to install MySQLdb. > > My problem is that all the rpm installs seem to impact the 2.3 that's there. > When I check the 2.3 site-packages directory, I find alot of goodies like > > Alchemist.py kudzu.py rpmdb > authconfigmodule.so rpmmodule.so CacheBlackBox.py libusermodule.so > _snackmodule.so > mod_python snack.py CompatMysqldb.py mx > CompatMysqldb.pyc MySQLdb FileBlackBox.py _mysql_exceptions.py > URLBlackBox.py > ForgeBlackBox.py _mysql.so xf86config.py ForgeBlackBox.pyo > pyalchemist_python.py > _xmlplus > ixf86configmodule.so > > I assume some system tools must use them, even if I don't. I don't know if > I can just copy all this into the 2.4 site-packages (deleting .pyc and .pyo) > and get what I need. > > I'm not a sysadmin hotshot, and our sysadmin is not a python hotshot, so > between us we can really screw up a system. We would really like to stick > with either apt-get or rpm installs to keep our sysadmin issues under > control. Has anyone hit this wall already and found a reasonable solution?. > > --------------------------------------------------------------------------- > The information contained in this message may be privileged and / or > confidential and protected from disclosure. If the reader of this message is > not the intended recipient, you are hereby notified that any dissemination, > distribution or copying of this communication is strictly prohibited. If you > have received this communication in error, please notify the sender > immediately by replying to this message and deleting the material from any > computer. > --------------------------------------------------------------------------- Since you have two versions of Python on the machine, which one is first in the execution path? What is the output of the 'python -V' command? You might also try 'which python' or 'whence python' commands. From http Thu Aug 18 13:31:03 2005 From: http (Paul Rubin) Date: 18 Aug 2005 10:31:03 -0700 Subject: Bitwise operations in Python? References: <rt3Ne.3$0m4.1@amstwist00> Message-ID: <7x8xyz884o.fsf@ruckus.brouhaha.com> Carl <phleum_nospam at chello.se> writes: > IBITS(I, POS, LEN) > Extracts a sequence of bits. > The result has the value of the sequence of LEN bits in I beginning at bit > POS, right-adjusted and with all other bits zero. > > The bits are numbered from 0 to BIT_SIZE(I)-1, from right to left. > > Examples > > IBITS (14, 1, 3) has the value 7. >>> def ibits(i,pos,len): return (i >> pos) & ~(-1 << len) >>> ibits(14,1,3) 7 From python-list at d1z1.de Fri Aug 26 07:15:32 2005 From: python-list at d1z1.de (Dirk Zimmermann) Date: Fri, 26 Aug 2005 13:15:32 +0200 Subject: classes and list as parameter, whats wrong? In-Reply-To: <7ee3dcd80508260242717153fb@mail.gmail.com> References: <20050826093420.GC23815@hep.physik.uni-siegen.de> <7ee3dcd80508260242717153fb@mail.gmail.com> Message-ID: <20050826111532.GD23815@hep.physik.uni-siegen.de> Thanks for your help. * James <spiralx at gmail.com> [2005-08-26 11:42]: > No, the default paramter LL is only ever created once, not > reinitialised every time the constructor is called - this is quite a > common gotcha! But still, it is not absolutely clear for me, what is going on. So, at least just for my understanding: The parameter LL is created just once for the whole class and not for the object (because I del the object explicitly, which should destroy the object)? Thanks, Dirk From peter at engcorp.com Mon Aug 1 12:52:02 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 01 Aug 2005 12:52:02 -0400 Subject: Is this Pythonic? In-Reply-To: <slrndesi1l.v5t.zen19725@cabalamat.somewhere> References: <slrndesi1l.v5t.zen19725@cabalamat.somewhere> Message-ID: <LOCdnYPPD7jRyXPfRVn-2g@powergate.ca> phil hunt wrote: > Suppose I'm writing an abstract superclass which will have some > concrete subclasses. I want to signal in my code that the subclasses > will implement certan methods. Is this a Pythonic way of doing what > I have in mind: > > class Foo: # abstract superclass > def bar(self): > raise Exception, "Implemented by subclass" > def baz(self): > raise Exception, "Implemented by subclass" Change those to "raise NotImplementedError('blah')" instead and you'll be taking the more idiomatic approach. -Peter From fiddlehead at o2.pl Thu Aug 4 07:34:12 2005 From: fiddlehead at o2.pl (fiddlehead) Date: 4 Aug 2005 04:34:12 -0700 Subject: Pythoncard - gauge component. Message-ID: <1123155251.932977.269900@z14g2000cwz.googlegroups.com> Hello. I'd to use gauge component in the code below. I want to show Queue.quantity in gauge (during running thread, every time when it changed). I don't know which event i must use. I find some info about Time event for gauge but don't understand how it works. Any suggestions? #---gauge.rcrc.py--- {'application':{'type':'Application', 'name':'Template', 'backgrounds': [ {'type':'Background', 'name':'GaugeTest', 'size':(187, 147), 'components': [ {'type':'Gauge', 'name':'gauge', 'position':(4, 10), 'size':(156, 28), 'foregroundColor':(248, 29, 67), 'layout':'horizontal', 'max':100, 'value':0, }, {'type':'Button', 'name':'startbtn', 'position':(5, 44), 'label':'record', }, ] }] } } #--------------------------- #--------gauge.py---------------------- from threading import Thread from threading import Condition import time class Queue: def __init__(self): self.quantity=0 def produce(self): self.quantity+=1 def consume(self): self.quantity-=1 def isEmpty(self): return not self.quantity class Prod(Thread): def __init__(self, queue, cond): Thread.__init__(self) self.queue=queue self.cond=cond def run(self): while 1: self.cond.acquire() self.queue.produce() print "Producer produce(1), quantity:",self.queue.quantity self.cond.notifyAll() self.cond.release() time.sleep(1) class Cons(Thread): def __init__(self, queue, cond): Thread.__init__(self) self.queue=queue self.cond=cond def run(self): while 1: time.sleep(2) self.cond.acquire() while self.queue.isEmpty(): print " >>>Quantity: 0. I'm waiting." self.cond.wait() self.queue.consume() print " >>>Consumer consume(1), quantity:", self.queue.quantity self.cond.release() from PythonCard import model class PythonCardWin(model.Background): def on_initialize(self,event): self.q=Queue() self.c=Condition() self.p=Prod(self.q,self.c) self.c=Cons(self.q,self.c) def on_startbtn_mouseClick(self,event): self.p.start() self.c.start() def on_gauge_???????(self, event): ??????????/ if __name__ == '__main__': app = model.Application(PythonCardWin) app.MainLoop() From bokr at oz.net Sun Aug 7 20:51:22 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 08 Aug 2005 00:51:22 GMT Subject: PEP: Specialization Syntax References: <mailman.2824.1123446062.10512.python-list@python.org> Message-ID: <42f695f8.864310192@news.oz.net> On Sun, 07 Aug 2005 16:22:11 -0400, Nicolas Fleury <nidoizo at yahoo.com> wrote: >Hi everyone, I would to know what do you think of this PEP. Any comment >welcomed (even about English mistakes). > >PEP: XXX >Title: Specialization Syntax >Version: $Revision: 1.10 $ >Last-Modified: $Date: 2003/09/22 04:51:49 $ >Author: Nicolas Fleury <nidoizo at gmail.com> >Status: Draft >Type: Standards Track >Content-Type: text/plain >Created: 24-Jul-2005 >Python-Version: 2.5 >Post-History: >Abstract > > This PEP proposes a syntax in Python to do what is called in > this document "specialization". It contains more than one > proposal: > - Extend square brackets syntax to allow a full call syntax, > using a __specialize__ method, similarly to the __call__ > method. > - Extend function definition syntax to allow specialization > of functions. > - Parameterized types. > > >Motivation > > In his controversial blog entry "Adding Optional Typing to > Python -- Part II" [1], Guido Van Rossum introduced the idea > of "parameterized types" in Python. The proposition was to > use [square brackets] rather than <pointy ones> to allow > prototyping with __getitem__ method. However, the __getitem__ > method is not flexible enough. It doesn't support keyword > arguments and using multiple and default arguments can be pain, > since the only argument received would be a tuple. Calling > can also be error-prone if a tuple can be allowed as a first > argument. This PEP proposes to enhance square brackets syntax > to allow full-call syntax as with parenthesis. > > Note that Guido dropped the idea, for now, of parameterized > types in a following blog entry [2]. This PEP introduces > parameterized types only as a last step, and focus more on > having a syntax to prototype them. This PEP can also serve > as a place to discuss to feature of specialization independently. > > The term "specialization" is used in that document because > "parameterized functions" would sound like an already available > feature. As Guido pointed out [1], "generic" is neither a good > term. Specialization is a term in that case borrowed from C++. > The term alone is not perfect, since it refers to the action of > passing arguments to a "parameterized type" (or function) to > make it usable and a term must still be found to describe the > "unspecialized" type or function. > > Another motivation to this PEP is the frequent usage in Python > of functions to create functions. This pattern is often used > to create callback functions and decorators, to only name these. > However, the fact that both the creation and the use is using > parenthesis can be confusing. Also, a programmer ends up naming > two functions, when only the creating one is called by name and > the created one is doing the job. Some programmers ends up > naming the creating function with the name they would want to > give to the created function, confusing even more the code using > it. To fix this situation, this PEP proposes a syntax for > function specialization. > > >__specialize__ Special Member Function. By "Member Function" do you mean anything different from "method"? > > The first element of this proposal is the addition of the > __specialize__ special member function. The __specialize__ > function can have the same signatures as __call__. When Any function can have any legal signature, so I'm not sure what you are saying. > defined, the definition of __getitem__ has no effect, and > __specialize__ will be called instead. What about subclassing and overriding __getitem__ ? > > The language grammar is extended to allow keyword arguments > and no arguments. For example: > > class MyObject(object): > def __specialize__(self, a=4, b=6, *args, **kwargs): > pass here you can currently write __getitem__ = __specialize__ although you have to remember that obj[:] and related slicing expressions become legal and that obj[] does not, without a language sysntax change. > > obj = MyObject() > obj[b=7, a=8, c=10] > obj[] > > Note that when __specialize__ is defined, __setitem__, > __getslice__ and __setslice__ are still used as before. > > >The specializer Decorator > > To explain the syntaxes proposed in this PEP, the following > decorator is used: > > class Specializer: > def __init__(self, callableObj): > self.callableObj ^^?? = callableObj ? > self.__name__ = callableObj.__name__ > def __specialize__(self, *args, **kwargs): > self.callableObj(*args, **kwargs) > > def specializer(callableObj): > return Specializer(callableObj) > > It takes a callable and make it callable with square brackets > instead. Well, it wraps it, but the thing itself is still called as before from the wrapper, so "it" itself is not "callable" with square brackets ;-) > > >Function Specialization > > A common pattern in Python is to use a function to create > another function: > > def makeGetMemberFunc(memberName): > def getMember(object): > return getattr(object, memberName) > return getMember > > foo(makeGetMemberFunc('xyz')) Either closures like the above or bound methods work for this, so you just want more concise spelling? > > The second element of this proposal is to add a syntax so > that the previous example can be replaced by: > > def getMember[memberName](object): > return getattr(object, memberName) > > foo(getMember['xyz']) > > which is equivalent to: > > @specializer > def getMember(memberName): > def getMember(object): > return getattr(object, memberName) > return getMember > > foo(getMember['xyz']) Have you looked at currying? E.g., http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549 Also, I made a byte-hacking decorator that is able to inject local presets into a function itself (hence without wrapping overhead when used) or to curry in another variation of the decorator. E.g., >>> from ut.presets import presets, curry >>> @curry(memberName='xyz') ... def getMember(obj, memberName): ... return getattr(obj, memberName) ... >>> o = type('',(),{})() >>> o.xyz = 'This is object o attribute xyz' >>> getMember(o) 'This is object o attribute xyz' >>> import dis >>> dis.dis(getMember) 1 0 LOAD_CONST 1 ('xyz') 3 STORE_FAST 1 (memberName) 3 6 LOAD_GLOBAL 0 (getattr) 9 LOAD_FAST 0 (obj) 12 LOAD_FAST 1 (memberName) 15 CALL_FUNCTION 2 18 RETURN_VALUE >>> getMember.func_code.co_argcount 1 Or the presets decorator can make the preset available without having been a part of the original signature at all: >>> @presets(attname='xyz') ... def foo(obj): return getattr(obj, attname) ... >>> foo(o) 'This is object o attribute xyz' >>> dis.dis(foo) 1 0 LOAD_CONST 1 ('xyz') 3 STORE_FAST 1 (attname) 3 6 LOAD_GLOBAL 0 (getattr) 9 LOAD_FAST 0 (obj) 12 LOAD_FAST 1 (attname) 15 CALL_FUNCTION 2 18 RETURN_VALUE As mentioned, these are byte code hacks. So they are pretty fragile, version-portability-wise. > > >Class Specialization > > The last element of this proposal is to add a syntax to pass > arguments to class creation: > > class List[ElementType=object](list): > ... > > This would be the equivalent to: > > @specializer > def List(ElementType=object): > class List(list): > ... > return List > > Note that the additional syntax is inserted before the > inheritance, different than what was initially proposed [1]. > The reason is that inheritance can need the specialization > arguments, and it is more intuitive to use an argument > after its introduction: > > class MyList[ElementType=object](List[ElementType]): > ... > > Before I'd want to extend class syntax this way, I think I'd want to explore some other aspects of class syntax as well, with more (and more persuasive) use cases in view. Also more thought to what is done when and whether the issue is to supply information into existing control contexts or to modify control flow as well, to extend possibilities for customized processing. >Backward Compatibility > > The three propositions are backward compatible. > > >Open Issues > > Instead of adding a __specialize__ method, the __getitem__ When you say "the" __getitem__ method, what do you mean? AFAIK the method itself is an unrestricted function. It just happens that binding it as a class attribute __getitem__ makes it get called from code with square bracket access spellings. I think that's where your changes to allow "additional signatures" would have to go. I.e., in generation of code from the "calling" syntax. To illustrate: >>> class C(object): ... def __getitem__(self, *args, **kwargs): ... return self, args, kwargs ... >>> c=C() >>> c[1] (<__main__.C object at 0x02EF498C>, (1,), {}) >>> c[1,2] (<__main__.C object at 0x02EF498C>, ((1, 2),), {}) >>> c[:] (<__main__.C object at 0x02EF498C>, (slice(None, None, None),), {}) >>> c[kw='key word arg'] File "<stdin>", line 1 c[kw='key word arg'] ^ SyntaxError: invalid syntax But here the problem is not in the __getitem__ method: >>> c.__getitem__(kw='key word arg') (<__main__.C object at 0x02EF498C>, (), {'kw': 'key word arg'}) It's just that square bracket expression trailer syntax does not allow the same arg list syntax as parenthesis calling trailer syntax. > method could be changed to allow additional signatures: > > def __getitem__(self, *args, **kwargs): ... > > Should other operators that square brackets be used for > specialization? Didn't quite parse that ;-) You mean list comprehensions? Or ?? > > >References > > [1] Adding Optional Static Typing to Python -- Part II, > Guido van Rossum > http://www.artima.com/weblogs/viewpost.jsp?thread=86641 > > [2] Optional Static Typing -- Stop the Flames!, Guido van Rossum > http://www.artima.com/weblogs/viewpost.jsp?thread=87182 > > >Copyright > > This document has been placed in the public domain. > Regards, Bengt Richter From peter at engcorp.com Mon Aug 8 08:23:04 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 08 Aug 2005 08:23:04 -0400 Subject: How to determine that if a folder is empty? In-Reply-To: <mailman.2836.1123478023.10512.python-list@python.org> References: <mailman.2836.1123478023.10512.python-list@python.org> Message-ID: <af6dnbAGeN2N0mrfRVn-1g@powergate.ca> could ildg wrote: > I want to check if a folder named "foldername" is empty. > I use os.listdir(foldername)==[] to do this, > but it will be very slow if the folder has a lot of sub-files. > Is there any efficient ways to do this? I'm just curious to know under what circumstances where it's important to know whether a directory is empty it's also important that the operation occur with lightning speed... Reinhold's suggestion to delete the folder was interesting in this respect... isn't that (prior to deleting a folder) just about the only time one cares if it's empty, normally? And in this case you don't need to do the check, as Reinhard shows, so performance isn't an issue. -Peter From mknoth at earthlink.net Thu Aug 4 03:24:01 2005 From: mknoth at earthlink.net (kman3048) Date: Thu, 04 Aug 2005 07:24:01 -0000 Subject: API class creation Message-ID: <dcsfqh+q8o7@eGroups.com> Hello, as a relative newcomer to Python API programming I've got a problem: To extend Python: - there is an API C call to create a module - there is also a API C call to create a method - there is an API C call to create a Class instance Now, I need to create a Class and fill it with Methods and Variables. There are means to create (and attache) methods and variables. However, I have not found how to create a Class within a Module. Or do I have to use a low level API function to allocate an Object from Heap? One possible solution I think is not very elegant: - define a module and class within Python scripting - use this object by creating Instances of this object via API Is there no better way (however, I don't know if above works anyway). Thanks, Matt From cantabile.03 at wanadoo.fr Tue Aug 9 17:59:26 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Tue, 09 Aug 2005 23:59:26 +0200 Subject: gettext again In-Reply-To: <pan.2005.08.08.18.14.51.196634@tuxzilla.tuxhome> References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <pan.2005.08.07.17.52.09.461166@bar.org> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <pan.2005.08.07.20.44.01.986935@bar.org> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> <pan.2005.08.08.13.19.17.121477@bar.org> <42f77cb6$0$25055$8fcfb975@news.wanadoo.fr> <pan.2005.08.08.18.14.51.196634@tuxzilla.tuxhome> Message-ID: <42f9273d$0$22313$8fcfb975@news.wanadoo.fr> stas a ?crit : > As a reminder, make sure that you install gettext in the namespace > of your toplevel module. > What I mean is this: > > test1.py imports test2.py and test3.py > test2.py imports test4.py > > Now you have to place the gettext.install call in test1.py and > then the other modules can access it. > If you place the gettext call in, for example, test2.py then only > test2.py and test4.py have access to it. > So when it don't work as you expect make sure to check if every > module has access to the "_" from gettext. Noticed something : I must import test2.py AFTER gettext.install('test1') and even then, if test3.py imports test2.py, messages won't be translated in test3.py. I have to import test3.py in test1.py too. Is this normal behaviour or is there something I'm missing (again) ? PS : your project looks nice ! From rkern at ucsd.edu Sun Aug 7 04:31:29 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 01:31:29 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <20050807005406.1217660123.whereU@now.com> References: <20050807005406.1217660123.whereU@now.com> Message-ID: <dd4gt8$j7l$1@sea.gmane.org> Eric Pederson wrote: [snip yet another article repeating what's been said over and over again for years] > Is it wrong to appreciate Python as a language, but want to have the nice accoutrements we see in some competing languages? No it's not wrong to want these things. The problem is that we're not lacking in people posting this *same exact complaint* every month or so. We *are* lacking in people implementing these things. If you want to see these nice accoutrements, *stop posting here and get to work*! These threads never, ever bring anything new or interesting to the table, they don't build any consensus, and they certainly don't get any code written. -- 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 michele.simionato at gmail.com Wed Aug 17 12:22:29 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 17 Aug 2005 09:22:29 -0700 Subject: GUI tookit for science and education In-Reply-To: <ddp0fc$qb2$2@achot.icm.edu.pl> References: <ddp0fc$qb2$2@achot.icm.edu.pl> Message-ID: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> 1. Mateusz Loskot: >I would like to ask some scientists or students >which GUI toolkit they would recommend >to develop scientific prototypes (for education and >testing some theories). My vote is for ipython + matplotlib. Very easy and very powerful. Michele Simionato From bokr at oz.net Wed Aug 17 21:41:49 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 18 Aug 2005 01:41:49 GMT Subject: creating/modifying sparse files on linux References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> Message-ID: <4303e125.1735463644@news.oz.net> On 17 Aug 2005 11:53:39 -0700, "draghuram at gmail.com" <draghuram at gmail.com> wrote: > >Hi, > >Is there any special support for sparse file handling in python? My >initial search didn't bring up much (not a thorough search). I wrote >the following pice of code: > >options.size = 6442450944 >options.ranges = ["4096,1024","30000,314572800"] >fd = open("testfile", "w") >fd.seek(options.size-1) >fd.write("a") >for drange in options.ranges: > off = int(drange.split(",")[0]) > len = int(drange.split(",")[1]) > print "off =", off, " len =", len > fd.seek(off) > for x in range(len): > fd.write("a") > >fd.close() > >This piece of code takes very long time and in fact I had to kill it as >the linux system started doing lot of swapping. Am I doing something >wrong here? Is there a better way to create/modify sparse files? > >Thanks I'm unclear as to what your goal is. Do you just need an object that provides an interface like a file object, but internally is more efficient than an a normal file object when you access it as above[1], or do you need to create a real file and record all the bytes in full (with what default for gaps?) on disk, so that it can be opened by another program and read as an ordinary file? Some operating system file systems may have some support for virtual zero-block runs and lazy allocation/representation of non-zero blocks in files. It's easy to imagine the rudiments, but I don't know of such a file system, not having looked ;-) You could write your own "sparse-file"-representation object, and maybe use pickle for persistence. Or maybe you could use zipfiles. The kind of data you are creating above would probably compress really well ;-) [1] writing 314+ million identical bytes one by one is silly, of course ;-) BTW, len is a built-in function, and using built-in names for variables is frowned upon as a bug-prone practice. Regards, Bengt Richter From mwm at mired.org Tue Aug 23 23:55:38 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 23 Aug 2005 23:55:38 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <gaGOe.213$5k1.200@newssvr27.news.prodigy.net> Message-ID: <86wtmcm1j9.fsf@bhuda.mired.org> "Mike Schilling" <mscottschilling at hotmail.com> writes: > "l v" <lv at aol.com> wrote in message > news:1124804082_1011 at spool6-east.superfeed.net... >> Xah Lee wrote: >>> (circa 1996), and email should be text only (anti-MIME, circa 1995), >> >> I think e-mail should be text only. I have both my email and news readers >> set to display in plain text only. It prevents the marketeers and >> spammers from obtaining feedback that my email address is valid. A >> surprising amount of information can be obtained from your computer by >> allowing HTML and all of it's baggage when executing on your computer. >> Phishing comes to my mind first and it works because people click the link >> without looking to see where the link really takes them. > > A formatting-only subset of HTML would be useful for both e-mail and Usenet > posts. Used to be people who wanted to send formatted text via email would use rich text. It never really caught on. But given that most of the people sending around formatted text are using point-n-click GUIs to create the stuff, the main advantage of HTML - that it's easy to write by hand - isn't needed. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From rzzzwilson at hotmail.com Mon Aug 8 23:50:45 2005 From: rzzzwilson at hotmail.com (Ross Wilson) Date: Tue, 09 Aug 2005 13:50:45 +1000 Subject: How to connect to UNIX machine from windows box References: <mailman.2875.1123559014.10512.python-list@python.org> Message-ID: <pan.2005.08.09.03.50.45.208425@hotmail.com> > I want to connect to unix machine using ssh to run some commands . > I have not tried this, but it might be useful. http://www.lag.net/paramiko/ HTH, Ross From nemesis at nowhere.invalid Mon Aug 1 08:36:52 2005 From: nemesis at nowhere.invalid (Nemesis) Date: Mon, 01 Aug 2005 12:36:52 GMT Subject: rfc822 module bug? References: <20050730085418.2139.16534.XPN@orion.homeinvalid> <5ddre11dhqb6s8db3ne8ilop2ubrg7cs46@4ax.com> Message-ID: <20050801123923.1792.87994.XPN@orion.homeinvalid> Mentre io pensavo ad una intro simpatica "Tim Roberts" scriveva: [rfc822 module bug] >>Date: Tue,26 Jul 2005 13:14:27 GMT +0200 >> >>It seems to be correct?, but parsedate_tz is not able to decode it, it >>is confused by the absence of a space after the ",". > > Fascinating. I've written a lot of e-mail programs, and I would have bet > real money that this was not legal by either RFC822 or 2822, but the BNF > certainly supports your assertion that this is valid. [...] > This is actually from RFC2822, but the point is the same. Yes you are right of course. I think I'll submit this bug on the Python web-site. -- "Sfugge un braccio a Pessotto." (Amedeo Goria) |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org From steve at holdenweb.com Thu Aug 25 12:48:37 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Aug 2005 12:48:37 -0400 Subject: variable hell In-Reply-To: <1124982660.23716.56.camel@dot.uniqsys.com> References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> <430dd8e1@127.0.0.1> <1124982294.23716.51.camel@dot.uniqsys.com> <1124982660.23716.56.camel@dot.uniqsys.com> Message-ID: <430DF665.3020803@holdenweb.com> Carsten Haese wrote: > On Thu, 2005-08-25 at 11:04, I hastily wrote: > >>On Thu, 2005-08-25 at 10:43, Nx wrote: >> >>>Thanks for the many replies >>> >>> here is an example for what it will be used for , in this case >>> fixed at 31 fieldvalues: >>> >>> inputvalues=(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25, >>> s26,s27,s28,s29,s30,s31) >> >>inputvalues = tuple(mylist) > > > And actually, you probably don't have to do that, because the execute > method should be able to handle a list just as well as a tuple. > That depends on the database module. Some will insist in tuples, IIRC. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rafi at free.fr Thu Aug 25 10:13:31 2005 From: rafi at free.fr (rafi) Date: Thu, 25 Aug 2005 16:13:31 +0200 Subject: RE Despair - help required In-Reply-To: <430dcea0$1@news.bezeqint.net> References: <430d8883@news.bezeqint.net> <mailman.3506.1124978020.10512.python-list@python.org> <430dcea0$1@news.bezeqint.net> Message-ID: <430dd202$0$2096$626a14ce@news.free.fr> Yoav wrote: > Don't think it will do much good. I need to get them from a file and > extract the last folder in the path. For example: > if I get "c:\dos\util" > I want to extract the string "\util" like frederik says (I use '/' as I am using Unix): >>> import os >>> os.path.split ('c:/foo/bar') ('c:/foo', 'bar') >>> os.path.splitext ('c:/foo/bar') ('c:/foo/bar', '') >>> os.path.splitext ('c:/foo/bar.txt') ('c:/foo/bar', '.txt') or if you are really reluctant: >>> 'c:\\foo\\bar'.split ('\\') ['c:', 'foo', 'bar'] >>> 'c:\\foo\\bar'.split ('\\') [-1] 'bar' > Fredrik Lundh wrote: >> instead of struggling with weird REs, why not use Python's standard >> filename manipulation library instead? >> >> http://docs.python.org/lib/module-os.path.html >> >> </F> >> >> -- rafi "Imagination is more important than knowledge." (Albert Einstein) From tom at tompurl.com Fri Aug 26 15:43:09 2005 From: tom at tompurl.com (tom at tompurl.com) Date: Fri, 26 Aug 2005 14:43:09 -0500 (CDT) Subject: Socket Support When Compiling Python 2.3.5 On Cygwin In-Reply-To: <20050826183634.GA2040@tishler.net> References: <47801.159.53.78.143.1124984387.squirrel@mail.zoper.com> <20050826183634.GA2040@tishler.net> Message-ID: <24507.159.53.110.143.1125085389.squirrel@mail.zoper.com> Thanks for the response Jason. I re-ran make and noticed the following: building '_socket' extension gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fno-strict-aliasing -I. -I/tmp/Python-2.3.5/./Include -I/usr/local/include -I/tmp/Python-2.3.5/Include -I/tmp/Python-2.3.5 -c /tmp/Python-2.3.5/Modules/socketmodule.c -o build/temp.cygwin-1.5.18-i686-2.3/socketmodule.o /tmp/Python-2.3.5/Modules/socketmodule.c: In function `socket_inet_ntop': /tmp/Python-2.3.5/Modules/socketmodule.c:3045: error: `INET_ADDRSTRLEN' undeclared (first use in this function) /tmp/Python-2.3.5/Modules/socketmodule.c:3045: error: (Each undeclared identifier is reported only once /tmp/Python-2.3.5/Modules/socketmodule.c:3045: error: for each function it appears in.) /tmp/Python-2.3.5/Modules/socketmodule.c:3045: warning: unused variable `ip' I then did a Google search on this error and found the following thread on the Cygwin mailing list: http://www.mail-archive.com/cygwin at cygwin.com/msg58066.html Coincidentally, this question was posted by you. So you've helped me doubely today. Not bad! So, as you well know, this is a problem with Cygwin 1.5.18 and will be fixed in the next version. Thanks for all of the help! Tom Purl > Tom, > > On Thu, Aug 25, 2005 at 10:39:47AM -0500, tom at tompurl.com wrote: >> What do I need to do to make sure that this file will be created with >> I compile Python 2.3.5? > > Are there any error messages when the socket module is built during the > Python build? If so, then post them to the list. > > 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 kbk at shore.net Tue Aug 2 22:28:58 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Tue, 2 Aug 2005 22:28:58 -0400 (EDT) Subject: Weekly Python Patch/Bug Summary Message-ID: <200508030228.j732SwHG022094@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 354 open ( -3) / 2888 closed ( +3) / 3242 total ( +0) Bugs : 909 open (+11) / 5152 closed ( +8) / 6061 total (+19) RFE : 191 open ( +0) / 178 closed ( +0) / 369 total ( +0) Patches Closed ______________ PEP 342 Generator enhancements (2005-06-18) http://python.org/sf/1223381 closed by pje Provide tuple of "special" exceptions (2004-10-01) http://python.org/sf/1038256 closed by ncoghlan Patch for (Doc) #1243553 (2005-07-24) http://python.org/sf/1243910 closed by montanaro New / Reopened Bugs ___________________ "new" not marked as deprecated in the docs (2005-07-30) http://python.org/sf/1247765 opened by J?rgen Hermann error in popen2() reference (2005-07-30) CLOSED http://python.org/sf/1248036 opened by Lorenzo Luengo pdb 'next' does not skip list comprehension (2005-07-31) http://python.org/sf/1248119 opened by Joseph Heled set of pdb breakpoint fails (2005-07-31) http://python.org/sf/1248127 opened by Joseph Heled shelve .sync operation not documented (2005-07-31) http://python.org/sf/1248199 opened by paul rubin dir should accept dirproxies for __dict__ (2005-07-31) http://python.org/sf/1248658 opened by Ronald Oussoren 2.3.5 SRPM fails to build without tkinter installed (2005-07-31) http://python.org/sf/1248997 opened by Laurie Harper rfc822 module, bug in parsedate_tz (2005-08-01) http://python.org/sf/1249573 opened by nemesis isinstance() fails depending on how modules imported (2005-08-01) http://python.org/sf/1249615 opened by Hugh Gibson Encodings and aliases do not match runtime (2005-08-01) http://python.org/sf/1249749 opened by liturgist container methods raise KeyError not IndexError (2005-08-01) http://python.org/sf/1249837 opened by Wilfredo Sanchez numarray in debian python 2.4.1 (2005-08-01) CLOSED http://python.org/sf/1249867 opened by LovePanda numarray in debian python 2.4.1 (2005-08-01) CLOSED http://python.org/sf/1249873 opened by LovePanda numarray in debian python 2.4.1 (2005-08-01) http://python.org/sf/1249903 opened by LovePanda IDLE does not start. 2.4.1 (2005-08-01) CLOSED http://python.org/sf/1249965 opened by codepyro gethostbyname(gethostname()) fails on misconfigured system (2005-08-02) http://python.org/sf/1250170 opened by Tadeusz Andrzej Kadlubowski incorrect description of range function (2005-08-02) http://python.org/sf/1250306 opened by John Gleeson The -m option to python does not search zip files (2005-08-02) http://python.org/sf/1250389 opened by Paul Moore Tix: PanedWindow.panes nonfunctional (2005-08-02) http://python.org/sf/1250469 opened by Majromax Bugs Closed ___________ Segfault in Python interpreter 2.3.5 (2005-07-26) http://python.org/sf/1244864 closed by birkenfeld logging module doc needs to note that it changed in 2.4 (2005-07-25) http://python.org/sf/1244683 closed by vsajip manual.cls contains an invalid pdf-inquiry (2005-07-14) http://python.org/sf/1238210 closed by fdrake error in popen2() reference (2005-07-30) http://python.org/sf/1248036 closed by birkenfeld numarray in debian python 2.4.1 (2005-08-01) http://python.org/sf/1249867 closed by birkenfeld numarray in debian python 2.4.1 (2005-08-01) http://python.org/sf/1249873 closed by birkenfeld IDLE does not start. 2.4.1 (2005-08-01) http://python.org/sf/1249965 closed by codepyro Incorrect documentation of re.UNICODE (2005-07-22) http://python.org/sf/1243192 closed by birkenfeld From rkern at ucsd.edu Mon Aug 1 08:25:06 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 01 Aug 2005 05:25:06 -0700 Subject: python ETL In-Reply-To: <1122898017.573173.189620@g14g2000cwa.googlegroups.com> References: <1122898017.573173.189620@g14g2000cwa.googlegroups.com> Message-ID: <dcl4b5$dh5$1@sea.gmane.org> arielgr at gmail.com wrote: > Hi, > My company is involved in the development of many data marts and > data-warehouses, and I currently looking into migrating our old set of > tools (written in Korn) to a new, more dynamic and robust one. I am > looking into python as I have heard that it could be a good contestant > for the job, and wanted to know if anyone knew of an existing open > source project which implements ETL using python, or any libraries that > may ease the production of such tools. I'm not an expert in such matters, I had to Google for the definition of ETL ("extract, transform, and load" which appears to just be a buzzword for "data munging"); but it seems to me that "ETL" is so utterly broad in scope that we can't tell you anything until you give us some more information. What are your sources of data? What kind of data are you dealing with? What kinds of munging do you want to do? What formats are the data going to? However, given that your current toolset is written as Korn shell scripts, I'm pretty confident that Python will be up to the task. -- 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 cam.ac.uk at mh391.invalid Sun Aug 21 05:26:51 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sun, 21 Aug 2005 10:26:51 +0100 Subject: RE vs. SRE In-Reply-To: <430829de$1@news.bezeqint.net> References: <430829de$1@news.bezeqint.net> Message-ID: <de9hcv$5bd$1@gemini.csx.cam.ac.uk> Yoav wrote: > What is the difference between the two? Which on is better to use and why? In Python 2.4, this is what's in re.py: ''' """Minimal "re" compatibility wrapper. See "sre" for documentation.""" engine = "sre" # Some apps might use this undocumented variable from sre import * from sre import __all__ ''' If you're using CPython, they're the same thing now. Use re, because sre is really an undocumented implementation detail of re. -- Michael Hoffman From steve at holdenweb.com Mon Aug 15 07:46:53 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Aug 2005 12:46:53 +0100 Subject: cgi form validation problems In-Reply-To: <1124050921.941278.296970@f14g2000cwb.googlegroups.com> References: <1124050921.941278.296970@f14g2000cwb.googlegroups.com> Message-ID: <ddpva2$qfs$1@sea.gmane.org> googleboy wrote: > Hi. > > I am writing up my own web form. I'm a bit of a newb, and read up many > different how-tos and examples and documentaion. I finally had it > working just great until I decided that I wanted to add some extra > logic because there's one form that submits a particular type of > information. a little extra validation, and the creation of a list of > the values to be mailed in to the site manager. > > The code below is where I am going wrong (edited for brevity): > > > form=cgi.FieldStorage() > > rev_fields = { "param1":None, "param3":None, "param6":None, > "param5":None, "param8":None, "param9":None, "param10":None, > "param11":None } > > > # Everything worked until I added the following if statement: > > if form.has_key("param8"): # Only one form has this > param8 = form.getvalue("param8") > if param8 == 0: # 0 is the default value > print "Content-type: text/html" > debug("You must give the item a rating") > for field in form.keys(): > value = form[field].value > if rev_fields.has_key(field): > rev_fields[field] = value > for key in rev_fields: > if rev_fields[key] == None: > print "Content-type: text/html" > debug("All fields must be filled in. Please check your %s > submission." % key) > else: > #feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" % > (form["param1"].value, form["param3"].value, form["param6"]. > value, form["param5"].value, form["param8"].value, > form["param9"].value, form["param10"].value, form["param11"].value) > #feedback = ("%s, %s, %s, %s, %s, %s, %s, %s" % > (form.getvalue("param1"), form.getvalue("param3"), form.getvalue( > "param6"), form.getvalue("param5"), form.getvalue("param8"), > form.getvalue("param9"), form.getvalue("param10"), > form.getvalue("param11")) > feedback = ("%s, %s, %s, %s, %s, %s" % > (rev_fields["param1"], rev_fields["param3"], rev_fields["param6"], > rev_fields["param5"], rev_fields["param8"], rev_fields["param9"], > rev_fields["param10"], rev_fields["param11"]) I believe you missed a closing parenthesis, which is why you are getting the syntax error - the scanner has to look at the next source line because it expects it to continue the unclosed expression. That's why you are getting confused. > > > #feedback = form[ "score" ].value > > msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback: %s\r\n\r\n" > % > (rev_fields["param2"], rev_fields["param7"], rev_fields["param3"], > rev_fields["param6"])) > Since rev_fields is a dictionary, it would be easier to write this as msg = "From %(param2)s\r\nTo: %(param7)\r\nSubject: %(param3)s\r\n\r\n Feedback: %(param6)s\r\n\r\n" % rev_fields module any text wrapping the mailstream might have done to the above single line. > > If I comment out the 'else:' logic, it works great. But then I don't > get a list called feedback containing all teh bits I want, The error I > get is really strange, too: > > [Mon Aug 15 05:54:58 2005] [error] [client 60.224.106.116] Premature > end of script headers: /var/www/users/senta/html/gobooks/cgi/form.py > File "/var/www/users/senta/html/gobooks/cgi/form.py", line 99 > msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n Feedback: > %s\r\n\r\n" % > ^ > SyntaxError: invalid syntax > > Just a simple assignation.... I did think it might have been an > indentation error, but I changed that around and got a message telling > me about an indentation problem, which this doesn't do. > > I have tried several different ways to assign the values, as you can > see by the commented out lines. Tried getting the values directly from > teh form, and also from the validated rev_fields dictionary. I'd be > extremely grateful to anyone who helps me through this. > > TIA > > Googleboy > Hope this helps. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sjmachin at lexicon.net Wed Aug 10 00:28:05 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 10 Aug 2005 14:28:05 +1000 Subject: Does any one recognize this binary data storage format In-Reply-To: <42f97878.1053366641@news.oz.net> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <ddatkk$10k$1@ss405.t-com.hr> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> Message-ID: <42f98255@news.eftel.com> Bengt Richter wrote: > On Tue, 09 Aug 2005 21:50:06 -0000, Grant Edwards <grante at visi.com> wrote: > > >>On 2005-08-09, Scott David Daniels <Scott.Daniels at Acm.Org> wrote: >> >>>Grant Edwards wrote: >>> >>>>>Ex #1) 333-3333 >>>>>Hex On disk: 00 00 00 80 6a 6e 49 41 >>>>> >>>>>Ex #2) 666-6666 >>>>>Hex On disk: 00 00 00 80 6a 6e 59 41 >>>> >>>>So there's only a 1-bit different between the on-disk >>>>representation of 333-3333 and 666-6666. >>>> >>>>That sounds pretty unlikely. Are you 100% sure you're looking >>>>at the correct bytes? >>> >>>Perhaps the one bit is an exponent -- some kind of floating point >>>based format? That matches the doubling of all digits. >> >>That would just be sick. I can't imagine anybody on an 8-bit >>CPU using FP for a phone number. >> >>-- >>Grant >> > > >>> def double_binary_lehex_to_double(dhex): > ... "convert little-endian hex of ieee double binary to double" > ... assert len(dhex)==16, ( > ... "hex of double in binary must be 8 bytes (hex pairs in little-endian order") > ... dhex = ''.join(reversed([dhex[i:i+2] for i in xrange(0,16,2)])) > ... m = int(dhex, 16) > ... x = ((m>>52)&0x7ff) - 0x3ff - 52 > ... s = (m>>63)&0x1 > ... f = (m & ((1<<52)-1))|((m and 1 or 0)<<52) > ... return (1.0,-1.0)[s]*f*2.0**x > ... > >>> double_binary_lehex_to_double('000000806a6e4941') > 3333333.0 > >>> double_binary_lehex_to_double('000000806a6e5941') > 6666666.0 > >>> double_binary_lehex_to_double('0000108777F9Fc41') > 7777777777.0 > > ;-) > > Regards, > Bengt Richter Well done, Scott & Bengt!! I've just verified that this works with all 12 corrected examples posted by the OP. Grant, MS-DOS implies 16 bits at least; and yes there was an FPU (the 8087). And yes there are a lot of sick people who store things as numbers (whether integer or FP) when the only arithmetic operations that can be applied to them stuff them up mightily (like losing leading zeroes off post-codes, having NEGATIVE tax file numbers, etc) and it's still happening on the best OSes and 64-bit CPUS. Welcome to the real world :-) Cheers, John From dan at cellectivity.com Wed Aug 10 05:05:22 2005 From: dan at cellectivity.com (Dan) Date: Wed, 10 Aug 2005 10:05:22 +0100 Subject: What are modules really for? In-Reply-To: <42F9BC7D.1050300@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <1123664722.30409.15.camel@localhost.localdomain> > Functions existing in a module? Surely if "everything is an object" (OK > thats Java-talk but supposedly Python will eventually follow this too) > then there should be nothing in a module thats not part of a class. No, it's a bit the other way around. In Python, functions are objects: >>> del MyFunction >>> def MyFunction(x='abc', y='xyz'): pass ... >>> print MyFunction.func_defaults ('abc', 'xyz') > Related classes in the same file? Be careful. Doesn't anything "knowing" > about anything else compromise encapsulation? You might think of modules in Python as like packages in Java. However, putting classes in the same module doesn't give them any additional powers to interact with each other. (At least, not that I know of.) -- Distributed computing is like driving a wagon pulled by a thousand chickens. - Paul Lindner From usenet at isbd.co.uk Fri Aug 26 07:28:36 2005 From: usenet at isbd.co.uk (usenet at isbd.co.uk) Date: 26 Aug 2005 11:28:36 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <Xns96BD814C9C690castleamber@130.133.1.4> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8391F6ogbU1@individual.net> <Xns96BE3DCCE99C4castleamber@130.133.1.4> Message-ID: <3n8cn3Fb539U2@individual.net> In comp.lang.perl.misc John Bokma <john at castleamber.com> wrote: > usenet at isbd.co.uk wrote: > > > "NNTP and its applications" have evolved to provide a set of much more > > sophisticated means of accessing and giving information than any forum > > I've ever seen. > > Example(s). And do users need those sophisticated things? > Kill files Selecting posts and threads based on a scoring system A huge variety of different newsreaders allowing different users to access the news in they way they want. I don't use all the possibilities (e.g. I don't use kill files) but I do use a 'minority' text based newsreader because it is ideal for me. I don't get the option of a text based forum reader - I doubt many forums work with lynx. -- Chris Green From spam.csubich+block at block.subich.spam.com Thu Aug 4 09:34:50 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Thu, 04 Aug 2005 09:34:50 -0400 Subject: Metaclasses and class variables In-Reply-To: <mailman.2711.1123159559.10512.python-list@python.org> References: <mailman.2711.1123159559.10512.python-list@python.org> Message-ID: <DOoIe.9923$jq.8755@bignews3.bellsouth.net> Jan-Ole Esleben wrote: > class Meta(type): > def __new__(cls, name, bases, d): > d['classvar'] = [] > return type.__new__(cls, name, bases, d) The problem is that __new__ is called upon object construction, not class definition, but you're trying to set the class variables at definition-time. From godwinburby at gmail.com Wed Aug 24 00:34:27 2005 From: godwinburby at gmail.com (Godwin) Date: 23 Aug 2005 21:34:27 -0700 Subject: Eve from Adams' Ribs In-Reply-To: <1124791960.981976.43120@o13g2000cwo.googlegroups.com> References: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> <0bheed.c46.ln@lightning.itga.com.au> <1124791960.981976.43120@o13g2000cwo.googlegroups.com> Message-ID: <1124858067.046771.183610@f14g2000cwb.googlegroups.com> Thanx for the links , i loved the "monty lingua" module u gave me before. From tkpmep at hotmail.com Tue Aug 23 17:41:54 2005 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: 23 Aug 2005 14:41:54 -0700 Subject: Reading just a few lines from a text file Message-ID: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> I have a text file with many hundreds of lines of data. The data of interest to me, however, resides at the bottom of the file, in the last 20 lines. Right now, I read the entire file and discard the stuff I don't need. I'd like to speed up my program by reading only the last 20 lines. How do I do this? Thomas Philips From pink at odahoda.de Tue Aug 23 14:39:59 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Tue, 23 Aug 2005 20:39:59 +0200 Subject: DeprecationWarning: Non-ASCII character '\xf3' References: <LeJOe.92020$US.27276@news.ono.com> Message-ID: <defqdf$q9u$1@online.de> jau wrote: > Hi co-listers! > > I have been off Python for 2 years and now, that i'm used to Eclipse and > Java, I decided to start a project with Python to refresh skills this > time using Eclipse and TrueStudio. But now, two things can be occured > since the last time i used it. > > the first one, something concerning to the encoding has changed and i > haven't noticed it. > > the other one, when using Python from Eclipse i have to add any special > config lines at the begining of my Python files. > > if i have this hello world python "program" (i have to call it by > someway, hahaha) > > print "hello world" > > i get this output > > hello world > sys:1: DeprecationWarning: Non-ASCII character '\xf3' in file > C:\Workspace\J&J\src\es\jau\main.py on line 2, but no encoding declared; > see http://www.python.org/peps/pep-0263.html for details > > the article mentioned above didn't explain so much for me. > > i doesn't look to be an error, but curiosity is bitting me... what's > really happening here? Do I need to do any special thing to avoid this? The single print statement above should not trigger this warning. Are there any non-ASCII character in the file (perhaps comments?). If you use non-ASCII characters in python source files, you have to tell the interpreter which encoding you are using - otherwise funny things will happen. You have to find out which encoding Eclipse uses to save file (looks like iso-8859-1) and add the line # -*- coding: iso-8859-1 -*- at the top of the file. Python does not make any assumptions about the encoding beyond US-ASCII (perhaps it does, but it does not encourage taking advantage of this) - if you use anything else, then you'll have to declare it. This will be important, if you use unicode strings: u"str?nge characters" Python must know the encoding of the file in order to decode the string literal into an unicode string. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From steve at holdenweb.com Fri Aug 26 10:59:06 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Aug 2005 10:59:06 -0400 Subject: variable hell In-Reply-To: <delsi6$c5l$1@nnews.pacific.net.hk> References: <mailman.3511.1124982438.10512.python-list@python.org> <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> <mailman.3535.1125002125.10512.python-list@python.org> <rNOSPAMon-88C73B.16253825082005@news.gha.chartermi.net> <delsi6$c5l$1@nnews.pacific.net.hk> Message-ID: <denapa$der$1@sea.gmane.org> Nx wrote: > Thanks for all the responses and animated discussion, > which is still the best way to learn something new. > > Most of the time it is not that you want to do something > in a certain way , it rather is one cannot think of a > better , faster more efficient way . > > Nx Yes. A large part of learning a language is discovering the many idioms that have already been established for doing certain things. These are a kind of shorthand, established by long convention, that allow one to avoid the "learning-by-use" curve. When I first came to Python that was a very rewarding aspect of this newsgroup. To this day it remains one of the friendliest tech-spots in cyberspace. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mwm at mired.org Tue Aug 2 20:42:01 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 20:42:01 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <slrndeomre.oj7.zen19725@cabalamat.somewhere> <mailman.2452.1122811372.10512.python-list@python.org> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> <mailman.2469.1122836998.10512.python-list@python.org> <slrnderles.t74.zen19725@cabalamat.somewhere> <861x5deype.fsf@bhuda.mired.org> <slrndeu8l1.2ee.zen19725@cabalamat.somewhere> Message-ID: <86fytretra.fsf@bhuda.mired.org> zen19725 at zen.co.uk (phil hunt) writes: > On Tue, 02 Aug 2005 00:42:53 -0400, Mike Meyer <mwm at mired.org> wrote: >>zen19725 at zen.co.uk (phil hunt) writes: >>> In practise any Python GUI is going to contain code from otyher >>> languages since if it was coded all the way down in python it would >>> be too slow. >>Not necessarily. My window manger is Python all the way down > Your X server is written in Python? :-) I see the smiley, but just to make sure no one is confused, the answer is no. My window manager is written in Python. Unlike monolithic programs in proprietary OS's, X seperates the window manager from the thing that actually paints pixels on the screen. It's possible to run the window manager on another computer entirely, and people used to sell boxes that ran in that configuration out of the box. >> - it uses >>the Python Xlib implementation - and is plenty fast. >>Of course, it doesn't do a lot of graphics work, even for a window >>manager. > That's what I mean: painting the individual pixels on the screen. Well, no X graphics package will get any closer to that than my python window manager. The python code sends packets to the X server, and parses what comes back from it. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mwm at mired.org Thu Aug 4 21:33:29 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 04 Aug 2005 21:33:29 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <87wtn245qo.fsf@wilson.rwth-aachen.de> Message-ID: <86slxpyxp2.fsf@bhuda.mired.org> Torsten Bronger <bronger at physik.rwth-aachen.de> writes: > Hall??chen! > Mike Meyer <mwm at mired.org> writes: >> Torsten Bronger <bronger at physik.rwth-aachen.de> writes: >>> Mike Meyer <mwm at mired.org> writes: >>>> Torsten Bronger <bronger at physik.rwth-aachen.de> writes: >>>> [...] >>>> You didn't answer the question about how you define agile >>>> project. Please do so if you expect a comment on this. >>> Projects with a high Sourceforge activity index. >> That doesn't seem to match the common defintion of "agile" when it >> comes to programming. Then again, you have a habit of using words >> to mean whatever you want, without much reference to how they're >> used by the rest of the industry. > I'm not part of the industry. That's no excuse for not learning the terminology, or at least avoiding using phrases which already have a common meaning. > Sorry, but now the arguments are getting destructive. Agile > programming is a fixed phase, which I've never used. (And which > makes no sense in this discussion.) >> Sorry, but you're wrong. FORTRAN is very much a general purpose >> language. [...] > It's not about the potential use of a language, but its actual use. Of course it's not about potential uses. All languages are equivalent at that level. What it's about is the features and facilities of the language, and how well they support general-purpose alternatives. FORTRAN has always been a bit behind other alternatives, but not so far behind that it doesn't get used for real work. That's as true today as it was in 1955. The difference is ther are a lot of other choices, so it gets chosen less often. But I note that at least one of the 155 projects on SourceForge that list FORTRAN as a language is a GUI application for Windows. >>>> You can't have it both ways. Either C/C++ is all legacy code, or >>>> it's not. >>> ... is wrong in my opinion. Why should this be? >> Because any given proposition is either true or false. > If I say "most people are right-handed", then this means neither > that all people are right-handed nor that none is. Right. It means that *some* people are right-handed, and some people aren't. Just like some C/C++ applications are legacy code, and some aren't. Which contradicts your earlier assertion that C/C++ applications were all legacy code. >>>> There are *lots* of applications areas that don't need GUIs, and >>>> don't run on Windows. >>> This becomes a discussion about estimates we both don't know >>> exactly, and weight differently, so I'll leave it here. >> No, it's not a discussion about estimates. The average household >> in a G8 country has more computers that don't run Windows - and in >> fact don't have GUIs at all - than otherwise. [...] > However, it's about the types of software which is being produced > today. Ok, let's talk about the kinds of software being produced, and where it's coming from? All those computers need software. The embedded software market is pretty active - and is hiring a lot of C (specifically C, not C++) programmers. They may be hiring C++ programmers as well; I don't examine those ads. Could those people be using VC++? I suspect not, but can't say for sure. Earlier, you said you wanted a popular language because they get cool features faster. You hold up two proprietary VC++ (which is just an development environment) and VB as "popular" languages. If you've been watching software development long enough, you'd realize that "cool things" usually come from open source projects first. There are a number of reasons for this. One is that most of the software written isn't written for commercial sale: it's developed to make some product or employee more effective. Most of that is developed by or for various governments, which in the US means it's either PD (though possibly undistributed) or classified. People working on such software are every bit as likely to come up with "cool things" as people developing software for sale. The other reason is that if you want to experiment with some "cool thing", it's a lot easier to take an open source project and add that feature than it is to get sources to a proprietary product or write the thing from scratch. Once you do that, there's an incentive to give the feature back to the community, in that you dont have to patch every release of the product to include your feature. These two things play off of each other. People working on inhouse products don't have the legal headaches with open source software that people working on proprietary products do. So they don't have problems with making their business depend on them - and once they've done that, they tend to let employees spend time working on those products. I think this is a lot of open source development comes form - developers getting paid to fix the software because their employer needs it, not people working in their spare time. Hmm. I seem to have gotten on a soapbox. Sorry about that... <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From bearophileHUGS at lycos.com Sat Aug 13 06:07:28 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 13 Aug 2005 03:07:28 -0700 Subject: Spaces and tabs again Message-ID: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> Hello, I know this topic was discussed a *lot* in the past, sorry if it bores you... >From the Daily Python-URL I've seen this interesting Floating Point Benchmark: http://www.fourmilab.ch/fourmilog/archives/2005-08/000567.html This is the source pack: http://www.fourmilab.ch/fbench/fbench.zip I've read its Python sourcecode, probably there few things that can be changed to speed it up some (like moving the main code in a function, using Psyco, or even vectorizing it with numarray), but I've had problems in changing the code because it mixes tabs and spaces for the indentations. I like a lot how Python uses indentations, I've never had problems with them in my programs, but I have big problems when I find a source that mixes them (I often need time to find how much spaces a tab is, to try to convert them all in spaces). I know that some people likes tabs, and other people likes spaces, so probably a single standard cannot be enforced, but I think the python compiler must generate an error (and stop compiling) when the sourcecode of a module contains both spaces and tabs to indent the lines of code (and comments lines too?). Bye, bearophile From uval at rz.uni-karlsruhe.de Thu Aug 11 15:04:21 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-15?Q?Daniel_Sch=FCle?=) Date: Thu, 11 Aug 2005 21:04:21 +0200 Subject: len(sys.argv) in (3,4) In-Reply-To: <ddfqm1$hq4$1@news2.rz.uni-karlsruhe.de> References: <ddfqm1$hq4$1@news2.rz.uni-karlsruhe.de> Message-ID: <ddg800$qeu$1@news2.rz.uni-karlsruhe.de> I just tried the same code at home and it worked fine it has to do with windows .. some settings or whatever (python 2.4.1 installed on both) maybe someone have experienced the same problem and had more luck in solving the puzzle From onurb at xiludom.gro Tue Aug 23 06:35:51 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 23 Aug 2005 12:35:51 +0200 Subject: loop in python In-Reply-To: <mailman.3400.1124782504.10512.python-list@python.org> References: <20050823065501.GA24558@mrna.tn.nic.in> <dedcpn$h03$1@sea.gmane.org> <mailman.3400.1124782504.10512.python-list@python.org> Message-ID: <430afc09$0$30445$636a15ce@news.free.fr> km wrote: >>If you want a fast language, try Holden. I've just invented it. >>Unfortunately it gets the answer to every problem wrong unless the >>answer is 42, but boy it runs quickly. The code for the whole >>interpreter (it's written in Python) follows: > > >>print 42 > > > great ! u can use it for ur own projects. but pls donot suggest it to anyone else. <ot> If you hope to be taken seriously, please abandon the sms-talk style here. </ot> > anyway improve it - its quite buggy now :-D Nope, it works just as described. "It's not a bug, Sir, it's a feature" !-) > >>Speed of execution is so insignificant for the majority of programming problems > > I donot agree with that. > If thats the case then no one would be using C or C++ etc for instance. 1/ "for the majority of programming problems" : "the majority", not "all and every". 2/ Apache is coded in C, but there are cases where it can be outperformed by a specializd Python-coded HTTP server. 3/ OpenOffice is coded in C++ and it's one of the slowest app I ever saw (even Photoshop 6 on a dying P133/32mo Win98 box is more responsive) In most systems, the parts that can be performance bottlenecks are the presentation and the data persistence layers. That's the parts that are *already* coded in low-level languages and optimized as can be - if of course you use existing tools (GUI Toolkit, RDBMS etc) instead of trying to reimplement'em in Perl/Python/whatever !-) > one important thing is that i am not comparing python with C but with similar language, Perl. What you are "comparing" is either IO times (the "print loop" program), where Perl beats C - which means that Perl's IO have been written at a very low level instead of relying on the stdlib's IO - or absolutely meaningless (I just don't care if no-op loops are slow since I don't write no-op loops). > well ofcourse i dont jump into conclusion, Yes you did. > just with just a simple 'loops' snippet, that python is slower than perl. for i in xrange(100000): print "this 'benchmark' is ABSOLUTELY MEANINGLESS" > but when speed is important then ? also i hate people recommending "if u need speed code it as a C extension module". ofcourse i donot expect pure python/perl program to execute at the speed of a C program. In some cases, they can be fastest than the C version. > >>that this obsession reveals a certain inexperience. > > > its neither obsession nor inexperience ... its just the requirement. Which "requirement" ? > i think less buggy code is not the main concern for all. +1 QOTW > i am aware one of the main principle python isn founded is better readability but is that a feature which decreases execution speed ? Nope. It has to do with implementation (of the language), not design. > there obviously will be a bias in this list towards python Oh, really ? Err, wait, what's the name of this group, exactly ? > but i need a honest opinion of python vs perl. (especially when it comes to webscripting) This is another question, and has nothing to do with your "benchmark", but FWIW, Google uses Python, not Perl. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From Scott.Daniels at Acm.Org Wed Aug 24 17:07:45 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Aug 2005 14:07:45 -0700 Subject: Sorta noob question - file vs. open? In-Reply-To: <6tmpg19aa138j4cv2s0k5j7ir1goercvb0@4ax.com> References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> <430b9cc0$1@nntp0.pdx.net> <6tmpg19aa138j4cv2s0k5j7ir1goercvb0@4ax.com> Message-ID: <430cd5a2$1@nntp0.pdx.net> Peter A. Schott wrote: > I'll have to try this again. I obviously did something wrong in my code. I was > getting errors about not being able to write a string because it wasn't > supported. It was driving me nuts for a while until I just gave up and went > back to open(). I expect somewhere previously in the same frame (perhaps the interpreter top level) you had done either "file = open(...)" or "file = file(...)" which would prevent you from getting to the file in __builtins__. --Scott David Daniels Scott.Daniels at Acm.Org From bokr at oz.net Fri Aug 5 14:02:44 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 05 Aug 2005 18:02:44 GMT Subject: Passing a variable number of arguments to a wrapped function. References: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> Message-ID: <42f3a8dc.672538178@news.oz.net> On 5 Aug 2005 08:34:32 -0700, stephen at theboulets.net wrote: >Is there a better way of doing this so that I don't have to go through >every permutation of possible arguments (the example here from the >matplotlib 'plot' function): > >def makeplot(self, xvalues, yvalues, linecolor='', linewidth=''): > if linecolor and linewidth: > plot(xvalues, yvalues, linecolor, linewidth=linewidth) > elif linecolor: > plot(xvalues, yvalues, linecolor) > elif linewidth: > plot(xvalues, yvalues, linewidth=linewidth) > else: > plot(xvalues, yvalues) > It seems like you are not changing the order or values of arguments, so I'm wondering if this would work for you: def makeplot(self, *args, **kwargs): plot(*args, **kwargs) and if not, why not. Regards, Bengt Richter From rkern at ucsd.edu Tue Aug 23 04:28:53 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 23 Aug 2005 01:28:53 -0700 Subject: What's the difference between built-in func getattr() and normal call of a func of a class In-Reply-To: <1124784437.974574.12480@o13g2000cwo.googlegroups.com> References: <1124784437.974574.12480@o13g2000cwo.googlegroups.com> Message-ID: <deemo6$ciu$1@sea.gmane.org> Johnny wrote: > Hi, > > I wonder what is the difference between the built-in function > getattr() and the normal call of a function of a class. Here is the > details: > > getattr( object, name[, default]) > > Return the value of the named attributed of object. name must be a > string. If the string is the name of one of the object's attributes, > the result is the value of that attribute. For example, getattr(x, > 'foobar') is equivalent to x.foobar. If the named attribute does not > exist, default is returned if provided, otherwise AttributeError is > raised. > > Is that to say the only difference between the two is that no > matter the specific function exists or not the built-in func will > always return a value, but "class.function" will not? No, getattr(object, name) will raise an AttributeError if the attribute doesn't exist; no value will be returned. When getattr(object, name, default) is called, then a value will be returned regardless of whether or not the attribute exists (but possibly something else may go wrong). In terms of practice, the getattr() form allows you to specify the attribute at run-time rather than write-time. You can do things like iterate over a list of attributes. -- 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 python-url at phaseit.net Fri Aug 12 17:52:16 2005 From: python-url at phaseit.net (Cameron Laird) Date: Fri, 12 Aug 2005 21:52:16 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) Message-ID: <mailman.3059.1123952347.10512.python-announce-list@python.org> QOTW: "... So I started profiling the code and the slowdown was actually taking place at places where I didn't expect it." -- Guyon Mor?e (and about twenty-three thousand others) "[A] suggestion from the world of 'agile development': stop making so many decisions and start writing some actual code!" -- Peter Hansen Scott David Daniels and others illustrate that the most common answer for Python is, "It's (already) in there." In the case at hand the subject is primitive symbolic arithmetic: http://groups.google.com/group/comp.lang.python/index/browse_frm/thread/13ed519653969e55/ Andy Smith rails against "frameworks": http://an9.org/devdev/why_frameworks_suck?sxip-homesite=&checked=1 "Porcupine is a [Python-based] Web application server that features an embedded object database, the Porcupine Object Query Language, XMLRPC support, and QuiX, an integrated JavaScript XUL motor." http://www.innoscript.org Getters and setters are (mostly) for other languages; Python has properties (and descriptors!): http://groups.google.com/group/comp.lang.python/browse_thread/thread/f903ab167c91e6ce/ Ramza Brown confusingly but helpfully repackages "the absolute minimum libraries needed for Python to work with Win32": http://groups.google.com/group/comp.lang.python/browse_thread/thread/d0d4e4303e985729/ Paolino offers a technique for *pruning* attributes in a subclass: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1805446521e8f34e/ Hard though it may be for some of us to accept, a zillion threads might not be all bad. http://www.usenix.org/events/hotos03/tech/vonbehren.html Python helps win awards: http://groups.google.com/group/comp.lang.python/browse_thread/thread/c6190563601c437f/ Python fits on small machines, sort-of: http://groups.google.com/group/comp.lang.python/browse_thread/thread/834f5b571be0b5f6/ ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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. del.icio.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/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 <Python-URL at phaseit.net> should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask <claird at phaseit.net> 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 http Mon Aug 22 05:48:24 2005 From: http (Paul Rubin) Date: 22 Aug 2005 02:48:24 -0700 Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> <1124703805.178363.145870@g49g2000cwa.googlegroups.com> Message-ID: <7x64tyxpxz.fsf@ruckus.brouhaha.com> "Greg McIntyre" <greg at puyo.cjb.net> writes: > while c = f.read(1): > # ... > > I couldn't find any general PEPs along these lines, only specific ones > (e.g. 308 re. an if-then-else expression). I often end up doing something like this: class foo: def set(self, x): self.x = x return x c = foo() while c.set(f.read(1)): # do stuff with c.x In that file example, it's too much nuisance, but when you're comparing some input against a series of regexps and you'd otherwise need a multi-line construction for each one, this method comes in quite handy. From hancock at anansispaceworks.com Tue Aug 30 18:00:36 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 30 Aug 2005 17:00:36 -0500 Subject: OpenSource documentation problems In-Reply-To: <ZXTQe.811$la.216@newssvr22.news.prodigy.net> References: <mailman.113.1125301928.8229.python-list@python.org> <ZXTQe.811$la.216@newssvr22.news.prodigy.net> Message-ID: <200508301700.36140.hancock@anansispaceworks.com> On Tuesday 30 August 2005 02:32 am, Bryan Olson wrote: > I don't see any need to look beyond Python for a good example of > poor documentation. Are there serious Python programmers who > don't constantly struggle with errors and omissions in the doc? Uh, yes, actually. IMHO, the available Python documentation is, extremely helpful, concise and accessible. Maybe you aren't using all of it: 1) Remember that any object or module you load will tell you its contents with a dir() or give you automatically generated documentation with help(). This documentation has the advantage of being almost always accurate and up-to-date, even if it is sometimes too brief and poorly explained. 2) More in-depth documentation for the Python standard library is available in the "Library Reference". This covers everything from built-in functions to fairly obscure modules that are nevertheless in the Python library. 3) Questions about the functioning of the language are most accurately resolved by trying them out in the interpreter. This is usually faster than any documentation search. Python's interpreter is extremely friendly and easy to start up, so this is really easy to do. 4) But if you want a more theoretical and explained version of the language, there's always the "Language Reference". Between these 4 sources, I can resolve almost any question that comes up about the core Python language. Somewhat more obscure applications are covered by the "Extending and Embedding" document, and there are other documents and tutorials either in your Python distribution (if you have a good one) or on the http://www.python.org website). If you're really looking for cookbook examples, there are specific websites to check for, though I usually just hit Google with a few keywords. And if all that fails you, you can always ask the people on this list. I have NEVER seen a closed source application or programming language that came with that much documentation and support. OTOH, there are lots of poorly-documented third-party Python modules (as in any language). Zope is a particularly nasty example -- though I think I understand some of the reasons behind that (rapidly changing API, poor interaction with doc tools, etc). F. Lundh's documentation for Python Imaging Library is excellent, though. I also have to say, that as a module writer, Python's support for self-documenting code or "literate programming" is excellent. I'm really coming to appreciate the value of this. I don't know, maybe I just don't have high expectations out of documentation. I've certainly made do with far worse documentation than Python has. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From mccutchen at gmail.com Fri Aug 19 13:11:12 2005 From: mccutchen at gmail.com (Will McCutchen) Date: 19 Aug 2005 10:11:12 -0700 Subject: Idempotent XML processing References: <mailman.3286.1124468557.10512.python-list@python.org> Message-ID: <1124471472.839234.109490@z14g2000cwz.googlegroups.com> > In my current project, I am working with XML data in a protocol that has > checksum/signature verification of a portion of the document. > ... > the server sends me XML with empty elements as full open/close tags, > but toxml() serializes them to the XML empty element (<Element/>), so > the checksum winds up not matching. (This is a horrible response to your question, so I apologize in advance.) Does it even make sense to use a checksum to verify XML, since there are basically[1] infinite ways to validly write equivalent XML data? I would think the only way that a checksum would be a viable way to verify a document is if you had some sort of standard normalized format, and made sure the data was normalized both before you computed and before you calculated the checksum. That way, you would be sure that, for instance, all insignificant whitespace was removed and all empty elements were represented uniformly. Again, I'm sorry because I didn't provide any real useful information, I just tried to poke holes in your current project. Will. [1] Unless all of your whitespace is significant From zarnovican at gmail.com Tue Aug 16 14:38:31 2005 From: zarnovican at gmail.com (BranoZ) Date: 16 Aug 2005 11:38:31 -0700 Subject: get the return code when piping something to a python script? References: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> Message-ID: <1124217511.485128.125930@g49g2000cwa.googlegroups.com> mhenry1384 wrote: > On WinXP, I am doing this > > nant.exe | python MyFilter.py > > How do I set the return code from MyFilter.py based on the return of > nant.exe? Is this possible? I don't know how it is on WinXP, but in UNIX you IMHO cannot easily get the retcode of the peer _if_ the pipe was created by your common parent, the shell. Only the parent knows retcodes of its children. You can communicate the status over the pipe. E.g. when producer will successufuly finish it will write (let say) last line with only one '.' Didn't help you much.. BranoZ From v.vayer at gmail.com Wed Aug 24 04:50:25 2005 From: v.vayer at gmail.com (v.vayer at gmail.com) Date: 24 Aug 2005 01:50:25 -0700 Subject: execfile in global scope Message-ID: <1124873425.620610.170970@g47g2000cwa.googlegroups.com> I need to execfile() from a function in order to set value for a global variable from inside the executed file. I know there are "globals" and "locals" optional arguments for execfile, but I just can't figure out how to use them correctly. Here is an example: Change.py ========= x = 555 Main.py ======= def changevar(): execfile("change.py") x = 111 # global var changevar() print x # returns 111 instead of 555 From mensanator at aol.com Tue Aug 30 11:10:00 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 30 Aug 2005 08:10:00 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> Message-ID: <1125414600.375677.201060@z14g2000cwz.googlegroups.com> n00m wrote: > When I double-click on "some.py" file console window appears just for a > moment and right after that it's closed. If this script is started from > inside of IDLE (F5 key) then it executes as it should be (e.g. > executing all its print statements). > > Any ideas? OS: Windows; Python 2.3.4. Thanks. Your console window closes when the program terminates. And no, you won't necessarily see any of your print statements before the window closed. They were buffered and the window closed before they could be displayed. Start a console window manually. From the command prompt, type some.py or python some.py From Pierre-Eric.Melchy at uni-konstanz.de Thu Aug 4 07:10:47 2005 From: Pierre-Eric.Melchy at uni-konstanz.de (Pierre-Eric.Melchy at uni-konstanz.de) Date: 4 Aug 2005 04:10:47 -0700 Subject: Reliable destruction Message-ID: <1123153847.649321.235450@z14g2000cwz.googlegroups.com> Hello, I have a class measurement representing a physical measurement. Different objects in this class represent laboratory equipment, which might raise an exception (e.g. overtemperature). In any case the equipment has to be switched off after the experiment, since if a power supply stays in the on state for a prolonged time equipment may be destroyed. Switching off is done by invoking the destructors of the instruments. My measurement looks like this: class measurement: def __init__(self): self.setup() self.run() def setup(self): self.powerSupply=apparate.PowerSupply() self.magnet=apparate.magnet() # Exception("Communication Error") self.thermo=apparate.thermometer() # some 5 more instruments def run(): for i in range(100) self.powerSupply.setCurrent(i) # Exception("Overcurrent") self.magnet.setField(0.5*i) Different measurements are executed in a script which might run overnight: If one measurement raises an exception the next one might still work and I don't want to loose the results from the following experiments. try: measurement() except: pass try: measurement2() except: pass An exception might be thrown anywhere in init or run if e.g. the PowerSupply overheats. Maybe an asynchronous event might happen, too (user interrupt with ^C but I might live without that if it is impossible to handle) My questions are: 1) under normal conditions (no exceptions) is there a guarantee, that __del__ of all instruments is called at the end of measurement()? 2) if an exception is thrown, will all instruments be deleted if the error occurs in run() ? (only the instruments already initialized if the error occurs in setup() )? I am using CPython (on WinXP) and there are no reference cycles between the instruments. I have to stress again that a reliable finalization is important and cannot wait until the interpreter shuts down. I have tried this and it seems to work but this is of course no guarantee. Many thanks From paolo_veronelli at libero.it Thu Aug 11 16:23:13 2005 From: paolo_veronelli at libero.it (Paolino) Date: Thu, 11 Aug 2005 22:23:13 +0200 Subject: help in algorithm In-Reply-To: <42fb9533.1191793828@news.oz.net> References: <mailman.2937.1123682219.10512.python-list@python.org> <42fb9533.1191793828@news.oz.net> Message-ID: <42FBB3B1.3050602@libero.it> Bengt Richter wrote: > On Wed, 10 Aug 2005 16:51:55 +0200, Paolino <paolo_veronelli at tiscali.it> wrote: > > >>I have a self organizing net which aim is clustering words. >>Let's think the clustering is about their 2-grams set. >>Words then are instances of this class. >> >>class clusterable(str): >> def __abs__(self):# the set of q-grams (to be calculated only once) >> return set([(self+self[0])[n:n+2] for n in range(len(self))]) >> def __sub__(self,other): # the q-grams distance between 2 words >> set1=abs(self) >> set2=abs(other) >> return len(set1|set2)-len(set1&set2) >> >>I'm looking for the medium of a set of words, as the word which >>minimizes the sum of the distances from those words. >> >>Aka:sum([medium-word for word in words]) >> >> >>Thanks for ideas, Paolino >> > > Just wondering if this is a desired result: > > >>> clusterable('banana')-clusterable('bananana') > 0 Yes, the clustering is the main filter,it's good (I hope) to cut the space of words down one or two magnitudes. Final choices must be done with the expensive Levenstain distance, or other edit-type distance. Now I'm using an empirical solution where I suppose the best set has lenght L equal the medium of the lenghts.Then I choose from the frequency distribution of 2-grams the first L 2-grams. I have no clue this is the right set and I'm sure that set is not a word as there is no chance to chain those 2-grams to form a word. Thanks for comments Paolino From grante at visi.com Thu Aug 18 10:27:41 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 18 Aug 2005 14:27:41 -0000 Subject: Tkinter and gnuplot module References: <mailman.3198.1124343464.10512.python-list@python.org> Message-ID: <11g96mtm2t3l5f5@corp.supernews.com> On 2005-08-18, Titi Anggono <tiang_ono at yahoo.com> wrote: > 1. Can we use Tkinter for web application such as Java? No. You can't use Tkinter in a Java app, since Tkinter is a Python module (unless it works with Jython). > 2. I use gnuplot.py module for interfacing with gnuplot in > linux. Can we make the plot result shown in web ? I tried > using cgi, and it didn't work. Sure. Just plot to a .png file and serve up the .png file. -- Grant Edwards grante Yow! Now KEN is having at a MENTAL CRISIS beacuse visi.com his "R.V." PAYMENTS are OVER-DUE!! From Peter.Vandersteegen at gmail.com Wed Aug 3 04:29:45 2005 From: Peter.Vandersteegen at gmail.com (peter) Date: 3 Aug 2005 01:29:45 -0700 Subject: distutils package_dir newbie In-Reply-To: <mailman.2660.1123056916.10512.python-list@python.org> References: <1123055950.708133.66580@g49g2000cwa.googlegroups.com> <mailman.2660.1123056916.10512.python-list@python.org> Message-ID: <1123057785.888610.204630@g44g2000cwa.googlegroups.com> thx for answering is such short notice. I recieve the following error when I use your setup: error: package directory 'project_user' does not exist (the complete error is added at the end of this document) I'm using python 2.3.5 (build by activeState) based on python 2.3.5 Do you have an idea what could have happened here? kind regards Peter ps. complete error running sdist warning: sdist: missing required meta-data: url warning: sdist: missing meta-data: either (author and author_email) or (maintain er and maintainer_email) must be supplied warning: sdist: manifest template 'MANIFEST.in' does not exist (using default fi le list) warning: sdist: standard file not found: should have one of README, README.txt error: package directory 'project_user' does not exist From sonicsmooth at gmail.com Sat Aug 27 20:00:07 2005 From: sonicsmooth at gmail.com (sonicSpammersGoToHellSmooth) Date: 27 Aug 2005 17:00:07 -0700 Subject: Newbie question: Sub-interpreters for CAD program References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> <h270h15kegod8uep9t0s6a43iklt6f5vlk@4ax.com> Message-ID: <1125187206.961711.91120@o13g2000cwo.googlegroups.com> Cool, I went to the UofA for my MS in ECE, 2000. I did my theses under Chuck Higgins. -- http://neuromorph.ece.arizona.edu/pubs/ma_schwager_msthesis.pdf The tools we had were constantly underwhelming me, so I've been thinking for years that a properly designed new toolset for students should be marketable, etc. I'll take a look at your site (although I think I may have come across it before.) Michael :) From skilpat at gmail.com Thu Aug 4 16:40:10 2005 From: skilpat at gmail.com (Scott Kilpatrick) Date: 4 Aug 2005 13:40:10 -0700 Subject: SciPy and NetCDF References: <1122391443.306350.297100@g14g2000cwa.googlegroups.com> <mailman.2237.1122401452.10512.python-list@python.org> <1122499062.943121.65200@z14g2000cwz.googlegroups.com> <dc8v9s$3eu$1@news.doit.wisc.edu> Message-ID: <1123188009.988338.237220@g14g2000cwa.googlegroups.com> Thanks for your help guys! That cleared some stuff up for me. Now I just have to wait for the sysadmin to get back from his vacation, bah. Scott From felix at keyremovethisghost.com Tue Aug 2 21:15:20 2005 From: felix at keyremovethisghost.com (Felix Collins) Date: Wed, 03 Aug 2005 13:15:20 +1200 Subject: HELP:sorting list of outline numbers Message-ID: <JUUHe.5349$PL5.486067@news.xtra.co.nz> Hi All, does anyone know any cleaver tricks to sort a list of outline numbers. An outline number is a number of the form... 1.2.3 they should be sorted in the following way... 1 1.1 1.2 1.12 python's alpha sort (by design) sorts them... 1 1.1 1.12 1.2 That's no good for me. I'm planning on splitting the strings into multiple lists of ints and doing numerical sorts. Thanks for any clever ideas that might make it easier. Felix From zen19725 at zen.co.uk Wed Aug 3 08:29:54 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 13:29:54 +0100 Subject: Art of Unit Testing References: <dco7sg$dj0$1@news.urz.uni-heidelberg.de> <87mzo0s25q.fsf@lucien.dreaming> Message-ID: <slrndf1e62.129.zen19725@cabalamat.somewhere> On Tue, 02 Aug 2005 19:02:09 +0200, Bj?rn Lindstr?m <bkhl at stp.lingfil.uu.se> wrote: >Christoph Zwerschke <zwerschke at zuv.uni-heidelberg.de> writes: > >> Would it make sense to add "globaleSetup" and "globalTearDown" methods >> to the TestCase class? I think at least it would not harm >> anybody. Where should such proposals be submitted? > >In general that's not such a good idea. If you build your tests like >that, it gets hard to know which test really went wrong, No it isn't, provided you've coded your setup code and tests well. And if you haven't coded your setup code and tests well, you're fucked anyway. Programming languages and libraries should assume the programmers is competent and knows what he's doing. People who disagree should stick to Java or Pascal or something. > and you might >get the situation where the whole set of tests works, but depend on each >other in some way. (This can also happen for more obscure reasons, and >is worth looking out for whichever way you do it.) Sure. And if the programmer is competent, he'll bear that in mind when he's writing the tests. >So, rebuilding the environment for the each before every single test is >generally worth the overhead. Note "generally". Sometimes it isn't. -- Email: zen19725 at zen dot co dot uk From levub137 at wi.rr.com Mon Aug 29 07:19:58 2005 From: levub137 at wi.rr.com (Raymond L. Buvel) Date: Mon, 29 Aug 2005 11:19:58 GMT Subject: Lossless Number Conversion In-Reply-To: <K7qQe.1363$wE1.143@trndny01> References: <K7qQe.1363$wE1.143@trndny01> Message-ID: <ybCQe.36541$32.19527@tornado.rdc-kc.rr.com> Chris Spencer wrote: > Is there any library for Python that implements a kind of universal > number object. Something that, if you divide two integers, generates a > ratio instead of a float, or if you take the square root of a negative, > generates a complex number instead of raising an exception? Lisp has > something like this, and it makes number crunching much more convenient. > > Chris If you are on any Unix-like platform, you might want to check out clnum. It works like the gmpy package but has complex versions of rationals and arbitrary precision floats. http://calcrpnpy.sourceforge.net/clnum.html From __peter__ at web.de Fri Aug 12 03:06:32 2005 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Aug 2005 09:06:32 +0200 Subject: Where can be a problem? References: <1123827773.392501.155760@z14g2000cwz.googlegroups.com> Message-ID: <ddhhnt$pth$04$1@news.t-online.com> Lad wrote: > I use the following > ############### > import re > Results=[] > data1='<a href="detailaspxmember=15015&mode=advert" </a><a > href="detailaspxmember=15016&mode=advert" </a><a > href="detailaspxmember=15017&mode=advert" </a>' > ID = re.compile(r'^.*=(\d+)&.*$',re.MULTILINE) > Results=re.findall(ID,data1) > print Results > ############# > to extract from data1 all numbers such as 15015,15016,15017 > > But the program extracts only the last number 15017. > Why? > Thank you for help > La. After changing data = '... ' to data = '''... ''' I get all three numbers. There is probably another significant difference between the posted code and the code you are actually running. Peter From ptmcg at austin.rr.com Wed Aug 10 15:55:37 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 10 Aug 2005 12:55:37 -0700 Subject: Help with Regular Expressions References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> <1123680438.327709.171480@z14g2000cwz.googlegroups.com> <e%rKe.227$rp.68@bignews1.bellsouth.net> Message-ID: <1123703737.569036.74100@g47g2000cwa.googlegroups.com> The pyparsing distribution includes epydoc-generated class documentation, and a few example programs. Dave Kuhlman has a nice HOWTO at http://www.rexx.com/~dkuhlman/python_201/python_201.html#SECTION007600000000000000000 Drop me a note if you are looking for some specific tips or techniques. (I'm working on an article on using pyparsing as an adventure game command processor.) -- Paul From sjmachin at lexicon.net Mon Aug 8 00:08:37 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 08 Aug 2005 14:08:37 +1000 Subject: Splitting a string into groups of three characters In-Reply-To: <1123470331.579657.28080@g47g2000cwa.googlegroups.com> References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> <1123470331.579657.28080@g47g2000cwa.googlegroups.com> Message-ID: <42f6dac2@news.eftel.com> gene tani wrote: > Um, you shd 1st search cookbook, or Vaults Parnassu, dmoz python > section, pypackage: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347689 which includes e.g. def each_slice_lol(listin,n): """non-overlapp'g slices, return (list of lists) """ len_listin=len(listin) return [listin[i:min(len_listin, i+n)] for i in range(0,len_listin,n)] and the listin[i:min(len_listin, i+n)] is grossly wasteful; it does EXACTLY the same as listin[i:i+n] for the values of i and n that make sense. From the Python reference manual: """The semantics for a simple slicing are as follows. The primary must evaluate to a sequence object. The lower and upper bound expressions, if present, must evaluate to plain integers; defaults are zero and the sys.maxint, respectively. If either bound is negative, the sequence's length is added to it. The slicing now selects all items with index k such that i <= k < j where i and j are the specified lower and upper bounds. This may be an empty sequence. It is not an error if i or j lie outside the range of valid indexes (such items don't exist so they aren't selected). """ From jgrahn-nntq at algonet.se Sat Aug 20 06:43:24 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 20 Aug 2005 10:43:24 GMT Subject: Some questions References: <mailman.3203.1124350334.10512.python-list@python.org> <E0YMe.20135$F23.246376@twister2.libero.it> Message-ID: <slrndgdtsk.r2g.jgrahn-nntq@frailea.sa.invalid> On Thu, 18 Aug 2005 08:53:56 GMT, Alessandro Bottoni <alessandro.bottoni at infinito.it> wrote: > Titi Anggono wrote: ... >> 2. I use gnuplot.py module for interfacing with >> gnuplot in linux. Can we make the plot result shown in >> web ? I tried using cgi, and it didn't work. > > The ability to display a image (in this case a GNUPlot plot) on a web page > depends on the browser. Normally, you have to install a specific plug-in > for displaying not-standard types of images on a web page, like it happens > with Macromedia Flash. > > I do not know if exists any GNUPlot plug-in for the most common web > browsers. Maybe you can save your plot in a format that is compatible with > the existing viewers, like GIF, TIFF or JPEG. Have a look at GNUPlot > documentation for this. There is AFAIK no specific gnuplot image format, so saving to some other format would have to be involved anyway. My version of Gnuplot includes support for PNG, jpeg, encapsulated PostScript and SVG among other things[1]. PNG is probably the best overall choice. For bonus points, one could generate the format the browser says it prefers ... /Jorgen [1] "set terminal" at the gnuplot prompt lists them. -- // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu \X/ algonet.se> R'lyeh wgah'nagl fhtagn! From mathmom at gmail.com Sat Aug 13 01:27:15 2005 From: mathmom at gmail.com (Sheila King) Date: 12 Aug 2005 22:27:15 -0700 Subject: socket setdefaulttimeout In-Reply-To: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> Message-ID: <1123910835.163089.60080@g14g2000cwa.googlegroups.com> I do note that the setdefaulttimeout is accomplishing something in my full program. I am testing some error handling in the code at the moment, and am raising an exception to make the code go into the "except" blocks... The part that sends an error email notice bombed due to socket timeout. (well, until I raised the timeout to 3 seconds...) The last time I asked about this topic in the newsgroups...was a while back (like 2 or so years) and someone said that because the socket function that I'm trying to use is coded in C, rather than Python, that I could not use the timeoutsocket module (which was the only way prior to Python 2.3 to set timeouts on sockets). I wonder...is it possible this applies to the particular timeouts I'm trying to enforce on the "gethostbyname" DNS lookups? Insights appreciated.... From imailsrv at adgcq.com Tue Aug 9 12:13:45 2005 From: imailsrv at adgcq.com (List Server) Date: Tue, 9 Aug 2005 12:13:45 -0400 Subject: Illegal IMail List Server Command! Message-ID: <20050809121345656.AA8D7AF2B8@adgcq.com> IMail List Server for Windows NT, Ipswitch, Inc. -------------------------------------------------------------------- Valid Commands are: To subscribe to a list, send a mail message to "imailsrv" at this address with the following in the body of the message: subscribe listname your_full_name To unsubscribe from a list, send a mail message to "imailsrv" at this address with the following in the body of the message: unsubscribe listname To receive a list of the lists supported here: list To receive a list of users on a given list (If enabled for that particular list): list listname To receive help send: help [listname] To change to digest mode, send a mail message to "imailsrv" at this address with the following in the body of the message: set mode digest listname To change back to standard mode, send a mail message to "imailsrv" at this address with the following in the body of the message: set mode standard listname From rzzzwilson at hotmail.com Wed Aug 24 05:01:50 2005 From: rzzzwilson at hotmail.com (Ross Wilson) Date: Wed, 24 Aug 2005 19:01:50 +1000 Subject: list insertion References: <mailman.3444.1124855904.10512.python-list@python.org> Message-ID: <pan.2005.08.24.09.01.50.806374@hotmail.com> On Tue, 23 Aug 2005 20:58:11 -0700, Randy Bush wrote: > i am trying to insert into a singly linked list > > hold = self.next > self.next = DaClass(value) > self.next.next = hold > > but i suspect (from print statement insertions) that the result > is not as i expect. as the concept and code should be very > common, as i am too old for pride, i thought i would ask. > > mahalo, > randy The example above looks like it would work, as long as other stuff you _don't_ show is fine. Specifically, how do you handle the case when the list is empty? Better to show a more complete example with output and how that is not what you expect. Ross From jsgaarde at gmail.com Wed Aug 17 16:22:41 2005 From: jsgaarde at gmail.com (Jakob Simon-Gaarde) Date: 17 Aug 2005 13:22:41 -0700 Subject: win32pipe.popen3 In-Reply-To: <1124301101.559487.283280@o13g2000cwo.googlegroups.com> References: <1124301101.559487.283280@o13g2000cwo.googlegroups.com> Message-ID: <1124310161.204396.50720@g49g2000cwa.googlegroups.com> Me again. I forgot to mention that readline() in popen2,3 and 4 even locks up the parent-proces though it is called from a thread, so it's a real deadlock. From polytechnique at gmail.com Wed Aug 31 10:54:37 2005 From: polytechnique at gmail.com (DENG) Date: 31 Aug 2005 07:54:37 -0700 Subject: HTML tags optimization [ interesting problem] Message-ID: <1125500077.461196.321910@g43g2000cwa.googlegroups.com> hi all, i use SGMLParser to process HTML files, in order to do some optimizations, something like this: <i><b>TEXT1</b></i><b><i><u>TEXT2</u></i></b> optimise to <i><b>TEXT1<u>TEXT2</u></b><i> at the very beginning, i was thinking of analysing each text-block, to know their color, size, if is bold or italic, but i found it was too complicated. e.g <font color=red><font size=6>TEXT1</font></font> optimise to <font color=red size=6>TEXT1</font> but if there is TEXT2 exist <font color=red><font size=6>TEXT1</font>TEXT2</font> we can not do any optimization. my problem is I can not find a method to treat all those situation, I had too much thinking and get fool now anyone can give me some advices? thanks PS: other examples: 1 <font size=5><font size=7>TEXT</font></font> => <font size=7>TEXT</font> 2 <i>TEXT </i><i>TEXT</i> => <i>TEXT TEXT</i> 3 <i>TEXT<i>TEXT</i></i> => <i>TEXT</i> etc... From nicolas.riesch at genevoise.ch Tue Aug 23 11:19:06 2005 From: nicolas.riesch at genevoise.ch (nicolas_riesch) Date: 23 Aug 2005 08:19:06 -0700 Subject: literal accented characters in python asp page with Microsoft IIS In-Reply-To: <3n0oukF193t10U1@individual.net> References: <1124778963.267120.167110@o13g2000cwo.googlegroups.com> <3n0oukF193t10U1@individual.net> Message-ID: <1124810346.337879.233520@g49g2000cwa.googlegroups.com> I've tried it, but I still get this message from IIS : HTTP/1.1 500 Server Error From reinhold-birkenfeld-nospam at wolke7.net Tue Aug 2 03:36:50 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Tue, 02 Aug 2005 09:36:50 +0200 Subject: Is this Pythonic? In-Reply-To: <mailman.2583.1122937274.10512.python-list@python.org> References: <mailman.2583.1122937274.10512.python-list@python.org> Message-ID: <3l8m4jF112eobU1@individual.net> Delaney, Timothy (Tim) wrote: > Peter Hansen wrote: > >> Change those to "raise NotImplementedError('blah')" instead and you'll >> be taking the more idiomatic approach. > > One thing I've noticed, which I may raise on python-dev ... > NotImplementedError does *not* play well with super() ... > > class A (object): > def test (self): > raise NotImplementedError > > class B (object): > def test (self): > print 'B' > super(B, self).test() > > class C (B, A): > def test (self): > print 'C' > super(C, self).test() > > It's actually worse than AttributeError, because the method actually > exists. In both cases though you need to know when you create the base > class how it's going to be used to work out whether a super() call is > needed. > > One option is to do a try: except (AttributeError, NotImplementedError). > Yuk - talk about hiding errors :( Hm... one could return NotImplemented from the abstract method. It won't raise an error immediately, but will certainly be discovered at some point. Not optimal though. Reinhold From sybrenUSE at YOURthirdtower.com.imagination Mon Aug 29 06:12:07 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 29 Aug 2005 12:12:07 +0200 Subject: Python built email message doesn't support OutLook Express References: <mailman.115.1125302010.8229.python-list@python.org> Message-ID: <slrndh5nh9.u8f.sybrenUSE@schuimige.unrealtower.org> praba kar enlightened us with: > This code will build plain email message properly. It's not a plain email message. It's an html email without a plain text part. Highly annoying to many people. > But after building the message. If a email user download this mail > through out look express then this email message will display > without any alignment. Post the msg.as_string() output so we can see whay you're sending. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From tjreedy at udel.edu Sat Aug 13 23:19:55 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Aug 2005 23:19:55 -0400 Subject: Bug on Python2.3.4 [FreeBSD]? References: <ddioc3$evr$1@news2.rz.uni-karlsruhe.de><donn-BC56BC.16011812082005@gnus01.u.washington.edu><mailman.3044.1123892005.10512.python-list@python.org><1123906696.459433@yasure> <ddkdgo$gdk$1@news2.rz.uni-karlsruhe.de> <1123967048.441133.286260@z14g2000cwz.googlegroups.com> Message-ID: <ddmd8s$9v1$1@sea.gmane.org> > I am now enlightened as to the usefulness of 'r+', as it starts the > read fp at the begining of the file. Both 'r+' and 'w+' let you write anywhere, whereas 'a+' is supposed to make all writes EOF appends. 'r+' (and 'r') requires an existing file while 'w+' (like 'w') will open a new file or truncate an existing file. Terry J. Reedy From me at privacy.net Sat Aug 6 21:38:51 2005 From: me at privacy.net (Dan Sommers) Date: Sat, 06 Aug 2005 21:38:51 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <87wtn245qo.fsf@wilson.rwth-aachen.de> <86slxpyxp2.fsf@bhuda.mired.org> <873bporhgm.fsf@wilson.rwth-aachen.de> <86mznvyge7.fsf@bhuda.mired.org> Message-ID: <m2u0i2cyqc.fsf@unique.fully.qualified.domain.name.yeah.right> On Fri, 05 Aug 2005 21:59:28 -0400, Mike Meyer <mwm at mired.org> wrote: > Is there a free language you consider successful? I can't think of any > that are a lot more (i.e. - an order of magnitude) successful than > Python that aren't derived from C. How about Postscript? (I believe that Postscript was developed as a proprietary language, but it has since become sufficiently Free that there is a Free interpreter that renders Postscript code, and a lot of Free programs generate Postscript code as output.) Stretching (but not too far) "language," how about HTML? Except for toasters, almost every computing device sold these days contains an HTML interpreter, and a great deal of embedded systems create HTML and use HTTP as an administrative interface. Regards, Dan -- Dan Sommers <http://www.tombstonezero.net/dan/> From spe.stani.be at gmail.com Wed Aug 17 12:47:58 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 17 Aug 2005 09:47:58 -0700 Subject: SPE 0.7.5.b IDE: New windows installer (with working shortcuts) Message-ID: <1124297278.902093.191890@g49g2000cwa.googlegroups.com> Thanks to Jose Galvez, there is a now a working python installer for python2.4 SPE 0.7.5.b now features a remote, encrypted and embedded python debugger of Nir Aides. Stani Spe is a free python IDE with auto indentation & completion, call tips, syntax coloring & highlighting, UML diagrams, class explorer, source index, auto todo list, sticky notes, pycrust shell, file browsers, drag&drop, context help, Blender support, ... Spe ships with Python debugger (remote & encrypted), wxGlade (gui designer), PyChecker (source code doctor) and Kiki (regex console). http://pythonide.stani.be http://pythonide.stani.be/screenshots Screenshot of windows shortcuts: http://pythonide.stani.be/screenshots/spe-win-start.png From axel at white-eagle.invalid.uk Fri Aug 26 08:33:46 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Fri, 26 Aug 2005 12:33:46 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <m3ll2qx73f.fsf@invalid.address> <l7oPe.1736$yo7.860@newssvr23.news.prodigy.net> <dem3hh$o9h$1@news1.xnet.hr> <QJxPe.8924$A%1.6685@newssvr13.news.prodigy.com> Message-ID: <K_DPe.36616$Il.17522@fe2.news.blueyonder.co.uk> In comp.lang.perl.misc Mike Schilling <mscottschilling at hotmail.com> wrote: > "Denis Kasak" <denis.kasak at gmail.com> wrote in message > news:dem3hh$o9h$1 at news1.xnet.hr... >> Mike Schilling wrote: >>> I see a difference between "X would be useful for A, B, and C" and "Y >>> will always be the only proper way." >>> Don't you? >> Y would not be useful because of the bandwidth it consumes, the malware it >> would introduce, the additional time spent focusing on the format rather >> than quality of the content and, frankly, because it's useless. > Threaded mail-readers too, screen-based editors , spell-checkers, all > useless frills. All dependent on and only affecting the user who employs them. It does not require other users to do anything. It is none of my business whether you used vi, emacs, ed or whatever to compose your message; whether you ran a spell checker over it; or how you read messages and respond to them - perhaps you telnet'd to the news server and made your transactions manually. Axel From usenet.filter at gmail.com Sun Aug 7 22:23:19 2005 From: usenet.filter at gmail.com (Stephan) Date: 7 Aug 2005 19:23:19 -0700 Subject: Python's CSV reader References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> <ZsrQVVzYvg8CFwy6@at-andros.demon.co.uk> <1123169310.391973.217860@o13g2000cwo.googlegroups.com> <VZvDYU+Kz28CFwQl@at-andros.demon.co.uk> Message-ID: <1123467799.077938.60540@z14g2000cwz.googlegroups.com> Andrew McLean wrote: > You are welcome. One point. I think there have been at least two > different interpretations of precisely what you task is. > > I had assumed that all the different "header" lines contained data for > the same fields in the same order, and similarly that all the "detail" > lines contained data for the same fields in the same order. Indeed, you are correct. Peter's version is interesting in its own right, but not precisely what I had in mind. However, from his example I saw what I was missing: I didn't realize that you could reassign the DictReader field names on the fly. Here is a rudimentary example of my working code and the data it can parse. ------------------------------------- John|Smith Beef|Potatos|Dinner Roll|Ice Cream Susan|Jones Chicken|Peas|Biscuits|Cake Roger|Miller Pork|Salad|Muffin|Cookies ------------------------------------- import csv HeaderFields = ["First Name", "Last Name"] DetailFields = ["Entree", "Side Dish", "Starch", "Desert"] reader = csv.DictReader(open("testdata.txt"), [], delimiter="|") while True: try: # Read next "header" line (if there isn't one then exit the loop) reader.fieldnames = HeaderFields header = reader.next() # Read the next "detail" line reader.fieldnames = DetailFields detail = reader.next() # Print the parsed data print '-' * 40 print "Header (%d fields): %s" % (len(header), header) print "Detail (%d fields): %s" % (len(detail), detail) except StopIteration: break Regards, -Stephan From zen19725 at zen.co.uk Wed Aug 3 08:26:44 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 13:26:44 +0100 Subject: Art of Unit Testing References: <dco7sg$dj0$1@news.urz.uni-heidelberg.de> <1123001938.602349.164510@z14g2000cwz.googlegroups.com> <dcoghi$j7d$1@online.de> <dcokrm$qcf$1@online.de> <dcps38$4nj$1@online.de> Message-ID: <slrndf1e04.129.zen19725@cabalamat.somewhere> On Wed, 03 Aug 2005 09:35:08 +0200, Christoph Zwerschke <cito at online.de> wrote: > >> Some (many?) people don't like the unittest module, because it is not very >> pythonic - nothing to wonder as it has its root in the Java world. That's >> probably one of the reasons why there are other (more pythonic) unittesting >> frameworks for Python out there. > >So I think it would have been better that "unittest" had been named >"PUnit" to make clear that it is a JUnit port and to allow a more >pythonic testing framework to be added to the Python's standard lib. Not a bad idea. -- Email: zen19725 at zen dot co dot uk From jeffrey.schwab at rcn.com Mon Aug 29 16:19:55 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Mon, 29 Aug 2005 16:19:55 -0400 Subject: NooB Question In-Reply-To: <pan.2005.08.28.15.51.02.149211@sbcglobal.net> References: <pan.2005.08.28.15.51.02.149211@sbcglobal.net> Message-ID: <zPqdnRyin6F28I7eRVn-jw@rcn.net> APCass wrote: > How do you execute a .py in Linux with KDE? If I double click on my > program it opens Kwrite, for editing. Try inserting this as the first line of the file: #!/usr/bin/env python From sjmachin at lexicon.net Thu Aug 11 08:34:32 2005 From: sjmachin at lexicon.net (John Machin) Date: Thu, 11 Aug 2005 22:34:32 +1000 Subject: Regular expression to match a # In-Reply-To: <Xns96AF85EE68544duncanbooth@127.0.0.1> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <mailman.2973.1123759573.10512.python-list@python.org> <Xns96AF85EE68544duncanbooth@127.0.0.1> Message-ID: <42fb45d7$1@news.eftel.com> Duncan Booth wrote: > Dan wrote: > > >>>My (probably to naive) approach is: p = re.compile(r'\b#include\b) >> >>I think your problem is the \b at the beginning. \b matches a word break >>(defined as \w\W or \W\w). There would only be a word break before the # >>if the preceding character were a \w (that is, [A-Za-z0-9_], and maybe >>some other characters depending on your locale). >> >>However, the \b after the "include" is exactly what you want. >> > > > So the OP probably wanted '\B' the exact opposite of '\b' for the start of > the string, i.e. only match the # if it is NOT preceded by a wordbreak. > > Alternatively for C style #includes search for r'^\s*#\s*include\b'. Search for r'^something' can never be better/faster than match for r'something', and with a dopey implementation of search [which Python's re is NOT] it could be much worse. So please don't tell newbies to search for r'^something'. From ray_usenet at yahoo.com Fri Aug 12 10:09:13 2005 From: ray_usenet at yahoo.com (Ray) Date: 12 Aug 2005 07:09:13 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: <42fc6756$0$12705$626a14ce@news.free.fr> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <QGUKe.193376$5V4.71993@pd7tw3no> <1123817487.901244.272700@z14g2000cwz.googlegroups.com> <42fc6756$0$12705$626a14ce@news.free.fr> Message-ID: <1123855753.638565.194810@g49g2000cwa.googlegroups.com> bruno modulix wrote: <snipped> > And BTW, don't bother making all your attributes "protected" or > "private" then writing getters and setters, Python has a good support > for computed attributes, so you can change the implementation without > problem (which is the original reason for not-public attributes): Thanks Bruno! This is good stuff. This is exactly what I want to avoid: writing Java in Python. Cheers, Ray > > # first version: > class Foo(object): > def __init__(self): > self.baaz = 42 # public attribute > > # later we discover that we want Foo.baaz to be computed: > class Foo(object): > def __init__(self): > self.baaz = 42 > > def _set_baaz(self, value): > if value < 21 or value > 84: > raise ValueError, "baaz value must be in range 21..84" > self._baaz = value > > def _get_baaz(self): > return self._baaz * 2 > > baaz = property(fget=_get_baaz, fset=_set_baaz) > > Easy as pie, uh ?-) > > > -- > bruno desthuilliers > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > p in 'onurb at xiludom.gro'.split('@')])" From bokr at oz.net Thu Aug 11 15:58:41 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 11 Aug 2005 19:58:41 GMT Subject: Pre-PEP Proposal: Codetags References: <mailman.2965.1123740201.10512.python-list@python.org> <42FAF489.3010306@v.loewis.de> Message-ID: <42fb9f3b.1194361460@news.oz.net> On Thu, 11 Aug 2005 08:47:37 +0200, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <martin at v.loewis.de> wrote: >Micah Elliott wrote: >> I also have this living as a wiki <http://tracos.org/codetag/wiki/Pep> >> if people would like to add comments there. I might try to capture there >> feedback from this group anyway. First try at a PEP -- thanks for any >> feedback! > >I think you somewhat misunderstood the purpose of the PEP process. >This is meant primarily for enhancements to Python (the language >and its library), and it is meant to save the PEP author from >implementing unagreeable functionality - if the PEP is accepted, >the PEP author is typically expected to implement the proposed >functionality (in many cases, having a draft implementation is >prerequisite to accepting it). > >Both elements seem to be missing your document: it does not propose >changes to the Python language; instead, it proposes a specific >way of writing comments (ie. something that is not relevant to the >Python interpreter or libraries, only to the Python developer). Erm, (cough) PEP 263 specifies comment syntax ;-) But I agree that the OP's proposal is not a core language matter. Perhaps this is another PEEP candidate (i.e., a "Python Evironment Enhancement Proposal" to put in a "PEEP" application/tools/environment-oriented clone of the PEP process). Maybe a PEEP top page in the wiki with links to specific PEEPs could be a way to try it out. Regards, Bengt Richter From cam.ac.uk at mh391.invalid Tue Aug 2 19:49:28 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Wed, 03 Aug 2005 00:49:28 +0100 Subject: startfile problems In-Reply-To: <mailman.2644.1123022144.10512.python-list@python.org> References: <mailman.2597.1122959433.10512.python-list@python.org> <tf7ue191ida664u5o1ubg82pbuk3ggomhh@4ax.com> <mailman.2604.1122968139.10512.python-list@python.org> <ed6ve1t6jp4lapvij0thh4ia64qu4ee2s7@4ax.com> <mailman.2644.1123022144.10512.python-list@python.org> Message-ID: <dcp0qd$2cd$1@gemini.csx.cam.ac.uk> Timothy Smith wrote: > yep the program is executed in the same dir as the pdf file. like i said > it actually opens it, but throws up an exception as well. You are far more likely to get informed help if you post the traceback here, as has been suggested twice already. -- Michael Hoffman From Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org Thu Aug 25 14:48:44 2005 From: Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org (Alexander) Date: Thu, 25 Aug 2005 22:48:44 +0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <MSGID_2=3A5025=2F3.131_430e4b2f@fidonet.org> ?????? Xah! 11 aug 2005 at 18:23, Xah Lee wrote: XL> Jargons of Info Tech industry XL> (A Love of Jargons) XL> Xah Lee, 2002 Feb XL> People in the computing field like to spur the use of spurious ...skipped... Look at this site for some info: http://lleo.aha.ru/na/en Alexander, zatv at bk.ru From fredrik at pythonware.com Fri Aug 26 11:30:55 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 26 Aug 2005 17:30:55 +0200 Subject: Integrate C source in a Python project References: <GFEPe.17832$zs.4815@tornado.fastwebnet.it><1125063243.748286.117800@g47g2000cwa.googlegroups.com> <L3FPe.17886$zs.14081@tornado.fastwebnet.it> Message-ID: <dencjf$k12$1@sea.gmane.org> "billiejoex" wrote_ > Than you James. I'll take a look as soon as possible. > It is possible do the contrary (integrates python source in a C project)? http://docs.python.org/ext/embedding.html </F> From nothingcanfulfill at gmail.com Sun Aug 21 04:46:58 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 21 Aug 2005 01:46:58 -0700 Subject: Traceback Questions In-Reply-To: <mailman.3287.1124470278.10512.python-list@python.org> References: <1124408964.797947.214270@f14g2000cwb.googlegroups.com> <mailman.3287.1124470278.10512.python-list@python.org> Message-ID: <1124614018.272165.275550@f14g2000cwb.googlegroups.com> Thanks man, I'll definately take a look into this and hopefully port it over and publish it. Have a GREAT day -Wes From renting at astron.nl Tue Aug 2 04:26:41 2005 From: renting at astron.nl (Adriaan Renting) Date: Tue, 02 Aug 2005 10:26:41 +0200 Subject: Python IDE's Message-ID: <s2ef4a8a.018@server7.nfra.nl> vi/vim is a godssend if you need a working system that needs to fit in 4 Mb or ROM, but it's an editor not an IDE. You can debate about how good an editor it is, but that's just differences in taste I suppose. When talking about IDE's I mean a lot more as 'just' an editor, below is my 'wishlist', I would be very interested what solutions you use, how much time it took you to set up this solution, and which parts of my 'wishlist' it implements. Also suggestions to add to my 'wishlist' are welcome: - Integrated help. when I press <help button> I should get a help page that's appropriate for the piece of code my cursor currently sits on. - Code completion. If I type 'os.path.', the editor should be a ble to show me a list of all methods and attributes the module has. If I then continue with 'os.path.isfile(', it should show me the parameters for the function. - Integrated GUI design. The IDE should have a graphical tool for designing GUIs, and the editor should be aware of it and propagate changes in an inobtrusive way. - Integrated debugger. I should be able to run my module/program from the editor, execute up to the current cursor position, preset breakpoints (maybe with conditions). The editor should highlight the current line being executed, and give you the choice to: step to the next line, step into the execution of the current line, step out to the function that called the current code, run to the next brekpoint, etc. When the code is running I should be able to inspect the values of all variables currently assigned and change them on the fly. - Code aware editor. Syntax highlighting, syntax checking, automatic indentation, loop folding. Functionality like refatoring, "create function from selected code", inlining current selected function, template macros, coding mistake warnings (for "if (somevar); {do something;}" in C/C++ kind of mistakes). - Integration with version control system. - Code documentation/inspection tools. Ability to generate include and inheritance trees, LOC counters, profiling what lines of you code get executed most/never, helpfile generation from code, etc. - Project management. Tools for communication with coworkers, bugtracking, which targets need which files, automatic install scripts/tools, etc. - Accessible user interface. All functionality should be accessible through some menu structure, so I don't need to depend on my memory. Prefereable reprogrammable/assignable shortcut keys for all functionality, maybe even some form of macros, plugins, etc. - For C/C++: memory leak detection Why I want this? Because I want to spend my time programming my code, not my developement environment. I currently use Eric3+QtDesigner for Python, and while not perfect, I realy like it. I have used Borland C++Builder for C/C++ in the past for Windows, but I haven't found a satisfactory C/C++ solution for my current Linux system yet. -------------------------------------------------------------------------- Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ >>> <en.karpachov at ospaz.ru> 08/02/05 4:42 AM >>> On Mon, 01 Aug 2005 18:21:08 -0400 Benji York wrote: > Jon Hewer wrote: > > But, if i use Vi, then whenever i want to test some code i have to > > open up python, import the necessary modules and run it - I like the > > idea of developing python in an IDE and just hitting a run button. > > map <F5> :w<CR>:!python %<CR> Or, probably even better: map <F5> :w<CR>:!xterm -e python -i % &<CR><CR> -- jk -- http://mail.python.org/mailman/listinfo/python-list From mwm at mired.org Tue Aug 2 20:48:51 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 20:48:51 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <mailman.2456.1122818669.10512.python-list@python.org> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <mailman.2458.1122823396.10512.python-list@python.org> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <mailman.2482.1122850652.10512.python-list@python.org> <86zms0ex85.fsf@bhuda.mired.org> <mailman.2599.1122960634.10512.python-list@python.org> Message-ID: <86acjzetfw.fsf@bhuda.mired.org> Paul McNett <p at ulmcnett.com> writes: >>>project I've found, but still doable. >> Well, I've got a long history of installing things from source - >> going >> back to v6. On OS X, I like the darwin ports stuff, so I tried that: >> % sudo port install wxpython >> It blew up trying to compile wxpython. The multitude of dependencies >> all seemed to build find. Building wxpython from the source >> distribution by hand doesn't seem to fair any better. > > To build wxPython from source, you really need to follow Robin's > detailed instructions in BUILD.txt, located somewhere in the source > tree (I have to look for it every time, but I think it is in > wxSrc/wxPython/docs/BUILD.txt). It isn't difficult but there's more to > it than the standard ./configure;make;make install. I found BUILD.txt. I followed it to the letter. It still blew up. There may be a problem with Tiger that hasn't been reported yet (yeah, I know - I really ought to report it...). Then again, it could be a problem with trying to install it on the darwin ports Python 2.4 package instead of the 2.3.5 that Tiger ships with. > I think you'll find that wxPython installs perfectly on Tiger using > the package provided. Indeed, the only really painful platform to > install wxPython on is Linux, where you pretty much need to build from > source if you want the latest and greatest. Well, it built just fine on my FreeBSD box. Then again, I've generally found installing from source on FreeBSD to be easier than installing RPM's on Linux. I'll probably copy THE over to my FreeBSD box and try it there. thanks, <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From rebound1618 at yahoo.com Tue Aug 9 22:55:39 2005 From: rebound1618 at yahoo.com (Jerry He) Date: Tue, 9 Aug 2005 19:55:39 -0700 (PDT) Subject: Is there a way of executing a command in a string? Message-ID: <20050810025540.85941.qmail@web51507.mail.yahoo.com> Hi, suppose I have the following string cmdstr = "b = lambda s: s*s" Is there a way to execute this string other than copying it onto a file and then importing it? thanks in advance, Jerry __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From wilfredthompson at gmail.com Sun Aug 7 16:59:32 2005 From: wilfredthompson at gmail.com (wilf) Date: 7 Aug 2005 13:59:32 -0700 Subject: visual studio 2005 Message-ID: <1123448372.152963.155180@g47g2000cwa.googlegroups.com> Has anyone had success compiling python with this? From guoxiaotian at gmail.com Sun Aug 14 01:10:27 2005 From: guoxiaotian at gmail.com (guoxiaotian at gmail.com) Date: 13 Aug 2005 22:10:27 -0700 Subject: py2exe: no exe produced? Message-ID: <1123996227.332130.219450@o13g2000cwo.googlegroups.com> I tried py2exe the latest version with python 2.4 on windows. the setup script looks like this: ___________________________________________ # setup.py from distutils.core import setup import py2exe setup(name="Hello", scripts=["f:\python\hello.py"],) ____________________________________________ when I run the script, the output looks like F:\Python>python setup.py py2exe running py2exe running build_scripts creating F:\Python\dist *** searching for required modules *** *** parsing results *** *** finding dlls needed *** *** create binaries *** *** byte compile python files *** skipping byte-compilation of D:\Python24\lib\UserDict.py to UserDict.pyc skipping byte-compilation of D:\Python24\lib\atexit.py to atexit.pyc skipping byte-compilation of D:\Python24\lib\copy.py to copy.pyc skipping byte-compilation of D:\Python24\lib\copy_reg.py to copy_reg.pyc skipping byte-compilation of D:\Python24\lib\linecache.py to linecache.pyc skipping byte-compilation of D:\Python24\lib\macpath.py to macpath.pyc skipping byte-compilation of D:\Python24\lib\ntpath.py to ntpath.pyc skipping byte-compilation of D:\Python24\lib\os.py to os.pyc skipping byte-compilation of D:\Python24\lib\os2emxpath.py to os2emxpath.pyc skipping byte-compilation of D:\Python24\lib\popen2.py to popen2.pyc skipping byte-compilation of D:\Python24\lib\posixpath.py to posixpath.pyc skipping byte-compilation of D:\Python24\lib\re.py to re.pyc skipping byte-compilation of D:\Python24\lib\repr.py to repr.pyc skipping byte-compilation of D:\Python24\lib\sre.py to sre.pyc skipping byte-compilation of D:\Python24\lib\sre_compile.py to sre_compile.pyc skipping byte-compilation of D:\Python24\lib\sre_constants.py to sre_constants.pyc skipping byte-compilation of D:\Python24\lib\sre_parse.py to sre_parse.pyc skipping byte-compilation of D:\Python24\lib\stat.py to stat.pyc skipping byte-compilation of D:\Python24\lib\string.py to string.pyc skipping byte-compilation of D:\Python24\lib\traceback.py to traceback.pyc skipping byte-compilation of D:\Python24\lib\types.py to types.pyc skipping byte-compilation of D:\Python24\lib\warnings.py to warnings.pyc *** copy extensions *** *** copy dlls *** copying D:\Python24\w9xpopen.exe -> F:\Python\dist when it's done only 2 files produced under dist dir: library.zip w95popen.exe any ideas? Thanks in advance! From rschroev_nospam_ml at fastmail.fm Tue Aug 30 05:58:09 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 30 Aug 2005 09:58:09 GMT Subject: OpenSource documentation problems In-Reply-To: <ZXTQe.811$la.216@newssvr22.news.prodigy.net> References: <mailman.113.1125301928.8229.python-list@python.org> <ZXTQe.811$la.216@newssvr22.news.prodigy.net> Message-ID: <R4WQe.181751$1h2.10061955@phobos.telenet-ops.be> Bryan Olson wrote: > Adriaan Renting wrote: > [...] > > > I do agree that a lot of OSS projects seem to lack somewhat in > > the documentation department, compared to a lot of commercial > > software. I would give the man page of gcc as an example, it's > > just one 6600 line blurb. > > I don't see any need to look beyond Python for a good example of > poor documentation. Are there serious Python programmers who > don't constantly struggle with errors and omissions in the doc? There certainly are some areas where the documentation could be improved, but on the whole I think it's pretty good. I guess I'm not what you call a serious Python programmer, but still so far the documentation has provided answers to practically all questions I had. > I don't mind the 6600 line blurb form, just so long as the info > is there and is correct. I agree. And on the whole I like manpages better than GNU's info system. info is good for providing background information and an overview of how everything works, but when I need a reference about command line options or config file settings, my experience is that I can find the needed information much easier in man pages. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From billiejoex at fastwebnet.it Tue Aug 16 07:58:10 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Tue, 16 Aug 2005 13:58:10 +0200 Subject: sniffer in python References: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> <0KmdncVnD80_Hp3eRVn-rw@powergate.ca> <fd0Me.7604$zs.6172@tornado.fastwebnet.it> <VqqdnWMBm5I23ZzeRVn-rA@powergate.ca> <SHiMe.8015$zs.2505@tornado.fastwebnet.it> <D7jMe.8031$zs.6009@tornado.fastwebnet.it> Message-ID: <pxkMe.8081$zs.7996@tornado.fastwebnet.it> Moreover the getInterface() function seems to be unexistent: >>> from pcapy import * >>> getInterface() Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'getInterface' is not defined Maybe it can be used only on *nix platforms? From spe.stani.be at gmail.com Tue Aug 9 18:25:21 2005 From: spe.stani.be at gmail.com (spe.stani.be at gmail.com) Date: 9 Aug 2005 15:25:21 -0700 Subject: SPE: New website & Mac Os X fund raising Message-ID: <1123626321.459465.202300@g47g2000cwa.googlegroups.com> SPE (Stani's Python Editor) is an open-source python IDE with auto indentation & completion, call tips, syntax coloring & highlighting, UML diagrams, class explorer, source index, auto todo list, sticky notes, pycrust shell, file browsers, drag&drop, context help, Blender support, ... Spe ships with Python debugger (remote & encrypted), wxGlade (gui designer), PyChecker (source code doctor) and Kiki (regex console). To support the development of SPE for Mac, some enthousiastic mac SPE users have started a fund raising campaign to buy a Mac for SPE: "What it would be worth to you to have a new release of SPE running on your Mac Os X the same day as it appears on other platforms? $50? $75? $100? My company, Dartware, has contributed 250 Euros to start the fundraising. We're willing to give a major boost because it's worth it for us to have a nice environment for Python programming." - Rich Brown (Dartware) Acquiring a Mac for SPE will allow to optimize it properly and to release it simultaneously for Mac Os X. Any donation is welcome, but of course generous donations are necessary. Due to the high Paypal commission fees, European users are explicitly requested to donate through IBAN. More info on the donation page. Until now people donated 314 Euros. 416 Euros is still required to make the purchase (mini Mac & KVM switch) go through. If some people would donate 50 euros, this target could easily get archieved. Otherwise if you have an old Mac, which runs Os X and which you are ready to give to SPE, contact me. If someone is able to convince Mac to do some sponsering, please contact me as well. The new version of SPE 0.7.5.b, which will include the debugger, will be released soon. Subscribe to the mailing list or read more on the SPE News Blog. Links and bookmarks to the SPE website should be updated to http://pythonide.stani.be! Stani (spe.stani.be at gmail.com) Homepage: http://pythonide.stani.be Screenshots: http://pythonide.stani.be/screenshots How to donate: http://pythonide.stani.be/blog/sm_donate Post which started the fund raising: http://lists.berlios.de/pipermail/python-spe-mac/2005-August/000054.html From richie at entrian.com Tue Aug 9 05:56:04 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 09 Aug 2005 10:56:04 +0100 Subject: .pth files In-Reply-To: <pan.2005.08.09.09.29.05.221751@logilab.fr> References: <pan.2005.08.09.09.29.05.221751@logilab.fr> Message-ID: <e7vgf1poj34b8rcs0ftisd80aktpa466oi@4ax.com> [Sylvain] > I've some questions regarding pth files (which btw are undocumented in the > python reference, is this intentional ?) http://google.com/search?q=site:docs.python.org%20pth The first hit explains how .pth files work (although it's the sort of documentation that makes Xah Lee explode with fury). -- Richie Hindle richie at entrian.com From Florian.Lindner at xgm.de Thu Aug 18 05:30:39 2005 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Thu, 18 Aug 2005 11:30:39 +0200 Subject: Python for Webscripting (like PHP) Message-ID: <de1kc1$oo9$01$1@news.t-online.com> Hello, I've been using Python a lot for scripting (mainly scripts for server administration / DB access). All these scripts were shell based. Now I'm considering using Python (with mod_python on Apache 2) for a web project, just how I've used PHP in some smaller Projects before (<?php print "foo" ?>).. How suitable is Python for these kind of projects? What do think? Does the stdlib offers all basic functions for this kind of requirements? Thanks, Florian From sjmachin at lexicon.net Sun Aug 7 22:18:42 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 08 Aug 2005 12:18:42 +1000 Subject: Splitting a string into groups of three characters In-Reply-To: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: <42f6c0fe$1@news.eftel.com> lemon97 at gmail.com wrote: > Hi, > > Is there a function that split a string into groups, containing an "x" > amount of characters? > > Ex. > TheFunction("Hello World",3) > > Returns: > > ['Hell','o W','orl','d'] > > > Any reply would be truly appreciated. > > Thank You, > Maybe, somewhere out there -- you could write one yourself, like this: # untested def nsplit(s, n): return [s[k:k+n] for k in xrange(0, len(s), n)] From hancock at anansispaceworks.com Wed Aug 31 10:13:30 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 31 Aug 2005 09:13:30 -0500 Subject: What are new-style classes? In-Reply-To: <3nk08hF1snjcU1@individual.net> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> <Mi%Qe.2797$884.427117@news20.bellglobal.com> <3nk08hF1snjcU1@individual.net> Message-ID: <200508310913.30475.hancock@anansispaceworks.com> On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote: > The customary way is to use "class new_class(object):". There's no advantage in using > __metaclass__ except that you can set it globally for all classes in that module > (which can be confusing on its own). > > My comment mostly referred to "new-style classes must be declared as a subclass of > a new-style class", which is not true. Nonsense. "__metaclass__" is simply an implementation detail. We know that because it begins with "__". Therefore it is invisible, and any delusion you may have that you can see it is a complete non-issue. In Python we call that encapsulation. ;-D Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From cfgauss at u.washington.edu Fri Aug 26 06:19:15 2005 From: cfgauss at u.washington.edu (cfgauss) Date: 26 Aug 2005 03:19:15 -0700 Subject: problem with classes Message-ID: <1125051555.534857.317790@g47g2000cwa.googlegroups.com> I am having a strange problem with classes. I'm fairly sure the problem is with classes, anyway, because when I re-write the program without them, it works like I'd expect it to. When I run this program, at first, L[0].z[1] is 0, because z=[0,0]. But after I run that loop to assign different values to L[1].z[0] and L[1].z[1], somehow the value of L[0].z[1] has changed to 1. I have no idea why this is happening, can anyone help me? class Stuff: z=[0,0] L = [Stuff(),Stuff()] print "L[0].z[1]=%i" % L[0].z[1] for j in range(2): L[1].z[j] = j print "L[0].z[1]=%i" % L[0].z[1] From rafi at free.fr Thu Aug 25 18:08:09 2005 From: rafi at free.fr (rafi) Date: Fri, 26 Aug 2005 00:08:09 +0200 Subject: a dummy python question In-Reply-To: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> References: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> Message-ID: <430e4140$0$24722$636a15ce@news.free.fr> Learning Python wrote: >>>def outer(x): > > def inner(i): > print i, > if i: inner(i-1) > inner(x) > >>>outer(3) > > Here supposely, it should report error, because the function inner > cannot see itself since inner is only in local namespace of outer. There is no error. the function inner is defined recursively: It calls itself with a different value than the one it has been called with. When defining a recursive function, there are case when it calls itself and other when it does not (otherwise the recursion is infinite and the program crashes after all the memory is used). Here it does not call itself when the value given as parameter is 0 (the if fails). one can always see itself (even at definition time) > but I typed in this in python interface. It works! > it print out: > 3 2 1 0 > > If you turn this into a module file and run this > it print out > 3 2 1 0 none I suppose you wrote this down (instead of cut and paste) as the none is not capitalized. There must be something else in your module that writes the none as your code presented above should really not "as is". -- rafi "Imagination is more important than knowledge." (Albert Einstein) From http Sat Aug 20 22:53:38 2005 From: http (Paul Rubin) Date: 20 Aug 2005 19:53:38 -0700 Subject: Well, another try Re: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <mailman.3302.1124512971.10512.python-list@python.org> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> <mailman.3303.1124519218.10512.python-list@python.org> <de70bj$1ot$1@news2.kornet.net> <mailman.3313.1124564895.10512.python-list@python.org> <de8pjp$idq$1@news2.kornet.net> Message-ID: <7xhddkgfv1.fsf@ruckus.brouhaha.com> James Sungjin Kim <kimsj at mobile.snu.ac.kr> writes: > Now I realized that Command 'lambda' is a similar to Command 'inline' > in C++. In addition, Command 'iter' is something new but not much new > to c engineers, since it is related to 'for loops', e.g., Actually not related at all. Nothing like lambda or iter exist in C++. They are a bit complicated to explain to newbies (unless you've programmed in Lisp or in functional-programming languages), thus the suggestion of looking in the docs. That's also the reason that suggesting using lambda and iter that way was considered a bad answer to "how do you write something like 'while c = f.read(1)'". Anyway, quick explanation of lambda: it's a way of creating functions without having to give then names. Example: lambda x: x*x is a function that computes the square of x. So you could say n = (lambda x: x*x)(3) which sets n = 9. There is a faction on clpy which says lambda is bad and all functions should have their own names. Others say they're useful for things like callbacks, and requiring all functions to be named makes no more sense than requiring all intermediate results in infix expressions to be named. You unfortunately happened to trip into a slightly contentious topic on clpy and got flamed a bit as a result. I won't explain iter here, since it's more complex than lambda. From me at privacy.net Fri Aug 5 11:14:31 2005 From: me at privacy.net (Dan Sommers) Date: Fri, 05 Aug 2005 11:14:31 -0400 Subject: why no arg, abs methods for comlex type? References: <dcvqc2$8oi$1@news2.rz.uni-karlsruhe.de> Message-ID: <m21x58a014.fsf@unique.fully.qualified.domain.name.yeah.right> On Fri, 05 Aug 2005 15:42:41 +0200, Daniel Sch?le <uval at rz.uni-karlsruhe.de> wrote: > Hello all, > I often have to deal with complex numbers > using python iteractive as calculator > I wonder why there are no methods like arg, abs > well one can use > c = 1+1j > abs(c) > In my opinion it would also be nice to have the > possibility to write it as > c.abs() > it looks more OO I guess it's for the same reason that we are spared from writing things like this: z = x.squared().added_to(y.squared()).squareroot() E = m.multiplied_by(c.squared()) More OO, yes. More readable, not IMO. > I would also like to see some more functions to make > calculations with complex number more convenient [ ... ] > maybe there exists some proposals aiming this goal? SciPy or Numeric? Regards, Dan -- Dan Sommers <http://www.tombstonezero.net/dan/> From harlinseritt at yahoo.com Wed Aug 10 07:26:59 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: 10 Aug 2005 04:26:59 -0700 Subject: Help with Regular Expressions In-Reply-To: <mailman.2923.1123671847.10512.python-list@python.org> References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> <mailman.2923.1123671847.10512.python-list@python.org> Message-ID: <1123673219.653144.265270@f14g2000cwb.googlegroups.com> Ahh that's it Frederik. That's what I was looking for. The regular expression problems I will take care of, but first wanted to walk before running. ;) Thanks, Harlin Seritt From mwm at mired.org Tue Aug 16 22:22:52 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 16 Aug 2005 22:22:52 -0400 Subject: Library vs Framework References: <ddj5qv$enq$1@lairds.us> <mailman.3120.1124179535.10512.python-list@python.org> <ddsqms$mp1$1@news.doit.wisc.edu> <200508161031.26507.hancock@anansispaceworks.com> <mailman.3138.1124209204.10512.python-list@python.org> Message-ID: <86ek8t2tfn.fsf@bhuda.mired.org> Peter Decker <pydecker at gmail.com> writes: > I've written several apps that need to update a database, and each one > had to do the same things: connect, grab data, create controls to > display/edit that data, validate any changes and then stuff the edited > data back into the database. I started playing with the Dabo framework > a few months ago, and it does all of that for me. I just set the > connection info, and then set a couple of properties on controls, and > the rest just works. > > I'm sure others who don't like using frameworks will chime in that > they've done similar things; that they've created reusable classes > that make writing such appsmuch easier than having to rewrite the same > code time and time again. In that case, I'd contend that you've simply > created your own framework as you've gone along. Well, they may have created a library class that does the job for them. Figuring out which is which seemed to be the point of this thread. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From yoav_artzi at il.vio.com Tue Aug 30 09:03:35 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Tue, 30 Aug 2005 16:03:35 +0300 Subject: close failed: [Errno 0] No error goes to stdout In-Reply-To: <mailman.146.1125347844.8229.python-list@python.org> References: <4311b9bf@news.bezeqint.net> <qaidnR0jbcixd4zeRVn-vQ@powergate.ca> <4312c4bc$1@news.bezeqint.net> <mailman.146.1125347844.8229.python-list@python.org> Message-ID: <43145839$1@news.bezeqint.net> Steve Holden wrote: > Yoav wrote: > >> I run a Java command line program. The point is, that it's not the >> program that output this error message for sure. And I don't expect >> popen3() to catch and report errors. I just want to keep my screen >> output clean, and I expect popen3() to run the program and not let >> anything slip to the screen, after all as I understood it is supposed >> to capture STDERR and STDOUT, but maybe I didn' t understand it right >> (it's quite probable). Anyway anyway I can do such a thing? >> > It would be helpful if you could verify your theory by running the > program from the command line with standard AND error output > redirection, verifying that no output at all apears on the console when > you type > > cmd > /tmp/stdout 2>/tmp/stderr > > You are correct in supposing that popen3 is supposed to trap all stdout > and stderr output. > > regards > Steve Thank you all for your help. I managed to get rid of it, and I have this theory which I want to hear your opinion about it: It seems like it happened because I didn't bother to close the files resulting from os.popen3(), and left Python to close them on it own. the STDERR file wasn't always created, and therefore when Python tried to close it, it generated an error. I thought that Python has better abilities at closing files on its own, but I guess I was wrong. So my conclusion is that whenever I open a file it MY job to close it. Again, thank you all, you have been a great help. So now I am closing it with a "try:... except: pass". Thanks, Yoav. From sboyle55 at yahoo.com Mon Aug 1 19:16:36 2005 From: sboyle55 at yahoo.com (sboyle55 at yahoo.com) Date: 1 Aug 2005 16:16:36 -0700 Subject: Using gnu readline in my own python program? Message-ID: <1122938196.818416.234960@g44g2000cwa.googlegroups.com> Hi...I'm a newbie to python, and very confused. I'm writing a simple program and want the user to be able to edit a line that I display using the full gnu readline capabilitites. (For example, control+a to go to the beginning of the line.) Then I want to be able to read the line after it's been edited... I know that with perl I would do this with some variation on term::readline. I've looked at the readline and code packages under Python but I can't make heads or tails of them. The readline example in the docs is way over my head. Any ideas? Thanks From apardon at forel.vub.ac.be Fri Aug 26 04:22:33 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 26 Aug 2005 08:22:33 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRVn-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <WZaPe.1953$eQ.899@newssvr30.news.prodigy.com> <mailman.3485.1124942826.10512.python-list@python.org> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> Message-ID: <slrndgtka9.1qv.apardon@rcpc42.vub.ac.be> Op 2005-08-25, Bryan Olson schreef <fakeaddress at nowhere.org>: > Steve Holden asked: > > Do you just go round looking for trouble? > > In the course of programming, yes, absolutly. > > > As far as position reporting goes, it seems pretty clear that find() > > will always report positive index values. In a five-character string > > then -1 and 4 are effectively equivalent. > > > > What on earth makes you call this a bug? > > What you just said, versus what the doc says. > > > And what are you proposing that > > find() should return if the substring isn't found at all? please don't > > suggest it should raise an exception, as index() exists to provide that > > functionality. > > There are a number of good options. A legal index is not one of > them. IMO, with find a number of "features" of python come together. that create an awkward situation. 1) 0 is a false value, but indexes start at 0 so you can't return 0 to indicate nothing was found. 2) -1 is returned, which is both a true value and a legal index. It probably is too late now, but I always felt, find should have returned None when the substring isn't found. -- Antoon Pardon From rkern at ucsd.edu Wed Aug 31 18:54:59 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 31 Aug 2005 15:54:59 -0700 Subject: To Python List Moderator In-Reply-To: <20050831222822.85607.qmail@web80012.mail.yahoo.com> References: <20050831222822.85607.qmail@web80012.mail.yahoo.com> Message-ID: <df5cg2$4n4$1@sea.gmane.org> David Fickbohm wrote: > Can you please remove me from the list starting tomorrow I am going an a > weeks vacation. You have to do it yourself. http://mail.python.org/mailman/listinfo/python-list -- 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 grante at visi.com Wed Aug 24 10:25:37 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 24 Aug 2005 14:25:37 -0000 Subject: py-serial + CSV References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> <1124820032.854336.278790@f14g2000cwb.googlegroups.com> <slrndgo9l5.8t4.sybrenUSE@schuimige.unrealtower.org> Message-ID: <11gp0r18hf98g18@corp.supernews.com> On 2005-08-24, Sybren Stuvel <sybrenUSE at YOURthirdtower.com.imagination> wrote: >> import serial >> s = serial.Serial(port=0,baudrate=4800, timeout=20) >> while 1: >> line = s.readline() >> words = line.split(',') >> if words[0]=="$GPRMC": >> print words[1], words[3], words[5] >> >> I just wonder if there is some beter (or as you are saying "more >> pythonic":) aproach how to write such a piece of code. > > You could use regular expressions instead. "There is a programmer who has a problem to solve. He decides to use regular expressions. Now he has two problems." > And to make it even more pythonic, replace the "while" and the > "line = s.readline()" with "for line in s:" Serial port objects aren't iterable. -- Grant Edwards grante Yow! I was making donuts at and now I'm on a bus! visi.com From gregpinero at gmail.com Tue Aug 9 15:18:39 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 9 Aug 2005 15:18:39 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: <ddat8d$ltt$1@news.doit.wisc.edu> References: <mailman.2892.1123599204.10512.python-list@python.org> <n5jhf1dr636psttdm4mic7apjv0i0qrmns@4ax.com> <mailman.2896.1123605144.10512.python-list@python.org> <ddao5r$j5q$1@news.doit.wisc.edu> <TT5Ke.5238$3p.1389@bignews3.bellsouth.net> <ddat8d$ltt$1@news.doit.wisc.edu> Message-ID: <312cfe2b050809121853b8a2ee@mail.gmail.com> Thanks everyone. I understand now. Everything is a reference, all that matters is whether I can go inside the "cubbyhole" and change something. Immutables don't allow this. So what if I do want to share a boolean variable like so: <code> sharedbool=True class cls1:pass cl=cls1() cl.sharedbool1=sharedbool sharedbool=False >>cl.sharedbool1 True #but I wanted false! </code> My guess having read this threat would be to make a simple wrapper class for a boolean so I'm changing something inside the object instead of reassigning it? <code> class bigbool: /t def __init__(self,tf): /t/t self.val=tf /t def setval(self,tf): /t/t self.val=tf </code> Is there an easier way? -Greg On 8/9/05, Rocco Moretti <roccomoretti at hotpop.com> wrote: > Christopher Subich wrote: > > Rocco Moretti wrote: > > > >> Variables in Python are names. They aren't the cubbyholes into which > >> you put values, they are sticky notes on the front of the cubby hole. > > > > > > +1 MOTW (Metaphor of the Week) > > Thanks, but please note it's not really mine - I've seen it somewhere > else before. I thought it was from the website I linked earlier[1], but > now I'm a little embarrased to find out that isn't, and I have no clue > where it's from. > > [1] http://starship.python.net/crew/mwh/hacks/objectthink.html > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From gregpinero at gmail.com Tue Aug 2 14:02:39 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 2 Aug 2005 14:02:39 -0400 Subject: py2exe windows apps path question In-Reply-To: <312cfe2b050802110016a5be88@mail.gmail.com> References: <11ev0tcg9n2ndd@corp.supernews.com> <dcoahp$9u9$3@news1.zwoll1.ov.home.nl> <312cfe2b050802110016a5be88@mail.gmail.com> Message-ID: <312cfe2b05080211023bbff4cd@mail.gmail.com> On 8/2/05, Gregory Pi?ero <gregpinero at gmail.com> wrote: > Vincent, I'm not sure I completely understand your question but this > link may be the answer nonetheless: > http://www.jrsoftware.org/isfaq.php#workingdir I meant to say Grant, ... , Vincent wasn't the one with the question. Sorry. From paolo_veronelli at tiscali.it Fri Aug 26 09:13:03 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Fri, 26 Aug 2005 15:13:03 +0200 Subject: algorithm for non-dimensionalization In-Reply-To: <1124990980.137239.243470@g44g2000cwa.googlegroups.com> References: <1124990980.137239.243470@g44g2000cwa.googlegroups.com> Message-ID: <430F155F.1050304@tiscali.it> gyromagnetic at gmail.com wrote: > Hi, > I am trying to non-dimensionalize some data I have obtained. There are > no 'standard' dimensionless groups for my application, so I would like > to obtain the 'best' non-dimensional groups based on some statistical > measures of the resulting transformed data. > > At this point, I am looking for a way to generate dimensionless > groupings from a set of base units. I would like to have a way to > output all dimensionless groups that comprise no more than some > specified number of fundamental (or base) units. > > For instance, if I have data like the following: > > dat1(length), dat2(time), dat3(length), dat4(length/time), > dat5(length^2) > > and I want dimensionless groups with no more than four base units, I > would like a result like the following: > > dat1/dat3, dat1/(dat2*dat4), dat5/(dat1*dat3), dat5/(dat2*dat4*dat1), > ... > > I plan to code this in Python, and would appreciate any thoughts you > might have about algorithms or approaches to carry out this task. > > Thank you. > > -g > Thinking more,it's an eigenvector problem. Where all dat* magnitudes are expressed as a vector of integers in the dimensions space,and the result vector is all 0. IE E=[m][L^2][T^-2] v=[L][T^-1] f=[T^-1] p=[m][L][T^-1] ...... in the mass,lenght,time space are [1,2,-2] [0,1,-1] [0,0,-1] [1,1,-1] say matrix D then D*[x1,x2,x3,x4]=[0,0,0] (looking for adimensionals) So you are looking for an eigenvector formed by only integers. Ciao Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From temposs at gmail.com Tue Aug 2 12:01:58 2005 From: temposs at gmail.com (temposs at gmail.com) Date: 2 Aug 2005 09:01:58 -0700 Subject: a pickle's pickle Message-ID: <1122998518.750304.191860@g44g2000cwa.googlegroups.com> I'm trying to pickle a class, and while I get no errors or anything, almost none of the class instance gets pickled, and I don't know why...Here's the pickled output: (i__main__ TrainingMatrix p0 (dp1 S'matrixWords' p2 I4714 sS'numWords' p3 I4714 sS'totalWordsProcessed' p4 I46735 sS'numContexts' p5 I7664 sS'estimator' p6 (dp7 sb. --End of output The class TrainingMatrix has no embedded classes and none of its methods have embedded methods. An instance of this class running in my program for about 10 minutes can build up on the order of 100MB in resident memory, but the output seems to be the same regardless of the data set size. The output seems to not even capture all of the member variables in the class. Here is the class code, abridged: class TrainingMatrix: matrix = [] estimator = {} wordInfo = {} contextInfo = {} totalWordsProcessed = 0 numWords = 0 numContexts = 0 matrixWords = 0 def AddWordInfo(self,newWordInfo,newCapScheme): ... #End AddWordInfo def AddNewWord(self,newCapScheme): ... #End AddNewCapScheme def AddContext(self,newContext): ... #End AddContext def AddInstance(self,word,context): ... #End AddInstance def UpdateMatrix(self,wordIndex,contextIndex,isLowerCase): ... #End UpdateMatrix def PrintMatrix(self): ... #End PrintMatrix def EstimateLowerCase(self): ... #End GetNumWords def GetWordInfo(self,wordToFind): ... #End GetWordInfo def GetContext(self,wordList,direction): ... #End GetContext def GetBestCapScheme(self,wordInfo,precedeContext,followContext): ... #End GetBestCapScheme def IsLowerCase(self,word): ... #End IsLowerCase #End TrainingMatrix ################### And here is the pickling code: try: trainDB = open(trainDBString,"r+") except IOError: trainDB = open(trainDBString,"w") trainDB.close() trainDB = open(trainDBString,"r+") #End try ... try: trainerString = trainDB.read() trainer = loads(trainerString) except EOFError: trainer = TrainingMatrix() #End try ... trainerString = dumps(trainer) trainDB.write(trainerString) I've also tried a simple shelve implementation but got results similar to this, which is why I recoded to pickle, since it's lower level. Any help is appreciated :-) -Andrew From gregpinero at gmail.com Wed Aug 31 13:00:07 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Wed, 31 Aug 2005 13:00:07 -0400 Subject: To the python-list moderator In-Reply-To: <Dpidndxiv9x4R4jeRVn-gw@comcast.com> References: <Dpidndxiv9x4R4jeRVn-gw@comcast.com> Message-ID: <312cfe2b05083110007a5829cb@mail.gmail.com> I got this same message. I'm using gmail. Greg On 8/31/05, Terry Reedy <tjreedy at udel.edu> wrote: > > For a couple of years, I have been reading and posting and posting to > python-list and c.l.p via gmane.news.orgs gmane.comp.python.general group. > Today I got this from 'python-list-bounces', which I presume is a > 'machine' > rather than a 'human' address. > > --------------------------- > Your mail to 'Python-list' with the subject > > Re: how to join two Dictionary together? > > Is being held until the list moderator can review it for approval. > > The reason it is being held: > > Message has a suspicious header > > Either the message will get posted to the list, or you will receive > notification of the moderator's decision. > ----------------------------- > > Since I had nothing to do with the headers, the problem is between gmane's > sending (perhaps when responding to a message from a particular site) and > your review. I hope this can be fixed. > > Terry J. Reedy > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com <http://www.blendedtechnologies.com>) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20050831/36ef82eb/attachment.html> From berlin.brown at gmail.com Thu Aug 11 19:25:47 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Thu, 11 Aug 2005 19:25:47 -0400 Subject: The python license model Message-ID: <tpGdnUh98pTjQ2bfRVn-tA@comcast.com> Can you distribute a python system with only a couple of libraries that you plan to use. For example, I generally avoid having a system with hundreds of loose scripts(ie python library). So, I have considered only taking the libraries I need. My question, is python license friendly for doing this? I haven't worked with 'egg' too much. -- Ramza from Atlanta http://www.newspiritcompany.com From tpearce at internode.on.net Mon Aug 22 07:57:06 2005 From: tpearce at internode.on.net (m7b52000) Date: Mon, 22 Aug 2005 21:27:06 +0930 Subject: passing arguments from scale widget to function In-Reply-To: <op.svwqatuimko9fo@pcx194.rd.bbc.co.uk> References: <430828c4$1@duster.adelaide.on.net> <op.svwheakamko9fo@pcx194.rd.bbc.co.uk> <4309b3f2$1@duster.adelaide.on.net> <op.svwqatuimko9fo@pcx194.rd.bbc.co.uk> Message-ID: <4309bd93$1@duster.adelaide.on.net> Matt Hammond wrote: > On Mon, 22 Aug 2005 12:16:01 +0100, m7b52000 <tpearce at internode.on.net> > wrote: > >>> command = lambda : Calc(a.get()) > > >> I get the following message when I use lambda as above: >> >> TypeError: <lambda>() takes no arguments (1 given) > > > Oops, forgot! The Scale widget outputs a single argument - the value of > the slider. You therefore could write: > > command = lambda value : Calc(value) > > or even simpler: > > command = Calc > > In the latter case, you're supplying your "calc" function as the > function to be called. Calc takes a single argument - the value of the > slider, so it fulfills the task. Note that we're passing "Calc" (the > function itself), not "Calc(...)" (the result of calling the function) > > regards > > > Matt > Ahhhh. Partial success with : command = Calc. A slider will now pass its argument to a function without problem. My Calc function however is expecting 3 arguments - 1 from each slider i.e moving any of the 3 sliders should cause a recalculation. I am now getting the following error: TypeError: Calc() takes exactly 3 arguments (1 given) p.s your help is much appreciated.... From noreply at gcgroup.net Wed Aug 24 12:10:56 2005 From: noreply at gcgroup.net (William Gill) Date: Wed, 24 Aug 2005 16:10:56 GMT Subject: a question about tkinter StringVars() In-Reply-To: <opsv0q8xkmrqur0o@eb.pragmadev> References: <P20Pe.1293$u_6.101@newssvr17.news.prodigy.com> <opsv0q8xkmrqur0o@eb.pragmadev> Message-ID: <k_0Pe.1323$u_6.726@newssvr17.news.prodigy.com> Eric Brunel wrote: > On Wed, 24 Aug 2005 15:07:27 GMT, William Gill <noreply at gcgroup.net> wrote: > >> Working with tkinter, I have a createWidgets() method in a class. >> Within createWidgets() I create several StringVars() and >> assign them to the textvariable option of several widgets. >> Effectively my code structure is: >> >> def createWidgets(self): >> ... >> var = StringVar() >> Entry(master,textvariable=var) >> ... >> ... >> >> Though 'var' would normally go out of scope when createWidgets >> completes, since the Entry and its reference do not go out of scope, >> only the name 'var' goes out of scope, not the StringVar object, Right? > > > Well, apparently not: > > ------------------------------------------------ > from Tkinter import * > > class MyStringVar(StringVar): > def __del__(self): > print "I'm dying!" > > root = Tk() > > def cw(): > var = MyStringVar() > Entry(root, textvariable=var).pack() > > cw() > > root.mainloop() > ------------------------------------------------ > > Running this script actually prints "I'm dying!", so there is obviously > no reference from the Entry widget to the variable object. The reference > is actually kept at tcl level between an entry and the *tcl* variable, > which knows nothing about the *Python* variable. I will have to do some experimenting. > > BTW, the whole purpose of StringVar's is to be kept so that the text for > the entry can be retrieved or modified by another part of the program. > So what can be the purpose of creating variables in a function or method > and not keeping them anywhere else than a local variable? I was trying to keep my question simple. In actuality, I have a widget I'll call dataForm that extends tkSimpleDialog.Dialog. In it I have several entry and checkbox widgets, and a call to a changed() method passed from the parent. When I'm done editing dataForm, all the variables are processed in a save() method, and dataForm is destroyed. What happened when I used self.var = MyStringVar() and Entry(root, textvariable=self.var).pack(), is that a subsequent call to create a dataForm instance has residual data from the previous instance AND the change callback caused an error. Changing to local variables seemed to cure the problems. I just tried changing back to the self.var approach, and it seems to work fine??? I must have had some name conflicts in my earlier code. I'll try to figure it out, and post if I do. Bill From grante at visi.com Tue Aug 23 10:53:27 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 23 Aug 2005 14:53:27 -0000 Subject: Convert float to string ... References: <defcp7$f4n$1@fuerst.cs.uni-magdeburg.de> Message-ID: <11gme371p89tr00@corp.supernews.com> On 2005-08-23, Konrad M?hler <konrad at my-rho.de> wrote: > Hi, > > a simple question but i found no solution: > > How can i convert a float value into a string value? > > > string_value1 = string(float_value) + ' abc' string_value1 = str(float_value) + ' abc' Or the more versatile: string_value1 = "%10.3f abc" % float_value -- Grant Edwards grante Yow! I'm having a BIG at BANG THEORY!! visi.com From opengeometry at yahoo.ca Mon Aug 29 22:17:45 2005 From: opengeometry at yahoo.ca (William Park) Date: Mon, 29 Aug 2005 22:17:45 -0400 Subject: File parser References: <snu0h870sg.fsf@gmail.com> Message-ID: <2413f$4313c1c9$d1b7149e$21595@PRIMUS.CA> Angelic Devil <aaron.ginn at gmail.com> wrote: > BAR > END BAR > > FOOBAR > END FOOBAR man csplit -- William Park <opengeometry at yahoo.ca>, Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From aleaxit at gmail.com Mon Aug 22 21:39:30 2005 From: aleaxit at gmail.com (aleaxit at gmail.com) Date: 22 Aug 2005 18:39:30 -0700 Subject: up to date books? In-Reply-To: <slrndgdsdl.r2g.jgrahn-nntq@frailea.sa.invalid> References: <TMqdnRHoSoNyk5neRVn-3Q@rcn.net><de1m3u$bqq$1@wake.carmen.se> <slrndgdsdl.r2g.jgrahn-nntq@frailea.sa.invalid> Message-ID: <1124761170.650704.181020@o13g2000cwo.googlegroups.com> Glad to hear that my efforts to cover some of 2.3's release features in a mostly-2.2 book were appreciated. I'm probably going to do the same thing for the 2nd edition of the Nutshell: wait until 2.5 alpha's out so I can mention _its_ feechurz in a mostly-2.4 book... meaning the 2nd ed of the Nutshell may be almost a year away... Alex From john at castleamber.com Fri Aug 26 17:55:15 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 21:55:15 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <gaGOe.213$5k1.200@newssvr27.news.prodigy.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <Xns96BD814C9C690castleamber@130.133.1.4> <1125064956.863140.32270@g14g2000cwa.googlegroups.com> Message-ID: <Xns96BEABFDBBF3Fcastleamber@130.133.1.4> "T Beck" <Tracy.Beck at Infineon.com> wrote: > > John Bokma wrote: >> "T Beck" <Tracy.Beck at Infineon.com> wrote: >> >> > If we argue that people are evolving the way e-mail is handled, and >> > adding entire new feature sets to something which has been around >> > since the earliest days of the internet, then that's perfectly >> > feasable. HTML itself has grown. We've also added Javascript and >> > Shockwave. >> >> They are not additions to HTML, like PNG is no addition to HTML, or >> wav, mp3, etc. >> > [snip] > > Wasn't the point... I never said they were. "HTML itself has grown. We've also added Javascript" I read that as: JavaScript is an addition to HTML. > HTML is at version 4.0(I > think?) 4.01? And I think it will stay there, since XML seems to be the future. > now, AND we've added extra layers of stuff you can use > alongside of it. The internet is a free-flowing evolving place... to > try to protect one little segment like usenet from ever evolving is > just ensuring it's slow death, IMHO. And if so, who cares? As long as people hang out on Usenet it will stay. Does Usenet need al those extra gimmicks? To me, it would be nice if a small set would be available. But need? No. The death of Usenet has been predicted for ages. And I see only more and more groups, and maybe more and more people on it. As long as people who have to say something sensible keep using it, it will stay. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From steve at holdenweb.com Fri Aug 19 05:33:16 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Aug 2005 10:33:16 +0100 Subject: Database of non standard library modules... In-Reply-To: <de46qn$2f0$1@sea.gmane.org> References: <d76c7b8f050819014953a63197@mail.gmail.com> <de46qn$2f0$1@sea.gmane.org> Message-ID: <de48vl$6j8$3@sea.gmane.org> Robert Kern wrote: > Jon Hewer wrote: > >>Is there an online database of non standard library modules for Python? > > > http://cheeseshop.python.org/pypi > While cheeseshop might resonate with the Monty Python fans I have to say I think the name sucks in terms of explaining what to expect. If I ask someone where I can find a piece of code and the direct me to the cheese shop, I might look for another language. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From della at toglimi.linux.it Thu Aug 11 06:25:19 2005 From: della at toglimi.linux.it (Matteo Dell'Amico) Date: Thu, 11 Aug 2005 10:25:19 GMT Subject: set of sets In-Reply-To: <mailman.2971.1123753988.10512.python-list@python.org> References: <mailman.2971.1123753988.10512.python-list@python.org> Message-ID: <jIFKe.13627$HM1.364840@twister1.libero.it> Paolino wrote: > I thought rewriting __hash__ should be enough to avoid mutables problem > but: > > class H(set): > def __hash__(self) > return id(self) > > s=H() > > f=set() > > f.add(s) > f.remove(s) > > the add succeeds > the remove fails eventually not calling hash(s). Why don't you just use "frozenset"? -- Ciao, Matteo From carsten at uniqsys.com Thu Aug 25 11:04:54 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Thu, 25 Aug 2005 11:04:54 -0400 Subject: variable hell In-Reply-To: <430dd8e1@127.0.0.1> References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> <430dd8e1@127.0.0.1> Message-ID: <1124982294.23716.51.camel@dot.uniqsys.com> On Thu, 2005-08-25 at 10:43, Nx wrote: > Thanks for the many replies > > here is an example for what it will be used for , in this case > fixed at 31 fieldvalues: > > inputvalues=(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25, > s26,s27,s28,s29,s30,s31) inputvalues = tuple(mylist) Hope this helps, Carsten. From martin at v.loewis.de Mon Aug 15 17:32:57 2005 From: martin at v.loewis.de (=?ISO-8859-2?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 15 Aug 2005 23:32:57 +0200 Subject: Windows 32 service problem (ImportError) In-Reply-To: <mailman.3092.1124109598.10512.python-list@python.org> References: <mailman.3092.1124109598.10512.python-list@python.org> Message-ID: <43010a09$0$16007$9b622d9e@news.freenet.de> Laszlo Zsolt Nagy wrote: > exceptions.ImportError: dynamic module does not define init function > (initzlib) > ------------- > > Where is the problem? Please help. My guess is that you have a zlib.dll somewhere, which gets used before zlib.pyd. Regards, Martin From gnb at itga.com.au Wed Aug 10 03:34:43 2005 From: gnb at itga.com.au (Gregory Bond) Date: Wed, 10 Aug 2005 17:34:43 +1000 Subject: Module Extension C/CPI Question In-Reply-To: <mailman.2901.1123636571.10512.python-list@python.org> References: <mailman.2901.1123636571.10512.python-list@python.org> Message-ID: <kmacdd.5cr.ln@lightning.itga.com.au> Jeremy Moles wrote: > Or, perhaps, there's even a better way? I'm getting more and more > experienced with the Python/C API, so I don't need a walk-through or > anything. :) Just an experienced recommendation... > Better by far to create a new python type in C that has your struct inside it and use PyMemberDefs to make those members automagically available to Python. This has the monster advantage that members are only converted from C objects to Python objects if they are referenced - which is likely to have serious performance advantages if (as seems likely with really large data objects) most of the members of most of the objects aren't ever referenced. See the "Embedding & Extending" document, Chapter 2. From onurb at xiludom.gro Sat Aug 13 11:39:59 2005 From: onurb at xiludom.gro (bruno modulix) Date: Sat, 13 Aug 2005 17:39:59 +0200 Subject: need help with my append syntax In-Reply-To: <1123864268.248317.23940@g44g2000cwa.googlegroups.com> References: <1123864268.248317.23940@g44g2000cwa.googlegroups.com> Message-ID: <42fe1451$0$32467$626a14ce@news.free.fr> yaffa wrote: > dear folks, Dear Yaffa, > i'm trying to append a semicolon to my addr string Python strings don't have a 'append' method. > and am using the > syntax below. for some reason the added on of the ; doesn't work. "doesn't work" is the worst possible description of a problem. Please read http://www.catb.org/~esr/faqs/smart-questions.html > when i print it out later on it only shows the original value of addr. > > addr = incident.findNextSibling('td') > addr.append('%s;') If you don't have an AttributeError here then addr is not bound to a string. > thanks > > yaffa > -- bruno desthuilliers ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@')" python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From darkpaladin79 at hotmail.com Tue Aug 30 15:22:05 2005 From: darkpaladin79 at hotmail.com (Ivan Shevanski) Date: Tue, 30 Aug 2005 15:22:05 -0400 Subject: py to exe: suggestions? In-Reply-To: <1125231403.476434.162930@z14g2000cwz.googlegroups.com> Message-ID: <BAY103-F30BA79807C240BFC69D230A2AE0@phx.gbl> Not sure if you already got the answer to this lol but since this is one thing about python i do know how to do, use CXFreeze. Its basicly a combination of all the programs you have already tryed. Works great for me =D sorry I dont have a link, just google it. -Ivan _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From nothingcanfulfill at gmail.com Sun Aug 21 04:48:38 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 21 Aug 2005 01:48:38 -0700 Subject: Module Name Conflicts In-Reply-To: <1124413952.401306.168240@g47g2000cwa.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> <1124408324.310617.198340@z14g2000cwz.googlegroups.com> <1124413952.401306.168240@g47g2000cwa.googlegroups.com> Message-ID: <1124614118.264193.140360@o13g2000cwo.googlegroups.com> Heh, so long as it works. Sorry for the delay, I've been away for a bit ;P Hope it's all owrking out -Wes From martindemello at yahoo.com Wed Aug 24 11:12:44 2005 From: martindemello at yahoo.com (Martin DeMello) Date: Wed, 24 Aug 2005 15:12:44 GMT Subject: gtkmozembed in fedora core 3 References: <4TAOe.90515$vj.4835@pd7tw1no> <430b22ae$0$6564$ba620e4c@news.skynet.be> Message-ID: <M70Pe.298547$5V4.211143@pd7tw3no> Jonas Geiregat <yux at sdf-eu.org> wrote: > > If you can't find any rpm's there aren't any available. > You need to compile mozilla with (I think) support for gtkmozembed but I > guess that's done by default when you compile mozilla with > ac_add_options --enable-default-toolkit=gtk2 in your mozconfig file. > Check /usr/lib/mozilla for libgtkembedmoz.so if it's not there you'll > have to rebuild your mozilla/firefox rpm , again I think, these are just > some random tips .. > Good luck! Thanks, I'll give it a whirl! martin From could.net at gmail.com Fri Aug 5 03:07:55 2005 From: could.net at gmail.com (could ildg) Date: Fri, 5 Aug 2005 15:07:55 +0800 Subject: IronPython 0.9 Released In-Reply-To: <20050804231232.85365666.EP@zomething.com> References: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> <20050804230820.1518126954.EP@zomething.com> <20050804231232.85365666.EP@zomething.com> Message-ID: <311b5ce10508050007a9667c7@mail.gmail.com> Why is iron python runs so fast but jython runs so slow while C# and java seem very much the same? On 8/5/05, EP <EP at zomething.com> wrote: > Oops. Nevermind. > > [like the old Saturday Night Live] > > > > > ------------Original Message------------ > > From: "EP" <EP at zomething.com> > > To: python-list at python.org > > Date: Thu, Aug-4-2005 10:09 PM > > Subject: Re: IronPython 0.9 Released > > > > "Luis M. Gonzalez" Announced: > > > > > IronPython 0.9 Released(8/2/2005 10:28:41 AM) > > > > > > > > http://www.microsoft.com/downloads/details.aspx?familyid=cf5ae627-5df1-4f8a-ba8b-d64f0676f43f&displaylang=en > > > > > > > MS website says: > > > > """System Requirements > > > > * Supported Operating Systems: Windows Server 2003; Windows XP > > > > You must install the .NET Framework Version 2.0 Redistributable Package > > Beta 2 prior to installing IronPython.""" > > > > > > And > > > > > > """Important: You cannot install two different language versions of the > > .NET Framework on the same machine. Attempting to install a second > > language version of the .NET Framework will cause the following error to > > appear: "Setup cannot install Microsoft .NET Framework because another > > version of the product is already installed." If you are targeting a > > non-English platform or if you wish to view .NET Framework resources in a > > different language, you must download the appropriate language version > > of the .NET Framework language pack.""" > > > > > > So, one has to uninstall their stable .NET Framework to install a beta > > .NET Framework to try out a beta release of a new Python? Would this > > not be of concern to folks who actually build ontop of .NET (and want to > > be sure their current code / applications / tools work)? > > > > It is really all or none with MS, isn't it? If the > > language/application is not ready for prime time, why would someone commit to beta code > > and a beta framework upon which other applications depend? > > > > > > I may have the wrong perspective on all this, but it really befuddles > > me. > > > > > > [Bring on PyPy] > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From Scott.Daniels at Acm.Org Fri Aug 26 22:34:41 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Aug 2005 19:34:41 -0700 Subject: Python library/module for MSAccess In-Reply-To: <mailman.51.1125100690.8229.python-list@python.org> References: <mailman.51.1125100690.8229.python-list@python.org> Message-ID: <430fc532$1@nntp0.pdx.net> Jonathon Blake wrote: > I thought I had seen a python library/module that easily enabled one > to read / write / create MSAccess databases a couple of years ago. > [My impression is that the Jet Database engine was _not_ required.] Access is a generalized I/O to databases. THe normal default DB _is_ the Jet Database engine. Easiest access for me is through the win32 module 'odbc'. --Scott David Daniels Scott.Daniels at Acm.Org From bj_666 at gmx.net Sun Aug 14 16:04:06 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sun, 14 Aug 2005 22:04:06 +0200 Subject: pickle.load not working? References: <1123884180.348659.247960@z14g2000cwz.googlegroups.com> Message-ID: <pan.2005.08.14.20.04.04.603094@gmx.net> In <1123884180.348659.247960 at z14g2000cwz.googlegroups.com>, sp1d3rx at gmail.com wrote: > it reads a file saved this way: > ---------------------- > import pickle > > class chatuser: #container for storing user information... > login = "" > authcode = "" > cookie = "" > ip = "" > loggedin = 0 > invalid_logins = 0 > allow_login = 1 > status = "" > realname = "" > phone = "" > email = "" > > derek = chatuser If this is copy and pasted and not just a typo then `derek` is just another name for the `chatuser` class now and not an *instance* of it. Ciao, Marc 'BlackJack' Rintsch From stewart.midwinter at gmail.com Sun Aug 21 14:44:21 2005 From: stewart.midwinter at gmail.com (stewart.midwinter at gmail.com) Date: 21 Aug 2005 11:44:21 -0700 Subject: TKinter In-Reply-To: <1124560693.691175.250000@g49g2000cwa.googlegroups.com> References: <1124560693.691175.250000@g49g2000cwa.googlegroups.com> Message-ID: <1124649861.083189.321670@g47g2000cwa.googlegroups.com> It's pretty hard to know what the problem is with the vague description you've provided. Why not post your problem code or, if there's a lot of it, create a small sample that has the problematic behaviour. Better yet, post your message to tkinter-discuss at python.org cheers S From gelios at rbcmail.ru Wed Aug 10 09:42:34 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Wed, 10 Aug 2005 17:42:34 +0400 Subject: MainThread blocks all others References: <ddb7st$2lpp$1@gavrilo.mtu.ru> <HHaKe.2321$Z87.409@newssvr14.news.prodigy.com> <fRaKe.3656$zr1.2646@newssvr13.news.prodigy.com> <42f9d4ef_2@news.isis.de> <QWmKe.2561$Z87.610@newssvr14.news.prodigy.com> Message-ID: <42fa0457_2@news.isis.de> Hi, Thanks your reply again. Please find my comments below. > Your code did not, and could not, use the value of counter for > anything but busy-waiting. You had: > > while counter != 1: > pass > # ... continue... > > If you replace this with the semaphore, you can just assume a > counter value of one. > I replaced it by semaphore, but how should i check is semaphore changed or not? When I call release() method of semaphore, internal counter is increased and value will be equal to number of release() calls minus number of acquire() calls. Am I right? Ok, in this case what condition should I check in while statement? From fakeaddress at nowhere.org Wed Aug 31 16:11:36 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 20:11:36 GMT Subject: global interpreter lock In-Reply-To: <43149abd.168178447@news.oz.net> References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <zGJNe.242$Ux3.75@newssvr21.news.prodigy.com> <868xyw9g30.fsf@bhuda.mired.org> <As_Oe.654$dw4.615@newssvr29.news.prodigy.net> <86slwymx79.fsf@bhuda.mired.org> <slrndgv04g.264.zen19725@cabalamat.somewhere> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <slrndgvb58.312.zen19725@cabalamat.somewhere> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> <D3KQe.666$la.544@newssvr22.news.prodigy.net> <864q98b7k0.fsf@bhuda.mired.org> <WXRQe.230$hc4.32@newssvr12.news.prodigy.com> <43149abd.168178447@news.oz.net> Message-ID: <Y9oRe.37$pt.27@newssvr27.news.prodigy.net> Bengt Richter wrote: > Bryan Olson wrote: >>For a long time, >>the most sophisticated software services generally have used >>multiple lines of execution, and now that's mostly in the form >>of threads. No one actually disagrees, but they go right on >>knocking the modern methods. > > I think Mike is asking for references/citations/links to the > "concurrency systems" and "modern methods" you are talking about ;-) > (I'd be interested too ;-) Sure. I tried to be helpful there, but maybe I need to be more specific. The ref from my previous post, Google-able as "The C10K problem" is good but now a little dated. System support for threads has advanced far beyond what Mr. Meyer dealt with in programming the Amiga. In industry, the two major camps are Posix threads, and Microsoft's Win32 threads (on NT or better). Some commercial Unix vendors have mature support for Posix threads; on Linux, the NPTL is young but clearly the way to move forward. Java and Ada will wrap the native thread package, which C(++) offers it directly. Microsoft's threading now works really well. The WaitMultipleObjects idea is a huge winner. -- --Bryan From http Fri Aug 26 05:27:26 2005 From: http (Paul Rubin) Date: 26 Aug 2005 02:27:26 -0700 Subject: Better crypto hash functions, long, with code References: <O1BPe.751$5k1.734@newssvr27.news.prodigy.net> Message-ID: <7xpss1nj41.fsf@ruckus.brouhaha.com> Bryan Olson <fakeaddress at nowhere.org> writes: > The module provides classes and functions. The functions are: > > string_to_hex(str): Return a string with two hex digits for > each byte of str, representing the ord() of the byte. The > case of the hex digits A-F/a-f is up to Python's built-in > formatting; Python doc doesn't specify the case, so it may > be either and may change. > > oid_to_der(arc_sequence): Return the DER encoding of an OID, > including the encoded tag and length. > > smd_from_oid(oid): Look up and return the Secure Message > Digest class corresponding to the oid, or None if no such > class is known. The oid may be a sequence of integer arcs, > or a string holding the DER encoding. Note there's a PEP for crypto hash function API's and modules like hmac.py expect hashes to conform to it: http://www.python.org/peps/pep-0247.html You might want to bring your own API closer to it. Also, I think the PEP should be extended to include those OID lookup functions. From Scott.Daniels at Acm.Org Wed Aug 3 10:31:33 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 03 Aug 2005 07:31:33 -0700 Subject: HELP:sorting list of outline numbers In-Reply-To: <mailman.2651.1123037792.10512.python-list@python.org> References: <mailman.2651.1123037792.10512.python-list@python.org> Message-ID: <42f0ccb9$1@nntp0.pdx.net> Delaney, Timothy (Tim) wrote: > Scott David Daniels wrote: >>For 2.3: (using DSU -- Decorate, Sort, Undecorate) ... >> lst = ['1', '1.2', '1.12', '1.1', '3.1'] >> decorated = [(numparts(txt), txt) for txt in lst] >> decorated.sort() >> lst[:] = [txt for code, txt in decorated] > > Slightly better to do:: > ... > lst = ['1', '1.2', '1.12', '1.1', '3.1'] > decorated = [(numparts(txt), i, txt) for i, txt in enumerate(lst)] > decorated.sort() > lst[:] = [txt[-1] for d in decorated] In the particular case given, I don't think it matters. In general, however, I agree the latter is a better idea. Just so someone hopping in here is clear about what is better, and explicitly _not_ because I think Tim misunderstands the issue, The latter version, in the case of a match on the "decorated" version compares first the "key", and then, if the keys match, it compares the position in the list. In no case does it actually compare the original list elements. The 2.4 version (just using the key= form of sort) does the same kind of thing; it avoids comparing the element and only compares keys. The reason you care about this is that is can be arbitrarily expensive to compare elements, or the elements themselves may be "incomparable" (think of complex numbers). --Scott David Daniels Scott.Daniels at Acm.Org From http Sat Aug 6 20:42:31 2005 From: http (Paul Rubin) Date: 06 Aug 2005 17:42:31 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> Message-ID: <7x7jeytw5k.fsf@ruckus.brouhaha.com> Mike Meyer <mwm at mired.org> writes: > You can't "fix" this. This code (in some python-like langauge that > isn't python): > > x = 23 > > def fun(): > x = 25 > # Rest of code > > has two possible interpretations. The fix is to add a "local" declaration in "fun": local x = 25 for example. If you want the one from the outer scope, then use, perhaps, outer x = 25 One really screwy situation with Python is x = 23 def f(): x = 25 def g(): x += 3 g obviously is supposed to inherit x from the surrounding scope, but there's no way for g to actually change x. From finite.automaton at gmail.com Mon Aug 22 14:12:12 2005 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 22 Aug 2005 11:12:12 -0700 Subject: How to print the name of a list? References: <1124727846.909693.129750@g43g2000cwa.googlegroups.com> Message-ID: <1124734332.592708.192120@o13g2000cwo.googlegroups.com> In general, no --- there is no unique mapping between references and names. For debugging, however, it is sometimes useful to try this kind of reverse lookup by iterating over the global dictionary: def guess_name(thing): for name, reference in globals.iteritems(): if thing is reference: return name else: return None # example use: foo = [1, 2, 3] bar = [4, 5, 6] baz = [foo, bar] for thing in baz: print guess_name(thing) # prints "foo" and "bar" I should emphasize that this is NOT failsafe, and it shouldn't be used in any way except for debugging IMHO. If you need to associate names with objects in a guaranteed way, use a dictionary. From ms at cerenity.org Wed Aug 3 18:36:23 2005 From: ms at cerenity.org (Michael Sparks) Date: Thu, 04 Aug 2005 00:36:23 +0200 Subject: Advanced concurrancy References: <dcatca$r4k$1@hermes.shef.ac.uk> <42ea98a2$0$1185$ed2619ec@ptn-nntp-reader01.plus.net> <dckpu2$9lf$1@hermes.shef.ac.uk> Message-ID: <42f154fd$0$14656$ed2619ec@ptn-nntp-reader02.plus.net> Peter Tillotson wrote: > I've not yet had a chance to try some examples, but i've looked through > the documentation. It feels quite familiar, It hopefully should. The approach is based essentially on an asynchronous hardware approach, on the recognition that the fundamental reason that hangs together is because it can be reasoned about in a similar manner to CSP. (That naturally leads to similarities of course with Occam) > but i'd say that it is closer to Jade, the fipa (federation of intelligent > physical agents) compliant agent framework Thanks - I've not come across those - I'll have to take a look at that in detail. (With a cursory look, they sounds similar to an application area a colleague is interested in investigating) > than CSP or pi calculus. I like the behaviour > (component microthread) model, but the advantage of CSP / pi calculus is > that the resulting distributed system remains open to mathematical > analysis. Indeed. However, by trying to have the same basic limitations in the system, Kamaelia should be amenable to the sort of approaches taken by hardware verification systems. It's possibly worth mentioning that there is one person at BBC R&D who is extremely interested in applying CSP style analysis techniques to Kamaelia systems whom I sure would be interested in chatting to you. (Indeed the similarities between Kamaelia and CSP is biggest reason for his interest :-) The idea of a verification system for software that is actually in use for real world systems would be extremely nice/useful to have (though not simple to achieve). FWIW, I am interested in hearing suggestions on changing the system to make it more amenable to mathematical analysis. (Largely because I'm a fan of formal methods where possible, but pragmatically view TDD as the current most practical way of getting towards the levels of reliabiliy aimed for by formal methods) > For concurency its is the best framework i've seen :-) Thanks! > Have you come across the pylinda tuplespace implementation. It might be > well worth a look. I have, and I liked what I saw :) > I might be barking up the wrong tree - but it seems to me that > there could be considerable overlap between tuplespaces and mailboxes, Probably the closer match is the co-ordinating assistant tracker (I can see what you mean though). That provides a basic global key/value store/retrieve service, which in a concurrent system is probably most akin to a Linda tuplespace. In a biological system it's more akin to the hormonal system which is more of the model I like to think of as to /when/ to use that part of the system. (Evolution having more 'experience' than me on how to build a massively concurrent system after all !!) It's generally only used at present for one of two purposes: * Finding services that already exist (so that we don't try to open two displays for example) * Stats collection. Using a Linda tuplespace there would be an interesting next move, however we generally only extend the system based on specific need rather than exploring architecture (Which I'm sure you understand!). > though you did mention that you were moving towards twisted as the > underlying platform for the future. Perhaps not underlying, but definitely interoperating with (It seems rather wasteful to reinvent wheels). > I'm quite interested in the mini version and also using the modules as > mobile code rather than installing it formally. I'll document it slightly better and post up on the website in the next 48 hours or so. In the meantime, the optimisation test which includes a slightly modified mini-axon can be found here: http://cvs.sourceforge.net/viewcvs.py/kamaelia/Sketches/OptimisationTest/ Specifically the file "simplegame.py". This includes a cutdown version of Axon that's about 100 lines long (lines 41 - 144 specifically), with the important classes being: class microprocess(object): class newComponent(object): class scheduler(microprocess): class component(microprocess): class send_one_component(component): def linkage(source,sink): > I'll probably zip the Axon directory and distribute the zip with the code, > adding the zip to the python path dynamically. Sounds interesting. If you go ahead with this we'd be interested in hearing how you get on. Best Regards, Michael. From tracy at bluedotonline.com Mon Aug 29 07:35:17 2005 From: tracy at bluedotonline.com (tracy) Date: Mon, 29 Aug 2005 19:35:17 +0800 Subject: CHANGE OF EMAIL ADDRESS NOTIFICATION Message-ID: <10508291935.AA02092@bluedotonline.com> CHANGE OF EMAIL ADDRESS NOTIFICATION Dear Clients, Suppliers & Friends, Effective August 1st 2005, my new email address will be tracytaw at swotdesigngroup.com. During this transition period, I'll still be receiving mails from my old account. Thanks & Regards, Tracy Taw SWOT Brand Architecture Sdn Bhd an entity of SWOT DESIGN GROUP T. 603 7877 6000 F. 603 7877 9005 E. info at swotdesigngroup.com From eddie at holyrood.ed.ac.uk Fri Aug 26 07:22:40 2005 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Fri, 26 Aug 2005 11:22:40 +0000 (UTC) Subject: ideas for university project ?? References: <mailman.12.1125053385.8229.python-list@python.org> Message-ID: <demu20$6tu$1@scotsman.ed.ac.uk> Jon Hewer <jonhewer at gmail.com> writes: >Hi >I'm about to start my third, and final, year in computer science at >cambridge uni, and i need to come up with an idea for a software >project, but i'm really struggling for ideas, and i was wondering >whether anyone here had any suggestions. >I'd say i'm probably most experienced in Java, but I have started >learning Python, and although i haven't got very far yet, I plan on >doing some more in the next few weeks. >Areas of interested include AI, distributed systems. Most of all i >want something that is interesting, and actually useful (thats >probably stating the obvious!) Well, there's a dearth of good software for network management especially for medium to large networks. Traffic stats, configuration management, device status etc. It would certainly be useful but whether it rocks your boat interest wise ... Admittedly I personally would like to play with Erlang rather than Python for this. Eddie From billiejoex at fastwebnet.it Wed Aug 31 06:57:41 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Wed, 31 Aug 2005 12:57:41 +0200 Subject: use threading without classes Message-ID: <F1gRe.2673$nT3.1438@tornado.fastwebnet.it> Hi all. Hi would like to use two threads in a program but all the examples I found on the net use oop programming that I doesn't love too much. :-) Can you code me a short example in wich two different functions are executed at the same time, plz? Thank you all. From tjreedy at udel.edu Wed Aug 24 16:12:20 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Aug 2005 16:12:20 -0400 Subject: Warning when doubly linked list is defined gloablly References: <1124881914.018491.315800@g14g2000cwa.googlegroups.com> Message-ID: <deikb3$6rs$1@sea.gmane.org> "chand" <chandra.bangalore at gmail.com> wrote in message news:1124881914.018491.315800 at g14g2000cwa.googlegroups.com... > Hi., > > In my api.py file 'g_opt_list' is defined globally > g_opt_list =[[],[],[],[],[],[],[]] > > I am using this global list in the fucntion > > def function (): > gloabl g_opt_list > > when I run the py file, I am getting the Following Error > > SyntaxWarning: name 'g_opt_list' is used prior to global declaration > > Please let me know how to remove this error To expand slightly on previous answers: 1. Write a *minimal* file that gives you the error. This means that removing any statement ceases to give you the error. This may answer your questions. 2. If still puzzled, post again. But cut and paste that *exact* file and also the *full* error traceback. Terry J. Reedy From franz.steinhaeusler at gmx.at Thu Aug 11 10:04:28 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Thu, 11 Aug 2005 16:04:28 +0200 Subject: new python debugger References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> <ubnhf1hgsmnef6r8svu2u2cdepis9q9jni@4ax.com> <1123740657.066728.39080@g43g2000cwa.googlegroups.com> <nebmf1dffel5mlf8qqag8jj2s67fio7blp@4ax.com> <bpcmf15lnd04uolunhsotbq1f0ulqup25q@4ax.com> <1123762771.062491.235800@g14g2000cwa.googlegroups.com> Message-ID: <kbmmf118jkckrvoana4658g58bkn0jlkql@4ax.com> On 11 Aug 2005 05:19:31 -0700, nir1408 at gmail.com wrote: >Thanks for the valuable input. I will look into it. You're welcome. > >In the mean time, until I implement your suggestions, here are some >workarounds for the problems you experienced. >[...] Really, you want to implement? cool ;) If you don't mind, I will continue in your sf "open discussion" forum. Cheers, -- Franz Steinhaeusler From fakeaddress at nowhere.org Thu Aug 11 22:14:20 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 02:14:20 GMT Subject: Bug in slice type In-Reply-To: <i_qdnax5oqkfNWbfRVn-ow@comcast.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <i_qdnax5oqkfNWbfRVn-ow@comcast.com> Message-ID: <0CTKe.90$k92.15@newssvr19.news.prodigy.com> Steven Bethard wrote: > I suspect there's a reason that it's done this way, but I agree with you > that this seems strange. Have you filed a bug report on Sourceforge? I gather that the slice class is young, so my guess is bug. I filed the report -- my first Sourceforge bug report. > BTW, a simpler example of the same phenomenon is: > > py> range(10)[slice(None, None, -2)] > [9, 7, 5, 3, 1] > py> slice(None, None, -2).indices(10) > (9, -1, -2) > py> range(10)[9:-1:-2] > [] Ah, thanks. -- --Bryan From sybrenUSE at YOURthirdtower.com.imagination Thu Aug 25 06:21:31 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Thu, 25 Aug 2005 12:21:31 +0200 Subject: Should I move to Amsterdam? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> Message-ID: <slrndgr6k4.i4a.sybrenUSE@schuimige.unrealtower.org> Martin P. Hellwig enlightened us with: > Personal transportation sucks in the Netherlands, if you live in the > Randstad (the area of the above mentioned cities) and you have to > travel across the Randstad, you go with the bike and/or > bus/tram/metro/train because that is the fastest way of > transportation. And a bike isn't "personal transportation"? > By the way, the big cities are notorious for losing your bike fast. True. Unless you have two proper locks. In that case your bike will last a very long time. > That doesn't mean that public transportation is good, no actual > since the public transportation is commercialized it sucks too. It's quite good actually. The Dutch Railways (Nationale Spoorwegen, NS for short) have a reputation of being late, but it isn't that bad. Trains run frequently, and if you have a serious delay, you even get part of your money back. My GF and I just got back from a holiday in Croatia. There, there is only a train every four hours, and then you're lucky. The track is so bad, going by bus is just as fast, except you can buy a ticket on the bus instead of having to buy a ticket + reservation in advance. On the way back, we used the ICE (intercity express) through Germany. It got delayed, so we missed our train to Amsterdam by 15 minutes. The delay was in K??ln, because the pope paid a visit - well known to the Deutsche Bahn, but still they didn't do anything about it. We had to use another train which left two hours later. And we didn't get any compensation for this - not even for the reservation for the train we missed. We had a delay of two hours. In The Netherlands you would at least get a significant percentage of your money back. Not in Germany. After all, I think with the frequent trains (compared to Croatia) and reasonable refunds (compared to Germany), the NS isn't that bad after all. > Just don't plan to get anywhere special with public transportation > after 2300h. There are night trains between the big cities in the Randstad. At least in Amsterdam busses go through the city all the night, every night. I don't know about other cities - I live in Amsterdam. > Well politics, in the Netherlands is like politics in the rest of > Western-Europe North-Atlantic-coast countries, excluding UK & > Ireland. Still, we were the first ones to legalize properly executed eutanasia. We were also the first to have official single-sex marriages. I don't know about other countries, but here prostitution is a regular job, so you have to pay taxes as a prostitute, and there is even a union. > Most of the time these politicians are social caring about everybody > in the country including non-voters, non-payers and > fanatic-believers of-whatever-you-can-imagine. That's very true. I'm not too happy about that. Too many people refuse to vote, for just that reason. > Most people in here are non-believers or so lightly believers that > you won't know the difference between them and the non-believers. > The biggest part of the remaining believers are realistic and value > life, moral and norms without compromising public safety, of course > fanatics are every where in the world including the Netherlands. Here in Amsterdam, things are getting more nasty. A writer/critic/actor was killed "in the name of Allah", just because he excercised his freedom of speech. Another man was seriously messed up while standing in his own front door opening, just because he's homosexual. In his street, sometimes people are shouting "Go away you homo, you're not welcome here. This is a Macoccan street!. I'm not discriminating, but Maroccans telling Dutch people they aren't welcome in their own captial? I wish _those_ people would just go back to Marocco. > The only serious downsize is that in the Randstad the house prices > are too high Very true. My girlfriend and I are renting a house in the northern part of Amsterdam, just above Central Station. We had to search quite hard to find that, though! Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From enleverlesO.OmcO at OmclaveauO.com Wed Aug 31 02:16:52 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Wed, 31 Aug 2005 08:16:52 +0200 Subject: trouble with time --again References: <1125423761.517155.162710@g44g2000cwa.googlegroups.com> Message-ID: <43154bd9$0$27047$626a14ce@news.free.fr> Hi ! Try : import datetime date1 = datetime.datetime(2005,01,01,8,20,0) print date1.strftime('%Y-%m-%d %H:%M:%S') @-salutations Michel Claveau From ptmcg at austin.rr.com Fri Aug 12 00:55:06 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 11 Aug 2005 21:55:06 -0700 Subject: How do these Java concepts translate to Python? References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <1123822506.925971.69450@g14g2000cwa.googlegroups.com> Please look through this example code, and the comments. If I've misspoken, please anyone correct my errors. -- Paul class OldStyleClass: """A definition of an old style class.""" pass class NewStyleClass(object): """Note that NewStyleClass explicitly inherits from object. This is what makes it new-style.""" pass class B(object): pass class C(object): pass class A(B,C): """Class A inherits from classes B and C. Since they are new-style, A is new-style, too.""" # this is a class variable of A. classVar = 0 def __init__(self,initArgs=None): """This string documents this routine, which is the initializer for new instances. __init__ is not typically explicitly called (except from subclasses), but is automatically called when creating new instances of class A, as in: aObj = A(initWithThisValue) Since initArgs is declared with a default value, it is also possible to create an object as: aObj = A() and __init__ will be invoked with None as the value of initArgs. """ if initArgs is not None: self.instanceVar = initArgs else: self.instanceVar = 0 @staticmethod def staticMethod(a,b,c): """This is a class-level method. Presumably it has something to do with this class, perhaps as a factory or other utility method. This method is invoked as: A.staticMethod(100, ['A','B'], 3.14159) What makes this a static method is the @staticmethod decorator that precedes the class definition. (Pre-2.4 code would use the form: staticMethod = staticmethod(staticMethod) in place of the @staticmethod decorator.) """ pass @classmethod def classMethod(cls,d,e,f): """This is also a class-level method, but is distinct in that the class is implicitly passed as the first argument, although the caller does not pass the class in. This method looks similar to the static method invocation: A.classMethod(5,'XYZZY',[]) But in this case, the variable cls takes the value of the class used to invoke the method, either A or some subclass of A. """ print cls,type(cls) def instanceMethod(self,g,h,i): """By default, this method is assumed to be an instance method. The first argument in the list is the object's own reference variable - by convention this is near- universally named 'self', although some prefer the variable name '_'. Any variable will do really, such as 'me', 'this', 'I', etc., but it is the first variable in the list. The caller does not explicitly pass this object reference variable in the calling arg list. Invoking instanceMethod looks like: aVar = A() aVar.instanceMethod(1,2,3) """ pass def __hiddenMethod(self,x,y,z): """By the magic of the leading '__' on this method name, this method is not externally visible. It *can* be called from derived classes, though, so it can be thought of as roughly analogous to being a 'protected' method in C++ or Java (although as I recall, 'protected' in Java isn't really all that protected). Leading '__' can also be used to hide instance and class vars, too. """ pass # Here is how you define a class-level variable of A that is of type A. # You could use these to predefine special A variables, as in # simulating an enum, or in creating some common values of a given # class, such as Color.RED, Color.GREEN, etc. A.specialA = A("special") A.unusualA = A("unusual") class G(A): """A subclass of A, used to demonstrate calling a classmethod, and a hidden method.""" pass def tryHidden(self): # call a method defined in the superclass self.__hiddenMethod(4,5,6) # Invoke some class-methods. The first call will pass the class A # as the first arg, the second will pass the class G as the first arg. A.classMethod(1,2,3) G.classMethod(4,5,6) g = G() g.tryHidden() # Allowed g.__hiddenMethod(5,6,7) # Not allowed! From python at hope.cz Fri Aug 12 09:39:05 2005 From: python at hope.cz (Lad) Date: 12 Aug 2005 06:39:05 -0700 Subject: Where can be a problem? In-Reply-To: <ddhhnt$pth$04$1@news.t-online.com> References: <1123827773.392501.155760@z14g2000cwz.googlegroups.com> <ddhhnt$pth$04$1@news.t-online.com> Message-ID: <1123853944.966310.23340@g49g2000cwa.googlegroups.com> Peter, I tried exactly this ######## import re Results=[] data1='<a href="detailaspxmember=15015&mode=advert" </a><a href="detailaspxmember=15016&mode=advert" </a><a href="detailaspxmember=15017&mode=advert" </a>' ID = re.compile(r'^.*=(\d+)&.*$',re.MULTILINE) Results=re.findall(ID,data1) print "Results are= ",Results ######### and received Results are= ['15017'] Not all numbers What exactly did you get? Thanks. L. From ChuckDubya at gmail.com Wed Aug 17 02:24:13 2005 From: ChuckDubya at gmail.com (ChuckDubya at gmail.com) Date: 16 Aug 2005 23:24:13 -0700 Subject: Making programs work together. In-Reply-To: <4302d48e.1666704914@news.oz.net> References: <1124256651.450266.90580@g47g2000cwa.googlegroups.com> <4302d48e.1666704914@news.oz.net> Message-ID: <1124259853.264169.157750@g44g2000cwa.googlegroups.com> Example: I'm driving a car in a game and I hit an oil slick so instead of me having to lift off the throttle button on the keyboard, I want to make a program to disengage the throttle as long as I'm on that oil slick. Does that clear anything up? From mail at tuxipuxi.org Fri Aug 12 09:37:22 2005 From: mail at tuxipuxi.org (Michael Goettsche) Date: Fri, 12 Aug 2005 15:37:22 +0200 Subject: Writing a small battleship game server in Python In-Reply-To: <1123779784.423243.25040@g43g2000cwa.googlegroups.com> References: <200508111746.15668.mail@tuxipuxi.org> <mailman.2988.1123778105.10512.python-list@python.org> <1123779784.423243.25040@g43g2000cwa.googlegroups.com> Message-ID: <200508121537.22818.mail@tuxipuxi.org> On Thursday 11 August 2005 19:03, googlenews at tooper.org wrote: > Why not using directly SOAP ? > > A minimalistic 'Hello world' client looks like : > > from SOAPpy import SOAPProxy > > server= SOAPProxy("http://localhost:8080") > print server.Hello("world") > > and the server side like : > > from SOAPpy import SOAPServer > > def Hello(name): > print "Wishing "+name+" hello !" > return "Hello "+name > > server= SOAPServer(("localhost",8080)) > server.registerFunction(Hello) > server.serve_forever() > > Difficult to make it simpler isn't it ? Thanks to you too and the same question for you. :-) How well will this server work with clients written in other languages/toolkits without the need of installing additional things? for example, does Delphi have a Soap implementation? IIRC Qt doesn't offer one for free. Thanks, Michael From t-meyer at ihug.co.nz Mon Aug 1 19:16:45 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 2 Aug 2005 11:16:45 +1200 Subject: rfc822 module bug? In-Reply-To: <ECBA357DDED63B4995F5C1F5CBE5B1E8037EC325@its-xchg4.massey.ac.nz> Message-ID: <ECBA357DDED63B4995F5C1F5CBE5B1E801B0F827@its-xchg4.massey.ac.nz> [rfc822 module bug] >> Date: Tue,26 Jul 2005 13:14:27 GMT +0200 >> >> It seems to be correct?, but parsedate_tz is not able to >> decode it, it is confused by the absence of a space after >> the ",". [...] > I think I'll submit this bug on the Python web-site. Please don't. The rfc822 module is deprecated from Python 2.3 in favour of the email package. This bug does not exist in the email package (at least in Python 2.4). For example: >>> import rfc822 >>> rfc822.parsedate_tz("Tue, 26 Jul 2005 13:14:27 GMT +0200") (2005, 7, 26, 13, 14, 27, 0, 1, 0, 0) >>> rfc822.parsedate_tz("Tue,26 Jul 2005 13:14:27 GMT +0200") >>> import email >>> import email.Utils >>> email.Utils.parsedate_tz("Tue, 26 Jul 2005 13:14:27 GMT +0200") (2005, 7, 26, 13, 14, 27, 0, 1, 0, 0) >>> email.Utils.parsedate_tz("Tue,26 Jul 2005 13:14:27 GMT +0200") (2005, 7, 26, 13, 14, 27, 0, 1, 0, 0) =Tony.Meyer From fperez.net at gmail.com Fri Aug 19 12:46:34 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Fri, 19 Aug 2005 10:46:34 -0600 Subject: Traceback Questions References: <1124408964.797947.214270@f14g2000cwb.googlegroups.com> Message-ID: <de52db$j3n$1@sea.gmane.org> ncf wrote: > I'm just beginning with tracebacks, building off of what I see in > asyncore's compact_traceback code, in order to hopefully store all the > values from the location in which the exception occured. > > I'm actually trying to make this into a python bug report system for my > current project, and am seeking advice on how to use sys.exc_info()[2] > better (the traceback element) > > Does anyone have any advice on how I'd preform a traceback-based > bugreport-like system? The more I work on this, the more I'm confusing > myself. :\ You may want to look at ipython's CrashHandler system: http://projects.scipy.org/ipython/ipython/file/ipython/trunk/IPython/CrashHandler.py It does all of what you've described in your post automatically. Some of it is ipython-specific, but it should be easy enough to tweake it for your needs. For download links (the above is an SVN source browsing link): http://ipython.scipy.org At some point I should really abstract this out, there seems to be a need for it out there. Cheers, f From bokr at oz.net Sun Aug 7 20:53:42 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 08 Aug 2005 00:53:42 GMT Subject: PEP: Specialization Syntax References: <mailman.2824.1123446062.10512.python-list@python.org> <42F66FF2.7010901@v.loewis.de> <mailman.2825.1123449575.10512.python-list@python.org> Message-ID: <42f690ab.862953731@news.oz.net> On Sun, 07 Aug 2005 17:20:25 -0400, Nicolas Fleury <nidoizo at yahoo.com> wrote: >Martin v. L?wis wrote: >> -1. I don't see the point of this PEP. Apparently, you want to define >> parametrized types - but for what purpose? I.e. what are the specific >> use cases for the proposed syntax, and why do you need to change the >> language to support these use cases? I very much doubt that there are >> no acceptable alternatives for each case. > >Well, I'm using the alternatives. For example, where I work we have >built a small framework to create binary data to be loaded-in-place by >C++ code (it might be presented at next GDC (Game Developer >Conference)). It uses metaclasses and descriptors to allow things like: > >class MyObject(LoadInPlaceObject): > size = Member(Int32) > data = Member(makeArrayType(makePtrType(MyObject2, nullable=True))) > ... > >I know, it's not really Python, but still, defining functions like >makeArrayType and makePtrType is a pain. It is necessary to maintain a >dictionary of types (to avoid redundacy) and simple things like: > >def makeType(someArgument): > class MyObject: > someArgument = someArgument > return MyObject > >are not allowed. So its ends up with something like: I don't understand why you wouldn't give the function arg a different name in the first place instead of via a temporary intermediary binding, e.g., def makeType(someArgument_alias): class MyObject: someArgument = someArgument_alias return MyObject > >__arrayTypes = {} >def makeArrayType(arg1, arg2=someDefault): > if (arg1, arg2) in __arrayTypes: > return __arrayTypes[arg1, arg2] > renamed_arg1 = arg1 > renamed_arg2 = arg2 > class Array: > arg1 = renamed_arg1 > arg2 = renamed_arg2 > ... > __arrayTypes[arg1, arg2] = Array > return Array > Or (untested, using new style class): def makeArrayType(arg1, arg2=someDefault): try: return __arrayTypes[arg1, arg2] except KeyError: __arrayTypes[arg1, arg2] = Array = type('Array',(),{'arg1':arg1, 'arg2':arg2}) return Array (just re-spelling functionality, not understanding what your real use case is ;-) >Does it qualify as an "acceptable alternative"? when it could have been: > >class Array[arg1, arg2=someDefault]: > ... > >I probably should have put this example in the PEP. > >> IOW, whatever it is that you could do with this PEP, it seems you could >> do this today easily. I agree with this, until I see some really persuasive use cases. > >The PEP validity is also very much influenced if optional static typing >is planned to be added to the language. I realize defending this PEP is >much harder without static typing and my use cases imply typing of some >sort anyway. > I'll have to catch up with that. Have been very bogged down for a long while. Regards, Bengt Richter From ray_usenet at yahoo.com Sat Aug 20 03:18:26 2005 From: ray_usenet at yahoo.com (Ray) Date: 20 Aug 2005 00:18:26 -0700 Subject: Please Criticize My Code Message-ID: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> Hello, I just wrote a short script that generates look and say sequence. What do you Python guys think of it? Too "Java-ish"? I can't shake off the feeling that somebody may have done this with 2-3 lines of Python magic. Heh. # generator for sequence def lookAndSaySequence(firstTerm, n): term = str(firstTerm) for i in xrange(n): yield term term = lookAndSay(term) # the method that looks, and says def lookAndSay(number): look_at_this = str(number) say_this = ['0', look_at_this[0]] for digit in look_at_this: if say_this[-1] != digit: say_this.extend(('1', digit)) else: say_this[-2] = str(int(say_this[-2]) + 1) return "".join(say_this) # run it! print [x for x in lookAndSaySequence(1, 30)] Thanks, Ray From yoav_artzi at il.vio.com Thu Aug 25 09:29:44 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Thu, 25 Aug 2005 16:29:44 +0300 Subject: Getting rid of "close failed: [Errno 0] No Error" on Win32 In-Reply-To: <430c6ecb$1@news.bezeqint.net> References: <430c6ecb$1@news.bezeqint.net> Message-ID: <430dc69c$1@news.bezeqint.net> Ok , I tried: try: os.popen3(...) except: as someone suggested here. And on FreeBSD I don't get the error message, and it works great. However, on Win32 I do get the annoying message. Any idea why? And How I can make it go away? thanks. Yoav wrote: > I am using os.popen3 to call a console process and get its output and > stderr. However on Win32 (and not OS X) I also get the Errno message. > It's printed to the screen, which I wish to keep clean. How can disable > this notification? > > Thanks. From luismgz at gmail.com Thu Aug 18 09:29:54 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 18 Aug 2005 06:29:54 -0700 Subject: Python for Webscripting (like PHP) In-Reply-To: <de1kc1$oo9$01$1@news.t-online.com> References: <de1kc1$oo9$01$1@news.t-online.com> Message-ID: <1124371794.875629.38600@g14g2000cwa.googlegroups.com> Mod_python has a PSP (python server pages - ala php) implementation. However it's still not mature enough and, imho, it has a serious drawback in its way to handle indentation. But this is just the first release and I hope it will improve in the near future. My favorite is Karrigell ( http://karrigell.sourceforge.net ). It is a pleasure to work with, minimalistic, simple and to the point. No template language needed, just regular python and html and, as far as I know, mod_python integration is uderway. Hope it helps... Luis From tjreedy at udel.edu Fri Aug 26 21:20:02 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Aug 2005 21:20:02 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk><1124160882.554543.75730@g43g2000cwa.googlegroups.com><m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk><wMOdnW4N1cAeAZneRVn-2g@comcast.com><VoOdnZAkbdDgO5neRVn-hg@comcast.com><EpLNe.824$GV7.650@newssvr25.news.prodigy.net><WZaPe.1953$eQ.899@newssvr30.news.prodigy.com><mailman.3485.1124942826.10512.python-list@python.org><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><slrndgtka9.1qv.apardon@rcpc42.vub.ac.be><vpBPe.549$MN5.241@newssvr25.news.prodigy.net><mailman.37.1125074193.8229.python-list@python.org><7sJPe.573$MN5.131@newssvr25.news.prodigy.net><mailman.43.1125084774.8229.python-list@python.org><7xmzn41ofc.fsf@ruckus.brouhaha.com><mailman.47.1125090294.8229.python-list@python.org> <7xslwwjsft.fsf@ruckus.brouhaha.com> Message-ID: <deof42$ilm$1@sea.gmane.org> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xslwwjsft.fsf at ruckus.brouhaha.com... > "Terry Reedy" <tjreedy at udel.edu> writes: >> The try/except pattern is a pretty basic part of Python's design. One >> could say the same about clutter for *every* function or method that >> raises >> an exception on invalid input. Should more or even all be duplicated? >> Why >> just this one? > > Someone must have thought str.find was worth having, or else it > wouldn't be in the library. Well, Guido no longer thinks it worth having and emphatically agreed that it should be added to one of the 'To be removed' sections of PEP 3000. Terry J. Reedy From vincent at visualtrans.de Tue Aug 2 14:40:08 2005 From: vincent at visualtrans.de (vincent wehren) Date: Tue, 2 Aug 2005 20:40:08 +0200 Subject: py2exe windows apps path question References: <11ev0tcg9n2ndd@corp.supernews.com> <dcoahp$9u9$3@news1.zwoll1.ov.home.nl> <11evdoj8c4brd1b@corp.supernews.com> Message-ID: <dcoema$adr$1@news4.zwoll1.ov.home.nl> "Grant Edwards" <grante at visi.com> schrieb im Newsbeitrag news:11evdoj8c4brd1b at corp.supernews.com... | On 2005-08-02, vincent wehren <vincent at visualtrans.de> wrote: | > | > "Grant Edwards" <grante at visi.com> schrieb im Newsbeitrag | > news:11ev0tcg9n2ndd at corp.supernews.com... | >|I have several python apps (some wxPython, some plain text-mode | >| stuff) that I distribute internally for installation on Win32 | >| machines. They're bundled/installed using py2exe and inno | >| setup. | >| | >| I followed what I think is the normal procedure of installing | >| each app in its own directory under /Program | >| Files/<vendor>/<app>. | >| | >| The problem is that the apps only run if they're started with | >| the install directory as the current working directory. | >| Otherwise they can't find the .dll's they use from the install | >| directory. | > | > AFAIK, Windows normally *does* search the directory where the executable | > module for the current process lives in for dlls. What sort of dlls are | > given you trouble? | | One's a "driver" for a CAN bus USB widget. The other failure | that springs to mind is that gnuplot-py couldn't find something | (could have been an .exe) that was in the app directory. Grant, If you are building paths in you code that are relative to your app, please see my reply to Greg's post. If not, you may as a workaround want to try to add the frozen application's directory to the system path environment variable. Windows will look for dlls there, too. To get the app's actual location, you will need something like the getAppPrefix() function as per my reply to Greg's reply. The getAppPrefix() function will also hold when the user adds your frozen app to his/her system path and call the app from any location from the command line - sys.argv[0] just won't do the trick in such a setting. HTH, -- Vincent Wehren | | -- | Grant Edwards grante Yow! HUGH BEAUMONT died | at in 1982!! | visi.com From oren.tirosh at gmail.com Tue Aug 23 02:39:16 2005 From: oren.tirosh at gmail.com (Oren Tirosh) Date: 22 Aug 2005 23:39:16 -0700 Subject: How to get a unique id for bound methods? References: <rowen-A3BA2B.13291919082005@gnus01.u.washington.edu> Message-ID: <1124779156.078049.25830@g47g2000cwa.googlegroups.com> Russell E. Owen wrote: > I have several situations in my code where I want a unique identifier > for a method of some object (I think this is called a bound method). I > want this id to be both unique to that method and also stable (so I can > regenerate it later if necessary). >>> def persistent_bound_method(m): ... return m.im_self.__dict__.setdefault(m.im_func.func_name, m) ... >>> class A: ... def x(self): ... return ... >>> a=A() >>> a.x is a.x False >>> persistent_bound_method(a.x) is persistent_bound_method(a.x) True >>> From leonhard.vogt at gmx.ch Tue Aug 2 12:33:31 2005 From: leonhard.vogt at gmx.ch (Leonhard Vogt) Date: Tue, 02 Aug 2005 18:33:31 +0200 Subject: time.clock() or time.time() In-Reply-To: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> References: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> Message-ID: <42efa05d_1@news.bluewin.ch> peterbe at gmail.com schrieb: > What's the difference between time.clock() and time.time() > (and please don't say clock() is the CPU clock and time() is the actual > time because that doesn't help me at all :) clock (depending on the platform ?) measures the time spent by your program. Time gives you the system time, so the difference is the time between your calls, your program could have been idle (waiting for input or sharing processor due to multitasking) > I'm trying to benchmark some function calls for Zope project and when I > use t0=time.clock(); foo(); print time.clock()-t0 > I get much smaller values than when I use time.clock() (most of them > 0.0 but some 0.01) Run your code 100 times and divide the result by 100. Leonhard From adamtj at adamtj.org Sun Aug 28 19:34:37 2005 From: adamtj at adamtj.org (Adam Tomjack) Date: Sun, 28 Aug 2005 18:34:37 -0500 Subject: trictionary? In-Reply-To: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> References: <mailman.101.1125267629.8229.python-list@python.org> <0LOdnYjsqqd-24_eRVn-1w@comcast.com> Message-ID: <43124A0D.50405@adamtj.org> Steven Bethard wrote: ... > Using a two element list to store a pair of counts has > a bad code smell to me. ... Why is that? It strikes me as the cleanest way to solve that problem, as long as it's easy enough to figure out what each element really represents. You could name each element, but for a block of code eight lines long, doing anything more descriptive would be too verbose. Adam From cliff at develix.com Mon Aug 1 17:37:41 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 14:37:41 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <7xek9djr76.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <mailman.2438.1122791233.10512.python-list@python.org> <7xd5ozv1ng.fsf@ruckus.brouhaha.com> <mailman.2467.1122835539.10512.python-list@python.org> <7xek9e5ywq.fsf@ruckus.brouhaha.com> <mailman.2495.1122858673.10512.python-list@python.org> <mark-CECC3A.15265501082005@news.isp.giganews.com> <mailman.2570.1122929447.10512.python-list@python.org> <7xek9djr76.fsf@ruckus.brouhaha.com> Message-ID: <1122932261.19618.383.camel@localhost.localdomain> On Mon, 2005-08-01 at 14:13 -0700, Paul Rubin wrote: > Cliff Wells <cliff at develix.com> writes: > > Still, that leaves Linux and Mac out in the cold. But I'll admit you > > met my challenge. Most likely you can actually do most of the things > > with Tk you can with Wx, it's simply a matter of how much effort is > > going to be (for instance, it's certainly quite possible to embed Gecko > > in Tk, but I for one am not likely to be up to the task). > > I actually misunderstood your question about embedding a browser and > thought for a while about what it would take to write or port a > serious browser to use tkinter as its graphics layer. The resulting > picture wasn't pretty. I wonder whether it's feasible in wxpython. wxPython has a toy HTML renderer that allows embedding wxPython widgets directly into it. If you only need simple HTML it works great. It is also possible to embed IE, Safari and Mozilla (via wxMozilla) but you lose the ability to embed the wxPython widgets). > I like the idea of a browser-like portable gui toolkit. Instead of > merely wrapping some other widget set, you'd write your interface as > an XML file using HTML-like interface elements. You'd have callbacks > on the form submit buttons and optionally on the other input elements, > and you could get at the elements through the XML DOM if you were so > inclined (sort of like the HTML DOM that browsers expose through > Javascript). Implementations could run on top of Tk, GTK, native > Windows widgets, or whatever. Actually wxPython has this today (and has had for some time): you can build your interface code in XML and wxPython will build the interface on the fly. I played with it once as a method of building a dialog editor along the lines of VB, but the project I needed it for died and I didn't have time to finish. My discovery was that it was entirely doable though, had I had time to finish. In fact, with the XRC stuff in wxPython, you can even create custom controls with pure XML. I'm not sure how great this is for hand-built interfaces (but I haven't tried), but it seems ideal for automated generation of GUI's. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From lycka at carmen.se Mon Aug 22 08:02:45 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 22 Aug 2005 14:02:45 +0200 Subject: sending binary files to a 16 micro controller. In-Reply-To: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> Message-ID: <decet5$dm7$1@wake.carmen.se> johnny.karlsson at gmail.com wrote: > Hi, I'm working on a project were a need to be able to upload firmware > to a microcontroller based Ethernet device. But because of the memory > constraints the controller can only handle packages of 300 bytes each > time. So therefore the firmware file must be sent in chunks and i need > a header in each file describing which part of the file it is I'm > sending. Could anyone give me some pointer on how a could accomplish > that in python? I'm talking about the client that uploads the software > to the device via TCP. You can probably start here: http://docs.python.org/lib/socket-example.html If you're uncertain about the exact content of the transmitted messages, and has access to some other client program, you could write a Python server and see exactly what bit pattern the other client sends. Then you can write a Python client that behaves the same way. The basic pattern to split and transmit your file would probably be something like: f = open('filename') header_template = 'Chunk %05i, %03i bytes' for i, bytes in enumerate(f.read(max_number_of_bytes_per_chunk)): msg = header_template % (i, len(bytes)) msg += bytes sock.send(msg) sock.send('The end!') From leszczynscyATnospam.yahoo.com.nospam Tue Aug 9 19:36:56 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Tue, 09 Aug 2005 18:36:56 -0500 Subject: Python supports LSP, does it? Message-ID: <hJSdnSuJuKa5oWTfRVn-gw@comcast.com> wikipedia (http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming) says: """ Python's support for object oriented programming paradigm is vast. It supports polymorphism [...] fully in the Liskov substitution principle-sense for all objects. """ Just wondering if it is true statement. Is not LSP more a quality of the desing of class hierachy rather then language itslef? Comments? AndyL From ehooren at gmail.com Sun Aug 21 19:04:37 2005 From: ehooren at gmail.com (Dragonfly) Date: Mon, 22 Aug 2005 01:04:37 +0200 Subject: Python dutch Message-ID: <4e7ed7e9050821160448c09354@mail.gmail.com> hi, Do you have a python lesson book in dutch version on your site? greetz erik =) From ccurvey at gmail.com Thu Aug 11 09:42:23 2005 From: ccurvey at gmail.com (Chris Curvey) Date: 11 Aug 2005 06:42:23 -0700 Subject: client server question In-Reply-To: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> References: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> Message-ID: <1123767743.583123.50710@o13g2000cwo.googlegroups.com> import threading import logging ###################################################################### class Reader(threading.Thread): def __init__(self, clientsock): threading.Thread.__init__(self) self.logger = logging.getLogger("Reader") #----------------------------------------------------------------- def run(self): self.logger.info("New child %s" % (threading.currentThread().getName())) self.logger.info("Got connection from %s" % (clientsock.getpeername())) #################################################################### # set up a socket to listen for incoming connections from our clients s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host, port)) s.listen(1) while True: try: clientsock, clientaddr = s.accept() except KeyboardInterrupt: raise except: traceback.print_exc() continue client = Reader(clientsock) client.setDaemon(1) client.start() From mandus at gmail.com Wed Aug 3 15:12:47 2005 From: mandus at gmail.com (Mandus) Date: Wed, 3 Aug 2005 19:12:47 +0000 (UTC) Subject: pain References: <mailman.2668.1123083842.10512.python-list@python.org> Message-ID: <slrndf25pc.3m7.mandus@phulius.simula.no> Wed, 03 Aug 2005 17:45:34 +0200 skrev Mage: > Hello, > > I started to learn python some months ago. Mostly for fun, but I > replaced php to python in many tools at my company in the last weeks. > > Because of our boss decision now I have to learn java. I can tell java [snip] maybe you can use jython, and tell your boss it's Java. A boss forcing people to learn and use Java probably have no interest at all ever read the code himself, so you will probably get away with it. I mean, a clueless boss... or just find another place to work? Don't code Java, be happy :-) mvh, -- Mandus - the only mandus around. From bill.mill at gmail.com Mon Aug 22 13:57:57 2005 From: bill.mill at gmail.com (Bill Mill) Date: Mon, 22 Aug 2005 13:57:57 -0400 Subject: loop in python In-Reply-To: <20050823101056.GA25131@mrna.tn.nic.in> References: <mailman.3362.1124726899.10512.python-list@python.org> <d_adnWwgVZOcYZTeRVn-gA@powergate.ca> <20050823101056.GA25131@mrna.tn.nic.in> Message-ID: <797fe3d405082210573ad35ff3@mail.gmail.com> They come out even in the computer language shootout: http://shootout.alioth.debian.org/benchmark.php?test=all&lang=python&sort=fullcpu (tied 8-8 in execution time, although perl wins 4-12 on memory consumption) Peace Bill Mill On 8/23/05, km <km at mrna.tn.nic.in> wrote: > Hi all, > > > thing. If *all* your loops are going to do is print stuff, then you're > > doing the right thing with the version that "emits values". > > ya most of the loops print values. > > > know this). Since you haven't got any working code, it's not possible > > that you *need* whatever negligible speed difference there might be > > between Python and Perl. > > > > Python, don't let your first attempts at benchmarking dissuade you. > > Really, trust us. > > ya i do. > > > Python's strengths lie in four things: the readability of the code, the > > huge range of library modules available, the elegance of its object > > oriented constructs, and the helpfulness of its community. Raw speed is > > not one of its strengths, but there are tens of thousands of people > > using it quite effectively and without daily concern for its speed (same > > as Perl, by the way since, again, they are _not_ significantly different > > in speed no matter what an empty loop test shows). > > I agree that python emphasizes on readability which i didnt see in many of the languages, but when the application concern is speed, does it mean that python is not yet ready? even most of the googling abt python vs perl convince me that perl is faster than python in most of the aspects. Also the first thing any newbie to python asks me is abt "raw speed in comparison with similar languages like perl" when i advocate python to perl. > > > regards, > KM > -- > http://mail.python.org/mailman/listinfo/python-list > From bearophileHUGS at lycos.com Sat Aug 20 05:01:55 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 20 Aug 2005 02:01:55 -0700 Subject: Please Criticize My Code References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> Message-ID: <1124528515.710074.282200@z14g2000cwz.googlegroups.com> Two versions of mine, one of the fastest (not using Psyco) and one of the shortest: . from itertools import groupby . . def audioactiveFast(n): . strl = {("1","1","1"): "31", ("1","1"): "21", ("1",): "11", . ("2","2","2"): "32", ("2","2"): "22", ("2",): "12", . ("3","3","3"): "33", ("3","3"): "23", ("3",): "13" } . result = [1] . prec = "1" . for i in xrange(n-1): . prec = "".join( strl[tuple(l)] for e,l in groupby(prec) ) . result.append( int(prec) ) . return result . . . def audioactiveShort(n): . s = [1] . for i in xrange(n-1): . r = 0 . for e,l in groupby(str(s[-1])): . r = r*100 + len(list(l))*10 + int(e) . s.append( r ) . return s Bye, bearophile From zen19725 at zen.co.uk Wed Aug 3 14:48:00 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 19:48:00 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> <slrndeu5ia.d1.zen19725@cabalamat.somewhere> <dcnisi$ks6$1@nntp0.reith.bbc.co.uk> <slrndf1b11.129.zen19725@cabalamat.somewhere> <dcqrtt$rqj$1@nntp0.reith.bbc.co.uk> Message-ID: <slrndf24au.2je.zen19725@cabalamat.somewhere> On Wed, 03 Aug 2005 16:57:34 +0100, Michael Sparks <michaels at rd.bbc.co.uk> wrote: > >> Is the audience programmers or >> less technical people? A project that allows non-technical people >> to build complex network applications is an ambitious one, but not >> impossible (I'd find it very impressive and very exciting, >> particularly if it runs on devices such as mobile phones). > >It's a little ambitious at this stage, yes. But it couldbe there eventually? >>> * Ogg Vorbis streaming server/client systems (via vorbissimple) >>> * Simple network aware games (via pygame) >>> * Quickly build TCP based network servers and clients >> >> What sort of servers and clients? > >Whatever you feel like. If you want a server to split and serve audio, >you could do that. This is streaming audio, right? For non-streaming I can just use an ftp or http server. >>> * Quickly build Multicast based network servers and clients >> Serving what? Could I use it, for example, to build an n-player >> encrypted VoIP server to allow people to do conference calls over >> the Internet? > >You could do that probably. (Though we don't have a component >for audio capture (though a read file adaptor reading from /dev/audio >might work depending on your platform I suppose) and audio >encoding at the moment, so those would probably be the core >components to integrate. That's a slightly worrying answer for me, worrying because it seems I've misunderstood the nature of the project. I assumed that components for audio capture, and related activities, would be at the heart of the project. > If you want to use multicast over the wide >area internet you'd also have to convince all the people using the >system to use ISPs that support multicast......) (or just sent the signal out multiple times) >> (I mean proper encryption here, the sort GCHQ or the NSA can't break) > >I'd be impressed if that could be written, using anything really. (Can't >implies never) What -- good encryption? That's pretty much a well-known technique these days (unless the NSA has some *very* advanced hardware in their basement, which I strongly suspect they don't). >>>The basic underlying metaphor of a component us like an office worker >>>with inboxes and outboxes, with deliveries occuring between desks, > >> That metaphor brings up an image (at least to me) that the sorts of >> data that can be communicated are things like documents, >> spreadsheets, business graphs, memos. > >They could indeed. The underlying framework doesn't differentiate >between data nor have any realtime aspect embedded in the system >at present. Just because we're focussing on systems that have a realtime >element and are multimedia based, this does not mean the system is >limited to that. Again, this makes me think I've misunderstood the project. >> OK, I get the straming part of it. But what asbout non-streaming >> stuff? What other protocols are necessary? > >One example is peer to peer mesh setup. People normally >think of P2P as a distribution mechanism. However, the underlying >approach also very good at setting up communications meshes. When you say a mesh, what do you mean? >This could be of use in many areas, such as GRID based systems >for distributed rendering, application layer multicast, and network >multicast island joining. Unpack, please. >Due to the illegal /uses/ of P2P, much work in this area is difficult to >reuse due to defensive coding. Oh. Could you give an example? >We also have to be able to demonstrate system to other people >inside the BBC in a way non-technical people understand. That means >showing structures in a friendly dynamic way, showing pictures, >playing sounds (hence visualisation - looking inside running systems). Visualisation, if done properly, ought to be useful to technical people too. >That means we need ways of integrating with systems like pygame & >other toolkits. If however I'm talking outside the BBC I'll try to give >examples which people might find interesting - such as building a >presentation tool. The blocks are very much like Lego & K'Nex and >adding in a new block enables all sorts of new applications. That's kind of the impression that I've got. >For example, we could take the text ticker, combine that with a text >feed and have a personal autocue/teleprompter. Alternatively someone >could use it to have subtitles (say) at the opera displayed on a Nokia >770 (maemo) based device. That would be useful. Or you could have subtitles in different languages, and the user gets to choose which one to display... -- Email: zen19725 at zen dot co dot uk From ray_usenet at yahoo.com Sun Aug 21 22:02:19 2005 From: ray_usenet at yahoo.com (Ray) Date: 21 Aug 2005 19:02:19 -0700 Subject: Please Criticize My Code In-Reply-To: <1124656679.384400.65220@z14g2000cwz.googlegroups.com> References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> <1124557167.256292.61220@g44g2000cwa.googlegroups.com> <haydnWlFkrnECpreRVn-og@rcn.net> <1124656679.384400.65220@z14g2000cwz.googlegroups.com> Message-ID: <1124676139.911635.159910@g47g2000cwa.googlegroups.com> Christoph Rackwitz wrote: > Why not? Because the regex isn't compiled? > Don't tell me not to do something, tell me why i should'nt do it. No it's not the regex, it's because you just spoiled the challenge for everybody who hasn't solved level 10 yet... From fertig at cstreetsearch.com Mon Aug 29 18:28:11 2005 From: fertig at cstreetsearch.com (amf) Date: 29 Aug 2005 15:28:11 -0700 Subject: networking Message-ID: <1125354491.054233.316330@f14g2000cwb.googlegroups.com> I'm seeking learn more about Python, and specifically to talk with people in the greater Boston, MA area. Can anyone suggest the best way to do this? Feel free to contact me offline: fertig at cstreetsearch.com Amf From martin.witte at gmail.com Wed Aug 10 16:56:02 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 10 Aug 2005 13:56:02 -0700 Subject: providing arguments to base.__init__ In-Reply-To: <dddntt$7m9$1@news2.rz.uni-karlsruhe.de> References: <dddntt$7m9$1@news2.rz.uni-karlsruhe.de> Message-ID: <1123707362.092468.165280@g44g2000cwa.googlegroups.com> I only have an answer to the last one: you do not call the 'destructors' of the base classes, so they are not executed. From EP at zomething.com Thu Aug 4 04:17:33 2005 From: EP at zomething.com (EP) Date: Thu, 4 Aug 2005 00:17:33 -0800 Subject: Dabo in 30 seconds? In-Reply-To: <dcqve4$qvs$1@sea.gmane.org> References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <200508010830.27322.ed@leafe.com> <dclgn7$kja$1@sea.gmane.org> <200508011220.41469.ed@leafe.com> <dcob6m$cl0$1@sea.gmane.org> <42EFB4CF.5070205@ulmcnett.com> <dcqve4$qvs$1@sea.gmane.org> Message-ID: <20050804001733.1289796339.EP@zomething.com> > But it would be a nice enhancement to add the option for auto-emailing > in case > of trouble. > I like still like e-mail notices (it has a nice format we are used to as we use to communicate other things, and you can parse the text easily)... but I wonder: given the spam / virus induced sensitivity to mail servers, does it make more sense to send a text message to a db on the developer's server? Has anyone got some open source code to do something like that handy? /EP From bill.pursell at gmail.com Wed Aug 10 18:40:22 2005 From: bill.pursell at gmail.com (bill) Date: 10 Aug 2005 15:40:22 -0700 Subject: signals (again) Message-ID: <1123713622.727375.206270@f14g2000cwb.googlegroups.com> I see this (or similar) question occasionally looking back through the archive, but haven't yet seen a definitive answer, so I'm going to ask it again. Consider the following: while True: do_something_to_files_in_directory(fd) fcntl(fd, F_NOTFIY, DN_CREATE) signal.pause() How do you deal with the signal that occurs after the fcntl and before the pause? The solution to sleep instead of pause is aesthetically ugly and doesn't really help. I've thought about examining the stack trace in the signal handler for SIGIO and responding appropriately, but that's pretty ugly too. I saw some mention of implementing a try: construct that would delay receipt of the signal for one atomic python instruction, and that seemed like a good idea, but I didn't see much follow up on that. What's the pythonic thing to do here? How can I guarantee timely response to the creation of a file in the directory referenced by fd? From rkern at ucsd.edu Wed Aug 3 04:36:37 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 03 Aug 2005 01:36:37 -0700 Subject: distutils package_dir newbie In-Reply-To: <1123057785.888610.204630@g44g2000cwa.googlegroups.com> References: <1123055950.708133.66580@g49g2000cwa.googlegroups.com> <mailman.2660.1123056916.10512.python-list@python.org> <1123057785.888610.204630@g44g2000cwa.googlegroups.com> Message-ID: <dcpvms$tn4$1@sea.gmane.org> peter wrote: > thx for answering is such short notice. > > I recieve the following error when I use your setup: > error: package directory 'project_user' does not exist > (the complete error is added at the end of this document) > > I'm using python 2.3.5 (build by activeState) based on python 2.3.5 > > Do you have an idea what could have happened here? No. Works just fine on Python 2.3.5 on OS X. Did you copy-and-paste the setup.py file I gave? or did you type it yourself? Could you please give the full setup.py that you used? (And please do some kind of quoting of the message you are responding to.) -- 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 fakeaddress at nowhere.org Tue Aug 9 19:46:22 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 09 Aug 2005 23:46:22 GMT Subject: Putting function references in a Queue In-Reply-To: <1mh1u4qoeju2f.1suxwcnapp086$.dlg@40tude.net> References: <1mh1u4qoeju2f.1suxwcnapp086$.dlg@40tude.net> Message-ID: <ifbKe.3664$zr1.1060@newssvr13.news.prodigy.com> Richard Townsend wrote: > I've been experimenting putting a reference to a function into a Queue > object and was wondering what actually gets put in the Queue - is it the > function's code object? It's a Python-internal-reference-thingy. > If I read from the Queue in a different module, it appears that I don't > need to import the module that defines the function - or any module that it > uses - is this generally true, or are there some conditions to be aware of? Yes, generally true. It has to be implemented somewhere in the process; the reference-thingy knows where. > The scenario I'm working on has child threads doing some tasks and then > sending back tuples (done, function, args, kwargs) via the Queue, to be > called in the main thread. The Python code is ultimately embedded in a > C/Motif app. I think that's a good thing to do. The tricky part is getting an event loop to wait on both the queue and other kinds of events. Periodic polling works, but kind of sucks. What's the 'done' argument? A lock maybe? -- --Bryan From paschott at no.yahoo.spamm.com Wed Aug 17 15:30:51 2005 From: paschott at no.yahoo.spamm.com (Peter A. Schott) Date: Wed, 17 Aug 2005 19:30:51 GMT Subject: Python & SQL Server DTS? Message-ID: <k447g15efosp5rtc1v9mrtfe7udic5b77n@4ax.com> Got a strange issue here. I know that MS allows other scripting languages to run in its ActiveX tasks in DTS. I can change one of the tasks to run Python code, create a Main function, and run it manually. However, once I try to run the entire package, the package hangs at this step. It doesn't appear to even start to execute. I've added code in my function to raise a message box using the win32 extensions. They work when I run the task manually, but none appear when I run it as part of the package. Anyone experienced this? Anyone worked with Python & DTS before? Any suggestions? Thanks in advance. -Pete Schott From onurb at xiludom.gro Thu Aug 25 14:54:15 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 25 Aug 2005 20:54:15 +0200 Subject: variable hell In-Reply-To: <1124983927.323716.97340@g43g2000cwa.googlegroups.com> References: <430dc538@127.0.0.1> <mailman.3504.1124977389.10512.python-list@python.org> <1124983927.323716.97340@g43g2000cwa.googlegroups.com> Message-ID: <430e13d9$0$27051$626a14ce@news.free.fr> sp1d3rx at gmail.com wrote: > Hey, if the man wants to write it that way, let the man write it that > way. If it works for him, great... he's sure confused the heck out of > all of us, and that translates into job security for him! As you can > see, the name of the post is 'variable hell' and that is exactly what > he is creating, so "Adriaan Renting", excellent response! > http://mindprod.com/jgloss/unmain.html -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From mwm at mired.org Fri Aug 19 23:06:19 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 19 Aug 2005 23:06:19 -0400 Subject: global interpreter lock References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> Message-ID: <86fyt5b93o.fsf@bhuda.mired.org> Bryan Olson <fakeaddress at nowhere.org> writes: > I don't see much point in trying to convince programmers that > they don't really want concurrent threads. They really do. Some > don't know how to use them, but that's largely because they > haven't had them. I doubt a language for thread-phobes has much > of a future. The real problem is that the concurrency models available in currently popular languages are still at the "goto" stage of language development. Better models exist, have existed for decades, and are available in a variety of languages. It's not that these languages are for "thread-phobes", either. They don't lose power any more than Python looses power by not having a goto. They languages haven't taken off for reasons unrelated to the threading model(*). The rule I follow in choosing my tools is "Use the least complex tool that will get the job done." Given that the threading models in popular languages are complex and hard to work with, I look elsewhere for solutions. I've had good luck using async I/O in lieue of theards. It's won't solve every problem, but where it does, it's much simpler to work with. <mike *) I recently saw a discussion elsehwere that touched on almost the same topic, lamenting that diagnostic tools in popular programming languages pretty much sucked, being at best no better than they were 30 years ago. The two together seem to indicate that something is fundamentally broken somewhere. -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From gregpinero at gmail.com Tue Aug 9 10:53:15 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 9 Aug 2005 10:53:15 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) Message-ID: <312cfe2b0508090753531e12de@mail.gmail.com> Hey guys, would someone mind giving me a quick rundown of how references work in Python when passing arguments into functions? The code below should highlight my specific confusion: <code> bool1=True lst1=[1,2,3] def func1(arg1): arg1.append(4) def func2(arg1): arg1=False >>func1(lst1) >>lst1 [1,2,3,4] >>func2(bool1) >>bool1 True </code> Why does my list variable get changed for the rest of the program, but my boolean variable doesn't. What am I not understanding? -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From nephish at xit.net Thu Aug 18 04:47:28 2005 From: nephish at xit.net (nephish at xit.net) Date: 18 Aug 2005 01:47:28 -0700 Subject: question about binary and serial info In-Reply-To: <1124344877.985737.40510@g44g2000cwa.googlegroups.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <1124337614.259032.4970@g14g2000cwa.googlegroups.com> <1124339226.523475.257400@z14g2000cwz.googlegroups.com> <1124344877.985737.40510@g44g2000cwa.googlegroups.com> Message-ID: <1124354848.599569.78070@z14g2000cwz.googlegroups.com> this is exactly what i need. i have not previously had a need for this kind of thing, but i sure need some documentation for it now. is there a resource out there to find out how to convert decimal number to a byte, a byte to a decimal and more about the & operator? i really appreciate this info. this is exactly what i was looking for. shawn From cliff at develix.com Mon Aug 1 16:54:58 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 13:54:58 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <7xirypjsua.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <mailman.2456.1122818669.10512.python-list@python.org> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <mailman.2458.1122823396.10512.python-list@python.org> <7xvf2rync2.fsf@ruckus.brouhaha.com> <mailman.2540.1122906282.10512.python-list@python.org> <7x1x5do2da.fsf@ruckus.brouhaha.com> <mailman.2567.1122927657.10512.python-list@python.org> <7xirypjsua.fsf@ruckus.brouhaha.com> Message-ID: <1122929698.19618.373.camel@localhost.localdomain> On Mon, 2005-08-01 at 13:38 -0700, Paul Rubin wrote: > Peter Decker <pydecker at gmail.com> writes: > > We were discussing your 'enormous pain' installing wxPython. I find it > > interesting that you selectively quoted part of one line of my post, > > Yes, the one line I quoted was the one that said most people have > wxPython installed, which is a preposterous claim. The reason they > don't have it installed is they don't have reason to go through the > hassle of installing it, given (among other things) that tkinter is > already there. If they don't want to go through that hassle, I don't > see why I should want to go through it. I seriously hope you are being intentionally obtuse, otherwise your difficulties with wxPython have acquired a sharply illuminated source. It was quite clear that by saying "most people" he was not referring to the set of "most Python users", but rather the set of "most people who have tried wxPython". Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From tjreedy at udel.edu Mon Aug 22 21:15:51 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Aug 2005 21:15:51 -0400 Subject: loop in python References: <mailman.3362.1124726899.10512.python-list@python.org><d_adnWwgVZOcYZTeRVn-gA@powergate.ca><mailman.3366.1124732215.10512.python-list@python.org> <dedgo7$mru$1@online.de> Message-ID: <dedtc7$p0i$1@sea.gmane.org> "Benjamin Niemann" <pink at odahoda.de> wrote in message news:dedgo7$mru$1 at online.de... > km wrote: > >> Hi all, >> >>> thing. If *all* your loops are going to do is print stuff, then you're >>> doing the right thing with the version that "emits values". >> >> ya most of the loops print values. > > In that case, you are interested in IO performance. The time spent > handling > the loop is not significant compared to the time spent executing the > 'print' statement - which is a very complex operation despite its simple > usage. > > An implementation where a simple control flow structure has an measurable > impact on the overall timing of an IO bound program would really > suprising. > Python suprises me often, but in different ways ;) > > Perhaps you could try to use sys.stdout.write() directly, avoiding the > overhead of 'print'. Perhaps there are differences between the (default) > output buffering settings of perl and python. According to postings some years ago, the perl folks have worked specially hard to speed I/O, even to the point of replacing or rewriting some of the C stdio library, at least for some systems. Hence, at that time, Perl was expected and known to be noticeably faster than Python on such systems. Since then, Python I/O has been sped up to at least make better use of stdio, so the gap may be less. This suggests to me: 1. One should not generalize to other aspects of computation. If, for instance, Python got Numerical Python before Perl got the equivalent, then it would have been multiples faster at numerical computation. 2. One should compare the lastest with the lastest to compare the results of catch up with stay ahead efforts. 3. One should test computations that are relevant to the question being asked. Python I/O speedups were aimed at 'for line in somefile: ...' and equivalent outputs, not in quickly writing thousands or millions of characters one at a time. Terry J. Reedy From http Sun Aug 7 05:42:43 2005 From: http (Paul Rubin) Date: 07 Aug 2005 02:42:43 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <mailman.2810.1123403537.10512.python-list@python.org> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> Message-ID: <7xoe8a6q24.fsf@ruckus.brouhaha.com> bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: > I don't see why the things you talk about would have to be part of the > main Python distribution. Ruby on Rails seems to do pretty well without > being included with the core language. I haven't used Ruby on Rails but from the description I saw, its distro includes everything needed, which I assume includes Ruby itself. > There's already a pretty successful programming framework for Python > (Zope), and I don't see why people wouldn't be able to put something > like that together to compete on more equal terms with Ruby on Rails, or > Delphi, &c. I have the impression that Zope is ungodly complex, and revolves around a weird and nonstandard database instead of having an SQL interface. > If you want the whole of the Python community to start developing stuff > for one particular GUI toolkit, I think you'll have much more success by > just making a really good GUI toolkit, than trying to force people to > use it by standardising it. (Which I think is shown by the proliferation > of GUI toolkits other than Tkinter.) Actually that proliferation is one of the culprits in Python being a pain to deal with. I'm personally not a GUI fetishist and Tkinter has been good enough for the client-side GUI's I've needed to write (I'm more web-oriented most of the time). But the reason for that proliferation is other people are dissatisfied with Tkinter. That by itself says the stdlib is lacking. > In short, when you have your one-click-install Pythonic IDE > extravaganza, I'm sure people will download it, whether or not they can > do it on python.org. There's already a Python IDE (Idle) included with the Python distro; its problem is that its limited in functionality and it's buggy. Anyway, I'm a Python user, not an evangelist. As a user I'm happy to have Python and am thankful to its authors, even though (like anything else) it's a long way from being perfect. But I do get annoyed by evangelists who make unsupportable claims that the product doesn't live up to. From pink at odahoda.de Wed Aug 10 07:46:59 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 10 Aug 2005 13:46:59 +0200 Subject: Help with Regular Expressions References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> <mailman.2923.1123671847.10512.python-list@python.org> <1123673219.653144.265270@f14g2000cwb.googlegroups.com> <1123673507.271664.146180@g49g2000cwa.googlegroups.com> Message-ID: <ddcpbg$37j$1@online.de> Harlin Seritt wrote: > Forgive another question here, but what is the 'r' for when used with > expression: r'\w+...' ? r'..' or r".." are "raw strings" where backslashes do not introduce an escape sequence - so you don't have to write '\\', if you need a backslash in the string, e.g. r'\w+' == '\\w+'. Useful for regular expression (because the re module parses the '\X' sequences itself) or Windows pathes (e.g. r'C:\newfile.txt'). And you should append a '$' to the regular expression, because r"\w+@\w+\.\w+" would match 'foo at example.com-+*junk', too. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From daniel.dittmar at sap.corp Mon Aug 1 11:46:38 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Mon, 01 Aug 2005 17:46:38 +0200 Subject: Dabo in 30 seconds? In-Reply-To: <8ur1s2-r5t.ln1@strongwill.g2ctech> References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <mailman.2532.1122901180.10512.python-list@python.org> <dclb4i$24l$1@news.sap-ag.de> <8ur1s2-r5t.ln1@strongwill.g2ctech> Message-ID: <dclg4t$54o$1@news.sap-ag.de> Jorge Godoy wrote: > Daniel Dittmar wrote: > > >>To be fair to those slothes: some of them want to write software for a >>commercial setting where they have to install it on other peoples >>machines. So it isn't just getting it to work one one own's machine. >>Using a specifc Python library with external dependencies means also >>installing and *supporting* it on a possible large set of configurations. > > > I see no problem with that. Specially since there are lots of ways to share > directories on a network installation. You install it once and it's done. > Some on Windows, some on one Linux, some on another Linux with a newer GTK, some want it on their laptops to work on the road ... Daniel From dacut at kanga.org Mon Aug 1 23:37:24 2005 From: dacut at kanga.org (David Cuthbert) Date: Mon, 01 Aug 2005 23:37:24 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <mailman.2526.1122899437.10512.python-list@python.org> References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <mailman.2526.1122899437.10512.python-list@python.org> Message-ID: <WLednYMVO9zqd3PfRVn-jg@comcast.com> Ed Leafe wrote: > Should we have defensive code for every possible broken installation? We use > a lot of the Python standard library modules, many dbapi-compliant modules, > and, of course, wxPython. If someone mis-installs one of the pre-requisites, > do you expect Dabo to catch that and present you with a diagnostic message? > I'm serious here: I want to know what people consider acceptable for a > software package that relies on other packages. Every possible broken installation != checking for missing dependencies. It can be difficult/cumbersome/result in code bloat to constantly check for module A, feature B enabled in module C, etc. Further, you're certainly going to miss some at first. But as bug reports come in (like this one), add them to a list of checks performed in a checkconfig script. This script can be run at installation and/or by the user when something like this goes wrong. You could also have checkconfig print out useful features about the environment it's running in to help make bug reports better. Building something like this takes time, but every minute spent on it now is 10-20 minutes saved in handling the same old bug report in the future. From johan at pulp.se Tue Aug 2 13:33:05 2005 From: johan at pulp.se (Johan Lindberg) Date: 2 Aug 2005 10:33:05 -0700 Subject: finding sublist References: <1122991014.595476.5740@g47g2000cwa.googlegroups.com> Message-ID: <1123003985.735221.119630@g44g2000cwa.googlegroups.com> Hello. > my target is implement a function controlla(string - a binary string-) > that check if there is in a string two equal not overlapping > subsequences at least of length limitem: > > my code: > [snip] > I may have misunderstood it, but does your function work the way you want it to? >>>controlla("testeststest") no I can't get it to print anything other than "no". But then again, I'm reading and posting via Google and I guess all those break statements shouldn't be on the same indent-level. > the question is: Is there a faster way doing that? I don't know, > changing string into list or array, using map, or module, using > different loop, regular expression,funcional programming , list > comprehensions , sets, different looping techniques, i dont > know.......(!) Since you're using nested for loops when searching the string you should make sure not to perform more iterations than neccessary. The function below returns a list of all, non-overlapping, substrings in text where len(substring)>= minLength. The outer loop is limited to about half of the length of the text which is where most of the speed comes from but I'm sure it can be tweaked for more. def foo(text, minLength): result= [] for length in range(minLength, len(text)/ 2+ 1): for start in range(len(text)): end= start+ length if end< len(text): part= text[start:end] if text.find(part, end)!= -1: if part not in result: result.append(part) return result >>>foo("testeststest", 4) ['test', 'stes', 'stest'] >>>foo("testeststest", 3) ['tes', 'est', 'ste', 'test', 'stes', 'stest'] HTH Johan Lindberg johan at pulp.se From paschott at no.yahoo.spamm.com Tue Aug 23 18:14:28 2005 From: paschott at no.yahoo.spamm.com (Peter A. Schott) Date: Tue, 23 Aug 2005 22:14:28 GMT Subject: ftplib - issues with some files not completing? Message-ID: <h18ng19m32ecmuemijqhevrep904e6v0eq@4ax.com> Any tips/tricks on how to ensure that I've got the complete file before closing the local file? I think my code is basically correct and works more than 99% of the time, but it still has an occasional issue with an encrypted file where it doesn't receive the whole file and I can't decrypt it. Should I checksum the files somehow or is there a standard trick to ensure I get the complete file? Thanks in advance. -Pete Schott From peter at engcorp.com Fri Aug 5 13:00:04 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 05 Aug 2005 13:00:04 -0400 Subject: Making a timebomb In-Reply-To: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> References: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> Message-ID: <KIWdnTAtgNcUBm7fRVn-oQ@powergate.ca> callmebill at gmail.com wrote: > I have a server that right now runs infinitely. I'd like to make it > die after some amount of time. I was thinking of having a timebomb > thread that starts when the server starts. The timebomb sits, and > sleeps for the specified timeout period (e.g., 5 hours), then does > something to make the main thread terminate. But I'm too inexperienced > to figure out what that thing is. > > Any suggestions? ... > class MyServer: > def __init__(self): > serve() The right answer depends entirely on things you don't mention, most specifically just what serve() is doing in the above code. Generally speaking, long-running code is either running in a loop, repeating some operations -- and a polling technique (to check for timeout) can be used -- or it is asynchronous, such as a server listening on sockets -- in which case you need either to use whatever builtin support is in the framework you're building on (and you should be building on a framework, not doing this from scratch), or you need to use non-blocking sockets and select(), or in the worst case you need to have your server connect internally to itself (think "loopback") and send itself a message so that the blocked threads will wake up and can then voluntarily terminate. Not the clearest message I've written lately... sorry, but if that's not enough to point you in the right direction, give more detail and you'll get a better answer. -Peter From dan at cellectivity.com Tue Aug 16 09:33:11 2005 From: dan at cellectivity.com (Dan) Date: Tue, 16 Aug 2005 14:33:11 +0100 Subject: __del__ pattern? Message-ID: <1124199192.6359.0.camel@localhost.localdomain> > What does "default" mean, and is that definition in conflict with what I > said? The docs say it means INADDR_ANY. someSocket.bind(('', somePort)) means accept connections from any machine. (We use INADDR_ANY instead of '' in C.) someSocket.bind(('localhost', somePort)) means accept only connections from the local machine. Obviously, the second form is much more secure. Even if you don't plan on accepting any of the connections, it's always more secure to let the operating system turn everyone else away. -- Marc Ewing had a reputation for being able to fix any computer problem at his university. He always wore a red baseball, and so was known as "the guy in the red hat". Later, when he started his own open-source company, he wondered what to call it... From francois.perche at gmail.com Wed Aug 10 18:07:31 2005 From: francois.perche at gmail.com (perchef) Date: 10 Aug 2005 15:07:31 -0700 Subject: wxPython and threads again In-Reply-To: <L7udnZ2dnZ1l6661nZ2dnRHLZ9-dnZ2dRVn-z52dnZ0@powergate.ca> References: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> <slrndfkd1k.efj.dek@bosshog.lbl.gov> <L7udnZ2dnZ1l6661nZ2dnRHLZ9-dnZ2dRVn-z52dnZ0@powergate.ca> Message-ID: <1123711651.778825.89440@f14g2000cwb.googlegroups.com> thanks for all these advices. I think a custom event will be the way to go. for the moment I use something _really_ ugly : a mix between GUI, threads and recursive fonctions. From cbfalconer at yahoo.com Thu Aug 25 23:43:16 2005 From: cbfalconer at yahoo.com (CBFalconer) Date: Fri, 26 Aug 2005 03:43:16 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <gaGOe.213$5k1.200@newssvr27.news.prodigy.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <Xns96BD814C9C690castleamber@130.133.1.4> <3n6kkjF4qppU1@individual.net> <nvvPe.215244$tt5.180216@edtnps90> Message-ID: <430E8E1E.92071F5A@yahoo.com> Chris Head wrote: > ... snip ... > > Why can't we use the Web for what it was meant for: viewing > hypertext pages? Why must we turn it into a wrapper around every > application imaginable? Because the Lord High PoohBah (Bill) has so decreed. He has replaced General bullMoose. -- Chuck F (cbfalconer at yahoo.com) (cbfalconer at worldnet.att.net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address! From adsheehan at eircom.net Tue Aug 16 19:54:53 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 16 Aug 2005 16:54:53 -0700 Subject: Urgent: Embedding Python problems - advice sought Message-ID: <1124236492.970194.270970@g47g2000cwa.googlegroups.com> Hi, I am embedding Python into a multi-threaded C++ application running on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify: - if Python correctly supports multiple sub-interpreters (Py_NewInterpreter) ? - if Python correctly supports multiple thread states per sub-interpreter (PyThreadState_New) ? and the "real" question: - what is the rationale for choosing one of: [a] one sub-interpreter with many thread states [b] many sub-interpreters with one thread state each [c] many sub-interpreters with many threas states each Thanks for helping Alan From renting at astron.nl Wed Aug 24 02:54:57 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 24 Aug 2005 08:54:57 +0200 Subject: Logging all activity on a tty/pty? Message-ID: <s30c35f5.038@server7.nfra.nl> I only do this on Linux, and it will probably not work on all versions of Unix, not even to mention Windows, but I basically have used the code of Pexpect and removed the part that does the expecting. ;-) The author of the Pexpect module also has clearly documented potential pitfalls in his FAQ. I think you can find it on pexpect.sourceforge.org See also the documentation of the pty module. >>>Dan Stromberg <strombrg at dcs.nac.uci.edu> 08/24/05 1:54 am >>> Is there a way, using python, to (voluntarily) log all activity in a given shell, in a way that should work on pretty much all *ix's with a port of python? Thanks! -- http://mail.python.org/mailman/listinfo/python-list From gandalf at geochemsource.com Wed Aug 17 05:26:24 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Wed, 17 Aug 2005 11:26:24 +0200 Subject: zlib + Windows 32 service problem (ImportError) In-Reply-To: <ddsjfd$r48$1@news5.zwoll1.ov.home.nl> References: <43008D0D.4000509@geochemsource.com> <mailman.3098.1124117300.10512.python-list@python.org><ddql2o$l1c$1@news1.zwoll1.ov.home.nl> <mailman.3121.1124180797.10512.python-list@python.org> <ddsjfd$r48$1@news5.zwoll1.ov.home.nl> Message-ID: <430302C0.7030406@geochemsource.com> | >| >C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program >| Files\Common Files\GTK\2.0\bin >| >| Then I restarted my computer. It is still missing initzlib. :-( >| Please note that I can run the same program as an application, logged in >| as the same user. >| >| Les > >Changing the Windows dll search path doesn't make any difference. It is >sys.path (Python's search path) that's causing you the headache. Please see >the mentioned thread for proposed solutions. > > Great. I could make my service working with this snippet: import sys sys.path.insert(0,r'C:\Python24\DLLs') But this is very ugly. Primarily, I do not want to use absolute path names in a this program. I want to use the same code on different computers and operating systems, but this code is not portable. Secondly, I do not understand why sys.path is different when I start python interactively. I believe that sys.path should be the same when starting the program as a service. The only difference between the application and the service is that the 'main' program of the service imports some additional modules. See them below. iT:\Python\Projects\NamedConnector>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> >>> s1 = str(sys.path) >>> >>> import win32serviceutil, win32service >>> import pywintypes, win32con, winerror >>> from win32event import * >>> from win32file import * >>> from win32pipe import * >>> from win32api import * >>> from ntsecuritycon import * >>> >>> >>> s2 = str(sys.path) >>> >>> print s1 == s2 True I cannot distribute my service until I make it independent of the python installation directory. Why sys.path is different when starting the code as a windows service? How can I make this code portable? By the way, you have been a great help. Thank you very much. I can now continue working. :-) Les From sklass at pointcircle.com Mon Aug 29 20:57:34 2005 From: sklass at pointcircle.com (rh0dium) Date: 29 Aug 2005 17:57:34 -0700 Subject: Using select on a unix command in lieu of signal In-Reply-To: <1125350001.101171.255060@o13g2000cwo.googlegroups.com> References: <1125347796.648556.282610@g43g2000cwa.googlegroups.com> <7xr7ccv56c.fsf@ruckus.brouhaha.com> <1125350001.101171.255060@o13g2000cwo.googlegroups.com> Message-ID: <1125363454.816578.73260@g47g2000cwa.googlegroups.com> So here's how I solved this.. It's seems crude - but hey it works. select not needed.. def runCmd( self, cmd, timeout=None ): self.logger.debug("Initializing function %s - %s" % (sys._getframe().f_code.co_name,cmd) ) command = cmd + "\n" child = popen2.Popen3(command) t0 = time.time() out = None while time.time() - t0 < timeout: if child.poll() != -1: self.logger.debug("Command %s completed succesfully" % cmd ) out = child.poll() results = "".join(child.fromchild.readlines()) results = results.rstrip() break print "Still waiting..", child.poll(), time.time() - t0, t0 time.sleep(.5) if out == None: self.logger.warning( "Command: %s failed!" % cmd) kill = os.kill(child.pid,9) self.logger.debug( "Killing command %s - Result: %s" % (cmd, kill)) out = results = None else: self.logger.debug("Exit: %s Reullts: %s" % (out,results)) child.tochild.close() child.fromchild.close() return out,results Comments.. rh0dium wrote: > Paul Rubin wrote: > > "rh0dium" <sklass at pointcircle.com> writes: > > > Thanks much - Alternatively if anyone else has a better way to do what > > > I am trying to get done always looking for better ways. I still want > > > this to work though.. > > > > You don't have to use select, since you can use timeouts with normal > > socket i/o. So you could use threads. 3000 threads is a lot but not > > insanely so. > > OK I could use the timeout.. but I am using a queue as well. So each > thread gets several commands. I assumed (could be wrong) that if I use > a timeout the whole thread gets killed not the individual process. The > purpose of the queue was to limit the number of concurrent workers, and > keep the load on the machine somewaht manageable. > > So to add more to this here is how I call the runCmd > > # Initialize a que to 25 max hosts > workQ = Queue.Queue(25) > > # Start some threads.. > for i in range(MAX_THREADS): > getReachableHosts(queue=workQ).start() > > # Now give the threads something to do.. The nice thing here is > that by > # waiting unil now this will hold up the queue.. > for host in base_hosts: > workQ.put(host) > > # After this is finally done thow a null to close the threads.. > for i in range(MAX_THREADS): > workQ.put(None) > > And then getReachables.. > > class getReachableHosts(threading.Thread): > def __init__(self,queue=None, ): > self.logger = logging.getLogger("metriX.%s" % > self.__class__.__name__) > self.logger.info("Initializing class %s" % > self.__class__.__name__) > self.__queue = queue > threading.Thread.__init__(self) > > def run(self): > self.logger.debug("Initializing function %s" % > sys._getframe().f_code.co_name ) > while 1: > host = self.__queue.get(timeout=5) > if host is None: > break > > self.logger.debug("Getting open ports on %s" % host) > command = "nmap -p 22,514 -oG - %s | perl -lane 'print > unless /^#/'" % host > > (out,results)=self.runCmd(cmd=cmd,timeout=5) > > > Much appreciate the advice and help!! From trentm at ActiveState.com Wed Aug 17 16:42:10 2005 From: trentm at ActiveState.com (Trent Mick) Date: Wed, 17 Aug 2005 13:42:10 -0700 Subject: creating/modifying sparse files on linux In-Reply-To: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> Message-ID: <20050817204210.GD21364@ActiveState.com> [draghuram at gmail.com wrote] > > Hi, > > Is there any special support for sparse file handling in python? My > initial search didn't bring up much (not a thorough search). I wrote > the following pice of code: > > options.size = 6442450944 > options.ranges = ["4096,1024","30000,314572800"] > fd = open("testfile", "w") > fd.seek(options.size-1) > fd.write("a") > for drange in options.ranges: > off = int(drange.split(",")[0]) > len = int(drange.split(",")[1]) > print "off =", off, " len =", len > fd.seek(off) > for x in range(len): > fd.write("a") > > fd.close() > > This piece of code takes very long time and in fact I had to kill it as > the linux system started doing lot of swapping. Am I doing something > wrong here? Is there a better way to create/modify sparse files? test_largefile.py in the Python test suite does this kind of thing and doesn't take very long for me to run on Linux (SuSE 9.0 box). Trent -- Trent Mick TrentM at ActiveState.com From utabintarbo at gmail.com Sun Aug 21 14:19:37 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 21 Aug 2005 11:19:37 -0700 Subject: X-Platform method of remote execution of Windows programs Message-ID: <1124648377.416523.292030@z14g2000cwz.googlegroups.com> How can I execute a program in windows on a remote pc, from both linux and windows, using python (more-or-less) alone? Any help would be GREATLY appreciated! Bob From quantumcheesedog at gmail.com Sat Aug 6 21:44:49 2005 From: quantumcheesedog at gmail.com (Steve Bailey) Date: Sat, 6 Aug 2005 18:44:49 -0700 Subject: Does FTPLIB have a 'local change directory' ? In-Reply-To: <20050807013944.GB22724@unpythonic.net> References: <3tdJe.1566$Z87.303@newssvr14.news.prodigy.com> <20050807013944.GB22724@unpythonic.net> Message-ID: <c18ad1bb0508061844ab754f5@mail.gmail.com> Yes, I tried using just the filename itself in using storbinary, but it returned some kind of error, but your suggestion to use os.chdir is so obvious I'm not sure why I didn't think of that. Thanks for the email Steve On 8/6/05, jepler at unpythonic.net <jepler at unpythonic.net> wrote: > If you want to change the working directory of a Python program, then use > os.chdir() for that purpose. That's what 'lcd' does in ftp client software. > It doesn't send a remote command of any kind. > > Or, when you call the storbinary method, give the os.path.basename() of the > file you are storing, instead of the name you used to open the file on the local > system. > > Jeff > > > From pbagora at yahoo.com Mon Aug 1 14:49:31 2005 From: pbagora at yahoo.com (Pranav Bagora) Date: Mon, 1 Aug 2005 11:49:31 -0700 (PDT) Subject: Python-list Digest, Vol 23, Issue 18 In-Reply-To: <mailman.9718.1122918303.10511.python-list@python.org> Message-ID: <20050801184931.93621.qmail@web32407.mail.mud.yahoo.com> hello, I am trying to write a python code which reads a web service and creates its corresponding wsdl file. Any idea how to do it. Thanks Pranav __________________________________ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail From dial#####$$NOSPAM##$#$##tone at gmail.com Thu Aug 18 09:43:13 2005 From: dial#####$$NOSPAM##$#$##tone at gmail.com (Valentino Volonghi aka Dialtone) Date: Thu, 18 Aug 2005 15:43:13 +0200 Subject: Python for Webscripting (like PHP) References: <de1kc1$oo9$01$1@news.t-online.com> <Yd%Me.21226$HM1.606063@twister1.libero.it> Message-ID: <1h1hy35.o0wbe714njbzfN%dial#####$$NOSPAM##$#$##tone@gmail.com> Alessandro Bottoni <alessandro.bottoni at infinito.it> wrote: > (Python has even been told to be used by Yahoo! and Google, among others, > but nobody was able to demonstrate this, so far) ? Google and Microsoft and Nokia had talks during PyCon 2005. If you look at the GMAIL help system you would see that all the links in there end in .py. Blogger is almost completely built with python. Google is also one of the members of the PSF. What should be demonstrated? -- Valentino Volonghi aka Dialtone Now Running MacOSX 10.4 Blog: http://vvolonghi.blogspot.com http://weever.berlios.de From renting at astron.nl Thu Aug 25 03:04:42 2005 From: renting at astron.nl (Adriaan Renting) Date: Thu, 25 Aug 2005 09:04:42 +0200 Subject: Should I move to Amsterdam? Message-ID: <s30d89bb.072@server7.nfra.nl> Thank you for your praise of my little country, but depending on your definition, the Netherlands might not be as civil as you assume. A lot of my foreign collegues commplain about how rude the dutch can be. Countries like sweden or japan seem to have much better manners. As to which countries have been civilized for the longest time, the Netherlands wouldn't rank very high there either, China, Greece or Egypt have been civilized much longer. I do think however that New york should have it's name reverted to New Amsterdam ;-) >>>Tom Anderson <twic at urchin.earth.li> 08/24/05 6:49 pm >>> On Wed, 24 Aug 2005, Armin Steinhoff wrote: >Adriaan Renting wrote: > >>>>>"Wade" <wade at leftwich.us> 08/24/05 2:31 pm >>> >> >>http://www.slate.com/id/2124561/entry/2124562/ Nice little series by >>Seth Stevenson for Americans daydreaming about emigration. Somewhere, >>anywhere ... maybe Amsterdam? I've never been to the Netherlands >>myself, but it sounds very civilized. > >What a joke ... Amsterdam is 'civilized' since several hundreds of years >:) Indeed. Perhaps we should rename it Old New York to reinforce the point :). But yes, the Netherlands is a highly civilised country - up there with Denmark and Canada, and above the UK, France or Germany, IMNERHO. I'm not going to bother comparing it to the US! tom -- This should be on ox.boring, shouldn't it? -- http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Fri Aug 5 10:34:17 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 5 Aug 2005 10:34:17 -0400 Subject: The ONLY thing that prevents me from using Python References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> Message-ID: <dcvtda$i6m$1@sea.gmane.org> "Kevin" <816168 at gmail.com> wrote in message news:1123248107.576277.319410 at g44g2000cwa.googlegroups.com... > The problem is that it's difficult to find hosting services with Python > installed and supported. The Python Wiki has lists of both free and commercial hosting services. The top page is http://wiki.python.org/moin/PythonHosting. Did you look at these? Are the choices inadequate? (I have no idea, never having been involved with the subject.) ... > I am sure this issue has already been raised a billion times. Yes, that is why the wiki pages were added. Improvements are welcome, I presume. .... > I really wish Python could be more widely available on web server > machines. This is just my own experience and I would like to hear your > comments. We all wish that. But in my ignorance, I wonder why the few that there are are so insufficient that you would drop Python (for PHP, no less). Do clients require that you use specific hosting services, even though they do not host a preferred package? Do the few Python hosters that there are, knowing that they are few, exploit Python developers with high rates or other obnoxious policies? This issue has been raised enough that I really am curious. Terry J. Reedy From fakeaddress at nowhere.org Wed Aug 10 10:02:02 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 14:02:02 GMT Subject: MainThread blocks all others In-Reply-To: <42fa056e_1@news.isis.de> References: <ddb7st$2lpp$1@gavrilo.mtu.ru> <HHaKe.2321$Z87.409@newssvr14.news.prodigy.com> <fRaKe.3656$zr1.2646@newssvr13.news.prodigy.com> <42f9d4ef_2@news.isis.de> <42f9e68a_1@news.isis.de> <53nKe.3824$zr1.1930@newssvr13.news.prodigy.com> <42fa056e_1@news.isis.de> Message-ID: <uNnKe.3836$zr1.398@newssvr13.news.prodigy.com> Nodir Gulyamov wrote: > Hi again, comments below: > > >>> doSomeJob(self): >>> ##### BLOCKING HERE ### >>> if not self.myEvent.isSet(): >>> self.myEvent.wait() >> >>The initial 'if' is superflous. > > Excuse me, please explain. The code: if some_event.isSet(): some_event.wait() does exactly the same thing as: some_event.wait() See: http://docs.python.org/lib/event-objects.html >>> self.myEvent.clear() >>> # ... continue... >>> >>># this class subscribed to some observer which implements thread >>>class monitor: >>> def __init__(self, klass): >>> #do some init >>> self.c = klass >>> def update(self): >>> self.c.increaseCounter() >>> >>>if __name__ == "__main__": >>> cl1 = class1() >>> m = monitor(cl1) >>> mo = MonitorObserver(m) >> >>Obviously that won't work. You only have one thread, and it blocks >>in doSomeJob, so no one can ever trigger the even. > > Actually I have 2 threads. One of them is MainThread and second one is > created by Observer in which update method called. Whatever other thread you have in other code, this code is whacked. Who do you think calls cl1.increaseCounter(), and how did they get a reference to cl1? -- --Bryan From damir at agg.astranet.ru Fri Aug 12 08:03:03 2005 From: damir at agg.astranet.ru (Damir Hakimov) Date: Fri, 12 Aug 2005 16:03:03 +0400 Subject: bug in property? Message-ID: <42FC8FF7.4080202@agg.astranet.ru> #!/usr/bin/python2.4 class test_property: def __init__(self): self._x="Zero" pass def setx(self,x): print "set x" #this is not work self._x=x def getx(self): return self._x def delx(self): del(self._x) x=property(getx,setx,delx,"XXX") t=test_property() t.x=1 print t.x damir at debian-IBM:~$ ./test.py 1 And were is "set x"? If you comment out t.x=1 you'll see that getx() works. Damir From spammers-go-here at spam.invalid Sat Aug 13 23:29:27 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sat, 13 Aug 2005 23:29:27 -0400 Subject: Standalone applications ? Message-ID: <42feba84$0$18644$14726298@news.sunsite.dk> Hi I just finished developing an application using Qt Designer in Python that uses pyqwt, gpib, etc. How does one create standalone executables for applications such as these ? Thanks. From p at ulmcnett.com Tue Aug 2 14:00:47 2005 From: p at ulmcnett.com (Paul McNett) Date: Tue, 02 Aug 2005 11:00:47 -0700 Subject: Dabo in 30 seconds? In-Reply-To: <dcob6m$cl0$1@sea.gmane.org> References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <200508010830.27322.ed@leafe.com> <dclgn7$kja$1@sea.gmane.org> <200508011220.41469.ed@leafe.com> <dcob6m$cl0$1@sea.gmane.org> Message-ID: <42EFB4CF.5070205@ulmcnett.com> Fernando Perez wrote: > <plug, but hopefully a useful one> > > You may want to steal the crash handling code from ipython. In order to > address this kind of problem, ipython sticks an exceptionally verbose > traceback printer into sys.excepthook. If ipython ever crashes, the user gets > a LOT of info, and it's all packaged ready to go, to be emailed to me. Here's > an example of the result (I stuck 1/0 inside to force the crash): [snip] > This approach has worked very well for me over the years, and these crash > report emails have become fortunately rather rare as of late :) > > If you are interested, just get ipython and grab the files for this, it's all > BSD licensed. You can also browse the SVN repo here if you want to look at > the code: > > http://ipython.scipy.org/svn/ipython/ipython/trunk/IPython/ > > The relevant files are ultraTB.py and CrashHandler.py. Thanks Fernando, consider your excellent code stolen! :) I'll probably make a flag that defaults to ultraTB but that can also be set to leave sys.excepthook as-is. Best of both worlds! I've done things like this in the past, in my own Visual Foxpro framework. In that situation, I had enough control over the deployment to also ship a small smtp client, and automatically email the error without requiring any interaction at all. Clients were impressed when I'd already have a fix for the problem before they even notified me of the issue! -- Paul McNett http://paulmcnett.com From dickinsm at verizon.net Thu Aug 25 14:58:07 2005 From: dickinsm at verizon.net (Mark Dickinson) Date: Thu, 25 Aug 2005 18:58:07 GMT Subject: Speed quirk: redundant line gives six-fold speedup References: <dickinsm-546322.12442425082005@news.verizon.net> <mailman.3528.1124993571.10512.python-list@python.org> Message-ID: <dickinsm-A44D4F.14580725082005@news.verizon.net> In article <mailman.3528.1124993571.10512.python-list at python.org>, Stelios Xanthakis <sxanth at ceid.upatras.gr> wrote: > In the sudoku solver, there is a min (number, object) which is > probably what's affected by the extistance of the dummy variable. > Now, in sudoku puzzles some times the algorithm has to suppose > that in a box the right solution is one of the possible, try it > and if it fails then try the other one. I guess that the result > of from the different 'min' leads the solver to first try the > correct solution in the fast case and therefore need not attempt > the wrong one. Or at least this is what I think that happens. Thank you! That does indeed seem to be the explanation. The min() line looks for the shortest `constraint'; that is, the box with the fewest possible symbols, or the symbol with the smallest number of possible positions within a given row, column or block; the code below that line then tries all possibilities for this constraint. The line should really be something like min(c for c in rowitems(h), key = lambda c: c.S) but that isn't going to work until Python 2.5 comes out, and I was too lazy to expand the whole thing properly instead of using the cheap trick I did. Thanks again for clearing up this confusion. Mark From bronger at physik.rwth-aachen.de Tue Aug 2 03:45:36 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Tue, 02 Aug 2005 09:45:36 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> Message-ID: <87oe8gdbof.fsf@wilson.rwth-aachen.de> Hall?chen! Mike Meyer <mwm at mired.org> writes: > Torsten Bronger <bronger at physik.rwth-aachen.de> writes: > >> [...] >> >> I'm interested in a language with a big community. This is my >> definition of success. [...] >> >> GUI applications seem to be the most attractive application type. >> This is not only true for commercial programming. When I look at >> the most agile projects on Sourceforge, almost all of them have a >> GUI. > > Why restrict yourself to agile projects? Because such projects attract the greatest number of developers, many of them being amongst the most diligent developers, too. I expect this to have a positive influence of the language. > [...] > > I won't argue that most of the projects on Sourceforge have GUIs - > that's certainly true. I will argue that most of the projects are > done in languages that aren't what you call GUI-aware. Yes, this is what I meant with "legacy code". C and C++ are actually special-purpose. They are good for controlling a computer but not for implementing an idea. Their current vitality on almost all software areas arise from the fact that they had been extremely successful before Java, C#, and VB came into play. Invented today, they would be niche languages. However, even C++ is really successful only when used as a GUI-aware dialect. Additionally, Python does not have this legacy bonus. >> Therefore, GUI-aware languages attract much larger user bases, >> and so they cater my definition of being successful. > > Since you haven't stated what that definition is, I can't really say > anything about this. Yes, I did. > [...] > >> Legacy code is not a sign of success IMO because it implies a >> difficult future. > > So you're saying that Python, Perl, Linux, the various BSD > et. al. will have a difficult future? [...] No. All I said was that if a language's "success" relies almost exclusively on the heavy presence of legacy code, its future is difficult. I see this for C and C++ excluding VC++. They will always be there, but "cool new things" will be made available firstly (or only) for Java, C#, Python etc. > [...] > > Or maybe you could switch to Jython, and just use swing? Actually I'm very happy with CPython. Besides, I don't like the Java world. When I left C++ last winter, I dithered between C#, Ruby, and Python. BTW this thread was extremely interesting for me. I've learnt a lot. (Unfortunately, two weeks ago I opted for wxPython, after a long and tough time of thorough pondering, and today this thread informed be about progress on the Tk front. *cry* ;-) Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From jforcier at strozllc.com Tue Aug 9 13:50:18 2005 From: jforcier at strozllc.com (Jeffrey E. Forcier) Date: 9 Aug 2005 10:50:18 -0700 Subject: Recommendations for CVS systems In-Reply-To: <liqms2-0ld.ln1@strongwill.g2ctech> References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <liqms2-0ld.ln1@strongwill.g2ctech> Message-ID: <1123609818.770605.267740@g14g2000cwa.googlegroups.com> Thirding the Subversion/SVN suggestions. It's generally a newer, better CVS with some new features and a lot less of the negative features/lack thereof, of the older system. If any of your team has CVS experience they should have no real problem with the switch, and anyone without prior version control experience will just be that much better off starting with Subversion. From spammers-go-here at spam.invalid Tue Aug 9 17:54:59 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Tue, 09 Aug 2005 17:54:59 -0400 Subject: Embedding a runtime graph in Qt3 designer generated UI References: <42f6e4c8$0$18646$14726298@news.sunsite.dk> <mailman.2840.1123485700.10512.python-list@python.org> Message-ID: <42f9262b$0$18642$14726298@news.sunsite.dk> Phil Thompson wrote: >> 2. In the same vein, how does one embed a runtime plot in a qt3 UI ? It >> will >> need to be a python solution since I am using python libraries to acquire >> the data. > > Have a look at PyQwt which is a set of Python bindings for the Qt-based > Qwt plotting library. > > Phil Can a designer plugin be used this way ? I tried inserting a FileChooser (available as an .so file under designer plugins) object onto the main window and then used pyuic. Traceback (most recent call last): File "measure.py", line 16, in ? f = MEASURE() File "/home/m_singh/measure.py", line 422, in __init__ self.fileChooser1 = FileChooser(self.groupBox4,"fileChooser1") NameError: global name 'FileChooser' is not defined The wrapper in my .py file : from qt import * from measure import * import sys if __name__ == "__main__": app = QApplication(sys.argv) f = MEASURE() f.show() app.setMainWidget(f) app.exec_loop() An attempt to use QwtPlot gives the same kind of error. Or is the only way forward for me to generate a .py file from non-plugin objects, and then hand code the pyqwt part into that result (Or use Python: in the ui). From paragate at gmx.net Mon Aug 22 05:55:02 2005 From: paragate at gmx.net (wolf) Date: 22 Aug 2005 02:55:02 -0700 Subject: PEP: Generalised String Coercion References: <mailman.2776.1123323832.10512.python-list@python.org> Message-ID: <1124704502.242822.228300@g49g2000cwa.googlegroups.com> hi, i guess that anyone reading this pep will agree that *something* must be done to the state of unicode affairs in python. there are zillions of modules out there that have str() scattered all over the place, and they all *break* on the first mention of d?sseldorf... i'm not quite sure myself how to evolve python to make it grow from unicode-enabled to unicode-perfect, so for me some discussion would be a good thing. only two micro-remarks to the pep as it stands: 1) i dislike the naming of the function ``text()`` -- i?ve been using the word 'text' for a long time to mean 'some appropriate representation of character data', i.e. mostly something that would pass :: assert isinstance(x,basestring) i feel this is a fairly common way of defining the term, so to me a function `` text(x)`` should really * return its argument unaltered if it passes ``isinstance(x,basestring)``, * try to return spefically a unicode object (by using the ``x.__unicode__()`` method, where available) * or return an 8bit-string (from ``x.__repr__()`` or ``x.__str__()``) as discussed later on in the pep, it is conceivable to assign the functionality of the ``text()`` function of the pep to ``basestring`` -- that would make perfect sense to me (not sure whether that stands scrutiny in the big picture, tho). 2) really minor: somewhere near the beginning it says :: def text(obj): return '%s' % obj and the claim is that this "behaves as desired" except for unicode-issues, which is incorrect. the second line must read :: return '%s' % ( obj, ) or else it will fail if ``obj`` is a tuple that is not of length one. cheers, _wolf From pydecker at gmail.com Mon Aug 8 10:05:07 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 8 Aug 2005 10:05:07 -0400 Subject: Python -- (just) a successful experiment? In-Reply-To: <dd7div$nit$1@sea.gmane.org> References: <20050807005406.1217660123.whereU@now.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <mailman.2816.1123426672.10512.python-list@python.org> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <dd5a3f$6lv$1@sea.gmane.org> <20050808005104.862503556.EP@zomething.com> <dd7div$nit$1@sea.gmane.org> Message-ID: <ca55a99005080807051df8fea0@mail.gmail.com> On 8/8/05, Robert Kern <rkern at ucsd.edu> wrote: > What I'm trying to say is that posting to c.l.py is absolutely > ineffective in achieving that goal. Code attracts people that like to > code. Tedious, repetitive c.l.py threads attract people that like to > write tedious, repetitive c.l.py threads. +1 QOTW -- # p.d. From godoy at ieee.org Tue Aug 2 00:35:13 2005 From: godoy at ieee.org (Jorge Godoy) Date: Tue, 02 Aug 2005 01:35:13 -0300 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <d7rur2-ksb.ln1@strongwill.g2ctech> <861x5ehk4g.fsf@bhuda.mired.org> <rrqvr2-v7q.ln1@strongwill.g2ctech> <86d5oxf0u8.fsf@bhuda.mired.org> Message-ID: <tp93s2-o4p.ln1@strongwill.g2ctech> Mike Meyer wrote: > Exactly what problem are you trying to solve? If it's the one about > not having a standard GUI, I don't think it's a problem. Me neither. You pointed out that having a standard distribution made by some company would solve the non-standard GUI problem. I believe we share the same opinion, judging from this last post of yours. Maybe I missed something on your message and read it as if you had a different opinion. >> In fact this sounds more like a joke I've heard a while ago: standards, >> if you don't like the ones out there, create your own. > > Works for me. What works for you? You believe that chaos is better than having standards? I believe that flexibility is good, but not chaos. > I think you have me confused with someone else. I was responding to > someone who was claiming that the lack of a standard enterprise > strength GUI toolkit was a serious problem for Python - I disagree. I I dunno. Maybe I confused your words. I agree on disagreeing ;-) > won't recap the thread, but other languages have been *very* > successful without having a GUI as part of the language, all they had > was one development environment distributed with a GUI. One IDE, you mean? I believe the freedom to choose from multiple IDEs is also good. Some code on VI, others on Emacs, others on Eclipse, others on ... I agree that having multiple toolkits is good. > BTW, in answer to your rhetorical question about GUI's for Linux, the > answer is plwm. :-) And does it integrate well with common business apps, such as a mail client, note taking apps, addressbooks (with personal and shared entries), calendar with ability to share appointments, etc.? Be seeing you, -- Jorge Godoy <godoy at ieee.org> From ivanlan at pauahtun.org Thu Aug 11 21:49:53 2005 From: ivanlan at pauahtun.org (Ivan Van Laningham) Date: Thu, 11 Aug 2005 19:49:53 -0600 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <6rCdnRM5Y9QmZ2bfRVn-1Q@speakeasy.net> Message-ID: <42FC0041.B5DB0E14@pauahtun.org> Hi All-- Erik Max Francis wrote: > > Xah Lee wrote: > > > Jargons of Info Tech industry > > > > (A Love of Jargons) > > > > Xah Lee, 2002 Feb > > Congratulations, this time you managed to get to your second paragraph > before your Tourette's kicked in. > You made it that far? Congratulations. I barely got past the name of the troll. Metta, Ivan ---------------------------------------------- Ivan Van Laningham God N Locomotive Works http://www.pauahtun.org/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours From lycka at carmen.se Wed Aug 17 05:36:06 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 17 Aug 2005 11:36:06 +0200 Subject: Making programs work together. In-Reply-To: <1124256651.450266.90580@g47g2000cwa.googlegroups.com> References: <1124256651.450266.90580@g47g2000cwa.googlegroups.com> Message-ID: <ddv0e6$nis$1@wake.carmen.se> ChuckDubya at gmail.com wrote: > I'm looking to make what's basically a macro for a computer game. But > I want this "macro" to take information from the game itself, so it's > not really a macro. That's exactly a macro as the term is used in e.g. MS Office macros written in VBA etc. Do you have access to the source code for the game? From spam at me.please Wed Aug 10 23:51:45 2005 From: spam at me.please (Evil Bastard) Date: Thu, 11 Aug 2005 15:51:45 +1200 Subject: What is Python?! In-Reply-To: <42fa51db$0$7802$626a14ce@news.free.fr> References: <ddcnbf$aen$02$1@news.t-online.com> <roy-8911D7.08041710082005@reader2.panix.com> <42fa51db$0$7802$626a14ce@news.free.fr> Message-ID: <42faccb9$1@news.orcon.net.nz> bruno modulix wrote: > You can tell buy the most common use. bash is a scripting language, > javascript is a scripting language, perl is a scripting language, php is > a scripting language, Python is *not* a scripting language !-) Perhaps a better definition - the term 'scripting language' is increasingly being used by CTOs as a justification for saving money by putting large chunks of their workforces on lower pay scales - an attitude of 'scripters aren't as skilled as real programmers, so don't deserve the same pay'. To me, the term is archic. What 'scripting language' means to me is: 1. insufficient facilities for general purpose or 'serious' programming 2. ability to get simple useful programs up and working quickly 3. absence of a hack/compile/link/test cycle. What makes 1 and 3 redundant is that linkage mechanisms have diversified over the years. For instance, java and python's 'import' statements, java's CLASSPATH and python's 'sys.path'. I guess a language could be called a 'scripting language' if: - the source code can be executed directly, and/or - source need not be converted to a separate file in a non-human-readable format before it can be executed, and/or - a change to the source file automatically causes a change in runtime behaviour By these, Python is most definitely a scripting language, and joins Perl and PHP. Whereas changes to java source files don't change runtime behaviour. OTOH, Python is also a compiled language, since it can be 'fixed' into a n executable binary format. -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From rphillips at engineer.co.summit.oh.us Fri Aug 19 07:10:23 2005 From: rphillips at engineer.co.summit.oh.us (paron) Date: 19 Aug 2005 04:10:23 -0700 Subject: Python for Webscripting (like PHP) References: <de1kc1$oo9$01$1@news.t-online.com> Message-ID: <1124449823.428290.206950@g47g2000cwa.googlegroups.com> Yes the stdlib offers all the basic functions, but why work so hard? Get CherryPy (http://www.cherrypy.org) and relax a bit. You'll be able to concentrate on Python for the backend, HTML for the frontend, without a lot of directory-diddling. Also, check out http://www-128.ibm.com/developerworks/opensource/library/os-cherrypy/index.html#main for a nice, fresh slice. Ron From sjmachin at lexicon.net Sun Aug 14 23:12:57 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Aug 2005 13:12:57 +1000 Subject: Spaces and tabs again In-Reply-To: <43000262.7050209@redlinepy.com> References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <ddlike$on6$1@panix2.panix.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> <6spsf1hr7i0ho9fa0ptauhst1s61jkig13@4ax.com> <m2d5oh1ela.fsf@unique.fully.qualified.domain.name.yeah.right> <43000262.7050209@redlinepy.com> Message-ID: <43000838@news.eftel.com> Paul Watson wrote: > Dan Sommers wrote: > >> On Sun, 14 Aug 2005 01:04:04 GMT, >> Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote: >> >> >>> On 13 Aug 2005 13:18:21 -0700, sigzero at gmail.com declaimed the following >>> in comp.lang.python: >> >> >> >>>> Are you kidding? You are going to MANDATE spaces? >>>> >>> >>> After the backlash, Python 4.0 will ban leading spaces and require >>> tabs <G> >> >> >> >> Why not petition the unicode people to include PYTHON INDENT and PYTHON >> DEDENT code points, and leave the display up to the text editors? ;-) >> >> Regards, >> Dan > > > The Unicode people will correctly point out that there is already a > Unicode codepoint assignment which can be used for this purpose. It is > even in the BMP portion of the C0 controls group. > > 0009 = HORIZONTAL TABULATION and how do you use this to get the DEDENT effect? Use something out of the bidirectional kit? E.g. RLO then tab then PDF ;-) From peter at engcorp.com Sun Aug 28 12:45:33 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Aug 2005 12:45:33 -0400 Subject: close failed: [Errno 0] No error goes to stdout In-Reply-To: <4311b9bf@news.bezeqint.net> References: <4311b9bf@news.bezeqint.net> Message-ID: <qaidnR0jbcixd4zeRVn-vQ@powergate.ca> Yoav wrote: > I use the following code to the console output: > > def get_console(cmd): > try: > p_in, p_out, p_err = os.popen3(cmd) > except: > pass > out_str = '' > for obj in p_out: > out_str = out_str + obj > for obj in p_err: > out_str = out_str + obj > return out_str > > > for some reason some exceptions (stderr outputs) are not captured by the > try method, and slip to the screen. Any one has any idea on how can > prevent from any output that I don't want to? > The output I get on these exceptions is: > close failed: [Errno 0] No error What makes you think the errors are getting past the try/except? Could they be printed by the program you are invoking with popen3() instead? What does "cmd" equal when you get this failure? Maybe you are expecting that popen3() will somehow raise exceptions when the called program fails, exceptions which the except statement would catch. That's not the case. -Peter From peter at engcorp.com Mon Aug 22 16:58:29 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 16:58:29 -0400 Subject: loop in python In-Reply-To: <mailman.3366.1124732215.10512.python-list@python.org> References: <mailman.3362.1124726899.10512.python-list@python.org> <d_adnWwgVZOcYZTeRVn-gA@powergate.ca> <mailman.3366.1124732215.10512.python-list@python.org> Message-ID: <c9SdnaiS_uPuoZfeRVn-sQ@powergate.ca> km wrote: >>thing. If *all* your loops are going to do is print stuff, then you're >>doing the right thing with the version that "emits values". > > ya most of the loops print values. No, you missed my point. I said if *all* the loops are going to do is print stuff. In other words, no other calculations, no function calls, no nothing. Just simple "print" statements. Doing this in your test just tests I/O in the C library and operating system, not anything to do with the speed of Python, as Bruno has clarified in detail. -Peter From fredrik at pythonware.com Wed Aug 10 07:01:03 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 10 Aug 2005 13:01:03 +0200 Subject: Help with Regular Expressions References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> Message-ID: <ddcmpg$1gh$1@sea.gmane.org> Harlin Seritt wrote: > I am trying to find some matches and have them put into a list when > processing is done. I'll use a simple example like email addresses. > > My input is the following: > wordList = ['myname1', 'myname2 at domain.tld', 'myname3 at domain.tld', > 'myname4 at domain', 'myname5 at domain.tldx'] > > My regular expression would be something like '\w\@\w\.\w' (I realize > it could and should be more detailed but that's not the point for now). > > I would like to find out how to output the matches for this expression > of my 'wordList' into a neat list variable. How do I get this done? that's more of a list manipulation question than a regular expression question, of course. to apply a regular expression to all items in a list, apply it to all items in a list. a list comprehension is the shortest way to do this: >>> out = [word for word in wordList if re.match("\w+@\w+\.\w+", word)] >>> out ['myname2 at domain.tld', 'myname3 at domain.tld', 'myname5 at domain.tldx'] </F> From nicolas.riesch at genevoise.ch Tue Aug 23 02:36:03 2005 From: nicolas.riesch at genevoise.ch (nicolas_riesch) Date: 22 Aug 2005 23:36:03 -0700 Subject: literal accented characters in python asp page with Microsoft IIS Message-ID: <1124778963.267120.167110@o13g2000cwo.googlegroups.com> I try to use python as the language in an asp page with Microsoft IIS 5.0. I have these two files, req_bad.asp and req_ok.asp ---------- req_bad.asp --------- <%@LANGUAGE=Python%> <% # il y a un probl?me ici Response.write('Hello') %> ----------------------------- ---------- req_ok.asp --------- <%@LANGUAGE=Python%> <% # il y a un probleme ici Response.write('Hello') %> ----------------------------- When I retrieve req_bad.asp from a browser, I get the error message: HTTP/1.1 500 Server Error When I try with req_ok.asp, it works and displays 'hello'. The only difference is that in req_bad.asp, I use an accented character in the french word "probl?me". In req_ok.asp, there is no accented character. Someone knows how to write literal accented characters in a python asp page ? It is not only for the comments, but also to write out strings with Response.write('probl?me') which doesn't work either. If I write "probl\xe8me" instead of "probl?me", it works well. But as I already have lots of code containing literal accented characters, I would have liked to be able to use them in asp pages, without modifying them. It is only in asp pages that things don't work. If I run code containing literal accented characters as normal Python program, it works. Is the problem related to IIS and is there some configuration to change to make it work ? From spam at me.please Mon Aug 8 16:58:30 2005 From: spam at me.please (Evil Bastard) Date: Tue, 09 Aug 2005 08:58:30 +1200 Subject: python for microcontrollers Message-ID: <42f7c8d4$1@news.orcon.net.nz> Hi all, I'm currently tackling the problem of implementing a python to assembler compiler for PIC 18Fxxx microcontrollers, and thought I'd open it up publicly for suggestions before I embed too many mistakes in the implementation. The easy part is getting the ast, via compiler.ast. Also easy is generating the code, once the data models are worked out. The hard part is mapping from the abundant high-level python reality to the sparse 8-bit microcontroller reality. I looked at pyastra, but it has fatal problems for my situation: - no backend for 18fxxx devices - only 8-bit ints supported I'm presently ripping some parts from the runtime engine of a forth compiler I wrote earlier, to add support for 8-32 bit ints, floats, and a dual-stack environment that offers comfortable support for local variables/function parameters, as well as support for simpler and more compact code generation. Python is all about implicitly and dynamically creating/destroying arbitrarily typed objects from a heap. I've got a very compact malloc/free, and could cook up a refcounting scheme, but using this for core types like ints would destroy performance, on a chip that's already struggling to do 10 mips. The best idea I've come up with so far is to use a convention of identifier endings to specify type, eg: - foo_i16 - signed 16-bit - foo_u32 - unsigned 32-bit - bar_f - 24-bit float - blah - if an identifier doesn't have a 'magic ending', it will be deemed to be signed 16-bit also, some virtual functions uint16(), int16(), uint32(), int32(), float() etc, which work similar to C casting and type conversion, so I don't have to struggle with type inference at compile time. Yes, this approach sucks. But can anyone offer any suggestions which suck less? -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From merkosh at hadiko.de Sat Aug 13 05:11:52 2005 From: merkosh at hadiko.de (Uwe Mayer) Date: Sat, 13 Aug 2005 11:11:52 +0200 Subject: Bug on Python2.3.4 [FreeBSD]? References: <ddioc3$evr$1@news2.rz.uni-karlsruhe.de><mailman.3041.1123874270.10512.python-list@python.org><ddiva5$j2m$1@news2.rz.uni-karlsruhe.de> <donn-BC56BC.16011812082005@gnus01.u.washington.edu> <mailman.3044.1123892005.10512.python-list@python.org> <1123906696.459433@yasure> Message-ID: <ddkdgo$gdk$1@news2.rz.uni-karlsruhe.de> Saturday 13 August 2005 06:18 am Donn Cave wrote: > Of course, but the question was, where do reads start? I would > guess the GNU C library "innovated" on this point. But in the > end it doesn't really matter unless Python is going to try to > square that all up and make open() consistent across platforms. Personally, I think Python should unify this difference across plattforms and explicitly document the behaviour in the library reference. But I don't know how a decision on that is going to be formed. I will forward a request for taking this point up into the library reference's file() function, perhaps a footnote pointing out the end-of-file position on BSD and start-of-file on Linux. Uwe From jonhewer at gmail.com Fri Aug 19 07:46:20 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Fri, 19 Aug 2005 12:46:20 +0100 Subject: Python for Webscripting (like PHP) In-Reply-To: <d76c7b8f050819044662ffa5fc@mail.gmail.com> References: <de1kc1$oo9$01$1@news.t-online.com> <1124449823.428290.206950@g47g2000cwa.googlegroups.com> <d76c7b8f050819044662ffa5fc@mail.gmail.com> Message-ID: <d76c7b8f05081904469817dc7@mail.gmail.com> 'cherryPy' even On 8/19/05, Jon Hewer <jonhewer at gmail.com> wrote: > I like the look of cheeryPy - snyone know if its easy to get it > running on top of Apache? > > Thanks > > On 19 Aug 2005 04:10:23 -0700, paron <rphillips at engineer.co.summit.oh.us> wrote: > > Yes the stdlib offers all the basic functions, but why work so hard? > > Get CherryPy (http://www.cherrypy.org) and relax a bit. You'll be able > > to concentrate on Python for the backend, HTML for the frontend, > > without a lot of directory-diddling. > > > > Also, check out > > http://www-128.ibm.com/developerworks/opensource/library/os-cherrypy/index.html#main > > for a nice, fresh slice. > > > > Ron > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > From nul at nul.be Mon Aug 22 15:30:48 2005 From: nul at nul.be (jan V) Date: Mon, 22 Aug 2005 19:30:48 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <ln8xyt7oxp.fsf@nuthaus.mib.org> Message-ID: <IJpOe.175886$zs4.9923722@phobos.telenet-ops.be> > +-------------------+ .:\:\:/:/:. > | PLEASE DO NOT | :.:\:\:/:/:.: > | FEED THE TROLLS | :=.' - - '.=: > | | '=(\ 9 9 /)=' > | Thank you, | ( (_) ) > | Management | /`-vvv-'\ > +-------------------+ / \ > | | @@@ / /|,,,,,|\ \ > | | @@@ /_// /^\ \\_\ > @x@@x@ | | |/ WW( ( ) )WW > \||||/ | | \| __\,,\ /,,/__ > \||/ | | | jgs (______Y______) > /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Please don't use ASCII art... not everyone uses a fixed-width font for his newsreader............... (your picture looks all mangled here) From grante at visi.com Tue Aug 9 17:50:06 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 09 Aug 2005 21:50:06 -0000 Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <ddatkk$10k$1@ss405.t-com.hr> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> Message-ID: <11fi98edg5mha3f@corp.supernews.com> On 2005-08-09, Scott David Daniels <Scott.Daniels at Acm.Org> wrote: > Grant Edwards wrote: >>>Ex #1) 333-3333 >>>Hex On disk: 00 00 00 80 6a 6e 49 41 >>> >>>Ex #2) 666-6666 >>>Hex On disk: 00 00 00 80 6a 6e 59 41 >> >> So there's only a 1-bit different between the on-disk >> representation of 333-3333 and 666-6666. >> >> That sounds pretty unlikely. Are you 100% sure you're looking >> at the correct bytes? > > Perhaps the one bit is an exponent -- some kind of floating point > based format? That matches the doubling of all digits. That would just be sick. I can't imagine anybody on an 8-bit CPU using FP for a phone number. -- Grant From mensanator at aol.com Wed Aug 3 17:37:20 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 3 Aug 2005 14:37:20 -0700 Subject: Py: a very dangerous language In-Reply-To: <1123099531.243492.4110@z14g2000cwz.googlegroups.com> References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> <dcr73h$cqn$1@online.de> <1123099531.243492.4110@z14g2000cwz.googlegroups.com> Message-ID: <1123105040.522151.70990@f14g2000cwb.googlegroups.com> Luis M. Gonzalez wrote: > Well, I have no problems going to bed. > The problem is that while sleeping, I keep on coding in my head... > Sometimes I reach the "A ha!" state, then I wake up, turn on the my pc > and type the solution. > I'm a little bit worried though... I don't even have erotic dreams > anymore! Ask your friendly neighborhood Freudian what dreams about pythons represent. From mwh at python.net Tue Aug 9 10:45:11 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 09 Aug 2005 14:45:11 GMT Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <mailman.2810.1123403537.10512.python-list@python.org> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <mailman.2816.1123426672.10512.python-list@python.org> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <dd5a3f$6lv$1@sea.gmane.org> <20050808005104.862503556.EP@zomething.com> <mailman.2845.1123498571.10512.python-list@python.org> <m2wtmv89od.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> Message-ID: <m2slxj88yx.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> Michael Hudson <mwh at python.net> writes: > Robert Kern <rkern at ucsd.edu> writes: > >> What I'm trying to say is that posting to c.l.py is absolutely >> ineffective in achieving that goal. Code attracts people that like >> to code. Tedious, repetitive c.l.py threads attract people that like >> to write tedious, repetitive c.l.py threads. > > +1 QOTW, though I may be too late Not only was I late, I was unoriginal! Oh well. Cheers, mwh -- Every day I send overnight packages filled with rabid weasels to people who use frames for no good reason. -- The Usenet Oracle, Oracularity #1017-1 From ray_usenet at yahoo.com Sat Aug 20 05:24:24 2005 From: ray_usenet at yahoo.com (Ray) Date: 20 Aug 2005 02:24:24 -0700 Subject: Please Criticize My Code In-Reply-To: <1124528515.710074.282200@z14g2000cwz.googlegroups.com> References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> <1124528515.710074.282200@z14g2000cwz.googlegroups.com> Message-ID: <1124529864.034851.153380@g43g2000cwa.googlegroups.com> Damn, those are cool, man. Thanks! This Python thing keeps expanding and expanding my brain... Ray bearophileHUGS at lycos.com wrote: <snipped> From eldridge at u-turnmediagroup.com Tue Aug 2 13:14:56 2005 From: eldridge at u-turnmediagroup.com (Bill Eldridge) Date: Tue, 02 Aug 2005 19:14:56 +0200 Subject: Pythoncom scripting Windows Media Player & visible Message-ID: <42EFAA10.9010808@u-turnmediagroup.com> I'm trying to make Windows Media Player visible and control it from Python. It seems when I call it below, I get only the console version, and there's no Visible method like with Internet Explorer. I do catch events, but I need it visible. Should it be put into a panel instead? Should a different type dispatch be called or a different method? it seems that there are a console and a windows classes in the COM browser, but I can't seem to access any useful windows classes. I get "fullScreen" as False, but can't set it. openPlayer(address) will launch a visible window, but with no control of the the window after that. Ideas? from win32com.client import Dispatch,DispatchWithEvents class WMPEvents: def OnVisible(self,evt): print "OnVisible changed:",evt def OnError(self,evt=None): print "OnError",evt def OnMediaError(self,evt=None): print "OnMediaError",evt def OnDisconnect(self,evt): print "OnDisconnect",evt def OnStatusChange(self): print "OnStatusChange" def OnDisconnect(self,evt): print "Disconnect",evt def OnBuffering(self,evt): print "OnBuffering changed:",evt def OnOpenStateChange(self,evt=None): print "OnOpenStateChange" ,evt mp = DispatchWithEvents("WMPlayer.OCX.7",WMPEvents) mp.Visible = True # Does nothing tune = mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma") mp.currentPlaylist.appendItem(tune) mp.controls.playItem(tune) mp.controls.play() raw_input("Press enter to stop playing") mp.controls.stop() From paolo_veronelli at tiscali.it Mon Aug 1 18:52:13 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 02 Aug 2005 00:52:13 +0200 Subject: namespaces In-Reply-To: <42ee15ba.307192259@news.oz.net> References: <42EC9690.2040301@tiscali.it><dci1r3$g6i$1@sea.gmane.org> <mailman.2450.1122803387.10512.python-list@python.org> <pan.2005.07.31.11.14.22.657414@REMOVETHIScyber.com.au> <mailman.2453.1122812091.10512.python-list@python.org> <1122826472.004836.273980@g43g2000cwa.googlegroups.com> <mailman.2466.1122835539.10512.python-list@python.org> <42ee15ba.307192259@news.oz.net> Message-ID: <42EEA79D.4060000@tiscali.it> Bengt Richter wrote: > Ok, to make the statement execute, execute function: > > >>> function() > >>> a=function.foo > >>> a > 'something' > >>> vars(function) > {'foo': 'something'} > Yep too stupid I've been :) Thanks ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From twic at urchin.earth.li Wed Aug 24 12:49:31 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 24 Aug 2005 17:49:31 +0100 Subject: Should I move to Amsterdam? In-Reply-To: <dehut7$dvc$01$1@news.t-online.com> References: <mailman.3467.1124888360.10512.python-list@python.org> <dehut7$dvc$01$1@news.t-online.com> Message-ID: <Pine.LNX.4.62.0508241746320.24540@urchin.earth.li> On Wed, 24 Aug 2005, Armin Steinhoff wrote: > Adriaan Renting wrote: > >>>>> "Wade" <wade at leftwich.us> 08/24/05 2:31 pm >>> >> >> http://www.slate.com/id/2124561/entry/2124562/ Nice little series by >> Seth Stevenson for Americans daydreaming about emigration. Somewhere, >> anywhere ... maybe Amsterdam? I've never been to the Netherlands >> myself, but it sounds very civilized. > > What a joke ... Amsterdam is 'civilized' since several hundreds of years > :) Indeed. Perhaps we should rename it Old New York to reinforce the point :). But yes, the Netherlands is a highly civilised country - up there with Denmark and Canada, and above the UK, France or Germany, IMNERHO. I'm not going to bother comparing it to the US! tom -- This should be on ox.boring, shouldn't it? From sjmachin at lexicon.net Sat Aug 13 00:45:33 2005 From: sjmachin at lexicon.net (John Machin) Date: Sat, 13 Aug 2005 14:45:33 +1000 Subject: UCALC equivalent In-Reply-To: <42fcea4a$1@nntp0.pdx.net> References: <mailman.3037.1123867031.10512.python-list@python.org> <42FCDCA7.7030107@syscononline.com> <Xns96B08CF2316F2maxericksongmailcom@216.168.3.44> <42fcea4a$1@nntp0.pdx.net> Message-ID: <42fd7aec@news.eftel.com> Scott David Daniels wrote: > max wrote: > >> Larry Bates <lbates at syscononline.com> wrote in >> news:42FCDCA7.7030107 at syscononline.com: >> >>> Python has built in eval function and doesn't require a library. >> >> >> Are you kidding? Read the original post a little more closely. The >> o.p. is looking for a library that evaluates mathematical expressions >> and is callable from python code. > > > He is absolutely correct. > From the web page referenced: > > ucDefineFunction("area(length,width) = length*width"); > ucDefineFunction("frac(x)=abs(abs(x)-int(abs(x)))"); > ucDefineFunction("test() = 5"); > ucDefineFunction("abc(x, y=10) = x + y"); > ucDefineFunction("shl[x, y] = x * 2^y"); > > cout.precision(16); > cout << ucEval("frac(150/17) * area(20,30)") << endl; > cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)") > << endl; > > > The python equivalent: > > exec "def area(length,width): return length*width" > exec "def frac(x): return abs(abs(x) - int(abs(x)))" > exec "def test(): return 5" > exec "def abc(x, y=10): return x + y" > exec "def shl(x, y): return x * 2^y" Perhaps this should be: exec "def shl(x, y): return x * 2 ** y" or exec "def shl(x, y): return x << y" > > print eval("frac(150/17) * area(20,30)") > print eval("abc(5) - abc(3,4) * shl(0x0E, 1)") > > --Scott David Daniels > Scott.Daniels at Acm.Org From gene.tani at gmail.com Thu Aug 11 07:38:25 2005 From: gene.tani at gmail.com (gene tani) Date: 11 Aug 2005 04:38:25 -0700 Subject: regex help In-Reply-To: <mailman.2960.1123728599.10512.python-list@python.org> References: <mailman.2960.1123728599.10512.python-list@python.org> Message-ID: <1123760305.889088.175370@o13g2000cwo.googlegroups.com> when *I* google http://www.awaretek.com/tutorials.html#regular http://en.wikibooks.org/wiki/Programming:Python_Strings http://www.regexlib.com/Default.aspx http://docs.python.org/lib/module-re.html http://diveintopython.org/regular_expressions/index.html#re.intro http://www.amk.ca/python/howto/regex/ http://gnosis.cx/publish/programming/regular_expressions.html also look into ActiveStateKomodo reg ex debugger ( I think WIng IDE has it too From tjreedy at udel.edu Sat Aug 6 16:31:21 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 6 Aug 2005 16:31:21 -0400 Subject: Generalised String Coercion References: <20050806102342.GA11309@mems-exchange.org> Message-ID: <dd36mq$pjr$1@sea.gmane.org> > PEP: 349 > Title: Generalised String Coercion ... > Rationale > Python has had a Unicode string type for some time now but use of > it is not yet widespread. There is a large amount of Python code > that assumes that string data is represented as str instances. > The long term plan for Python is to phase out the str type and use > unicode for all string data. This PEP strikes me as premature, as putting the toy wagon before the horse, since it is premised on a major change to Python, possibly the most disruptive and controversial ever, being a done deal. However there is, as far as I could find no PEP on Making Strings be Unicode, let alone a discussed, debated, and finalized PEP on the subject. > Clearly, a smooth migration path must be provided. Of course. But the path depends on the detailed final target, which has not, as far as I know, has been finalized, and certainly not in the needed PEP. Your proposal might be part of the transition section of such a PEP or of a separate migration path PEP. Terry J. Reedy From jzgoda at o2.usun.pl Tue Aug 23 15:55:06 2005 From: jzgoda at o2.usun.pl (Jarek Zgoda) Date: Tue, 23 Aug 2005 21:55:06 +0200 Subject: setlocale() in a module/extension library In-Reply-To: <873bp0pif9.fsf@mobile.repose.cx> References: <873bp0pif9.fsf@mobile.repose.cx> Message-ID: <defuvr$nfd$1@atlantis.news.tpi.pl> Damien Elmes napisa?(a): > My question is this: it would be nice if every user of my library > didn't need to add the above two lines to their code. But on the other > hand, I'm unsure of the implications of modifying the locale from > within a module, and it doesn't seem very clean. Would calling > setlocale() from a library be a bad thing? If so, any alternative > recommendations would be greatly welcome. I think that many of them does that already, just to get proper display on terminals, proper timezone settings etc. Anyway, setting locale in library doesn't seem to be good, as this may change locale in global application environment (what if user on system with Russian locale sets application locale to de_DE to have german timezone settings?). -- Jarek Zgoda http://jpa.berlios.de/ From could.net at gmail.com Mon Aug 15 21:09:11 2005 From: could.net at gmail.com (could ildg) Date: Tue, 16 Aug 2005 09:09:11 +0800 Subject: How can I exclude a word by using re? In-Reply-To: <430085e8$1@news.eftel.com> References: <mailman.3072.1124029458.10512.python-list@python.org> <430085e8$1@news.eftel.com> Message-ID: <311b5ce1050815180920235835@mail.gmail.com> I want to use re because I want to extract something from a html. It will be very complicated without using re. But while using re, I found that I must exlude a hole word "</td>", certainly, there are many many "</td>" in this html. My re is as below: _____________________________________________ r=re.compile(ur'valign=top>(?P<number>\d{1,2})</td><td[^>]*>\s{0,2}' ur'<a href="(?P<url>[^<>]+\.mp3)"( )target=_blank>' ur'(?P<name>.+)</td>',re.UNICODE|re.IGNORECASE) _____________________________________________ There should be over 30 matches in the html. But I find nothing by re.finditer(html) because my last line of re is wrong. I can't use "(?P<name>.+)</td>" because there are many many "</td>" in the html and I just want the ".*" to match what are before the firest "</td>". So I think if there is some idea I can exclude a word, this will be done. Assume there is "NOT(WORD)" can do it, I just need to write the last line of the re as "(?P<name>(NOT(</td>))+)</td>". But I still have no idea after thinking and trying for a very long time. In other words, I want the "</td>" of "(?P<name>.+)</td>" to be exactly the first "</td>" in this match. And there is more than one match in this html, so this must be done by using re. And I can't use any of your idea because what I want I deal with is a very complicated html, not just a single line of word. I can copy part of the html up to here but it's kinda too lengthy. On 8/15/05, John Machin <sjmachin at lexicon.net> wrote: > could ildg wrote: > > In re, the punctuation "^" can exclude a single character, but I want > > to exclude a whole word now. for example I have a string "hi, how are > > you. hello", I want to extract all the part before the world "hello", > > I can't use ".*[^hello]" because "^" only exclude single char "h" or > > "e" or "l" or "o". Will somebody tell me how to do it? Thanks. > > (1) Why must you use re? It's often a good idea to use string methods > where they can do the job you want. > (2) What do you want to have happen if "hello" is not in the string? > > Example: > > C:\junk>type upto.py > def upto(strg, what): > k = strg.find(what) > if k > -1: > return strg[:k] > return None # or raise an exception > > helo = "hi, how are you? HELLO I'm fine, thank you hello hello hello. > that's it" > > print repr(upto(helo, "HELLO")) > print repr(upto(helo, "hello")) > print repr(upto(helo, "hi")) > print repr(upto(helo, "goodbye")) > print repr(upto("", "goodbye")) > print repr(upto("", "")) > > C:\junk>upto.py > 'hi, how are you? ' > "hi, how are you? HELLO I'm fine, thank you " > '' > None > None > '' > > HTH, > John > -- > http://mail.python.org/mailman/listinfo/python-list > From zen19725 at zen.co.uk Wed Aug 3 07:36:04 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 12:36:04 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> <slrndeu5ia.d1.zen19725@cabalamat.somewhere> <dcnisi$ks6$1@nntp0.reith.bbc.co.uk> Message-ID: <slrndf1b11.129.zen19725@cabalamat.somewhere> On Tue, 02 Aug 2005 11:05:16 +0100, Michael Sparks <michaels at rd.bbc.co.uk> wrote: >Phil Hunt wrote: > >> Kamaelia seems it might be an interesting project. However, I don't >> think the project is well served by this announcement -- which I >> find vague and hard to understand. Which is a shame, because it >> means that other people probably don't understand it very well >> either, which means less people will use it. > >It is a shame, and thanks for mentioning this. Let me have another >go :-) (ripping to shreds welcome :) > >OK, here's a better go. (It's always difficult to think where to pitch >this sort of thing) >---START--- >The project aims to make it simple to build networked multimedia >systems (eg audio, video, interactive systems), There's plenty of software that facilitates networking, for example Python already has software for tcp and http clients/servers, and for xmlrpc remote procedure calls. So what does Kamaelia do that's extra? I imagine it's to to with streaming large amounts of data. For example, a streaming video or audio player. Or VoIP, perhaps. > which are naturally >componentised and naturally concurrent allowing quick and fast reuse in >the same way as Unix pipelines do. OK, so what do the components in the pipelines do? What sort of data do they hold? Unix pipelines act on ascii files; I assume you are do this on audio and visual data. What langauage will the ele,ments in thne pipelines be written it? I assume some will be in C/C++ for speed. >It is designed as a practical toolkit, such that you can build systems >such as: When you say "you" who do you mean? Is the audience programmers or less technical people? A project that allows non-technical people to build complex network applications is an ambitious one, but not impossible (I'd find it very impressive and very exciting, particularly if it runs on devices such as mobile phones). > * Ogg Vorbis streaming server/client systems (via vorbissimple) > * Simple network aware games (via pygame) > * Quickly build TCP based network servers and clients What sort of servers and clients? Serving what? Could I use it, for example, to build a > * Quickly build Multicast based network servers and clients Serving what? Could I use it, for example, to build an n-player encrypted (I mean proper encryption here, the sort GCHQ or the NSA can't break) VoIP server to allow people to do conference calls over the Internet? >It runs on Linux, Window, Mac OS X with a subset running on Series 60 >phones. > >The basic underlying metaphor of a component us like an office worker >with inboxes and outboxes, with deliveries occuring between desks, >offices, and depts. The component can thus do work anyway it likes but >only communicates with these inboxes and outboxes. Like office workers, >components run in parallel, and to achieve this are generally >implemented using python generators, but can also used threads. That metaphor brings up an image (at least to me) that the sorts of data that can be communicated are things like documents, spreadsheets, business graphs, memos. Also the metaphor doesn't indicate any sense of real-time-ness; stuff on an in tray isn't immediately processed and moved to the out tray.I'm pretty certain that's not what you have in mind. May I suggest a different metaphor? Consider a hi-fi system where you plug cables in to control the dataflow. For example, an unamplified audio signal goes into an amp, the amp has various dials and buttons on it, and an amplified signal comes out. Note that the signal processing is done in real time. Is that the sort of thing you are working on? >The rationale behind the project is to provide a toolkit enabling the >development of new protocols, including streaming, for large scale >media delivery. OK, I get the straming part of it. But what asbout non-streaming stuff? What other protocols are necessary? > The license essentially allows use in proprietary >systems without change, but all changes to the system itself must be >shared. Fair enough. >---END--- > >Is that clearer ? > >A short summary of all that could be: > >"""Kamaelia is a networking/communications infrastructure for innovative >multimedia systems. Kamaelia uses a component architecture designed to >simplify creation and testing of new protocols and large scale media >delivery systems.""" > >Hopefully that's clearer than: > >>>Kamaelia is a collection of Axon components designed for network >>>protocol experimentation in a single threaded, select based >>>environment. Axon components are python generators are augmented by >>>inbox and outbox queues (lists) for communication in a communicating >>>sequential processes (CSP) like fashion. > >[ which you noted "I really have very little idea what this means." ] Sort of. But it's still a bit vague. For example: "networking/communications infrastructure" can mean a lot of things. It doesn't even specify whether it is hardware or software. "innovative". This actually has two meanings. One is "is new / allows new things to be built". Another is "meaningless marketing buzzword" (half :-)). I assume you mean the former, but some people may be put off by what sounds like buzzwordspeak. A good short summary would answer these questions: * What broad category does the system fall under? Software or Hardware? (the answer here is software). For what sort of problem-domain? (here the answer is audio and video) * What sort of software is it? An end product, useful in itself? Or a library, from which people can build applications? * Who is it aimed at? Programmers, less-technical users, the genral public? * At what stage of completion is it? This is a question sometimes not answered well by open source projects, which can cause disappointment if a project is at an earlier stage of development than some percieve. And also, a project might have immediate goals that are quite modest, and long-term goals that are more ambitious. >For example, trivial sketches: > * A program to display an image using pygame > * A program that can understand when an area of space has been > clicked. (call it a button) > * A program that can print a list of filenames, pausing waiting for a > user to press return. (call it a chooser) > >Trivial changes: > * Take the filename of the image from an inbox > * Rather than print the filenames to send the filename to an outbox. > * Rather than wait for a user to press a key, wait for a message on > an inbox. > >A useful composition linking some of these together: > >Graphline( > CHOOSER = Chooser(items = files), > IMAGE = Image(size=(800,600), position=(8,48)), > NEXT = Button(caption="Next", msg="NEXT", position=(72,8)), > PREVIOUS = Button(caption="Previous", msg="PREV",position=(8,8)), > linkages = { > ("NEXT","outbox") : ("CHOOSER","inbox"), > ("PREVIOUS","outbox") : ("CHOOSER","inbox"), > ("CHOOSER","outbox") : ("IMAGE","inbox"), > } >).run() That's certainly less lines of code than it would take in Tkinter. And easier to follow. >And you have a simple presentation tool ! Now I'm confused. Is Kamaelia a GUI builder? >Another example. The visualisation framework was originally a stand >alone piece of code and was essentially just a piece of eye candy. I >threw in a few yields into certain locations. File reading & static >graph construction was replaced with recieving data from inboxes, and >then it was available for use (and networked after creating trivial >protocol components). Ah, so now I'm guessing it allows me to write networked PyGame applications, where with just a few lines of code I can have networked streaming video on my pyGame screen... am I right? >A piece of eye candy is now a useful tool. It's likely to gain the >ability to send to an outbox a message saying "this blob is clicked" >meaning we can have 'WYSIWYG' GUI based construction of pipelines >easily. That sounds useful. >Why wouldn't you use it? When Twisted is appropriate (Twisted is a more >mature framework). The problem with Twisted, IME, is I don't understand the documentation. -- Email: zen19725 at zen dot co dot uk From jitendran at productdossier.com Wed Aug 24 07:48:07 2005 From: jitendran at productdossier.com (jitya) Date: 24 Aug 2005 04:48:07 -0700 Subject: Inheritance problem ? References: <1124879676.525583.14390@g44g2000cwa.googlegroups.com> Message-ID: <1124884087.421461.153190@g43g2000cwa.googlegroups.com> tooper wrote: > Hello all, > > I'm trying to implement a common behavior for some object that can be > read from a DB or (when out of network) from an XML extract of this DB. > I've then wrote 2 classes, one reading from XML & the other from the > DB, both inheritating from a common one where I want to implement > several common methods. > Doing this, I've come to some behaviour I can't explain to myself, > which I've reproduced in the example bellow : > > ----- > > class myfather: > def __repr__(self): > return "\t a="+self.a+"\n\t b="+self.b > > class mychilda(myfather): > def __init__(self,a): > self.a= a > def __getattr__(self,name): > return "Undefined for mychilda" > > class mychildb(myfather): > def __init__(self,b): > self.b= b > def __getattr__(self,name): > return "Undefined for mychildb" > > a= mychilda("a") > b= mychildb("b") > > print "a:\n"+str(a) > print "b:\n"+str(b) > > ----- > > I was expecting to get : > > a: > a= a > b= Undefined for mychilda > b: > a= Undefined for mychildb > b= b > > but I get the following error : > > File "/home/thierry/mytest.py", line 20, in ? > print "a:\n"+str(a) > TypeError: 'str' object is not callable > > Could someone explain me what I missed ? > > Thanks in advance ! hi I am got python 2.4 and changed "class myfather" to new style classes "class myfather(object)" it worked. here is the output : a: a=a b=Undefined for mychilda b: a=Undefined for mychildb b=b But i myself still need explaination ;) regards jitu From peter at engcorp.com Wed Aug 31 08:15:40 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 31 Aug 2005 08:15:40 -0400 Subject: .pth files in working directory In-Reply-To: <df3vjc$4o4$1@swifty.westend.com> References: <df3vjc$4o4$1@swifty.westend.com> Message-ID: <T5KdnfnERZn0AojeRVn-oQ@powergate.ca> Peter Maas wrote: > My goal is to have the top level of a directory tree in the Python > path without touching anything outside the directory. I tried to > create .pth files with the top level path in every subdirectory > but this doesn't work despite working directory being part of the > Python path. > > Creating the pth file in .../site-packages works but I prefer to > have everything inside the directory tree so that removing the tree > is sufficient for a complete uninstall. Any hints are appreciated, > thanks. Not sure from the above description exactly what it is you want, but generally such non-standard sys.path and .pth manipulations are best handled by a sitecustomize.py file, possibly which makes its own calls to site.addsitedir() and such. Try "help(site)" for more. In this case, I think you'd have a sitecustomize.py which looks for .pth files in the current directory and calls site.addsitedir(), but I'm not sure. Maybe if this doesn't work, an example would clarify things. -Peter From richardjones at optushome.com.au Sat Aug 20 20:50:55 2005 From: richardjones at optushome.com.au (richard) Date: Sun, 21 Aug 2005 10:50:55 +1000 Subject: Update: Python Game Programming Challenge Message-ID: <4307cfef$0$8999$afc38c87@news.optusnet.com.au> The Python Game Programming Challenge (otherwise known as PyWeek) is only a week away from starting! Theme voting has started! http://www.mechanicalcat.net/tech/PyWeek/1 Richard From DavidF at homegain.com Fri Aug 19 17:56:37 2005 From: DavidF at homegain.com (David Fickbohm) Date: Fri, 19 Aug 2005 14:56:37 -0700 Subject: trying to check the creation date of a file Message-ID: <C0F6DD0E8F3B9040A77F857FCFAC452A051CF657@hqsxch01.homegain.com> People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an idea how to check a creation date it would be appreciated. Thanks dave def delete_old_files (t:\dm\~\users) # find files and delete files created more than XX number of days ago update_exist = 0 input_dir = t:\dm\~\users\xxxx.yyyyyy\zzzz if os.path.exists (input_dir) : files = os.listdir (input_dir) else: print "Unable to find input file dir: %s !!!" % input_dir sys.exit(2) if len(files): for file in files : file = os.path.join(input_dir) #all files in output directory will be csv or xls, can be deleted if old enough if os.path.isfile(file): #need to check ext not file, file name changes each day if re.search(t:\dm\~\users\xxxxx\) and #creation date gt x number of days ago t:\dm\~\users\davef.input_list.delete(file) file_delete = 1 if file_delete: print "\n file deleted: \n%s" % str(t:\dm\~\users\xxxxx.input_list) return file_delete Dave Fickbohm Data Mining Analyst Homegain+ 1250 45th St. Emeryville, CA, 94608 Phone 510 594 4151 - Voice 510 655 0848 - Fax From temposs at gmail.com Tue Aug 2 15:20:35 2005 From: temposs at gmail.com (temposs at gmail.com) Date: 2 Aug 2005 12:20:35 -0700 Subject: a pickle's pickle In-Reply-To: <mailman.2637.1123010033.10512.python-list@python.org> References: <1122998518.750304.191860@g44g2000cwa.googlegroups.com> <dco7bc$msl$1@wake.carmen.se> <1123003411.326539.300220@g47g2000cwa.googlegroups.com> <mailman.2637.1123010033.10512.python-list@python.org> Message-ID: <1123010435.733750.300680@g14g2000cwa.googlegroups.com> Benji, Thanks so much, you have saved the day ^_^ From martin at v.loewis.de Sun Aug 21 10:28:36 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 21 Aug 2005 16:28:36 +0200 Subject: pythonXX.dll size: please split CJK codecs out In-Reply-To: <8xWNe.24050$HM1.696102@twister1.libero.it> References: <iOLNe.23176$F23.275935@twister2.libero.it> <43082c5f$0$31577$9b622d9e@news.freenet.de> <8xWNe.24050$HM1.696102@twister1.libero.it> Message-ID: <43088f95$0$31585$9b622d9e@news.freenet.de> Giovanni Bajo wrote: > FWIW, this just highlights how ineffecient your build system is. Everything you > currently do by hand could be automated, including MSI generation. Also, you > describe the Windows procedure, which I suppose it does not take into account > what needs to be done for other OS. But I'm sure that revamping the Python > building system is not a piece of cake. You are wrong. It is not true that everything I do by hand could be automated. Atleast after automation, I still would have to do things by hand, namely invoke the automation. You probably haven't looked at the MSI generation at all: it *is* automatic. However, everytime something changes in the structure, the code generating the MSI must be adjusted to the new structure. > I'll take the point though: it's easier to maintain for developers, and most > Python users don't care. See, this I find surprising. If there really is such a big need for python24.dll being split in many more modules - why doesn't anybody just do this, and offers it as a separate installation for use with py2exe? The fact that this hasn't happened indicates that users don't need it badly enough. I personally rarely need to create a standalone Python application, but when I did, I just used freeze, and static linking. That way, I got a single binary, with no magic packaging, and a minimal one, too. >>In addition, having everything in a single DLL speeds up Python >>startup a little, since less file searching is necessary. > > I highly doubt this can be noticed in an actual benchmark, but I could be > wrong. I can produce numbers though, if this can help people decide. No, this is a minor issue. If you do write a PEP, and you find it relatively easy to compare the maximum modularization to the minimal one, it would be useful to underline your point, of course. > I'm willing to write up such a PEP, but it's hard to devise an universal > policy. Indeed. For Python 2.4, I made up a policy for myself: everything that does not depend on a separate (non-system) library goes into pythonxy.dll. That way, everybody will be able to compile Python from sources without downloading anything else, yet it causes minimum maintenance overhead. That's how the current python24.dll came about. > Basically, the only element we can play with is the size of the > resulting binary for the module. Would you like a policy like "split out every > module whose binary on Windows is > X kbytes?". It's less important what I like - I think I would ask for a poll on the proposed PEP, and I would be -1 on anything that means more work for contributors. But that would be only one voice, and, if a majority of the Windows Python users preferred your policy, it would be implemented (of course, somebody contributing the resulting project files or some automation for them would also help). > My personal preference would go to something "make python2x.dll include only > the modules which are really core, like sys and os". This would also provide > guidance to future modules, as they would simply go in external modules (I > don't think really core stuff is being added right now). Ok, then write that into the PEP. You would have to provide a definition for "core", e.g. "everything that is needed for startup". As a guideline, the Unix build process currently includes only the following modules by default: - marshal, imp, __main__, __builtin__, sys, exceptions: Modules living in Python/*.c - gc, signal: invoked directly from the interpreter - thread: not sure - posix, errno, _sre, _codecs, so that setup.py can run - zipimport, to avoid bootstrapping problems for importing python24.zip - _symtable, because setup.py cannot get the dependencies right - xxsubtype, for an undocumented reason I forgot Regards, Martin From lars at gustaebel.de Sun Aug 28 03:22:42 2005 From: lars at gustaebel.de (=?iso-8859-1?q?Lars_Gust=E4bel?=) Date: Sun, 28 Aug 2005 09:22:42 +0200 Subject: problems with tarfile.open and tar.bz2 References: <1125072329.310958.20650@g43g2000cwa.googlegroups.com> Message-ID: <pan.2005.08.28.07.22.42.684158@gustaebel.de> On Fri, 26 Aug 2005 09:05:29 -0700, justin.vanwinkle wrote: > Hello everyone, > > I need some tar functionality for my program. Currently the following > code properly displays tar archives, and tar.gz archives. However, it > chokes on tar.bz2 archives with the following error: > > File "mail_filter.py", line 262, in extract_archive > tar_archive = tarfile.open('', 'r', fileobj) > File "/usr/lib/python2.3/tarfile.py", line 900, in open > return func(name, "r", fileobj) > File "/usr/lib/python2.3/tarfile.py", line 980, in bz2open > raise ValueError, "no support for external file objects" > ValueError: no support for external file objects The problem here is that the bz2.BZ2File class that tarfile.py uses to access tar.bz2 files has no support for an external file-object argument. In contrast to gzip.GzipFile, it works solely on real files. This limitation is somewhat annoying, but so far no one took the trouble changing the bz2 module. If your program does not rely on random access to the tar.bz2 file, you can still use the "r|bz2" stream mode: tar_archive = tarfile.open(mode="r|bz2", fileobj=StringIO.StringIO(attach)) for tarinfo in tar_archive: print tarinfo.name print tar_archive.extractfile(tarinfo).read() tar_archive.close() -- Lars Gust?bel lars at gustaebel.de From fbarbuto2002.no at spam.yahoo.ca Thu Aug 11 23:27:44 2005 From: fbarbuto2002.no at spam.yahoo.ca (Fausto Arinos Barbuto) Date: Fri, 12 Aug 2005 03:27:44 GMT Subject: How do these Java concepts translate to Python? References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <QGUKe.193376$5V4.71993@pd7tw3no> Ray wrote: > 1. Where are the access specifiers? (public, protected, private) AFAIK, there is not such a thing in Python. ---Fausto From stewart.midwinter at gmail.com Mon Aug 29 16:31:43 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Mon, 29 Aug 2005 14:31:43 -0600 Subject: suggestion for Python graphing package, please Message-ID: <d4c0d4800508291331f9e0031@mail.gmail.com> I need a graphing library that I can access from within a Tkinter application running on Windows. It needs to be able to draw some *simple* 2D plots, and then output them to a file (e.g. .PNG, .JPG) for inclusion in a HTML-formatted e-mail to interested parties. Many of the packages that I've looked at a) either don't output to a file, or b) are very old (3-5 years), or c) don't run on Windows. I don't actually care if the library itself is written in Python or c++ or something else. Any suggestions? thanks, -- Stewart Midwinter stewart at midwinter.ca stewart.midwinter at gmail.com Skype:midtoad GoogleTalk:midtoad iChatAV:midtoad MSN:midtoad Yahoo:midtoad AIM:midtoad1 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20050829/8da7e4ad/attachment.html> From peter at engcorp.com Mon Aug 8 08:07:30 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 08 Aug 2005 08:07:30 -0400 Subject: Python -- (just) a successful experiment? In-Reply-To: <7xpsso3jih.fsf@ruckus.brouhaha.com> References: <20050807005406.1217660123.whereU@now.com> <mailman.2810.1123403537.10512.python-list@python.org> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <mailman.2832.1123468020.10512.python-list@python.org> <7xpsso3jih.fsf@ruckus.brouhaha.com> Message-ID: <A9ydnZ2dnZ1sCtGtnZ2dnffWat-dnZ2dRVn-zp2dnZ0@powergate.ca> Paul Rubin wrote: > I dunno about PyGTK but one of the more common complaints about > wxPython is that it's not Pythonic enough. And wxPython is probably > the most popular Python GUI toolkit after Tkinter. So people don't > want C wrappers. I think what they mostly want is a wide choice of > good looking widgets. They don't like Tkinter because its widget set > is limited and what widgets it does have, look like crap. I not only didn't like the look of Tkinter (but could have lived with it if that's all that was wrong with it), but I also simply couldn't figure out how to make it do the things I wanted to do. Fairly simple things, I thought, yet things that would have (apparently) required delving deeply into the innards or obscure documentation to figure out how to do it. In some cases, after extensive efforts to develop my own, I would stumble across an example of what I wanted. Often I was surprised to find that it was relatively simple solution, yet it was always unclear to me how I would have figured out something like that on my own. With wxPython, I don't like the non-Pythonic nature any more than I liked the non-Pythonic nature of Tkinter. I don't use the wider set of existing widgets very much, since often I need to roll my own anyway. I can always, however, figure out how to get what I want done, and it usually doesn't take me very long to do it. wxPython fits my brain. Tkinter didn't. YMMV. C wrappers? Existing widget sets? Pythonic nature? None of these were really interesting or important to me.** Getting stuff done, that was important. I was and am able to do that with wxPython while with Tkinter I was not. (And no, folks, this isn't a flame against Tkinter at all. I fully appreciate that the "problem" was me, since many others are capable of getting the results they need from the framework. But they weren't sitting next to me when I needed them. ;-) ) FWIW, -Peter ** "Pythonic nature" is actually of interest, but it's definitely not an overriding concern when you have work to do. From martin.witte at gmail.com Mon Aug 29 05:20:07 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 29 Aug 2005 02:20:07 -0700 Subject: Question In-Reply-To: <1125270985.457418.17830@g44g2000cwa.googlegroups.com> References: <1125270985.457418.17830@g44g2000cwa.googlegroups.com> Message-ID: <1125307207.360246.122550@g44g2000cwa.googlegroups.com> Much more useful stuff for beginners is here: http://wiki.python.org/moin/BeginnersGuide From saint.infidel at gmail.com Thu Aug 18 15:31:52 2005 From: saint.infidel at gmail.com (infidel) Date: 18 Aug 2005 12:31:52 -0700 Subject: threadsafety in cherrypy with kid Message-ID: <1124393512.774098.33250@f14g2000cwb.googlegroups.com> I have just recently discovered CherryPy and Kid (many kudos to the respective developers!) and am tinkering with them to see what I can come up with. The application I eventually want to write will eventually require the python code to call stored procedures in a database which means I'll need to run CherryPy with a threadPool so individual database calls don't block the whole server. I'm not to that point yet, I'm just getting a feel for what is possible, and I wanted to make sure the following usage of my Kid template (named "index") is threadsafe: from cherrypy import cpg import kid; kid.enable_import() from infidel.web import index class Root(object): @cpg.expose def index(self, *args, **kwargs): count = cpg.request.sessionMap.get('count', 0) + 1 cpg.request.sessionMap['count'] = count template = index.Template(times=count) return template.serialize(output='html-strict') if __name__ == '__main__': cpg.root = Root() cpg.server.start(configFile = 'web.ini') Does it matter that I've done the import of index at the module level instead of inside the index method? The example at the CherryPy recipes site does this: from cherrypy import cpg import kid class HomePage: def index(self): test = kid.Template(file='test.kid') test.title = "Test Kid Page" test.lines = ['qwe','asd','zxc'] return test.serialize(output='xhtml') index.exposed = True if __name__ == "__main__": cpg.root = HomePage() cpg.server.start() Is there a qualitative difference between what I've done and what the examle does? From billiejoex at fastwebnet.it Mon Aug 15 08:51:10 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Mon, 15 Aug 2005 14:51:10 +0200 Subject: sniffer in python References: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> <0KmdncVnD80_Hp3eRVn-rw@powergate.ca> Message-ID: <fd0Me.7604$zs.6172@tornado.fastwebnet.it> Thank you for your fast reply. You're right. I'll be more specific, sorry. The example source is the one you can find on the 'Impacket' page on the same site of pcapy: http://oss.coresecurity.com/impacket/sniff.py I use a Win XP prof sp2 system, python ver. 2.4.1. Here's the output: C:\Python24>1.py Traceback (most recent call last): File "C:\Python24\1.py", line 107, in ? main(filter) File "C:\Python24\1.py", line 88, in main dev = getInterface() File "C:\Python24\1.py", line 81, in getInterface print '%i - %s' % (count, iface) File "C:\Python23\lib\encodings\cp850.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode characters in position 4-19: ch aracter maps to <undefined> >> For python exist a porting called pcapy: >> http://oss.coresecurity.com/projects/pcapy.html >> ...that I'd like to use BUT... all the examples reported on the sites >> don't works!! > > It usually helps to describe *in what way* things don't work. > > Do they crash? If so, provide the full traceback. > > Do they not install? If so, provide error messages. > > Do they appear to run but without visible signs of activity? If so, say > so... and describe exactly what options you were using, what platform and > version of platform, Python, and library you are using, and any other > conditions relevant to the situation. > > Help us help you... > > (Alternative suggestion: use whatever mailing list is provided for that > specific project, if there is one, so you get access to more people with > direct knowledge of what might go wrong.) > > -Peter From rkern at ucsd.edu Thu Aug 25 18:07:52 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 15:07:52 -0700 Subject: a dummy python question In-Reply-To: <1125006812.641866.125150@g44g2000cwa.googlegroups.com> References: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> <1125006812.641866.125150@g44g2000cwa.googlegroups.com> Message-ID: <delffo$e7t$1@sea.gmane.org> infidel wrote: > Learning Python wrote: > >>A example in learning Python by Mark Lutz and David Ascher >> >>about function scope >> >>example like this: >> >> >>>>def outer(x): >> >> def inner(i): >> print i, >> if i: inner(i-1) >> inner(x) >> >>>>outer(3) >> >>Here supposely, it should report error, because the function inner >>cannot see itself since inner is only in local namespace of outer. > > If that were so, Pythonistas could never write a recursive function! No, presumably at the writing of the edition of _Learning Python_ that he is reading, Python did not have nested scopes in the language, yet. One could always write a recursive function provided it was at the top-level of the module. One could not write a recursive function inside another function because inside inner(), it could only access two namespaces, the one local to inner() and the module's namespace, not the namespace of outer() where inner() is defined. For the original poster: Your book is old. You will want to catch up on recent additions to the language by reading the "What's New in Python 2.x" portions of the documentation for each major revision. Specifically: http://www.python.org/doc/2.2.3/whatsnew/node9.html http://www.python.org/doc/2.2.3/whatsnew/whatsnew22.html http://www.python.org/doc/2.3.5/whatsnew/whatsnew23.html http://www.python.org/doc/2.4.1/whatsnew/whatsnew24.html -- 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 Sat Aug 6 20:10:58 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 06 Aug 2005 20:10:58 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) In-Reply-To: <86br4avf5t.fsf@bhuda.mired.org> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <C9udnRprcKxjImnfRVn-tA@powergate.ca> <11f9u843r0fts5b@news.supernews.com> <86br4avf5t.fsf@bhuda.mired.org> Message-ID: <F-ednYFnrNBizGjfRVn-2w@powergate.ca> Mike Meyer wrote: > "John Roth" <newsgroups at jhrothjr.com> writes: >>The world is moving on, in ways that I think you're not seeing. >>And Python is standing still in many of those same ways. > > I find it hilarious that this arrived at my news server the same day > that Peter Hansens rant (look for the subject "Syntax error after > upgrading to Python 2.4") about Python changing to fast did. ?? Which rant was that? I posted only one message in that thread, and it wasn't a rant (according to my definition of the term... what's yours?) and it wasn't even about Python changing too fast. At least, I didn't mean it to be about that. Did you really interpret it that way? -Peter From michele.simionato at gmail.com Tue Aug 2 04:24:53 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 2 Aug 2005 01:24:53 -0700 Subject: doctest bug with nested triple quotes In-Reply-To: <mailman.2598.1122959486.10512.python-list@python.org> References: <1122957696.085082.293440@o13g2000cwo.googlegroups.com> <mailman.2598.1122959486.10512.python-list@python.org> Message-ID: <1122971093.908618.284710@g49g2000cwa.googlegroups.com> This is my file $ python -c "print open('x.py').read().encode('base64')" IiIiCj4+PiBkdW1teSA9ICcnJwpzb21ldGhpbmcKaGVyZQonJycKIiIiCmltcG9ydCBkb2N0ZXN0 OyBkb2N0ZXN0LnRlc3Rtb2QoKQo= but anyway I think Peter Otten is right, the problem is with the missing dots. It makes sense, actually, but for some reason I would never have thought of it (I did not expect doctest to be so smart to strip the dots even inside a string). Thanks for the feeback and the quick solution, Michele Simionato From sjmaster at gmail.com Wed Aug 31 15:18:39 2005 From: sjmaster at gmail.com (Steve M) Date: 31 Aug 2005 12:18:39 -0700 Subject: Mapping network drive on Linux In-Reply-To: <1125515126.166481.61750@g47g2000cwa.googlegroups.com> References: <1125515126.166481.61750@g47g2000cwa.googlegroups.com> Message-ID: <1125515919.083814.38910@f14g2000cwb.googlegroups.com> You can approximate it by doing this at the command prompt: # mkdir /z #mount //blah/data /z I assume 'blah' is the hostname for a Windows machine and 'data' is the name of a share on blah. You might need to install smbfs and/or use 'mount.smb' and/or use 'mount -t smbfs'. Of course this can all be done as a matter of Linux system administration and not as part of your python program. (To do it within Python, take the string you would type at the command prompt and call os.system() on it.) If my assumption is wrong then the answer depends on what you mean by 'map a network drive to a local drive'. From rudigreen at rogers.com Sun Aug 14 01:33:06 2005 From: rudigreen at rogers.com (Rudi Grinberg) Date: Sun, 14 Aug 2005 01:33:06 -0400 Subject: Testing Message-ID: <hIWdnYjhNsYRSmPfRVn-hw@rogers.com> nothing to see From john at castleamber.com Fri Aug 26 07:05:19 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 11:05:19 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <Xns96BD814C9C690castleamber@130.133.1.4> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8391F6ogbU1@individual.net> Message-ID: <Xns96BE3DCCE99C4castleamber@130.133.1.4> usenet at isbd.co.uk wrote: > "NNTP and its applications" have evolved to provide a set of much more > sophisticated means of accessing and giving information than any forum > I've ever seen. Example(s). And do users need those sophisticated things? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From redhackgp at rediffmail.com Mon Aug 1 01:12:47 2005 From: redhackgp at rediffmail.com (Gurpreet Sachdeva) Date: 1 Aug 2005 05:12:47 -0000 Subject: Operator Overloading Message-ID: <20050801051247.10135.qmail@webmail29.rediffmail.com> Hi, Is there any provision in python which allows me to make my own operators? My problem is that I need to combine two dictonaries with their keys and I don't want to use any of the existing operators like '+','-','*'. So is there a way I can make '**' or '~' as my operators to add two dictonaries? If not which all operators can I overoad? Thanks, Garry http://garrythegambler.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20050801/a41c7044/attachment.html> From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 26 14:57:11 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 26 Aug 2005 20:57:11 +0200 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRVn-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <WZaPe.1953$eQ.899@newssvr30.news.prodigy.com> <mailman.3485.1124942826.10512.python-list@python.org> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <slrndgtka9.1qv.apardon@rcpc42.vub.ac.be> <vpBPe.549$MN5.241@newssvr25.news.prodigy.net> <mailman.37.1125074193.8229.python-list@python.org> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: <3n9707Ffik2U1@individual.net> Bryan Olson wrote: > Steve Holden wrote: > > Bryan Olson wrote: > >> Antoon Pardon wrote: > > >> > It probably is too late now, but I always felt, find should > >> > have returned None when the substring isn't found. > >> > >> None is certainly a reasonable candidate. > [...] > >> The really broken part is that unsuccessful searches return a > >> legal index. > >> > > We might agree, before further discussion, that this isn't the most > > elegant part of Python's design, and it's down to history that this tiny > > little wart remains. > > I don't think my proposal breaks historic Python code, and I > don't think it has the same kind of unfortunate subtle > consequences as the current indexing scheme. You may think the > wart is tiny, but the duct-tape* is available so let's cure it. > > [*] http://www.google.com/search?as_q=warts+%22duct+tape%22 Well, nobody stops you from posting this on python-dev and be screamed at by Guido... just-kidding-ly Reinhold From renting at astron.nl Wed Aug 24 08:58:39 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 24 Aug 2005 14:58:39 +0200 Subject: Should I move to Amsterdam? Message-ID: <s30c8b3f.040@server7.nfra.nl> Well, I'm not sure if Amsterdam is nice, but the Netherlands is o.k., except for the weather. I'd like to descripbe it as 49 weeks of autumn, 1 week of spring, 1 week of summer, 1 week of winter. Currently my employer only has an opening for a Microwave Antenna designer though, sorry no Python coders. http://www.astron.nl/astron/jobs/index.htm Seems like a nice column, I'll read it completely some other time. >>>"Wade" <wade at leftwich.us> 08/24/05 2:31 pm >>> http://www.slate.com/id/2124561/entry/2124562/ Nice little series by Seth Stevenson for Americans daydreaming about emigration. Somewhere, anywhere ... maybe Amsterdam? I've never been to the Netherlands myself, but it sounds very civilized. Extra Python connection, besides the obvious one: Is "gezellig" related to the Zen of Python? ( http://wordcraft.infopop.cc/eve/ubb.x/a/tpc/f/6351024471/m/2041067571/r/3901049571 ) -- Wade Leftwich Ithaca, NY -- http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Fri Aug 26 17:02:43 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Aug 2005 17:02:43 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk><1124160882.554543.75730@g43g2000cwa.googlegroups.com><m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk><wMOdnW4N1cAeAZneRVn-2g@comcast.com><VoOdnZAkbdDgO5neRVn-hg@comcast.com><EpLNe.824$GV7.650@newssvr25.news.prodigy.net><WZaPe.1953$eQ.899@newssvr30.news.prodigy.com><mailman.3485.1124942826.10512.python-list@python.org><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><slrndgtka9.1qv.apardon@rcpc42.vub.ac.be><vpBPe.549$MN5.241@newssvr25.news.prodigy.net><mailman.37.1125074193.8229.python-list@python.org><7sJPe.573$MN5.131@newssvr25.news.prodigy.net><mailman.43.1125084774.8229.python-list@python.org> <7xmzn41ofc.fsf@ruckus.brouhaha.com> Message-ID: <deo01j$gvk$1@sea.gmane.org> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xmzn41ofc.fsf at ruckus.brouhaha.com... > "Terry Reedy" <tjreedy at udel.edu> writes: >>Str.find is >> redundant with the Pythonic exception-raising str.index >> and I think it should be removed in Py3. > > I like having it available so you don't have to clutter your code with > try/except if the substring isn't there. But it should not return a > valid integer index. The try/except pattern is a pretty basic part of Python's design. One could say the same about clutter for *every* function or method that raises an exception on invalid input. Should more or even all be duplicated? Why just this one? Terry J. Reedy From DRNewcomb at attglobal.NOT.net Thu Aug 11 22:22:19 2005 From: DRNewcomb at attglobal.NOT.net (Donald Newcomb) Date: Thu, 11 Aug 2005 21:22:19 -0500 Subject: NEWB: General purpose list iteration? Message-ID: <42fc13f4_4@news1.prserv.net> I'm a real Python NEWB and am intrigued by some of Python's features, so I'm starting to write code to do some things to see how it works. So far I really like the lists and dictionaries since I learned to love content addressability in MATLAB. I was wondering it there's a simple routine (I think I can write a recurisve routine to do this.) to scan all the elements of a list, descending to lowest level and change something. What I'd like to do today is to convert everything from string to float. So, if I had a list of lists that looked like: [['1.1', '1.2', '1.3'], [['2.1', '2.2'], [['3.1', '3.2'], ['4.1', '4.2']]]] and I'd like it to be: [[1.1, 1.2, 1.3], [[2.1, 2.2], [[3.1, 3,2], [4.1, 4.2]]]] is there just a library routine I can call to do this? Right now, I'm using 'for' loops nested to the maximum depth anticipated. for i in range(len(list)): for j in range(len(list[i])): for k in range(len(list[i][j])): etc list[i][j][...] = float(list[i][j][....]) Which works but is not pretty. I was just looking for a way to say: listb = float(lista) However, the way I've started jamming everything into lists and dictionaries, I'm sure I'll be needing to do other in-place conversions similar to this in the future. -- Donald Newcomb DRNewcomb (at) attglobal (dot) net From piet at cs.uu.nl Sat Aug 27 14:37:31 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 27 Aug 2005 20:37:31 +0200 Subject: global interpreter lock References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <zGJNe.242$Ux3.75@newssvr21.news.prodigy.com> <868xyw9g30.fsf@bhuda.mired.org> <As_Oe.654$dw4.615@newssvr29.news.prodigy.net> <86slwymx79.fsf@bhuda.mired.org> <slrndgv04g.264.zen19725@cabalamat.somewhere> <7xoe7kjsag.fsf@ruckus.brouhaha.com> Message-ID: <wzwtm72plg.fsf@ordesa.local> >>>>> Paul Rubin <http://phr.cx at NOSPAM.invalid> (PR) wrote: >PR> zen19725 at zen.co.uk (phil hunt) writes: >>> >Let's see. Reality is that writing correct programs is hard. Writing >>> >correct programs that use concurrency is even harder, because of the >>> >exponential explosion of the order that operations can happen >>> >in. Personally, I'm willing to use anything I can find that makes >>> >those tasks easier. >>> >>> Indeed so. Use threading (or whatever) when one has to, use an >>> asynchronous single-threaded process whenever you can. >PR> This is silly. You could say the exact same thing about if >PR> statements. The number of paths through the program is exponential in >PR> the number of if statements executed. So we better get rid of if >PR> statements. >PR> Really, the essence of programming is to find ways of organizing the >PR> program to stay reliable and maintainable in the face of that >PR> combinatorial explosion. That means facing the problem and finding >PR> solutions, not running away. The principle is no different for >PR> threads than it is for if statements. The principle is (more or less) similar, but for parallel programs it is an order of magnitude more complicated. Compare the correctness proofs of parallel programs with those of sequential programs. -- Piet van Oostrum <piet at cs.uu.nl> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From mwm at mired.org Sat Aug 6 18:54:16 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 06 Aug 2005 18:54:16 -0400 Subject: Proposed new collection methods Message-ID: <86d5oqvfqf.fsf@bhuda.mired.org> Another thread pointed out a couple of methods that would be nice to have on Python collections: find and inject. These are taken from <URL: http://martinfowler.com/bliki/CollectionClosureMethod.html >. find can be defined as: def find(self, test = None): for item in self: if test: if test(item): return item elif item: return item return ValueError, '%s.index(): no matching items in list' \ % self.__class__.__name__ find with no arguments is identical to the any function <URL: http://www.artima.com/forums/flat.jsp?forum=106&thread=98196 > that Guido has already accepted <URL: http://mail.python.org/pipermail/python-dev/2005-March/052010.html >, except it's a method. find raises a ValueError so that you can search for any value. This also keeps it's behavior similar to index. An alternative to adding a new method to collections would be adding a new keyword argument - test - to the list index method. This would remove the overlap of functionality with any. However, it would also mean you couldn't use it on anything but lists (and presumably strings). I'm not sure how serious a restriction that is. inject is basically an OO version of reduce. You can define it in terms of reduce: def inject(self, op, init = None): return reduce(op, self, init) The arguments against reduce probably apply to it as well. But it makes the pain from removing reduce vanish. These have probably been proposed before, but under other names. If so, I'd appreciate pointers to the discussion. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From paolo_veronelli at tiscali.it Fri Aug 12 11:55:18 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Fri, 12 Aug 2005 17:55:18 +0200 Subject: simpli int/str problem In-Reply-To: <8c05f79c05081207443094dc67@mail.gmail.com> References: <8c05f79c05081207443094dc67@mail.gmail.com> Message-ID: <42FCC666.7030805@tiscali.it> sinan . wrote: > hi all, > i have a string and int values in same dictionary like this > dict = {'str_name': 'etc' , 'int_name' : 112 } > the error occures when do this > SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + dict['str_name'] + "', > '" + dict['int_name'] + "')" > cursor.execute(SQL) > python does not accep dict['int_name'] in SQL variable but when i > convert this variable to the str , python accepts but i cannot insert > that into database because database only accept int in `BH ` > thanks. Try use: SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('%s,%d)"%(dict['str_name'],dict['int_name']) Paolino ___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com From jack at performancedrivers.com Sun Aug 14 10:13:54 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Sun, 14 Aug 2005 10:13:54 -0400 Subject: Permutation Generator In-Reply-To: <Michael.J.Fromberger-27BD71.15483812082005@localhost> References: <mailman.3042.1123875574.10512.python-list@python.org> <Michael.J.Fromberger-27BD71.15483812082005@localhost> Message-ID: <20050814141354.GB1547@performancedrivers.com> On Fri, Aug 12, 2005 at 03:48:38PM -0400, Michael J. Fromberger wrote: > In article <mailman.3042.1123875574.10512.python-list at python.org>, > Talin <talin at acm.org> wrote: > > > I'm sure I am not the first person to do this, but I wanted to share > > this: a generator which returns all permutations of a list: > > You're right that you're not the first person to do this: Many others > have also posted incorrect permutation generators. > Amen, combinatorics are so popular they should be in the FAQ. groups.google.com can show you many pure python recipies and benchmarks, but I'll give my ususal response: http://probstat.sourceforge.net/ I'm not just the author, I'm a client-ly, -jackdied From sjmachin at lexicon.net Thu Aug 11 19:13:05 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 09:13:05 +1000 Subject: Regular expression to match a # In-Reply-To: <1123801101.340465.282320@g43g2000cwa.googlegroups.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <mailman.2973.1123759573.10512.python-list@python.org> <Xns96AF85EE68544duncanbooth@127.0.0.1> <42fb45d7$1@news.eftel.com> <ddg0ef$7q6$1@panix1.panix.com> <42fbb9a9$1@news.eftel.com> <1123799252.257355.158320@f14g2000cwb.googlegroups.com> <42fbd1a1$1@news.eftel.com> <1123801101.340465.282320@g43g2000cwa.googlegroups.com> Message-ID: <42fbdb81$1@news.eftel.com> Devan L wrote: > John Machin wrote: > >>Devan L wrote: >> >>>John Machin wrote: >>> >>> >>>>Aahz wrote: >>>> >>>> >>>>>In article <42fb45d7$1 at news.eftel.com>, >>>>>John Machin <sjmachin at lexicon.net> wrote: >>>>> >>>>> >>>>> >>>>>>Search for r'^something' can never be better/faster than match for >>>>>>r'something', and with a dopey implementation of search [which Python's >>>>>>re is NOT] it could be much worse. So please don't tell newbies to >>>>>>search for r'^something'. >>>>> >>>>> >>>>>You're somehow getting mixed up in thinking that "^" is some kind of >>>>>"not" operator -- it's the start of line anchor in this context. >>>> >>>>I can't imagine where you got that idea from. >>>> >>>>If I change "[which Python's re is NOT]" to "[Python's re's search() is >>>>not dopey]", does that help you? >>>> >>>>The point was made in a context where the OP appeared to be reading a >>>>line at a time and parsing it, and re.compile(r'something').match() >>>>would do the job; re.compile(r'^something').search() will do the job too >>>>-- BECAUSE ^ means start of line anchor -- but somewhat redundantly, and >>>>very inefficiently in the failing case with dopey implementations of >>>>search() (which apply match() at offsets 0, 1, 2, .....). >>> >>> >>>I don't see much difference. >> >>and I didn't expect that you would -- like I wrote above: "Python's re's >>search() is not dopey". > > > Your wording makes it hard to distinguish what exactly is "dopey". > """ dopey implementations of search() (which apply match() at offsets 0, 1, 2, .....). """ The "dopiness" is that the ^ operator means that the pattern cannot possibly match starting at 1, 2, 3, etc but a non-optimised search will not recognise that and will try all possibilities, so the failing case takes time dependant on the length of the string. From araki at hotmail.com Fri Aug 19 14:37:02 2005 From: araki at hotmail.com (araki at hotmail.com) Date: 19 Aug 2005 11:37:02 -0700 Subject: python classes taught Message-ID: <1124476622.522386.166050@g14g2000cwa.googlegroups.com> anyone know of any college/school that is teaching the python language? From bdesth.quelquechose at free.quelquepart.fr Wed Aug 31 17:55:24 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 31 Aug 2005 23:55:24 +0200 Subject: HTML tags optimization [better learn CSS] In-Reply-To: <1125500077.461196.321910@g43g2000cwa.googlegroups.com> References: <1125500077.461196.321910@g43g2000cwa.googlegroups.com> Message-ID: <43161f47$0$2108$626a14ce@news.free.fr> DENG a ?crit : > hi all, > > i use SGMLParser to process HTML files, in order to do some > optimizations, > > something like this: > > <i><b>TEXT1</b></i><b><i><u>TEXT2</u></i></b> > > optimise to > > <i><b>TEXT1<u>TEXT2</u></b><i> Doesn't Tidy do this already ? > > at the very beginning, i was thinking of analysing each text-block, to > know their color, size, if is bold or italic, but i found it was too > complicated. > > e.g > > <font color=red><font size=6>TEXT1</font></font> Whoever writes such a thing in 2005 ought to be shot down for the sake of mankind !-) > optimise to > > <font color=red size=6>TEXT1</font> You call this "optimized HTML" ? Even MS Word produces better code... > > but if there is TEXT2 exist > > <font color=red><font size=6>TEXT1</font>TEXT2</font> > > we can not do any optimization. > > my problem is I can not find a method to treat all those situation, Tidy is open source AFAICT. > I > had too much thinking and get fool now > > > anyone can give me some advices? Learn to use Tidy and CSS. From francois.perche at gmail.com Sat Aug 13 19:34:17 2005 From: francois.perche at gmail.com (perchef) Date: 13 Aug 2005 16:34:17 -0700 Subject: wx.MessageDialog displayed without components inside In-Reply-To: <pan.2005.08.13.17.07.20.357284@tuxzilla.tuxhome> References: <1123951035.856439.173160@g44g2000cwa.googlegroups.com> <pan.2005.08.13.17.07.20.357284@tuxzilla.tuxhome> Message-ID: <1123976057.103585.237410@z14g2000cwz.googlegroups.com> nope, I have put md.Destroy() away and it didn't change something. I don't think that's the problem because ShowModal() is a blocking method, execution is stop until you press YES or NO (in my case with wx.YES_NO) From russandheather at gmail.com Thu Aug 25 14:58:40 2005 From: russandheather at gmail.com (Qopit) Date: 25 Aug 2005 11:58:40 -0700 Subject: Suppressing checking of modules with pychecker Message-ID: <1124996320.482701.26660@o13g2000cwo.googlegroups.com> Does anyone know how to stop the command line pychecker from analyzing particular modules? It really gets slowed down on some big ones. In particular having 'import wx' takes a long while (30 - 60s). If you try pycheck'ing the program below it takes a while and prints a zillion warnings. #--- import wx print "Go make a sandwich while this finishes..." #--- I tried the blacklisting -b option, but can't seem to get it to work right. Plus I think it just suppresses the warnings but does not stop it from digging through the wx module. Anyone using pychecker with wxPython apps know what to do? From cowie.rob at gmail.com Wed Aug 31 15:46:48 2005 From: cowie.rob at gmail.com (Rob Cowie) Date: 31 Aug 2005 12:46:48 -0700 Subject: Retrieving Filename from Path In-Reply-To: <1125508678.590072.87180@g44g2000cwa.googlegroups.com> References: <1125508327.616838.55630@g44g2000cwa.googlegroups.com> <1125508678.590072.87180@g44g2000cwa.googlegroups.com> Message-ID: <1125517608.529464.296540@g14g2000cwa.googlegroups.com> Thanks, os.path.basename(filePath) it is then. BTW, the help(module) function is new to me! Must have missed it when reading the tutorial. Cheers! From deets at web.de Fri Aug 12 04:22:56 2005 From: deets at web.de (Diez B. Roggisch) Date: 12 Aug 2005 01:22:56 -0700 Subject: Using globals with classes In-Reply-To: <42fc2e42$0$18637$14726298@news.sunsite.dk> References: <42fc2e42$0$18637$14726298@news.sunsite.dk> Message-ID: <1123834976.452126.205570@z14g2000cwz.googlegroups.com> > Is there a way to make a Python function "remember" the values of certain > variables ? Or use fortran 95 like use module, only : varname, type of > within a def ? I'm not sure what you are trying to do here - but it seems to me that you are not properly designing your application. You really shouldn't use the Designers code-insertion features. The reason is simple: you the have two tools to write code in instead of one (your editor/IDE). And you don't make plotkey* global - use instance variables. So I'm going to describe how I dow work with PyQt: - I create a Widget in the designer - compile it using pyuic - _extend_ it - write my code in the extended version So I end up with something like this (I use modules to separate classes): ui/plot.ui ui/plot.py views/plot.py where views/plot.py looks like this: class Plot(ui.plot.Plot): def __init__(self, *args): ui.plot.Plot.__init__(self, *args) self.plotkey1 = <whatever> def update(self): # access self.plotkey here HTH, DIez From cmd at alephant.net Mon Aug 29 11:09:18 2005 From: cmd at alephant.net (Christopher DeMarco) Date: Mon, 29 Aug 2005 11:09:18 -0400 Subject: Python and file locking - NFS or MySQL? Message-ID: <20050829150918.GA12296@onion.alephant.net> Hi all... ...I've got a Python script running on a bunch of boxen sharing some common NFS-exported space. I need (not want :) to lock files for writing, and I need (not want :) to do it safely (i.e. atomically). I'm doing this in Linux; NFS4 is available. As I understand it, my options are: 1. Python's fcntl() is an interface to the fcntl(2) system call, which is claimed to work "mostly" over NFS v >= 3. 2. open(2) is atomic on a local FS, I've read discussions that imply that link(2) is atomic over NFS (is it?), so I can link from local lockfile to remote target atomically. I don't grok this; open(2) + link(2) + stat(2) == 3 calls on my fingers. HTH is this supposed to work? 3. Atomically update a MySQL database indicating that the file is locked - MySQL has atomic transactions now, right? And how good is the Python MySQL API - IIRC Perl didn't have atomic transactions last year; will this work in contemporary Python? I've got a while (several weeks) to chew this problem over (my current implementation is ``assert("Poof! File locked")''). What are my options for safely locking files via NFS? I don't want to get involved with NLM as my impression is it's being buggy and unwieldy. Thanks in advance! I was present at an undersea, unexplained mass sponge migration. -- Christopher DeMarco <cmd at alephant.net> Alephant Systems (http://alephant.net) PGP public key at http://pgp.alephant.net +1 412 708 9660 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: <http://mail.python.org/pipermail/python-list/attachments/20050829/9b1c4edd/attachment.sig> From kbk at shore.net Wed Aug 10 21:34:43 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Wed, 10 Aug 2005 21:34:43 -0400 (EDT) Subject: Weekly Python Patch/Bug Summary Message-ID: <200508110134.j7B1YhHG024463@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 352 open ( -2) / 2896 closed ( +8) / 3248 total ( +6) Bugs : 913 open ( +4) / 5162 closed (+10) / 6075 total (+14) RFE : 191 open ( +0) / 178 closed ( +0) / 369 total ( +0) New / Reopened Patches ______________________ compiler package: "global a; a=5" (2005-08-04) http://python.org/sf/1251748 opened by Armin Rigo Simplying Tkinter's event loop (2005-08-05) http://python.org/sf/1252236 opened by Michiel de Hoon modulefinder misses modules (2005-08-05) http://python.org/sf/1252550 opened by Thomas Heller poplib list() docstring fix (2005-08-05) CLOSED http://python.org/sf/1252706 opened by Steve Greenland QuickTime API needs corrected object types (2005-08-09) http://python.org/sf/1254695 opened by Christopher K Davis GCC detection for runtime_library_dirs when ccache is used (2005-08-09) http://python.org/sf/1254718 opened by Seo Sanghyeon Patches Closed ______________ Faster commonprefix in macpath, ntpath, etc. (2005-01-20) http://python.org/sf/1105730 closed by birkenfeld poplib list() docstring fix (2005-08-05) http://python.org/sf/1252706 closed by birkenfeld absolute paths cause problems for MSVC (2003-10-21) http://python.org/sf/827386 closed by loewis Fix LINKCC (Bug #1189330) (2005-07-15) http://python.org/sf/1239112 closed by loewis file.encoding support for file.write and file.writelines (2005-06-04) http://python.org/sf/1214889 closed by birkenfeld st_gen and st_birthtime support for FreeBSD (2005-04-11) http://python.org/sf/1180695 closed by loewis Add unicode for sys.argv, os.environ, os.system (2005-07-02) http://python.org/sf/1231336 closed by loewis Refactoring Python/import.c (2004-12-30) http://python.org/sf/1093253 closed by theller New / Reopened Bugs ___________________ cgitb gives wrong lineno inside try:..finally: (2005-08-03) http://python.org/sf/1251026 opened by Rob W.W. Hooft Decoding with unicode_internal segfaults on UCS-4 builds (2005-08-03) http://python.org/sf/1251300 opened by nhaldimann smtplib and email.py (2005-08-03) http://python.org/sf/1251528 opened by Cosmin Nicolaescu Python 2.4.1 crashes when importing the attached script (2005-08-04) http://python.org/sf/1251631 opened by Viktor Ferenczi Fail codecs.lookup() on 'mbcs' and 'tactis' (2005-08-04) http://python.org/sf/1251921 reopened by lemburg Fail codecs.lookup() on 'mbcs' and 'tactis' (2005-08-04) http://python.org/sf/1251921 opened by liturgist Issue with telnetlib read_until not timing out (2005-08-04) http://python.org/sf/1252001 opened by padded IOError after normal write (2005-08-04) http://python.org/sf/1252149 opened by Patrick Gerken os.system on win32 can't handle pathnames with spaces (2005-08-05) CLOSED http://python.org/sf/1252733 opened by Ori Avtalion non-admin install may fail (win xp pro) (2005-07-05) CLOSED http://python.org/sf/1232947 reopened by loewis raw_input() displays wrong unicode prompt (2005-01-10) http://python.org/sf/1099364 reopened by prikryl Python interpreter unnecessarily linked against c++ runtime (2005-08-08) http://python.org/sf/1254125 opened by Zak Kipling parser fails on long non-ascii lines if coding declared (2005-08-08) CLOSED http://python.org/sf/1254248 opened by Oleg Noga Docs for list.extend() are incorrect (2005-08-08) CLOSED http://python.org/sf/1254362 opened by Kent Johnson "appropriately decorated" is undefined in MultiFile.push doc (2005-08-09) http://python.org/sf/1255218 opened by Alan float('-inf') (2005-08-10) http://python.org/sf/1255395 opened by Steven Bird bug in use of __getattribute__ ? (2005-08-10) CLOSED http://python.org/sf/1256010 opened by sylvain ferriol Bugs Closed ___________ numarray in debian python 2.4.1 (2005-08-02) http://python.org/sf/1249903 closed by birkenfeld incorrect description of range function (2005-08-02) http://python.org/sf/1250306 closed by birkenfeld isinstance() fails depending on how modules imported (2005-08-01) http://python.org/sf/1249615 closed by hgibson50 set of pdb breakpoint fails (2005-07-30) http://python.org/sf/1248127 closed by birkenfeld Fail codecs.lookup() on 'mbcs' and 'tactis' (2005-08-04) http://python.org/sf/1251921 closed by loewis os.system on win32 can't handle pathnames with spaces (2005-08-05) http://python.org/sf/1252733 closed by salty-horse distutils: MetroWerks support can go (2005-07-17) http://python.org/sf/1239948 closed by jackjansen non-admin install may fail (win xp pro) (2005-07-05) http://python.org/sf/1232947 closed by loewis segfault in os module (2005-06-24) http://python.org/sf/1226969 closed by loewis LINKCC incorrect (2005-04-25) http://python.org/sf/1189330 closed by loewis parser fails on long non-ascii lines if coding declared (2005-08-08) http://python.org/sf/1254248 closed by doerwalter Docs for list.extend() are incorrect (2005-08-08) http://python.org/sf/1254362 closed by birkenfeld bug in use of __getattribute__ ? (2005-08-10) http://python.org/sf/1256010 closed by birkenfeld From eric.nieuwland at xs4all.nl Wed Aug 10 14:32:56 2005 From: eric.nieuwland at xs4all.nl (Eric Nieuwland) Date: Wed, 10 Aug 2005 20:32:56 +0200 Subject: FTP over SSL (explicit encryption) In-Reply-To: <gjoKe.2945$0d.860@trnddc06> References: <gjoKe.2945$0d.860@trnddc06> Message-ID: <1d796184157f3b3148d568b4b3218cc9@xs4all.nl> David Isaac wrote: > I am looking for a pure Python secure ftp solution. > Does it exist? Do you want SFTP or FTP/S? > I would have thought that the existence of OpenSSL > would imply "yes" but I cannot find anything. > > ftplib does not seem to provide any secure services. Indeed. If you want SFTP, just make a copy of ftplib and modify so it will use an SSL socket instead of a normal socket. After that, only some minor point may remain. > [...]I know about M2Crypto > http://sandbox.rulemaker.net/ngps/m2/ > but that requires installing SWIG and OpenSSL. > (If someone tells me they have found this trivial > under Windows, I am willing to try ... ) I guess SFTP should work on Windows as well. > I would have thought that this was a common need with > a standard Python solution, so I suspect I'm overlooking > something obvious. AFAIK you're not. I'm having a look at FTP/S right now. That's a little more complicated, but it seems doable. If I succeed, I guess I'll donate the stuff as an extension to ftplib. --eric From bokr at oz.net Tue Aug 30 15:03:01 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 30 Aug 2005 19:03:01 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk><1124160882.554543.75730@g43g2000cwa.googlegroups.com><m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk><wMOdnW4N1cAeAZneRVn-2g@comcast.com><VoOdnZAkbdDgO5neRVn-hg@comcast.com><EpLNe.824$GV7.650@newssvr25.news.prodigy.net><WZaPe.1953$eQ.899@newssvr30.news.prodigy.com><mailman.3485.1124942826.10512.python-list@python.org><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><slrndgtka9.1qv.apardon@rcpc42.vub.ac.be><vpBPe.549$MN5.241@newssvr25.news.prodigy.net><mailman.37.1125074193.8229.python-list@python.org><7sJPe.573$MN5.131@newssvr25.news.prodigy.net><mailman.56.1125109269.8229.python-list@python.org><slrndh5itn.hia.apardon@rcpc42.vub.ac.be><devuln$bro$1@sea.gmane.org><mailman.159.1125379590.8229.python-list@python.org> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <mailman.160.1125389834.8229.python-list@python.org> <b8VQe.472$sF6.70@newssvr24.news.prodigy.net> Message-ID: <4314a1bd.169970023@news.oz.net> On Tue, 30 Aug 2005 08:53:27 GMT, Bryan Olson <fakeaddress at nowhere.org> wrote: [...] >Specification > > We propose a new style of slicing and indexing for Python > sequences. Instead of: > > sequence[start : stop : step] > > new-style slicing uses the syntax: > > sequence[start ; stop ; step] > I don't mind the semantics, but I don't like the semicolons ;-) What about if when brackets trail as if attributes, it means your-style slicing written with colons instead of semicolons? sequence.[start : stop : step] I think that would just be a tweak on the trailer syntax. I just really dislike the semicolons ;-) Regards, Bengt Richter From the.g.man.x at gmail.com Thu Aug 4 22:27:12 2005 From: the.g.man.x at gmail.com (Erik the Red) Date: 4 Aug 2005 19:27:12 -0700 Subject: Euclid's Algorithm in Python? Message-ID: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> In Fundamental Algorithms (The Art of Computer Programming), the first algorithm discussed is Euclid's Algorithm. The only idea I have of writing this in python is that it must involve usage of the modulo % sign. How do I write this in python? From peter at engcorp.com Fri Aug 12 12:43:27 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 12 Aug 2005 12:43:27 -0400 Subject: thread limit in python In-Reply-To: <1123859196.289006.200380@g44g2000cwa.googlegroups.com> References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> <1123859196.289006.200380@g44g2000cwa.googlegroups.com> Message-ID: <bLmdnZptdt-8T2HfRVn-qQ@powergate.ca> danieldsmith at gmail.com wrote: > and sorry to continue to post here. since this is occurring in both c > and python, i think there's no question i'm running into an os limit. Probably, but I haven't yet seen anyone ask the real important question. What possible use could you have for more than 1000 *simultaneously active* threads? There are very likely several alternative approaches that will fit your use case and have better characteristics (e.g. higher performance, simpler code, safer architecture, etc). -Peter From xah at xahlee.org Wed Aug 31 06:24:22 2005 From: xah at xahlee.org (Xah Lee) Date: 31 Aug 2005 03:24:22 -0700 Subject: change date format Message-ID: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> Apache by default uses the following format for date: 30/Aug/2005 is there a module that turn this directly into yyyymmdd? Xah xah at xahlee.org ? http://xahlee.org/ From christopher.saunter at durham.ac.uk Wed Aug 3 13:33:54 2005 From: christopher.saunter at durham.ac.uk (c d saunter) Date: Wed, 3 Aug 2005 17:33:54 +0000 (UTC) Subject: Parallel port programming on windows XP/2000? References: <HHZHe.236676$Qo.191698@fed1read01> Message-ID: <dcqv62$6fv$1@heffalump.dur.ac.uk> Novice Experl (ex at pe.rl) wrote: : I'd like to write a simple application that interfaces with the parallel port, and changes the data on it according to keyboard input. I hope I can get it to run under windows xp and / or windows 2000. : How can I do this? What do I need to know? It doesn't look like the standard library (the one under my pillow) has that feature. In addition, I've heard that with newer versions of windows don't let you communicate with the port directly, instead requiring interfacing with some driver? I always use DLPortIO, makes life almost as simple as GWBasic and a DOS box... You can either create a custom extension around this or use ctypes. Generally speaking a custom .dll is only needed if you are your lpt transactions are bidirectional, highly interleaved and high bandwidth. DLPortIO: http://www.driverlinx.com/DownLoad/DlPortIO.htm ctypes: http://starship.python.net/crew/theller/ctypes/ Note that DLPortIO is not a Python thing, it's a generic Windows .dll with C and VB examples, and needs installing, so it can't be packaged with py2exe. I'd guess this is the same for other parallel port accesing tools - I think you need admin privilidges on a Windows NT/2K/XP box to install DLPortIO, but not to use it. If you decide this is the best route for you and find yourself stuck, drop me an email for some example code. --- cds : I came across this: : http://pyserial.sourceforge.net/pyparallel.html : but it seems to only be used for direct access (would it work with XP?), and hasn't been updated for a couple of years. In addition, it requires something called "Java Communications" (JavaComm) extension for Java/Jython, doesn't provide a link to it, and when I google it - google returns the page I came from! : To add to the confusion, I hope I can provide a py2exe executable of my script instead of forcing a complete installation. : --------------= Posted using GrabIt =---------------- : ------= Binary Usenet downloading made easy =--------- : -= Get GrabIt for free from http://www.shemes.com/ =- From sklass at pointcircle.com Thu Aug 4 10:27:29 2005 From: sklass at pointcircle.com (rh0dium) Date: 4 Aug 2005 07:27:29 -0700 Subject: Passing a log handle to a module? Help needed with logging module and In-Reply-To: <dcie79$f07$1@gemini.csx.cam.ac.uk> References: <1122784140.800331.86740@z14g2000cwz.googlegroups.com> <dcie79$f07$1@gemini.csx.cam.ac.uk> Message-ID: <1123165649.187515.88410@g44g2000cwa.googlegroups.com> I found my problem it wasn't this piece of the problem it was another... Thanks. However if you want a working example go here.. http://www.onlamp.com/pub/a/python/2005/06/02/logging.html From pwatson at redlinepy.com Mon Aug 15 12:59:30 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 15 Aug 2005 11:59:30 -0500 Subject: Using for in one-liner In-Reply-To: <1124124363.780021.240270@o13g2000cwo.googlegroups.com> References: <3mbu82F15h18oU1@individual.net> <1124124363.780021.240270@o13g2000cwo.googlegroups.com> Message-ID: <4300C9F2.7030003@redlinepy.com> wittempj at hotmail.com wrote: > to me it seems the ',' is superfluous, this works: python -c "import > sys;print ''.join([l for l in sys.stdin.readlines()])" in 2.4.1 - with > the comma it works as well but it looks weird, as if you want to > un-pack a tuple. Without the comma, an additional newline is written at the end. From http Thu Aug 25 14:22:16 2005 From: http (Paul Rubin) Date: 25 Aug 2005 11:22:16 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRVn-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <WZaPe.1953$eQ.899@newssvr30.news.prodigy.com> <mailman.3485.1124942826.10512.python-list@python.org> Message-ID: <7xu0hdg9lz.fsf@ruckus.brouhaha.com> Steve Holden <steve at holdenweb.com> writes: > As far as position reporting goes, it seems pretty clear that find() > will always report positive index values. In a five-character string > then -1 and 4 are effectively equivalent. > > What on earth makes you call this a bug? And what are you proposing > that find() should return if the substring isn't found at all? please > don't suggest it should raise an exception, as index() exists to > provide that functionality. Bryan is making the case that Python's use of negative subscripts to measure from the end of sequences is bogus, and that it should be done some other way instead. I've certainly had bugs in my own programs related to that "feature". From steve at holdenweb.com Tue Aug 23 09:14:14 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 23 Aug 2005 09:14:14 -0400 Subject: Best way to 'touch' a file? In-Reply-To: <eeKdnbwPVPraiJbeRVn-oA@powergate.ca> References: <mailman.3329.1124643300.10512.python-list@python.org> <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca><mailman.3383.1124745482.10512.python-list@python.org> <tqmdnYA7UvHA0pfeRVn-iw@powergate.ca><mailman.3390.1124750954.10512.python-list@python.org> <zp-dnYjfErJT9JfeRVn-tA@powergate.ca> <mailman.3398.1124772186.10512.python-list@python.org> <eeKdnbwPVPraiJbeRVn-oA@powergate.ca> Message-ID: <def7dn$vte$1@sea.gmane.org> Peter Hansen wrote: > Fredrik Lundh wrote: > >>Peter Hansen wrote: >> >> >>>You've quoted selectively. He also said "Unix-style 'touch'", from >>>which one could quite legitimately infer >> >>nope. read his post again. > > > Sigh. You're being tiring, Fredrik: > You probably mean "tiresome". Bots can be like that sometimes. And not only bots > '''I'm looking for an easy way to perform a UNIX-style "touch", to > update the modification time of a file without actually modifying it.''' > > And if your point is that I spelled UNIX in mixed case, and change the > double quotation marks to single quotation marks, you really need to > take a break. > > If your point is that this statement *clearly and unambiguously* rejects > the create-if-missing feature as undesirable, then I can say only that > you are simply wrong. > I rather suspect his point is that the OP's problem description specifically implies the file's prior existence. As I believe Fredrik did, I read "update the modification time of a file" to mean that the file already has a modification time. This would make the import of the path module you mentioned a little over the top given there's already a function in os to handle the requirement. Given that both solutions have been presented, as far as the rest of the list is concerned we are probably all three just being tiresome now. The OP can choose whichever best meets his real requirements, whether they were accurately stated or not. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From uval at rz.uni-karlsruhe.de Fri Aug 5 08:06:59 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Fri, 05 Aug 2005 14:06:59 +0200 Subject: Newbie Program In-Reply-To: <mailman.2736.1123218601.10512.python-list@python.org> References: <mailman.2736.1123218601.10512.python-list@python.org> Message-ID: <dcvkok$4s1$1@news2.rz.uni-karlsruhe.de> Eric schrieb: > I am reading a book on Python and ran across and exercise that I just > can't seem to figure out. Its pretty simple, but I just can't get > past a certain point. > > The task is to create a program that flips a coin 100 times and keeps > track of the total of heads and tails which is printed to the screen. > > My plan was to use import random with a range of 2 and use a > conditional statement to count to 100. The problem I am encountering > is how do I keep track of the totals for heads and tails? > > Any suggestions would be appreciated. Keep in mind I am very new to > Python so there may be a more sophisticated way, but I am just trying > to use what the book has taught so far. > > Thanks, > Eric >>> import random >>> coin = ("head", "tail") >>> cnt = {"head":0, "tail":0} >>> for i in xrange(100): ... cnt[random.choice(coin)] += 1 ... >>> cnt {'head': 49, 'tail': 51} >>> my solution From gandalf at geochemsource.com Wed Aug 17 10:03:10 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Wed, 17 Aug 2005 16:03:10 +0200 Subject: sys.path and win32 services (was: importerror) In-Reply-To: <430324ba$1@news.eftel.com> References: <43008D0D.4000509@geochemsource.com> <mailman.3098.1124117300.10512.python-list@python.org><ddql2o$l1c$1@news1.zwoll1.ov.home.nl> <mailman.3121.1124180797.10512.python-list@python.org> <ddsjfd$r48$1@news5.zwoll1.ov.home.nl> <mailman.3164.1124270802.10512.python-list@python.org> <430324ba$1@news.eftel.com> Message-ID: <4303439E.9060304@geochemsource.com> >Why do you think str() is needed here? > > Because I'm not sure if sys.path was overwritten or changed. Some bad modules could overwrite sys.path with another list. I know I'm paranoid. :-) >Possibly because sys.path can start with '' which is interpreted as the >current directory. Perhaps when the code is started as a windows service >[I know nothing about windows services], the current directory is set to >%windir%\system32 (where lots of DLLs hang out), and if there is a >zlib.dll there, it will get picked up first. Try printing the current >directory (see above). > > Okay, I did so. I wrote a service that prints out sys.path into a logfile. Here is the result: sys.path=['C:\\Python24\\lib\\site-packages\\win32', 'T:\\Python\\Lib', 'C:\\WINDOWS\\system32\\python24.zip', 'C:\\WINDOWS\\system32', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Python24\\lib\\site-packages\\win32', 'C:\\Python24', 'C:\\Python24\\lib\\site-packages', 'C:\\Python24\\lib\\site-packages\\PIL', 'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\Python24\\lib\\site-packages\\Pythonwin', 'C:\\Python24\\lib\\site-packages\\wx-2.6-msw-ansi', 'T:\\Python\\Projects\\NamedConnector'] The empty string is not on sys.path. This is very strange, because it is different when I start the python interactively. The problem was caused by "C:\WINDOWS\system32", not the empty string. I'm still not sure why it is included in sys.path, and why '' is not there? I also checked the Python documentation about sys.path, and read the thread mentioned before but still sys.path is magical, and magic is not Pythonic. :-) Anyway, I think I have found the most platform independent solution. Here it is: >>> import _socket >>> import os >>> import sys >>> dyndir = os.path.split(_socket.__file__)[0] # This can be "/usr/local/lib/python2.4/lib-dynload" or "C:\Python24\DLLs" or whatever >>> sys.path.append(dyndir) In most cases, '_socket.pyd' will be the first module that can be imported, and it will by in the dynaload directory for sure. I feel this is still unclean code. Do you think that it would be nice to add new features to the sys module? sys.dlpath - could be the path to the lib-dynload or DLLs folder sys.libpath - could be the path to the lib folder >Setting the PYTHONVERBOSE environment variable may assist in showing >where modules are being loaded from. > > This cannot be used in conjunction with a windows service, because its output cannot be seen. :-( From fredrik at pythonware.com Mon Aug 29 10:37:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Aug 2005 16:37:07 +0200 Subject: python image thumbnail generator? References: <pan.2005.08.28.02.06.19.799993@wintergreen.in> <43112AF7.4010108@rogers.com> Message-ID: <dev6id$mbi$1@sea.gmane.org> Mike C. Fletcher wrote: > The core function looks something like this: > > import Image # this is PIL > > def getThumbnail( filename, size = (32,32) ): > '''Get a thumbnail image of filename''' > image = Image.open(filename) > rx, ry = image.size[0]/float(size[0]), image.size[1]/float(size[1]) > if rx > ry: > resize = int(size[0]), int(round(image.size[1]*(1.0/rx), 0)) > else: > resize = int(round(image.size[0]*(1.0/ry), 0)), int(size[1]) > image = image.resize( resize, Image.BILINEAR ) footnote: if you're creating thumbnails from JPEG or PhotoCD images, using the "thumbnail" method can be a lot more efficient (unlike resize, it tweaks the codec so it doesn't have to load the entire full-sized image). footnote 2: Image.ANTIALIAS is slower, but tends to give a much better result than Image.BILINEAR, especiall for "noisy" images. </F> From jepler at unpythonic.net Tue Aug 16 08:53:43 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 16 Aug 2005 07:53:43 -0500 Subject: base64.encode and decode not correct In-Reply-To: <4301D507.3070509@agg.astranet.ru> References: <4301D507.3070509@agg.astranet.ru> Message-ID: <20050816125339.GA6028@unpythonic.net> It seems unlikely that there is a bug in Python's base64 encode/decode functions, but it is possible. For me, a long string of the same length you mention survives an encode/decode pair (a round-trip): Python 2.3.3 (#1, May 7 2004, 10:31:40) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> b = "x" * 1728512 >>> b.encode("base64").decode("base64") == b True >>> import base64 >>> b == base64.decodestring(base64.encodestring(b)) True I also ran a program which tests this round-trip property for random data of all lengths from 0 to 4095, and it ran until I stopped it, rather than printing an AssertionError: import os, base64 f = open("/dev/urandom") while 1: for l in range(4096): b = f.read(l) assert b == base64.decodestring(base64.encodestring(b)) os.write(2, ".") print "!" Of course, Python itself has a test-suite for base64 which tests strings of several lengths against the values they should give after encoding or decoding. $ python /usr/lib/python2.3/test/test_base64.py test_decodestring (__main__.Base64TestCase) ... ok test_encodestring (__main__.Base64TestCase) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK If your 1728512-character string doesn't pass the simple round-trip test, then you've uncovered a latent Python bug that my tests didn't demonstrate. If it does, then the problem lies somewhere else in your code, possibly in the part that transmits the encoded message. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20050816/079eaa56/attachment.sig> From usenet.20.evilspam at spamgourmet.com Sun Aug 28 15:09:19 2005 From: usenet.20.evilspam at spamgourmet.com (Chris Spencer) Date: Sun, 28 Aug 2005 19:09:19 GMT Subject: Socket Troubles In-Reply-To: <4311dff6$0$22907$ed2619ec@ptn-nntp-reader01.plus.net> References: <0ndQe.259$DV.23@trndny07> <4311dff6$0$22907$ed2619ec@ptn-nntp-reader01.plus.net> Message-ID: <zZnQe.599$cY.164@trndny06> Michael Sparks wrote: > Chris Spencer wrote: > > At one point in your code you do this: > self._socket.setblocking(0) > > This says "if we can't recieve or send data without blocking, fail rather > than succeed". One of the failure modes is to return error 11. This is > infact normally defined as: > #define EAGAIN 11 /* Try again */ > > What this means is "sorry, I couldn't do this without blocking right now, > try again very shortly!". > > Looking at your code it continually loops (in BaseConnectionHandler_recv) > receiving data - whether or not there's any data to receive: > def _recv(self): > while self.running: > try: > data = self._socket.recv(4096) > if not len(data): > time.sleep(0.1) > continue > except Exception, e: > log('Recieve failed for handler',self.address,'because of',e) > > break > > Since you never actually check to see if the socket is ready to give you > data, and you've set it non-blocking, seeing lots of EAGAIN errors is > pretty much what you'd expect to see. (Simply sleeping is not sufficient!) > > I suppose the short answer though really is this: you set the socket > non-blocking, you should therefore expect to see failures telling you > to try again, and follow their advice! :) You're quite right. I fixed this by using select(). However, I was still having problems with open() blocking the main thread. Then I realized a slight problem: t = threading.Thread(target=self._connection_handler(h)) I changed this to: t = threading.Thread(target=self._connection_handler, args=(h,)) and now it appears to be working correctly. Thanks for your help! I truly appreciate it. Chris From bokr at oz.net Fri Aug 19 01:59:38 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 19 Aug 2005 05:59:38 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <43057145.1837895163@news.oz.net> On 18 Aug 2005 22:21:53 -0700, "Greg McIntyre" <greg at puyo.cjb.net> wrote: >I have a Python snippet: > > f = open("blah.txt", "r") > while True: > c = f.read(1) > if c == '': break # EOF > # ... work on c > >Is some way to make this code more compact and simple? It's a bit >spaghetti. > >This is what I would ideally like: > > f = open("blah.txt", "r") > while c = f.read(1): > # ... work on c > How about (untested): for c in iter((lambda f=open('blah.txt', 'r'): f.read(1)), ''): # ... work on c ("if c=='': break" functionality courtesy of iter(f, sentinel) form above) Of course, reading characters one by one is not very efficient, so if the file is reasonably sized, you might just want to read the whole thing and iterate through it, something like for c in open('blah.txt').read(): # ... work on c >But I get a syntax error. > > while c = f.read(1): > ^ >SyntaxError: invalid syntax > >And read() doesn't work that way anyway because it returns '' on EOF >and '' != False. If I try: > > f = open("blah.txt", "r") > while (c = f.read(1)) != '': > # ... work on c > >I get a syntax error also. :( > >Is this related to Python's expression vs. statement syntactic >separation? How can I be write this code more nicely? > Yes, it is related as you suspect. I'll leave it to you to make a chunk-buffering one-liner for huge files that iterates by characters, if one-liners turn you on. Otherwise it is easy to write a generator that will do it. Byt the time I post this, someone will probably have done it ;-) Regards, Bengt Richter From rschroev_nospam_ml at fastmail.fm Tue Aug 9 16:17:16 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 09 Aug 2005 20:17:16 GMT Subject: Does any one recognize this binary data storage format In-Reply-To: <ddatkk$10k$1@ss405.t-com.hr> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <ddatkk$10k$1@ss405.t-com.hr> Message-ID: <gb8Ke.165642$3f.8864883@phobos.telenet-ops.be> Dejan Rodiger wrote: > geskerrett at hotmail.com said the following on 9.08.2005 19:29: > >>Phone 1: 5616864700 >>Hex On Disk: C0DBA8ECF441 > > > 5616864700(10)=14ECA8DBC(16) > 14 EC A8 DB C leftshift by 4 bits (it will add 0 on last C) > C0 DB A8 EC 14 00 write bytes from right to left > C0 DB A8 EC F4 41 Add E041 > > >>Phone 1: 8003346488 >>Hex On Disk: 800396d0fd41 > > > 8003346488(10)=1DD096038(16) > 1D D0 96 03 8 > 80 03 96 D0 1D 00 > 80 03 96 d0 fd 41 Add E041 > > But works only for Phone 1 :-) E041 is some kind of checksum perhaps? -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From usenet.20.evilspam at spamgourmet.com Sun Aug 28 17:36:42 2005 From: usenet.20.evilspam at spamgourmet.com (Chris Spencer) Date: Sun, 28 Aug 2005 21:36:42 GMT Subject: Lossless Number Conversion Message-ID: <K7qQe.1363$wE1.143@trndny01> Is there any library for Python that implements a kind of universal number object. Something that, if you divide two integers, generates a ratio instead of a float, or if you take the square root of a negative, generates a complex number instead of raising an exception? Lisp has something like this, and it makes number crunching much more convenient. Chris From richie at entrian.com Tue Aug 23 06:12:20 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 23 Aug 2005 11:12:20 +0100 Subject: Network performance In-Reply-To: <83ECF740-BE8B-40B1-A8C8-54899442AFC3@adm.umu.se> References: <83ECF740-BE8B-40B1-A8C8-54899442AFC3@adm.umu.se> Message-ID: <u9tlg1teen1t4mcks2i9c0ptt5dredfldp@4ax.com> [Roland] > The client sends a number of lines (each ending with \n) and ends one > set of lines with a empty line. > [...] > I was surprised to find that the performance was [poor]. Are you sending all the lines in a single packet: >>> sock.send('\n'.join(lines)) or sending them one at a time: >>> for line in lines: >>> sock.send(line + '\n') ? If the latter, you are probably experiencing "Nagle delays". Google will furnish you with any number of explanations of what that means, but in summary, one end of a TCP/IP connection should never send two consecutive small packets without receiving a packet from the other end. ('Small' typically means less than about 1400 bytes.) Each time you do that, you'll suffer an artificial delay introduced by TCP/IP itself. -- Richie Hindle richie at entrian.com From sjdevnull at yahoo.com Fri Aug 26 15:07:50 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 26 Aug 2005 12:07:50 -0700 Subject: global interpreter lock In-Reply-To: <86slwymx79.fsf@bhuda.mired.org> References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <zGJNe.242$Ux3.75@newssvr21.news.prodigy.com> <868xyw9g30.fsf@bhuda.mired.org> <As_Oe.654$dw4.615@newssvr29.news.prodigy.net> <86slwymx79.fsf@bhuda.mired.org> Message-ID: <1125083270.659967.64430@f14g2000cwb.googlegroups.com> Mike Meyer wrote: > Bryan Olson <fakeaddress at nowhere.org> writes: > > The issue here is whether to confuse reality with what one might > > wish reality to be. > > Let's see. Reality is that writing correct programs is hard. Writing > correct programs that use concurrency is even harder, because of the > exponential explosion of the order that operations can happen > in. And dont forget: Writing concurrent programs without protected memory between execution contexts is even harder than with it. From n00m at narod.ru Tue Aug 30 07:54:53 2005 From: n00m at narod.ru (n00m) Date: 30 Aug 2005 04:54:53 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py Message-ID: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> When I double-click on "some.py" file console window appears just for a moment and right after that it's closed. If this script is started from inside of IDLE (F5 key) then it executes as it should be (e.g. executing all its print statements). Any ideas? OS: Windows; Python 2.3.4. Thanks. From sjmachin at lexicon.net Wed Aug 17 07:51:22 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 17 Aug 2005 21:51:22 +1000 Subject: zlib + Windows 32 service problem (ImportError) In-Reply-To: <mailman.3164.1124270802.10512.python-list@python.org> References: <43008D0D.4000509@geochemsource.com> <mailman.3098.1124117300.10512.python-list@python.org><ddql2o$l1c$1@news1.zwoll1.ov.home.nl> <mailman.3121.1124180797.10512.python-list@python.org> <ddsjfd$r48$1@news5.zwoll1.ov.home.nl> <mailman.3164.1124270802.10512.python-list@python.org> Message-ID: <430324ba$1@news.eftel.com> Laszlo Zsolt Nagy wrote: > | > >> | >> C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program >> >> | Files\Common Files\GTK\2.0\bin >> | >> | Then I restarted my computer. It is still missing initzlib. :-( >> | Please note that I can run the same program as an application, >> logged in >> | as the same user. >> | >> | Les >> >> Changing the Windows dll search path doesn't make any difference. It >> is sys.path (Python's search path) that's causing you the headache. >> Please see the mentioned thread for proposed solutions. >> >> > Great. I could make my service working with this snippet: > > import sys > sys.path.insert(0,r'C:\Python24\DLLs') > > But this is very ugly. Primarily, I do not want to use absolute path > names in a this program. I want to use the same code on different > computers and operating systems, but this code is not portable. Try this (or something like it): if sys.platform == "win32": sys.path.insert(0, sys.exec_prefix + r'\DLLs') > Secondly, I do not understand why sys.path is different when I start > python interactively. I believe that sys.path should be the same when > starting the program as a service. The only difference between the > application and the service is that the 'main' program of the service > imports some additional modules. See them below. > > iT:\Python\Projects\NamedConnector>python > Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> > >>> s1 = str(sys.path) Add this: print os.getcwd() # see below for why > >>> > >>> import win32serviceutil, win32service > >>> import pywintypes, win32con, winerror > >>> from win32event import * > >>> from win32file import * > >>> from win32pipe import * > >>> from win32api import * > >>> from ntsecuritycon import * > >>> > >>> > >>> s2 = str(sys.path) Why do you think str() is needed here? > >>> > >>> print s1 == s2 > True Add in here: print sys.path print os.getcwd() # see below for why > > I cannot distribute my service until I make it independent of the python > installation directory. > > Why sys.path is different when starting the code as a windows service? Possibly because sys.path can start with '' which is interpreted as the current directory. Perhaps when the code is started as a windows service [I know nothing about windows services], the current directory is set to %windir%\system32 (where lots of DLLs hang out), and if there is a zlib.dll there, it will get picked up first. Try printing the current directory (see above). Setting the PYTHONVERBOSE environment variable may assist in showing where modules are being loaded from. HTH, John From steve at holdenweb.com Mon Aug 29 17:21:58 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Aug 2005 17:21:58 -0400 Subject: socket.gaierror from httplib In-Reply-To: <1125332208.810975.92280@g43g2000cwa.googlegroups.com> References: <1125332208.810975.92280@g43g2000cwa.googlegroups.com> Message-ID: <devu9n$ap7$1@sea.gmane.org> spamsink42 at gmail.com wrote: > this code > > h=httplib.HTTPConnection('euronext.com') > h.request('GET', > 'http://www.euronext.com/home/0,3766,1732,00.html') > > fails with this message > > File "httplib.py", line 532, in connect > socket.SOCK_STREAM): > socket.gaierror: (-2, 'Name or service not known') > > what am i doing wrong? > > thanks > eric > The HTTPConnection specifies the server you are connection to (you only give to domain, which isn't guaranteed to resolve to the same IP address, or indeed even any IP address). Having connected, all you need to present in the request() method call is the HTTP method and the URI relative to the server. This works for me: >>> import httplib; h=httplib.HTTPConnection('www.euronext.com') >>> h.request('GET','/home/0,3766,1732,00.html') >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From fakeaddress at nowhere.org Wed Aug 10 02:33:05 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 06:33:05 GMT Subject: Catching stderr output from graphical apps Message-ID: <BchKe.3793$zr1.2649@newssvr13.news.prodigy.com> Here's a module to show stderr output from console-less Python apps, and stay out of the way otherwise. I plan to make a ASPN recipe of it, but I thought I'd run it by this group first. To use it, import the module. That's it. Upon import it will assign sys.stderr. In the normal case, your code is perfect so nothing ever gets written to stderr, and the module won't do much of anything. Upon the first write to stderr, if any, the module will launch a new process, and that process will show the stderr output in a window. The window will live until dismissed; I hate, hate, hate those vanishing-consoles-with-critical-information. The code shows some arguably-cool tricks. To fit everthing in one file, the module runs the Python interpreter on itself; it uses the "if __name__ == '__main__'" idiom to behave radically differently upon import versus direct execution. It uses TkInter for the window, but that's in a new process; it does not import TkInter into your application. To try it out, save it to a file -- I call it "errorwindow.py" - - and import it into some subsequently-incorrect code. For example: import errorwindow a = 3 + 1 + nonesuchdefined should cause a window to appear, showing the traceback of a Python NameError. -- --Bryan ---------------------------------------------------------------- """ Import this module into graphical Python apps to provide a sys.stderr. No functions to call, just import it. It uses only facilities in the Python standard distribution. If nothing is ever written to stderr, then the module just sits there and stays out of your face. Upon write to stderr, it launches a new process, piping it error stream. The new process throws up a window showing the error messages. """ import sys import os import thread if __name__ == '__main__': from Tkinter import * import Queue queue = Queue.Queue(99) def read_stdin(app): while 1: data = os.read(sys.stdin.fileno(), 2048) queue.put(data) if not data: break class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master.title("Error Stream from run of %s" % sys.argv[-1]) self.pack(fill=BOTH, expand=YES) self.logwidget = Text(self) self.logwidget.pack(side=TOP, fill=BOTH, expand=YES) # Disallow key entry, but allow copy with <Control-c> self.logwidget.bind('<Key>', lambda x: 'break') self.logwidget.bind('<Control-c>', lambda x: None) self.after(200, self.start_thread, ()) def start_thread(self, _): thread.start_new_thread(read_stdin, (self,)) self.after(200, self.check_q, ()) def check_q(self, _): go = True while go: try: data = queue.get_nowait() if not data: self.logwidget.configure(foreground ='#0000AA') data = "\n==== File Closed ====\n" go = False self.logwidget.insert(END, data) self.logwidget.see(END) except Queue.Empty: self.after(200, self.check_q, ()) go = False app = Application() app.mainloop() else: class ErrorPipe(object): def __init__(self): self.lock = thread.allocate_lock() self.empty = True def on_first_write(self): command = "%s %s %s" % (sys.executable, __file__, sys.argv[0]) self.pipe = os.popen(command, 'w') def _write(self, data): self.pipe.write(data) os.fsync(self.pipe) def write(self, data): self.lock.acquire() try: if self.empty: self.on_first_write() self.empty = False self._write(data) finally: self.lock.release() sys.stderr = ErrorPipe() From martin at v.loewis.de Fri Aug 26 04:19:03 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 26 Aug 2005 10:19:03 +0200 Subject: variable hell In-Reply-To: <mailman.3.1125039406.8229.python-list@python.org> References: <mailman.3.1125039406.8229.python-list@python.org> Message-ID: <430ED077.3050304@v.loewis.de> Adriaan Renting wrote: > Not in my Python. > > >>>>for count in range(0, 10): > > ... value = count > ... exec("'a%s=%s' % (count, value)") > ... > >>>>dir() > > ['__builtins__', '__doc__', '__name__', 'count', 'value'] You did not copy the suggestion properly: >>> for count in range(0, 10): ... exec 'a%s = %s' % (count,count) ... >>> dir() ['__builtins__', '__doc__', '__file__', '__name__', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'count'] >>> a5 5 (you can put additional parentheses around the string, but not additional quotation marks) Regards, Martin From jasondrew72 at gmail.com Wed Aug 10 11:30:18 2005 From: jasondrew72 at gmail.com (Jason Drew) Date: 10 Aug 2005 08:30:18 -0700 Subject: Documentation In-Reply-To: <42fa1a9f$1@griseus.its.uu.se> References: <42fa1a9f$1@griseus.its.uu.se> Message-ID: <1123687818.067296.3070@g44g2000cwa.googlegroups.com> The standard pydoc module is very useful. A simple example of how you could use it: >>> import pydoc >>> mymodule = pydoc.importfile(r"C:\My Py\my_foo.py") >>> html = pydoc.html.page(pydoc.describe(mymodule), pydoc.html.document(mymodule)) >>> open("foo.html", "w").write(html) Then you have a nice foo.html document for your module. The above isn't necessarily the best way to use pydoc though it's useful for a single-file bunch of classes. The documentation on pydoc seems pretty sketchy, but reading the pydoc.py file is a good way to learn how to use it. From weekender_ny at yahoo.com Sun Aug 7 12:15:24 2005 From: weekender_ny at yahoo.com (John) Date: 7 Aug 2005 09:15:24 -0700 Subject: socket + file i/o question References: <1123430926.790390.195590@f14g2000cwb.googlegroups.com> Message-ID: <1123431324.640997.7240@g44g2000cwa.googlegroups.com> Here is what the send and recieved number of bytes show up as: Filesize being sent = 507450 Server sending file to client... (total size sent , buffer size) ... 491520 4096 495616 4096 499712 4096 503808 3642 ./server.py: (107, 'Transport endpoint is not connected') On the client side, the bytes recieved shows one extra byte! (Bytes recieved, buffer size) ... 504256 1400 504256 1400 505656 1400 505656 1400 507056 1400 507056 395 507451 395 EOF received ./client.py: An unknown error occurred. Note that on the client there was an extra byte?? 507451 ?? Hope this helps in explaining my question better, --j From john at castleamber.com Fri Aug 26 17:58:18 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 21:58:18 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <gaGOe.213$5k1.200@newssvr27.news.prodigy.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> <Xns96BE4025C835Dcastleamber@130.133.1.4> <3n8di6Fbhg7U2@individual.net> <Xns96BE4F60DC591castleamber@130.133.1.4> <3n8sqaFch6kU1@individual.net> Message-ID: <Xns96BEAC81FD6B0castleamber@130.133.1.4> Ulrich Hobelmann <u.hobelmann at web.de> wrote: > John Bokma wrote: >>> I have cookies off, with explicit exception for sites where >>> I want cookies. When the crappy website doesn't bother to MENTION >>> that it wants cookies, i.e. give me an error page, how am I to know >>> that it needs cookies? Do I want EVERY website to ask me "do you >>> allow XY to set a cookie?" NO! >> >> So what do you want? An error page for every site that wants to set a >> cookie? > > No, the few sites where I actually have to log in to do anything > useful, when they're well-coded, tell me that they need cookies, and > if I think I like that website I make an exception entry for that > site, allowing cookies. Most sites just bombard you with useless, > crap cookies (maybe advertising), so they are silently ignored by my > browser. Delete them after each session automatically, except the ones on the exception list. You are clearly not an average user, so your usage pattern probably only messes up the stats they obtain via cookies anyway. I have long ago given up on manually accepting each and every cookie, and trying to guess it's purpose. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From peter at engcorp.com Wed Aug 10 07:32:37 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Aug 2005 07:32:37 -0400 Subject: Bizarre error from help() In-Reply-To: <ddbtef$qgk$1@rose.polar.local> References: <mailman.2906.1123643664.10512.python-list@python.org> <roy-170E1C.23192609082005@reader2.panix.com> <roy-F90D05.23251609082005@reader2.panix.com> <ddbtef$qgk$1@rose.polar.local> Message-ID: <S4mdnSt8MIOme2TfRVn-3Q@powergate.ca> Ben Finney wrote: > Roy Smith <roy at panix.com> wrote: > >>I've got a directory where I keep all sorts of little snippets of >>python code for testing. When I start up python in that directory, >>I get the error I reported. It turns out, I've got a file called >>"string.py" in it [...] >> >>something in the help system must be doing an "import string". > > All hail the coming of PEP 328: > > <URL:http://www.python.org/peps/pep-0328.html> Which, unless I misunderstand, would do nothing to change the behaviour of the OP's situation unless the mistakingly named "string.py" module was actually inside a package. If it was just in the current directory at the time, I don't think the PEP328 would have affected the situation. -Peter From rkern at ucsd.edu Mon Aug 29 14:13:32 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 29 Aug 2005 11:13:32 -0700 Subject: using common lisp with python. In-Reply-To: <1125338833.633816.69020@g49g2000cwa.googlegroups.com> References: <1125264907.656465.106900@g44g2000cwa.googlegroups.com> <43130f30$0$17711$626a14ce@news.free.fr> <1125332253.886031.256950@g49g2000cwa.googlegroups.com> <1125338833.633816.69020@g49g2000cwa.googlegroups.com> Message-ID: <devj8c$46v$1@sea.gmane.org> cipherpunk at gmail.com wrote: > Your best bet is probably to look into your LISP environment's FFI > (Foreign Function Interface). Most LISP environments have some way to > call C code directly. Insofar as going back the other way... that I'm > a little more sketchy on. Guile (the Scheme compiler from GNU) is a > strong contender, though. It's not Common LISP, but it's a LISP with > copious documentation for how to call it from C. ECL might be a good choice for real Common Lisp (more or less). http://ecls.sourceforge.net/ > I really can't see a reason to use Python as a glue layer. I'd > recommend rewriting your LISP code in Python before I'd recommend using > Python to interface between Common LISP and C. Agreed. -- 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 fidelerol at hotmail.com Sat Aug 13 19:06:32 2005 From: fidelerol at hotmail.com (BiskyMisky.com) Date: 13 Aug 2005 16:06:32 -0700 Subject: BiskyMisky Message-ID: <1123974391.996804.295820@g44g2000cwa.googlegroups.com> BiskyMisky www.biskymisky.com From cam.ac.uk at mh391.invalid Fri Aug 12 20:07:52 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sat, 13 Aug 2005 01:07:52 +0100 Subject: Cheese shop (was Re: python2.4/site-packages) In-Reply-To: <ddjd0k$eku$1@rose.polar.local> References: <mailman.2991.1123783552.10512.python-list@python.org> <ddg6r7$8v9$1@gemini.csx.cam.ac.uk> <hbPKe.4343$Je.2133@newsread2.news.atl.earthlink.net> <ddhib0$497$1@gemini.csx.cam.ac.uk> <7sadneieT7f10mHfRVn-gw@speakeasy.net> <ddjd0k$eku$1@rose.polar.local> Message-ID: <ddjdku$88p$2@gemini.csx.cam.ac.uk> Ben Finney wrote: > Conversely, PyPI is a dull name with no obvious pronunciation, thus > difficult to remember; whereas Cheese Shop is a short phrase (that can > be translated), is easy to remember and has easy analogies to its > actual function. A place you visit where you can never find what you want? -- Michael Hoffman From zen19725 at zen.co.uk Fri Aug 26 19:58:32 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Sat, 27 Aug 2005 00:58:32 +0100 Subject: global interpreter lock References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <zGJNe.242$Ux3.75@newssvr21.news.prodigy.com> <868xyw9g30.fsf@bhuda.mired.org> <As_Oe.654$dw4.615@newssvr29.news.prodigy.net> <86slwymx79.fsf@bhuda.mired.org> <slrndgv04g.264.zen19725@cabalamat.somewhere> <7xoe7kjsag.fsf@ruckus.brouhaha.com> Message-ID: <slrndgvb58.312.zen19725@cabalamat.somewhere> On 26 Aug 2005 14:35:03 -0700, Paul Rubin <http://phr.cx at NOSPAM.invalid> wrote: >zen19725 at zen.co.uk (phil hunt) writes: >> >Let's see. Reality is that writing correct programs is hard. Writing >> >correct programs that use concurrency is even harder, because of the >> >exponential explosion of the order that operations can happen >> >in. Personally, I'm willing to use anything I can find that makes >> >those tasks easier. >> >> Indeed so. Use threading (or whatever) when one has to, use an >> asynchronous single-threaded process whenever you can. > >This is silly. You could say the exact same thing about if >statements. The number of paths through the program is exponential in >the number of if statements executed. So we better get rid of if >statements. It's not the number of paths that's important. What's important is *predictability*, e.g. which instruction will the computer execute next? If you only have one thread, you can tell by looking at the code what gets executed next. It's very simple. If you have 2 threads you can easily have a timing-based situation that occurs rarely but which causes your program to behave wierdly. This sort of bug is very hard to reproduce and therefore to fix. >Really, the essence of programming is to find ways of organizing the >program to stay reliable and maintainable in the face of that >combinatorial explosion. Yes, and introducing code that makes randomly-occurring bugs more likely makes debugging inherently harder. > That means facing the problem and finding >solutions, not running away. Yes, find solutions. Don't find dangerous dead-ends that look like solutions but which will give you lots of trouble. -- Email: zen19725 at zen dot co dot uk From fperez.net at gmail.com Tue Aug 2 13:40:37 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Tue, 02 Aug 2005 11:40:37 -0600 Subject: Dabo in 30 seconds? References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <200508010830.27322.ed@leafe.com> <dclgn7$kja$1@sea.gmane.org> <200508011220.41469.ed@leafe.com> Message-ID: <dcob6m$cl0$1@sea.gmane.org> Ed Leafe wrote: > On Monday 01 August 2005 11:56, Terry Reedy wrote: > >> That is an impossibility. ?However, there is a middle path between that and >> no defensive code. ?In the present case, you appear to acknowledge a known >> easy way to mis-compile wxWidgets from Dabo's viewpoint. ?If there is a >> known easy way to detect that misconfiguration (which I suspect there is), >> and it is known that someone has tripped over that problem (which it now >> is), then a nice error message ?like 'Sorry, Dabo need wxWidgets compiled >> with the --include_stylized_text option' would certainly be friendlier than >> a stack trace. > > OK, that's more of what I had in mind. Truth be told, this is the first time > we've run into this, and as a result I'll make the change to that import > statement today. <plug, but hopefully a useful one> You may want to steal the crash handling code from ipython. In order to address this kind of problem, ipython sticks an exceptionally verbose traceback printer into sys.excepthook. If ipython ever crashes, the user gets a LOT of info, and it's all packaged ready to go, to be emailed to me. Here's an example of the result (I stuck 1/0 inside to force the crash): In [1]: print 'hello' hello In [2]: --------------------------------------------------------------------------- exceptions.ZeroDivisionError Python 2.3.4: /usr/bin/python Tue Aug 2 11:21:46 2005 A problem occured executing Python code. Here is the sequence of function calls leading up to the error, with the most recent (innermost) call last. /home/fperez/usr/bin/ipython -2 import IPython -1 0 IPython.Shell.start().mainloop() /usr/local/home/fperez/code/python/IPython/Shell.py in mainloop(self=<IPython.Shell.IPShell instance>, sys_exit=0, banner=None) /home/fperez/code/python/IPython/iplib.py in mainloop(self=<IPython.iplib.InteractiveShell instance>, banner='Python 2.3.4 (#1, Feb 2 2005, 12:11:53) \nType "...ut \'object\'. ?object also works, ?? prints more.\n') 1263 1264 def mainloop(self,banner=None): 1265 """Creates the local namespace and starts the mainloop. 1266 1267 If an optional banner argument is given, it will override the 1268 internally created default banner.""" 1269 1270 self.name_space_init() 1271 if self.rc.c: # Emulate Python's -c option 1272 self.exec_init_cmd() 1273 if banner is None: 1274 if self.rc.banner: 1275 banner = self.BANNER+self.banner2 1276 else: 1277 banner = '' -> 1278 self.interact(banner) self.interact = <bound method InteractiveShell.interact of <IPython.iplib.InteractiveShell instance at 0x4005ffac>> banner = 'Python 2.3.4 (#1, Feb 2 2005, 12:11:53) \nType "copyright", "credits" or "license" for more information.\n\nIPython 0.6.16_svn -- An enhanced Interactive Python.\n? -> Introduction to IPython\'s features \n%magic -> Information about IPython\'s \'magic\' % functions.\nhelp -> Python\'s own help system.\nobject? -> Details about \'object\'. ?object also works, ?? prints more.\n' 1279 1280 def exec_init_cmd(self): 1281 """Execute a command given at the command line. 1282 1283 This emulates Python's -c option.""" 1284 1285 sys.argv = ['-c'] 1286 self.push(self.rc.c) 1287 1288 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0): 1289 """Embeds IPython into a running python program. 1290 1291 Input: 1292 1293 - header: An optional header message can be specified. [...] LOTS MORE: each stack frame has a lot of surrounding context printed, and all locals as well. Then this is the end of the printout: 1399 except KeyboardInterrupt: -> 1400 1/0 1401 self.write("\nKeyboardInterrupt\n") 1402 self.resetbuffer() 1403 more = 0 1404 # keep cache in sync with the prompt counter: 1405 self.outputcache.prompt_count -= 1 1406 1407 if self.autoindent: 1408 self.readline_indent = 0 1409 1410 except bdb.BdbQuit: 1411 warn("The Python debugger has exited with a BdbQuit exception.\n" 1412 "Because of how pdb handles the stack, it is impossible\n" 1413 "for IPython to properly format this particular exception.\n" 1414 "IPython will resume normal operation.") 1415 ZeroDivisionError: integer division or modulo by zero ********************************************************************** Oops, IPython crashed. We do our best to make it stable, but... A crash report was automatically generated with the following information: - A verbatim copy of the traceback above this text. - A copy of your input history during this session. - Data on your current IPython configuration. It was left in the file named: '/home/fperez/.ipython/IPython_crash_report.txt' If you can email this file to the developers, the information in it will help them in understanding and correcting the problem. You can mail it to Fernando Perez at fperez at colorado.edu with the subject 'IPython Crash Report'. If you want to do it now, the following command will work (under Unix): mail -s 'IPython Crash Report' fperez at colorado.edu < /home/fperez/.ipython/IPython_crash_report.txt To ensure accurate tracking of this issue, please file a report about it at: http://www.scipy.net/roundup/ipython (IPython's online bug tracker). [END IPYTHON CRASH PRINTOUT] The point is that something like this: - gives an experienced user a lot of information to track down the bug if they feel like it. - but also gives the raw newbie an easy solution: just mail me that auto-generated crash file and forget about it. In fact, I've received over the years many tracebacks with enough detail for me to fix a problem in ipython (or to code defensively against broken third-party libs or bugs in the stdlib). And many of these problems could only be reproduced with user data I had no access to, but the traceback has enough detail that I can often understand the problem and fix it just based on that. This approach has worked very well for me over the years, and these crash report emails have become fortunately rather rare as of late :) If you are interested, just get ipython and grab the files for this, it's all BSD licensed. You can also browse the SVN repo here if you want to look at the code: http://ipython.scipy.org/svn/ipython/ipython/trunk/IPython/ The relevant files are ultraTB.py and CrashHandler.py. Cheers, f From http Mon Aug 8 23:37:01 2005 From: http (Paul Rubin) Date: 08 Aug 2005 20:37:01 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <mailman.2788.1123361707.10512.python-list@python.org> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <donn-83AF39.11565508082005@gnus01.u.washington.edu> <7x8xzcck9d.fsf@ruckus.brouhaha.com> <86wtmvlti7.fsf_-_@bhuda.mired.org> Message-ID: <7xoe87vl0i.fsf@ruckus.brouhaha.com> Mike Meyer <mwm at mired.org> writes: > Well, I tried sending this via email, but I can't derive a valid > address from Paul's anti-spammed address. Yeah, I should update that url since they turned off the forwarding. It should be <http://paulrubin.com>. But a thread titled "decline and fall of scripting languages" is reasonably on-topic for clpy, and discussion of non-Python languages is reasonable for a thread with such a title. So replying to the newsgroup is appropriate. > If you're thinking about checking out Ada, you might want to take a > look at D. I haven't gotten very far into it myself (I was attracted > by DbC), but it looks like a modern redesign of C: GC, OO, and > typedefs that actually define new types, while still being something > it's possible to generate reasonably fast code for. Yeah, I've looked at D and it seems pretty nicely designed, much more tasteful than C++. So far though, it seems to have only one implementation and not much of a user base. I dunno that I'm really that interested in checking out Ada. It seems like a dead end. Its main virtue is that it can target small embedded processors, which I don't know if D can do all that easily. Right now I'm mainly interested in OCaml, Haskell, Erlang, and maybe Occam. Haskell seems to have the happiest users, which is always a good thing. Erlang has been used for real-world systems and has built-in concurrency support. OCaml seems to crush Haskell and Erlang (and even Java) in performance. Occam isn't used for much practical any more, but takes a purist approach to concurrency that seems worth studying. The idea is to use one of those languages for a personal project after my current work project wraps up pretty soon. This would be both a learning effort and an attempt to write something useful. I'm thinking of a web application like a discussion board or wiki, intended to outperform the existing ones, i.e. able to handle a Slashdot or Wikipedia sized load (millions of hits/day) on a single fast PC instead of a rack full. "Single fast PC" will probably soon come to mean a two-cpu-chip motherboard in a 1U rack box, where each cpu chip is a dual core P4 or Athlon, so the application should be able to take advantage of at least 4-way multiprocessing, thus the interest in concurrency. From bokr at oz.net Mon Aug 1 08:34:05 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 01 Aug 2005 12:34:05 GMT Subject: namespaces References: <42EC9690.2040301@tiscali.it><dci1r3$g6i$1@sea.gmane.org> <mailman.2450.1122803387.10512.python-list@python.org> <pan.2005.07.31.11.14.22.657414@REMOVETHIScyber.com.au> <mailman.2453.1122812091.10512.python-list@python.org> <1122826472.004836.273980@g43g2000cwa.googlegroups.com> <mailman.2466.1122835539.10512.python-list@python.org> Message-ID: <42ee15ba.307192259@news.oz.net> On Sun, 31 Jul 2005 21:40:14 +0200, Paolino <paolo_veronelli at tiscali.it> wrote: >George Sakkis wrote: > >> Then write a closure. You get both encapsulation and efficience, and as >> a bonus, customization of the translating function: >> >> import string >> >> def translateFactory(validChars=string.letters+string.digits, >> replaceChar='_'): >> all=string.maketrans('','') >> badcars=all.translate(all,validChars) >> table=string.maketrans(badcars, replaceChar*len(badcars)) >> def translate(text): >> return text.translate(table) >> # bind any attributes you want to be accessible >> # translate.badcars = badcars >> # ... >> return translate >> >> >> tr = translateFactory() >> tr("Hel\xfflo") > >This is clean,but I suppose it would get cumbersome if I want to have >more functions in the namespace/factory and it implies all that bindings >in the end. You are allowed to have more than one factory ;-) > >The second point also shows my perplexities about functions namespace: > >def function(): > function.foo='something' > >a=function.foo > >Traceback (most recent call last): > File "<stdin>", line 1, in ? >AttributeError: 'function' object has no attribute 'foo' > You have not yet executed the statement function.foo='something' so you should not expect to see its effect ;-) >How should I read it? The namespace is half done inside the function? > >>> def function(): ... function.foo='something' ... >>> a=function.foo Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: 'function' object has no attribute 'foo' >>> vars(function) {} Ok, to make the statement execute, execute function: >>> function() >>> a=function.foo >>> a 'something' >>> vars(function) {'foo': 'something'} Regards, Bengt Richter From peter at engcorp.com Thu Aug 18 12:36:52 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 18 Aug 2005 12:36:52 -0400 Subject: Put a url in a browsers address bar In-Reply-To: <4304B66B.6030706@ncl.ac.uk> References: <de2bcc$nkr$1@ucsnew1.ncl.ac.uk> <mailman.3223.1124381894.10512.python-list@python.org> <4304B66B.6030706@ncl.ac.uk> Message-ID: <WLOdnWQ7fcm7JJneRVn-tA@powergate.ca> Colin Gillespie wrote: >> >>> I would like to place a url in my browsers address bar, then execute. >>> How can do this? >>> >> >> def goToGoogle(): >> import webbrowser >> webbrowser.open("www.google.com"); >> > > Thanks for the quick reply. Do you know what module I would use to fill > out a form on an open web page? The answer involves Google again, but this time it is "Use Google Groups to search the archives for previous answers to questions like yours", which is good advice to follow most of the time when you have a question that seems likely to have been asked before. Try this search pattern for a start "python fill out form on web page". (Note, Google Groups, not just Google.) -Peter From ed at leafe.com Tue Aug 16 12:31:53 2005 From: ed at leafe.com (Ed Leafe) Date: Tue, 16 Aug 2005 12:31:53 -0400 Subject: Wheel-reinvention with Python In-Reply-To: <ddscpl$6nq$1@wake.carmen.se> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <slrndg1ao0.ulg.dek@bosshog.lbl.gov> <ddscpl$6nq$1@wake.carmen.se> Message-ID: <200508161231.53387.ed@leafe.com> On Tuesday 16 August 2005 05:48, Magnus Lycka wrote: > The fact that his excellent, more or less daily postings are so badly > needed does indicate a problem, either with the design of the toolkit, > or with the docs. I'm not sure which. I htink that there is such an overwhelming amount of stuff in a UI toolkit that it is impossible to create a how-to. Instead, what is needed is a whole series of smaller how-tos for various situations. I mean, there are literally thousands upon thousands of UI behaviors to work with, and no way to describe how to work with low-level drawing primitives in the same document as how to process a menu selection. > When will that wxpython book appear? According to one of the authors, Noel Rappin: "It'll be called _wxPython In Action_ by Noel Rappin and Robin Dunn. I was told to expect that it would be released in November, but the exact date will depend on how quickly we can turn around the production." So while it's still a little ways off, it's certainly within sight! -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From matt.hammond at rd.bbc.co.uk Mon Aug 22 04:19:12 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Mon, 22 Aug 2005 09:19:12 +0100 Subject: passing arguments from scale widget to function References: <430828c4$1@duster.adelaide.on.net> Message-ID: <op.svwheakamko9fo@pcx194.rd.bbc.co.uk> On Sun, 21 Aug 2005 08:09:55 +0100, m7b52000 <oh_no_you_don't at noSPAM.com> wrote: > It is proving most difficult in Python. How do I pass the .get() values > to my calculating function? Do I use the command option for each slider? > e.g command = Calc(a.get()). Obviously not cos it doesn't work. It should work if you wrap it as a lambda function. As it is, you're assigning the result of the Calc() function to the 'command' argument/parameter of the slider widget. What you actually want is to assign just the function: command = lambda : Calc(a.get()) > I am not a real programmer and do not wish to get involved in classes > and objects.... If you're using Tcl/Tk you're already using them ... what do you think your Slider widget is? :-) Hope this helps! regards Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From timr at probo.com Sat Aug 13 02:02:10 2005 From: timr at probo.com (Tim Roberts) Date: Fri, 12 Aug 2005 23:02:10 -0700 Subject: len(sys.argv) in (3,4) References: <ddfqm1$hq4$1@news2.rz.uni-karlsruhe.de> <ddg800$qeu$1@news2.rz.uni-karlsruhe.de> Message-ID: <ot2rf1t37tbbt8a6rhvb13uf87fk9lpvrc@4ax.com> Daniel Sch?le <uval at rz.uni-karlsruhe.de> wrote: > >I just tried the same code at home and it worked fine >it has to do with windows .. some settings or whatever >(python 2.4.1 installed on both) > >maybe someone have experienced the same problem >and had more luck in solving the puzzle It's an installation problem, or maybe you tried to "fix" the installation yourself. I will wager real money that it works if you say this: python vhd2h.py vhd.vhd vhd.h -o When you omit the "python" name, the operating system has to figure out how to run the command. It does that by looking the extension up in the registry, finding the command to run. In a CMD shell, do this: c:\tmp> assoc .py .py=Python.File c:\tmp> ftype Python.File I'm guessing yours will print something like this: Python.File=c:\Python24\python24.exe %1 The %1 is substituted with the name of the script being run. In this example, however, the parameters are all discarded. If you set this instead: c:\tmp> ftype Python.File=c:\python24\python23.exe "%1" "%*" The "%*" says "put the rest of the parameters here." -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mohammed at aims.ac.za Wed Aug 17 19:02:42 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Thu, 18 Aug 2005 01:02:42 +0200 Subject: List of strings Message-ID: <4303C212.3090006@aims.ac.za> Hi All Thanks for your reply , what i am doing is , i am reading from file , using readlines() , I would like to check in these lines , if there is line belong to another one or not , if it is , then i would like to delete it ['0132442\n', '13\n', '24\n'] '13' is already in '0132442' '24' is already in '0132442' Thanks From trentm at ActiveState.com Fri Aug 26 13:07:32 2005 From: trentm at ActiveState.com (Trent Mick) Date: Fri, 26 Aug 2005 10:07:32 -0700 Subject: Command Line arguments In-Reply-To: <pan.2005.08.26.11.27.50.656221@aol.com> References: <pan.2005.08.25.00.53.22.559210@aol.com> <9gtqg1lkso6m6ukipku1ac7hk9sejhi3ld@4ax.com> <pan.2005.08.25.10.46.43.465487@aol.com> <mailman.3531.1124995211.10512.python-list@python.org> <pan.2005.08.26.11.27.50.656221@aol.com> Message-ID: <20050826170732.GF2012@ActiveState.com> [michael wrote] > >> I wonder why this was needed for 2.4 and not 2.2? I don't think it was > >> lingering things from old installs because it happened on a persons > >> computer that had never had any python installed before 2.4. > > [Trent] > > It might be due to a bug in the Python 2.4 installer not setting the > > proper file associations. What installer package did you use? > > I used the python2.4.MSI from python.org site (dated 3-6-05). I think this > was the first time they went to MSI verses an exe based installer. > > it says Python 2.4 (#60 November 30th, 2004) when I start it. I think Martin has been doing MSIs for a little bit longer than that, but I'm not sure. Martin, is it possible that there is a bug in setting up the .py/Python.File association in the python2.4.msi? Here is the start of this thread: http://mail.python.org/pipermail/python-list/2005-August/296007.html What association (if any) does your Python MSI setup? Cheers, Trent -- Trent Mick TrentM at ActiveState.com From peter at engcorp.com Fri Aug 5 22:14:40 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 05 Aug 2005 22:14:40 -0400 Subject: Problem with new python (2.4.1) installation In-Reply-To: <1123293065.790239.171500@g47g2000cwa.googlegroups.com> References: <1123293065.790239.171500@g47g2000cwa.googlegroups.com> Message-ID: <VpKdnTiERsIGgGnfRVn-hw@powergate.ca> john.coppens at gmail.com wrote: > After installing python 2.4.1 (previous version 2.3.4), and installing > pygtk 2.6.2, I get the following error message (almost with any program > I try to run): > > ImportError: could not import atk [snip...] > "/usr/lib/python2.4/site-packages/PythonCAD/Interface/Gtk/gtklayers.py", > line 274, in ? > class LayerTreeModel(gtk.GenericTreeModel): > AttributeError: 'module' object has no attribute 'GenericTreeModel' > > I suspect there is a problem with paths somewhere. Can someone help me > out here? Without the traceback for the first error I can only suggest that you stick a simple print statement in the line of code just before the AttributeError is raised, like so: print gtk The result should show you what path was used to load that particular module, and if it is a path problem you can probably figure it out from there. You haven't created your own modules named "atk" or "gtk" by any chance, have you? Or have leftover .pyc or .pyo files with those names, even though the .py files are no longer present? -Peter From uval at rz.uni-karlsruhe.de Sat Aug 6 08:21:09 2005 From: uval at rz.uni-karlsruhe.de (=?UTF-8?B?RGFuaWVsIFNjaMO8bGU=?=) Date: Sat, 06 Aug 2005 14:21:09 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: <mailman.2773.1123311974.10512.python-list@python.org> References: <dcvqc2$8oi$1@news2.rz.uni-karlsruhe.de> <J7idnRFolIvxIm7fRVn-sQ@speakeasy.net> <dd0ih2$ooe$1@news2.rz.uni-karlsruhe.de> <mailman.2773.1123311974.10512.python-list@python.org> Message-ID: <dd29v3$rml$1@news2.rz.uni-karlsruhe.de> [...] > <shrug> Okay. Write a patch. Personally, I would prefer that it be a > function in cmath rather than a method because then it could be made to > work on integers and regular floats, too. Ok, but what semantic should angle/arg have, say for 3 respectively for 3.0? the same as for arg(3+0j)? From steven.bethard at gmail.com Fri Aug 19 12:57:19 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 19 Aug 2005 10:57:19 -0600 Subject: sequence slicing documentation Message-ID: <nJKdnQ0waerykpveRVn-vw@comcast.com> In trying to work out what's different between the start, stop and step of slice.indices() and the start, stop and step of sequence slicing[1] I found that some of the list slicing documentation[2] is vague. I'd like to submit a documentation fix, but I want to make sure I have it right. Here's what points (3) and (5) of the Sequence Types documentation say now: """ (3) If i or j is negative, the index is relative to the end of the string: len(s) + i or len(s) + j is substituted. But note that -0 is still 0. ... (5) The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that $0 \leq n < \frac{j-i}{k}$. In other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j is reached (but never including j). If i or j is greater than len(s), use len(s). If i or j are omitted then they become ``end'' values (which end depends on the sign of k). Note, k cannot be zero. """ I'd like to replace that second-to-last sentence in point (5) with the vague ``end'' description with something more explicit. I'd like it to read something like: """ If k is positive and i or j is omitted, they will be replaced with 0 and len(s) respectively. If k is negative and i or j is omitted, they will be replaced with -1 and -len(s)-1 respectively. Note that these replacements happen before the rule from point (3) is applied. """ I'd also like to put an example with point (5) to show this behavior in action. Something like: """ So for example:: >>> seq = 'abcde' >>> len(seq) 5 >>> 'edc' == seq[:1:-1] == seq[-1:1:-1] True >>> 'ca' == seq[2::-2] == seq[2:-5-1:-2] True Note however that manually applying the rule from point (3) (adding len(s) to any i or j that is negative) works for i, but does not work for j:: >>> seq[5-1:1:-1] 'edc' >>> seq[2:-1:-2] '' This is because Python sees the -1 in the j position and applies the rule from point (3) again. """ If a few people could check over my logic here and make sure I'm not completely misguided, I'll post a documentation fix. Thanks, STeVe [1] http://mail.python.org/pipermail/python-list/2005-August/293963.html [2] http://docs.python.org/lib/typesseq.html From chris2k01 at hotmail.com Thu Aug 25 22:54:11 2005 From: chris2k01 at hotmail.com (Chris Head) Date: Fri, 26 Aug 2005 02:54:11 GMT Subject: Jargons of Info Tech industry In-Reply-To: <3n6kkjF4qppU1@individual.net> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <gaGOe.213$5k1.200@newssvr27.news.prodigy.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <Xns96BD814C9C690castleamber@130.133.1.4> <3n6kkjF4qppU1@individual.net> Message-ID: <nvvPe.215244$tt5.180216@edtnps90> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 usenet at isbd.co.uk wrote: [snip] > ... and generally these "web based message boards" (i.e. forums I > assume you mean) have none of the useful tools that Usenet offers and > are much, much slower. [snip] Arrgh, I *emphatically* *hate* Web-based-(almost anything). Why, oh WHY, would we subject ourselves to Web-based message boards and Webmail services? When using a proper e-mail client, your bandwidth usage consists of downloading your e-mail. When using a Webmail service, your bandwidth usage consists of downloading the message, PLUS the entire user interface. Additionally, a user interface operating inside an HTML renderer can NEVER be as fast as a native-code user interface with only the e-mail message itself passed through the renderer. I mean, the way Webmail works, you're at the message list and click on a message to view. This causes a whole new page, user-interface and all, to be loaded. In comparison, that's like shutting down and re-opening your e-mail program for every single message you want to view! Why can't we use the Web for what it was meant for: viewing hypertext pages? Why must we turn it into a wrapper around every application imaginable? ... </rant> Chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (MingW32) iD8DBQFDDoRR6ZGQ8LKA8nwRAvinAKCVi3Sfztpm3ILUk7TnunPJxBEVzwCguvAu ME8mWt2eVNpPUckJ3NT39KY= =TdTk -----END PGP SIGNATURE----- From billiejoex at fastwebnet.it Sun Aug 28 17:34:33 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Sun, 28 Aug 2005 23:34:33 +0200 Subject: aproximate a number References: <NLpQe.21622$zs.18048@tornado.fastwebnet.it> <43122a2f$0$23053$636a15ce@news.free.fr> Message-ID: <M5qQe.21670$zs.21118@tornado.fastwebnet.it> Thank you. :-) From peter at somewhere.com Wed Aug 31 09:07:41 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 15:07:41 +0200 Subject: .pth files in working directory In-Reply-To: <T5KdnfnERZn0AojeRVn-oQ@powergate.ca> References: <df3vjc$4o4$1@swifty.westend.com> <T5KdnfnERZn0AojeRVn-oQ@powergate.ca> Message-ID: <df4a14$jt2$1@swifty.westend.com> Peter Hansen schrieb: > Not sure from the above description exactly what it is you want, I want a tree top/ install.py sub1/ __init__.py mod1.py sub2/ mod2.py where I can do "from sub1 import mod1" in mod2.py no matter what the absolute path of top is. To achieve this I start install.py once to retrieve the absolute dir of itself (= abspath of top/) and creates .pth files with its absolute dir in every subdirectory. > but > generally such non-standard sys.path and .pth manipulations are best > handled by a sitecustomize.py file, possibly which makes its own calls > to site.addsitedir() and such. Try "help(site)" for more. But sitecustomize.py changes the Python installation, doesn't it? This wouldn't be an advantage over putting a .pth file into .../site-packages. -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From chaghi at sion.com Sat Aug 27 20:55:19 2005 From: chaghi at sion.com (Mariano Draghi) Date: Sat, 27 Aug 2005 21:55:19 -0300 Subject: Automatic language translation In-Reply-To: <1125189465.485171.18780@g47g2000cwa.googlegroups.com> References: <1125189465.485171.18780@g47g2000cwa.googlegroups.com> Message-ID: <der1uf$1cu$1@sea.gmane.org> Jon wrote: > Does python have a module that will translate between different spoken > languages? My python program displays all of its messages in English > currently and my boss wants it to default to Korean now. > > Any ideas how to go about doing this? > You need to use gettext. Please, have a look at http://docs.python.org/lib/module-gettext.html -- Mariano From msoulier at digitaltorque.ca Mon Aug 1 22:06:47 2005 From: msoulier at digitaltorque.ca (Michael P. Soulier) Date: Mon, 1 Aug 2005 22:06:47 -0400 Subject: Why Tcl/Tk? In-Reply-To: <97c93$42e80da0$d8fe9d88$9743@PRIMUS.CA> References: <mailman.2288.1122495186.10512.python-list@python.org> <97c93$42e80da0$d8fe9d88$9743@PRIMUS.CA> Message-ID: <20050802020646.GE6930@tigger.digitaltorque.ca> On 27/07/05 William Park said: > Old habits die hard. Soon, these folks will die off, and we'll be left > with GTK+ or wxWidgets. Not to mention dependency hell. Until wxPython is bundled with Python, it's a PITA to set it up on multiple boxes of different architectures and get all of the versions right. Java does this better. Mike -- Michael P. Soulier <msoulier at digitaltorque.ca> "Those who would give up esential liberty for temporary safety deserve neither liberty nor safety." --Benjamin Franklin -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20050801/aabf4bb8/attachment.sig> From peter at engcorp.com Fri Aug 19 08:35:04 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 19 Aug 2005 08:35:04 -0400 Subject: how do i add a new path into sys.path? In-Reply-To: <mailman.3259.1124443403.10512.python-list@python.org> References: <de1h3o$qa5$1@mail.cn99.com> <1124353535.829964.208660@o13g2000cwo.googlegroups.com> <mailman.3229.1124383746.10512.python-list@python.org> <de3i2g$t0o$1@news2.kornet.net> <mailman.3259.1124443403.10512.python-list@python.org> Message-ID: <QIGdnZ2dnZ131kLZnZ2dnWBMmN6dnZ2dRVn-0Z2dnZ0@powergate.ca> Steve Holden wrote: > The method I outlined works only for the duration of a single program > run, because the sys.path variable is set up each time you run the > Python interpreter. You need to look at the suggestions you've had for > setting the PYTHONPATH environment variable to effect changes to all > future Python execution. Or, often better and cleaner, use .pth files as described in the documentation for the standard library "site" module. -Peter From peter at engcorp.com Wed Aug 10 07:40:34 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Aug 2005 07:40:34 -0400 Subject: What is Python?! In-Reply-To: <ddcnbf$aen$02$1@news.t-online.com> References: <ddcnbf$aen$02$1@news.t-online.com> Message-ID: <3P-dnWqYNs6EdWTfRVn-2A@powergate.ca> Robert Wierschke wrote: > Having read that python is object orientated, I start wondering if > python is the right choice and what it is... > > a scripting language or a "normal" language like C++ etc. Ignore the "scripting language" label and just treat Python as a general purpose "normal" language like C++, Java, Ruby, and so forth. Judge a language by what is done with it, not by the implementation details. > So please tell me what python is, what are it's strength, what is it > good for and when should I use it and not one of the other languages. Easily findable with some web searching... Google is your friend. > Python is interpreted but is it compiled to something like the java byte > code or are there other ways to prevent the user to read my code? The simple answer is yes, it's like Java byte code, but it's Python byte code instead... As with any other language, relying on this to hide your code is inadvisable and ultimately a waste of time. -Peter From tganss_at_t_dash_online_dot_de-remove-all-after-first-real-dash at yahoo.com Thu Aug 18 14:16:40 2005 From: tganss_at_t_dash_online_dot_de-remove-all-after-first-real-dash at yahoo.com (Thomas Ganss) Date: Thu, 18 Aug 2005 19:16:40 +0100 Subject: Some questions In-Reply-To: <21cet2-2hr.ln1@lairds.us> References: <mailman.3203.1124350334.10512.python-list@python.org> <E0YMe.20135$F23.246376@twister2.libero.it> <21cet2-2hr.ln1@lairds.us> Message-ID: <de2fq4$sp2$02$1@news.t-online.com> Cameron Laird schrieb: > In article <E0YMe.20135$F23.246376 at twister2.libero.it>, > Alessandro Bottoni <alessandro.bottoni at infinito.it> wrote: > >>Titi Anggono wrote: >>>1. Can we use Tkinter for web application such as Java? ... > ... or, if you mean, "is Python an apt language for client-side > Web development in the way Java is, with the market-leading > browsers all embedding JVMs which can interpret class definitions", > the answers is, "No." And also "Yes". > > Standard Python is *not* good for client-side Web work. Jython is, > though. My blind guess would have been that Tkinter was *not* the GUI of choice for *J*ython. A quick googling turned up only Tkinter for *JP*ython 1.1 - am I [status relative python/jython newbie] missing here something ? From steve at holdenweb.com Wed Aug 24 11:19:49 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Aug 2005 11:19:49 -0400 Subject: Email client in Python In-Reply-To: <Pine.LNX.4.33.0508241653010.3502-100000@Phoenix.midascomm.com> References: <Pine.LNX.4.33.0508241653010.3502-100000@Phoenix.midascomm.com> Message-ID: <dei355$cv3$1@sea.gmane.org> knaren at midascomm.com wrote: > Hi grp, > I new to this grp and python too. > i have started writing few python scripts myself. > > now i am planning to write a bear minimum email client in > pyhton. i found the smtp module of python could serve my > pupose. I can send message using mails using the smtp lib. > Now i'm looking for some modules which can help me in > fetching the mails from the mailserver and managing folders. > > I also look for some existing mail client, written in python > which wud serve my cause. > > i searched google for no avail. > I'd recommend the poplib library. There is also imaplib, but that is much more difficult to use. Examples of use: http://docs.python.org/lib/pop3-example.html http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82233 http://effbot.org/zone/librarybook/network-protocols.pdf regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gene.tani at gmail.com Sun Aug 21 10:01:30 2005 From: gene.tani at gmail.com (gene tani) Date: 21 Aug 2005 07:01:30 -0700 Subject: import __main__ where can i find a module called "__main__.py"? In-Reply-To: <de9ts3$30td$1@mail.cn99.com> References: <de9ts3$30td$1@mail.cn99.com> Message-ID: <1124632889.966054.176800@g44g2000cwa.googlegroups.com> http://www.python.org/doc/faq/programming.html#how-do-i-find-the-current-module-name From john at castleamber.com Fri Aug 26 21:45:42 2005 From: john at castleamber.com (John Bokma) Date: 27 Aug 2005 01:45:42 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <gaGOe.213$5k1.200@newssvr27.news.prodigy.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <Xns96BD814C9C690castleamber@130.133.1.4> <3n6kkjF4qppU1@individual.net> <nvvPe.215244$tt5.180216@edtnps90> <Xns96BDF39F2CC18castleamber@130.133.1.4> <DBxPe.215291$tt5.164466@edtnps90> <Xns96BE2A09768B0castleamber@130.133.1.4> <iIHPe.197562$9A2.101810@edtnps89> <Xns96BEAF0BAA8D8castleamber@130.133.1.4> <Pine.SOL.4.58.0508261531390.8219@zen.rite-group.com> Message-ID: <Xns96BED30F1F24Bcastleamber@130.133.1.4> Rich Teer <rich.teer at rite-group.com> wrote: > On Fri, 26 Aug 2005, John Bokma wrote: > >> And workplaces. Some people have more then one computer in the house. My >> partner can check her email when I had her over the computer. When I > > I know this is entirely inappropriate and OT, but am I th eonly person > who reads that sentence with a grin? The idea of my wife checking her > email while I'm "doing her" over my computer is most amusing! :-) Aargh :-D. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From peter at somewhere.com Wed Aug 31 06:09:43 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 12:09:43 +0200 Subject: .pth files in working directory Message-ID: <df3vjc$4o4$1@swifty.westend.com> My goal is to have the top level of a directory tree in the Python path without touching anything outside the directory. I tried to create .pth files with the top level path in every subdirectory but this doesn't work despite working directory being part of the Python path. Creating the pth file in .../site-packages works but I prefer to have everything inside the directory tree so that removing the tree is sufficient for a complete uninstall. Any hints are appreciated, thanks. -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From dickinsm at verizon.net Thu Aug 25 15:20:38 2005 From: dickinsm at verizon.net (Mark Dickinson) Date: Thu, 25 Aug 2005 19:20:38 GMT Subject: Speed quirk: redundant line gives six-fold speedup References: <dickinsm-546322.12442425082005@news.verizon.net> <430E0C8D.5000506@ceid.upatras.gr> <20050825182936.GE5991@performancedrivers.com> <mailman.3532.1124995353.10512.python-list@python.org> Message-ID: <dickinsm-C0C12B.15203425082005@news.verizon.net> In article <mailman.3532.1124995353.10512.python-list at python.org>, Bill Mill <bill.mill at gmail.com> wrote: > I'm also pretty sure I've caught a bug in his code, though I'm not > sure how it works exactly. I replaced the 'min' built-in with my own > min, and he's going to get nondeterministic results from this line: > > mm = min((c.S, c) for c in rowitems(h))[1].D > > because 'c' is often the exact same object. A snippet from my > debugging version of 'min', which prints out the tuple its handed: > > (1, < main .LLentry object at 0x00969710>) > (1, < main .LLentry object at 0x00969710>) > (4, < main .LLentry object at 0x00969710>) > <snip more 4s from the same object> > (4, < main .LLentry object at 0x00969710>) > (3, < main .LLentry object at 0x00969710>) > (3, < main .LLentry object at 0x00969710>) > (3, < main .LLentry object at 0x00969710>) > (2, < main .LLentry object at 0x00969710>) > <snip more 2s, same object> The c's returned by any one call to rowitems(h) should all be distinct. This seems to work in my code---I can't reproduce your results above, and I don't *think* there's a bug there. > Although they appear in order here, they don't always. Often, multiple > objects have a value of 1, and he's going to get one of them at random > as the 'min' object. I'm pretty sure. I agree entirely---this is where my bug, and the source of all the confusion comes from. I was briefly aware as I wrote this that the result would be nondeterministic, but persuaded myself after two second's thought that it didn't matter, then forgot all about it. So mild changes in the rest of the program give rise to a different `random' choice in the min, and choosing to eunumerate all 3 possibilities for position 5,7 instead of the 3 possibilities for position 2, 1 (say) makes a huge diffference to the running time. I'm still surprised by the magnitude of the differences, though. I've learnt my lesson :) Thank you for your help, and apologies for wasting other people's time with this as well as my own! Mark From nomail at nomail.com Thu Aug 25 11:17:43 2005 From: nomail at nomail.com (Nx) Date: Thu, 25 Aug 2005 23:17:43 +0800 Subject: variable hell References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> <430dd8e1@127.0.0.1> <430ddcd0$0$719$636a15ce@news.free.fr> Message-ID: <430de100@127.0.0.1> > """ > > Why unpack inputvalues if your next step is to pack'em back again ? Or > what did I miss ? > The original values in this case are being read from a text file with one value including a linefeed per line and the original idea was, that having them read into a list was the best way to massage them into the form required to be used as input values for the insert statement. Nx From pinard at iro.umontreal.ca Wed Aug 10 19:51:11 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Wed, 10 Aug 2005 19:51:11 -0400 Subject: Recommendations for CVS systems In-Reply-To: <ZvydnVoHI8MIzmffRVn-2A@speakeasy.net> References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> <Wf-dnZ2dnZ1OB_TWnZ2dnY7CZN-dnZ2dRVn-yp2dnZ0@speakeasy.net> <ddd6fo$pmr$1@panix1.panix.com> <ZvydnVoHI8MIzmffRVn-2A@speakeasy.net> Message-ID: <20050810235111.GA7628@phenix.progiciels-bpi.ca> [Aahz] > For anything mission-critical, I wouldn't want to rely on a free license. For anything mission-critical, I wouldn't want to rely on closed sources... Could the best be open source and non-free license? :-) -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From beliavsky at aol.com Wed Aug 24 11:04:38 2005 From: beliavsky at aol.com (beliavsky at aol.com) Date: 24 Aug 2005 08:04:38 -0700 Subject: use SciPy with Python 2.4.1? Message-ID: <1124895877.968739.323680@o13g2000cwo.googlegroups.com> Is SciPy usable with Python 2.4.1? At http://www.scipy.org/download/ it says that 2.3.3 is recommended, and I don't see a binary for 2.4.1. From EP at zomething.com Tue Aug 9 01:53:42 2005 From: EP at zomething.com (EP) Date: Mon, 8 Aug 2005 21:53:42 -0800 Subject: Python -- (just) a successful experiment? In-Reply-To: <1123534185.140211.302750@o13g2000cwo.googlegroups.com> References: <20050807005406.1217660123.whereU@now.com> <mailman.2810.1123403537.10512.python-list@python.org> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <mailman.2816.1123426672.10512.python-list@python.org> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <dd5a3f$6lv$1@sea.gmane.org> <mailman.2841.1123487471.10512.python-list@python.org> <42f78937.926582004@news.oz.net> <1123534185.140211.302750@o13g2000cwo.googlegroups.com> Message-ID: <20050808215342.1671753471.EP@zomething.com> "Kay Schluehr" wrote: > I already see the headline: PEEP is the answer - PSF votes for software > patents. All ideas are written down by volunteers in great detail they > just have to be coded. Due to intellectual property rights PSF becomes > one of the richest organizations in the world. Guido van Rossum, > chairman of PSF and mighty governor of California recommends an > invasion into Iran: "we cannot accept that they didn't payed us for a > PEEP describing a steering mechism for a nuclear power station to be > written in Python. They are dangerous. They didn't have our > commitment." Mr. van Rossum also commented the unfriendly takeover of > the former software giant Microsoft that was immediately renamed into > "Snakeoil Corp." succinctly: "They had a platform we were interested > in". > > Yes, the Python experiment was (not just) successfull. (Aside) Karl, I do not think K is taking the matter seriously, even though our very survival against an axis of eval is at stake. Send some of your goons around to keep an eye on Schluehr - K may not be of, by, or for the PEEPle - and besides, I just don't like that attitude. I know, I know, Barbara says K's just a bitwise, but I've seen those weak types before. Sure makes me wish for my days of youth when we had the real James Baud, 0x007. But I assert, I will one day free this world of unlicensed coders and other rogue inventors and innovators who have no respect for the traditional logic that has always been my goto. ---------------------------------------- (Seriously) Certainly we do not want to go too far or you would not hear even a little PEEP out of me. But sometimes a rugged individual can be even more rugged and more individual if said individual has the support of friends by which to vet ideas and, by absorbing counterpoint, to develop one's own thoughts even further. And it is kind of nice when you have two teams drilling a mountain tunnel from opposite sides to have an effective way to line up efforts. EP "yes, my brain is Swiss cheese tonight" From rkern at ucsd.edu Mon Aug 29 05:08:58 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 29 Aug 2005 02:08:58 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <deuc2d$f73$1@wake.carmen.se> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRVn-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <WZaPe.1953$eQ.899@newssvr30.news.prodigy.com> <mailman.3485.1124942826.10512.python-list@python.org> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <slrndgtka9.1qv.apardon@rcpc42.vub.ac.be> <vpBPe.549$MN5.241@newssvr25.news.prodigy.net> <mailman.37.1125074193.8229.python-list@python.org> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <mailman.43.1125084774.8229.python-list@python.org> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <mailman.47.1125090294.8229.python-list@python.org> <878xyoe6m2.fsf@wilson.rwth-aachen.de> <deoif6$o12$2@sea. <deuc2d$f73$1@wake.carmen.se> Message-ID: <deujbb$om5$1@sea.gmane.org> Magnus Lycka wrote: > Robert Kern wrote: > >>If I may digress for a bit, my advisor is currently working on a project >>that is processing seafloor depth datasets starting from a few decades >>ago. A lot of this data was orginally to be processed using FORTRAN >>software, so in the idiom of much FORTRAN software from those days, 9999 >>is often used to mark missing data. Unfortunately, 9999 is a perfectly >>valid datum in most of the unit systems used by the various datasets. >> >>Now he has to find a grad student to traul through the datasets and >>clean up the really invalid 9999's (as well as other such fun tasks like >>deciding if a dataset that says it's using feet is actually using meters). > > I'm afraid this didn't end with FORTRAN. It's not that long ago > that I wrote a program for my wife that combined a data editor > with a graph display, so that she could clean up time lines with > length and weight data for children (from an international research > project performed during the 90's). 99cm is not unreasonable as a > length, but if you see it in a graph with other length measurements, > it's easy to spot most of the false ones, just as mistyped year part > in a date (common in the beginning of a new year). > > Perhaps graphics can help this grad student too? It's certainly much > easier to spot deviations in curves than in an endless line of > numbers if the curves would normally be reasonably smooth. Yes! In fact, that was the context of the discussion when my advisor told me about this project. Another student had written an interactive GUI for exploring bathymetry maps. My advisor: "That kind of thing would be really great for this new project, etc. etc." -- 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 rkern at ucsd.edu Thu Aug 25 10:21:07 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 07:21:07 -0700 Subject: RE Despair - help required In-Reply-To: <430dcea0$1@news.bezeqint.net> References: <430d8883@news.bezeqint.net> <mailman.3506.1124978020.10512.python-list@python.org> <430dcea0$1@news.bezeqint.net> Message-ID: <dekk4j$4e7$1@sea.gmane.org> Yoav wrote: > Don't think it will do much good. I need to get them from a file and > extract the last folder in the path. For example: > if I get "c:\dos\util" > I want to extract the string "\util" You mean like this: import os os.path.sep + os.path.split(r"c:\dos\util")[-1] -- 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 tjreedy at udel.edu Sat Aug 20 15:57:01 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Aug 2005 15:57:01 -0400 Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? References: <20050820134954.3750.4.NOFFLE@localhost.localdomain.local> Message-ID: <de81ud$p78$1@sea.gmane.org> "Miernik" <miernik at ffii.org> wrote in message news:20050820134954.3750.4.NOFFLE at localhost.localdomain.local... > On my Debian GNU/Linux system I have Python 2.3 installed in > /usr/lib/python2.3/ where most Python system files like > > /usr/lib/python2.3/gzip.py > /usr/lib/python2.3/gzip.pyc > /usr/lib/python2.3/gzip.pyo > > live, besides of course /usr/bin/python2.3 > > I noticed that all those files come in three "flavours": > *.py *.pyc *.pyo > > Is it possible that only one "flavour" of these files is needed, and I > can > delete the remaining two, any my Python installation will still work? > > The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting > two "flavours" would save about 10 MB on my system, and that would help > me much as I am trying to fit my system on a 256 MB SD card, to make it > quiet (hard disks are noisy). I do not know how Python files are structured on *nix, but it is possible that there are subdirectories that you can eliminate for a runtime system, such as /test. Terry J. Reedy From sjmachin at lexicon.net Thu Aug 18 21:53:05 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 11:53:05 +1000 Subject: question about binary and serial info In-Reply-To: <11g9hct6qkfsc28@corp.supernews.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> Message-ID: <43053b81$1@news.eftel.com> Grant Edwards wrote: > On 2005-08-18, nephish at xit.net <nephish at xit.net> wrote: > > >>i have an ascii string comming in the serial port and i need to convert >>it to something else, like an integer, or binary, or even a hex so i >>can use the bitwise comparison on it. Nephish, *WHY* do want to use "the bitwise comparison" on it? What do you understand a "bitwise comparison" to be? > > > But what do you mean by "integer", "binary", and "hex"? > > Decimal, hex, and binary are all representations of integers. > > On your computer all integers are 2's compliment binary "all"??? "are"??? Try: sometimes, integers are represented in 2's complEment binary form; sometimes they are represented in other forms such as unsigned binary. For example an 8-bit byte can be use to represent integers in range(-128, 128) using (signed) twos complement binary, or integers in range(0, 256) using signed binary, or integers in the range (0, 10) using decimal ASCII codes, or integers in range (0, 100) using BCD with no sign nibble, or ... > (we're > going to ignore BCD for the moment). > > The only thing that can be "decimal" or "hex" are _string_ > representations of integer values. > > If you want something upon which you can perform the bitwise > boolean operations &, ^, |, then you most probably just want an > integer object. > > To convert a string to an integer, use the int() builtin > passing it the string an an optional base: > > >>>>int("1234") Grant: The OP is reading raw output from a serial port. He's already said he's getting "funny ASCII characters". One gets the impression he thinks he needs to do bit-twiddling on *each* byte. Looks like he needs ord(), or (better) struct.unpack() Nephish: (1) Please tell us what docs you have on what the serial gadget is outputting, in what format. (2) Please show us what code you are using to read the serial port. (3) Please show us the results of print repr(some_results_of_reading_from_the_serial_port) (4) Please tell us what you like to transform (3) into, or what you need to "bitwise" compare it to. Then we might be able to give you some coherent advice. From onurb at xiludom.gro Tue Aug 2 05:58:53 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 02 Aug 2005 11:58:53 +0200 Subject: calling functions In-Reply-To: <3l7pegF10qu8cU1@individual.net> References: <3l7pegF10qu8cU1@individual.net> Message-ID: <42ef43de$0$17087$626a14ce@news.free.fr> anthonyberet wrote: > This is the first time I have tried out functions (is that the main way > of making subroutines in Python?) A function is allowed to change it's arguments and to return None, so yes, you can consider it as a 'subroutine'. > > Anyway, my function, mutate, below > > #make a child string by randomly changing one character of the parent > > Def mutate(): s/Def/def/ <meta> please copy-paste code - retyping it increases the risk of typos. </meta> > newnum=random.randrange(27) > if newnum==0: > gene=' ' > else: > gene=chr(newnum+96) > position=random.randrange(len(target)) > child=parent[:position-1]+gene+parent[position+1:] Where does this 'gene' come from ?-) > mutate() > > > The trouble is when I later (as in further down the code) attempt to > retrieve the value of gene I get an error saying that gene is undefined. Of course it is. > It works fine when I don't have the routine defined as a function. - the > IF- Else structure means gene must have a value of ' ' or 'a' to 'z'. This 'gene' only lives in the function body - as with almost any other programming language. > It seems that the line: > > mutate() > > is not invoking the function, It is. But this function does not return anything (well, it returns None, which is the Python representation of exactly nothing) - and you'd loose it if it did anyway. <non-pythonic-explanation> A variable created in a function is local to the function. It disappears as soon as the function returns - unless you keep a reference to it one way or another. The usual way to do so is to return the variable to the caller : </non-pythonic-explanation> def mutate(): newnum = random.randrange(27) if newnum == 0: gene=' ' else: gene = chr(newnum + 96) return gene gene = mutate() # target and parent where undefined... # please post working code parent = "0123456789" #position = random.randrange(len(target)) position = random.randrange(len(parent)) child=parent[:position-1]+gene+parent[position+1:] Now you may want to check your algorithm, since it doesn't perform as described - but this is another problem !-) hints: import string string.ascii_lowercase help(random.choice) astring = "abcd" alist = list(astring) alist[0] = 'z' astring2 = ''.join(alist) Also note that a function can take arguments: def fun_with_args(arg1, arg2): print "in func_with_name : arg1 = %s - arg2 = %s" % (arg1, arg2) fun_with_args('toto', 'titi') so you can have the whole algorithm in the function body: def createChild(parent): # code here to create child return child parent = "0123456789" child = createChild(parent) print "parent : %s\nchild : %s" % (parent, child) > Thanks again - this group is great. I despair of ever being able to > contribute though :-( You did. There would be no answer if there were no questions !-) BTW, may I suggest you to spend some time on a good Python tutorial ? (there are many good ones freely available on the net). HTH -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From apardon at forel.vub.ac.be Mon Aug 29 04:47:52 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 29 Aug 2005 08:47:52 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRVn-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <WZaPe.1953$eQ.899@newssvr30.news.prodigy.com> <mailman.3485.1124942826.10512.python-list@python.org> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <slrndgtka9.1qv.apardon@rcpc42.vub.ac.be> <vpBPe.549$MN5.241@newssvr25.news.prodigy.net> <mailman.37.1125074193.8229.python-list@python.org> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <mailman.56.1125109269.8229.python-list@python.org> Message-ID: <slrndh5itn.hia.apardon@rcpc42.vub.ac.be> Op 2005-08-27, Steve Holden schreef <steve at holdenweb.com>: >> >> > If you want an exception from your code when 'w' isn't in the string you > should consider using index() rather than find. Sometimes it is convenient to have the exception thrown at a later time. > Otherwise, whatever find() returns you will have to have an "if" in > there to handle the not-found case. And maybe the more convenient place for this "if" is in a whole different part of your program, a part where using -1 as an invalid index isn't at all obvious. > This just sounds like whining to me. If you want to catch errors, use a > function that will raise an exception rather than relying on the > invalidity of the result. You always seem to look at such things in a very narrow scope. You never seem to consider that various parts of a program have to work together. So what happens if you have a module that is collecting string-index pair, colleted from various other parts. In one part you want to select the last letter, so you pythonically choose -1 as index. In an other part you get a result of find and are happy with -1 as an indictation for an invalid index. Then these data meet. -- Antoon Pardon From fakeaddress at nowhere.org Wed Aug 10 14:35:27 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 18:35:27 GMT Subject: wxPython and threads again In-Reply-To: <slrndfkd1k.efj.dek@bosshog.lbl.gov> References: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> <slrndfkd1k.efj.dek@bosshog.lbl.gov> Message-ID: <PNrKe.2654$Z87.2517@newssvr14.news.prodigy.com> David E. Konerding DSD staff wrote: [...] > You need another way to pass completion information between the downloader > thread and the main thread; the simplest way is to define a custom wx > Event, and wxPostEvent from the downloader thread when it completes ( > and when the gauge should be updated). wxPostEvent is safe to call from non-eventloop threads. > The main thread's wx event loop just spins, properly updating all other > parts of the GUI, and receiving events from the downloader thread. > > ANother approach is to have a thread-safe Queue and have the main thread/event loop > poll the queue with queue.get_nowait() periodically (typically 0.1-1 sec). > The downloader thread shares the queue object and puts data structures (typically > class instances, strings, or ints) that indicate status updates. The way-cool things to transmit, in either the queue or the event data, are tuples of: (func, args, kwargs) The so-called-'main' thread gets these, and blindly calls func(*args, **kwargs). Since only the main thread can safely update the GUI, other threads pass GUI-updating functions to be called by the main thread. The technique is beautifully general. The worker thread does it's long, blocking operations independently, and when it needs to update the GUI it sends the main thread a quick, non-blocking function. In wxPython, custom events can carry arbitrary data, so the easy thing to do is just pass the (func, args, kwargs) across with wxPostEvent (or so I've read; I'm not a wxPython user). TkInter has no equivalent to wxPostEvent. Contrary to popular belief, TkInter's event_generate is not thread-safe. The usual TkInter solution is a queue, which the main thread periodically polls via the 'after' function. > The easiest approach, though, is to use the threadedselectreactor in Twisted (you need > to check the HEAD branch out with subversion, because that reactor isn't included in any releases). > With threadedselectreactor, it's easy to incorporate both the GUI event loop and the twisted reactor. > Twisted already includes lots of code for doing asynchronous callback-style IO for > IO bound processes like downloading. Further, you don't even think in an explicitly threaded way- > createing a whole thread just to manage a download process which is motly IO and a little bookkeeping is > silly. Twisted's approach just makes a lot more sense and simplifies the code too. I couldn't disagree more about that being easier and simplifying the code. "Creating a whole thread" is trivial. -- --Bryan From deets at web.de Sun Aug 7 15:10:01 2005 From: deets at web.de (Diez B.Roggisch) Date: Sun, 7 Aug 2005 19:10:01 +0000 (UTC) Subject: Some newbie cgi form questions... References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> <mailman.2812.1123410423.10512.python-list@python.org> <1123429640.905460.140210@o13g2000cwo.googlegroups.com> Message-ID: <loom.20050807T210752-738@post.gmane.org> > Traceback (most recent call last): > File "/var/www/users/senta/html/gobooks/cgi/form.py", line 35, in ? > if not form.keys()[key]: > TypeError: list indices must be integers > > As you can see, I am using python 2.3 (my web service provider is > responsible for this - I'd use 2.4.1 if I could) That code above can't work - you want something like if not form.keys() in key: Try reading the error messages. And google them. Diez From peter at engcorp.com Sat Aug 27 13:17:25 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 27 Aug 2005 13:17:25 -0400 Subject: pcapy - print the DATA field of a packet In-Reply-To: <aq0Qe.19165$zs.1542@tornado.fastwebnet.it> References: <aq0Qe.19165$zs.1542@tornado.fastwebnet.it> Message-ID: <BqKdna2KzKS5PY3eRVn-1A@powergate.ca> billiejoex wrote: > Hi all. I'm using pcapy module to sniff some ICMP packets. I would like to > modify this source: > http://www.google.it/search?hl=it&q=pcapy&btnG=Cerca+con+Google&meta= > and visualize only the DATA filed of the sniffed packets instead of all > fields that are generally visualized (for example: ip src, ip dest, packet > type...) Sorry, but *which* source are you talking about? The link you provided appears to be merely a page of Google search results. Was there a specific page in there which you meant to point us to instead? -Peter From jdhunter at ace.bsd.uchicago.edu Thu Aug 18 00:10:35 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 17 Aug 2005 23:10:35 -0500 Subject: GUI tookit for science and education References: <ddp0fc$qb2$2@achot.icm.edu.pl> <1124295749.592080.57410@o13g2000cwo.googlegroups.com> <de0k0g$ncl$1@news2.kornet.net> <mailman.3193.1124326466.10512.python-list@python.org> <de0p2n$p78$1@news2.kornet.net> <mailman.3195.1124331238.10512.python-list@python.org> Message-ID: <87pssblwas.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "Robert" == Robert Kern <rkern at ucsd.edu> writes: Robert> H = U*D*V.T Robert> then I'm more than happy with that tradeoff. The small Robert> syntactic conveniences MATLAB provides are dwarfed by the Robert> intrinsic power of Python. Of course, U*D*V (transpose omitted for clarity) is the classic problem for an interpreted language: the creation of temporaries. weave allows you, via blitz, to do chained matrix/matrix operations without multiple passes through the loop and w/o temporaries by run-time compilation and linking of extension code. Perhap's the OP's reference to JIT is referring to a just in time compilation mechanism in matlab, similar to weave's. They've already discovered LAPACK and FFTW; it wouldn't be surprising if they solved blitzm (blitz in matlab), antialiasing, alpha transparency and multiple colormaps per figure in upcoming releases. JDH From jbellis at gmail.com Thu Aug 11 00:37:50 2005 From: jbellis at gmail.com (Jonathan Ellis) Date: 10 Aug 2005 21:37:50 -0700 Subject: datagram queue length Message-ID: <1123735070.310597.20350@g14g2000cwa.googlegroups.com> I seem to be running into a limit of 64 queued datagrams. This isn't a data buffer size; varying the size of the datagram makes no difference in the observed queue size. If more datagrams are sent before some are read, they are silently dropped. (By "silently," I mean, "tcpdump doesn't record these as dropped packets.") This is a problem because while my consumer can handle the overall load easily, the requests often come in large bursts. This only happens when the sending and receiving processes are on different machines, btw. Can anyone tell me where this magic 64 number comes from, so I can increase it? Illustration follows. -Jonathan # <receive udp requests> # start this, then immediately start the other # _on another machine_ import socket, time sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', 3001)) time.sleep(5) while True: data, client_addr = sock.recvfrom(8192) print data # <separate process to send stuff> import socket for i in range(200): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.sendto('a' * 100, 0, ('***other machine ip***', 3001)) sock.close() From godwinburby at gmail.com Tue Aug 23 01:02:05 2005 From: godwinburby at gmail.com (Godwin) Date: 22 Aug 2005 22:02:05 -0700 Subject: Eve from Adams' Ribs Message-ID: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> Dear Pythoneer, I'm thinking of making a class out of an rdbms table name(let's say oracle). I can dynamically query the column names and their datatypes from oracle. So at runtime can i create a class object that creates a class for example employee with methods that can manipulate that table. For example : class Employee(object): def insert(self,**kwds): "should insert values into the table based on column and value pairs supplied" def update(self,**kwds): "should update the table" def delete(self,where): "should delete a row" def select(self,*cols,where) "should retrieve results based on columns and where clause" But the funny fact is that i want this class to be dynamically generated at run time simply from a table name string. "Yes i want to create Eve out of Adams' rib". I think its possible with python as it is called a dynamic language. Would u let me on this python secret? From prinster at mail.com Sat Aug 27 00:45:25 2005 From: prinster at mail.com (Stephen Prinster) Date: Sat, 27 Aug 2005 04:45:25 GMT Subject: Python library/module for MSAccess In-Reply-To: <mailman.59.1125110940.8229.python-list@python.org> References: <mailman.51.1125100690.8229.python-list@python.org> <430fc532$1@nntp0.pdx.net> <mailman.59.1125110940.8229.python-list@python.org> Message-ID: <FdSPe.5536$L77.4449@newssvr19.news.prodigy.com> Jonathon Blake wrote: > [ Editing/creating msaccess databases on a Linux Box, and WINE _not_ installed.] I'm pretty sure I don't understand what you are wanting to do. You say you have "msaccess databases on a Linux Box" and you are not using the Jet Database engine. As far as I know, MS Access is just a front-end to databases, with Jet as the default backend (though it can connect to many others). What backend database engine/storage format are you using? There might be a python library for connecting to it, bypassing Access altogether. From jepler at unpythonic.net Sun Aug 7 20:07:50 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sun, 7 Aug 2005 19:07:50 -0500 Subject: Metaclasses and new-style classes In-Reply-To: <3756d9750508071541192a00e0@mail.gmail.com> References: <3756d9750508071541192a00e0@mail.gmail.com> Message-ID: <20050808000746.GA13847@unpythonic.net> This may be a limitation Zope imposes. I wrote this program: #----------------------------------------------------------------------- class M(type): def __new__(*args): print "new M", args class T(object): __metaclass__ = M #----------------------------------------------------------------------- Running it prints new M (<class '__main__.M'>, 'T', (<type 'object'>,), {'__module__': '__main__', '__metaclass__': <class '__main__.M'>}) ... so you can see that the __metaclass__ mechanism works just fine with new-style objects in plain Python. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20050807/32e008cd/attachment.sig> From en.karpachov at ospaz.ru Fri Aug 5 13:19:04 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Fri, 5 Aug 2005 21:19:04 +0400 Subject: Passing a variable number of arguments to a wrapped function. In-Reply-To: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> References: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> Message-ID: <20050805211904.18661984.jk@ospaz.ru> On 5 Aug 2005 08:34:32 -0700 stephen at theboulets.net wrote: > Is there a better way of doing this so that I don't have to go through > every permutation of possible arguments (the example here from the > matplotlib 'plot' function): > > def makeplot(self, xvalues, yvalues, linecolor='', linewidth=''): > if linecolor and linewidth: > plot(xvalues, yvalues, linecolor, linewidth=linewidth) > elif linecolor: > plot(xvalues, yvalues, linecolor) > elif linewidth: > plot(xvalues, yvalues, linewidth=linewidth) > else: > plot(xvalues, yvalues) What's wrong with: def makeplot(self, xvalues, yvalues, **kwargs): plot(xvalues, yvalues, **kwargs) or even: def makeplot(self, *a, **ka): plot(*a, **ka) ? -- jk From grante at visi.com Wed Aug 24 10:13:26 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 24 Aug 2005 14:13:26 -0000 Subject: Doubt C and Python References: <mailman.3454.1124870620.10512.python-list@python.org> Message-ID: <11gp046ko61rsa5@corp.supernews.com> On 2005-08-23, praba kar <prabapython at yahoo.co.in> wrote: >>> Some people with C background use Python instead of >>> programming in C.why? >> >> Becuase it is much more efficient. >> >> -James > > What why it is more efficient. Kindly let me > know with some details. Have you read _any_ of the thread? A number of people have already explained in detail why programming in Pything is more efficient. Please read the responses you've already gotten. -- Grant Edwards grante Yow! My DIGITAL WATCH at has an automatic SNOOZE visi.com FEATURE!! From cliff at develix.com Mon Aug 1 17:52:49 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 14:52:49 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <7xack1jr3a.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <mailman.2456.1122818669.10512.python-list@python.org> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <mailman.2458.1122823396.10512.python-list@python.org> <7xvf2rync2.fsf@ruckus.brouhaha.com> <mailman.2540.1122906282.10512.python-list@python.org> <7x1x5do2da.fsf@ruckus.brouhaha.com> <mailman.2567.1122927657.10512.python-list@python.org> <7xirypjsua.fsf@ruckus.brouhaha.com> <mailman.2572.1122929708.10512.python-list@python.org> <7xack1jr3a.fsf@ruckus.brouhaha.com> Message-ID: <1122933169.19618.396.camel@localhost.localdomain> On Mon, 2005-08-01 at 14:16 -0700, Paul Rubin wrote: > Cliff Wells <cliff at develix.com> writes: > > It was quite clear that by saying "most people" he was not referring to > > the set of "most Python users", but rather the set of "most people who > > have tried wxPython". > > That wasn't clear to me. If that's what he meant, he should have said so. Paul, Honestly what appears to me to be happening here is that you have found yourself assailed on all sides and are perhaps getting a bit too quick with both your reading of posts and with your replies. The end result is you end up trying to defend your earlier statements, which, due to haste, were either worded incorrectly or based on incorrect interpretations of what others have said. Then because you feel under attack you are compelled to defend those statements further, quite probably against your own better judgement. I know I've contributed plenty to this situation (and I'll also admit to having been in similar situations before, and it's a lot easier to get into this situation than to get out of it), therefore I'll make you a deal: you slow down and put a bit more thought into your replies and I'll lay off the sideways comments and cut you some slack. In fact, enough having been said, I think I'll just try to let this thread die a natural death. Deal? Regards, Cliff P.S. I would have preferred to have made this off-list, but I can't figure out how I should decipher your email address. -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From fakeaddress at nowhere.org Fri Aug 19 19:11:33 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 19 Aug 2005 23:11:33 GMT Subject: global interpreter lock In-Reply-To: <donn-44139D.10261019082005@gnus01.u.washington.edu> References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> Message-ID: <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> Donn Cave wrote: > Bryan Olson wrote: >>On a uniprocessor system, the GIL is no problem. On multi- >>processor/core systems, it's a big loser. > > > I rather suspect it's a bigger winner there. > > Someone who needs to execute Python instructions in parallel > is out of luck, of course, but that has to be a small crowd. Today, sure. The chip guys have spoken and the future is mult- core. > I would have to assume that in most applications that need > the kind of computational support that implies, are doing most > of the actual computation in C, in functions that run with the > lock released. That seems an odd thing to assume. > Rrunnable threads is 1 interpreter, plus N > "allow threads" C functions, where N is whatever the OS will bear. > > Meanwhile, the interpreter's serial concurrency limits the > damage. The unfortunate reality is that concurrency is a > bane, so to speak -- programming for concurrency takes skill > and discipline and a supportive environment, and Python's > interpreter provides a cheap and moderately effective support > that compensates for most programmers' unrealistic assessment > of their skill and discipline. Not that you can't go wrong, > but the chances you'll get nailed for it are greatly reduced - > especially in an SMP environment. I don't see much point in trying to convince programmers that they don't really want concurrent threads. They really do. Some don't know how to use them, but that's largely because they haven't had them. I doubt a language for thread-phobes has much of a future. -- --Bryan From wouter at voti.nl Fri Aug 26 03:52:06 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Fri, 26 Aug 2005 07:52:06 GMT Subject: file access dialog Message-ID: <430ec9b1.1708219820@news.xs4all.nl> I have a tool in Python to which I want to add a small GUI. The tools currently runs everywhere PySerial is supported. I need a file-access dialog. What is the preffered way to to this? Is there a platform-independent file-access dialog available, or should I use the windows native version when running on windows (and how do I do that)? Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From prabapython at yahoo.co.in Tue Aug 23 01:15:03 2005 From: prabapython at yahoo.co.in (praba kar) Date: Tue, 23 Aug 2005 06:15:03 +0100 (BST) Subject: Doubt C and Python In-Reply-To: <200508221700.10647.hancock@anansispaceworks.com> Message-ID: <20050823051503.2138.qmail@web8402.mail.in.yahoo.com> Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? regards Prabahar ____________________________________________________ Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html From webraviteja at gmail.com Sun Aug 28 23:55:05 2005 From: webraviteja at gmail.com (Ravi Teja) Date: 28 Aug 2005 20:55:05 -0700 Subject: Embedding Python in other programs References: <pan.2005.08.25.22.26.13.801218@comcast.net> <oPEPe.31959$HM1.902582@twister1.libero.it> <312cfe2b050826084036db598f@mail.gmail.com> <mailman.54.1125108741.8229.python-list@python.org> <1125134294.509755.64030@g43g2000cwa.googlegroups.com> <mailman.68.1125161855.8229.python-list@python.org> <1125208540.068217.10960@z14g2000cwz.googlegroups.com> <312cfe2b05082810296b988cc5@mail.gmail.com> <mailman.108.1125286322.8229.python-list@python.org> Message-ID: <1125287705.710880.262750@g44g2000cwa.googlegroups.com> Greg, I don't recall touching VB6 in 4 years. From whatever I remember, you are trying to do early binding (trying to find a registered type library). You need to do late binding instead (use CreateObject) to dynamically instantiate the COM object. Ravi Teja. From zxo102 at gmail.com Fri Aug 12 00:05:43 2005 From: zxo102 at gmail.com (zxo102) Date: 11 Aug 2005 21:05:43 -0700 Subject: list to tuple Message-ID: <1123819543.351623.324870@f14g2000cwb.googlegroups.com> Hi, I got several dynamic lists a1, b1, c1, .... from a python application such as a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, .... With python, I would like to reorganize them into a tuple like t1 = ((a1[0],b1[0],c1[0],...),(a1[1],b1[1],c1[1],...),...) Anybody knows how to do that. Thanks for your help. Ouyang From jstroud at mbi.ucla.edu Wed Aug 3 14:10:21 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 3 Aug 2005 11:10:21 -0700 Subject: using httplib for authentication In-Reply-To: <1123083671.702977.251200@g14g2000cwa.googlegroups.com> References: <mailman.2652.1123037796.10512.python-list@python.org> <1123083671.702977.251200@g14g2000cwa.googlegroups.com> Message-ID: <200508031110.21333.jstroud@mbi.ucla.edu> Thank you Fuzzy, I will look into these things. Maybe the site is setting a cookie, as you have suggested. I have never delved into the ways of http except to configure apache and write some very bare-bones web pages, so I have to say that some very obvious things do not occur to me. James On Wednesday 03 August 2005 08:41 am, Fuzzyman wrote: > Hello James, > > httplib is built on top of the socket module - but is still a library > meant for doing fairly low level http operations. For fetching URLs, > urllib2 is probably the way to go. It handles GET and POST with ease. > > If you think this will do the job then you could try reading the > urllib2 tutorial at : > > http://www.voidspace.org.uk/python/articles.shtml#http > > You might wnat to look at other extension modules too - ClientCookie > for handling cookies, ClientForm for automatically filling in the > forms, BeautifulSoup for parsing HTML pages.... > > All the Best, > > Fuzzy > http://www.voidspace.org.uk/python From santafefrank at cybermesa.com Wed Aug 24 08:34:24 2005 From: santafefrank at cybermesa.com (Frank LaFond) Date: Wed, 24 Aug 2005 06:34:24 -0600 Subject: jython debugger In-Reply-To: <1124880688.306010.10820@g49g2000cwa.googlegroups.com> References: <1124880688.306010.10820@g49g2000cwa.googlegroups.com> Message-ID: <dehql5$b94$1@reader2.nmix.net> The PyDev environment (http://pydev.sourceforge.net/) for Eclipse appears to have Jython debug support, though I just tried it now and it did not work for me. The release notes http://pydev.sourceforge.net/features.html seem to suggest it should, so perhaps I just haven't configured something properly. PyDev currently only works with Java 1.5; Java 1.4 is expected, but not available yet. If you try it, let us know if you can get it to work. Frank. volpadri at aliceposta.it wrote: > Hi, > I am looking for an ide debugger for jython: is there someone with > some suggestions ? > > Thanks, > Adriano > From codecraig at gmail.com Wed Aug 17 13:01:03 2005 From: codecraig at gmail.com (codecraig) Date: 17 Aug 2005 10:01:03 -0700 Subject: Obfuscator for Python Code Message-ID: <1124298063.074422.252770@g14g2000cwa.googlegroups.com> Is there any obfuscator out there that obfuscates the python code (byte code i guess)??? From mcfletch at rogers.com Sun Aug 21 21:36:29 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Sun, 21 Aug 2005 21:36:29 -0400 Subject: Decorator and Metaclasses Documentation In-Reply-To: <pan.2005.08.21.23.29.17.273028@scrpy.org> References: <pan.2005.08.21.23.29.17.273028@scrpy.org> Message-ID: <43092C1D.2020005@rogers.com> sysfault wrote: >Does anyone know of any good documentation on these topics, doesn't look >like the official python tutorial covers them. Thanks in advance. > > PyCon 2005, PyCon 2004 and PyGTA November 2004 presentations here are all on these topics: http://www.vrplumber.com/programming/ Though the don't go into extreme detail on decorators (they are basically syntactic sugar for a particular type of descriptor). HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From pbagora at yahoo.com Mon Aug 1 14:53:31 2005 From: pbagora at yahoo.com (Pranav Bagora) Date: Mon, 1 Aug 2005 11:53:31 -0700 (PDT) Subject: Script for generating WSDL In-Reply-To: <mailman.9726.1122922203.10511.python-list@python.org> Message-ID: <20050801185332.3228.qmail@web32406.mail.mud.yahoo.com> hello, I am trying to write a python code which reads a web service and creates its corresponding wsdl file. Any idea how to do it.Please help Thanks Pranav __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From trentm at ActiveState.com Thu Aug 25 14:39:48 2005 From: trentm at ActiveState.com (Trent Mick) Date: Thu, 25 Aug 2005 11:39:48 -0700 Subject: Command Line arguments In-Reply-To: <pan.2005.08.25.10.46.43.465487@aol.com> References: <pan.2005.08.25.00.53.22.559210@aol.com> <9gtqg1lkso6m6ukipku1ac7hk9sejhi3ld@4ax.com> <pan.2005.08.25.10.46.43.465487@aol.com> Message-ID: <20050825183948.GB23904@ActiveState.com> [michael wrote] > SOLVED! Thank you. > > I wonder why this was needed for 2.4 and not 2.2? I don't think it was > lingering things from old installs because it happened on a persons > computer that had never had any python installed before 2.4. It might be due to a bug in the Python 2.4 installer not setting the proper file associations. What installer package did you use? Trent -- Trent Mick TrentM at ActiveState.com From drevil_53711 at yahoo.com Fri Aug 19 11:42:53 2005 From: drevil_53711 at yahoo.com (Steve Young) Date: Fri, 19 Aug 2005 08:42:53 -0700 (PDT) Subject: BeautifulSoup Message-ID: <20050819154253.37685.qmail@web40426.mail.yahoo.com> I tried using BeautifulSoup to make changes to the url links on html pages, but when the page was displayed, it was garbled up and didn't look right (even when I didn't actually change anything on the page yet). I ran these steps in python to see what was up: >>from BeautifulSoup import BeautifulSoup >>from urllib2 import build_opener, Request >> >>req = Request('http://www.python.org/') >>f = build_opener().open(req) >>page = f.read() >>f.close() >> >>len(page) 12040 >> >>soup = BeautifulSoup() >>soup.feed(page) >>page2 = soup.renderContents() >>len(page2) 11889 I have version 2.1 of BeautifulSoup. It seems that other ppl have used BeautifulSoup and it works fine for them so I'm not sure what I'm doing wrong. Any help would be appreciated, thanks. -Steve ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From pcolsen at comcast.net Wed Aug 10 14:12:01 2005 From: pcolsen at comcast.net (Peter Olsen) Date: Wed, 10 Aug 2005 23:12:01 +0500 Subject: Short term project Message-ID: <2.1-2711132-368-A-OEWW@smtp.comcast.net> I'd like to hear more. Michael Seeley wrote: > To: comp-lang-python-announce at moderators.isc.org > From: "Michael Seeley" <mike.seeley at sbcglobal.net> > Subject: Short term project > Date: Mon, 01 Aug 2005 20:18:47 GMT > > I have a client in Fort Worth, TX that needs a Python programmer for a > short > project. This could be a telecommuting position. Please email me at > mseeley at msxi.com if interested. > > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations.html From tjreedy at udel.edu Wed Aug 31 12:29:26 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2005 12:29:26 -0400 Subject: To the python-list moderator Message-ID: <Dpidndxiv9x4R4jeRVn-gw@comcast.com> For a couple of years, I have been reading and posting and posting to python-list and c.l.p via gmane.news.orgs gmane.comp.python.general group. Today I got this from 'python-list-bounces', which I presume is a 'machine' rather than a 'human' address. --------------------------- Your mail to 'Python-list' with the subject Re: how to join two Dictionary together? Is being held until the list moderator can review it for approval. The reason it is being held: Message has a suspicious header Either the message will get posted to the list, or you will receive notification of the moderator's decision. ----------------------------- Since I had nothing to do with the headers, the problem is between gmane's sending (perhaps when responding to a message from a particular site) and your review. I hope this can be fixed. Terry J. Reedy From fiedzia at fiedzia.prv.pl Thu Aug 25 05:27:30 2005 From: fiedzia at fiedzia.prv.pl (Maciej Dziardziel) Date: Thu, 25 Aug 2005 11:27:30 +0200 Subject: newbie question: convert a list to one string References: <1124959699.071708.239210@g14g2000cwa.googlegroups.com> Message-ID: <20050825092730.49E1.0.NOFFLE@fiedzia.homeip.net> martijn at gamecreators.nl wrote: > H! > > I'm searching for the fastest way to convert a list to one big string. > > For example: > test = ['test','test2','test3'] '-'.join(test) -- Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl) www.fiedzia.prv.pl Stewardesses is the longest word that is typed with only the left hand. From gnb at itga.com.au Thu Aug 11 21:55:29 2005 From: gnb at itga.com.au (Gregory Bond) Date: Fri, 12 Aug 2005 11:55:29 +1000 Subject: Printing literal text of an argument In-Reply-To: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> References: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> Message-ID: <iivgdd.8hb.ln@lightning.itga.com.au> Rex Eastbourne wrote: > def debug(aname, avalue): > print aname, 'is': > pprint.pprint(avalue) > use eval: def debug(s): print s, 'is' pprint.pprint(eval(s)) (it does mean the arg is a string not code......) > On a > slightly different topic, is it also possible to make the macro print > the line number where the function was first called? You can raise and catch an exception then walk up the call stack: import sys def debug(s): print s, 'is' pprint.pprint(eval(s)) try: raise "" except: tb = sys.exc_info()[2] # Find the calling frame frame = tb.tb_frame.f_back print "Called from line", frame.f_lineno See the language reference manual sec 3.2 "Standard Type Hierarchy". From lycka at carmen.se Tue Aug 23 09:39:57 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 23 Aug 2005 15:39:57 +0200 Subject: Eve from Adams' Ribs In-Reply-To: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> References: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> Message-ID: <def8vd$al2$1@wake.carmen.se> Godwin wrote: > I think its possible with python as it is called a dynamic > language. Certainly, but what's really the point with these classes? If they are completely generated from tables, they won't have different behaviour anyway, just a different chunk of attributes to fetch, save and update. It's probably as easy to just have one class, and to have a dynamic list of attributes and values that you define by passing in the table name in __init__. From me at privacy.net Fri Aug 26 09:00:41 2005 From: me at privacy.net (Dragan Cvetkovic) Date: Fri, 26 Aug 2005 09:00:41 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <Xns96BD814C9C690castleamber@130.133.1.4> <3n6kkjF4qppU1@individual.net> <Xns96BDA8A94A1C6castleamber@130.133.1.4> <3n83eqF6ogbU2@individual.net> <Xns96BE3FBBED70Fcastleamber@130.133.1.4> Message-ID: <lmy86o26py.fsf@privacy.net> John Bokma <john at castleamber.com> writes: >> A forum provides a >> single, usually rather limited, interface for the user with no way for >> the user to change it radically. > > Does the user want this? And with a user stylesheet you can change it > quite radically :-) > > And in return the user gets: colors, fonts, font sizes, embedding of > images, flash, you name it. Moving avatars, even sounds. Sounds scary. When I want to read a text, I don't need the whole multimedia experience. Bye, Dragan -- Dragan Cvetkovic, To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer !!! Sender/From address is bogus. Use reply-to one !!! From dan at cellectivity.com Thu Aug 11 07:26:01 2005 From: dan at cellectivity.com (Dan) Date: Thu, 11 Aug 2005 12:26:01 +0100 Subject: Regular expression to match a # In-Reply-To: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> Message-ID: <1123759563.6562.25.camel@localhost.localdomain> > My (probably to naive) approach is: p = re.compile(r'\b#include\b) I think your problem is the \b at the beginning. \b matches a word break (defined as \w\W or \W\w). There would only be a word break before the # if the preceding character were a \w (that is, [A-Za-z0-9_], and maybe some other characters depending on your locale). However, the \b after the "include" is exactly what you want. -- I had picked out the theme of the baby's room and done other things. I decided to let Jon have this. - Jamie Cusack (of the Netherlands), whose husband Jon finally talked her into letting him name their son Jon 2.0 From twic at urchin.earth.li Wed Aug 17 08:48:55 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 17 Aug 2005 13:48:55 +0100 Subject: FW: List copying idiom was Re: [Python-Dev] implementation of copystandard lib In-Reply-To: <mailman.3153.1124237762.10512.python-list@python.org> References: <mailman.3153.1124237762.10512.python-list@python.org> Message-ID: <Pine.LNX.4.62.0508171348310.30095@urchin.earth.li> On Wed, 17 Aug 2005, Delaney, Timothy (Tim) wrote: > Tom Anderson wrote: > >> When you say [:], do you mean that you copy lists like this: >> >> l = someList() >> m = [] >> m[:] = l > > Forwarded to python-list, where it belongs. The idiom is actually: > > a = [1, 2, 3] > b = a[:] Aha. I'd never thought of that. Doh. tom -- 10 PARTY : GOTO 10 From tjreedy at udel.edu Mon Aug 22 17:44:35 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Aug 2005 17:44:35 -0400 Subject: loop in python References: <mailman.3362.1124726899.10512.python-list@python.org><d_adnWwgVZOcYZTeRVn-gA@powergate.ca> <20050823101056.GA25131@mrna.tn.nic.in> Message-ID: <dedh03$tdg$1@sea.gmane.org> "km" <km at mrna.tn.nic.in> wrote in message news:20050823101056.GA25131 at mrna.tn.nic.in... > I agree that python emphasizes on readability which i didnt see in many > of the languages, but when the application concern is speed, does it > mean that python is not yet ready? even most of the googling abt python Funny you should mention 'googling'. Are you aware that at least the first versions of the Google web spider and indexer were written in Python? Google continues to use Python. But then, they are smarter than most people when it comes to business economics and competitive advantage. > vs perl convince me that perl is faster than python in most of the > aspects. Total cost of a computer program project includes human programmer time to write, test, revise, and maintain. For many people, Python wins on this sometimes dominant aspect. For commercial projects, calendar time to market is also critical. > Also the first thing any newbie to python asks me is abt "raw speed in > comparison with similar languages like perl" when i advocate python to > > perl. I presume by 'raw speed' you/they mean cpu execution speed as opposed to human read, write, and understanding speed. I really don't know what to say to someone who counts their own time as worthless in comparision to penny a minute CPU time. But also, I would not advocate Python over Perl to a full-time programmer who is both comfortable and productive with Perl. Terry J. Reedy From axel at white-eagle.invalid.uk Tue Aug 23 12:36:15 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Tue, 23 Aug 2005 16:36:15 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <ln8xyt7oxp.fsf@nuthaus.mib.org> <IJpOe.175886$zs4.9923722@phobos.telenet-ops.be> <jxvqPlA0RkCDFAwZ@phaedsys.demon.co.uk> Message-ID: <3gIOe.14766$5m3.4808@fe1.news.blueyonder.co.uk> In comp.lang.perl.misc Chris Hills <chris at phaedsys.org> wrote: > In article <IJpOe.175886$zs4.9923722 at phobos.telenet-ops.be>, jan V > <nul at nul.be> writes >>> +-------------------+ .:\:\:/:/:. >>> | PLEASE DO NOT | :.:\:\:/:/:.: >>> | FEED THE TROLLS | :=.' - - '.=: >>> | | '=(\ 9 9 /)=' >>> | Thank you, | ( (_) ) >>> | Management | /`-vvv-'\ >>> +-------------------+ / \ >>> | | @@@ / /|,,,,,|\ \ >>> | | @@@ /_// /^\ \\_\ >>> @x@@x@ | | |/ WW( ( ) )WW >>> \||||/ | | \| __\,,\ /,,/__ >>> \||/ | | | jgs (______Y______) >>> /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ >> >>Please don't use ASCII art... not everyone uses a fixed-width font for his >>newsreader............... > I thought usenet specified fixed font. If you use something else don't > complain. > The Troll don't look pretty in fixed font either:-) I don't think trolls are supposed to look pretty, but rather ugly. Axel From christoph.rackwitz at gmail.com Sat Aug 20 12:59:27 2005 From: christoph.rackwitz at gmail.com (Christoph Rackwitz) Date: 20 Aug 2005 09:59:27 -0700 Subject: Please Criticize My Code References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> Message-ID: <1124557167.256292.61220@g44g2000cwa.googlegroups.com> i guess, it is pythonchallenge.com level 10? if so, i used this thing: import re def enc(s): return ''.join('%s%s' % (len(a[0]),a[0][0]) for a in re.findall('((.)\\2*)', s)) From spammers-go-here at spam.invalid Sun Aug 7 14:40:22 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sun, 07 Aug 2005 14:40:22 -0400 Subject: Optional assignments ? References: <42f6456a$0$18641$14726298@news.sunsite.dk> <mailman.2819.1123436892.10512.python-list@python.org> Message-ID: <42f65592$0$18647$14726298@news.sunsite.dk> Robert Kern wrote: > Madhusudan Singh wrote: >> Hi >> >> Is it possible to have something like : >> >> a,b,c,d=fn(that returns 10 return values) ? > > a,b,c,d = fn()[:4] > Thanks ! From http Thu Aug 4 18:41:28 2005 From: http (Paul Rubin) Date: 04 Aug 2005 15:41:28 -0700 Subject: Parallel arithmetic? References: <42f298d6$1_5@alt.athenanews.com> Message-ID: <7xll3h72av.fsf@ruckus.brouhaha.com> "Terrance N. Phillip" <mediocre_person at hotmail.com> writes: > Given a and b, two equal length lists of integers, I want c to be > [a1-b1, a2-b2, ... , an-bn]. c = [a[i] - b[i] for i in xrange(len(a))] From ggg at zzz.it Tue Aug 23 10:57:21 2005 From: ggg at zzz.it (deelan) Date: Tue, 23 Aug 2005 16:57:21 +0200 Subject: Convert float to string ... In-Reply-To: <defcp7$f4n$1@fuerst.cs.uni-magdeburg.de> References: <defcp7$f4n$1@fuerst.cs.uni-magdeburg.de> Message-ID: <YLGOe.32944$TR5.28219@news.edisontel.com> Konrad M?hler wrote: > Hi, > > a simple question but i found no solution: > > How can i convert a float value into a string value? > just use the "str" built-in type: >>> f = 9.99 >>> str(f) '9.99' -- deelan, #1 fan of adriana lima! <http://www.deelan.com/> From llgloul at yahoo.fr Sat Aug 13 09:48:00 2005 From: llgloul at yahoo.fr (laurent) Date: 13 Aug 2005 06:48:00 -0700 Subject: How to find Python path in Visual C++ install wizard In-Reply-To: <42FDD8DE.9070104@v.loewis.de> References: <AOiLe.3305$DV3.1197@newssvr17.news.prodigy.com> <42FDD8DE.9070104@v.loewis.de> Message-ID: <1123940880.684436.281820@g14g2000cwa.googlegroups.com> Hello, there's a pretty solution. if the user hasn't got python or don't want to install python. You can make your application executable without a complete installation of python. for this, look at project like py2exe or freeze. These tools make an executable of your pyc files and produce some files : python.zip (for python higher 2.3) and python.dll and other dll for application that needs some dynamic python's extension. regards, Laurent From paul at boddie.org.uk Sun Aug 7 09:55:59 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 7 Aug 2005 06:55:59 -0700 Subject: Python -- (just) a successful experiment? References: <mailman.2809.1123401248.10512.python-list@python.org> Message-ID: <1123422959.086345.76190@g49g2000cwa.googlegroups.com> Eric Pederson wrote: > Why do web scripters still cling to their Perl, even in corporate environments? Ignorance. One could argue that Python should be promoted more, but Perl had the "cool tool" buzz a good ten years ago. Such habits don't fade away very quickly. > Why hasn't Python made inroads against Java? I would guess that most people deploying Java want to be able to buy and deploy some big name product with the pretense that they can always switch to another big name product later on, all in the name of "multiple vendor support". > Why is Ruby, and Ruby on Rails, getting such strong play? Relentless hype from blogging celebrities? [...] > Applications like Zope and Plone help drive more people toward the language, though the competition is stiff. If you've tried Plone, you must have noticed that it too installs itself nicely, or at least it did when I last tried it out on a proprietary operating system with no development tools of its own. This observation somewhat undermines your assertion that the vanilla Python language runtime should be bundled with the kitchen sink in order to compete with the most hyped solution of the day. Indeed, I'd suggest Zope and Plone as fairly interesting choices for those people wanting to dabble with a self-contained Web solution but who don't want to start choosing from a long list of technologies. Paul From R.Brodie at rl.ac.uk Thu Aug 4 10:59:01 2005 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Thu, 4 Aug 2005 15:59:01 +0100 Subject: Fail codecs.lookup() on 'mbcs' and 'tactis' References: <3lelp7F12526dU1@individual.net> <mailman.2717.1123167085.10512.python-list@python.org> Message-ID: <dctafm$a53$1@blackmamba.itd.rl.ac.uk> <jepler at unpythonic.net> wrote in message news:mailman.2717.1123167085.10512.python-list at python.org... > I don't know what 'tactis' is, but 'mbcs' is not a portable character set name. > It's a special character set name on win32, which refers to some system-specific > multibyte character set. > > I don't think these "failures" are a Python bug. I suppose, for consistency, it should ideally raise LookupError, though From martin.witte at gmail.com Wed Aug 31 14:13:24 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 31 Aug 2005 11:13:24 -0700 Subject: command line arguments References: <mailman.231.1125502440.8229.python-list@python.org> Message-ID: <1125512004.352928.103620@g47g2000cwa.googlegroups.com> You also could opt for the OptionParser in optparse, it is quiet powerful, and you can keep your code clean. Your requirements would translate to something like: py>#!/usr/bin/env python py>"""show OptionParser py>""" py>from optparse import OptionParser py> py>def main(): py> parser = OptionParser(usage = __doc__, version = '3.1415926') py> parser.add_option("-n", "--name", dest="name", action="store", py> help="enter a name") py> parser.add_option("-u", "--url", action="store", dest="url", help = "enter an url") py> py> (options, args) = parser.parse_args() py> if not options.name and not options.url: py> parser.error('specify both name and url') py> print options.name py> print options.url py> py>if __name__ == "__main__": py> main() when called it will print things like: martin at ubuntu:~ $ ./test.py -u www.python.org -n python {'url': 'www.python.org', 'name': 'python'} [] martin at ubuntu:~ $ ./test.py -u www.python.org -n python python www.python.org martin at ubuntu:~ $ ./test.py -h usage: show OptionParser options: --version show program's version number and exit -h, --help show this help message and exit -n NAME, --name=NAME enter a name -u URL, --url=URL enter an url martin at ubuntu:~ $ ./test.py --version 3.1415926 martin at ubuntu:~ $ ./test.py usage: show OptionParser test.py: error: specify both name and url martin at ubuntu:~ $ From onurb at xiludom.gro Tue Aug 23 13:55:28 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 23 Aug 2005 19:55:28 +0200 Subject: pipes like perl In-Reply-To: <i%IOe.95826$fm.6463957@news4.tin.it> References: <i%IOe.95826$fm.6463957@news4.tin.it> Message-ID: <430b6311$0$29696$636a15ce@news.free.fr> max(01)* wrote: > hi. (snip) > it doesn't work, since "*do_something*" and *do_something_more* are > always executed (it seems like > > MYPIPE = os.popen("*some_system_command*", "r") > > does not raise any exception even if *some_system_command* does not > exist/work... > > any help? http://www.python.org/doc/2.4.1/lib/os-newstreams.html#os-newstreams """ The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None is returned. """ -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From cliff at develix.com Mon Aug 1 16:50:36 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 13:50:36 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <mark-CECC3A.15265501082005@news.isp.giganews.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <mailman.2438.1122791233.10512.python-list@python.org> <7xd5ozv1ng.fsf@ruckus.brouhaha.com> <mailman.2467.1122835539.10512.python-list@python.org> <7xek9e5ywq.fsf@ruckus.brouhaha.com> <mailman.2495.1122858673.10512.python-list@python.org> <mark-CECC3A.15265501082005@news.isp.giganews.com> Message-ID: <1122929436.19618.368.camel@localhost.localdomain> On Mon, 2005-08-01 at 15:26 -0400, Mark Roseman wrote: > > How can I embed a browser in Tk (I mean a real browser, like Mozilla, > > Safari, or even Exploder)? At all? On any platform? This has always > > been the tradeoff for Tk. > > Try this as one example: > http://wiki.tcl.tk/4094 Okay, I figured if any, Win32 would be the one that worked, and I even recall seeing this example at one time. However, last time I checked, this bit of code wasn't actually working (although it may have been a temporary situation). Still, that leaves Linux and Mac out in the cold. But I'll admit you met my challenge. Most likely you can actually do most of the things with Tk you can with Wx, it's simply a matter of how much effort is going to be (for instance, it's certainly quite possible to embed Gecko in Tk, but I for one am not likely to be up to the task). > I'd respectfully disagree (having done large, real-world Tk apps). > You're right that Tk has a slow learning curve, which makes it easy to > knock out simple interfaces really quickly - and generally ones that are > not too impressive looking. You can do more sophisticated ones, and > ones that blend properly into the platforms you're working on - however, > the amount of effort and learning curve increase substantially. This is > because you end up needing to do a lot more fiddling, looking at or > using any of a large number of add-on packages, etc.). Yes, this was my finding with Tk. I ended up using Pmw.MegaWidgets and a few other things to make up for deficiencies in the core library, but mostly I found a need to write highly sophisticated controls myself, many of which were simply provided by wxPython. I was spending more time writing controls than writing applications. It was kind of fun and interesting, but not very productive. This is what prompted my move to wxPython several years ago. I still believe wxPython to be a much more rapidly evolving toolkit (although my tracking of Tk has fallen to almost nil since the switch so I'm willing to stand corrected or at least leave the point open to debate). The native look-and-feel across all platforms was another big motivation, but no the primary one. Mostly I found that the steeper learning curve paid off quite well in the long run. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From ed at leafe.com Tue Aug 2 14:02:13 2005 From: ed at leafe.com (Ed Leafe) Date: Tue, 2 Aug 2005 14:02:13 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <dcob6m$cl0$1@sea.gmane.org> References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <200508011220.41469.ed@leafe.com> <dcob6m$cl0$1@sea.gmane.org> Message-ID: <200508021402.13474.ed@leafe.com> On Tuesday 02 August 2005 13:40, Fernando Perez wrote: > The point is that something like this: > > - gives an experienced user a lot of information to track down the bug if > they feel like it. > > - but also gives the raw newbie an easy solution: just mail me that > auto-generated crash file and forget about it. Thanks! This looks like a great approach - I may have to borrow it! -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From peter at engcorp.com Wed Aug 31 12:06:32 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 31 Aug 2005 12:06:32 -0400 Subject: command line arguments In-Reply-To: <mailman.231.1125502440.8229.python-list@python.org> References: <mailman.231.1125502440.8229.python-list@python.org> Message-ID: <gJmdnZ2dnZ2agSD-nZ2dnRBIiN6dnZ2dRVn-yJ2dnZ0@powergate.ca> Jon Hewer wrote: > i am writing a little script and currently implementing command line > arguments following the guide by mark pilgrim from dive into python; > > http://diveintopython.org/scripts_and_streams/command_line_arguments.html > > thats all fine, however i am not sure of the BEST way to handle > multiple command line arguments > > for my script, i want to be able to accept two arguments, a name and a > url, but i am not sure if its best to use one command line option/flag > (eg -n to specify name) and then grab the url from the extra data > which will be in 'args': > > opts, args = getopt.getopt(sys.argv[1:], "n:", ["name="]) > > or to have two command line options/flags, -n and -u, and checking > that these have both been specified and then proceeding (this might be > a little messier) > > any tips would be much appreciated I would approach this as a usability issue for your users, rather than from the point of view of which is "a little messier" in the code. What's the purpose of this utility? Is it to do something with the URL? And the URL must always be specified? What about the name? Also mandatory, or optional? The relationship between the two? I would guess (without yet knowing what you are doing) that if these things are not really *optional*, making them options is not the best approach and you might be better off just requiring them to be specified on the command line as two arguments. -Peter From nospam at here.com Wed Aug 17 08:45:26 2005 From: nospam at here.com (Matt Feinstein) Date: Wed, 17 Aug 2005 08:45:26 -0400 Subject: Off-screen rendering in PyOpenGL? Message-ID: <62c6g1d76usot8aub2dptonujeasnutlsk@4ax.com> Poking around in the PyOpenGL tarball... I can see that the wrapper for the WGL pixel format function includes flags for rendering to a bitmap and for hardware acceleration... so maybe I could get hardware-accelerated off-screen rendering under win32.. but what about linux? Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From me at jonbowlas.com Tue Aug 16 09:24:55 2005 From: me at jonbowlas.com (Jon Bowlas) Date: Tue, 16 Aug 2005 14:24:55 +0100 Subject: looping list problem In-Reply-To: <ddsn27$g7d$1@sea.gmane.org> Message-ID: <ECOWS02MyAs6jn2F3I400005783@smtp-out2.blueyonder.co.uk> Ok so I changed it to this: attobject = context.get_attobject() navstring = context.get_uclattribute(attobject, 'ucl_navhide') hiddennavelements = navstring.split(' ') for hiddennavelement in hiddennavelements: yield hiddennavelements But I get the following error- Line 5: Yield statements are not allowed. Any ideas -----Original Message----- From: python-list-bounces+me=jonbowlas.com at python.org [mailto:python-list-bounces+me=jonbowlas.com at python.org] On Behalf Of Fredrik Lundh Sent: 16 August 2005 13:44 To: python-list at python.org Subject: Re: looping list problem Jon Bowlas wrote: > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > hiddennavelements = navstring.split(' ') > for hiddennavelement in hiddennavelements: > return hiddennavelement > > So the script 'get_attobject' basically looks for an instance of the > attributes object in the current folder, if it doesn't locate one then it > uses acquisition to find one in a parent folder. The script > 'get_uclattribute' then gets the nodeValues of the requested node. In this > instance its ucl_navhide, then I split the 'navstring' string at the spaces > and attempt the for-loop to output each of the values. > > Unfortunately it appears I am unable to loop through each of the list items > in hiddennavelements, as it only returns the first value & will not repeat. did you perhaps mean to use "yield" instead of "return" ? </F> -- http://mail.python.org/mailman/listinfo/python-list From e-huss at netmeridian.com Sun Aug 21 03:07:28 2005 From: e-huss at netmeridian.com (Eric Huss) Date: Sun, 21 Aug 2005 00:07:28 -0700 (PDT) Subject: subpackage import problem Message-ID: <Pine.BSF.4.58.0508202343080.55728@wintermute.sponsor.net> I'm having a problem with packages within packages. Here's an example: foo/ foo/__init__.py: empty file foo/sub/__init__.py: from foo.sub.B import B foo/sub/A.py: class A: pass foo/sub/B.py import foo.sub.A class B(foo.sub.A): pass Trying to "import foo.sub" will result in this error: >>> import foo.sub Traceback (most recent call last): File "<stdin>", line 1, in ? File "foo/sub/__init__.py", line 1, in ? from foo.sub.B import B File "foo/sub/B.py", line 3, in ? class B(foo.sub.A): AttributeError: 'module' object has no attribute 'sub' This can be fixed using a relative import in B.py, but I don't feel comfortable with relative package imports (unintentional shadowing of modules you want to use in the future, and the symantics might change in the future due to PEP 328). Does anyone have any suggestions? The situation this comes up is: - Have package foo with module bar. - Module bar has a large number of classes. - I want to break bar up into multiple files because it is getting too large. - In order to keep these classes together, I create a subpackage with a separate file for each class. - I import these files in the subpackage __init__.py so I don't have to change any other code and so I don't have foo.bar.flashlight.flashlight() lines where the word "flashlight" is repeated. -Eric From tprimke at interia.pl Wed Aug 17 06:08:11 2005 From: tprimke at interia.pl (TPJ) Date: 17 Aug 2005 03:08:11 -0700 Subject: Standalone applications ? In-Reply-To: <1124016548.909588.77090@g47g2000cwa.googlegroups.com> References: <42feba84$0$18644$14726298@news.sunsite.dk> <pan.2005.08.14.04.06.55.77838@free.net.ph> <42feca21$0$18650$14726298@news.sunsite.dk> <1124016548.909588.77090@g47g2000cwa.googlegroups.com> Message-ID: <1124273290.838341.246820@g49g2000cwa.googlegroups.com> Well, I think I must answer to my own post... There is at least one reason to bother with executables. I have just read a message. Someone wanted to run a program written in Python + wxPython. But he has failed. Why? Because the version of wxPython on his system was newer and it's API was different. Of course he could install an older (the proper) version of wxPython as well... But he's not a developer. He don't know how to install Python, wxPython and so on... And he's not interested in such knowledge. So there *is* a reason for making executables. From jitutivari at yahoo.co.uk Thu Aug 25 04:54:42 2005 From: jitutivari at yahoo.co.uk (Jitu) Date: 25 Aug 2005 01:54:42 -0700 Subject: Get datatype of a column Message-ID: <1124960082.335563.274800@g14g2000cwa.googlegroups.com> Hi does anyone know how to get a column type from a database using jdbc and python? thanks From __peter__ at web.de Thu Aug 4 11:07:50 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Aug 2005 17:07:50 +0200 Subject: Mass importing of a template based system.. Trouble with name substitutions References: <1123123110.255400.145060@g44g2000cwa.googlegroups.com> Message-ID: <dctaut$thc$00$1@news.t-online.com> rh0dium wrote: > for?mod?in?modules: > a?=?mod.mod() > a.run() Puzzle: If mod.mod did what you expect, what would a.run have to do to maintain consistency? There would be no way to determine the name of the module bound to the mod variable, but fortunately the Python developers foresaw your problem and stashed it (the name) in the __name__ attribute. Use getattr(obj, attrname) to look up an attribute whose name is not known at compile time: for mod in modules: a = getattr(mod, mod.__name__)() a.run() Peter From prabapython at yahoo.co.in Tue Aug 23 08:37:04 2005 From: prabapython at yahoo.co.in (praba kar) Date: Tue, 23 Aug 2005 13:37:04 +0100 (BST) Subject: reg packages examples In-Reply-To: <1124799829.184333.275660@g14g2000cwa.googlegroups.com> Message-ID: <20050823123704.94820.qmail@web8403.mail.in.yahoo.com> Dear All, I want to know about Modules and packages. I can understand about Modules but I cannot understand about Packages. Kindly let me know about Packages with small example. I can understand conceptually but I don't know how to write programmatically. regards Prabahar ____________________________________________________ Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html From nothingcanfulfill at gmail.com Tue Aug 9 22:02:15 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 9 Aug 2005 19:02:15 -0700 Subject: Import question In-Reply-To: <DxcKe.7898$7p.5217@bignews5.bellsouth.net> References: <1123614152.482652.72900@g44g2000cwa.googlegroups.com> <1123634807.617032.271850@g14g2000cwa.googlegroups.com> <DxcKe.7898$7p.5217@bignews5.bellsouth.net> Message-ID: <1123638871.421376.216310@g47g2000cwa.googlegroups.com> Crap. Forgot to mention that in some instances, I do want the class definitions to create new instances and such. Sorry :) From godoy at ieee.org Mon Aug 1 13:27:16 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 01 Aug 2005 14:27:16 -0300 Subject: Dabo in 30 seconds? References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <mailman.2532.1122901180.10512.python-list@python.org> <dclb4i$24l$1@news.sap-ag.de> <8ur1s2-r5t.ln1@strongwill.g2ctech> <dclg4t$54o$1@news.sap-ag.de> <m7v1s2-ld.ln1@strongwill.g2ctech> <mailman.2553.1122914852.10512.python-list@python.org> Message-ID: <gl22s2-ho2.ln1@strongwill.g2ctech> Cliff Wells wrote: > On Mon, 2005-08-01 at 13:28 -0300, Jorge Godoy wrote: >> >> We can find several problems, almost all of them can be solved with the >> admin's creativity. > >>>> import creativity > Traceback (most recent call last): > File "<stdin>", line 1, in ? > ImportError: No module named creativity >>>> > > Nope. Not included with Python. Can't be used. You haven't installed the package 'admin'. ;-) -- Jorge Godoy <godoy at ieee.org> From notanlinesgirly1 at yahoo.com Wed Aug 24 08:07:02 2005 From: notanlinesgirly1 at yahoo.com (Casee) Date: Wed, 24 Aug 2005 12:07:02 -0000 Subject: wanna stop by my homemade glory hole? Message-ID: <dehnt6+fqc7@eGroups.com> my husband is installing an extra bathroom poolside. there is a perfect size hole (unless you have a huge cock) to stick your dick through into the adjoing room. come around the side of my house(perfect if you look like a repair man) enter into the unfisnished bathroom and I'll service you from the other side. you can leave when your done, no talking or small talk. i want to do this before the hole gets patched up. its been a huge fantasy of mine ever since I've seen a glory hole online. you can email me for a time convienient for you. im home all-day most days so my schedule is open. do you prefer a certain color of lipstick? check out my pic and email here under kallegirl26 www.no-strings-fun.net/kallegirl26 ready and waiting, me ;o) From rkern at ucsd.edu Mon Aug 29 16:35:05 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 29 Aug 2005 13:35:05 -0700 Subject: new line In-Reply-To: <K1KQe.28113$hV3.11465@nntpserver.swip.net> References: <K1KQe.28113$hV3.11465@nntpserver.swip.net> Message-ID: <devrhs$1cr$1@sea.gmane.org> Kuljo wrote: > Dear friends > I'm so sorry to bore you with this trivial problem. Allthou: I have string > having 0x0a as new line, but I should have \n instead. In [9]: '\x0a' Out[9]: '\n' They're the same thing. -- 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 steve at holdenweb.com Wed Aug 24 21:35:07 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Aug 2005 21:35:07 -0400 Subject: while c = f.read(1) [comment on news hosting] In-Reply-To: <1124932777.548549.320150@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <mailman.3253.1124431515.10512.python-list@python.org> <1124702804.589011.257970@o13g2000cwo.googlegroups.com> <mailman.3350.1124706634.10512.python-list@python.org> <87fyt1mods.fsf@peds-pc311.bsd.uchicago.edu> <mailman.3395.1124762174.10512.python-list@python.org> <1124932777.548549.320150@o13g2000cwo.googlegroups.com> Message-ID: <dej776$kte$1@sea.gmane.org> Greg McIntyre wrote: > Robert Kern wrote: > >>> Robert> Please quote the message you are replying to. We have no >>> Robert> idea what "the 2nd option" is. >>> >>>I think he means the second option you presented >>> >>> If you must read one character at a time, >>> >>> def reader(fileobj, blocksize=1): >>> """Return an iterator that reads blocks of a given size from a >>> file object until EOF. >>> ...snip >>> >>>With a decent threaded news/mail reader, the thread provides >>>sufficient context, no? >> >>Not taking into account the python-list gateway or GMane. I see his >>message threaded directly under his original one. >> >>And dammit, I'm vain enough that if people are complimenting my code, I >>want to be sure about it. ;-) > > > Sorry Robert, I'm using Google Groups until I figure out the news > settings for our ISP at work (which is most unhelpful). I'm not used to > using it and the default 'Reply' option doesn't quote. :\ Not a good > excuse, I know. [...] Well you could do worse than use the gmane.comp.python.general newsgroup if you want to use an NNTP newsreader. I recently left the ISP who had provided me with news services for years, and I am very happy with the gmane service (though heaven only knows why they chose to use a name other than comp.lang.python for the group: perhaps they were only aware of the list it gateways when they established the service). Anyway, ther price is certainly right. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From nidoizo at yahoo.com Sun Aug 7 17:20:25 2005 From: nidoizo at yahoo.com (Nicolas Fleury) Date: Sun, 07 Aug 2005 17:20:25 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <42F66FF2.7010901@v.loewis.de> References: <mailman.2824.1123446062.10512.python-list@python.org> <42F66FF2.7010901@v.loewis.de> Message-ID: <dd5toi$lhg$1@sea.gmane.org> Martin v. L?wis wrote: > -1. I don't see the point of this PEP. Apparently, you want to define > parametrized types - but for what purpose? I.e. what are the specific > use cases for the proposed syntax, and why do you need to change the > language to support these use cases? I very much doubt that there are > no acceptable alternatives for each case. Well, I'm using the alternatives. For example, where I work we have built a small framework to create binary data to be loaded-in-place by C++ code (it might be presented at next GDC (Game Developer Conference)). It uses metaclasses and descriptors to allow things like: class MyObject(LoadInPlaceObject): size = Member(Int32) data = Member(makeArrayType(makePtrType(MyObject2, nullable=True))) ... I know, it's not really Python, but still, defining functions like makeArrayType and makePtrType is a pain. It is necessary to maintain a dictionary of types (to avoid redundacy) and simple things like: def makeType(someArgument): class MyObject: someArgument = someArgument return MyObject are not allowed. So its ends up with something like: __arrayTypes = {} def makeArrayType(arg1, arg2=someDefault): if (arg1, arg2) in __arrayTypes: return __arrayTypes[arg1, arg2] renamed_arg1 = arg1 renamed_arg2 = arg2 class Array: arg1 = renamed_arg1 arg2 = renamed_arg2 ... __arrayTypes[arg1, arg2] = Array return Array Does it qualify as an "acceptable alternative"? when it could have been: class Array[arg1, arg2=someDefault]: ... I probably should have put this example in the PEP. > IOW, whatever it is that you could do with this PEP, it seems you could > do this today easily. The PEP validity is also very much influenced if optional static typing is planned to be added to the language. I realize defending this PEP is much harder without static typing and my use cases imply typing of some sort anyway. Regards, Nicolas From rkern at ucsd.edu Fri Aug 19 04:55:51 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 19 Aug 2005 01:55:51 -0700 Subject: Database of non standard library modules... In-Reply-To: <d76c7b8f050819014953a63197@mail.gmail.com> References: <d76c7b8f050819014953a63197@mail.gmail.com> Message-ID: <de46qn$2f0$1@sea.gmane.org> Jon Hewer wrote: > Is there an online database of non standard library modules for Python? http://cheeseshop.python.org/pypi -- 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 titogarcia_borra_esto at gmail.com Wed Aug 10 12:14:34 2005 From: titogarcia_borra_esto at gmail.com (Tito) Date: Wed, 10 Aug 2005 18:14:34 +0200 Subject: What are modules really for? In-Reply-To: <mailman.2925.1123673242.10512.python-list@python.org> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> <ddcirs$8ep$1@news.ya.com> <mailman.2925.1123673242.10512.python-list@python.org> Message-ID: <ddd92m$o06$1@news.ya.com> Neil Benn wrote: > Tito wrote: >> N.Davis wrote: >>> Functions existing in a module? Surely if "everything is an object" >>> (OK thats Java-talk but supposedly Python will eventually follow this >>> too) then there should be nothing in a module thats not part of a class. >> >> Well, all data in a Python program are objects, in the sense that they >> have an identity on their own, and variables are only references to them. >> >> Why is it necessary to have all code into classes for meeting the >> "everything is an object" panacea? >> > If you don't have a class how can you combine functionality with data > and hold state - that is one of the points of a class. Yes, of course. You don't have OO if you cannot define your own classes. I only said that I don't find it necessary to have all code confined in classes. > Python has the > added concept that if you don;t need this you can create functions with > no associations - lots of languages do that but Java, Eiffel, C#, etc > don't have that concept. You need to make a difference between > everything is an object and everything is a class here. A programmer > coming from Java/C# wouldn't think about that. >> >>> Even a static method is simply a class function that operates on the >>> "collection of all instances" rather than a single instance. >> >> That is not true. A static method knows nothing about the instances of >> a class, unless you do it your own. Besides, it will work whether you >> have created instances of the class or not. >> >> So, a static method is just a global method declared withing a class, >> which just serves as a namespace for it. >> > In java, a static method is the same as a class method in Python, you > can then use the cls param to access class attributes (that is what teh > OP implied). However a static method can help with namespacing. What > looks better : > > initialise_local_message_router() > objPublisher = get_publisher_from_local_router('bob') > > or > > LocalRouter.initialise() > objPublisher = LocalRouter.getPublisher('bob') > > IMHO, the second case makes much more sense that a floating function > which makes things less expressive. Yes. So we agree on the fact that the class' name serves as a namespace. >>> Related classes in the same file? Be careful. Doesn't anything >>> "knowing" about anything else compromise encapsulation? Why would >>> properly-designed classes have such a close relationship? >> >> Question back: why do you think having classes defined in the same >> file compromises encapsulation? Classes don't know more about each >> other for the fact of being written into the same file. Anyway, in >> Python, classes know always too much from each other, don't they?, as >> there are no access modifiers for class attributes. >> > If I want to change one class and replace the file on the install then I > need to put a whole bunch of classes on - increasing the change of > making a mistake. Sorry, I don't understand the previous sentence. What is meant by "replace on the install"? And by "to put a whole bunch of classes on"? > Module scoping exists with globals, also you have the > convetnion of creating classes with the name of _XXX to mean module > level only. Do you mean that _XXX server as an access modifier among modules? Yes, that can be a reason to split definitions of classes into different modules. >>> Having back in the day worked on big real-time systems where being >>> very strict about encapsulation was a god-send for fighting >>> complexity, I feel unnerved by Perl and Python's laid-back OO culture >>> of "you can do it if you feel like it but don't have to". >>> >> >> >> Well, that is the case with whatever general-purpose programming >> language. You have virtually an infinite number of ways to do things, >> and most of them are not appropriate. >> >> > Some languages are more strict than others - yes you need covnentions > but you will need more conventions in a less strict language. The > upside is that, if you are careful, you can leverage the added oosness > to implement features which would be a pain in other languages. > Enterprise systems have different objectives than a cgi script or single > client install stuff. It's a judgement call. > >> The thing with Python is, in my opinion, that it wants to put all the >> power in your hands to do whatever you want in the fastest way >> possible. If I want to do something, I don't declare a class that >> knows how to do it, then create it and invoke the right method, I just >> put the code to do what I want to do. If, in between, I find that one >> class would make my life easier, I declare it just in place and go on. >> If I find repetitive tasks I can declare functions, but I won't go for >> a class immediately. Why do you think putting code into functions is >> not encapsulating? >> >>> While you could do all manner of nasty hacks in C++ I worked with >>> people who carefully avoided this. >> >> Well done, but messes you can do in whatever language. >> > Agreed but in some languages you can cause more havoc than in others, > look at the distinction .NET makes between managed and unmanaged code to > get a handle on this. Well, I wasn't talking exactly about making use of dangerous features of languages, but more about the way of using imperative object-oriented languages in a non-object-oriented way. Regards, Tito From mwm at mired.org Sat Aug 20 22:11:27 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 20 Aug 2005 22:11:27 -0400 Subject: global interpreter lock References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <7xvf2183mt.fsf@ruckus.brouhaha.com> <1124553656.678727@yasure> Message-ID: <86d5o89gz4.fsf@bhuda.mired.org> "Donn Cave" <donn at drizzle.com> writes: > Quoth Paul Rubin <http://phr.cx at NOSPAM.invalid>: > | Mike Meyer <mwm at mired.org> writes: > |> The real problem is that the concurrency models available in currently > |> popular languages are still at the "goto" stage of language > |> development. Better models exist, have existed for decades, and are > |> available in a variety of languages. > | But Python's threading system is designed to be like Java's, and > | actual Java implementations seem to support concurrent threads just fine. > I don't see a contradiction here. "goto" is "just fine", too -- > you can write excellent programs with goto. Right. The only thing wrong with "goto" is that we've since found better ways to describe program flow. These ways are less complex, hence easier to use and understand. > Mike, care to mention an example or two of the better models you > had in mind there? I've seen a couple of such, but have never been able to find the one I really liked in Google again :-(. That leaves Eiffel's SCOOP (aka Concurrent Eiffel). You can find a short intro at <URL: http://archive.eiffel.com/doc/manuals/technology/concurrency/short/page.html >. Even simpler to program in is the model used by Erlang. It's more CSP than threading, though, as it doesn't have shared memory as part of the model. But if you can use the simpler model to solve your problem - you probably should. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From devlai at gmail.com Sun Aug 7 13:24:05 2005 From: devlai at gmail.com (Devan L) Date: 7 Aug 2005 10:24:05 -0700 Subject: Some newbie cgi form questions... In-Reply-To: <1123429640.905460.140210@o13g2000cwo.googlegroups.com> References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> <mailman.2812.1123410423.10512.python-list@python.org> <1123429640.905460.140210@o13g2000cwo.googlegroups.com> Message-ID: <1123435445.757797.68940@g47g2000cwa.googlegroups.com> googleboy wrote: > for key in form.keys():Yes, I know which fields are hidden because I > made them that way, but I am trying to figure out a way I can iterate > over the fields and do one thing with hidden fields (assign them to > variables that tell the form how to process) and a different thing with > non hidden fields (present them back to the browser with after > emailling them on to the form owner). I want this script to work fro > several forms on the same webserver, some of which will have several > different and individual names. I am also hopeful that I may be able > to extrapolate from that ways to differentiate other things from my > form input things, but we'll see how it goes. > > My html code looks like this: > > <h1>Send Feedback</h1> > > <form action="cgi/formparse.py" method="get"> > <input name="subject" type="text" size="32" maxlength="196">Subject<br> > <input name="name" type="text" maxlength="64">Your name<br> > <input name="email1" type="text" size="24" maxlength="128">Your email > address. <br> > <br><br>Please let me know your thoughts below.<br><textarea > name="thoughts" cols="64" rows="12"></textarea><br> > <input type=submit value="Submit"> > <input type="hidden" name="recipient" value="foo at bar.com"> > <input type="hidden" name="email" value="foo at bar.org"> > <input type="hidden" name="mailserver" value="localhost"> > <input name="Clear" type="button" value="Clear"></form> > > > In other news, I have tried suggested syntaxes aboce (thanks guys!) but > I get strange errors. If the following: > > for key in form.keys(): > if not form.keys(): > print "<h1> ERROR! <h1><BR>" > print "Please go back and fill in all fields. All fields are > required.<br>" > > I get a traceback in teh error_log file that looks like this: > > Traceback (most recent call last): > File "cgi/form.py", line 34, in ? > for key, value in form.items(): > File "/usr/local/lib/python2.3/cgi.py", line 533, in __getattr__ > raise AttributeError, name > AttributeError: items > > if this: > > for key in form.keys(): > if not form.keys()[key]: > print "<h1> ERROR! <h1><BR>" > print "Please go back and fill in all fields. All fields are > required.<br>" > print '</body></html>' > > the I get this traceback: > > Traceback (most recent call last): > File "/var/www/users/senta/html/gobooks/cgi/form.py", line 35, in ? > if not form.keys()[key]: > TypeError: list indices must be integers > > As you can see, I am using python 2.3 (my web service provider is > responsible for this - I'd use 2.4.1 if I could) > > TIA > > googleboy >>> import cgi >>> form = cgi.FieldStorage() >>> dir(form) ['FieldStorageClass', '_FieldStorage__write', '__contains__', '__doc__', '__getattr__', '__getitem__', '__init__', '__iter__', '__len__', '__module__', '__repr__', 'bufsize', 'disposition', 'disposition_options', 'done', 'file', 'filename', 'fp', 'getfirst', 'getlist', 'getvalue', 'has_key', 'headers', 'innerboundary', 'keep_blank_values', 'keys', 'length', 'list', 'make_file', 'name', 'outerboundary', 'read_binary', 'read_lines', 'read_lines_to_eof', 'read_lines_to_outerboundary', 'read_multi', 'read_single', 'read_urlencoded', 'skip_lines', 'strict_parsing', 'type', 'type_options'] The form is not a dictionary. From ms at cerenity.org Wed Aug 3 18:07:40 2005 From: ms at cerenity.org (Michael Sparks) Date: Thu, 04 Aug 2005 00:07:40 +0200 Subject: ANN: Kamaelia 0.2.0 released! References: <mailman.2610.1122983585.10512.python-list@python.org> Message-ID: <42f14e42$0$3493$ed2619ec@ptn-nntp-reader03.plus.net> Tim Golden wrote: > I just wanted to say that I find the ideas behind Kamaelia > interesting, and I only wish I had an application for it! > Because I'm not especially into media-streaming, I'm more > interested in it from the point of view of the generator-based > architecture. It's nice to know that people find it interesting even without a direct need. (Indeed I suspect this is the case with many open source projects.) One thing we are learning as we go along is how to use generators to refactor out commonly used code out of loops like this. One example is status updating: import time def long_running_thing(foo): t = time.time()pplication for it! > Because I'm not especially into media-streaming, I'm more > interested in it from the point of view of the generator-based > architecture. It's nice to know that people find it interesting even without a direct need. (Indeed I suspect this is the case with many open source projects.) One thing we are learning as we go along is how to use generators to refactor out commonly used code out of loops like this. One example is status updating: import time def long_running_thing(foo): t = time.time() while running: << do something long running>> if time.time() - t > update_interval: print update_message An alternative to this is this: def updater(interval, message): t = time.time(): while 1: if time.time() - t > interval: print message def long_running_thing(foo): myUpdater = updater(5, "Still running") while running: << do something long running>> myUpdater.next() You can do similar things for frame rates and so on. Obviously in our system we generally go one step further and translate the resulting generators into components, but sometimes simple conversion to generators alone can make the code much clearer. Tim Golden wrote: > What prompted me to write now was in appreciation of Michael's > taking the effort to recast his words into a form which might > well be understood better by others (including me) when he > might well have simply huffed a bit and told the other poster > to read the words on the site and stop complaining about the HTML! I tend to generally think that for each poster to a newsgroup there's often several lurkers who share the same opinion, and given text is a very harsh medium, I try to make allowances for that. Answering questions can sometimes also help others to assist with documentation patches of course. Technical writing not necessarily being the same skill set as code writing or architecture design after all :-) I must admit I do remember the earlier days of usenet when people would ask a question, get several answers, and the original poster would summarise the responses (something that doesn't happen as often these days unfortunately, possibly due to services like google news making it easier to go back and see the discussion). phil hunt wrote: > (And on a more general level to improve the average quality of > documentation for open source projects. Something which is bvery > often deficient.) You have to remember as well that most open source projects rely on volunteers, and anyone can write docs. If you want to improve the average quality of docs for open source projects there is only one way to do this - to be prepared to write the documentation yourself or pay someone to do it. (In our case documentation is driven by internal need, which doesn't always match the needs of people externally. You might not've seen the white paper giving a detailed overview of the project from a technical perspective here: http://tinyurl.com/8543e) Tim Golden wrote: > Thanks, Michael. Hope the project continues apace and if I > can ever find a need for it, I'll know where to look. Thanks for your kind words. Best Regards, Michael. From clovis_q at 40networks.com Fri Aug 26 16:52:36 2005 From: clovis_q at 40networks.com (clovis_q at 40networks.com) Date: Fri, 26 Aug 2005 13:52:36 PDT Subject: posting 20050826 Message-ID: <430f8114.comp.lang.python@mail2> "Now wait a minute," I said. "If you can't make tendrils anymore, how did yo u make the call earlier today?" "I don't think that would be very helpful," Miranda said. Posted by john at 11:45 PM Best Screenplay (Adapted): Connie Reiser & Larry Card, from the book Hard Me mories by Rachel Spiegelman From gregpinero at gmail.com Mon Aug 1 17:13:36 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Mon, 1 Aug 2005 17:13:36 -0400 Subject: Distutils Question - Creating an "installer" for python users? Message-ID: <312cfe2b05080114135b4ed187@mail.gmail.com> Hey guys, I wrote a fairly simple program that has 3 python files, and needs a couple directories created to run. It also uses PythonCard. I would like make it easily distributable to users who already have Python installed. Would anyone mind explaining this in easy to follow steps or pointing me to a good tutorial (probably more newbie friendly than the one in the python docs). I already made a py2exe version for windows users without python installed so I already have a somewhat working setup.py file. Thanks in advance for your help. -- Gregory Pi?ero CEO and Founder Blended Technologies (www.blendedtechnologies.com) From opengeometry at yahoo.ca Mon Aug 22 16:40:04 2005 From: opengeometry at yahoo.ca (William Park) Date: Mon, 22 Aug 2005 16:40:04 -0400 Subject: split function References: <mailman.3373.1124739875.10512.python-list@python.org> Message-ID: <2c004$430a3824$d8fea55f$14002@PRIMUS.CA> Mohammed Altaj <mohammed at aims.ac.za> wrote: > > Dear All > > What i want to do is , my input is like > 0 2 > 0 3 > 0 4 > 1 2 > 1 4 > 2 3 > 3 4 > > I am comparing and put the number in group , like ,the first three lines > , all has zero as first input for each line, so the out put should look > like > 0 2 3 4 > and so on > 1 2 4 > 2 3 > 3 4 Use Python's dictionary (also known as associative array or hash). Read documentation. -- William Park <opengeometry at yahoo.ca>, Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From orome.the.valar at gmail.com Thu Aug 11 05:34:14 2005 From: orome.the.valar at gmail.com (sinan .) Date: Thu, 11 Aug 2005 12:34:14 +0300 Subject: read function in python serial Message-ID: <8c05f79c05081102343e9827db@mail.gmail.com> hi i`m developing a program that reads the serial device. i like the readline() function, but readline() depends on \n character, i want a similar function that waits for a specific character or string that i gave like [ETX] (hex03) how can i do this ? thank you. From ksenia.marasanova at gmail.com Wed Aug 10 03:28:49 2005 From: ksenia.marasanova at gmail.com (Ksenia Marasanova) Date: Wed, 10 Aug 2005 09:28:49 +0200 Subject: sorting question Message-ID: <130df19305081000282edf03df@mail.gmail.com> Hi, I have a list that contains nodes from a tree. Each node is a class instance, but I'll use dictionary here to simplify the example. So the list looks like this: [ {'id': 1, 'name': 'Parent node', 'ord_number': 1, 'parent_id': 0, 'url': '/parentnode/'}, {'id': 2, 'name': 'My node', 'ord_number': 1, 'parent_id': 1, 'url': '/parentnode/mynode/'} ] Where 'ord_number' is the "sibling index". It's not always properly filled in; sometimes it's the same for several siblings, or doesn't starts with 1. I want to sort this list with the following rules: 1. The parent must always come before the children in the list 2. Nodes with the same parent must be sorted by 'ord_number' The first rule is easy, cause I can use 'url' for it. List with nodes is coming from the database, so I just do "ORDER BY url". The second rule is kind of tricky to do in the database. I probably would need to do something like "ORDER BY cut_off_lastpart_from_url(url), ord_number". But there seems to be no native string function in Postgres to do it easily, so I desided to sort it in Python. So I've come up with this: def cmp_tree(x, y): if x['parent_id'] == y['parent_id']: return cmp(x['ord_number'], y['ord_number']) else: return cmp(x['url'], y['url']) nodes.sort(cmp_tree) but it doesn't work as expected. Apparently I don't have a clue about how sorting function work :( Can anybody help? -- Ksenia From NOXwebmasterx at xmbstevensx.com Fri Aug 19 23:30:14 2005 From: NOXwebmasterx at xmbstevensx.com (mbstevens) Date: Sat, 20 Aug 2005 03:30:14 GMT Subject: Moinmoin config In-Reply-To: <1124505462.437697.107950@z14g2000cwz.googlegroups.com> References: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> <18da$4304e393$506cf87a$23485@news.chello.at> <1124505462.437697.107950@z14g2000cwz.googlegroups.com> Message-ID: <atxNe.9343$RS.9185@newsread3.news.pas.earthlink.net> Mark wrote: > The missing link under /var/www/html was exactly the problem. Somehow > missed this in the labyrinth of setup instructions. > > I have another question, and as of yet, have not found another > discussion group for moinmoin, so sorry, but here goes: > > I have a table and would like the table borders to go away. Although > it doesn't talk about border widths explicitliy, the HelpOnTables seems > to point to this : > > <tablestyle="width: 80%; border: 0;"> > > But that does nothing to the border lines. Adjusting width in the same > line does work to change the size of the table, but it doesn't seem to > understand 'border'. > > Anyone know how to make the borders disappear? > > Thanks > Mark > I would try a stylesheet forum or an (X)HTML forum for this question, but first look here, http://lynx.fnal.gov/runjob/HelpOnConfiguration/CascadingStyleSheets and then look here, http://www.w3.org/TR/REC-CSS2/tables.html#borders But, if the information you're putting in the table is not true tabular data, consider more semantic markup. -- mbstevens http://www.mbstevens.com/cgi/mkatt.pl?name=python/Critique_Generator From godoy at ieee.org Mon Aug 8 09:00:43 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 08 Aug 2005 10:00:43 -0300 Subject: PyQt: Problem finding and showing a record in a QDataBrowser Message-ID: <0l1ks2-1rh.ln1@strongwill.g2ctech> [I've also posted this to pyqt-pykde list, but I haven't got any answers so far. I also thought that someone here might have solved it or have a different idea to help me :-) Sorry for those that read it twice. ] Hi. I have created an interface where I have a QDataBrowser and all of its editing and navigating controls and one of the displayed controls is in a QSpinBox. I have the navigation from current to next and previous records working fine if I only use the data browser controls. I also can recover the correct record if I type in a valid code at the spin box. For the spin box to work, I'm doing this: def codAmostra_valueChanged(self, amostra_id): cursor = self.dbAmostras.sqlCursor() cursor.select('amostra_id=%s' % amostra_id) self.dbAmostras.first() self.dbAmostras.refresh() (codAmostra is my spinbox, dbAmostras is my QDataBrowser -- just as a curiosity, "amostra" is the pt_BR for "sample") I was willing to use "self.dbAmostras.seek()", but it requires that I know the exact position of the record -- using it I wouldn't need to filter my data and I think the problem would be solved... -- but I don't know it. There can be "holes" in my sequence (otherwise I'd use only the spinbox) and I'll be having a few million entries (what makes it impossible to go through each and every record every time I change the value at the spinbox manually). I was reading Qt3 docs trying to find out some other mean to recover the record I need without messing with the filter because if I use the filter, then I can't paginate through all records anymore. Any hints on an alternative approach that would allow me to use both controls? * Python 2.4 * SIP 4.1.1 (4.1.1-255) * >>> qt.qVersion() '3.3.4' >>> Thanks in advance, -- Jorge Godoy <godoy at ieee.org> From prabapython at yahoo.co.in Mon Aug 29 06:49:48 2005 From: prabapython at yahoo.co.in (praba kar) Date: Mon, 29 Aug 2005 11:49:48 +0100 (BST) Subject: Python built email message doesn't support OutLook Express In-Reply-To: <slrndh5nh9.u8f.sybrenUSE@schuimige.unrealtower.org> Message-ID: <20050829104948.72772.qmail@web8404.mail.in.yahoo.com> --- Sybren Stuvel <sybrenUSE at YOURthirdtower.com.imagination> wrote: > praba kar enlightened us with: > > This code will build plain email message properly. > > It's not a plain email message. It's an html email > without a plain > text part. Highly annoying to many people. > > > But after building the message. If a email user > download this mail > > through out look express then this email message > will display > > without any alignment. > > Post the msg.as_string() output so we can see whay > you're sending. msg = email.MIMEBase('text','html') msg['Return-Path'] = user+'@'+domain msg['Date'] = formatdate(localtime=1) msg['Subject'] = subject msg['From'] = from_name msg['To'] = to msg['Cc'] = cc msg.set_payload("Body of the email messagge") fh = os.popen('/bin/sendmail %s'% (eachid),'w') fh.write(msg.as_string()) fh.close() Here I am sending what I was built in the message example to headers(address,cc address, subject) and Body of the mail content (ie) msg.set_payload("Body of the email messagge") regards Prabahar __________________________________________________________ Free antispam, antivirus and 1GB to save all your messages Only in Yahoo! Mail: http://in.mail.yahoo.com From rkern at ucsd.edu Tue Aug 30 07:54:38 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 30 Aug 2005 04:54:38 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <slrndh8g37.hia.apardon@rcpc42.vub.ac.be> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRVn-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <WZaPe.1953$eQ.899@newssvr30.news.prodigy.com> <mailman.3485.1124942826.10512.python-list@python.org> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <slrndgtka9.1qv.apardon@rcpc42.vub.ac.be> <vpBPe.549$MN5.241@newssvr25.news.prodigy.net> <mailman.37.1125074193.8229.python-list@python.org> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <mailman.56.1125109269.8229.python-list@python.org> <slrndh5itn.hia.apardon@rcpc42.vub.ac.be> <devuln$bro$1@sea.gmane.org> <mailman.159.1125379590.8229.python-list@python.org> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <b8VQe.472$sF6.70@newssvr24.news <slrndh8g37.hia.apardon@rcpc42.vub.ac.be> Message-ID: <df1hdu$a92$1@sea.gmane.org> Antoon Pardon wrote: > Op 2005-08-30, Robert Kern schreef <rkern at ucsd.edu>: > >>Bryan Olson wrote: >> >>> Currently, user-defined classes can implement Python >>> subscripting and slicing without implementing Python's len() >>> function. In our proposal, the '$' symbol stands for the >>> sequence's length, so classes must be able to report their >>> length in order for $ to work within their slices and >>> indexes. >>> >>> Specifically, to support new-style slicing, a class that >>> accepts index or slice arguments to any of: >>> >>> __getitem__ >>> __setitem__ >>> __delitem__ >>> __getslice__ >>> __setslice__ >>> __delslice__ >>> >>> must also consistently implement: >>> >>> __len__ >>> >>> Sane programmers already follow this rule. >> >>Incorrect. Some sane programmers have multiple dimensions they need to >>index. > > I don't see how that contradicts Bryan's statement. > >> from Numeric import * >> A = array([[0, 1], [2, 3], [4, 5]]) >> A[$-1, $-1] >> >>The result of len(A) has nothing to do with the second $. > > But that is irrelevant to the fact wether or not sane > programmes follow Bryan's stated rule. That the second > $ has nothing to do with len(A), doesn't contradict > __len__ has to be implemented nor that sane programers > already do. Except that the *consistent* implementation is supposed to support the interpretation of $. It clearly can't for multiple dimensions. -- 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 http Sat Aug 20 22:39:56 2005 From: http (Paul Rubin) Date: 20 Aug 2005 19:39:56 -0700 Subject: global interpreter lock References: <mailman.3258.1124442762.10512.python-list@python.org> <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <donn-44139D.10261019082005@gnus01.u.washington.edu> <FGtNe.785$zD3.341@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <7xvf2183mt.fsf@ruckus.brouhaha.com> <1124553656.678727@yasure> <86d5o89gz4.fsf@bhuda.mired.org> Message-ID: <7xiry0vwqr.fsf@ruckus.brouhaha.com> Mike Meyer <mwm at mired.org> writes: > Even simpler to program in is the model used by Erlang. It's more CSP > than threading, though, as it doesn't have shared memory as part of > the model. But if you can use the simpler model to solve your problem > - you probably should. Well, ok, the Python equivalent would be wrapping every shareable object in its own thread, that communicates with other threads through Queues. This is how some Pythonistas suggest writing practically all multi-threaded Python code. It does a reasonable job of avoiding synchronization headaches and it's not that hard to code that way. But I think to do it on Erlang's scale, Python needs user-level microthreads and not just OS threads. Maybe Python 3000 can add some language support, though an opportunity was missed when Python's generator syntax got defined the way it did. I've been reading a bit about Erlang and am impressed with it. Here is a good thesis about parallelizing Erlang, link courtesy of Ulf Wiger on comp.lang.functional: http://www.erlang.se/publications/xjobb/0089-hedqvist.pdf The thesis also gives a good general description of how Erlang works. From cliff at develix.com Mon Aug 1 12:06:46 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 09:06:46 -0700 Subject: Dabo in 30 seconds? In-Reply-To: <dclb4i$24l$1@news.sap-ag.de> References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <mailman.2532.1122901180.10512.python-list@python.org> <dclb4i$24l$1@news.sap-ag.de> Message-ID: <1122912406.19618.333.camel@localhost.localdomain> On Mon, 2005-08-01 at 16:21 +0200, Daniel Dittmar wrote: > Cliff Wells wrote: > > But then I'm willing to > > actually work a little to get what I want. For other it seems they > > won't be happy unless you drive to their house and install it for them > > To be fair to those slothes: some of them want to write software for a > commercial setting where they have to install it on other peoples > machines. So it isn't just getting it to work one one own's machine. > Using a specifc Python library with external dependencies means also > installing and *supporting* it on a possible large set of configurations. I can understand this, but from my experience, their concerns are badly misplaced: I recently wrote a fairly sizable Python app (~8K LOC) that utilized several 3rd party python librarys: wxPython, Twisted, FeedParser, DateUtils and SQLite to name a few off the top of my head (plus I had to repackage libxml and libxslt on OS/X because 10.3 ships with broken versions :P). It ran on Windows and OS/X (and Linux, but that was never deployed as the customer wasn't interested). This was for a *very* large customer and made it to nearly 10,000 desktops. Not one complaint had to do with installation of 3rd party packages. Why? Because I *packaged* it for them. Most of the effort I put in had little to do with any 3rd party Python library but rather just the ins and outs of each platform's packaging tools (and this can be no little pain I assure you). I will also note, out of fairness, that the port to OS/X was not as pain-free as I had hoped (wxPython was fairly new to that platform and I found more than a few bugs - most of them are resolved now, because I didn't just give up when I found them, rather I reported them and <drum roll> they got fixed! Who would have thought?!). In short, these people's complaints reveal only two things: 1) they are hopelessly pessimistic, whether out of pure laziness, lack of experience or what I'm unsure and 2) they've never actually tried very hard or perhaps even at all. Overall that's a recipe for failure in any endeavor. As I mentioned earlier, programming is half brains and half tenacity. If you lack one or the other, your chances of success are pretty slim. The sad thing is that their ability to cling so tenaciously to such an unqualified position leaves me wondering if it isn't truly the first quality that they lack. Given how easy Python makes things, I'd hate to see how they'd fare with a *real* programming language <wink>. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From en.karpachov at ospaz.ru Tue Aug 9 14:54:57 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Tue, 9 Aug 2005 22:54:57 +0400 Subject: What are modules really for? In-Reply-To: <42F8CC8F.7020500@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> Message-ID: <20050809225457.1579568b.jk@ospaz.ru> On Tue, 09 Aug 2005 16:32:31 +0100 N.Davis wrote: > With single inheritance in C++ or Java, if you wanted to see what a > method did and it appeared to be inherited, you would simply look in the > base class's file, and if necessary recurse up the inheritance hierarchy > until you found the method. > > With Python an inherited method could be in one of many base classes And Python doesn't differ from C++ in this matter, as C++ have multiple inheritance during (more than) last 15 years. If you don't use it in C++ then feel free not to use it in Python as well. -- jk From drevil_53711 at yahoo.com Mon Aug 29 15:04:46 2005 From: drevil_53711 at yahoo.com (Steve Young) Date: Mon, 29 Aug 2005 12:04:46 -0700 (PDT) Subject: python and ajax Message-ID: <20050829190446.60169.qmail@web40421.mail.yahoo.com> Hi, I was wondering if anybody knew of any good tutorial/example of AJAX/xmlhttprequest in python. Thanks. -Steve ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From pink at odahoda.de Thu Aug 4 07:57:36 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Thu, 04 Aug 2005 13:57:36 +0200 Subject: Reliable destruction References: <1123153847.649321.235450@z14g2000cwz.googlegroups.com> Message-ID: <dcsvnk$j51$1@online.de> Pierre-Eric.Melchy at uni-konstanz.de wrote: > Hello, > > I have a class measurement representing a physical measurement. > Different objects in this class represent laboratory equipment, which > might raise an exception (e.g. overtemperature). > > In any case the equipment has to be switched off after the experiment, > since if a > power supply stays in the on state for a prolonged time equipment may > be > destroyed. Switching off is done by invoking the destructors of the > instruments. > > My measurement looks like this: > > class measurement: > def __init__(self): > self.setup() > self.run() > > def setup(self): > self.powerSupply=apparate.PowerSupply() > self.magnet=apparate.magnet() # Exception("Communication Error") > self.thermo=apparate.thermometer() > # some 5 more instruments > > def run(): > for i in range(100) > self.powerSupply.setCurrent(i) # Exception("Overcurrent") > self.magnet.setField(0.5*i) > > > Different measurements are executed in a script which might run > overnight: > If one measurement raises an exception the next one might still work > and I don't > want to loose the results from the following experiments. > > try: > measurement() > except: > pass > try: > measurement2() > except: > pass > > > An exception might be thrown anywhere in init or run if e.g. the > PowerSupply > overheats. Maybe an asynchronous event might happen, too (user > interrupt with ^C but I might live without that if it is impossible to > handle) > > My questions are: > 1) under normal conditions (no exceptions) is there a guarantee, that > __del__ of > all instruments is called at the end of measurement()? > > 2) if an exception is thrown, will all instruments be deleted if the > error > occurs in run() ? > (only the instruments already initialized if the error occurs > in setup() )? > > I am using CPython (on WinXP) and there are no reference cycles between > the instruments. > > I have to stress again that a reliable finalization is important and > cannot wait > until the interpreter shuts down. > > I have tried this and it seems to work but this is of course no > guarantee. I would suggest an explicit tearDown() method try: m = measurement() try: m.setup() m.run() finally: m.tearDown() except KeyboardInterrupt: # user pressed ctrl-C print "***BREAK" sys.exit(1) except: # you should at least log the exception for later debugging traceback.print_exc() and remove the calls to setup() and run() from the constructor. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From tjreedy at udel.edu Tue Aug 16 19:24:04 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2005 19:24:04 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <mailman.2782.1123345903.10512.python-list@python.org><ZvKdnVT156XXbmnfRVn-3Q@powergate.ca><mailman.2783.1123352473.10512.python-list@python.org><ej7af11vvur6u5plc7d9b11aagg84c3cr5@4ax.com> <4302228e.1621136831@news.oz.net> Message-ID: <ddtsil$2ep$1@sea.gmane.org> "Bengt Richter" <bokr at oz.net> wrote in message news:4302228e.1621136831 at news.oz.net... > IOW, "...open the box and find the i'th item /in/ the box..." is not > really > finding the i'th item _itself_ "/in/" the box. It is finding one end of a > string > tied to some point /in/ the box, but the actual item/object is at the > other end > of the string, not /in/ the box, and many other strings may potentially > also > be leading to the same object, whether originating from anonymous > structural > binding points in other objects, or named binding points in > name-tag-containing > objects/namespaces. The way I think of it is that Python's collective objects are like club rosters: one person (object) can be on many rosters. A container would be like a room, and a person could only be in one room at a time. Terry J. Reedy From saint.infidel at gmail.com Tue Aug 30 11:40:11 2005 From: saint.infidel at gmail.com (infidel) Date: 30 Aug 2005 08:40:11 -0700 Subject: File parser In-Reply-To: <snu0h870sg.fsf@gmail.com> References: <snu0h870sg.fsf@gmail.com> Message-ID: <1125416411.098740.111590@g44g2000cwa.googlegroups.com> Angelic Devil wrote: > I'm building a file parser but I have a problem I'm not sure how to > solve. The files this will parse have the potential to be huge > (multiple GBs). There are distinct sections of the file that I > want to read into separate dictionaries to perform different > operations on. Each section has specific begin and end statements > like the following: > > KEYWORD > . > . > . > END KEYWORD > > The very first thing I do is read the entire file contents into a > string. I then store the contents in a list, splitting on line ends > as follows: > > > file_lines = file_contents.split('\n') > > > Next, I build smaller lists from the different sections using the > begin and end keywords: > > > begin_index = file_lines.index(begin_keyword) > end_index = file_lines.index(end_keyword) > small_list = [ file_lines[begin_index + 1] : file_lines[end_index - 1] ] > > > I then plan on parsing each list to build the different dictionaries. > The problem is that one begin statement is a substring of another > begin statement as in the following example: > > > BAR > END BAR > > FOOBAR > END FOOBAR > > > I can't just look for the line in the list that contains BAR because > FOOBAR might come first in the list. My list would then look like > > [foobar_1, foobar_2, ..., foobar_n, ..., bar_1, bar_2, ..., bar_m] > > I don't really want to use regular expressions, but I don't see a way > to get around this without doing so. Does anyone have any suggestions > on how to accomplish this? If regexps are the way to go, is there an > efficient way to parse the contents of a potentially large list using > regular expressions? > > Any help is appreciated! > > Thanks, > Aaron Some time ago I was toying around with writing a tool in python to parse our VB6 code (the original idea was to write our own .NET conversion tool because the Wizard that comes with VS.NET sucks hard on some things). I tried various parsing tools and EBNF grammars but VB6 isn't really an EBNF-esque syntax in all cases, so I needed something else. VB6 syntax is similar to what you have, with all kinds of different "Begin/End" blocks, and some files can be rather big. Also, when you get to conditionals and looping constructs you can have seriously nested logic, so the approach I took was to imitate a SAX parser. I created a class that reads VB6 source line by line, and calls empty "event handler" methods (just like SAX) such as self.begin_type or self.begin_procedure and self.end_type or self.end_procedure. Then I created a subclass that actually implemented those event handlers by building a sort of tree that represents the program in a more abstract fashion. I never got to the point of writing the tree out in a new language, but I had fun hacking on the project for a while. I think a similar approach could work for you here. From timothyd at ntf.com.au Wed Aug 31 21:01:07 2005 From: timothyd at ntf.com.au (Timothy Downs) Date: Thu, 01 Sep 2005 11:01:07 +1000 Subject: Survey Tool In-Reply-To: <BAY103-F384910A73F689A7CBA9283A2A00@phx.gbl> References: <BAY103-F384910A73F689A7CBA9283A2A00@phx.gbl> Message-ID: <431652D3.7040201@ntf.com.au> Sorry if I wasn't clear- Was after a Python program serving up (using CGI, Django, CherryPy.. or whatever) a survey- filled out using a web browser. Timothy Downs > Wait. . .Do you want it on a website? I don't really understand you > > > -Ivan > > _________________________________________________________________ > Don?t just search. Find. Check out the new MSN Search! > http://search.msn.click-url.com/go/onm00200636ave/direct/01/ > From steve at holdenweb.com Sun Aug 28 09:50:30 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 28 Aug 2005 09:50:30 -0400 Subject: What are new-style classes? In-Reply-To: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> Message-ID: <desfgm$o6a$1@sea.gmane.org> Vaibhav wrote: > I recently heard about 'new-style classes'. I am very sorry if this > sounds like a newbie question, but what are they? I checked the Python > Manual but did not find anything conclusive. Could someone please > enlighten me? Thanks! > Older Pythons have a dichotomy between programmer-declared object classes (from which subclasses can inherit) and the built-in object classes (which just existed as built-in, but which could not be used as the base of subclasses). More recently the object hierarchy was redesigned, and now everything inherits from object, so (if you know what you are doing) you can implement subclasses of the built-in types such as dict, float and str. Robert Kern has given you a link that explains the situation in detail. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From paolo_veronelli at tiscali.it Thu Aug 11 07:39:49 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Thu, 11 Aug 2005 13:39:49 +0200 Subject: set of sets In-Reply-To: <jIFKe.13627$HM1.364840@twister1.libero.it> References: <mailman.2971.1123753988.10512.python-list@python.org> <jIFKe.13627$HM1.364840@twister1.libero.it> Message-ID: <42FB3905.9090105@tiscali.it> Matteo Dell'Amico wrote: > Paolino wrote: > >>I thought rewriting __hash__ should be enough to avoid mutables problem >>but: >> >>class H(set): >> def __hash__(self) >> return id(self) >> >>s=H() >> >>f=set() >> >>f.add(s) >>f.remove(s) >> >>the add succeeds >>the remove fails eventually not calling hash(s). > > > Why don't you just use "frozenset"? > This is what I'm doing, but the problem remains IMO. Anyway with frozenset I have to override __new__ instead of __init__ to make the initialization which is an operation not described in the frozenset docs, which makes subclassing frozenset a different operation. Thanks Paolino ___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com From en.karpachov at ospaz.ru Mon Aug 1 22:42:23 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Tue, 2 Aug 2005 06:42:23 +0400 Subject: Python IDE's In-Reply-To: <42EEA054.3010208@benjiyork.com> References: <20050731205901.53A6E1E4005@bag.python.org> <dckll1$6rp$1@sea.gm ane.org> <mailman.2514.1122886913.10512.python-list@python.org> <1122915471 .559698.231740@g43g2000cwa.googlegroups.com> <op.suuiizrn1js0xs@news.telkom sa.net> <d76c7b8f050801150677a162dc@mail.gmail.com> <42EEA054.3010208@benjiyork.com> Message-ID: <20050802064223.2b32e8fe.jk@ospaz.ru> On Mon, 01 Aug 2005 18:21:08 -0400 Benji York wrote: > Jon Hewer wrote: > > But, if i use Vi, then whenever i want to test some code i have to > > open up python, import the necessary modules and run it - I like the > > idea of developing python in an IDE and just hitting a run button. > > map <F5> :w<CR>:!python %<CR> Or, probably even better: map <F5> :w<CR>:!xterm -e python -i % &<CR><CR> -- jk From jasonjho at gmail.com Fri Aug 12 15:50:11 2005 From: jasonjho at gmail.com (jasonjho at gmail.com) Date: 12 Aug 2005 12:50:11 -0700 Subject: Dual mode for file/directory chooser Message-ID: <1123876211.758328.162330@f14g2000cwb.googlegroups.com> Does tkinter have a dialog chooser for supporting both file and directory selections? I can only seem to find ask* methods that provide function for each, and not both. Thanks, J From alessandro.bottoni at infinito.it Fri Aug 19 07:26:41 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Fri, 19 Aug 2005 11:26:41 GMT Subject: Database of non standard library modules... References: <d76c7b8f050819014953a63197@mail.gmail.com> <mailman.3257.1124442118.10512.python-list@python.org> Message-ID: <RljNe.21410$F23.258590@twister2.libero.it> Robert Kern wrote: > Jon Hewer wrote: >> Is there an online database of non standard library modules for Python? > > http://cheeseshop.python.org/pypi > Actually, there are many other Python source code and apps repositories. Here a few links, just in case you was not aware of them: http://mu.arete.cc/pcr/ http://www.vex.net/parnassus/ http://pythonical.sourceforge.net/ http://www.strout.net/python/intro.html CU ----------------------------------- Alessandro Bottoni From fakeaddress at nowhere.org Tue Aug 9 19:18:35 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 09 Aug 2005 23:18:35 GMT Subject: MainThread blocks all others In-Reply-To: <HHaKe.2321$Z87.409@newssvr14.news.prodigy.com> References: <ddb7st$2lpp$1@gavrilo.mtu.ru> <HHaKe.2321$Z87.409@newssvr14.news.prodigy.com> Message-ID: <fRaKe.3656$zr1.2646@newssvr13.news.prodigy.com> I wrote: > Make self.counter a semaphore. Untested code: A little clean-up. Still untested: import threading class class1: def __init__(self): self.counter = threading.semaphore(0) result = self.doSomeJob() def increaseCounter(self): self.counter.release() def doSomeJob(self): # Busy-waiting sucks. # while counter != 1: # pass self.counter.acquire() # ... continue... -- --Bryan From MrJean1 at gmail.com Thu Aug 25 16:04:21 2005 From: MrJean1 at gmail.com (MrJean1) Date: 25 Aug 2005 13:04:21 -0700 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <mailman.3532.1124995353.10512.python-list@python.org> References: <dickinsm-546322.12442425082005@news.verizon.net> <430E0C8D.5000506@ceid.upatras.gr> <20050825182936.GE5991@performancedrivers.com> <mailman.3532.1124995353.10512.python-list@python.org> Message-ID: <1125000261.009534.36350@g47g2000cwa.googlegroups.com> Two observations: 1 - The difference in run time with and without the dummy* globals is due to a difference in the number of invokations of the search() function: 1,140 resp. 27,530 in my environment. To verify, just change the line def search(): .... to searches = 0 def search(): global searches searches += 1 .... and add at the very end print searches, "searches" 2 - The run times with and without the dummy* variables is equal(ly slow) if the LLentry() class and min() function call are modified to be independent of the object value. Change line class LLentry: pass to LLinst = 0 class LLentry(object): def __init__(self): global LLinst LLinst += 1 self.I = LLinst and change line mm = min((c.S, c) for c in rowitems(h))[1].D to mm = min((c.S, c.I, c) for c in rowitems(h))[2].D /Jean Brouwers From rrr at ronadam.com Tue Aug 9 22:16:16 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 10 Aug 2005 02:16:16 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <QrdKe.2028$dJ5.1335@tornado.tampabay.rr.com> seberino at spawar.navy.mil wrote: > I've heard 2 people complain that word 'global' is confusing. > > Perhaps 'modulescope' or 'module' would be better? > > Am I the first peope to have thought of this and suggested it? > > Is this a candidate for Python 3000 yet? > > Chris After reading though some of the suggestions in this thread, (but not all of them), how about something a bit more flexible but not too different. For python 3000 if at all... Have the ability to define names as shared that only live while the function that declared them has not exited. The new statements could be called *share* and *shared*. def boo(): shared x,y,z # Used names predefined in shared name space. return x+1,y+2,z+3 def foo(): x,y,z = 1,2,3 share x,y,z # These would be visible to sub functions # but not visible to parent scopes once the # function ends. [*1] boo() # modify shared x,y and z in foo. [*1.] Unless they have also declared the same names as share. (See below.) 'Share' is used to define names to be visible in child scopes, and 'shared' allows access to shared names declared in parent scopes. Having too keywords is more explicit, although this may work with a single key word pretty much as it does now. A single shared name space would still be used where 'share' adds names to be 'shared' and those names are deleted when the function that declared them exits. They don't need to live past the life of the function they were first declared in. In recursive functions, (or when a name is reshared), declaring a name as shared could just increment a reference counter, and it wouldn't be removed from shared until it reaches zero again. Using 'share' twice with the same name in the same function should cause an error. Using 'shared' with a name that is not in shared name space would cause an error. Just a few thoughts. Cheers, Ron From ex at pe.rl Wed Aug 3 02:44:54 2005 From: ex at pe.rl (Novice Experl) Date: Tue, 2 Aug 2005 23:44:54 -0700 Subject: Parallel port programming on windows XP/2000? Message-ID: <HHZHe.236676$Qo.191698@fed1read01> I'd like to write a simple application that interfaces with the parallel port, and changes the data on it according to keyboard input. I hope I can get it to run under windows xp and / or windows 2000. How can I do this? What do I need to know? It doesn't look like the standard library (the one under my pillow) has that feature. In addition, I've heard that with newer versions of windows don't let you communicate with the port directly, instead requiring interfacing with some driver? I came across this: http://pyserial.sourceforge.net/pyparallel.html but it seems to only be used for direct access (would it work with XP?), and hasn't been updated for a couple of years. In addition, it requires something called "Java Communications" (JavaComm) extension for Java/Jython, doesn't provide a link to it, and when I google it - google returns the page I came from! To add to the confusion, I hope I can provide a py2exe executable of my script instead of forcing a complete installation. --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 24 03:54:41 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 24 Aug 2005 09:54:41 +0200 Subject: py-serial + CSV References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> <1124820032.854336.278790@f14g2000cwb.googlegroups.com> Message-ID: <slrndgo9l5.8t4.sybrenUSE@schuimige.unrealtower.org> McBooCzech enlightened us with: > This (according to your suggestions) is my code which works for me > > import serial > s = serial.Serial(port=0,baudrate=4800, timeout=20) > while 1: > line = s.readline() > words = line.split(',') > if words[0]=="$GPRMC": > print words[1], words[3], words[5] > > I just wonder if there is some beter (or as you are saying "more > pythonic":) aproach how to write such a piece of code. You could use regular expressions instead. And to make it even more pythonic, replace the "while" and the "line = s.readline()" with "for line in s:" Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From mwm at mired.org Fri Aug 19 22:47:38 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 19 Aug 2005 22:47:38 -0400 Subject: Python jobs References: <de1kc1$oo9$01$1@news.t-online.com> <Yd%Me.21226$HM1.606063@twister1.libero.it> <yPednZ2dnZ3Eg1n1nZ2dnREBmd6dnZ2dRVn-z52dnZ0@powergate.ca> <mailman.3231.1124384145.10512.python-list@python.org> <de2i8m$bs6$1@panix3.panix.com> <de48fc$6j8$2@sea.gmane.org> <312cfe2b0508190821715fb488@mail.gmail.com> <mailman.3299.1124491674.10512.python-list@python.org> Message-ID: <86k6ihb9yt.fsf@bhuda.mired.org> "Terry Reedy" <tjreedy at udel.edu> writes: > generally counter-indicated unless the name (.marketplace) or charter say > otherwise. Exceptions would be a low volume of things of direct and narrow > interest. So I consider the rare job announcements posted here ok. The > same for book announcements. The key words here are "of direct and narrow interest". Job postings that don't mention Python in c.l.python are spam, nothing else. Maybe the Python jobs lists needs a "available developers" counterpart? Or would it be to big/dynamic to maintain using whatever is behind the jobs list? <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mwm at mired.org Thu Aug 11 22:13:43 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 11 Aug 2005 22:13:43 -0400 Subject: Printing literal text of an argument References: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> <mailman.3005.1123800320.10512.python-list@python.org> Message-ID: <86hddv7vhk.fsf@bhuda.mired.org> [Format recovered from top posting] Jeremy Moles <jeremy at emperorlinux.com> writes: > On Thu, 2005-08-11 at 14:04 -0700, Rex Eastbourne wrote: >> Hi all, >> >> I've written the following simple macro called debug(aname, avalue) >> that prints out the name of an expression and its value: >> >> def debug(aname, avalue): >> print aname, 'is': >> pprint.pprint(avalue) >> >> An example call is: >> >> debug('compose(f1,f2)', compose(f1,f2)) >> >> Writing the exact same thing twice (one in quotes and the other not) >> sets off an alarm in my head. Is there a way to make this function take >> only one argument, and use both its value and its literal form? On a >> slightly different topic, is it also possible to make the macro print >> the line number where the function was first called? > def debug(s): > print "s" > exec(s) Um, no. First, I'm pretty sure you mean "print s" for the print statement. The one you have just prints a single s. Second, exec is a statement, not a function. The correct syntax is "exec s". The one you used works, because an expression in parenthesies evaluates to the value of the expression. Finally, doing an "exec s" doesn't display a value - you need to print the results of the exec, which you can't do. You want to use an eval here, not an exec. Eval is a function, and returns a value. It's limited to expressions. Which will meet Rex's stated requirements. Of course, all this is moot because the eval (exec) happens in a different context than the call, so the results can be radically different than what you expect: >>> def debug(s): ... print s ... print eval(s) ... >>> def foo(): ... x = 3 ... debug("x") ... >>> foo() x Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 3, in foo File "<stdin>", line 3, in debug File "<string>", line 1, in ? NameError: name 'x' is not defined >>> See what I mean? You really need to pass the context to debug for it to get the right thing: >>> def debug(x, glob, loc): ... print x ... print eval(x, glob, loc) ... >>> def foo(): ... x = 3 ... debug("x", globals(), locals()) ... >>> foo() x 3 >>> You can figure out the locals via introspection (see the help for the inspect module for more details). I'm not sure if there's a similar way to figure out what the globals were at the point that debug is called. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From peter at engcorp.com Thu Aug 11 08:22:29 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 11 Aug 2005 08:22:29 -0400 Subject: interpreter frame In-Reply-To: <1123711701.529320.85880@g14g2000cwa.googlegroups.com> References: <1123689998.800361.278370@g43g2000cwa.googlegroups.com> <L7udnZ2dnZ1k6661nZ2dnXvLZ9-dnZ2dRVn-z52dnZ0@powergate.ca> <1123711701.529320.85880@g14g2000cwa.googlegroups.com> Message-ID: <lK-dnQOlDIj33mbfRVn-jA@powergate.ca> Leo wrote: > Good try, but that doesn't seem to work either. Maybe I should have > emphasized that what I really want is the line of code, as opposed to > the entire frame. Ah, it wasn't clear from your first post that you were specifically interested in a line you entered at the *interactive prompt*. The word "interpreter" is sometimes applied to the virtual machine, so I thought you just wanted the current frame inside an application. For the "interactive interpreter", I doubt the line of code that you are executing is preserved anywhere (at least not in a supported, documented fashion) as source, so I don't think there's a simple way to get at it. Certainly not (I believe) through the frame or code object. Maybe checking the source will lead to a hack solution... -Peter From greg at puyo.cjb.net Mon Aug 22 06:10:14 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 22 Aug 2005 03:10:14 -0700 Subject: while c = f.read(1) In-Reply-To: <430579A4.1060800@lexicon.net> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> Message-ID: <1124705414.704694.241960@f14g2000cwb.googlegroups.com> John Machin wrote: > > Is some way to make this code more compact and simple? It's a bit > > spaghetti. > > Not at all, IMHO. This is a simple forward-branching exit from a loop in > explicable circumstances (EOF). It is a common-enough idiom that doesn't > detract from readability & understandability. Spaghetti is like a GOTO > that jumps backwards into the middle of a loop for no discernable reason. While that is true, I had high hopes that I could do this: while c = f.read(1): # ... And relative to that, it is more complex. And although I am nit-picking to try to simplify this code, I wanted to understand why Python works in this way (even if that's just "historical reasons"), and check to see if there was not some shorter more modern Pythonic alternative. I did actually like Robert Kern's suggestion which used an iterator and a function to factor out the complexity of setting it up. I think that is actually better code than the original. It matches my philosophy in programming of pushing complexity *out* of the code which does the actual job, even if it means writing a few support functions/classes/whatever. I know they can be re-used and refined and I know that it is the code that does the actual job that is most likely to be rewritten in future revisions of the code with shifts in requirements. > You have a bit of a misunderstanding here that needs correcting: > > In "if <blah>" and "while <blah>", <blah> is NOT restricted to being in > (True, False). See section 5.10 of the Python Reference Manual: I'm sorry! I realise that now and I'm sorry to have caused the traffic I did. Thank you for pointing it out to me though - it's pretty fundamental Python! *Greg thumbtacks a note to his forehead* > How about > for c in f.read(): > ? > Note that this reads the whole file into memory (changing \r\n to \n on > Windows) ... performance-wise for large files you've spent some memory > but clawed back the rather large CPU time spent doing f.read(1) once per > character. The "more nicely" factor improves outasight, IMHO. I would if only I had any kind of guarrantee on the file size but I don't - this code is for reading a header out of a binary file which uses delimiters and escape characters to mark out its fields. I didn't design the format, but after cleaning up the code that deals with it, I may *re*design it. ;) > Mild curiosity: what are you doing processing one character at a time > that can't be done with a built-in function, a standard module, or a > 3rd-party module? Our company is designing a new file type. *sigh*. Confidentiality prevents me from saying any more, too. If that bugs you because it's not open source, sorry I need a job. Don't worry though, I'm developing an open source remote GUI for the code management system we're using called Aegis (http://aegis.sf.net). It's not sufficiently implemented yet to warrant posting publically (I'd describe its current state as "framework") but if anybody reading this is interested then give me a yell and it'll have a public project page or something overnight. ;) From rafi at free.fr Thu Aug 25 16:15:11 2005 From: rafi at free.fr (rafi) Date: Thu, 25 Aug 2005 22:15:11 +0200 Subject: variable hell In-Reply-To: <3n6ldtF2qhoU1@individual.net> References: <mailman.3511.1124982438.10512.python-list@python.org> <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> Message-ID: <430e26c6$0$2092$626a14ce@news.free.fr> Reinhold Birkenfeld wrote: >>> exec(eval("'a%s=%s' % (count, value)")) >> >>why using the eval? >> >>exec ('a%s=%s' % (count, value)) >> >>should be fine > > And this demonstrates why exec as a statement was a mistake ;) > > It actually is > > exec 'a%s=%s' % (count, value) Noted. In the meantime another question I cannot find an answer to: any idea why does eval() consider '=' as a syntax error? >>> eval ('a=1') Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1 a=1 ^ SyntaxError: invalid syntax Thanks -- rafi "Imagination is more important than knowledge." (Albert Einstein) From martin.witte at gmail.com Mon Aug 8 12:18:45 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 8 Aug 2005 09:18:45 -0700 Subject: Is there a better/simpler logging module? In-Reply-To: <5VKJe.9469$HM1.273456@twister1.libero.it> References: <5VKJe.9469$HM1.273456@twister1.libero.it> Message-ID: <1123517925.664331.288020@o13g2000cwo.googlegroups.com> If you need some simple logging why not create a logger like one of the basic examples, see http://docs.python.org/lib/minimal-example.html, these examples are not that complex. From hongyuan1306 at gmail.com Sat Aug 13 11:01:21 2005 From: hongyuan1306 at gmail.com (Yuan HOng) Date: Sat, 13 Aug 2005 23:01:21 +0800 Subject: Archetype Permission Errors with CMFBoard 2.2 Message-ID: <91320d220508130801126f7@mail.gmail.com> Hi, I am trying to integrate the latest CMFBoard 2.2 with my Plone site (2.0.5 with Archetypes 1.3.3-final). I'd like to have my users to post anonymously with CMFBoard, so I added a forumNB of type 'open'. However, when an anonymous user tries to added a new Topic to the board, a bunch of error messages were seen in the event.log as shown below. As a result, I find the topic of a new forum topic can not be displayed in several locations. Can someone explain what the various errors mean and how shall I set up my permission so CMFBoard will work correctly for anonymous users? By the way, is CMFBoard 2.2 known to work stably with Archetype 1.3.3? So many warning/errors for just adding a simple topic make me really worry. Below is the event.log transcript: ------ 2005-08-08T03:53:07 INFO(0) Plone Debug /opt/zope/client0/Products/CMFBoard/skins/cmfboard/forum_add_topic_form.cpt: No default action specified for status success, content type ANY. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify a default action for this case. ------ 2005-08-08T03:53:36 ERROR(200) Archetypes caught Unauthorized on discussiontool.overrideDiscussionFor(forum/forum/public/0001) Traceback (most recent call last): File "/opt/zope/client0/Products/Archetypes/ExtensibleMetadata.py", line 250, in allowDiscussion dtool.overrideDiscussionFor(self, allowDiscussion) File "/opt/zope/client0/Products/CMFDefault/DiscussionTool.py", line 84, in overrideDiscussionFor raise "Unauthorized" Unauthorized ------ 2005-08-08T03:53:36 ERROR(200) CMFBoard None Traceback (most recent call last): File "/opt/zope/client0/Products/CMFBoard/utils.py", line 149, in forum_stateChanged sci.object.notifyStateChanged(sci) TypeError: notifyStateChanged() takes exactly 1 argument (2 given) ------ 2005-08-08T03:53:36 INFO(0) Archetypes Products/Archetypes/Field.py[492]:writeable User None tried to update ForumMessage:title but doesn't have enough permissions. ------ 2005-08-08T03:53:36 INFO(0) Archetypes User None tried to update ForumMessage:authorname but doesn't have enough permissions. ------ 2005-08-08T03:53:36 INFO(0) Archetypes User None tried to update ForumMessage:message_icon but doesn't have enough permissions. ------ 2005-08-08T03:53:36 INFO(0) Archetypes User None tried to update ForumMessage:parsing_flag but doesn't have enough permissions. ------ 2005-08-08T03:53:36 INFO(0) Archetypes User None tried to update ForumMessage:text but doesn't have enough permissions. ------ 2005-08-08T03:53:36 INFO(0) Archetypes User None tried to update ForumMessage:signature but doesn't have enough permissions. ------ 2005-08-08T03:53:36 INFO(0) Plone Debug /opt/zope/client0/Products/CMFBoard/skins/cmfboard/forum_topic.cpt: No default action specified for status success, content type ANY. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify a default action for this case. ------ 2005-08-08T03:53:36 INFO(0) Plone Debug /opt/zope/client0/Products/CMFBoard/skins/cmfboard/forum_topic.cpt: No default validators specified for content type ANY. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify default validators for this case. ------ 2005-08-08T03:53:36 INFO(0) Plone Debug /opt/zope/client0/Products/CMFBoard/skins/cmfboard/forum_quickreply_widget.cpt: No default action specified for status success, content type ANY. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify a default action for this case. -- Hong Yuan ????????? ??????????? http://www.homemaster.cn From rkern at ucsd.edu Wed Aug 31 00:34:47 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 30 Aug 2005 21:34:47 -0700 Subject: reg email packages work In-Reply-To: <20050831042039.25690.qmail@web8409.mail.in.yahoo.com> References: <slrndh8q9a.f9h.sybrenUSE@schuimige.unrealtower.org> <20050831042039.25690.qmail@web8409.mail.in.yahoo.com> Message-ID: <df3c18$s2a$1@sea.gmane.org> praba kar wrote: > --- Sybren Stuvel > <sybrenUSE at YOURthirdtower.com.imagination> wrote: > >>Steve Holden enlightened us with: >> >>>It's obvious you aren't using that EXACT code, >> >>because it doesn't >> >>>formulate a three-paragraph message. So the bit we >> >>really need to >> >>>see is how you capture and formulate the argument >> >>to set_payload(). >> >>I'd rather see what I asked for, which is the output >>of >>msg.as_string(). That contains all that's sent to >>the client. > > msg.as_string() have all the client data(which include > headers and body of the message He's not asking you for a description of it. He is asking for the output itself. -- 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 Mon Aug 22 18:46:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 00:46:24 +0200 Subject: Best way to 'touch' a file? References: <mailman.3329.1124643300.10512.python-list@python.org> <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca><mailman.3383.1124745482.10512.python-list@python.org> <tqmdnYA7UvHA0pfeRVn-iw@powergate.ca> Message-ID: <dedkjs$703$1@sea.gmane.org> Peter Hansen wrote: > And, depending on your needs, quite ineffective: > > >>> import os > >>> os.utime('missing.file', None) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > OSError: [Errno 2] No such file or directory: 'missing.file' > > >>> from path import path > >>> path('missing.file').touch() > >>> path('missing.file').exists() > True > > I guess it depends on whether "touch" implies creation-when-missing, as > with the command line version, or just updating the time. the OP wanted "to update the modification time of a file without actually modifying it". os.utime does exactly that; no more, no less, and no extra dependencies. </F> From peter at engcorp.com Thu Aug 18 14:16:39 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 18 Aug 2005 14:16:39 -0400 Subject: question about binary and serial info In-Reply-To: <DfydnezYoeY0U5neRVn-tA@powergate.ca> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <1124386952.353027.93050@g47g2000cwa.googlegroups.com> <DfydnezYoeY0U5neRVn-tA@powergate.ca> Message-ID: <pdGdnZ2dnZ3e69rnnZ2dnRRNmd6dnZ2dRVn-y52dnZ0@powergate.ca> Peter Hansen wrote: > ASCII, however, they represent these three characters: "Foo". Your data > looks like chunk when treated as ASCII, so it's probably just bytes. Weird. I think I meant "junk" (not "chunk"), but obviously was writing verbally, not visually... -Peter From lycka at carmen.se Thu Aug 11 08:34:15 2005 From: lycka at carmen.se (Magnus Lycka) Date: Thu, 11 Aug 2005 14:34:15 +0200 Subject: What are modules really for? In-Reply-To: <42F9BC7D.1050300@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <ddfgk7$snn$1@wake.carmen.se> N.Davis wrote: > Functions existing in a module? Surely if "everything is an object" (OK > thats Java-talk but supposedly Python will eventually follow this too) int too? ;) Actaully, I think Python and Java are fairly much on equal footing here, with Java possibly being slightly behind rather than ahead. > then there should be nothing in a module thats not part of a class. Even > a static method is simply a class function that operates on the > "collection of all instances" rather than a single instance. Object != class instance. In Python, almost everything is an object. Files, classes, instances, ints, modules, functions etc can be passes around, assigned to new names, referenced in containers, printed etc etc. This is very helpful. Forcing people to write a lot of bloat code around their functions isn't really that helpful... I can appreciate a language like Smalltalk, designed from ground up with a pure OO approach--but it seems to me that Java's design was basically to make a C++ derivate with bars and safety belts in a lot of places to stop programmers from shooting themselves in the foot. > Related classes in the same file? Be careful. Doesn't anything "knowing" > about anything else compromise encapsulation? Why would > properly-designed classes have such a close relationship? In your code, nothing ever knows anything about anything else? :) I'm sure you have written code where a class knows of some other class, for instance through inheritance or composition. It does actually even happen that it's reasonable to let two classes be mutually aware of each other, even if it's not as common as one way relationships. It's often better to have a third class control the relationship between the two, but that's my design decision, not Guido van Rossum's or James Gosling's. There is a fundamental difference in the philosophies behind the design of Java and Python. It seems to me that Java is designed to make is difficult for programmers to write bad code, while Python is designed to make it easy to write good code. This makes a big difference. Another aspect to consider is that Python classes are typically shorter than Java classes, since Python isn't as noisy as Java. Perhaps you should have a look at HTMLGen for instance. It's a library for generating HTML code. (Pretty old.) IIRC it has a lot of classes that are just one line long. These classes represent simple tags, and all behaviour is defined in some base class, so the only thing that differs between i.e. the I class and the B class is that str(I('Hello')) should be rendered as <I>Hello</I> and str(B('Hello')) should be rendered as <B>Hello</B>. I don't know what the name of their base class is, but assuming 'X', they are just implemented as 'class I(X):pass' and class B(X):pass'. It would have been a bit silly if Python had forced them out in different files... From Andrey.Smirnov at Sun.COM Thu Aug 18 11:19:07 2005 From: Andrey.Smirnov at Sun.COM (Andrey Smirnov) Date: Thu, 18 Aug 2005 09:19:07 -0600 Subject: Strange email.Parser error? In-Reply-To: <18199ab805081808031ed9232a@mail.gmail.com> References: <43049E7B.7070700@Sun.COM> <18199ab805081808031ed9232a@mail.gmail.com> Message-ID: <4304A6EB.9010609@Sun.COM> Ah - this makes more sense. Did the implementation of 'fp' file-like object change in 2.4.1 and it no longer has a read()? Andre. Anthony Botrel wrote: > Hi, > > in the call fp.read(8192) the function read() gets 2 arguments : <fp> and <8192> > > Member functions implicitely get their object as first argument, this > is why you get this error. So you have 2 possibilities : either read() > doesn't take an argument anymore, or read() is not a member of fp. > > Anthony B. > > On 8/18/05, Andrey Smirnov <Andrey.Smirnov at sun.com> wrote: > >>I am getting the following traceback after upgrading my app to Python >>2.4.1. It's telling me that there is an error in Parser.py. It tells >>me that 'fp.read(8192)' is given 2 arguments, but it is clearly not >>true. Does anybody know what's going on here? >> >>Traceback (most recent call last): >> File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line >>252, in work >> worker(e.linkval, info) >> File "/opt/etext/bin/etreceive", line 30, in worker >> result = decode.searchfile(f) >> File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line >>43, in searchfile >> return Email(f) >> File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line >>510, in __init__ >> self.child.append(Email(mf)) >> File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line >>404, in __init__ >> msg = Parser().parse(f) >> File "/opt/etext/lib/python2.4/email/Parser.py", line 65, in parse >> data = fp.read(8192) >>TypeError: read() takes exactly 1 argument (2 given) >> >>Thanks, >>Andre. >> >>-- >> >>-- >>http://mail.python.org/mailman/listinfo/python-list >> -- ################################################################ _/_/_/ _/ _/ _/ _/ Andre Smirnov _/ _/ _/ _/_/ _/ CNS - DSE _/_/_/ _/ _/ _/ _/ _/ 303 272-8352 / x78352 _/ _/ _/ _/ _/_/ Mailstop: UBRM05-203 _/_/_/ _/_/_/ _/ _/ 500 Eldorado boulevard Broomfield, CO 80021 From martin at v.loewis.de Thu Aug 25 17:02:06 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 25 Aug 2005 23:02:06 +0200 Subject: Filetypes in email attachments. In-Reply-To: <1124985916.435829.288930@g43g2000cwa.googlegroups.com> References: <1124985916.435829.288930@g43g2000cwa.googlegroups.com> Message-ID: <430e31cf$0$11119$9b622d9e@news.freenet.de> justin.vanwinkle at gmail.com wrote: > I would like to use the magic file to detect the filetype, if this is > possible. I have the attachement stored and (generally) decoded in a > variable. There is a Python binding to the libmagic library, see http://mx.gw.com/pipermail/file/2003/000055.html Meanwhile, this binding is part of the standard file(1) distribution. Regards, Martin From onurb at xiludom.gro Wed Aug 10 11:47:19 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 10 Aug 2005 17:47:19 +0200 Subject: What are modules really for? In-Reply-To: <42F9BC7D.1050300@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <42fa2189$0$4880$626a14ce@news.free.fr> N.Davis wrote: (snip) > Functions existing in a module? Surely if "everything is an object" (OK > thats Java-talk but supposedly Python will eventually follow this too) > then there should be nothing in a module thats not part of a class. Why ? The name of the paradigm is *object* oriented, not *class* oriented !-) Believe it or else, there are OO languages that don't even have a concept of 'class' (self, Javascript, Io, ...). They are called prototype-based languages (by opposition to class-based), and are usually much more object-oriented than Java. In Python, "everything is an object" means that even classes and functions are objects. Try this: def fun(): pass print fun.__class__.__name__ in fact, 'def' is just synctatic sugar to create a new instance of class 'function' Now try this: class Function(object): def __call__(self, arg): print "%s called with arg %s" % (self, arg) f = Function() f(42) So in fact, a function is just a special case of a callable object. When we say that Python is 100% OO, we mean it !-) > Even > a static method is simply a class function that operates on the > "collection of all instances" rather than a single instance. Nope. In most Java code, static methods are functions in disguise. Write a Java class with only static methods and static variables, and you have a very classic procedural module... > Related classes in the same file? Be careful. Of what ? This is a common practice in most OO languages, you know... > Doesn't anything "knowing" > about anything else compromise encapsulation? Nope. Any of your objects needs to know at least something about at least another object, or how could they send messages to each other ? BTW encapsulation is *not* data-hiding. > Why would > properly-designed classes have such a close relationship? I don't think you understand what kind of 'close relationship' we're talking about. It's not about "a class knowing each and every implementation detail of another class", it's about a bunch of classes designed to work together to achieve a given goal. BTW, note that the stronger coupling in OO is probably implementation inheritence, and it's overabused in most static-typed languages. > Having back in the day worked on big real-time systems where being very > strict about encapsulation was a god-send for fighting complexity, I > feel unnerved by Perl and Python's laid-back OO culture Please avoid comparing oranges and apples. Perl culture is about hacks and unreadable code, when Python's culture is about simplicity and readability. Just not the same culture. > of "you can do > it if you feel like it but don't have to". Some languages have what we call a "discipline-and-bondage" culture. Some others have a "we're all consenting adults here" culture. The difference is that the first category of languages impose arbitrary restrictions on the programmer, that usually lead to more verbose and complex code, which usually leads to much opportunities for bugs. > While you could do all manner > of nasty hacks in C++ I worked with people who carefully avoided this. > Maybe that was just luck.... Nope, just common sens I'd say. But also, C++ - just like C - is a low-*level language that allows you to do what you want with resources (and specially with memory), so the consequences of a programming error can be much more desastrous. Now "nasty hacks" are not part of the Python culture. Dynamicity and simplicity are not nasty hacks, just a way to get rid of useless complexity. If you have a problem with having many classes in one file, then you'll have a hard time with some other Python's features, like eg relying on conventions for access control[1] or duck-typing[2] [1] 'aName' => public, '_aName' => protected, '__aName' => private [2] "if it walks like a duck and quake like a duck, then it's close enough to a duck for what we want to do with it...." So my best advice here is: don't fight against the language, don't waste your time trying to enforce Java idioms in Python (I did, so believe me when I tell you it's a pure waste of time), just forget Java idioms and learn Python as it is. You'll discover that Python is not a "scripting" language, but one of the most powerful and enjoyable languages around. (disclaimer : my sig is a deliberate counter-exemple of good Python coding style) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From aleaxit at gmail.com Mon Aug 22 21:49:35 2005 From: aleaxit at gmail.com (aleaxit at gmail.com) Date: 22 Aug 2005 18:49:35 -0700 Subject: up to date books? In-Reply-To: <430511db$1@news.eftel.com> References: <TMqdnRHoSoNyk5neRVn-3Q@rcn.net> <QnWMe.20058$F23.245544@twister2.libero.it> <430511db$1@news.eftel.com> Message-ID: <1124761775.244032.32770@f14g2000cwb.googlegroups.com> One of my most popular talks is "re-learning Python" -- can be anywhere between 1 and 4 hours, depending on level of detail -- it's all about the changes 1.5.2 -> today's Python, why they came about and why you would want to use them... Alex From rich.teer at rite-group.com Mon Aug 22 15:53:29 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Mon, 22 Aug 2005 19:53:29 GMT Subject: Jargons of Info Tech industry In-Reply-To: <IJpOe.175886$zs4.9923722@phobos.telenet-ops.be> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <ln8xyt7oxp.fsf@nuthaus.mib.org> <IJpOe.175886$zs4.9923722@phobos.telenet-ops.be> Message-ID: <Pine.SOL.4.58.0508221252420.796@zen.rite-group.com> On Mon, 22 Aug 2005, jan V wrote: > Please don't use ASCII art... not everyone uses a fixed-width font for his > newsreader............... Then I humbly submit thet they are using broken and/or badly configured readers. ;-) -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From pink at odahoda.de Tue Aug 2 16:27:28 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Tue, 02 Aug 2005 22:27:28 +0200 Subject: Art of Unit Testing References: <dco7sg$dj0$1@news.urz.uni-heidelberg.de> <1123001938.602349.164510@z14g2000cwz.googlegroups.com> <dcoghi$j7d$1@online.de> Message-ID: <dcokrm$qcf$1@online.de> Christoph Zwerschke wrote: > Thanks for the link, Grig. I wasn't aware of the py lib so far. The > possibility to create fixtures at the three different scopes is exactly > what I was looking for. > > Anyway, I think it would be nice to have that feature in the standard > lib unittest as well. It should not be too hard to add setUpOnce and > tearDownOnce methods in addition to setUp and tearDown. Actually, I am > wondering that there doesn't seem to be any development progress since > unittest was included in the standard lib of Python 2.1 in August 2001. > I had expected that such an important module would be continually > improved and maintained. How come? So few people using unit tests? Or do > most people write their own testing code or use py.test? Or because it is already close to perfection (at least in what it is intended to do). The unittest module is a 'port' of the JUnit framework for Java which has a certain wellknown API and semantics. The same API is available for many other languages, so it is probably a good idea to stick with it in order to make people coming from other language feel more comfortable with Python. Some (many?) people don't like the unittest module, because it is not very pythonic - nothing to wonder as it has its root in the Java world. That's probably one of the reasons why there are other (more pythonic) unittesting frameworks for Python out there. I prefer to use unittest (because this was the API the textbook was using that introduced me to this topic) and I also had the problem of heavy setup costs. I deal with it by using a script around my testsuite (instead of calling just unittest.main()) that does the setup/teardown of the environment. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From could.net at gmail.com Thu Aug 4 03:13:11 2005 From: could.net at gmail.com (could ildg) Date: Thu, 4 Aug 2005 15:13:11 +0800 Subject: Does pyparsing support UNICODE strings? Message-ID: <311b5ce10508040013750360e6@mail.gmail.com> pyparsing is very convenient to use. But I want to find some a py tool to parse non-English strings. Does pyparsing support UNICODE strings? If not, can someone tell me what py tool can do it? Thanks in advance. From richardjones at optushome.com.au Mon Aug 8 02:13:48 2005 From: richardjones at optushome.com.au (richard) Date: Mon, 08 Aug 2005 16:13:48 +1000 Subject: Oreilly CodeZoo References: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> Message-ID: <42f6f81c$0$8993$afc38c87@news.optusnet.com.au> gene tani wrote: > http://radar.oreilly.com/archives/2005/08/codezoo_program_1.html > > http://python.codezoo.com/ > > Nice to see that python is in-demand, but what is the rationale for > another ASPN cookbook/Parnassus / pypackage / dmoz type repository? We (PyPI / Cheese Shop developers) are talking to the CodeZoo people about the relationship between the two systems. Things PyPI has: 1. python setup.py register 2. python setup.py (sdist|bdist|bdist_egg|bdist_wininst|...) upload 3. http://cheeseshop.python.org/ 4. better categorisation (IMO) 5. XML-RPC interface 6. 852 packages registered The things that CodeZoo has: 1. reviews, user tips and ratings 2. a full-time editor to make sure that the reviews are reasonable 3. links to O'Reilly articles 4. a big DOWNLOAD button. hurm, that's a good idea, I should add one of those to the PyPI interface... I hope no-one has that patented 5. DOAP (being added to PyPI) 6. Ads in the top bar and a sidebar (hehe) Getting links from PyPI over to the CodeZoo information would be pretty easy. Getting links from the CodeZoo pages to PyPI information / packages would be pretty easy. Richard From wccppp at gmail.com Mon Aug 15 13:33:24 2005 From: wccppp at gmail.com (wcc) Date: 15 Aug 2005 10:33:24 -0700 Subject: EasyDialogs - select multiple files? Message-ID: <1124127204.566082.309300@g14g2000cwa.googlegroups.com> Hello group, Can I use EasyDialogs to select multiple files? I saw the function AskFileForOpen but which does not have a flag allowing selection of multiple files. Did I miss something? Thanks very much, - wcc From George.Flaherty at marketmax.com Wed Aug 10 12:13:24 2005 From: George.Flaherty at marketmax.com (George Flaherty) Date: Wed, 10 Aug 2005 12:13:24 -0400 Subject: Documentation Message-ID: <59CF9F456FAA9045B405C441EC916F3E0291C697@MERC24.na.sas.com> I prefer epydoc http://epydoc.sourceforge.net. Granted it is an add on and uses "LaTex'ish" flags in the comments, but the final doc is very clean. -g -----Original Message----- From: python-list-bounces+george.flaherty=marketmax.com at python.org [mailto:python-list-bounces+george.flaherty=marketmax.com at python.org] On Behalf Of Jan Danielsson Sent: Wednesday, August 10, 2005 11:18 AM To: python-list at python.org Subject: Documentation Hello all, What is the proper way to document a class in Python? I have written a few python libraries that I would like to document. I'm doing a lot of this: class Foo(object): """ This is a class which blah, blah, blah... It's features are blah, blah, blah... """ def addStuff(self): """ This method does blah, blah, blah... """ I'm going to assume that Python has some "official" tool which can be used to automatically create documentation for a .py-file (like Java does), but what do I need to do to support it, and how does it work? -- Kind Regards, Jan Danielsson Te audire no possum. Musa sapientum fixa est in aure. -- http://mail.python.org/mailman/listinfo/python-list From jstier at cs.uvic.ca Tue Aug 9 17:38:44 2005 From: jstier at cs.uvic.ca (J) Date: 9 Aug 2005 14:38:44 -0700 Subject: Adding and attribute to an instance Message-ID: <1123623524.732496.79460@g49g2000cwa.googlegroups.com> Hi, I am trying to add new data attributes to my extension classes from within a script. I am under the impression that python allows that implicity This is the definition of my class PyTypeObject CmdPlace::PyType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "Place", /*tp_name*/ sizeof(CmdPlace::PyStruct), /*tp_basicsize*/ 0, /*tp_itemsize*/ 0, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ PyObject_GenericGetAttr, /*tp_getattro*/ PyObject_GenericSetAttr, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ "CmdPlace", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ CmdPlace::sPyMethods, /* tp_methods */ CmdPlace::sPyMembers, /* tp_members */ CmdPlace::sPyGetSeters, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; I call PyType_Ready(&PyType); Py_INCREF(&PyType); to initialize the type, and PyObject_INIT((PyObject*)&mPyObject, &CmdPlace::PyType); to initialize an object. Objects of this type are only ever instantiated from C++. When I evaluate a sript I just add the object as "MyObject" to the dicitonary passed to Py_Eval... All the members and methods work fine, but when I do MyObject.aNewAttribue = 12 I get at an error saying object has no attribute "aNewAttribue". I have looked at some of the source code in PyObject_GenericGetAttr and it turns out that the object has no dictionary. It seens that the address of the dictionary is computed somehow via tp_dictoffset in the type object. Basically my question is, how can I make this work. Cheers Jochen From spam.csubich+block at block.subich.spam.com Sun Aug 7 00:53:00 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Sun, 07 Aug 2005 00:53:00 -0400 Subject: Proposed new collection methods In-Reply-To: <mailman.2805.1123388598.10512.python-list@python.org> References: <86d5oqvfqf.fsf@bhuda.mired.org> <cUdJe.19125$jq.10198@bignews3.bellsouth.net> <dd3qr9$hnv$1@sea.gmane.org> <mailman.2802.1123381256.10512.python-list@python.org> <xtidncuIpPK2FGjfRVn-gg@rcn.net> <mailman.2805.1123388598.10512.python-list@python.org> Message-ID: <PrgJe.19278$jq.18203@bignews3.bellsouth.net> Robert Kern wrote: > Jeff Schwab wrote: >> Why are you retarded? Isn't the above code O(n)? >> >> Forgive me for not understanding, I'm still awfully new to Python >> (having come from Perl & C++), and I didn't see an explanation in the >> FAQ. > (s for s in iter(self) is test(s)) is a generator expression. It is > roughly equivalent to [snip] > That implementation does indeed return as soon as it locates the first > item, so yes, I was being retarded. Thank you for the best programming-language related laugh I've had today. :) I know just the kind of synapse-misfires that lead to completely obvious, yet also completely wrong conclusions like that -- I've done well more than my own share. For the grandparent poster: generators and its baby brother generator expressions are the kind of really neat feature that you're never told about in CS101. Generators themselves are relatively well-covered in the Python documentation, which should serve as a decent introduction to the topic. From cipherpunk at gmail.com Mon Aug 29 14:07:13 2005 From: cipherpunk at gmail.com (cipherpunk at gmail.com) Date: 29 Aug 2005 11:07:13 -0700 Subject: using common lisp with python. In-Reply-To: <1125332253.886031.256950@g49g2000cwa.googlegroups.com> References: <1125264907.656465.106900@g44g2000cwa.googlegroups.com> <43130f30$0$17711$626a14ce@news.free.fr> <1125332253.886031.256950@g49g2000cwa.googlegroups.com> Message-ID: <1125338833.633816.69020@g49g2000cwa.googlegroups.com> Your best bet is probably to look into your LISP environment's FFI (Foreign Function Interface). Most LISP environments have some way to call C code directly. Insofar as going back the other way... that I'm a little more sketchy on. Guile (the Scheme compiler from GNU) is a strong contender, though. It's not Common LISP, but it's a LISP with copious documentation for how to call it from C. I really can't see a reason to use Python as a glue layer. I'd recommend rewriting your LISP code in Python before I'd recommend using Python to interface between Common LISP and C. From jfouhy at paradise.net.nz Thu Aug 4 19:36:23 2005 From: jfouhy at paradise.net.nz (Repton) Date: 4 Aug 2005 16:36:23 -0700 Subject: cut & paste text between tkinter widgets In-Reply-To: <pZdIe.6944$jq.1511@bignews3.bellsouth.net> References: <ze5Ie.629$3M4.325@newssvr27.news.prodigy.net> <zv5Ie.685$%X1.523@bignews1.bellsouth.net> <OIaIe.872$3M4.210@newssvr27.news.prodigy.net> <pZdIe.6944$jq.1511@bignews3.bellsouth.net> Message-ID: <1123198583.339591.283890@g47g2000cwa.googlegroups.com> Christopher Subich wrote: > In experimenting with this, I found a slight... fun issue involved in > this. Selection_get is the correct method to call, but it doesn't quite > work out of the box. > >>> g.selection_get() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "C:\Python24\Lib\lib-tk\Tkinter.py", line 574, in selection_get > return self.tk.call(('selection', 'get') + self._options(kw)) > _tkinter.TclError: PRIMARY selection doesn't exist or form "STRING" not > defined > > This poses a small problem. I'm not sure whether this is a > Win32-related issue, or it's because the PRIMARY selection isn't fully > configured. You need to select something first :-) >>> from Tkinter import * >>> tk = Tk(); e = Entry(tk); e.pack() >>> # Type 'foo' into the Entry, then highlight it ... >>> e.selection_get() 'foo' e.selection_get() will raise TclError if the widget you call it on has nothing selected. > >>> g.selection_get(selection='CLIPBOARD') I didn't know about this, though.. -- John. From djanvk at gmail..com Fri Aug 12 10:48:40 2005 From: djanvk at gmail..com (djanvk at gmail..com) Date: Fri, 12 Aug 2005 14:48:40 GMT Subject: Text/IDE Python Editor? Message-ID: <n5cpf1hef4m1k4hb2vnob17kh739mnip9l@4ax.com> Any recommendations on a editior/IDE for programming in python? I'm using windows xp. Thanks From bill.mill at gmail.com Thu Aug 25 13:55:48 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 25 Aug 2005 13:55:48 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <797fe3d4050825104952c37fb@mail.gmail.com> References: <dickinsm-546322.12442425082005@news.verizon.net> <ytKdneR_9P_dY5DeRVn-3g@speakeasy.net> <mailman.3522.1124991313.10512.python-list@python.org> <5ZudndXd2JTen5PeRVn-2A@speakeasy.net> <797fe3d4050825104952c37fb@mail.gmail.com> Message-ID: <797fe3d40508251055615fcd16@mail.gmail.com> Bill Mill wrote: > > Pentium M 1.8 GHz Windows 2k. Here's the top of the profile results > for fast and slow on my machine (these won't look decent except in a > fixed-width font): > <snip profiles> > > Interestingly, the test.py:36 line, which takes 45 seconds (!!) in the > slow version, does not appear at all in the fast profile. I can't > figure out why - both printed out their data, so template must have > been called somewhere. > OK, I'm getting somewhere now. When I replace: template = (" | %s %s %s | %s %s %s | %s %s %s |\n" * 3).join([" +-------+-------+-------+\n"] * 4) wtih: template = """ | %s %s %s | %s %s %s | %s %s %s |\n | %s %s %s | %s %s %s | %s %s %s |\n | %s %s %s | %s %s %s | %s %s %s |\n +-------+-------+-------+\n | %s %s %s | %s %s %s | %s %s %s |\n | %s %s %s | %s %s %s | %s %s %s |\n | %s %s %s | %s %s %s | %s %s %s |\n +-------+-------+-------+\n | %s %s %s | %s %s %s | %s %s %s |\n | %s %s %s | %s %s %s | %s %s %s |\n | %s %s %s | %s %s %s | %s %s %s |\n +-------+-------+-------+\n""" Then the non-dummy version is faster than the dummy version (very slightly, presumably because it doesn't need to allocate 28 dummy variables). Peace Bill Mill bill.mill at gmail.com From nospam at nospam.com Sat Aug 20 14:49:50 2005 From: nospam at nospam.com (42) Date: Sat, 20 Aug 2005 18:49:50 GMT Subject: Sandboxes References: <MPG.1d70a3f449c0ede9989c96@shawnews.vf.shawcable.net> <3mog8aF17j66oU1@uni-berlin.de> Message-ID: <MPG.1d711b37785d066b989c97@shawnews.vf.shawcable.net> In article <3mog8aF17j66oU1 at uni-berlin.de>, deets at nospam.web.de says... > > Would this sufficient? Are there any drawbacks or giant gaping holes? > > I'm anticipating that I'd also need to block 'exec' and 'eval' to > > prevent an import from being obfuscated past the pre-parse. > > > > Or is this a hopeless cause? > > Yes. There have been numerous discussions about this, and there are so > many different ways to overcome such imposed limitations - it won't work. > > > > > Finally, either way, would anyone recommend a different script engine > > that might be more suitable for what I'm trying to accomplish that I > > might not have looked at. I don't need much; it needs to work with C#, > > and be able to easily interact with 'published' interface. I'd also like > > to leverage a "popular" language instead of something obscure. > > Maybe LUA? I only heard that it's well suited for such tasks. > > The overall question for me is: Why crippled acess at all? What do you > fear your users could do that harms you or others? There are of coures > valid reasons, I don't question that generally. E.g. applets and the > like. So what is the actual usecase? Basically I just want a language to allow users to write macros, interact with application objects, set property values, sequence operations, supporting loops and branch logic and so forth. Something along the lines of a drawing program that allowed uers to write and/or download scripts to perform batches of arbitrary (parameterized) operations. e.g.scripts along the lines of: function drawfan(x,y,r) i=45 while (i<90) if i.isEven() color=red; else color=blue; PublishedInterface.Drawline(x,y, x+r*sin(i), y+r*cos(i),color) i++ end while I want the 'worst case' a malicious script to be able to accompish to be a program crash or hang. regards, From godoy at ieee.org Mon Aug 1 12:28:43 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 01 Aug 2005 13:28:43 -0300 Subject: Dabo in 30 seconds? References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <mailman.2532.1122901180.10512.python-list@python.org> <dclb4i$24l$1@news.sap-ag.de> <8ur1s2-r5t.ln1@strongwill.g2ctech> <dclg4t$54o$1@news.sap-ag.de> Message-ID: <m7v1s2-ld.ln1@strongwill.g2ctech> Daniel Dittmar wrote: >> I see no problem with that. Specially since there are lots of ways to >> share >> directories on a network installation. You install it once and it's >> done. >> > > Some on Windows, some on one Linux, some on another Linux with a newer > GTK, some want it on their laptops to work on the road ... All of the fixed and network accessible are easily solvable (? Is it correct English?). Corporative environments should also have an upgrade policy, so the "new GTK" would just exist after testing has been done and this "new GTK" is certified for the company's apps. For laptops to work on the road there are two options: VPNs and installing it locally. How many "laptops to work on the road" there will be compared to "fixed workstations"? We can find several problems, almost all of them can be solved with the admin's creativity. -- Jorge Godoy <godoy at ieee.org> From robert.dowell at gmail.com Wed Aug 31 13:17:58 2005 From: robert.dowell at gmail.com (robert.dowell at gmail.com) Date: 31 Aug 2005 10:17:58 -0700 Subject: Retrieving Filename from Path In-Reply-To: <1125508327.616838.55630@g44g2000cwa.googlegroups.com> References: <1125508327.616838.55630@g44g2000cwa.googlegroups.com> Message-ID: <1125508678.590072.87180@g44g2000cwa.googlegroups.com> >>> import os.path >>> help(os.path) Help on module ntpath: NAME ntpath - Common pathname manipulations, WindowsNT/95 version. FILE c:\data\utils\python24\lib\ntpath.py DESCRIPTION Instead of importing this module directly, import os and refer to this module as os.path. FUNCTIONS abspath(path) Return the absolute version of a path basename(p) Returns the final component of a pathname commonprefix(m) Given a list of pathnames, returns the longest common leading component dirname(p) Returns the directory component of a pathname exists(path) Test whether a path exists expanduser(path) Expand ~ and ~user constructs. If user or $HOME is unknown, do nothing. expandvars(path) Expand shell variables of form $var and ${var}. Unknown variables are left unchanged. getatime(filename) Return the last access time of a file, reported by os.stat() getctime(filename) Return the creation time of a file, reported by os.stat(). getmtime(filename) Return the last modification time of a file, reported by os.stat() getsize(filename) Return the size of a file, reported by os.stat() isabs(s) Test whether a path is absolute isdir(path) Test whether a path is a directory isfile(path) Test whether a path is a regular file islink(path) Test for symbolic link. On WindowsNT/95 always returns false ismount(path) Test whether a path is a mount point (defined as root of drive) join(a, *p) Join two or more pathname components, inserting "\" as needed normcase(s) Normalize case of pathname. Makes all characters lowercase and all slashes into backslashes. normpath(path) Normalize path, eliminating double slashes, etc. realpath = abspath(path) Return the absolute version of a path split(p) Split a pathname. Return tuple (head, tail) where tail is everything after the final slash. Either part may be empty. splitdrive(p) Split a pathname into drive and path specifiers. Returns a 2-tuple "(drive,path)"; either part may be empty splitext(p) Split the extension from a pathname. Extension is everything from the last dot to the end. Return (root, ext), either part may be empty. splitunc(p) Split a pathname into UNC mount point and relative path specifiers. Return a 2-tuple (unc, rest); either part may be empty. If unc is not empty, it has the form '//host/mount' (or similar using backslashes). unc+rest is always the input path. Paths containing drive letters never have an UNC part. walk(top, func, arg) Directory tree walk with callback function. For each directory in the directory tree rooted at top (including top itself, but excluding '.' and '..'), call func(arg, dirname, fnames). dirname is the name of the directory, and fnames a list of the names of the files and subdirectories in dirname (excluding '.' and '..'). func may modify the fnames list in-place (e.g. via del or slice assignment), and walk will only recurse into the subdirectories whose names remain in fnames; this can be used to implement a filter, or to impose a specific order of visiting. No semantics are defined for, or required of, arg, beyond that arg is always passed to func. It can be used, e.g., to pass a filename pattern, or a mutable object designed to accumulate statistics. Passing None for arg is common. DATA __all__ = ['normcase', 'isabs', 'join', 'splitdrive', 'split', 'splite... altsep = '/' curdir = '.' defpath = r'.;C:\bin' devnull = 'nul' extsep = '.' pardir = '..' pathsep = ';' sep = r'\' supports_unicode_filenames = True Rob Cowie wrote: > Hi, > > Given a string representing the path to a file, what is the best way to > get at the filename? Does the OS module provide a function to parse the > path? or is it acceptable to split the string using '/' as delimiters > and get the last 'word'. The reason I'm not entirely happy with that > method is that it is platform specific. I would prefer to use a built > in method if possible. > > Cheers, > > Rob Cowie From wierob at gmx.de Wed Aug 10 07:40:02 2005 From: wierob at gmx.de (Robert Wierschke) Date: Wed, 10 Aug 2005 13:40:02 +0200 Subject: What is Python?! In-Reply-To: <EklKe.61699$fm.4076087@news4.tin.it> References: <ddcnbf$aen$02$1@news.t-online.com> <EklKe.61699$fm.4076087@news4.tin.it> Message-ID: <ddcoo8$pqt$00$1@news.t-online.com> Adriano Varoli Piazza schrieb: > Robert Wierschke ha scritto: > ... > Reading the FAQ at the python website too difficult? I don't think you > missed any of the most frequently asked... Good job. > sorry I 've forgetten the FAQ From nicolasp at aaton.com Thu Aug 4 08:22:12 2005 From: nicolasp at aaton.com (nico) Date: Thu, 04 Aug 2005 14:22:12 +0200 Subject: Embedded python Message-ID: <42f20657$0$27904$626a14ce@news.free.fr> Hi, Does anyone have embedded a python interpreter on a proprietary hardware ? I have a home made hardware running a home made OS. C is used as programming language. I'd like to add a python interpreter to my system. Any guidelines ? Nicolas From mom.myggen at gmail.com Fri Aug 26 13:41:11 2005 From: mom.myggen at gmail.com (OllieZ) Date: 26 Aug 2005 10:41:11 -0700 Subject: same menu point is activated In-Reply-To: <uMjPe.1955$z2.405@newsread3.news.pas.earthlink.net> References: <1124957306.899701.223010@g49g2000cwa.googlegroups.com> <uMjPe.1955$z2.405@newsread3.news.pas.earthlink.net> Message-ID: <1125078071.888664.245240@g47g2000cwa.googlegroups.com> Thx a lot, i'll try that asap :) OllieZ From ebouabyd at welho.com Sat Aug 13 05:21:12 2005 From: ebouabyd at welho.com (Mosti El) Date: Sat, 13 Aug 2005 12:21:12 +0300 Subject: breaking a loop References: <fUNKe.5188$5g.4209@tornado.socal.rr.com> Message-ID: <ddkds6$taa$1@nyytiset.pp.htv.fi> I think u need break before exit() so if u want break from any loop just add break "el chupacabra" <nowayjose at noway.com> wrote in message news:fUNKe.5188$5g.4209 at tornado.socal.rr.com... > Hi, I'm just learning Python....thanks in advance... > > Do you get out of this loop? > > Problem: When I type 'exit' (no quotes) the program doesn't quit the loop...it actually attemps to find entries that containt the 'exit' string. > > Desired behavior: when I type 'exit' the program should quit. > > def search(): > searchWhat = "" > while searchWhat != 'exit': > searchWhat = "%%%s%%" % raw_input ('Search for : ') > cursor.execute("select * from TABLE where FIELD like %s", (searchWhat)) > result = cursor.fetchall() > print '+------------------------------------------------------------------+' > print '| # | Name | LastName |' > print '+------------------------------------------------------------------+' > for record in result: > print ' ', record[0], ' : ', record[1], ' ==> ', record[2] > print '+------------------------------------------------------------------+' > #end for statement, end of search > > > --------------= Posted using GrabIt =---------------- > ------= Binary Usenet downloading made easy =--------- > -= Get GrabIt for free from http://www.shemes.com/ =- > From wouter at voti.nl Tue Aug 23 15:09:08 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Tue, 23 Aug 2005 19:09:08 GMT Subject: Doubt C and Python References: <mailman.3405.1124784768.10512.python-list@python.org> <APGdnW2XmLAhipbeRVn-sw@rcn.net> Message-ID: <430b73e2.1489645246@news.xs4all.nl> >For me, the choice is typically among C++, Perl, Python, and Java. The >arguments for Python relative to these languages are: > add: I develop on my platform (which happens to be XP, but that is irrelevant), I put the Python source on my website, and I never worry about the platform my users will be using. An those users don't need to know how to compile a program, it will just run. Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From johnny.karlsson at gmail.com Mon Aug 22 14:37:30 2005 From: johnny.karlsson at gmail.com (johnny.karlsson at gmail.com) Date: 22 Aug 2005 11:37:30 -0700 Subject: sending binary files to a 16 micro controller. In-Reply-To: <u8mdnf9zOZW5bpTeRVn-vg@powergate.ca> References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <decet5$dm7$1@wake.carmen.se> <11gjn8k74pb6uc0@corp.supernews.com> <decptq$bit$1@blackmamba.itd.rl.ac.uk> <1124725190.368311.306720@z14g2000cwz.googlegroups.com> <u8mdnf9zOZW5bpTeRVn-vg@powergate.ca> Message-ID: <1124735850.821464.21350@o13g2000cwo.googlegroups.com> yeah, i didn't mean running python on the HC12 but using compiled python on a ARM7 or simular would be nice. There was a project for embedded python but it seems to have died. Yeah i've been thinking about using UDP but then i would have to impliment checksums and having a reliable way to send and acknowlege the chunks sent. But i'll start tinkering with it tomorow and se what i'll end up with. I allready have a tcp-server for the device so it would'nt be to much hassle to modify it. i'm using OpenTCP by the way. From hatcliff at cis.ksu.edu Tue Aug 23 11:58:51 2005 From: hatcliff at cis.ksu.edu (John Hatcliff) Date: Tue, 23 Aug 2005 10:58:51 -0500 Subject: PEPM 2006: Call for Papers -- ACM SIGPLAN 2006 Workshop on Partial Evaluation and Program Manipulation Message-ID: <430B47BB.10702@cis.ksu.edu> C A L L F O R P A P E R S === P E P M 2006 === ACM SIGPLAN 2006 Workshop on Partial Evaluation and Program Manipulation (Affiliated with POPL 2006) http://www.cis.ksu.edu/santos/pepm06 January 9-10, 2006 Charleston, South Carolina The PEPM Symposium/Workshop series aims to bring together researchers and practitioners working in the areas of program manipulation, partial evaluation, and program generation. PEPM focuses on techniques, supporting theory, tools, and applications of the analysis and manipulation of programs. The 2006 PEPM workshop will be based on a broad interpretation of semantics-based program manipulation. This year, a concerted effort will be made to expand the scope of PEPM significantly beyond the traditionally covered areas of partial evaluation and specialization and include practical applications of program transformations such as refactoring tools, and practical implementation techniques such as rule-based transformation systems. In addition, the scope of PEPM will be broadened to cover manipulation and transformations of program and system representations such as structural and semantic models that occur in the context of model-driven development. In order to reach out to practitioners, a separate category of tool demonstration papers will be solicited. Topics of interest for PEPM'06 include, but are not limited to: * Program and model manipulation techniques such as transformations driven by rules, patterns, or analyses, partial evaluation, specialization, slicing, symbolic execution, refactoring, aspect weaving, decompilation, and obfuscation. * Program analysis techniques that are used to drive program/model manipulation such as abstract interpretation, static analysis, binding-time analysis, dynamic analysis, constraint solving, and type systems. * Analysis and transformation for programs/models with advanced features such as objects, generics, ownership types, aspects, reflection, XML type systems, component frameworks, and middleware. * Techniques that treat programs/models as data objects including meta-programming, generative programming, model-driven program generation and transformation. * Application of the above techniques including experimental studies, engineering needed for scalability, and benchmarking in a wide variety of domains including source code manipulation, domain-specific language implementations, scientific computing, middleware frameworks and infrastructure needed for distributed and web-based applications. We especially encourage papers that break new ground including descriptions of how program/model manipulation tools can be integrated into realistic software development processes, descriptions of robust tools capable of effectively handling realistic applications, and new areas of application such as rapidly evolving systems, distributed and web-based programming including middleware manipulation, model-driven development, and on-the-fly program adaptation driven by run-time or statistical analysis. Submission Categories, Guidelines, and Proceedings: Regular Research Papers must not exceed 10 pages in ACM Proceedings style. Tool demonstration papers must not exceed 4 pages in ACM Proceedings style, and authors will be expected to present a live demonstration of the described tool at the workshop. Suggested topics, evaluation criteria, and writing guidelines for both research tool demonstration papers will be made available on the PEPM'06 Web-site. Papers should be submitted electronically via the workshop web site. We plan to publish the workshop proceedings in ACM SIGPLAN Notices (with full papers appearing in the ACM Digital Library) and selected papers will be invited for a journal special issue dedicated to PEPM'06. Important Dates: Submission........: October 7, 2005 Apia, 11:59pm, Samoan time (firm deadline, no extensions) Notification......: November 18, 2005 Camera-Ready Paper: December 16, 2005. Workshop co-Chairs: John Hatcliff, Kansas State University, USA (hatcliff at cis.ksu.edu) Frank Tip, IBM T.J. Watson Research Center, USA (ftip at us.ibm.com) PEPM 2006 Program Committee: Krzysztof Czarnecki University of Waterloo Gary Daugherty Rockwell Collins Advanced Technology Center Tom Dean Queen's University Mangala Gowri Nanda IBM India John Hatcliff (co-chair) Kansas State University Nevin Heintze Agere Systems Jaakko J?rvi Texas A & M University Jens Krinke University of Hagen Shriram Krishnamurthi Brown University Julia Lawall University of Copenhagen (DIKU) Oege de Moor Oxford University Germ?n Puebla Technical University of Madrid Peter Sestoft Royal Veterinary and Agricultural University (Denmark) Gregor Snelting University of Passau Frank Tip (co-chair) IBM T.J. Watson Research Center Eelco Visser Universiteit Utrecht -- ---------------------------------------------------------------------------- John Hatcliff Phone: 785-532-6350 Professor Fax..: 785-532-7353 Department of Computing and Information Sciences Email: hatcliff at cis.ksu.edu 234 Nichols Hall WWW..: http://www.cis.ksu.edu/~hatcliff Kansas State University Manhattan, KS 66506 ---------------------------------------------------------------------------- From timothyd at ntf.com.au Wed Aug 31 20:23:39 2005 From: timothyd at ntf.com.au (Timothy Downs) Date: Thu, 01 Sep 2005 10:23:39 +1000 Subject: Survey Tool Message-ID: <43164A0B.7090406@ntf.com.au> I've been looking around for an online (that is, web-based) survey tool for commercial use, and have been unable to any written in Python. Is anyone aware of such a thing existing? A price tag is not a problem, although access to source code is desirable. Timothy Downs From seberino at spawar.navy.mil Fri Aug 5 15:40:41 2005 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 5 Aug 2005 12:40:41 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) Message-ID: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> I've heard 2 people complain that word 'global' is confusing. Perhaps 'modulescope' or 'module' would be better? Am I the first peope to have thought of this and suggested it? Is this a candidate for Python 3000 yet? Chris From benji at benjiyork.com Tue Aug 2 16:18:53 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 02 Aug 2005 16:18:53 -0400 Subject: Python IDE's In-Reply-To: <s2ef4a8a.018@server7.nfra.nl> References: <s2ef4a8a.018@server7.nfra.nl> Message-ID: <42EFD52D.5040705@benjiyork.com> Adriaan Renting wrote: > vi/vim is a godssend if you need a working system that needs to fit in 4 > Mb or ROM, but it's an editor not an IDE. > When talking about IDE's I mean a lot more as 'just' an editor, below is > my 'wishlist', I would be very interested what solutions you use, how > much time it took you to set up this solution, and which parts of my > 'wishlist' it implements. First, a disclaimer: your point of "how much time it took you to set up?" is definitely valid. I would assert that it is also valid to ask "how much time did it save you once it was set up to work precisely the way you wanted it to?" > - Integrated help. > - Code completion. > - Integrated debugger. I've seen (but not used, because I don't want these features) Vim scripts to do these. They exist for Emacs too. > - Integrated GUI design. > The IDE should have a graphical tool for designing GUIs, and the editor > should be aware of it and propagate changes in an inobtrusive way. Not in Vim (or Emacs), but the best GUI designers /I've/ seen are stand-alone anyway. In other words, their not in an IDE either. > - Code aware editor. > - Integration with version control system. > - Code documentation/inspection tools. I use Vim for these. > Ability to generate include and inheritance trees On the rare occasions I do something like this it's with apidoc. > LOC counters I use sloccount (outside of Vim). > profiling what lines of you code get executed most/never I use a testing framework or profiler for that (outside of Vim) > helpfile generation from code, etc. I don't do that, but if I did, it would probably be outside of Vim. > Tools for communication with coworkers Gaim and Thunderbird > bugtracking Zope collector and Roundup > which targets need which files, automatic install scripts/tools, > etc. (If I understand you correctly) I use a tool we developed internally to do this. > - Accessible user interface. > All functionality should be accessible through some menu structure, so I > don't need to depend on my memory. Prefereable reprogrammable/assignable > shortcut keys for all functionality, maybe even some form of macros, > plugins, etc. Vim (and Emacs) does this (there are a few non-menu accessible things, but they can be added to menus as you please). > - For C/C++: > memory leak detection External tools. > Why I want this? Because I want to spend my time programming my > code, not my developement environment. Why would I spend the time setting this up? Because I want to spend my time programming my code, not fighting my development environment. :) I wonder why you would want some of these things integrated into an IDE (communication, LOC counter, etc.) -- Benji York From rafi at free.fr Mon Aug 1 17:14:43 2005 From: rafi at free.fr (rafi) Date: Mon, 01 Aug 2005 23:14:43 +0200 Subject: inheriting from datetime In-Reply-To: <1122929471.966054.146010@g44g2000cwa.googlegroups.com> References: <1122929471.966054.146010@g44g2000cwa.googlegroups.com> Message-ID: <42ee90c6$0$7657$626a14ce@news.free.fr> Rob Conner wrote: > So this is simple, why can't I run the following code? I've tried many > variances of this, but simply cannot inherit from datetime or > datetime.datetime. I get this on line 3. > TypeError: function takes at most 2 arguments (3 given) line 3 of the following code or line 3 of the use of the code? on my box it runs, except that ValueError is not caught by the except. side question: what is the point of accepting invalid dates? -- rafi "Imagination is more important than knowledge." (Albert Einstein) From onurb at xiludom.gro Tue Aug 2 06:05:21 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 02 Aug 2005 12:05:21 +0200 Subject: Newer than a Newbe In-Reply-To: <EiwHe.12576$kc6.5400@trnddc03> References: <EiwHe.12576$kc6.5400@trnddc03> Message-ID: <42ef4563$0$7841$626a14ce@news.free.fr> None wrote: > Hello, > I am just starting to look into python.I have been prog with php for > several years.My question is: > Can/Is Python used as a web scripting language Yes, definitively. There are in fact almost too many web-programming solutions in Python, from the good ole cgi to the full-blown web application server. >, and if so do many hosts > support it? No. > Thanks You're welcome !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From matt.hammond at rd.bbc.co.uk Mon Aug 22 04:33:26 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Mon, 22 Aug 2005 09:33:26 +0100 Subject: Problem (or even bug?) with Tkinter References: <op.svqyy6gbmko9fo@pcx194.rd.bbc.co.uk> <opsvq4xev4rqur0o@eb.pragmadev> <op.svrapqbumko9fo@pcx194.rd.bbc.co.uk> Message-ID: <op.svwh10jnmko9fo@pcx194.rd.bbc.co.uk> A fix for this has just been pointed out to me (by Reinhard Max): <quote> I've seen problems with non-working entry and text widgets on SUSE Linux when Tk is used with the SCIM input manager. Could you please check whether the XMODIFIERS variable exists in the environment of your Tk process? If exists and has the value "@im=SCIM", you could try as aworkaround to set it to "@im=local", or just unset it before starting Tk. If that fixes your problem, and you don't otherwise make use of SCIM, you can just deinstall the scim package. Unfortunately I haven't yet found a way to make Tk cooperate better with SCIM. As a workaround for SUSE Linux 10.0 I might just unset XMODIFIERS during Tk's startup, so that at least typing ASCII will work. </quote> Altering the XMODIFIERS environment variable as he suggested solved the problem. -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From gordonb.vu2n4 at burditt.org Thu Aug 25 22:42:48 2005 From: gordonb.vu2n4 at burditt.org (Gordon Burditt) Date: Fri, 26 Aug 2005 02:42:48 -0000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <86acj5mpty.fsf@bhuda.mired.org> Message-ID: <11gt0d8bjanaabe@corp.supernews.com> >HTML is designed to degrade gracefully (never mind that most web >authors and many browser developers don't seem to comprehend this), so >you don't really need a "subset" html to get the safety features you >want. All you need to do is disable the appropriate features in the >HTML renderer in your news and mail readers. JavaScript, Java, and any >form of object embedding. Oh yeah, and frames. And links. And cookies. And any kind of external site or local file access. And browser history. Gordon L. Burditt From fbarbuto2002.no at spam.yahoo.ca Thu Aug 11 23:24:46 2005 From: fbarbuto2002.no at spam.yahoo.ca (Fausto Arinos Barbuto) Date: Fri, 12 Aug 2005 03:24:46 GMT Subject: Psyco & Linux Message-ID: <2EUKe.193369$5V4.19467@pd7tw3no> Hi All; I have Psyco (on Windows XP) and now I want to install it on Linux, too. I FTP'd the tarball (tar.gz) from Psyco's site but can't get it compiled. First, I tried the usual "python setup.py install" but that did not work. I later found a RPM for Psyco but it wasn't suitable to the Linux version I'm currently using. Has any of you had a similar experience? If so, how did you manage to solve the problem (in the case that you did)? Before one asks, I must say that I'm trying to build the package as the super user (root). :-) The specifics of my system are: Athlon AMD-64 3300+ SuSE 9.3 Professional (64-bit) Python 2.4 gcc/g++ 3.3.5 Thanks in advance for any help. ---Fausto From rafi at free.fr Fri Aug 26 03:26:01 2005 From: rafi at free.fr (rafi) Date: Fri, 26 Aug 2005 09:26:01 +0200 Subject: variable hell In-Reply-To: <rNOSPAMon-88C73B.16253825082005@news.gha.chartermi.net> References: <mailman.3511.1124982438.10512.python-list@python.org> <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> <mailman.3535.1125002125.10512.python-list@python.org> <rNOSPAMon-88C73B.16253825082005@news.gha.chartermi.net> Message-ID: <430ec3ff$0$27032$626a14ce@news.free.fr> Ron Garret wrote: >>Because eval() takes an expression as an argument, and assignment is a >>statement. > > And if you find this distinction annoying, try Lisp. that's were I come from :-) -- rafi "Imagination is more important than knowledge." (Albert Einstein) From rkern at ucsd.edu Wed Aug 24 21:52:04 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 24 Aug 2005 18:52:04 -0700 Subject: while c = f.read(1) [comment on news hosting] In-Reply-To: <dej776$kte$1@sea.gmane.org> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <mailman.3253.1124431515.10512.python-list@python.org> <1124702804.589011.257970@o13g2000cwo.googlegroups.com> <mailman.3350.1124706634.10512.python-list@python.org> <87fyt1mods.fsf@peds-pc311.bsd.uchicago.edu> <mailman.3395.1124762174.10512.python-list@python.org> <1124932777.548549.320150@o13g2000cwo.googlegroups.com> <dej776$kte$1@sea.gmane.org> Message-ID: <dej884$mp2$1@sea.gmane.org> Steve Holden wrote: > Well you could do worse than use the gmane.comp.python.general newsgroup > if you want to use an NNTP newsreader. I recently left the ISP who had > provided me with news services for years, and I am very happy with the > gmane service (though heaven only knows why they chose to use a name > other than comp.lang.python for the group: perhaps they were only aware > of the list it gateways when they established the service). Their service is *only* about gatewaying mailing lists to their NNTP server. I'm certain they were aware of comp.lang.python and how it is gatewayed to python-list, but they aren't a general USENET node and don't get USENET feeds from other nodes. gmane.comp.python.general articles come only from python-list. I imagine that it would be impolite to name any of their newsgroups using one of the controlled Big Eight hierarchies. But I agree that it is quite nice and is what I use to access c.l.py/python-list so that I can use the same server both at home and at work. http://gmane.org -- 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 bdesth.quelquechose at free.quelquepart.fr Mon Aug 1 16:50:34 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 01 Aug 2005 22:50:34 +0200 Subject: Is this Pythonic? In-Reply-To: <op.suuhv4kn1js0xs@news.telkomsa.net> References: <slrndesi1l.v5t.zen19725@cabalamat.somewhere> <LOCdnYPPD7jRyXPfRVn-2g@powergate.ca> <op.suuhv4kn1js0xs@news.telkomsa.net> Message-ID: <42ee83db$0$3338$636a15ce@news.free.fr> Caleb Hattingh a ?crit : > Peter > > To my mind, this kind of setup (interface class, or abstact class are two different things. >) is > more usually used in static languages True. >to benefit polymorphism This is a good reason to use an interface in Java. C++ has no notion of 'interface', so you have to use abstract classes to achieve the same result. > - but > python is dynamically typed, so in which situations would this setup be > useful in a python program? Abstract classes ? When you want to factor out common implementation in a base class and force derived class to implement specific parts. One common use case is the template method (aka "hollywood", aka "don't call us, we'll call you") pattern. > You see, I expected your post to say that > it wouldn't even be necessary, but you didn't :) Implementation inheritance is never "necessary". Nor are OO, modularity, structured programming, and human-readable programming languages !-) It's a fact that inheritence being "only" (err... should I say "mostly" ?) an implementation mechanism in dynamic languages, class hierarchies tends to be much more flat. But this doesn't mean that abstract base classes are useless. > I have spent a little effort training myself not to bother setting up > class hierarchies like this in python I had this pattern too. From googlenews at tooper.org Wed Aug 24 07:02:02 2005 From: googlenews at tooper.org (tooper) Date: 24 Aug 2005 04:02:02 -0700 Subject: Variables in REs In-Reply-To: <430c43cd$1@news.bezeqint.net> References: <430c43cd$1@news.bezeqint.net> Message-ID: <1124881322.542897.215790@g43g2000cwa.googlegroups.com> Use os.sep to get / or \ or whatever character used to build pathes on the os you're working on From mark at markroseman.com Mon Aug 1 17:54:15 2005 From: mark at markroseman.com (Mark Roseman) Date: Mon, 01 Aug 2005 17:54:15 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <mailman.2438.1122791233.10512.python-list@python.org> <7xd5ozv1ng.fsf@ruckus.brouhaha.com> <mailman.2467.1122835539.10512.python-list@python.org> <7xek9e5ywq.fsf@ruckus.brouhaha.com> <mailman.2495.1122858673.10512.python-list@python.org> <mark-CECC3A.15265501082005@news.isp.giganews.com> <mailman.2570.1122929447.10512.python-list@python.org> <7xek9djr76.fsf@ruckus.brouhaha.com> Message-ID: <mark-C1002B.17541501082005@news.isp.giganews.com> Paul Rubin <http://phr.cx at NOSPAM.invalid> wrote: > Cliff Wells <cliff at develix.com> writes: > > Still, that leaves Linux and Mac out in the cold. But I'll admit you > > met my challenge. Most likely you can actually do most of the things > > with Tk you can with Wx, it's simply a matter of how much effort is > > going to be (for instance, it's certainly quite possible to embed Gecko > > in Tk, but I for one am not likely to be up to the task). > > I actually misunderstood your question about embedding a browser and > thought for a while about what it would take to write or port a > serious browser to use tkinter as its graphics layer. The resulting > picture wasn't pretty. I wonder whether it's feasible in wxpython. I'll point out that this has been done (in fact, many times). For example: http://tkhtml.hwaci.com (Integrating Gecko in has also been done, as a side note). I'll highlight a meta-point regarding this thread: there's a lot of stuff in Tk that is available but not built into the standard library, nor necessarily well documented or even easy to find. While this is a sad state of affairs, and to my mind no excuse (even though this is a common situation with open source software), it emphasizes that a cursory look does not tell the whole story. While I certainly don't begrudge anyone their choice of tools, it's no surprise that someone who's become more familiar with wxPython would have an unduly low opinion of Tk. They've obviously spent more time overcoming the warts in wxPython, and wouldn't have spent comparable effort learning what it would take to overcome the warts in Tk - it just looks hopelessly flawed in comparison. Switch "wxPython" and "Tk" around in the above argument and I think the statements equally hold of course. Mark From amk at amk.ca Mon Aug 22 11:29:06 2005 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 22 Aug 2005 10:29:06 -0500 Subject: Sanitizing untrusted code for eval() References: <pan.2005.08.22.13.55.38.277993@vt.edu> Message-ID: <UMSdneKpXuXfcpTeRVn-rw@speakeasy.net> On Mon, 22 Aug 2005 13:55:45 GMT, Jim Washington <jwashin at vt.edu> wrote: > I'm still working on yet another parser for JSON (http://json.org). See http://python.ca/nas/log/200507/index.html#21_001 for another parser. I don't know if it uses eval() or not, but would bet on "not" because Neil is pretty security-conscious. --amk From grante at visi.com Tue Aug 2 15:32:13 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 02 Aug 2005 19:32:13 -0000 Subject: py2exe windows apps path question References: <11ev0tcg9n2ndd@corp.supernews.com> <dcoahp$9u9$3@news1.zwoll1.ov.home.nl> <11evdoj8c4brd1b@corp.supernews.com> <dcoema$adr$1@news4.zwoll1.ov.home.nl> Message-ID: <11eviht7e6k6425@corp.supernews.com> On 2005-08-02, vincent wehren <vincent at visualtrans.de> wrote: > If you are building paths in you code that are relative to > your app, I'm not using any paths. I use cytpes to load a .dll, and I don't really know what gnuplot-py is doing, but I think it's executing a .exe file and talking to it via a pipe or something. > please see my reply to Greg's post. If not, you may > as a workaround want to try to add the frozen application's > directory to the system path environment variable. Windows > will look for dlls there, too. That's probably the right answer. > To get the app's actual location, you will need something like > the getAppPrefix() function as per my reply to Greg's reply. > The getAppPrefix() function will also hold when the user adds > your frozen app to his/her system path and call the app from > any location from the command line - sys.argv[0] just won't do > the trick in such a setting. I'll give that a try. -- Grant Edwards grante Yow! .. I think I'd at better go back to my DESK visi.com and toy with a few common MISAPPREHENSIONS... From oriana.falco at thalesesec.com Mon Aug 22 18:05:31 2005 From: oriana.falco at thalesesec.com (oriana.falco at thalesesec.com) Date: 22 Aug 2005 15:05:31 -0700 Subject: How to print the name of a list? In-Reply-To: <ded9q0$do6$1@plaza.suomi.net> References: <1124727846.909693.129750@g43g2000cwa.googlegroups.com> <ded9q0$do6$1@plaza.suomi.net> Message-ID: <1124748331.809901.293280@o13g2000cwo.googlegroups.com> Wow, thanks.....that's a neat little function....I'll still check out the dictionary stuff. For now, this helps a lot though... THANKS!!! From olekristianvillabo at gmail.com Thu Aug 25 05:26:40 2005 From: olekristianvillabo at gmail.com (olekristianvillabo at gmail.com) Date: 25 Aug 2005 02:26:40 -0700 Subject: MySQLdb module, method executemany with anything other than strings? Message-ID: <1124962000.842751.125710@g49g2000cwa.googlegroups.com> The method cursor.executemany is there in order to avoid multiple calls to cursor.execute(). I have tried, with success, to do like every single example (that I have found on the www) on the subject shows, to use a insert statement on the form: statement = INSERT INTO table (colA,colB,colC) values (%s,%s,%s) and pass in a list containing tuples list = [('bla','bla','bla'),('bla','bla','bla'),('bla','bla','bla')] on the form cursor.executemany(statement,list) This works fine for all strings, but I have never been able to insert a single integer or a float using this method. I get an error message reporting that float (or an int) is required. Statement is then of course changed to something like statement = INSERT INTO table (colA,colB,colC) values (%s,%i,%f) list = [('bla',1,0.65),('bla',3,3.7),('bla',3,0.9)] Havee anybody experienced similar problems? Am I doing something wrong? Any feedback is greatly appreciated. Here is som real output from the interpreter: >>> statement = 'insert into testtable3 (url,probability) values (%s,%f)' >>> l [('url1', 0.98999999999999999), ('url2', 0.89000000000000001)] >>> cursor.executemany(statement,l) Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 181, in execu any self.errorhandler(self, TypeError, msg) File "C:\Python24\Lib\site-packages\MySQLdb\connections.py", line 33, in de lterrorhandler raise errorclass, errorvalue TypeError: float argument required From lycka at carmen.se Wed Aug 24 12:10:01 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 24 Aug 2005 18:10:01 +0200 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <mailman.3469.1124892172.10512.python-list@python.org> References: <mailman.3469.1124892172.10512.python-list@python.org> Message-ID: <dei64q$hgg$1@wake.carmen.se> Andreas Kostyrka wrote: > I cannot comment on linode as I'm not a customer. The info on the website > seems ok. But the prices are somehow laughable: I'm currently paying > EUR39 for a dedicated host (with at least 200GB traffic, I'd had to look it up > 60GB "storage", 256MB RAM and a 2.4GHz P4 CPU all alone to me). > > That makes the 79.95 dollars for "Linode 256" somehow a bit expensive. > OTOH perhaps dedicated servers are really cheap in Germany ;) You will get a price in the same magnitude (SEK395, approx EUR42 or USD52) from my ISP in Sweden. rimuhosting.com certainly seems more reasonable at USD20. From rkern at ucsd.edu Fri Aug 19 02:04:36 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 18 Aug 2005 23:04:36 -0700 Subject: while c = f.read(1) In-Reply-To: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <de3spk$91n$1@sea.gmane.org> Greg McIntyre wrote: > I have a Python snippet: > > f = open("blah.txt", "r") > while True: > c = f.read(1) > if c == '': break # EOF > # ... work on c > > Is some way to make this code more compact and simple? It's a bit > spaghetti. That's not spaghetti. Not even close. In any case, is there a reason you are reading one character at a time instead of reading the contents of the file into memory and iterating over the resulting string? f = open('blah.txt', 'r') text = f.read() f.close() for c in f: # ... If you must read one character at a time, def reader(fileobj, blocksize=1): """Return an iterator that reads blocks of a given size from a file object until EOF. """ # Note that iter() can take a function to call repeatedly until it # receives a given sentinel value, here ''. return iter(lambda: fileobj.read(blocksize), '') f = open('blah.txt', 'r') try: for c in reader(f): # ... finally: f.close() -- 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 nethawg1 at verizon.net Fri Aug 19 14:50:38 2005 From: nethawg1 at verizon.net (SuppressedPen) Date: Fri, 19 Aug 2005 18:50:38 GMT Subject: Python 2.1 Bible Source Message-ID: <2SpNe.57$Hi.50@trnddc04> Hi Everyone! Just started with Python 2 weeks ago and I can't put it down it's to easy and to powerful, I'm sure the goons will be after us for having it soon, Hi Hi. Was wondering if anyone might know where I can find the source code for PYTHON 2.1 BIBLE book. Apparently it was online until the publisher sold the company. I also understand it has been sold a second time since the book was published. Maybe someone has a copy? Thanks. DOUG. From piet at cs.uu.nl Thu Aug 25 06:23:36 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 25 Aug 2005 12:23:36 +0200 Subject: Should I move to Amsterdam? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> Message-ID: <wzfysyiac7.fsf@ordesa.cs.uu.nl> >>>>> "Martin P. Hellwig" <mhellwig at xs4all.nl> (MPH) wrote: >MPH> Of course this is all done with public transport and/or bike, not without >MPH> reason. >MPH> Personal transportation sucks in the Netherlands, if you live in the >MPH> Randstad (the area of the above mentioned cities) and you have to travel >MPH> across the Randstad, you go with the bike and/or bus/tram/metro/train >MPH> because that is the fastest way of transportation. That depends very much on where you live and where you have to go (mostly on the number of changes of transport vehicle). I, for example live in a small village, 11 km from my work in Utrecht. By bus it is 45-60 minutes, by bike 40 min. and by car (rush hour) usually 20-25 min. Only when something serious happens it can be 45 min. by car. This happens about once a year. Most of the time I take the bike, but not for the speed. It is actually a pleasant ride, mainly through woods and meadows. My daughter worked some years ago in Nieuwegein, adjacent to Utrecht. By car 20 min., by public transport 60-90 min. And this is not in some remote area, but just in the center of the country, one of the most densely populated areas. -- Piet van Oostrum <piet at cs.uu.nl> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tim.peters at gmail.com Mon Aug 8 19:17:10 2005 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 8 Aug 2005 19:17:10 -0400 Subject: issues with doctest and threads In-Reply-To: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> References: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> Message-ID: <1f7befae05080816175b15c56@mail.gmail.com> [Michele Simionato] > I am getting a strange error with this script: > > $ cat doctest-threads.py > """ > >>> import time, threading > >>> def example(): > ... thread.out = [] > ... while thread.running: > ... time.sleep(.01) > ... thread.out.append(".") > >>> thread = threading.Thread(None, example) > >>> thread.running = True; thread.start() > >>> time.sleep(.1) > >>> thread.running = False > >>> print thread.out > ['.', '.', '.', '.', '.', '.', '.', '.', '.'] > """ > > if __name__ == "__main__": > import doctest; doctest.testmod() > > $ python doctest-threads.py > Exception in thread Thread-1: > Traceback (most recent call last): > File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap > self.run() > File "/usr/lib/python2.4/threading.py", line 422, in run > self.__target(*self.__args, **self.__kwargs) > File "<doctest __main__[1]>", line 5, in example > NameError: global name 'thread' is not defined It looks like pure thread-race accident to me. The main program does nothing to guarantee that the thread is finished before it prints `thread.out`, neither anything to guarantee that Python doesn't exit while the thread is still running. Stuff, e.g., a time.sleep(5) after "thread.running = False", and it's much more likely to work the way you intended (but still not guaranteed). A guarantee requires explicit synchronization; adding >>> thread.join() after "thread.running = False" should be sufficient. That ensures two things: 1. The `example` thread is done before thread.out gets printed. 2. The *main* thread doesn't exit (and Python doesn't start tearing itself down) while the `example` thread is still running. The exact output depends on OS scheduling accidents, but I expect you'll see 10 dots most often. BTW, trying to coordinate threads with sleep() calls is usually a Bad Idea; you can't generally expect more from an OS than that it will treat sleep's argument as a lower bound on the elapsed time the sleeper actually yields the CPU. From benji at benjiyork.com Fri Aug 19 17:24:41 2005 From: benji at benjiyork.com (Benji York) Date: Fri, 19 Aug 2005 17:24:41 -0400 Subject: How to get a unique id for bound methods? In-Reply-To: <rowen-A3BA2B.13291919082005@gnus01.u.washington.edu> References: <rowen-A3BA2B.13291919082005@gnus01.u.washington.edu> Message-ID: <43064E19.90701@benjiyork.com> Russell E. Owen wrote: > The id of two different methods of the same object seems to be the > same, and it may not be stable either. Two facts you're (apparently) unaware of are conspiring against you: 1) the "id" of an object is consistent for the lifetime of the object, but may be reused after the object goes away 2) methods are bound on an as-needed basis and then normally discarded (unless you do something to keep them around) An illustration: class cls(object): def meth1(self): pass def meth2(self): pass c = cls() m1 = c.meth1 print id(m1) -1209779308 m2 = c.meth1 print id(m2) -1209652732 > I guess that just means bound methods aren't objects in their own right, > but it surprised me. Nope, they're objects, they just don't tend to be around very long. > The "hash" function looks promising -- it prints out consistent values > if I use it instead of "id" in the code above. Is it stable and unique? > The documentation talks about "objects" again, which given the behavior > of id makes me pretty nervous. > > Any advice would be much appreciated. I think you'll get the best advice from this group if you tell us what the larger problem is that you're trying to solve. -- Benji York From cjw at sympatico.ca Tue Aug 30 11:54:27 2005 From: cjw at sympatico.ca (Colin J. Williams) Date: Tue, 30 Aug 2005 11:54:27 -0400 Subject: What are new-style classes? In-Reply-To: <3nehc2F15ainU1@individual.net> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> <mailman.95.1125256244.8229.python-list@python.org> <3nehc2F15ainU1@individual.net> Message-ID: <Mi%Qe.2797$884.427117@news20.bellglobal.com> Reinhold Birkenfeld wrote: > Terry Hancock wrote: > >>On Sunday 28 August 2005 04:47 am, Vaibhav wrote: >> >>>I recently heard about 'new-style classes'. I am very sorry if this >>>sounds like a newbie question, but what are they? I checked the Python >>>Manual but did not find anything conclusive. Could someone please >>>enlighten me? Thanks! >> >>"New style" classes are becoming the standard in Python, and must >>always be declared as a subclass of a new style class, including built-in >>classes. > > > [Warning, advanced stuff ahead!] > > That's not entirely true. New-style classes need not be derived from a new- > style class, they need to use the metaclass "type" or a derived. > > So you can also declare a new-style class as > > class new_class: > __metaclass__ = type > > Or, if you want to switch a whole module with many classes to new-style, just set a > > __metaclass__ = type > > globally. > > > Reinhold What are the pros and cons of the alternate approach? Colin W. From jgrahn-nntq at algonet.se Sat Aug 20 06:33:41 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 20 Aug 2005 10:33:41 GMT Subject: up to date books? References: <TMqdnRHoSoNyk5neRVn-3Q@rcn.net> <Of4Ne.973$No6.23389@news.tufts.edu> <de4j40$q67$1@wake.carmen.se> Message-ID: <slrndgdtag.r2g.jgrahn-nntq@frailea.sa.invalid> On Fri, 19 Aug 2005 14:25:36 +0200, Magnus Lycka <lycka at carmen.se> wrote: > John Salerno wrote: >> Just one more quick question: I'm basically learning programming for >> fun, and I'm concentrating on C# right now. Python seems interesting, >> but I was wondering if I should even bother. Would it supplement C# in >> any way, or can C# do everything Python can? > > Python is an excellent tool in any programmers toolbox. [...] ... > If I was a professional C# developer, I'm pretty sure I'd use Python > quite a bit. As a professional C++ programmer and database developer, > I've used Python to manage tests, find and repair broken data in > mission critical production systems, [...] > Actually, during seven years as an independent consultant, I found good > use for Python with every client. Same here. Python is also a language that organizations and bosses tend to, increasingly, accept as a "real language" in which "real programs" can be written. Sometimes perceptions matter. One more positive thing about Python, as compared to C#, is that it isn't tied to a specific manufacturer or environment. That may not matter short-term, but in the long run, it may be crucial for the program -- and for the programmer. /Jorgen -- // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu \X/ algonet.se> R'lyeh wgah'nagl fhtagn! From mensanator at aol.com Sun Aug 28 21:54:40 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 28 Aug 2005 18:54:40 -0700 Subject: trictionary? References: <mailman.101.1125267629.8229.python-list@python.org> <0LOdnYjsqqd-24_eRVn-1w@comcast.com> <mailman.105.1125272091.8229.python-list@python.org> <wtqdnceGAJbo04_eRVn-1g@comcast.com> Message-ID: <1125280480.602131.269670@g49g2000cwa.googlegroups.com> Steven Bethard wrote: > Adam Tomjack wrote: > > Steven Bethard wrote: > > ... > >> Using a two element list to store a pair of counts has a bad code > >> smell to me. > > ... > > > > Why is that? > > Note that "code smell"[1] doesn't mean that something is actually wrong, > just that it might be. In Python, pairs are usually handled with > tuples[2], but tuples would be inconvenient in this case, since the > first value must be modified. Declaring a class with two attributes as > you suggested is often a good substitute, but if the OP's code is really > what it looks like, I get another code smell because declaring a class > to be used by only 10 lines of code seems like overkill. > > I also get a code smell from a dict holding two-element lists because > I've been writing in Python and answering questions on the Python-list > for a couple of years now, and I've never needed one yet. ;-) > > STeVe > > [1]http://en.wikipedia.org/wiki/Code_smell > [2]http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types Could you do me a favor and see what this smells like? I put some data in a csv file (with headers) and this will bring it in quite simply as a dictionary with [names] as keys and an attribute dictionary as the value. py_monsters.csv: name,hardiness,agility,friend,courage,room,weight,special_def_odds,armor,weapon,odds,dice,side,hits,reaction,desc PIRATE,5,20,0,10,26,300,0,0,11,60,1,10,0,"not met",You see a man with a beard and a brass ring in his ear. He is wearing clothes made of silk and is wielding a very fancily engraved sword. import csv temp1 = [] temp2 = [] reader = csv.reader(file(r"py_monsters.csv")) for rec in reader: temp1.append(rec) for i in temp1[1:]: temp2.append((i[0],dict(zip(temp1[0][1:],i[1:])))) monsters = dict(temp2) This gives me what I want [('PIRATE', {'reaction': 'not met', 'agility': '20', 'room': '26', 'weight': '300', 'armor': '0', 'weapon': '11', 'hits': '0', 'side': '10', 'special_def_odds': '0', 'courage': '10', 'hardiness': '5', 'desc': 'You see a man with a beard and a brass ring in his ear. He is wearing clothes made of silk and is wielding a very fancily engraved sword.', 'odds': '60', 'friend': '0', 'dice': '1'})] so that I can now write code like if monsters['PIRATE']['reaction']=='not met': print monsters['PIRATE']['desc'] instead of using stupid index numbers. But the loader seems to have a kind of perl-like odor to it, i.e., next week I won't understand what it does. From newsgroups at jhrothjr.com Sat Aug 6 13:53:04 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 6 Aug 2005 11:53:04 -0600 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <C9udnRprcKxjImnfRVn-tA@powergate.ca> Message-ID: <11f9u843r0fts5b@news.supernews.com> "Peter Hansen" <peter at engcorp.com> wrote in message news:C9udnRprcKxjImnfRVn-tA at powergate.ca... > John Roth wrote: >> It's not going to happen because the Python community is fat and happy, >> and is not seeing the competition moving up on the outside. >> Characteristics >> that make a great language one day make a mediocre one a few years >> later, and make a has-been a few years after that. > > And here I thought that was the point of Python 3000. To let the > community produce a much improved language while avoiding the problems > caused by too much change occurring while people are trying to get useful > things done with what the language is _now_. The competition (and let's > see a description of just what that means, too) probably has the dual > advantage of newness and a small, hackerish community that is more than > happy to see rapid and radical change. You're right -- as with the > stereotypical large/slow vs. small/agile company motif -- that smaller and > more agile will pass larger and slow "on the outside", but you're wrong if > you think that means the larger-slower entity should drop what it's been > doing so well and try to compete entirely on the smaller-faster entity's > own ground. Maybe "fat and happy" wasn't the best choice of words (and maybe Extreme Programming wasn't Kent Beck's best choice of words either.) However. I see nothing in the existing Python 3000 PEP that does anything other than inspire a yawn. Sure, it's a bunch of cleanup, and some of it is definitely needed. What I don't see is the inspired leap forward that will once again put Python in the forefront rather than simply being one choice among many. What I want to see in Python 3000 is an AST based language that lets the editors do the pretty printing. Do you want automatic indenting or would you prefer end statements? It's an editor formatting option. The AST neither knows or cares. Don't want to see self? Editor formatting option. The AST knows what scope each identifier belongs to because it's right there in the text. No need for rules that you have to learn, sometimes the hard way. Want to see type inference? I haven't a clue how to do it in a dynamic language like Python, but an AST based language is a perfect test bed for experimentation. What's good about other languages? I see very little here that is an examination of what Smalltalk, Ruby, Perl, etc. seem to have gotten right and could be moved into Python to good effect. Talk to people who've moved from Python to Ruby, or to some other language. Ask them why, if Python is so great, what's even greater in that other language. If you still don't understand, you might want to read this: http://martinfowler.com/bliki/CollectionClosureMethod.html Look at Pep 8. It's a compendium of coding standards for the standard library. So far, ok. Coding standards are generally good. But why does Guido like underscores in method names? I know there was (and the accent is on the word was) some research, refuted well over a decade ago, that mixedCase was hard to read. The fact is that _all_ conventions for separating words are hard to read until the brain grows new synapses that handle it. Of the options, no separation is the hardest to handle. There are reasons why ancient texts, which had neither word separators nor punctuation, have very contentious translations. I find the notion that there should be one obviously right way to do something to be a good design principle, so why isn't there a single supported GUI library? If I'm over in Java-land, just about everything comes with a GUI. Python ships with a lot of little demonstration and utility scripts - none of which has a GUI. Part of the tone here is because of the PEP 208 voting process. From day one, I knew it was going to fail. Anyone who stood back and looked at the process, rather than getting into the detail, knew it was going to fail. There was no way that the Python community was going to come up with a simple majority in favor of one proposal. None. And it was obvious from the start. And the sad fact is that a proposition of the form: "We want a conditional expression; Guido should pick the syntax he finds the least obnoxious and get on with it" would have passed. Overwhelmingly. I came across a better voting process (Condorcet) later. Unfortunately it was later or I would have suggested it. Why the jihad (and I'm using the word advisedly) against the map, filter and reduce operators? It seems to be completely irrational from my viewpoint. I've seen the arguements, and they make no sense. > BTW, I think "large and stable" would have been less offensive than "fat > and happy", but perhaps you meant to imply we're both lazy and complacent, > rather than just satisfied with something that works and not inclined to > shoot for moving targets every working day. If so, I'm not sure why you'd > say that, since the evidence doesn't support it. I'm not suggesting shooting at a moving target. I'm suggesting getting the head out of the sand, looking at trends, and figuring out the _large_ steps to take next, not the nickle and dime fixups that are the only things I see in PEP 3000. (Not to say that some of them aren't going to be a lot of work. Some of them are.) I came back from Agile2005 last week. The open space session on Ruby was maybe 5 times as large as the one on Python. And both of them were kind of an afterthought. Look at the OSCon blogs. There were a number of hardcore Python people there. They couldn't get into Ruby sessions because they were jammed. Standing room only. There's a report out that the "scripting languages" in general are losing mindshare big time in Europe, Africa and the east in general. In fact, everywhere except in North America. I'm generally somewhat skeptical of these reports unless I can see the methodology, but it's definitely a data point. Another thing that stands out: the explicit versus dynamic typing debate has moved on from program correctness (which is a wash) to other areas that explicit (or derived) type information can be used for. I see this in PyFit: the languages where explicit type information is available by reflection have cleaner implementations. The languages with dynamic typing all have to deal with the fact that they can't get type information by reflection, and it's a diverse mess. The world is moving on, in ways that I think you're not seeing. And Python is standing still in many of those same ways. John Roth John Roth > > > -Peter From benji at benjiyork.com Mon Aug 1 12:23:37 2005 From: benji at benjiyork.com (Benji York) Date: Mon, 01 Aug 2005 12:23:37 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <1122912406.19618.333.camel@localhost.localdomain> References: <HJEIJEJFFBMMEGAENGDJMEIPCAAA.blodge@citi-us.com> <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <mailman.2532.1122901180.10512.python-list@python.org> <dclb4i$24l$1@news.sap-ag.de> <1122912406.19618.333.camel@localhost.localdomain> Message-ID: <42EE4C89.4060209@benjiyork.com> Cliff Wells wrote: > As I mentioned earlier, programming is half brains and half > tenacity. +1 QOTY (quote of the year) -- Benji York From mknoth at earthlink.net Thu Aug 11 15:41:23 2005 From: mknoth at earthlink.net (kman3048) Date: 11 Aug 2005 12:41:23 -0700 Subject: adding standard types to new type Message-ID: <1123789283.111424.6240@g49g2000cwa.googlegroups.com> I've created a new type using the API and want to add not only methods (which is easy with PyMethodDef structure) but also insert several Python standard type variables. Is there some equivalent to PyModule_AddObject - just working on the new type instead Module? Or do I have to add a dictionary to the new type and insert the new variables to the dictionary? What is the correct way? Using the new type should be: import NewTypeModule newtypevar=NewTypeModule.create() dir(newtypevar) <'method1', 'method2', 'variable1', ...> type(newtypevar.variable1) <'tuple'> Thanks a Lot! Matt From mwm at mired.org Sat Aug 6 01:35:01 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 06 Aug 2005 01:35:01 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> Message-ID: <861x57wrui.fsf@bhuda.mired.org> "John Roth" <newsgroups at jhrothjr.com> writes: > <seberino at spawar.navy.mil> wrote in message > news:1123270841.195692.21470 at g47g2000cwa.googlegroups.com... > A much better idea would be to fix the underlying > situation that makes the global statement necessary. You can't "fix" this. This code (in some python-like langauge that isn't python): x = 23 def fun(): x = 25 # Rest of code has two possible interpretations. Either the occurrence of x in fun references the global, or it references a local that shadows the global. There are reasons for wanting both behaviors. So you have to have some way to distinguish between the two, and you want it to happen per variable, not per function. The method with the fewest keywords is to have one be the default, and some keyword that triggers the other. So the only way to remove the global statement would be to have some way to mark the other interpretation, with say a "local" decleration. I thik that would be much worse than "global". For one thing, most variables would be local whether or not they are declared. Second, having an indication that you need to check module globals in the function is a better than not having that clue there. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From theller at python.net Thu Aug 25 15:11:59 2005 From: theller at python.net (Thomas Heller) Date: Thu, 25 Aug 2005 21:11:59 +0200 Subject: Unix diff command under Window. References: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> <1x4j4c2o.fsf@python.net> <0f8Pe.9409$FA3.6140@news-server.bigpond.net.au> <mailman.3530.1124995113.10512.python-list@python.org> Message-ID: <3boxvnk0.fsf@python.net> Trent Mick <trentm at ActiveState.com> writes: > [Neil Hodgson wrote] >> Thomas Heller: >> >> > Yes. There's a script in your Python distribution: >> > Tools/scripts/diff.py >> > >> > See also the docs for the 'difflib' standard library module. >> >> Is the opposite code, a Python equivalent to 'patch' available? I >> have endless trouble receiving patch files that assume one of Windows or >> Unix (in terms of path names and line end characters) which then fail to >> apply on the other platform. I would like to have a version I could hack on. > > So would I! I also have problems with the available patch.exe binaries > hanging or crashing occassionally on Windows. The only slightly related thing that I know of is the 'Perl Power Tools' Unix reconstruction project. Seems they have a 'patch' command implemented in perl: http://ppt.perl.org/commands/patch/ Thomas From bokr at oz.net Sat Aug 27 21:44:09 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 28 Aug 2005 01:44:09 GMT Subject: list insertion References: <mailman.3444.1124855904.10512.python-list@python.org> Message-ID: <431116b4.2601142154@news.oz.net> On Tue, 23 Aug 2005 20:58:11 -0700, Randy Bush <randy at psg.com> wrote: >i am trying to insert into a singly linked list > > hold = self.next > self.next = DaClass(value) > self.next.next = hold > >but i suspect (from print statement insertions) that the result >is not as i expect. as the concept and code should be very >common, as i am too old for pride, i thought i would ask. > I think you're fine. Here's some possible context for your code: >>> class DaClass(object): ... def __init__(self, value): ... self.value = value ... self.next = None ... def values(self): ... while True: ... yield self.value ... if self.next is None: break ... self = self.next ... def insert(self, value): ... hold = self.next ... self.next = DaClass(value) ... self.next.next = hold ... return self ... def __repr__(self): ... return '<DaClass %s>'%(' -> '.join(map(repr, self.values()))) ... ... >>> sll = DaClass(1) >>> sll <DaClass 1> >>> sll.insert(2) <DaClass 1 -> 2> >>> sll <DaClass 1 -> 2> >>> sll.insert('a') <DaClass 1 -> 'a' -> 2> >>> sll.next <DaClass 'a' -> 2> >>> sll.next.insert('b') <DaClass 'a' -> 'b' -> 2> >>> sll <DaClass 1 -> 'a' -> 'b' -> 2> Regards, Bengt Richter From mwm at mired.org Thu Aug 4 01:04:34 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 04 Aug 2005 01:04:34 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <mailman.2383.1122649616.10512.python-list@python.org> <dcdi24$7n2$1@gemini.csx.cam.ac.uk> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <mailman.2385.1122656505.10512.python-list@python.org> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <mailman.2438.1122791233.10512.python-list@python.org> <8664uqhkfj.fsf@bhuda.mired.org> <mailman.2470.1122837924.10512.python-list@python.org> <86hde9f172.fsf@bhuda.mired.org> <mailman.2594.1122956547.10512.python-list@python.org> <86r7dbeuvq.fsf@bhuda.mired.org> <mailman.2649.1123035056.10512.python-list@python.org> <86r7db16a9.fsf@bhuda.mired.org> <mailman.2685.1123101998.10512.python-list@python.org> Message-ID: <86irym1ee5.fsf@bhuda.mired.org> Cliff Wells <cliff at develix.com> writes: > On Wed, 2005-08-03 at 09:47 -0400, Mike Meyer wrote: >> Cliff Wells <cliff at develix.com> writes: >> > On Tue, 2005-08-02 at 20:17 -0400, Mike Meyer wrote: >> >> Um - you're not answering the question I asked. I asked "What app do I >> >> use to bundle my applications for Unix, ala py2exe (or whatever it is) >> >> for Windows?" You're telling me how to install wxPython on those >> >> platforms. >> >> I know how to install wxPython. What I want to know is how to build an >> >> application bundle for all those Unix systems for a Python app I use >> >> that includes wxPython - or any other third party libraries I may be >> >> using. >> > >> > Sorry, I assumed you'd know about distutils: >> >> Cliff, please quit being an ass. You keep assuming that because some >> tool isn't the answer to my question that I don't know about >> it. That's simply rude. It would be *much* more polite to ask "What's >> wrong with distutils" rather than saying "So you don't know about >> distutils." > > Since you said "please". I'll try to forget about "the wonders of X" > comment you made that I found just as rude. I made one comment that you found rude - which wasn't intended to be - and you feel that's justification for intentionally insulting me in pretty much every reply? >> > http://www.python.org/doc/current/dist/ >> > http://www.python.org/doc/current/dist/built-dist.html >> > >> > distutils can go so far as to build an rpm for you, but you'll need to >> > package things like .debs yourself. >> >> I've very familiar with distutils. It doesn't do what I asked for, in >> that it only bundles up *my* code. It doesn't bundle the things I >> depend on the way py2exe does. It's patently *not* the answer to the >> question I asked. > > It can. It isn't terrifically easy, but distutils can be used to > package up 3rd party libraries, including binary libs. It can, in fact, > package up any file you so desire. So can tar. That doesn't make it a solution to the problem, either. >> I'm surprised you haven't mentioned eggs yet. Those work across all >> the platforms I named. Of course, they aren't the answer to my >> question either, because, like PRMs et al, they only reference >> external dependencies, they don't include them. > > While this describes the general use case of RPM, you can most certainly > include external dependencies. You do it by not making them external. > If you need wxPython included with your app, you can build wxPython as a > subtree of your project and package it that way. While wasteful of > space, it is also the only sure way to make sure that your app has the > correct version and all needed dependencies. This is how py2exe does it > on Windows and py2app does it on Mac (they just make it automatic). Right. Let's go back to the original question: What's the app I use on Unix that acts like py2exe on Windows and py2app on Unix? Any archiving system can be coerced into collecting all the parts together. None of them do it automatically. That automatically makes them *not* an answer to the question. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From http Fri Aug 19 05:16:57 2005 From: http (Paul Rubin) Date: 19 Aug 2005 02:16:57 -0700 Subject: global interpreter lock References: <mailman.3258.1124442762.10512.python-list@python.org> Message-ID: <7xwtmi70c6.fsf@ruckus.brouhaha.com> km <km at mrna.tn.nic.in> writes: > is true parallelism possible in python ? or atleast in the coming versions ? > is global interpreter lock a bane in this context ? http://poshmodule.sf.net From lycka at carmen.se Fri Aug 5 09:51:19 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 05 Aug 2005 15:51:19 +0200 Subject: time.clock() or time.time() In-Reply-To: <mailman.2670.1123085296.10512.python-list@python.org> References: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> <mailman.2624.1122999901.10512.python-list@python.org> <dco8r5$pk3$1@wake.carmen.se> <mailman.2670.1123085296.10512.python-list@python.org> Message-ID: <dcvqsn$t1f$1@wake.carmen.se> Shane Hathaway wrote: > However, isn't this thoroughly un-Pythonic? No wonder people have to > ask. Only if they've never read K&R, and I thought that was compulsory! ;^) There are a few python libraries, such as time and math, that are basically just thin wrappers around standard C libraries. In some cases, they are complemented with more modern libraries, such as datetime. You might argue on how pythonic (or useful, or beginner friendly) they are, but they cost very little to maintain across platforms. It's important to keep the maintenance costs down for any project, certainly for a project such as Python, and as far as I know, there is no cross platform standard API to access CPU time, so a time.cputime() function would require a lot of work to maintain, and I don't know if anyone really had a strong need for it. There is a benefit to maintain (standard or not) API's that programmers have experience from when programming in other languages. Of course, I think it's a good thing to properly adapt API's to Python ways of working. I.e. if a C++ library returning an iterator is wrapped, I want to be able to do... for item in container: print item ...rather than... it = container.start() while it != container.end(): item = it.deref() print item Still, it's often a Good Thing if a Python API is as similar as possible to e.g. a C++ API that it wraps. One of the great aspects of Python is that it's a good team player. It doesn't try to create a world of its own, like Smalltalk and ABC does, but blends in well in a mixed language environment. We work extensively with a mix of C++ and Python (as well as some other languages) here at Carmen, and it would be painful if I had to remember two different API's for each library that I access from both C++ and Python. From g.belyh at grsu.by Thu Aug 4 11:13:33 2005 From: g.belyh at grsu.by (Belyh G.P.) Date: Thu, 04 Aug 2005 18:13:33 +0300 Subject: installing python2.4.1 In-Reply-To: <42F2300F.2050007@grsu.by> References: <42F22F51.8030506@grsu.by> <42F2300F.2050007@grsu.by> Message-ID: <42F2309D.2000708@grsu.by> Belyh G.P. wrote: >Belyh G.P. wrote: > >OS - Debian GNU/Linux 3.1 > > Sorry forgor "Hi all!" :) From nochiel at gmail.com Mon Aug 1 13:43:51 2005 From: nochiel at gmail.com (yoda) Date: 1 Aug 2005 10:43:51 -0700 Subject: Listing Processes Running on Remote Machines In-Reply-To: <mailman.2000.1121952732.10512.python-list@python.org> References: <mailman.2000.1121952732.10512.python-list@python.org> Message-ID: <1122918231.666265.39990@g43g2000cwa.googlegroups.com> Thanks. I'll definitely look into it. I actually got distracted while investigating Pyro(http://pyro.sourceforge.net/) to see if I could achieve the same results... It seems like a lighter weight more accessible solution than STAF (at least for my immediate needs).. I'll update you with my progress... From ms at cerenity.org Wed Aug 3 16:16:37 2005 From: ms at cerenity.org (Michael Sparks) Date: Wed, 03 Aug 2005 22:16:37 +0200 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> <slrndeu5ia.d1.zen19725@cabalamat.somewhere> <dcnisi$ks6$1@nntp0.reith.bbc.co.uk> <slrndf1b11.129.zen19725@cabalamat.somewhere> <dcqrtt$rqj$1@nntp0.reith.bbc.co.uk> <slrndf24au.2je.zen19725@cabalamat.somewhere> Message-ID: <42f1343b$0$3473$ed2619ec@ptn-nntp-reader03.plus.net> phil hunt wrote: > On Wed, 03 Aug 2005 16:57:34 +0100, Michael Sparks <michaels at rd.bbc.co.uk> wrote: >>> Is the audience programmers or >>> less technical people? A project that allows non-technical people >>> to build complex network applications is an ambitious one, but not ... >>It's a little ambitious at this stage, yes. > But it couldbe there eventually? Could? Yes. Will? Can't say. I can agree it would be nice, and given time/resources (or someone sufficiently interested externally) then it may happen. (IMO there's no real reason that it couldn't happen aside from time/effort/resources) >>> What sort of servers and clients? >>Whatever you feel like. If you want a server to split and serve audio, >>you could do that. > This is streaming audio, right? For non-streaming I can just use an > ftp or http server. There's more to network servers and clients than just audio & video, or unidirectional download. For example the visualisation/introspection tool is an example of a client server system. The server is the visualisation tool. It listens on a specified port waiting for a connection. The client connects and sends data to it about the internal structure, and the server displays this. >>>> * Quickly build Multicast based network servers and clients >>> Serving what? Could I use it, for example, to build an n-player >>> encrypted VoIP server to allow people to do conference calls over >>> the Internet? >> >>You could do that probably. (Though we don't have a component >>for audio capture (though a read file adaptor reading from /dev/audio >>might work depending on your platform I suppose) and audio >>encoding at the moment, so those would probably be the core >>components to integrate. > > That's a slightly worrying answer for me, worrying because it seems > I've misunderstood the nature of the project. I assumed that > components for audio capture, and related activities, would be at > the heart of the project. *Our* main interest, at the moment, is in /delivery/ of content. Dealing with capture would be largely re-inventing wheels before we know whether the framework is a suitable framework. We are looking at making it possible to use pymedia for dealing with capture/encoding/decoding. There's a number of things along the way we need to deal with this, but we're not starting from the perspective of capture. (After all for capture we can generally look at using dedicated encoder hardware that will often spit out it's encoded information in the form of a network connection. As a result capture and encoding hasn't been a priority as yet. Sometimes looking into a project from the outside I can appreciate that certain decisions might look strange, but consider that you don't need to worry about capture in order >>> (I mean proper encryption here, the sort GCHQ or the NSA can't break) >> >>I'd be impressed if that could be written, using anything really. (Can't >>implies never) > > What -- good encryption? That's pretty much a well-known technique > these days (unless the NSA has some *very* advanced hardware in > their basement, which I strongly suspect they don't). You said *can't*. That says to me cannot ever be broken. If you have a large number of listeners, as your statement implied, that implies decryptable by many listeners - you then just need one compromised listener (essentially you're asking for the equivalent of implementing a DRM system that the NSA couldn't break...). If you can provide me with a library that you can guarantee that it will satisfy the following properties: encoded = F(data) and a piece of client code that can do this: decoded = G(encoded) Then yes, that can be wrapped. That's trivial in fact: ---(start)--- from magic import unbreakable_encryption class encoder(component): def __init__(self, **args): self.encoder = unbreakable_encryption.encoder(**args) def main(self): while 1: if self.dataReady("inbox"): data = self.recv("inbox") encoded = self.encoder.encode(data) self.send(encoded, "outbox") yield 1 class decoder(component): def __init__(self, **args): self.decoder = unbreakable_encryption.decoder(**args) def main(self): while 1: if self.dataReady("inbox"): data = self.recv("inbox") decoded = self.decoder.decode(data) self.send(decoded, "outbox") yield 1 ---(end)--- If you believe you can implement F&G for general use such that F&G can //never// be decrypted by anyone other than authorised recipients, I suggest you cease this conversation - you have some highly marketable technology. >>>>The basic underlying metaphor of a component us like an office worker >>>>with inboxes and outboxes, with deliveries occuring between desks, >> >>> That metaphor brings up an image (at least to me) that the sorts of >>> data that can be communicated are things like documents, >>> spreadsheets, business graphs, memos. >> >>They could indeed. The underlying framework doesn't differentiate >>between data nor have any realtime aspect embedded in the system >>at present. Just because we're focussing on systems that have a realtime >>element and are multimedia based, this does not mean the system is >>limited to that. > > Again, this makes me think I've misunderstood the project. Realtime systems are a subset of all systems that are interesting in terms of network delivery & multimedia systems. Realtime scheduling is a well known area and if/when this becomes an issue, we'll look at adding it into the mix. The real problem is dealing with concurrency and making it simple to work with. Making realtime concurrent systems easy to work with strikes me as running before you can walk. (Network systems are naturally concurrent, so if you're aiming to make network systems easy to build you're really talking about making concurrent systems easy to build.) >>> OK, I get the straming part of it. But what asbout non-streaming >>> stuff? What other protocols are necessary? >> >>One example is peer to peer mesh setup. People normally >>think of P2P as a distribution mechanism. However, the underlying >>approach also very good at setting up communications meshes. > > When you say a mesh, what do you mean? I mean a mesh. (see below) >>This could be of use in many areas, such as GRID based systems >>for distributed rendering, application layer multicast, and network >>multicast island joining. > Unpack, please. They're all big systems, all of which utilise networks of collaborating systems for different purposes. Grid starting point: * http://en.wikipedia.org/wiki/Grid_computing *short* introduction to application level multicast (has many names, including overlay multicast): * http://www.mnlab.cs.depaul.edu/seminar/fall2002/Overcast.pdf * Also puts the term "mesh" in context. Multicast island joining is a special case and is exactly what it says - joining multicast islands together. >>Due to the illegal /uses/ of P2P, much work in this area is difficult to >>reuse due to defensive coding. > > Oh. Could you give an example? How many RFCs have you seen documenting the protocols used by (say) Napster, Bit Torrent, Gnutella, Limewire, Freenet? The legitimate uses of Bit Torrent for example tend to get ignored by certain large companies when trying to shut down systems. >>We also have to be able to demonstrate system to other people >>inside the BBC in a way non-technical people understand. That means >>showing structures in a friendly dynamic way, showing pictures, >>playing sounds (hence visualisation - looking inside running systems). > > Visualisation, if done properly, ought to be useful to technical > people too. It is (as mention on the page describing the visualisation tool). Regards, Michael. From gene.tani at gmail.com Mon Aug 1 17:29:48 2005 From: gene.tani at gmail.com (gene tani) Date: 1 Aug 2005 14:29:48 -0700 Subject: Newer than a Newbe In-Reply-To: <EiwHe.12576$kc6.5400@trnddc03> References: <EiwHe.12576$kc6.5400@trnddc03> Message-ID: <1122931788.663622.284600@g43g2000cwa.googlegroups.com> http://www.python.org/cgi-bin/moinmoin/PythonHosting From nyamatongwe+thunder at gmail.com Sun Aug 7 07:23:52 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 07 Aug 2005 11:23:52 GMT Subject: Python -- (just) a successful experiment? In-Reply-To: <7xoe8a6q24.fsf@ruckus.brouhaha.com> References: <20050807005406.1217660123.whereU@now.com> <mailman.2810.1123403537.10512.python-list@python.org> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> Message-ID: <cbmJe.74486$oJ.69907@news-server.bigpond.net.au> Paul Rubin: > I haven't used Ruby on Rails but from the description I saw, its distro > includes everything needed, which I assume includes Ruby itself. Whatever led you to assume that? * Install Ruby * Install RubyGems * Invoke gem to install rails http://download.rubyonrails.com/ Neil From stephan.diehl at gmx.net Tue Aug 30 02:55:06 2005 From: stephan.diehl at gmx.net (Stephan Diehl) Date: Tue, 30 Aug 2005 08:55:06 +0200 Subject: python and ajax References: <mailman.141.1125342298.8229.python-list@python.org> Message-ID: <pan.2005.08.30.06.55.06.42486@gmx.net> On Mon, 29 Aug 2005 12:04:46 -0700, Steve Young wrote: > Hi, I was wondering if anybody knew of any good > tutorial/example of AJAX/xmlhttprequest in python. > Thanks. > > -Steve As all the others have said already, AJAX has nothing to do with python, but everything with JavaScript. You might want to check out MochiKit (http://mochikit.com), a lightweight JavaScript library written by Bob Ippolito. Bob did a very good job in turning programming JS into a more python like experience. - stephan From fakeaddress at nowhere.org Fri Aug 19 12:33:21 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 19 Aug 2005 16:33:21 GMT Subject: __del__ pattern? In-Reply-To: <1124234979.494554.283670@g44g2000cwa.googlegroups.com> References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> <1124232686.973363.317640@z14g2000cwz.googlegroups.com> <1124234979.494554.283670@g44g2000cwa.googlegroups.com> Message-ID: <lRnNe.3189$Z87.2981@newssvr14.news.prodigy.com> BranoZ wrote: > bryanjugglercryptographer at yahoo.com wrote: > >>For a reasonably portable solution, leave the lock file open. >>On most systems, you cannot delete an open file,.. > > On most UNIXes, you can delete an open file. > Even flock-ed. This is BTW also an hack around flock. Yes, sorry; my bad. > Use file that is writeable by A and B in a directory that is > writeable only by root. Is that portable? What's the sequence the program should try? -- --Bryan From lycka at carmen.se Mon Aug 15 13:18:02 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 15 Aug 2005 19:18:02 +0200 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: <mailman.3099.1124117654.10512.python-list@python.org> References: <ddj5qv$enq$1@lairds.us> <ddq94i$cho$1@news.doit.wisc.edu> <mailman.3099.1124117654.10512.python-list@python.org> Message-ID: <ddqioa$cmo$1@wake.carmen.se> Simon Brunning wrote: > On 8/15/05, Rocco Moretti <roccomoretti at hotpop.com> wrote: > >>Which lead me to the question - what's the difference between a library >>and a framework? > > > If you call its code, it's a library. If it calls yours, it's a framework. Erh, it's not quite that simple. I don't know of any frameworks where you never call code that's part of the framework. I suppose there are libraries that e.g. use callbacks without being frameworks. Roughly, Simon is right though. Another way of saying it is that when you don't use a framework, you write the main function (often a main loop) of the application, you define the program's structure, and you might use one or more libraries for certain functions in your code. A framework, on the other hand, will provide the main function (e.g. an event loop) and the basic structure of the application, and you fill in the missing pieces with your code, to make the program do what you desire. You might still use one or more libraries in your framework- based app. You're not likely to use more than one framework at the same time though. That would often be like trying to sit in two different cars at the same time. Besides that, people usually mean big thingies when they talk about frameworks. For instance, Python's SocketServer and similar classes share a lot of features with frameworks. These base classes implement the basic logic flow of the applications you use them in. Just like in a framework, you just fill in the missing pieces by implementing some methods in your subclasses. Still, I never heard anyone call these classes frameworks. Maybe they're to small and simple to qualify... (GoF [ISBN:0201633612] calls this Design Pattern "Template Method", but these server classes aren't just instances of that pattern, you also use their main loops, so they *are* really tiny frameworks.) Examples of popular Python frameworks are Zope and Twisted. Frameworks cause some problems: * It's non-trivial to use several frameworks at the same time, since frameworks typically own event loops and mandate program structures. It's not impossible though, e.g. Twisted can use a number of different event loops (e.g. those of GTK+, Cocoa and Qt). * You typically need to learn a lot about a framework before you can use it well. It's much more easy to approach a library piece by piece. This leads to a steep learning curve. On the other hand, a well written framework should allow you to write code which is useful outside that framework, and in other frameworks. Using frameworks should not prevent you from writing generic and reusable code. If it does (more than the average library), there is something wrong with framework, or with the way you use it. I think Andy is wrong there. He might not be wrong in practice when it concerns certain frameworks. E.g. Zope Products are (as far as I understand) only useful in Zope, but on the other hand, I guess that most Zope Products would be best written as a generic library with no Zopeisms in it, and a Zope wrapper outside that. (I know some database adapters are written like that.) I also think that it can be great fun to write Python code using a framework. If a framework helps me focus on implementing the logic I need to create, and can take care of low level junk, and also makes my app more flexible, I'll enjoy that, even if I am somewhat restricted in how I code. After all, if you write a big app, and don't use a framework written by someone else, you will basically end up writing your own framework...and that will probably restrain you as much as a framework written by others. In general, code is more reusable if we can avoid reliance on third party code, whether it's libraries or frameworks, but when there are such dependencies, framework dependencies typically cause bigger sharing problems than library dependencies. Of course, it's better if we only depend on something more abstract, that can be implemented in various ways. Both Python's duck typing and concepts such as interfaces and adapters can help us there. It's interesting that Twisted has started to use Zope's interfaces. We'll see if this will lead to python components that are useful in both Zope, Twisted and in future apps and frameworks that use those interfaces. I'm just starting to use Twisted myself, even if I started to look at it previously. I never really liked Zope, but I have some hopes for Zope 3. I guess I might be much more enthusiatic, or much more pessimistic about frameworks on a few months (or sooner)... So far, Twisted looks fun. It has a lot of cool features, and I think it will help me make the application I'm about to write just as flexible as it needs to be, without too much headache. From python-url at phaseit.net Tue Aug 30 07:39:01 2005 From: python-url at phaseit.net ( Diez B.Roggisch ) Date: Tue, 30 Aug 2005 11:39:01 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 30) Message-ID: <mailman.173.1125404540.8229.python-announce-list@python.org> QOTW: "If I wanted to write five lines instead of one everywhere in a Python program, I'd use Java." -- Paul Rubin http://groups.google.com/group/comp.lang.python/msg/6fac4f3022acd1fa?hl=de& "i think less buggy code is not the main concern for all." -- km http://groups.google.com/group/comp.lang.python/msg/db5acbd68447ae33?hl=de& Bryan Olson discovers inconsistencies in the slice implementation that lead to a new slicing PEP and a lively discussion about string index semantics: http://groups.google.com/group/comp.lang.python/browse_frm/thread/402d770b6f503c27/66014427182265b9#66014427182265b9 Mark Dickinson finds strange runtime differences depending on the existence of dummy variables - the riddle is solved by Stelios Xanthakis who points out that min() can behave non-deterministically when the compared entities have no well-defined comparision sematics: http://groups.google.com/group/comp.lang.python/browse_frm/thread/2ff00f12499233e5/8b658bc804020f08#8b658bc804020f08 Russell E. Owen tries to get unique ids for bound methods - and discovers that id() can return the same value for two different bound methods. The solution is to keep a reference to the bound method, thus the id() won't be reused - which tkinters _register does: http://groups.google.com/group/comp.lang.python/browse_frm/thread/143a9000bdc9847e/5b2d07b8e5470583#5b2d07b8e5470583 Ramza Brown wants a small footprint python distro - and gets answers which shed light on the subject from varying perspectives: http://groups.google.com/group/comp.lang.python/browse_frm/thread/18e8f91c8e915c50/da5c5a740f7afe87#da5c5a740f7afe87 Diego Andr??s Sanabria wonders about the apparent lack of a binary tree data type in python: http://groups.google.com/group/comp.lang.python/browse_frm/thread/fb307dbdf7069b30/a0f94ea4a27ddb7c#a0f94ea4a27ddb7c sysfault wants enlightenment about decorators and metaclasses - and hopefully now has it: http://groups.google.com/group/comp.lang.python/browse_frm/thread/6bcb4d9ae934ac64/1060a20aaaf4b89a#1060a20aaaf4b89a Roland Hedberg wants to speed up his client/server implementation - and gets deep insight into the TCP/IP protocol stacks: http://groups.google.com/group/comp.lang.python/browse_frm/thread/507a711c61df7ad5/d6e871a24d8506a6#d6e871a24d8506a6 As often before, Jp Calderone eloquently illustrates the expressiveness Twisted affords those writing multitasking network servers: http://groups.google.com/group/comp.lang.python/browse_thread/thread/dce3370299af324e/ max(01)* needs help on piping commands in python: http://groups.google.com/group/comp.lang.python/browse_frm/thread/5cbe3126675ac0e0/1b3d6b36341e8cad#1b3d6b36341e8cad Pythoneers are nearly unanimous: when you need dynamic names for your variables ... you're probably doing something wrong. Python is plenty dynamic, though, so of course it's *possible*: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d9a99f17e0cad8f2/ Damien Elmes needs advice dealing with locales: http://groups.google.com/group/comp.lang.python/browse_frm/thread/8f44319aee701f71/ce6194ba78934818#ce6194ba78934818 KM compares apples with oranges - and gets told so: http://groups.google.com/group/comp.lang.python/browse_frm/thread/d1c6888eaec9930f/b444a3ec71e0e2b3#b444a3ec71e0e2b3 42 thinks he has new ideas about restricting python's execution - it turns out to be old news again, though: http://groups.google.com/group/comp.lang.python/browse_frm/thread/89e733d60380741b/4831ed5d84026549#4831ed5d84026549 ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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. del.icio.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/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 <Python-URL at phaseit.net> should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask <claird at phaseit.net> 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 fakeaddress at nowhere.org Wed Aug 24 22:50:22 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 25 Aug 2005 02:50:22 GMT Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: <mailman.3477.1124910784.10512.python-list@python.org> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <m2ek8zqkax.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <m2mznf1zg4.fsf@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk> <wMOdnW4N1cAeAZneRVn-2g@comcast.com> <VoOdnZAkbdDgO5neRVn-hg@comcast.com> <EpLNe.824$GV7.650@newssvr25.news.prodigy.net> <7x7jeflj8d.fsf@ruckus.brouhaha.com> <QB_Oe.315$5k1.0@newssvr27.news.prodigy.net> <mailman.3477.1124910784.10512.python-list@python.org> Message-ID: <OlaPe.4050$Z87.1368@newssvr14.news.prodigy.com> Robert Kern wrote: > By "+1" he means, "I like it." He's not correcting you. Ah, O.K. Thanks. -- --Bryan From john at castleamber.com Fri Aug 26 08:49:42 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 12:49:42 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <Pine.SOL.4.58.0508250932360.5888@zen.rite-group.com> <qOmPe.2899$u_6.1802@newssvr17.news.prodigy.com> <m3ll2qx73f.fsf@invalid.address> <l7oPe.1736$yo7.860@newssvr23.news.prodigy.net> <dem3hh$o9h$1@news1.xnet.hr> <QJxPe.8924$A%1.6685@newssvr13.news.prodigy.com> <demofh$tmv$1@news1.xnet.hr> <Xns96BE408D2E9D1castleamber@130.133.1.4> <3n8cqbFb539U3@individual.net> Message-ID: <Xns96BE4F7F6D13castleamber@130.133.1.4> usenet at isbd.co.uk wrote: > In comp.lang.perl.misc John Bokma <john at castleamber.com> wrote: >> >> > They >> > have no downsides I can possibly think of >> >> Some people never use them, and hence they use memory and add risks. >> > So they can choose a newsreader that doesn't have these facilities, no > extra memory use, no risk. That's besides the point, the point was that extra functionality has no downsides. They have. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From sp1d3rx at gmail.com Thu Aug 25 18:23:02 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 25 Aug 2005 15:23:02 -0700 Subject: pickle.load not working? In-Reply-To: <pan.2005.08.19.23.06.47.957706@gmx.net> References: <1123884180.348659.247960@z14g2000cwz.googlegroups.com> <pan.2005.08.14.20.04.04.603094@gmx.net> <1124379754.569717.25810@f14g2000cwb.googlegroups.com> <pan.2005.08.19.23.06.47.957706@gmx.net> Message-ID: <1125008582.733246.189580@g49g2000cwa.googlegroups.com> I get it, I missed the little parintheses or however you spell it. () . From bokr at oz.net Wed Aug 24 06:39:40 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 24 Aug 2005 10:39:40 GMT Subject: Anyone recognize this numeric storage format - similar to "float", but not quite References: <1124849085.656718.97720@g43g2000cwa.googlegroups.com> <mailman.3457.1124871142.10512.python-list@python.org> Message-ID: <430c4cb0.2287282378@news.oz.net> On Wed, 24 Aug 2005 04:10:07 -0400, "Terry Reedy" <tjreedy at udel.edu> wrote: ><geskerrett at hotmail.com> wrote in message >news:1124849085.656718.97720 at g43g2000cwa.googlegroups.com... >> We are working on a project to decipher a record structure of an old >> accounting system that originates from the late80's mid-90's. >> We have come across a number format that appears to be a "float" but >> doesn't match any of the more standard implementations. >> so we are hoping this is a recognizable number storage format with an >> identifiable name AND pre-built conversion method >> similiar to the "struct" modules available in python. [...] <moved from top-posted position> >This appears to be a repost, perhaps not by the op but due to a glitch >somewhere, of a question posted about a month ago and answered. > </moved> UIAM the more or less recent original you are thinking of turned out to be straight IEEE double format, and I think this is not, though I think it looks like one that was answered (by me ;-) quite a while ago (Dec 1 2003). Regards, Bengt Richter From devlai at gmail.com Fri Aug 5 02:30:09 2005 From: devlai at gmail.com (Devan L) Date: 4 Aug 2005 23:30:09 -0700 Subject: Newbie Program In-Reply-To: <mailman.2736.1123218601.10512.python-list@python.org> References: <mailman.2736.1123218601.10512.python-list@python.org> Message-ID: <1123223409.082751.156860@g49g2000cwa.googlegroups.com> Eric wrote: > I am reading a book on Python and ran across and exercise that I just > can't seem to figure out. Its pretty simple, but I just can't get > past a certain point. > > The task is to create a program that flips a coin 100 times and keeps > track of the total of heads and tails which is printed to the screen. > > My plan was to use import random with a range of 2 and use a > conditional statement to count to 100. The problem I am encountering > is how do I keep track of the totals for heads and tails? > > Any suggestions would be appreciated. Keep in mind I am very new to > Python so there may be a more sophisticated way, but I am just trying > to use what the book has taught so far. > > Thanks, > Eric Someone else read the same book, I suppose. http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/87fcaf8ffbbd69e7/c7ff2d2b5b0d776d?q=coin+flip&rnum=3#c7ff2d2b5b0d776d From rkern at ucsd.edu Wed Aug 24 19:36:52 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 24 Aug 2005 16:36:52 -0700 Subject: use SciPy with Python 2.4.1? In-Reply-To: <877jebjdim.fsf@peds-pc311.bsd.uchicago.edu> References: <1124895877.968739.323680@o13g2000cwo.googlegroups.com> <mailman.3478.1124911287.10512.python-list@python.org> <877jebjdim.fsf@peds-pc311.bsd.uchicago.edu> Message-ID: <dej0ak$6tt$1@sea.gmane.org> John Hunter wrote: >>>>>>"Robert" == Robert Kern <rkern at ucsd.edu> writes: > > > Robert> beliavsky at aol.com wrote: > >> Is SciPy usable with Python 2.4.1? At > >> http://www.scipy.org/download/ it says that 2.3.3 is > >> recommended, and I don't see a binary for 2.4.1. > > Robert> It is usable with Python 2.4.1 on Linux and OS X at > Robert> least. IIRC, mingw-compiled extensions don't work with the > Robert> standard Python 2.4.1 interpreter, which is, I believe, > Robert> the largest holdup for Windows binaries for 2.4.1. > > I routinely compile matplotlib with mingw for 2.4 and haven't had any > problems. If I recall correctly, a trivial patch for distutils is > needed which is described at > http://mail.python.org/pipermail/python-list/2004-December/254826.html Fantastic! <updating internal database ...> -- 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 sjdevnull at yahoo.com Sun Aug 21 23:28:31 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 21 Aug 2005 20:28:31 -0700 Subject: As Simple As Possible? In-Reply-To: <slrndgdrm2.r2g.jgrahn-nntq@frailea.sa.invalid> References: <1124338318.133726.304370@g49g2000cwa.googlegroups.com> <7677804.UTi409LUyN@knode.kde> <Pine.LNX.4.62.0508181502210.28869@urchin.earth.li> <slrndgdrm2.r2g.jgrahn-nntq@frailea.sa.invalid> Message-ID: <1124681310.978942.71880@z14g2000cwz.googlegroups.com> Jorgen Grahn wrote: > More importantly, I think: it's not polite for a programming language to > make it hard to communicate with the rest of your environment. > > Java pissed me off when I looked at it back in the 1990s, because I was on > Unix, and the language would barely give me access to the command line > options, had no getopt-style parser, etc. "No, you're supposed to write the > kinds of programs that /we/ want you to write!" > > Python, in contrast, happily provides all that (and enough, it seems, to > make Windows and web server people reasonably happy too). The ideological > stuff ends at the source code level. I always phrased it as "Java is platform independent; Python is platform agnostic". The failure of Java to provide access to even such simple niceties as select() (which is available on all major platforms in some form) because it doesn't fit the Java Way (TM) was pretty frustrating (they've fixed that example since, but analagous facilities are still lacking). Despite reject TMTOOTDI, Python doesn't have any interest in mandating a Pure Python solution done using one true philosophy of software design. From luismgz at gmail.com Fri Aug 19 19:17:54 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 19 Aug 2005 16:17:54 -0700 Subject: Karrigell tutorial published Message-ID: <1124493474.020801.70040@g14g2000cwa.googlegroups.com> Karrigell has new tutorial here: http://karrigell.sourceforge.net/en/tutorial.html For those who don't know what Karrigell is, I'd just say that it is the most pythonic, simple, fun, straightforward and full-featured web framework available today. Check it out! http://karrigell.sourceforge.net/ From u.hobelmann at web.de Sat Aug 27 05:27:00 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Sat, 27 Aug 2005 11:27:00 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <86ek8gw6js.fsf@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <gaGOe.213$5k1.200@newssvr27.news.prodigy.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <XClPe.899$dw4.492@newssvr29.news.prodigy.net> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> <Xns96BE4025C835Dcastleamber@130.133.1.4> <3n8di6Fbhg7U2@individual.net> <Xns96BE4F60DC591castleamber@130.133.1.4> <3n8sqaFch6kU1@individual.net> <86ek8gw6js.fsf@bhuda.mired.org> Message-ID: <3napv5Fl7hrU2@individual.net> Mike Meyer wrote: > Try turning off JavaScript (I assume you don't because you didn't > complain about it). Most of the sites on the web that use it don't > even use the NOSCRIPT tag to notify you that you have to turn the > things on - much less use it to do something useful. I had JS off for a long time, but now so many websites expect it, and even make browsing more convenient, that I grudgingly accepted it. ;) > Sturgeon's law applies to web sites, just like it does to everything > else. Yep. Filtering is the future in the overloaded world. -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From uval at rz.uni-karlsruhe.de Wed Aug 10 16:17:54 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-15?Q?Daniel_Sch=FCle?=) Date: Wed, 10 Aug 2005 22:17:54 +0200 Subject: providing arguments to base.__init__ Message-ID: <dddntt$7m9$1@news2.rz.uni-karlsruhe.de> Hello Ng, I was playing around with pymedia module and I succeeded when I used complementation instead of inheritance .. but then I was forced to wrap simple methods of sound.Output like pause/unpause/stop. It works, but seems to me unnecessary .. and I would like to grasp why the code below doesn't work *************************************** import threading, wave, sys, import pymedia.audio.sound as sound, tkFileDialog class wavePlayer(threading.Thread, sound.Output): def __init__(self, filename = None): if filename == None: filename = tkFileDialog.askopenfilename() try: self.wav = wave.open(filename) except: print "something went wrong" sys.exit(1) freq, nchannels, format = self.wav.getframerate(), self.wav.getnchannels(), sound.AFMT_S16_LE sound.Output.__init__(self, freq, nchannels, format) threading.Thread.__init__(self) *************************************** >>>p = wavePlayer.wavePlayer() Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: Output() takes at least 3 arguments (0 given) can somebody explain why this happens? I tried to construct more simple example but there it works fine, here is it >>> class base1: ... def __init__(self): ... self.x = [] ... print "base1" ... def __del__(self): ... print "~base1" ... >>> class base2: ... def __init__(self, a, b): ... self.x = a * b ... print "base2" ... def __del__(self): ... print "~base2" ... >>> class derived(base1, base2): ... def __init__(self): ... print "derived" ... base1.__init__(self) ... base2.__init__(self, 5, 7) ... def __del__(self): ... print "~derived" ... >>> d = derived() derived base1 base2 >>> dir(d) ['__del__', '__doc__', '__init__', '__module__', 'x'] >>> d.x 35 >>> >>> del d ~derived >>> >>> base2.__init__ is called in the same way sound.Output.__init__ is called both get multiple arguments one more curiosity, why doesn't del d, call destructors of base classes? Thanks for you answears -- Daniel From n00m at narod.ru Tue Aug 30 12:26:23 2005 From: n00m at narod.ru (n00m) Date: 30 Aug 2005 09:26:23 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: <1125414600.375677.201060@z14g2000cwz.googlegroups.com> References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125414600.375677.201060@z14g2000cwz.googlegroups.com> Message-ID: <1125419183.302634.12480@g47g2000cwa.googlegroups.com> Thank you, guys, for your replies! Now it works! From opengeometry at yahoo.ca Mon Aug 29 16:28:46 2005 From: opengeometry at yahoo.ca (William Park) Date: Mon, 29 Aug 2005 16:28:46 -0400 Subject: python xml DOM? pulldom? SAX? References: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> Message-ID: <3d3ea$43136ffe$d8fea5bf$16840@PRIMUS.CA> jog <jo at johannageiss.de> wrote: > Hi, > I want to get text out of some nodes of a huge xml file (1,5 GB). The > architecture of the xml file is something like this > <parent> > <page> > <title>bla > > > > blablabla > > > > > .... > > I want to combine the text out of page:title and page:revision:text for > every single page element. One by one I want to index these combined > texts (so for each page one index) > What is the most efficient API for that?: SAX ( I don?t thonk so) DOM > or pulldom? > Or should I just use Xpath somehow. > I don`t want to do anything else with his xml file afterwards. > I hope someone will understand me..... > Thank you very much > Jog I would use Expat interface from Python, Awk, or even Bash shell. I'm most familiar with shell interface to Expat, which would go something like start() # Usage: start tag att=value ... { case $1 in page) unset title text ;; esac } data() # Usage: data text { case ${XML_TAG_STACK[0]}.${XML_TAG_STACK[1]}.${XML_TAG_STACK[2]} in title.page.*) title=$1 ;; text.revision.page) text=$1 ;; esac } end() # Usage: end tag { case $1 in page) echo "title=$title text=$text" ;; esac } expat -s start -d data -e end < file.xml -- William Park , Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From martin at v.loewis.de Thu Aug 18 14:24:50 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 18 Aug 2005 20:24:50 +0200 Subject: certificate-based authentication In-Reply-To: References: Message-ID: <4304d273$0$419$9b622d9e@news.freenet.de> Dennis.Hoffman at seagate.com wrote: > I have been using XML-RPC to get information from one of our remote > servers. To improve security, the server now has a certificate installed, > and when I try to access it, I get an 'Unauthorized' exception. Is there > an xmlrpclib module that supports (client-side) certificate-based > authentication? If so, where can I get it, and what is involved in doing > the authentication? If not, what are my options? The standard xmlrpclib should work fine. You need to inherit from the SafeTransport class, overriding get_host_info to return the x509_info. You then pass an instance of your transport to the ServerProxy. HTH, Martin From noreply at gcgroup.net Tue Aug 16 12:03:48 2005 From: noreply at gcgroup.net (William Gill) Date: Tue, 16 Aug 2005 16:03:48 GMT Subject: help with mysql cursor.execute() In-Reply-To: <339vf11lvdl0qdt92e731i4u9qjgnoc73t@4ax.com> References: <8XMLe.878$Z%6.698@newssvr17.news.prodigy.com> <339vf11lvdl0qdt92e731i4u9qjgnoc73t@4ax.com> Message-ID: Dennis Lee Bieber wrote: > On Sun, 14 Aug 2005 19:28:04 GMT, William Gill > declaimed the following in comp.lang.python: > > >>I have been trying to pass parameters as indicated in the api. >>when I use: >> >> sql= 'select * from %s where cusid = %s ' % name,recID) >> Cursor.execute(sql) >> >>it works fine, but when I try : >> >> sql= 'select * from %s where cusid like %s ' >> Cursor.execute(sql,(name,recID)) >> > > Hypothesis: the database TABLE may need to be filled in externally. > .execute() parsing is designed to properly quote arguments for data > fields where needed. > > I suspect you are getting quote marks around the table name, which > is not a position they are expected. > From my testing, your suspicion is correct, as is your suggestion. sql = 'select * from %s where cusid = %%s ' % tablename Cursor.execute(sql, (recID,)) works, Bill > You'll likely have to use a two-step process: use string formatting > to fill in table and field names (if you are getting those from user > input, you'll have to validate that there isn't an injection attack -- > ie, user didn't enter "name; delete from name" as the table to be > processed); then use .execute() to pass the field values. > > If using MySQLdb, you could always read the source files... (Though, > unfortunately, the very bottom is a compiled library and hence > unreadable... > > > You'll find .execute() invokes an .escape() > > Py> escape(...) > Py> escape(obj, dict) -- escape any special characters in object > obj > Py> using mapping dict to provide quoting functions for each > type. > Py> Returns a SQL literal string. > > Note the last line: it returns a "literal string" -- in the form > needed to pass /data/. That won't work for field and table names, and > MySQLdb doesn't attempt any semantic parsing to find out is being > substituted -- if just converts (escapes) ALL parameters based on > datatype, THEN does a normal Python string formatting operation. From apardon at forel.vub.ac.be Wed Aug 31 03:26:48 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Aug 2005 07:26:48 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> Message-ID: Op 2005-08-30, Bengt Richter schreef : > On 30 Aug 2005 10:07:06 GMT, Antoon Pardon wrote: > >>Op 2005-08-30, Terry Reedy schreef : >>> >>> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message >>> news:7xy86k3r7n.fsf at ruckus.brouhaha.com... >>> >>>> Really it's x[-1]'s behavior that should go, not find/rfind. >>> >>> I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely >>> useful, especially when 'x' is an expression instead of a name. >> >>I don't think the ability to easily index sequences from the right is >>in dispute. Just the fact that negative numbers on their own provide >>this functionality. >> >>Because I sometimes find it usefull to have a sequence start and >>end at arbitrary indexes, I have written a table class. So I >>can have a table that is indexed from e.g. -4 to +6. So how am >>I supposed to easily get at that last value? > Give it a handy property? E.g., > > table.as_python_list[-1] Your missing the point, I probably didn't make it clear. It is not about the possibilty of doing such a thing. It is about python providing a frame for such things that work in general without the need of extra properties in 'special' cases. -- Antoon Pardon From mo.babaei at gmail.com Mon Aug 8 12:12:03 2005 From: mo.babaei at gmail.com (mohammad babaei) Date: Mon, 8 Aug 2005 20:42:03 +0430 Subject: Python framework Message-ID: <5bf3a41f05080809124ab203b0@mail.gmail.com> hi ! what's the best python framework to create web applications? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wenming_hu2002 at hotmail.com Sun Aug 21 08:47:59 2005 From: wenming_hu2002 at hotmail.com (wen) Date: Sun, 21 Aug 2005 20:47:59 +0800 Subject: import __main__ where can i find a module called "__main__.py"? Message-ID: and, in which case, the following case will happen: if __name__!='__main__': do_sth() any help would be appreciated. From onurb at xiludom.gro Tue Aug 23 06:07:37 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 23 Aug 2005 12:07:37 +0200 Subject: loop in python In-Reply-To: References: Message-ID: <430af56a$0$13099$626a14ce@news.free.fr> Terry Reedy wrote: > "Benjamin Niemann" wrote in message > news:dedgo7$mru$1 at online.de... > (snip) >>In that case, you are interested in IO performance. The time spent >>handling >>the loop is not significant compared to the time spent executing the >>'print' statement - which is a very complex operation despite its simple >>usage. >> >>An implementation where a simple control flow structure has an measurable >>impact on the overall timing of an IO bound program would really >>suprising. >>Python suprises me often, but in different ways ;) >> >>Perhaps you could try to use sys.stdout.write() directly, avoiding the >>overhead of 'print'. Perhaps there are differences between the (default) >>output buffering settings of perl and python. > > > According to postings some years ago, the perl folks have worked specially > hard to speed I/O, even to the point of replacing or rewriting some of the > C stdio library, at least for some systems. Hence, at that time, Perl was > expected and known to be noticeably faster than Python on such systems. The truth is that the Perl version of the "print loop" program is incredibly faster than it's C counterpart (at least on my gentoo/linux box). Since the "no-op loop" program is faster in C (I guess that GCC 'optimizes out' the whole loop !-), it seems clear that Perl's IO do not relie on the stdlib implementation. > Since then, Python I/O has been sped up to at least make better use of > stdio, so the gap may be less. The Python and C versions of the "print loop" program have execution times that are close enough... > 3. One should test computations that are relevant to the question being > asked. Of course !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From cliff at develix.com Mon Aug 1 12:44:27 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 09:44:27 -0700 Subject: namespaces In-Reply-To: References: <42EC9690.2040301@tiscali.it> <42ED9175.1050006@REMOVEMEcyber.com.au> <7xzms29ucn.fsf@ruckus.brouhaha.com> Message-ID: <1122914667.19618.341.camel@localhost.localdomain> On Tue, 2005-08-02 at 02:37 +1000, Steven D'Aprano wrote: > there is a reason why Lisp is a niche language, with very little if any use in the commercial world. Eric Naggum? Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From richardlewis at fastmail.co.uk Tue Aug 30 08:00:27 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Tue, 30 Aug 2005 13:00:27 +0100 Subject: DOM text In-Reply-To: <1125399938.12961.241773532@webmail.messagingengine.com> References: <3n889kFb1liU1@uni-berlin.de> <1125052998.4951.241536021@webmail.messagingengine.com> <1125397045.8198.241769418@webmail.messagingengine.com> <1125399938.12961.241773532@webmail.messagingengine.com> Message-ID: <1125403227.18568.241776799@webmail.messagingengine.com> On Tue, 30 Aug 2005 12:05:38 +0100, "Richard Lewis" said: > > On Tue, 30 Aug 2005 11:17:25 +0100, "Richard Lewis" > said: > > > > Here is the *complete* code for my SectionCursor class: > > In case anyone's interested, I've just noticed a logical error in the > next_node() method: OK, I'm beginning to wish I hadn't mentioned this now; I've changed the insert_node() method as well: ================================ def insert_node(self, ref_doc, new_node): if self.current_node.nodeType == Node.TEXT_NODE: parent_node = self.current_node.parentNode text_node = self.current_node next_node = text_node.nextSibling preceeding_portion = ref_doc.createTextNode(text_node.data[:self.char_pos]) proceeding_portion = ref_doc.createTextNode(text_node.data[self.char_pos:]) parent_node.replaceChild(preceeding_portion, text_node) if next_node is None: parent_node.appendChild(new_node) parent_node.appendChild(proceeding_portion) else: parent_node.insertBefore(new_node, next_node) parent_node.insertBefore(proceeding_portion, next_node) # where is the cursor? else: parent_node = self.current_node.parentNode next_node = self.current_node.nextSibling if next_node is None: parent_node.appendChild(new_node) else: parent_node.insertBefore(new_node, self.current_node) # where is the cursor? ================================ I've done some more testing and it seems that, after a call to insert_node() when the current_node is a Text node, current_node's parentNode, nextSibling and firstChild properties become None (assuming they weren't None before, which firstChild was). Hmm. Um...er, yeah. I don't think anyones following me anyway.... I'll keep fiddling with it. From mwm at mired.org Tue Aug 2 20:17:45 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 20:17:45 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <8664uqhkfj.fsf@bhuda.mired.org> <86hde9f172.fsf@bhuda.mired.org> Message-ID: <86r7dbeuvq.fsf@bhuda.mired.org> Cliff Wells writes: >> > Regardless, when you say "Unix", what do you mean? You may as well say >> > "OS" as this term has little meaning. Linux (which flavor)? BSD? SCO? >> > HPUX? OS/X? Minix? Whichever way, I suspect that a bit of distutils >> > hacking would solve your problem. >> >> I think the post I replied to covered the OS X case - there's an >> application bundler available for it already. > > Yes, I've used it to bundle wxPython apps on 10.3. > >> I want distributions that will work on all three major BSD variants >> and most Linux distrubtions - in particular, anything that uses deb's, >> rpm's or emerge. If you want to choose one in particular, try ubuntu >> Linux. > > OpenBSD: in portage > FreeBSD: in portage > 386BSD: don't know... does anyone still use this? > NetBSD: included AFAICT > Fedora: rpms available > Debian: debs available > Ubuntu: included > Gentoo: in portage > OS/X: available on wxpython.org Um - you're not answering the question I asked. I asked "What app do I use to bundle my applications for Unix, ala py2exe (or whatever it is) for Windows?" You're telling me how to install wxPython on those platforms. I know how to install wxPython. What I want to know is how to build an application bundle for all those Unix systems for a Python app I use that includes wxPython - or any other third party libraries I may be using. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From spam.csubich+block at block.subich.spam.com Wed Aug 10 23:11:05 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 10 Aug 2005 23:11:05 -0400 Subject: regex help In-Reply-To: References: Message-ID: jeff sacksteder wrote: > Regex questions seem to be rather resistant to googling. > > My regex currently looks like - 'FOO:.*\n\n' > > The chunk of text I am attempting to locate is a line beginning with > "FOO:", followed by an unknown number of lines, terminating with a > blank line. Clearly the ".*" phrase does not match the single newlines > occuring inside the block. Include the re.DOTALL flag when you compile the regular expression. From fakeaddress at nowhere.org Wed Aug 10 09:46:38 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 13:46:38 GMT Subject: how to write thread-safe module ? and pytz In-Reply-To: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> References: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> Message-ID: <2znKe.3830$zr1.603@newssvr13.news.prodigy.com> nicolas_riesch wrote: > Does someone know if the module pytz > (http://sourceforge.net/projects/pytz/) is thread-safe ? On that, I don't know. > That's because in the file pytz/tzinfo.py, I see global variables > _timedelta_cache, _datetime_cache, _ttinfo_cache, which are > dictionnaries and are used as cache. > I always thought that you must protect shared data with locks when > multithreading, but I don't see any lock anywhere in pytz. Definitely stick with what you always thought. > However, pytz seems to work well with multiple threads creating various > timezone objects at the same time. Buggy threading can seem to work well for along time. It may be a billion-to-one shot that a thread switch happens at just the wrong time. > I don't understand where the trick is, that allows multiple threads to > access this module without any locking and that all this seems to work > without any problem... > > Does this mean that there is a means to write a module that is > thread-safe, without importing the threading module and creating locks > ? > > Or have I not understood something ...? > > Can someone give me a hint ? In the current Python implementation, more things are atomic than the language guarantees to be atomic. Programmers should not depend on that behavior. Again, I don't know anything about pytz, but we wouldn't bother with locks and semaphores and such if we could make the problems go away just by ignoring them. -- --Bryan From jayt33 at gmail.com Sun Aug 7 13:48:50 2005 From: jayt33 at gmail.com (jayt33) Date: 7 Aug 2005 10:48:50 -0700 Subject: authentication project Message-ID: <1123436930.587565.99480@g47g2000cwa.googlegroups.com> im working on a project that involves creating a back end solution to authenticate and manage user accounts for a website. im new to python and am looking for some good references that can help me with this task. the requirements for the project are as follows: A new user can register with their email address and password of their choice. Upon registration, a confirmation email shall be sent which contains a link that needs to be clicked on within a fixed period of time in order to activate the account. Access to site resources shall be limited to users that have registered a valid user account. Also, the solution must automatically lock a given user account should an incorrect password be attempted repeatedly within a set timeframe. All necessary data is stored in a SQL Server database and Pyton Database API v2.0 is used to connect to the database. I need to develop a suitable schema and Python module to provide this functionality. Any help is much appreciated. Thanks, JT From bokr at oz.net Tue Aug 30 15:23:14 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 30 Aug 2005 19:23:14 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> Message-ID: <4314b190.174021119@news.oz.net> On 30 Aug 2005 10:07:06 GMT, Antoon Pardon wrote: >Op 2005-08-30, Terry Reedy schreef : >> >> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message >> news:7xy86k3r7n.fsf at ruckus.brouhaha.com... >> >>> Really it's x[-1]'s behavior that should go, not find/rfind. >> >> I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely >> useful, especially when 'x' is an expression instead of a name. > >I don't think the ability to easily index sequences from the right is >in dispute. Just the fact that negative numbers on their own provide >this functionality. > >Because I sometimes find it usefull to have a sequence start and >end at arbitrary indexes, I have written a table class. So I >can have a table that is indexed from e.g. -4 to +6. So how am >I supposed to easily get at that last value? Give it a handy property? E.g., table.as_python_list[-1] Regards, Bengt Richter From rune.strand at gmail.com Mon Aug 29 22:20:27 2005 From: rune.strand at gmail.com (Rune Strand) Date: 29 Aug 2005 19:20:27 -0700 Subject: File parser References: Message-ID: <1125368427.186511.149810@g47g2000cwa.googlegroups.com> It's not clear to me from your posting what possible order the tags may be inn. Assuming you will always END a section before beginning an new, eg. it's always: A some A-section lines. END A B some B-section lines. END B etc. And never: A some A-section lines. B some B-section lines. END B END A etc. is should be fairly simple. And if the file is several GB, your ought to use a generator in order to overcome the memory problem. Something like this: def make_tag_lookup(begin_tags): # create a dict with each {begin_tag : end_tag} end_tags = [('END ' + begin_tag) for begin_tag in begin_tags] return dict(zip(begin_tags, end_tags)) def return_sections(filepath, lookup): # Generator returning each section inside_section = False for line in open(filepath, 'r').readlines(): line = line.strip() if not inside_section: if line in lookup: inside_section = True data_section = [] section_end_tag = lookup[line] section_begin_tag = line data_section.append(line) # store section start tag else: if line == section_end_tag: data_section.append(line) # store section end tag inside_section = False yield data_section # yield entire section else: data_section.append(line) #store each line within section # create the generator yielding each section # sections = return_sections(datafile, make_tag_lookup(list_of_begin_tags)) for section in sections: for line in section: print line print '\n' From rkern at ucsd.edu Thu Aug 11 09:36:41 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 11 Aug 2005 06:36:41 -0700 Subject: set of sets In-Reply-To: <42FB3905.9090105@tiscali.it> References: <42FB3905.9090105@tiscali.it> Message-ID: Paolino wrote: > Matteo Dell'Amico wrote: >>Why don't you just use "frozenset"? > > This is what I'm doing, but the problem remains IMO. > Anyway with frozenset I have to override __new__ instead of __init__ to > make the initialization which is an operation not described in the > frozenset docs, which makes subclassing frozenset a different operation. Don't subclass. In [1]: s = frozenset() In [2]: f = set() In [3]: f.add(s) In [4]: f Out[4]: set([frozenset([])]) In [5]: f.remove(s) In [6]: f Out[6]: set([]) -- 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 reinhold-birkenfeld-nospam at wolke7.net Thu Aug 25 15:45:01 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 25 Aug 2005 21:45:01 +0200 Subject: variable hell In-Reply-To: <430debc5$0$25399$626a14ce@news.free.fr> References: <430debc5$0$25399$626a14ce@news.free.fr> Message-ID: <3n6ldtF2qhoU1@individual.net> rafi wrote: > Adriaan Renting wrote: >> You might be able to do something along the lines of >> >> for count in range(0,maxcount): >> value = values[count] >> exec(eval("'a%s=%s' % (count, value)")) > > why using the eval? > > exec ('a%s=%s' % (count, value)) > > should be fine And this demonstrates why exec as a statement was a mistake ;) It actually is exec 'a%s=%s' % (count, value) Reinhold From Scott.Daniels at Acm.Org Wed Aug 24 13:48:59 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Aug 2005 10:48:59 -0700 Subject: Externally-defined properties? In-Reply-To: References: Message-ID: <430ca70d$1@nntp0.pdx.net> Terry Hancock wrote: > Frankly, I was surprised this worked at all, but I tried > creating a property outside of a class (i.e. at the module > level), and it seems to behave as a property: Not so surprising. Making a class begins by making a little namespace, then using it to build the class. If you look at how class construction works, it gets handed the namespace to wrap parts (the originals are left alone). After playing with your example for a little, perhaps the following will illustrate things: def get_x(obj): return thevar def set_x(obj, val): global thevar thevar = val def del_x(obj): global thevar del thevar def textify(obj): objid = '%s_%s' % (obj.__class__.__name__, id(obj)) try: return '%s:%r' % (objid, thevar) except (NameError, AttributeError): return '%s:---' % objid prop = property(get_x, set_x, del_x) class One(object): x = prop __repr__ = textify class Two(object): y = prop __str__ = textify Class Three(object): __repr__ = textify a = One() b = Two() c = Three() print a, b, c a.x = 5 print a.x, b.y, a, b, c Three.z = One.x print c, c.z del b.y print a, b, c print a.x You may want to raise AttributeError on get_x (you have no name to use): def get_x(obj): try: return thevar except NameError: raise AttributeError > Am I about to shoot myself in the foot? Well, usually all this playing is good for understanding how Python works, but makes your connections less than explicit, and we know that explicit is better than implicit. --Scott David Daniels Scott.Daniels at Acm.Org From aahz at pythoncraft.com Thu Aug 18 13:58:46 2005 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2005 10:58:46 -0700 Subject: Python jobs (was Re: Python for Webscripting (like PHP)) References: Message-ID: In article , Steve Holden wrote: > >There's informal evidence that the Python secret is getting out. Sharpen >up your resumes, guys, you may not have to limit Python to home usage >soon :-) OTOH, the big sucking sound from Google and Yahoo (plus other places like Ironport) is making it more difficult to hire Python programmers in the Bay Area... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From martin.witte at gmail.com Mon Aug 15 12:46:03 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 15 Aug 2005 09:46:03 -0700 Subject: Using for in one-liner In-Reply-To: <3mbu82F15h18oU1@individual.net> References: <3mbu82F15h18oU1@individual.net> Message-ID: <1124124363.780021.240270@o13g2000cwo.googlegroups.com> to me it seems the ',' is superfluous, this works: python -c "import sys;print ''.join([l for l in sys.stdin.readlines()])" in 2.4.1 - with the comma it works as well but it looks weird, as if you want to un-pack a tuple. From webdev at chaosmedia.org Fri Aug 5 11:15:16 2005 From: webdev at chaosmedia.org (webdev) Date: Fri, 05 Aug 2005 17:15:16 +0200 Subject: minidom xml & non ascii / unicode & files Message-ID: <42f38284$0$5314$636a15ce@news.free.fr> lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3 script that grabs some web pages from the web, regex parse the data and stores it localy to xml file for further use.. at first i had no problem using python minidom and everything concerning my regex/xml processing works fine, until i tested my tool on some french page with "non ascii" chars and my script started to throw errors all over the place.. I've looked into the matter and discovered the unicode / string encoding processes implied when dealing with non ascii texts and i must say i almost lost my mind.. I'm loosing it actually.. so here are the few questions i'd like to have answers for : 1. when fetching a web page from the net, how am i supposed to know how it's encoded.. And can i decode it to unicode and encode it back to a byte string so i can use it in my code, with the charsets i want, like utf-8.. ? 2. in the same idea could anyone try to post the few lines that would actually parse an xml file, with non ascii chars, with minidom (parseString i guess). Then convert a string grabbed from the net so parts of it can be inserted in that dom object into new nodes or existing nodes. And finally write that dom object back to a file in a way it can be used again later with the same script.. I've been trying to do that for a few days with no luck.. I can do each separate part of the job, not that i'm quite sure how i decode/encode stuff in there, but as soon as i try to do everything at the same time i get encoding errors thrown all the time.. 3. in order to help me understand what's going on when doing encodes/decodes could you please tell me if in the following example, s and backToBytes are actually the same thing ?? s = "hello normal string" u = unicode( s, "utf-8" ) backToBytes = u.encode( "utf-8" ) i knwo they both are bytestrings but i doubt they have actually the same content.. 4. I've also tried to set the default encoding of python for my script using the sys.setdefaultencoding('utf-8') but it keeps telling me that this module does not have that method.. i'm left no choice but to edit the site.py file manually to change "ascii" to "utf-8", but i won't be able to do that on the client computers so.. Anyways i don't know if it would help my script at all.. any help will be greatly appreciated thx Marc From markmcintyre at spamcop.net Tue Aug 30 18:40:28 2005 From: markmcintyre at spamcop.net (Mark McIntyre) Date: Tue, 30 Aug 2005 23:40:28 +0100 Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: On 30 Aug 2005 18:06:48 GMT, in comp.lang.c , John Bokma wrote: >Mark McIntyre wrote: > >>Its a complete mystery. Just as is the reason why you are x-posting >>complete garbage to comp.lang.c... > >A similar mystery as in why Mark clueless n00b II McIntyre thinks it's a >good idea to cross post to all other groups except comp.lang.c? I see you felt it appropriate to RE-post this offtopic garbage back into clc. You sir, are a troll, and I'd claim my fiver if I could be arsed. -- Mark McIntyre CLC FAQ CLC readme: ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From michele.simionato at gmail.com Tue Aug 9 05:39:25 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 9 Aug 2005 02:39:25 -0700 Subject: issues with doctest and threads In-Reply-To: References: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> Message-ID: <1123580365.838675.182080@g14g2000cwa.googlegroups.com> Thank you for your replies Jeff & Tim. The snippet I submitted is unfortunate, since I was writing an example (for a Python course I am going to give in September) to show that you cannot reliably assume that you will get exactly 9 dots, because of the limitations of 'sleep'. Mindlessly, I have cut & pasted that snippet, but my real question was not "how many dots I get", it was: "why the error message talks about 'thread' not being in the globals?" It's true that I can avoid it with a thread.join() (which I had forgot), but still I really cannot understand the reason for such message. Why it is so misleading? Can something be done about it? TIA, Michele Simionato From http Sat Aug 20 07:13:03 2005 From: http (Paul Rubin) Date: 20 Aug 2005 04:13:03 -0700 Subject: Sandboxes References: Message-ID: <7x1x4oeu9s.fsf@ruckus.brouhaha.com> 42 writes: > Googling for information on securing Python in a "sandbox" seems > indicate that there are some built in features, but they aren't really > trustworthy. Is that correct? Yes. > For my purposes, I really just want to let users run in a sandbox, with > access to only the language, manipuate a few published objects in the > application (and perhaps give them some string and math libraries if > applicable). If they are malicious, this is asking for trouble. > I was wondering if it would be effective to pre-parse incoming scripts > and reject those containing "import"? I'd also have the application > inject the (short) list of trusted imports to the script before passing > it to the interpreter. No, that's not enough. > Would this sufficient? Are there any drawbacks or giant gaping holes? > I'm anticipating that I'd also need to block 'exec' and 'eval' to > prevent an import from being obfuscated past the pre-parse. > > Or is this a hopeless cause? Yes. It's even difficult with Java and Javascript, which were designed to have such security. From thomasbartkus at comcast.net Wed Aug 17 12:07:52 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Wed, 17 Aug 2005 11:07:52 -0500 Subject: Python as VBA replacement under Windows? References: <7cKdnQ8TVuYj157eRVn-oQ@telcove.net> Message-ID: "Wolfgang Keller" wrote in message news:mn.8bf77d584d2edf8b.30301 at gmx.de... > > Because the MS Office suite and a few (very few!) other applications expose > > their object models via COM, you can manipulate these programs with Python > > and other languages. No applicatoin "supports VBA as a macro language". > > What I meant was that quite a lot of Windows applications (not only MS > Office) allow to execute VBA scripts just like "macros" from within the > application. What I want now is to write a "dummy" VBA script > "container" that consists of/executes Python sourcecode by calling the > Pythonwin interpreter. I *think* you may want to approach this from the other way around. If it were me, I would write a Python app that initates, and maintains handles to, the target Windows app. The controlling Python app could then drop from sight and respond as necessary to events occurring within the Windows app. This is the way you would do it from an external VB app. > > Rather - VBA is bundled and integrated with MS Office in order to manipulate > > COM. You can use Python to do that too! > > Yup, from outside. What I would like to do is do it from "inside" the > application. I don't *think* this is possible. Nor do I think this is worth worrying about. You write VB/VBA applications to work either from the inside (in process) or the outside (out of process) with the former being somewhat more efficient. Unfortunately, this is where VBA with it's integrated editor is woven into the warp and woof of MS Office. You are stuck running "out of process" with Python. But again, I don't really see this as being worth worrying about. > > "perfectly possible"? > > Well, at least as far as there's a COM interface and for someone who > refuses to learn VB(A) but still wants to script Windows applications. I have dabbled a bit using Python to control Excel. But just a bit. It's just too easy to invoke VBA behind Excel and fire away - even if the resulting code isn't nearly so elegant! Somewhere out there, is a project to integrate Python into Visual Studio. Microsoft has rewritten Visual Studio to enable the integration of 3rd party languages. That might hold some promise for you although I have not been following developments here very closely. As for me - I'm sick of the directions MS is taking. I'm looking to Gnumeric/Python as an open source replacement to Excel/VBA :-) Thomas Bartkus From darkcowherd at gmail.com Fri Aug 12 22:41:58 2005 From: darkcowherd at gmail.com (Dark Cowherd) Date: Sat, 13 Aug 2005 08:11:58 +0530 Subject: UCALC equivalent In-Reply-To: <8vnvs2-7ll.ln1@lairds.us> References: <42fcea4a$1@nntp0.pdx.net> <8vnvs2-7ll.ln1@lairds.us> Message-ID: <5f4d3cb5050812194122fba0aa@mail.gmail.com> thx, Well moving to Python from another language needs lots of chanegs inside your head. -- DarkCowherd From titogarcia_deletethis at gmail.com Fri Aug 12 05:40:40 2005 From: titogarcia_deletethis at gmail.com (Tito) Date: Fri, 12 Aug 2005 11:40:40 +0200 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> <42fb5a47$0$27714$626a14ce@news.free.fr> Message-ID: bruno modulix wrote: > Magnus Lycka wrote: > >>N.Davis wrote: >> >> >>>Functions existing in a module? Surely if "everything is an object" >>>(OK thats Java-talk but supposedly Python will eventually follow this >>>too) >> >> >>int too? ;) > > > Yes, int too. I think he is talking about *Java* int. Regards, Tito From curtis.rendon at gmail.com Mon Aug 15 20:14:10 2005 From: curtis.rendon at gmail.com (curtis.rendon at gmail.com) Date: 15 Aug 2005 17:14:10 -0700 Subject: Is Tkinter compatible with GNOME? References: Message-ID: <1124151250.604911.64920@g14g2000cwa.googlegroups.com> Have you tried starting it in a .xsession file with something like: exec gnome-session & button_prog.py From stephen at theboulets.net Fri Aug 5 15:31:36 2005 From: stephen at theboulets.net (stephen at theboulets.net) Date: 5 Aug 2005 12:31:36 -0700 Subject: Passing a variable number of arguments to a wrapped function. In-Reply-To: <42f3a8dc.672538178@news.oz.net> References: <1123256072.542368.323390@g14g2000cwa.googlegroups.com> <42f3a8dc.672538178@news.oz.net> Message-ID: <1123270296.714056.23930@g14g2000cwa.googlegroups.com> Using 'plot(*args, **kwargs)' does seem to work just fine. Thanks to all for their suggestions. Stephen From jepler at unpythonic.net Sat Aug 6 21:39:44 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sat, 6 Aug 2005 20:39:44 -0500 Subject: Does FTPLIB have a 'local change directory' ? In-Reply-To: <3tdJe.1566$Z87.303@newssvr14.news.prodigy.com> References: <3tdJe.1566$Z87.303@newssvr14.news.prodigy.com> Message-ID: <20050807013944.GB22724@unpythonic.net> If you want to change the working directory of a Python program, then use os.chdir() for that purpose. That's what 'lcd' does in ftp client software. It doesn't send a remote command of any kind. Or, when you call the storbinary method, give the os.path.basename() of the file you are storing, instead of the name you used to open the file on the local system. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From python at rcn.com Fri Aug 26 18:39:10 2005 From: python at rcn.com (Raymond Hettinger) Date: 26 Aug 2005 15:39:10 -0700 Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: <1125095950.040968.232500@z14g2000cwz.googlegroups.com> Bryan Olson wrote: > The conclusion is inescapable: Python's handling of negative > subscripts is a wart. Indexing from the high end is too useful > to give up, but it should be specified by the slicing/indexing > operation, not by the value of the index expression. > > > PPEP (Proposed Python Enhancement Proposal): New-Style Indexing > > Instead of: > > sequence[start : stop : step] > > new-style slicing uses the syntax: > > sequence[start ; stop ; step] Bah! The pythonic way to handle negative slicing is to use reversed(). The principle is that the mind more easily handles this in two steps, specifying the range a forward direction, and then reversing it. IOW, it is easier to identify the included elements and see the direction of: reversed(xrange(1, 20, 2)) than it is for: xrange(19, -1, -2) See PEP 322 for discussion and examples: http://www.python.org/peps/pep-0322.html Raymond From gene.tani at gmail.com Sun Aug 28 08:16:43 2005 From: gene.tani at gmail.com (gene tani) Date: 28 Aug 2005 05:16:43 -0700 Subject: py to exe: suggestions? In-Reply-To: References: <1125217143.451511.25310@g43g2000cwa.googlegroups.com> Message-ID: <1125231403.476434.162930@z14g2000cwz.googlegroups.com> There's movpy, w/option to exclude Unicode/win98 capabilities: http://www.voidspace.org.uk/python/movpy/ Also: http://www.effbot.org/zone/exemaker.htm http://www.python.org/doc/current/dist/postinstallation-script.html http://www.jython.org/docs/differences.html Ben Finney wrote: > chris patton wrote: > > I need to convert a python file to an '.exe'. > > A Python program is executable only in the context of a Python > interpreter. Python is a dynamic language; it can't be compiled to > native machine code. > > > I've tried py2exe, and I don't like it because you have to include > > that huge dll and libraries. > > That's the Python interpreter environment, and the standard Python > library that is made available in the Python environment. Without > them, your program isn't executable. > > What were you hoping for? > > -- > \ "If trees could scream, would we be so cavalier about cutting | > `\ them down? We might, if they screamed all the time, for no good | > _o__) reason." -- Jack Handey | > Ben Finney From sylvain.thenault at logilab.fr Fri Aug 5 05:00:17 2005 From: sylvain.thenault at logilab.fr (Sylvain =?iso-8859-1?Q?Th=E9nault?=) Date: Fri, 5 Aug 2005 11:00:17 +0200 Subject: [ANN] pylint 0.7 In-Reply-To: <20050804185018.GA17068@phenix.progiciels-bpi.ca> References: <20050527105926.GC4750@logilab.fr> <20050804185018.GA17068@phenix.progiciels-bpi.ca> Message-ID: <20050805090017.GA3642@logilab.fr> On Thu, 04 Aug 2005 14:50:18 -0400, Fran?ois Pinard wrote: > [Sylvain Th?nault] > >> I'm pleased to announce a new release of PyLint. > > Bonjour Sylvain. J'ai la compulsion de dire bonjour, et merci! (On peut > me tutoyer sans probl?me.) Bonjour ! C'est une compulsion plut?t sympathique ! ;) > Ce logiciel `pylint', que je viens d'installer et d'essayer pour la > premi?re fois ce matin (donc, j'?cris encore sur l'effet d'une premi?re > impression), me semble vraiment excellent. j'esp?re que l'impression sur le long terme sera la m?me ! > Plaisir suppl?mentaire, `logilab.common' semble contenir de bien belles > choses, int?ressantes pour moi, je vais regarder ?a de plus pr?s. Il commence ? y avoir pas mal de chose dans cette librairie, qui nous sert un peu de fourre-tout pour tout le code qui est partag? entre plusieurs de nos projets. ?a manque un peu de documentation, mais le code devrait ?tre ? peu pr?s propre, et n'h?site pas ? nous poser des questions au besoin. > ?tant moi-m?me plut?t tatillon sur les questions stylistiques, je suis > heureux de trouver quelqu'un qui, en plus de parler ma langue, poss?de > probablement le m?me d?faut. Effectivement, je suis un peu (bon d'accord, *tr?s*) maniaque sur ces questions :) >> Please send any bugs or comments on the mailing list. > > Dois-je vraiment passer par l?? Les discussions sont n?cessairement un > petit peu plus impersonnelles sur une liste. Si oui, alors je le ferai, > bien s?r. J'imagine qu'il faut alors s'y inscrire aussi? Effectivement, c'est un peu plus impersonnel mais ?a ? l'avantage d'?tre archiv? et la discussion est ainsi partag?e avec les autres utilisateurs de pylint. Si tu pr?f?res ?crire en fran?ais, il y a aussi la liste forum-fr at logilab.org, qui a un tr?s faible trafic. Ces deux listes (forum-fr et python-projects) demande effectivement un abonnement, mais ce n'est pas requis pour poster, c'est juste que si tu n'est pas membre les mails seront mod?r?s, et donc mettront peut-?tre un peu plus de temps ? arriver. Apr?s, je r?pond aussi aux mails perso ;) Et si cela me semble int?ressant de faire partager la r?ponse, je met la liste en copie. > De petites choses qui m'ont tout de suite saut? aux yeux: > > * `pylint --version' devrait fournir l'adresse o? rapporter les > probl?mes. > > * `pylint --generate-rcfile' engendre un fichier qui poss?de trop > d'espace blanc intempestif, en particulier ? la fin de plusieurs > lignes, et aussi, ? la toute fin du fichier. Il serait int?ressant > aussi que le fichier engendr? se tienne dans 79 colonnes: pas toujours > possible pour le code, j'en conviens, mais au moins faisable pour les > commentaires. tu l'as g?n?r? sous windows ? Sous linux ?a marche bien, et les commentaires sont wrapp?s correctement sur 80 colonnes. Je pense que les espaces en trop sont aussi li?s ? ?a. Il me semblait avoir d?j? corrig? ce pb, faudra que je trouve une machine windows pour rejeter un oeil ? ce probl?me. > * `pylint --parseable=y' pourrait peut-?tre, sous option, ?viter > les noms de fichiers absolus et garder une notation relative, cela > ?liminerait passablement de bruit lorsque le r?pertoire courant est > nich? profond?ment. je met ?a dans notre tracker. > * Malgr? son origine fran?aise, `pylint' n'est pas sensible ? un > "locale" > fran?ais. J'imagine que l'internationalisation n'est pas pr?vue? c'est pr?vu depuis un moment, mais avec une priorit? au plus bas :) ?a devrait pas ?tre trop dur ? faire, tous les messages ?tant regroup?s dans un dictionnaire pour chaque checker. > Merci bien pour PYLINTHOME et PYLINTRC, les variables d'environnement. > J'en fait d?j? bon usage. :-) > > D'une certaine mani?re dans la m?me mentalit? de `pylint', j'ai > produit une sorte de redresseur stylistique que j'utilise directement de > l'int?rieur de Vim. J'ai probablement pens? un peu ? Emacs tout > aussi bien en l'?crivant, mais je n'ai pas utilis? Emacs depuis un bon > moment. toi, l'auteur de pymacs, pass? ? Vim ! Mais rien ne va plus ;) > Je d?sire bient?t replonger dans ce redresseur et le d?poussi?rer > s?rieusement, pour un autre gros projet. Il vaudrait peut-?tre la > peine de voir s'il m'est possible d'harmoniser mon outil au tien, et > vice-versa peut-?tre, un peu. Du m?me jet, il m'intrigue de comparer > le module `compiler' de Python 2.3, qui ne me satisfait plut?t bien, > mais pas tout-?-fait, avec le module `astng' de Logilab. le module astng est en fait une sur-couche du module compiler de la librairie standard. Il ne fait en gros qu'ajouter des propri?t?s et m?thodes aux noeuds de l'arbre produit par ce module, avec en plus quelques classes pour g?rer la g?n?ration de ces arbres. Et aussi construire des repr?sentations d'objets "vivants" (si le code source n'est pas accessible ou n'est pas du python par exemple). > Donc, en bref, survole: > > http://fp-etc.progiciels-bpi.ca/showfile.html?name=pynits/pynits.txt&mode=vim > > pour "sentir" si nos approches ont quelques atomes crochus! :-) Si oui, > cela peut ouvrir la porte ? quelques bonnes discussions sur l'art et la > mani?re, en Python. Ma m?re disait parfois: "Des go?ts et des > couleurs, on ne discute pas. Mais il y en a de meilleurs que d'autres." :) ?a m'a l'air int?ressant en tout cas. Je pense que astng/pylint peuvent clairement aider ? d?tecter les probl?mes de formattage et distinguer les lignes physiques/logiques. Dans le m?me genre, une des choses que j'aimerais faire est un outil de refactoring ? la BRM bas? sur astng, mais bon, je sais pas si j'aurais un jour le temps de m'y mettre... Quoi qu'il en soit la discussion m'int?resse ! ? bient?t, -- Sylvain Th?nault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From zarnovican at gmail.com Thu Aug 18 15:40:15 2005 From: zarnovican at gmail.com (BranoZ) Date: 18 Aug 2005 12:40:15 -0700 Subject: determine variable type In-Reply-To: <7xzmrfcbdf.fsf@ruckus.brouhaha.com> References: <7xzmrfcbdf.fsf@ruckus.brouhaha.com> Message-ID: <1124394015.082320.177640@o13g2000cwo.googlegroups.com> Paul Rubin wrote: > MCollins at seminolecountyfl.gov writes: > > i tried using type(var) but that only seemed to produce a response in the > > command line. > > > > is there a built in python function to determine if a variable is an > > integer? > > type(var) returns the type. For example: > > if type(x) == type(3): > print 'x is an integer' or x = 5 isinstance(x, int) True BranoZ From fakeaddress at nowhere.org Thu Aug 25 18:30:23 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 25 Aug 2005 22:30:23 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> Steve Holden asked: > Do you just go round looking for trouble? In the course of programming, yes, absolutly. > As far as position reporting goes, it seems pretty clear that find() > will always report positive index values. In a five-character string > then -1 and 4 are effectively equivalent. > > What on earth makes you call this a bug? What you just said, versus what the doc says. > And what are you proposing that > find() should return if the substring isn't found at all? please don't > suggest it should raise an exception, as index() exists to provide that > functionality. There are a number of good options. A legal index is not one of them. -- --Bryan From saravanand at vsnl.net Wed Aug 3 02:58:26 2005 From: saravanand at vsnl.net (Saravanan) Date: 2 Aug 2005 23:58:26 -0700 Subject: Python 2.3.3 Exceptions Message-ID: <1123052306.935085.116970@f14g2000cwb.googlegroups.com> Hello, Im using Python 2.3.3 along with Win32all (163). Currently my python application runs as Windows Service. Im using Win32all Service Framework to run the Python Code as a Windows Service. The following error has been reported to event viewer sparadically. "Reporting queued error: faulting application PythonService.exe, version 2.3.0.163, faulting module python23.dll, version 2.3.3150.1012, fault address 0x0005c202." Due to that, my service does not stops or crashes. Can anybody guess what is the problem? I have checked the Python Code, the crash always points to static int default_3way_compare(PyObject *v, PyObject *w) function in object.c As of now my project does not allow me to upgrade to higher version of Python. Thanks in Advance Saravanan D From jasondrew72 at gmail.com Tue Aug 23 19:01:03 2005 From: jasondrew72 at gmail.com (Jason Drew) Date: 23 Aug 2005 16:01:03 -0700 Subject: Sorta noob question - file vs. open? In-Reply-To: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> Message-ID: <1124838063.712707.95240@g47g2000cwa.googlegroups.com> Both your code snippets above work should work OK. If it seems like a file isn't being written, maybe you should specify its full path so you are sure about where to check for it. On the file-or-open question, the Python docs state, "The intent is for open() to continue to be preferred for use as a factory function which returns a new file object." I happen to know that because it was clarified for me recently by a few posters in this informative thread: http://groups.google.com/group/comp.lang.python/browse_frm/thread/fbc7fbacf0866763 (which didn't start out as a file-or-open discussion, but there you go). Hope this helps, Jason From bignose+hates-spam at benfinney.id.au Tue Aug 23 07:38:35 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 23 Aug 2005 21:38:35 +1000 (EST) Subject: check whether directory is readable References: <1124786052.372768.156730@o13g2000cwo.googlegroups.com> Message-ID: eels wrote: > how can I check whether a directory is readable or not. Are there > differences between unix and windows? The Pythonic way would be to just do what you need to do (in this case, presumably, read the directory) and catch the specific exception (in this case, presumably, OSError). try: # Do whatever needs a readable directory normal_reading_stuff() except OSError, e: # Do whatever we need to when the directory is unreadable print "Unable to read stuff:", e.strerror -- \ "I got contacts, but I only need them when I read, so I got | `\ flip-ups." -- Steven Wright | _o__) | Ben Finney From carsten at uniqsys.com Thu Aug 11 13:50:04 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Thu, 11 Aug 2005 13:50:04 -0400 Subject: Spreadsheet with Python scripting and database interface? In-Reply-To: References: Message-ID: <1123782603.30861.181.camel@dot.uniqsys.com> On Fri, 2005-07-29 at 04:21, Wolfgang Keller wrote: > Hello, > > I'm looking for a spreadsheet application (MacOS X prefered, but > Windows, Linux ar available as well) with support for Python scripting > (third-party "plug-ins" are ok) and a database interface. > > Applications that I know of (that they exist) are: > > MS Excel > Quattro > Lotus > OO Calc > Gnumeric > Kspread > > Which ones have I forgotten? > > Which ones have support for Python scripting? > [snip] > OO Calc: I know that PyUNO exists, but I know nothing about what it can > actually do? > [snip] See http://udk.openoffice.org/python/python-bridge.html for more than you'll ever want to know about this. In a nutshell, you can do pretty much anything. One thing that's not clear from your question is whether you want to script the office from within using a macro or from the outside via "remote control". PyUNO allows both, but Python macros are only possible with the OpenOffice 2 scripting framework. Hope this helps, Carsten Haese. From gry at ll.mit.edu Fri Aug 19 11:51:01 2005 From: gry at ll.mit.edu (gry at ll.mit.edu) Date: 19 Aug 2005 08:51:01 -0700 Subject: stdin -> stdout In-Reply-To: References: Message-ID: <1124466661.390473.127030@g49g2000cwa.googlegroups.com> import sys for l in sys.stdin: sys.stdout.write(l) -- George From tjreedy at udel.edu Sat Aug 6 02:15:08 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 6 Aug 2005 02:15:08 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <1123302662.011700.260260@g49g2000cwa.googlegroups.com> Message-ID: wrote in message news:1123302662.011700.260260 at g49g2000cwa.googlegroups.com... > Are you sure If I were, I would not have started the statement 'I suspect...'. I do not insert such words accidentally. TJR From cam.ac.uk at mh391.invalid Tue Aug 2 06:16:37 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Tue, 02 Aug 2005 11:16:37 +0100 Subject: [path-PEP] Path inherits from basestring again In-Reply-To: References: Message-ID: Ron Adam wrote: > PS. Could someone repost the links to the current pre-pep and the most > recent module version so I can look at it closer look? Pre-pre-PEP: http://wiki.python.org/moin/PathClass Reinhold's version of the module is in Python CVS in nondist/sandbox/path. Jason Orendorff's version is at . -- Michael Hoffman From uomart at ihug.co.nz Thu Aug 18 17:15:31 2005 From: uomart at ihug.co.nz (Jon Monteleone) Date: Fri, 19 Aug 2005 09:15:31 +1200 Subject: Coin-operated kiosk written in python -- need some help... References: <777056A4A8F1D21180EF0008C7DF75EE03317587@sunbelt.org> Message-ID: <003801c5a439$f7e135b0$5700a8c0@rmse> Thanks Fred, The OS I am using is linux distro fedora core 4 (RH, version 10 I think). The first question I have is exactly as you mention in 1. I need to have the gui running from machine bootup to shutdown. I wrote a bash daemon init script to turn my program into a daemon, but it doesnt seem to work. I used the standard bash daemon init script that exists in /usr/local/docs as a template. The script doesnt work correctly, so that is my first problem. But, assuming I get the script spawning my program as a daemon, the question becomes...will my Tkinter gui show up on the gnome presession screen (login screen) or do I need to add special code in .xinitrc or some other file to make it display? Your 2nd suggestion is already done. My program detects the coin drop in a separate thread. I do not have any problems running the program once I am logged into the Internet account. So, currently my specific questions are: 1) How do I make my gui display at the login screen (we can assume I get the program spawning as a daemon) 2) How do I get a push of the start button on my gui to login the user to the Internet account Cheers -Jon ----- Original Message ----- From: "Sells, Fred" To: "Jon Monteleone" ; Sent: Friday, August 19, 2005 5:01 AM Subject: RE: Coin-operated kiosk written in python -- need some help... I've done a similar app, but it keeps a gui up awaiting a timeclock punch. You need to tackle this in phases: 1. what os and get the gui to start at bootup. 2. start a separate thread that reads/blocks on the coin. you need more specific questions to get better help -----Original Message----- From: Jon Monteleone [mailto:uomart at ihug.co.nz] Sent: Thursday, August 18, 2005 11:15 AM To: python-list at python.org Subject: Coin-operated kiosk written in python -- need some help... Greetings, I posted a few days back and didnt get much of a response, so I figured I would post again with more detail. I am running gnome under fedora core 4. I want a kid to be able to drop a quarter into a coin slot and get 15 minutes of time on an account that has "restricted" Internet access via the firefox web browser. We are experimenting with different ways to allow kids to safely surf the web during school hours while recovering some of the cost for bandwidth. I have written a python program that detects the coin drop and adds 15 minutes to a gui written in tkinter. The gui contains 2 buttons and the usage time. I need a way for my gui to display from machine bootup until shutdown and through multiple logins and logouts of the web browsing account. I am familiar with kiosk setups but I dont know how to code my python program to display its gui at the login screen and continue running through multiple sessions of users logging into and out of the internet acct. I thought making my kiosk program a daemon would work, but I cant get the gui to display at the login screen and then there is the problem of having the press of a button on my gui enter username and password information. Basically, I envision the following sequence of events... 1) Machine is turned on and boots up 2) My kiosk is started (maybe as a daemon) 3) The daemon uses Tkinter to display its gui with the buttons and time 4) User drops coins and time on gui is incremented 5) User presses the start button 6) My program logs the user into the Internet account 7) Secure firefox is started 8) My program starts counting down the time on the gui 9) When the time reaches 0, the user is logged out When the user presses stop on my gui, they are logged out The user can drop more coins at any time during the session to prolong the session 10) Timer resets to 0 awaiting the next customer to drop coins Any help on how to display my gui and log into an account using python would be much appreciated. Cheers -Jon -- http://mail.python.org/mailman/listinfo/python-list --------------------------------------------------------------------------- The information contained in this message may be privileged and / or confidential and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and deleting the material from any computer. --------------------------------------------------------------------------- From gene.tani at gmail.com Thu Aug 18 14:29:47 2005 From: gene.tani at gmail.com (gene tani) Date: 18 Aug 2005 11:29:47 -0700 Subject: up to date books? In-Reply-To: References: Message-ID: <1124389787.873698.205070@g47g2000cwa.googlegroups.com> Start here: http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing http://dirtsimple.org/2004/12/java-is-not-python-either.html http://ischenko.blogspot.com/2005/02/java-may-not-be-that-bad-after-all.html and maybe poke around ehre to learn about language design, how people define typing, etc http://www.artima.com/ From apardon at forel.vub.ac.be Thu Aug 25 02:59:47 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 25 Aug 2005 06:59:47 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-24, Magnus Lycka schreef : > Antoon Pardon wrote: >> I think he did, because both expression are not equivallent >> unless some implicite constraints make them so. Values where >> both expressions differ are: >> >> start1=67, stop1=9, start2=10, stop2=29 > > Ouch! That didn't occur to me. How sloppy to just assume that > time periods can't end before they start. I have no trouble that you assume a time period starts before it ends. But two pieces of code that only give the same result under particular assumptions are not equivallent. For all I know his code might work without this assumption and thus be usefull in circumstances where yours is not. Maybe someone uses a convention where time intervals that stop before they start can have some meaning. Equivallent code IMO always gives the same results, not only under the particular constraints you are working with. > I'll shut up now. You win, > I'm obviously the idiot here, and Python's must be > redesigned from ground up. Pyrdon maybe? If I ever design a language it'll be called: 'Queny' -- Antoon Pardon From jtmerch at bellsouth.net Mon Aug 22 16:51:29 2005 From: jtmerch at bellsouth.net (Joe T.) Date: Mon, 22 Aug 2005 16:51:29 -0400 Subject: Python and the web Message-ID: Hello group, I'm new to Python and have a couple of beginner questions that I'm hoping someone can answer. 1. Is python something that you would recommend using for server side web programming? Something like C# or Java? If so, are there any resources that you could point me to that would help me with server side python programming for dynamic html data? Most of the tutorials that I see deal with the Shell but I'd like to know more about using Python for database querying and printing database data on an html page as I would with .net's C# or Java. 2. I know there's a Jpython but what use would I get from using Python with Java? If I'm already familiar with Java programming why would I want to use Python with Java? Again I appreciate any help with the above two questions. Thanks, Joe From draghuram at gmail.com Tue Aug 23 17:53:56 2005 From: draghuram at gmail.com (draghuram at gmail.com) Date: 23 Aug 2005 14:53:56 -0700 Subject: Reading just a few lines from a text file In-Reply-To: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> References: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> Message-ID: <1124834036.824027.95560@g14g2000cwa.googlegroups.com> I just did strace on "tail -20 ". Apparently, it does seek to the end and reads enough data to cover 20 lines. I guess it is calculating this "size" by counting 20 new lines .You may try to do the same thing. Thanks, Raghu. From jepler at unpythonic.net Mon Aug 1 20:07:19 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 1 Aug 2005 19:07:19 -0500 Subject: calling functions In-Reply-To: <3l7pegF10qu8cU1@individual.net> References: <3l7pegF10qu8cU1@individual.net> Message-ID: <20050802000716.GA9303@unpythonic.net> Without a 'global' statement, all variables which are assigned in the body of a function are local to that function. Here is an example showing that f() does not create a module-level variable, but g() does. >>> def f(): ... z = 3 ... >>> def g(): ... global z ... z = 3 ... >>> z Traceback (most recent call last): File "", line 1, in ? NameError: name 'z' is not defined >>> f() >>> z Traceback (most recent call last): File "", line 1, in ? NameError: name 'z' is not defined >>> g() >>> z 3 You also have a fencepost error in your slicing. You want to write child = parent[:position] + gene + parent[position+1] otherwise you end up including too few characters in child, and if position is 0 you get an even more unexpected result. However, instead of using 'global' you should just have mutate() return the new child. Here's a version of mutate() that I wrote: import string, random valid = string.lowercase + " " def mutate(parent): position = random.randrange(len(parent)) newgene = random.choice(valid) return parent[:position] + newgene + parent[position+1:] My mutate() returns the new string after it is mutated, so there's no need to use 'global' Here, I repeatedly mutate child to give a new child: >>> child 'forest of grass' >>> for i in range(5): ... child = mutate(child) ... print child ... forest of grays forqst of grays fooqst of grays zooqst of grays zooqst of brays Here, I find many mutations of parent: >>> for i in range(5): ... child = mutate(parent) ... print child ... foresf of grass forestsof grass forest ofpgrass forest oj grass forest cf grass If you have a fitness function f() which returns a higher number the more fit a string is, and you're using Python 2.4, here is some code to order several mutations of parent according to fitness: >>> children = sorted((mutate(parent) for i in range(5)), key=f, reverse=True) >>> fittest_child = children[0] Here's a stupid fitness function: def f(s): return f.count(" ") And it's fairly successful at breeding a string with lots of spaces: >>> child = "forest of grass" >>> for i in range(10): ... children = (mutate(child) for j in range(100)) ... child = sorted(children, key=f, reverse=True)[0] ... print child ... f rest of grass f rest of g ass f rest yf g ass f rest y g ass f rest y g a s t rest y g a s t rest y g a t re t y g a t e t y g a t e y g a Over 10 generations, the most fit of 100 mutations is used as the basis for the next generation. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From donnal at donnal.net Mon Aug 22 15:28:19 2005 From: donnal at donnal.net (Donnal Walter) Date: Mon, 22 Aug 2005 14:28:19 -0500 Subject: combining namespaces when importing two modules Message-ID: I would like to be able to write something like: import dcw as dw import xyz as dw such that the 'dw' namespace includes definitions from both dcw and xyz, but in the script above names from dcw1 are lost. How can I combine the two? (I'd rather not use 'import *'.) Thanks. Best regards, Donnal Walter Arkansas Children's Hospital From jrastrick at student.usyd.edu.au Sun Aug 7 20:25:33 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 7 Aug 2005 17:25:33 -0700 Subject: Metaclasses and new-style classes In-Reply-To: References: <3756d9750508071541192a00e0@mail.gmail.com> Message-ID: <1123460733.941988.171270@f14g2000cwb.googlegroups.com> Correct me if I'm wrong, but I think the OP was asking if metaclasses work with old-style classes, not new-style. jepler at unpythonic.net wrote: > This may be a limitation Zope imposes. > > I wrote this program: > #----------------------------------------------------------------------- > class M(type): > def __new__(*args): > print "new M", args > > class T(object): > __metaclass__ = M > #----------------------------------------------------------------------- > > Running it prints > new M (, 'T', (,), > {'__module__': '__main__', '__metaclass__': }) > ... so you can see that the __metaclass__ mechanism works just fine with > new-style objects in plain Python. > > Jeff From russandheather at gmail.com Wed Aug 10 17:21:24 2005 From: russandheather at gmail.com (Qopit) Date: 10 Aug 2005 14:21:24 -0700 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123703058.378299.133980@g47g2000cwa.googlegroups.com> Message-ID: <1123708884.865237.88070@g43g2000cwa.googlegroups.com> > if __name__ == '__main__': Yep - that does it... should have thought of that. Thanks. This works fine for pychecker with no hangage: #--- if __name__ == "__main__": while 1: x = raw_input("meh:") #--- From pwatson at redlinepy.com Tue Aug 16 17:25:47 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Tue, 16 Aug 2005 16:25:47 -0500 Subject: String functions deprication In-Reply-To: <43024BF5.4080304@redlinepy.com> References: <43024BF5.4080304@redlinepy.com> Message-ID: <430259DB.2080704@redlinepy.com> Sorry, the previous post was based on Python 2.1. That is probably not of much interest. How about 2.4.1? Python 2.4.1 (#1, Jul 19 2005, 14:16:43) [GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import string >>> dir(string) ['Template', '_TemplateMetaclass', '__builtins__', '__doc__', '__file__', '__name__', '_float', '_idmap', '_idmapL', '_int', '_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill'] >>> dir("") ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> for m in dir(string): ... if m not in dir(""): ... print m ... Template _TemplateMetaclass __builtins__ __file__ __name__ _float _idmap _idmapL _int _long _multimap _re ascii_letters ascii_lowercase ascii_uppercase atof atof_error atoi atoi_error atol atol_error capwords digits hexdigits index_error joinfields letters lowercase maketrans octdigits printable punctuation splitfields uppercase whitespace >>> for m in dir(""): ... if m not in dir(string): ... print m ... __add__ __class__ __contains__ __delattr__ __eq__ __ge__ __getattribute__ __getitem__ __getnewargs__ __getslice__ __gt__ __hash__ __init__ __le__ __len__ __lt__ __mod__ __mul__ __ne__ __new__ __reduce__ __reduce_ex__ __repr__ __rmod__ __rmul__ __setattr__ __str__ decode encode endswith isalnum isalpha isdigit islower isspace istitle isupper splitlines startswith title From peter at engcorp.com Tue Aug 16 08:03:58 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 16 Aug 2005 08:03:58 -0400 Subject: __del__ pattern? In-Reply-To: References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: Tom Anderson wrote: > On Mon, 15 Aug 2005, Peter Hansen wrote: >> Using '' instead of 'localhost' means bind to *all* interfaces, not >> just the loopback one. > > Doesn't '' mean 'bind to the *default* interface'? What does "default" mean, and is that definition in conflict with what I said? The docs say it means INADDR_ANY. They don't say what that means, so you'd have to read up on the C socket calls to learn more. Or some helpful soul will clarify for the class... :-) -Peter From mynews44 at yahoo.com Sun Aug 7 11:47:20 2005 From: mynews44 at yahoo.com (googleboy) Date: 7 Aug 2005 08:47:20 -0700 Subject: Some newbie cgi form questions... In-Reply-To: References: <1123405970.722953.287970@g49g2000cwa.googlegroups.com> Message-ID: <1123429640.905460.140210@o13g2000cwo.googlegroups.com> for key in form.keys():Yes, I know which fields are hidden because I made them that way, but I am trying to figure out a way I can iterate over the fields and do one thing with hidden fields (assign them to variables that tell the form how to process) and a different thing with non hidden fields (present them back to the browser with after emailling them on to the form owner). I want this script to work fro several forms on the same webserver, some of which will have several different and individual names. I am also hopeful that I may be able to extrapolate from that ways to differentiate other things from my form input things, but we'll see how it goes. My html code looks like this:

Send Feedback

Subject
Your name
Your email address.


Please let me know your thoughts below.

In other news, I have tried suggested syntaxes aboce (thanks guys!) but I get strange errors. If the following: for key in form.keys(): if not form.keys(): print "

ERROR!


" print "Please go back and fill in all fields. All fields are required.
" I get a traceback in teh error_log file that looks like this: Traceback (most recent call last): File "cgi/form.py", line 34, in ? for key, value in form.items(): File "/usr/local/lib/python2.3/cgi.py", line 533, in __getattr__ raise AttributeError, name AttributeError: items if this: for key in form.keys(): if not form.keys()[key]: print "

ERROR!


" print "Please go back and fill in all fields. All fields are required.
" print '' the I get this traceback: Traceback (most recent call last): File "/var/www/users/senta/html/gobooks/cgi/form.py", line 35, in ? if not form.keys()[key]: TypeError: list indices must be integers As you can see, I am using python 2.3 (my web service provider is responsible for this - I'd use 2.4.1 if I could) TIA googleboy From tdelaney at avaya.com Tue Aug 30 19:02:00 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Wed, 31 Aug 2005 09:02:00 +1000 Subject: micro-python - is it possible? Message-ID: <2773CAC687FD5F4689F526998C7E4E5F05CCAD@au3010avexu1.global.avaya.com> Wouter van Ooijen (www.voti.nl) wrote: >> No, not a tiny microcontroller environment. In the >> microcontroller world, "tiny" means 100 bytes of ram and 4KB of >> code space. > > That's medium :) > > PIC10F200: 256 12-bit instructions, 16 bytes RAM. Show off. Tim Delaney From lamthierry at gmail.com Wed Aug 31 16:49:43 2005 From: lamthierry at gmail.com (Thierry Lam) Date: 31 Aug 2005 13:49:43 -0700 Subject: Calling ftp commands from python Message-ID: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> Is it possible to run an ftp command to connect to some remote computer on the network. For example, if I want to retrieve some data from \\remcomputer\datafiles on the network and copy it to my local computer, how do I do it in python on the Unix side? I don't want to use mount since I don't have permission. Thanks Thierry From cantabile.03 at wanadoo.fr Wed Aug 3 11:01:28 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Wed, 03 Aug 2005 17:01:28 +0200 Subject: pygettext ? In-Reply-To: References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: <42f0dc47$0$894$8fcfb975@news.wanadoo.fr> Reinout van Schouwen a ?crit : > Hi, > > On Wed, 3 Aug 2005, cantabile wrote: > >> Hi, I'm trying to write an internationalized app. I'm learning python >> and read that pygettext would help me, but I found elsewhere it was >> obsolete (??) >> So, what's the correct and up to date tool to i18n python ? > > > Short answer: the functionality of pygettext has been incorporated in > the main gettext tool, so pygettext is obsolete. > > regards, > Thanks for the answer. Is there a good tutorial somewhere ? From claird at lairds.us Thu Aug 18 09:08:02 2005 From: claird at lairds.us (Cameron Laird) Date: Thu, 18 Aug 2005 13:08:02 GMT Subject: Some questions References: Message-ID: <21cet2-2hr.ln1@lairds.us> In article , Alessandro Bottoni wrote: >Titi Anggono wrote: >> 1. Can we use Tkinter for web application such as Java? > >What do you mean? If you want to build up a GUI (something like a HTML page) >for a web-based application, you can do it with TKinter. Your TKinter app >can connect to a web server (or any other kind of server) using the >standard Python networking libraries. > >If you want to make a web application (a server-side application similar to >the ones you can create with JSP or EJB) you do not need Tkinter at all. >Just use Python itself (see Albatross, Webware and Quixote for a few >web-app frameworks for Python). . . . ... or, if you mean, "is Python an apt language for client-side Web development in the way Java is, with the market-leading browsers all embedding JVMs which can interpret class definitions", the answers is, "No." And also "Yes". Standard Python is *not* good for client-side Web work. Jython is, though. From savvyside at aol.com Thu Aug 25 06:46:41 2005 From: savvyside at aol.com (michael) Date: Thu, 25 Aug 2005 10:46:41 GMT Subject: Command Line arguments References: <9gtqg1lkso6m6ukipku1ac7hk9sejhi3ld@4ax.com> Message-ID: On Thu, 25 Aug 2005 00:46:41 -0700, Tim Roberts wrote: > michael wrote: > >>I have a question about Windows based python (2.4 and later). >> >>For example, if I make a script called test.py like so: >> >>import sys >>print sys.argv >> >>then run it: >> >>python test.py this is a test >> >>I see a list with >> >>['test.py', 'this', 'is', 'a', 'test'] >> >> >>All is good! >> >>BUT... >> >>If i make .py extensions be run as exes (by setting the .py extension to >>be executable with PATHEXT setting in environment variables, the Python >>program will run, but NO arguments are passed! >> >>For example, after setting .py extension to be executable, i get this: >> >>test this is a test >> >>I get ['test.py]. NO arguments are passed. >> >>NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and >>earlier works FINE. > > It is a configuration problem. Bring up a Command Shell and run the assoc > and ftype commands like this: > > C:\Tmp>assoc .py > .py=Python.File > > C:\Tmp>ftype Python.File > Python.File="C:\Apps\Python24\python.exe" "%1" %* > > C:\Tmp> > > The KEY part of that is the %* at the end of the Python.File defintion. > That tells the system to insert the rest of the command line parameters at > that point. If you have ONLY the "%1", the command will run but no > parameters will be forwarded. If so, you can fix this by typing: > > C:\Tmp>ftype Python.File="C:\Apps\Python24\python.exe" "%1" %* > > Substituting your own path, of course. SOLVED! Thank you. I wonder why this was needed for 2.4 and not 2.2? I don't think it was lingering things from old installs because it happened on a persons computer that had never had any python installed before 2.4. Anyway, THANKS! Michael From CantankerousOldGit at gmail.com Fri Aug 5 19:38:16 2005 From: CantankerousOldGit at gmail.com (Cantankerous Old Git) Date: Sat, 06 Aug 2005 00:38:16 +0100 Subject: Making a timebomb In-Reply-To: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> References: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> Message-ID: callmebill at gmail.com wrote: > I have a server that right now runs infinitely. I'd like to make it > die after some amount of time. I was thinking of having a timebomb > thread that starts when the server starts. The timebomb sits, and > sleeps for the specified timeout period (e.g., 5 hours), then does > something to make the main thread terminate. But I'm too inexperienced > to figure out what that thing is. > > Any suggestions? > > > > class TimeBomb( threading.Thread ): > def run(self): > timeout = 5 * 60 * 60 #-- 3 hours > time.sleep( timeout ) > MakeTheRestOfTheStuffDie() > > class MyServer: > def __init__(self): > TimeBomb().run() > serve() > The proper way to do it is to have the timer set a flag that the other threads check regularly. The threads can then clean up and exit asap. The dirty way, which can leave corrupt half-written files and other nasties, is something like sys.exit(). The cog From chris at wintergreen.in Tue Aug 30 21:40:08 2005 From: chris at wintergreen.in (Chris Dewin) Date: Wed, 31 Aug 2005 10:40:08 +0900 Subject: Uploading images via cgi? Message-ID: How do I go about writing a cgi script, that will enable the client to upload things to a directory on my website? I would also like to write a script that enables the client to delete items in that directory if they want. Given that it's unix server, how do I go about ensuring the files are written to that dir with the right permissions? From david_blomstrom at yahoo.com Mon Aug 1 21:21:13 2005 From: david_blomstrom at yahoo.com (David Blomstrom) Date: Mon, 1 Aug 2005 18:21:13 -0700 (PDT) Subject: Application Error (referenced error) Message-ID: <20050802012113.82868.qmail@web60418.mail.yahoo.com> This is my first post on this list, and I'm new to Python. I downloaded a content management system called Plone and get the following error message when I try to start it: Plone Controller - [Plone Status]: pythonw.exe - Application Error The instruction at "0x009d3f09" referenced memory at "0x000000cB". The memory could not be "read". plone-users-request at lists.sourceforge.net I uninstalled it, then reinstalled it again, witih the same results. When I tried to start another Program in the Plone folder, I got this error message: "Windows is searching for runzope.bat. To locate the file yourself, click Browse." Do you have any idea what's causing this problem(s) and how I can fix i? Thanks. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From sysfault at scrpy.org Tue Aug 9 20:09:26 2005 From: sysfault at scrpy.org (sysfault) Date: Tue, 09 Aug 2005 20:09:26 -0400 Subject: Retaining an object Message-ID: Hello, I have a function which takes a program name, and I'm using os.popen() to open that program via the syntax: os.popen('pidof var_name', 'r'), but as you know var_name is not expanded within single quotes, I tried using double quotes, and such, but no luck. I was looking for a way to have var_name expanded without getting a syntax error by ommiting the surrounding quotes. I need to use a variable, it's the argument to a function. -- A wise man knows he knows nothing. From work-lists at ijuggle5.com Tue Aug 16 14:13:16 2005 From: work-lists at ijuggle5.com (Mark Thalman) Date: Tue, 16 Aug 2005 14:13:16 -0400 Subject: How to obtain GMT offset? In-Reply-To: References: Message-ID: <16F29B44-81A7-4344-A007-5362A3C6E0AB@ijuggle5.com> According to it is in seconds. -- Mark On Aug 16, 2005, at 9:35 AM, Peter Hansen wrote: > Erik Max Francis wrote: > >> time.timezone gives you the timezone offset in minutes. >> > > Dang, that means I'm twelve days in the past! > > >>>> import time >>>> time.timezone >>>> > 18000 > >>>> 18000/60 >>>> > 300 > (So that would be hours? ;-) ) > > >>>> 18000/60/24 >>>> > 12 > > Wait up guys! > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list > > From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 24 03:28:47 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 24 Aug 2005 09:28:47 +0200 Subject: how to deal with space between numbers References: Message-ID: Mohammed Altaj enlightened us with: > I managed to do all these things , but i did it in the way that i am > reading my data as strings ( no space between numbers) Keep the spaces, and use thestring.split() Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From talin at acm.org Fri Aug 12 15:39:08 2005 From: talin at acm.org (Talin) Date: Fri, 12 Aug 2005 12:39:08 -0700 Subject: Permutation Generator Message-ID: <42FCFADC.2030107@acm.org> I'm sure I am not the first person to do this, but I wanted to share this: a generator which returns all permutations of a list: def permute( lst ): if len( lst ) == 1: yield lst else: head = lst[:1] for x in permute( lst[1:] ): yield head + x yield x + head return -- Talin From tprimke at interia.pl Mon Aug 15 12:35:04 2005 From: tprimke at interia.pl (TPJ) Date: 15 Aug 2005 09:35:04 -0700 Subject: Standalone applications ? In-Reply-To: References: <42feba84$0$18644$14726298@news.sunsite.dk> <42feca21$0$18650$14726298@news.sunsite.dk> <1124016548.909588.77090@g47g2000cwa.googlegroups.com> Message-ID: <1124123704.309312.282540@g43g2000cwa.googlegroups.com> It's just the same as with Java, GTK+, Qt or any other library/platform. If you're doing development with Java, you can use any version that you like (for example the version 1.5) - and your application probably won't be able to run by an older version of Java. The same is with, for example, GTK+ library - if you use the version 2.6, your application might not work on systems with older version of the GTK+ library. And the same is with Python. When you develop application with Python, you must use some version of Python - and this is your dependency. You might say that your application needs a particular version of Python (and eventually particular versions of external modules). From twic at urchin.earth.li Mon Aug 22 18:25:26 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Mon, 22 Aug 2005 23:25:26 +0100 Subject: sending binary files to a 16 micro controller. In-Reply-To: <11gjn8k74pb6uc0@corp.supernews.com> References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <11gjn8k74pb6uc0@corp.supernews.com> Message-ID: On Mon, 22 Aug 2005, Grant Edwards wrote: > On 2005-08-22, Magnus Lycka wrote: > >>> Hi, I'm working on a project were a need to be able to upload firmware >>> to a microcontroller based Ethernet device. But because of the memory >>> constraints the controller can only handle packages of 300 bytes each >>> time. So therefore the firmware file must be sent in chunks > > It's very probable that the TCP stack will combine chunks and > send out full Ethernet frames (4K bytes). Those are *very* full ethernet frames! It seems to me that if the receiver can only handle a certain amount of data at a time, this should be reflected in its receive window; it should never advertise a bigger window than it can handle. if that's the case, the program should be able to write data as fast as it likes, as the sending TCP module will throttle it down so it goes out in right-sized drips. I'm not a TCP expert, though. Anyway, if you are going the small-writes route, make sure you set the TCP_NODELAY flag, to turn of Nagleing on the connection. I'm not sure if anyone mentioned that already. tom -- sh(1) was the first MOO From jeffrey.schwab at rcn.com Fri Aug 12 18:33:59 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Fri, 12 Aug 2005 18:33:59 -0400 Subject: Running one Python program from another as a different user In-Reply-To: <1123885309.455560.220670@z14g2000cwz.googlegroups.com> References: <1123885309.455560.220670@z14g2000cwz.googlegroups.com> Message-ID: dwelch91 at gmail.com wrote: > Greetings- > This is on Linux... I have a daemon running as root and I want to > execute another Python program as another user (a regular user). I have > the name of the user and can use the 'pwd' and 'grp' modules to get > that user's user and group ids. What I don't understand is how to then > go about launching that new program. I had considered having the > launched program switch itself back to the target user (somehow), but > the launched program is graphical in nature (PyQt), and I am afraid of > X11 locking out the display to user root (many distros seem to ship > with server access for user root turned off). That might prevent the > launched program from even starting? > > Any ideas? My Google searching was not successful in figuring this > out... from subprocess import * def run_as(username): pipe = Popen(["su", username], stdin=PIPE, stdout=PIPE) (out, err) = pipe.communicate("whoami") print out, if __name__ == "__main__": import sys for user in sys.argv[1:]: run_as(user) From alessandro.bottoni at infinito.it Thu Aug 18 08:32:56 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Thu, 18 Aug 2005 12:32:56 GMT Subject: Python for Webscripting (like PHP) References: Message-ID: Florian Lindner wrote: > How suitable is Python for these kind of projects? What do think? Does the > stdlib offers all basic functions for this kind of requirements? Python is extremely well suited for the web-app development and the STDLib supply most of what you need for this task. As a matter of fact, the easy development of web applications was one of the main focuses of the Python community since Rel 1.0. Thanks to the hard work of its supporters, Python is now widely considered one of the best tool you can use for developing web applications, even better than PHP. Have a look at these chapters of the official Python documentation to get convinced of what I'm saying: Chap. 11: Internet Protocols and Support Chap. 12: Internet Data Handling Chap. 13: Structured Mark-Up Languages Processing (Python has even been told to be used by Yahoo! and Google, among others, but nobody was able to demonstrate this, so far) Despite this, keep in mind that developing a _real_world_ web application without the right tools (session management and templating, in particular) is quite hard, no matter which language you use (even with PHP). Have a look at the many web frameworks mentioned at http://www.python.org/ and at http://www.vex.net/parnassus/ and choose the one you feel best suited for your task. Among these web framework, a couple of them deserve a particular attention: Maki is a XML based framework, very similar to the java-based Cocoon: http://maki.sourceforge.net/ http://cocoon.apache.org/ Albatross is aimed to stateful applications: http://www.object-craft.com.au/projects/albatross/ Regarding the template engine, the best one I'm aware of is Cheetah: http://www.cheetahtemplate.org/ A last word: beware of PSP (Python Server Pages). If used in the wrong way, this tool (like the original Java Server Pages) can make a real mess of your code (because of the inextricable tangle of Python and HTML code you can create). CU ----------------------------------- Alessandro Bottoni From noway at sorry.com Sun Aug 21 04:01:08 2005 From: noway at sorry.com (Giovanni Bajo) Date: Sun, 21 Aug 2005 08:01:08 GMT Subject: pythonXX.dll size: please split CJK codecs out References: <43082c5f$0$31577$9b622d9e@news.freenet.de> Message-ID: <8xWNe.24050$HM1.696102@twister1.libero.it> Martin v. L?wis wrote: >> I don't think I fully understand the reason why additional .pyd >> modules were built into the .dll. OTOH, this does not help anyone, >> since: > > The reason is simple: a single DLL is easier to maintain. You only > need > to add the new files to the VC project, edit config.c, and be done. No > new project to create for N different configurations, no messing with > the MSI builder. FWIW, this just highlights how ineffecient your build system is. Everything you currently do by hand could be automated, including MSI generation. Also, you describe the Windows procedure, which I suppose it does not take into account what needs to be done for other OS. But I'm sure that revamping the Python building system is not a piece of cake. I'll take the point though: it's easier to maintain for developers, and most Python users don't care. > In addition, having everything in a single DLL speeds up Python > startup a little, since less file searching is necessary. I highly doubt this can be noticed in an actual benchmark, but I could be wrong. I can produce numbers though, if this can help people decide. >> Can we at least undo this unfortunate move in time for 2.5? I would >> be grateful if *at least* the CJK codecs (which are like 1Mb big) >> are splitted out of python25.dll. IMHO, I would prefer having *more* >> granularity, rather than *less*. > > If somebody would formulate a policy (i.e. conditions under which > modules go into python2x.dll, vs. going into separate files), I'm > willing to implement it. This policy should best be formulated in > a PEP. > > The policy should be flexible wrt. to future changes. I.e. it should > *not* say "do everything as in Python 2.3", because this means I > would have to rip off the modules added after 2.3 entirely (i.e. > not ship them at all). Instead, the policy should give clear guidance > even for modules that are not yet developed. > > It should be a PEP, so that people can comment. For example, > I think I would be -1 on a policy "make python2x.dll as minimal > as possible, containing only modules that are absolutely > needed for startup". I'm willing to write up such a PEP, but it's hard to devise an universal policy. Basically, the only element we can play with is the size of the resulting binary for the module. Would you like a policy like "split out every module whose binary on Windows is > X kbytes?". My personal preference would go to something "make python2x.dll include only the modules which are really core, like sys and os". This would also provide guidance to future modules, as they would simply go in external modules (I don't think really core stuff is being added right now). At this point, my main goal is getting CJK out of the DLL, so everything that lets me achieve this goal is good for me. Thanks, -- Giovanni Bajo From jack at performancedrivers.com Thu Aug 25 14:10:31 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Thu, 25 Aug 2005 14:10:31 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <797fe3d40508251055615fcd16@mail.gmail.com> References: <5ZudndXd2JTen5PeRVn-2A@speakeasy.net> <797fe3d4050825104952c37fb@mail.gmail.com> <797fe3d40508251055615fcd16@mail.gmail.com> Message-ID: <20050825181031.GD5991@performancedrivers.com> On Thu, Aug 25, 2005 at 01:55:48PM -0400, Bill Mill wrote: > Bill Mill wrote: > > > > Pentium M 1.8 GHz Windows 2k. Here's the top of the profile results > > for fast and slow on my machine (these won't look decent except in a > > fixed-width font): > > > > > > > Interestingly, the test.py:36 line, which takes 45 seconds (!!) in the > > slow version, does not appear at all in the fast profile. I can't > > figure out why - both printed out their data, so template must have > > been called somewhere. > > > > OK, I'm getting somewhere now. When I replace: > > template = (" | %s %s %s | %s %s %s | %s %s %s |\n" * 3).join([" > +-------+-------+-------+\n"] * 4) > > wtih: > > template = """ | %s %s %s | %s %s %s | %s %s %s |\n > | %s %s %s | %s %s %s | %s %s %s |\n > | %s %s %s | %s %s %s | %s %s %s |\n > +-------+-------+-------+\n > | %s %s %s | %s %s %s | %s %s %s |\n > | %s %s %s | %s %s %s | %s %s %s |\n > | %s %s %s | %s %s %s | %s %s %s |\n > +-------+-------+-------+\n > | %s %s %s | %s %s %s | %s %s %s |\n > | %s %s %s | %s %s %s | %s %s %s |\n > | %s %s %s | %s %s %s | %s %s %s |\n > +-------+-------+-------+\n""" > > Then the non-dummy version is faster than the dummy version (very > slightly, presumably because it doesn't need to allocate 28 dummy > variables). I think this is just another tweaking that hits the magic spot (or avoids the bad spot) in some lookup table somewhere. Perhaps it has to do with the number interned strings and some worst case behavior? varnames are interened, so changing the number of globals would change the number of interened strings as well. -jackdied From nd51 at le.ac.uk Tue Aug 9 11:32:31 2005 From: nd51 at le.ac.uk (N.Davis) Date: Tue, 09 Aug 2005 16:32:31 +0100 Subject: What are modules really for? Message-ID: <42F8CC8F.7020500@le.ac.uk> I am very new to Python, but have done plenty of development in C++ and Java. One thing I find weird about python is the idea of a module. Why is this needed when there are already the ideas of class, file, and package? To my mind, although one CAN put many classes in a file, it is better to put one class per file, for readability and maintainability. One can then create packages and libraries, using groups of files, one class per file. Python seems to let you group classes together in one file and call it a module, but what for? I find that this, combined with mixins, makes it difficult to find out where code is inherited from. With single inheritance in C++ or Java, if you wanted to see what a method did and it appeared to be inherited, you would simply look in the base class's file, and if necessary recurse up the inheritance hierarchy until you found the method. With Python an inherited method could be in one of many base classes and/or mixins and there seems no particular logic as to what the filename would be. Am I missing something? Any comments would be appreciated. Thanks Nick Davis From http Mon Aug 8 15:15:58 2005 From: http (Paul Rubin) Date: 08 Aug 2005 12:15:58 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> Message-ID: <7x8xzcck9d.fsf@ruckus.brouhaha.com> Donn Cave writes: > > I'm not sure what you mean by that about OCAML. That its functional > > model is not pure enough? I'd like to look at Haskell as well, but I > > have the impression that its implementation is not as serious as > > OCaml's, i.e. no native-code compiler. > > On the contrary, there are a couple. Ghc is probably the leading > implementation these days, and by any reasonable measure, it is serious. OK, I've looked at the Haskell "gentle introduction" page a little bit and it's nice. I do remember Ocaml beating Haskell on a performance shootout and am not sure whether Ghc was used for the Haskell entry. I notice that Haskell strings are character lists, i.e. at least conceptually, "hello" takes the equivalent of five cons cells. Do real implementations (i.e. GHC) actually work like that? If so, that's enough to kill the whole thing right there. > Objective CAML is indeed not a pure functional language. Should that bother me? I should say, my interest in Ocaml or Haskell is not just to try out something new, but also as a step up from both Python and C/C++ for writing practical code. That is, I'm looking for something with good abstraction (unlike Java) and type safety (unlike C/C++), but for the goal of writing high performance code (like C/C++). I'm even (gasp) thinking of checking out Ada. From tjreedy at udel.edu Wed Aug 31 01:49:46 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2005 01:49:46 -0400 Subject: how to join two Dictionary together? References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> Message-ID: Read the list of dict methods at http://docs.python.org/lib/typesmapping.html Every Pythoneer should read LibRef c.2 at least once and either refer back to it or use help() to refresh memory of available methods. Terry J. Reedy From peter at engcorp.com Tue Aug 23 08:23:40 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 23 Aug 2005 08:23:40 -0400 Subject: Best way to 'touch' a file? In-Reply-To: References: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Message-ID: Fredrik Lundh wrote: > Peter Hansen wrote: > >>You've quoted selectively. He also said "Unix-style 'touch'", from >>which one could quite legitimately infer > > nope. read his post again. Sigh. You're being tiring, Fredrik: '''I'm looking for an easy way to perform a UNIX-style "touch", to update the modification time of a file without actually modifying it.''' And if your point is that I spelled UNIX in mixed case, and change the double quotation marks to single quotation marks, you really need to take a break. If your point is that this statement *clearly and unambiguously* rejects the create-if-missing feature as undesirable, then I can say only that you are simply wrong. -Peter From spammers-go-here at spam.invalid Tue Aug 30 18:22:12 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Tue, 30 Aug 2005 18:22:12 -0400 Subject: Problem with string -> int conversion ? Message-ID: <4314dbd0$0$18648$14726298@news.sunsite.dk> Hi I am working with an application that I designed with the Designer > pyuic workflow and I get the following error on trying to process the contents of a combobox : Traceback (most recent call last): File "measure.py", line 908, in acquiredata np=self.getNPrange() File "measure.py", line 1167, in getNPrange signalrange=int(signalrangestr) TypeError: int() argument must be a string or a number The code is : void Form3::getNPrange() { signalrangestr=self.NPcombobox.currentText() signalrange=int(signalrangestr) if globaldebug : print 'NP Signal range = ',signalrange return signalrange } The contents of the combobox are strings representing numbers in the range [0,6]. Isn't signalrangestr above a string ? Or at the very least, a number. I entered these numbers myself in designer, so they do not have any white-space (len(signalrangestr) returns 1). In any case, an attempt to use strip() fails with : Traceback (most recent call last): File "measure.py", line 908, in acquiredata np=self.getNPrange() File "measure.py", line 1169, in getNPrange signalrange=int(signalrangestr.strip()) AttributeError: strip From k04jg02 at kzoo.edu Sat Aug 6 01:52:04 2005 From: k04jg02 at kzoo.edu (Joseph Garvin) Date: Fri, 05 Aug 2005 23:52:04 -0600 Subject: ANN : dxPython 0.3.0 In-Reply-To: <1123288438.898030.317440@g49g2000cwa.googlegroups.com> References: <1123288438.898030.317440@g49g2000cwa.googlegroups.com> Message-ID: <42F45004.3050109@kzoo.edu> Atila Olah wrote: >In my opinion, you shoud make an (100%) English version of the site, if >you want more developers to join worldwide. > > > Isn't there some sort of Python directx thingy already? Surprised. From renting at astron.nl Fri Aug 26 04:36:59 2005 From: renting at astron.nl (Adriaan Renting) Date: Fri, 26 Aug 2005 10:36:59 +0200 Subject: file access dialog Message-ID: Well, I only know how to do it with Qt: Dialog = QFileDialog(self.filedir, 'Python files (*.py)', self, 'open file dialog') self.filename = str( Dialog.getOpenFileName()) I don't think PyQt is available for Qt4 on windows yet. You might be ablt to use this: http://www.quadgames.com/download/pythonqt/PyQtGPL10.exe Tk or wxWindows, or the Windows API itself might also be possible, I have no experience with them. Using either Tk or wxWindows should give a portable application as well. >>>Wouter van Ooijen www.voti.nl) 08/26/05 9:52 am >>> I have a tool in Python to which I want to add a small GUI. The tools currently runs everywhere PySerial is supported. I need a file-access dialog. What is the preffered way to to this? Is there a platform-independent file-access dialog available, or should I use the windows native version when running on windows (and how do I do that)? Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics -- http://mail.python.org/mailman/listinfo/python-list From theller at python.net Fri Aug 19 07:07:12 2005 From: theller at python.net (Thomas Heller) Date: Fri, 19 Aug 2005 13:07:12 +0200 Subject: Database of non standard library modules... References: Message-ID: <7jeixk0v.fsf@python.net> Steve Holden writes: > Robert Kern wrote: >> Jon Hewer wrote: >> >>>Is there an online database of non standard library modules for Python? >> http://cheeseshop.python.org/pypi >> > While cheeseshop might resonate with the Monty Python fans I have to > say I think the name sucks in terms of explaining what to expect. If I > ask someone where I can find a piece of code and the direct me to the > cheese shop, I might look for another language. +1 Thomas From __peter__ at web.de Tue Aug 16 12:24:33 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2005 18:24:33 +0200 Subject: looping list problem References: Message-ID: Jon Bowlas wrote: > Incidentally I'm doing this in zope. Many posters (including me) in this newsgroup don't do zope, so your best option is to ask on a zope-related mailing list. > I was hoping that this would loop through the elements in the list > returned by the hiddens function comparing them with the id of the current > value of c (bert) and if they are the same then it should ignore it and > move onto the next one, but it doesn't seem to do anything. > Ok, so I've adapted my script calling it a hiddens() function and included > it inside my get_tree_html function which creates my navigation: > > pub = context.get_publication() > obj = context.aq_inner > fpath = context.getPhysicalPath() > > def hiddens(): > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > return navstring.split(' ') > > def get_tree_html(node, endobj): > tree = '' > endpath = endobj.getPhysicalPath() > for c in node.get_ordered_publishables(): > if not c.is_published(): > continue > bert=c.getId(); > if bert=="index_right": > continue > if bert=="images": > continue > # this is where I loop through he elements returned by my hiddens > # function, comparing them with the value of bert Replace these lines > for element in hiddens(): > if element==bert: > continue # with the next hidden element with if bert in hiddens(): continue # with the next publishable c A 'continue' statement only affects the innermost loop, and as you don't have any code that follows it in the for-element-loop it didn't have any effect. Peter From daniel.dittmar at sap.corp Thu Aug 4 05:36:31 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Thu, 04 Aug 2005 11:36:31 +0200 Subject: API class creation In-Reply-To: References: Message-ID: kman3048 wrote: > Hello, > > as a relative newcomer to Python API programming I've got a problem: > > To extend Python: > - there is an API C call to create a module > - there is also a API C call to create a method > - there is an API C call to create a Class instance > > Now, I need to create a Class and fill it with Methods and Variables. > There are means to create (and attache) methods and variables. > However, I have not found how to create a Class within a Module. Or do > I have to use a low level API function to allocate an Object from Heap? static PyMethodDef moduleMethods [] = { ... }; statichere PyTypeObject MyClassType = { PyObject_HEAD_INIT (NULL) ... }; initmymodule () { PyObject* module; PyObject* dict; module = Py_InitModule4 ("mymodule", moduleMethods, "doc string", NULL, PYTHON_API_VERSION); if (module == NULL) { return; } dict = PyModule_GetDict (module); PyDict_SetItemString (dict, "MyClass"), (PyObject*) &MyClassType)); } Daniel From newpip at gmail.com Mon Aug 15 23:33:28 2005 From: newpip at gmail.com (new pip) Date: Tue, 16 Aug 2005 11:33:28 +0800 Subject: How to obtain GMT offset? Message-ID: I'm using Windows os. If the current system date time is '28 Jun 2001 14:17:15 +0700', how can I obtain the value '+0700' using python? Thank you From a_geek at web.de Sat Aug 13 11:42:00 2005 From: a_geek at web.de (a_geek at web.de) Date: Sat, 13 Aug 2005 17:42:00 +0200 Subject: catching all exceptions Message-ID: Hello, I'd like to catch all exeptions and be able to inspect them. The simple case: I know which exceptions I'll get: # standard textbook example: try: something() except ThisException, e: print "some error occurred: ", str(e) The not-so-simple case: Handling all other exceptions: # nice-to-have: try: something() except *, e: print "some error occurred: ", type(e), str(e) Well, actually the second statement doesn't even compile... any ideas why I shouldn't be able to catch "anonymous" exceptions like this, or whether and how I can (and only overlooked it)? TIA! Kind Regards, Toni From fredrik at pythonware.com Mon Aug 22 17:16:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 23:16:34 +0200 Subject: combining namespaces when importing two modules References: Message-ID: Donnal Walter wrote: >I would like to be able to write something like: > > import dcw as dw > import xyz as dw > > such that the 'dw' namespace includes definitions from both dcw and xyz, > but in the script above names from dcw1 are lost. How can I combine the > two? (I'd rather not use 'import *' why not? it's designed to make it easy to merge namespaces, so why not use it? $ more dw.py from dcw import * from xyz import * $ more myscript.py import dw ... From steve at holdenweb.com Mon Aug 29 16:32:59 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Aug 2005 16:32:59 -0400 Subject: NYC Opening In-Reply-To: <012b01c5ac9f$759d7c80$1300a8c0@asp0201> References: <012b01c5ac9f$759d7c80$1300a8c0@asp0201> Message-ID: <431370FB.3020205@holdenweb.com> Kevin McGann wrote: > A major Investment Bank is searching for a strong Java or C++ developer that > can build Pipes to Electronic Exchanges and ECNs. This is a new Internal > Hedge Fund Business and they are looking for superb C++ or Java programmers > that can enable them to go live in 1-2 months and begin trading. THIS IS AN > OPPORTUNITY TO WORK IN THE BUSINESS UNIT OF A MAJOR TOP-TIERED BANK!!!!! > Required Skills: > -Expert Java or C++ > -Extensive Multi-threading > -OOA/OOD Must have Design Patterns Experience > -Must have experience building Pipes/Connectivity Infrastructure/FIX > -Linux, Unix, SQL/RDBMS > Eventually this person will learn Stat/Arb business for Equities/FX and will > get to learn about trading strategies and work closely with Quants/Prop > Traders. > THEY ARE LOCATED IN NEW YORK, THIS IS FULL-TIME ONLY, WILL NOT CONSIDER > ANYONE FROM OUTSIDE THE US! THIS TEAM IS AN ELITE TEAM, YOU BETTER BE > GOOD!!!! > > Also have numerous opportunities so if you program in C++ or Java send me an > email or give me a call..... > --------------------------------------------- > Kevin M McGann > Senior Technology Recruiter > Continuity Partners Inc. > (212) 624-9187 > www.cpi-search.com > kmcgann at cpi-search.com > --------------------------------------------- > > It seems like this bank expects much more of its programmers than it does of its recruitment consultants ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gagaguy at gmail.com Wed Aug 3 22:42:39 2005 From: gagaguy at gmail.com (gagaguy at gmail.com) Date: 3 Aug 2005 19:42:39 -0700 Subject: quetion about "+=" and "runtime" Message-ID: <1123123359.768132.112990@g47g2000cwa.googlegroups.com> 1.i saw "+=" in a program code,but i haven't see it before,neither can i find it in a cook,who can tell me the usage of "python0" 2.how can i know how long does a program run? From max at alcyone.com Tue Aug 9 06:00:53 2005 From: max at alcyone.com (Erik Max Francis) Date: Tue, 09 Aug 2005 03:00:53 -0700 Subject: .pth files In-Reply-To: References: Message-ID: <7PydnT6VS7FI42XfRVn-hw@speakeasy.net> Richie Hindle wrote: > http://google.com/search?q=site:docs.python.org%20pth > > The first hit explains how .pth files work (although it's the sort of > documentation that makes Xah Lee explode with fury). That just makes it all the more delicious. -- 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 is another world, which is not of men. -- Li Bai From kbchung at hongik.ac.kr Fri Aug 12 06:07:02 2005 From: kbchung at hongik.ac.kr (KB) Date: 12 Aug 2005 03:07:02 -0700 Subject: How to quit a Windows GUI program gracefully with Python under Cygwin? In-Reply-To: <1123791622.954340.74930@o13g2000cwo.googlegroups.com> References: <1123761153.401824.43040@g49g2000cwa.googlegroups.com> <1123791622.954340.74930@o13g2000cwo.googlegroups.com> Message-ID: <1123841222.202745.259280@f14g2000cwb.googlegroups.com> Thanks. After I confirmed 'Alt-F4' would terminate and close a win32 application running independently, I installed 'SendKeys' module and tested with the following code under both Cygwin and Python Windows import os, SendKeys os.system('program datafile') SendKeys.SendKeys(""" {PAUSE 0.25} %{F4} """) What happened was that the 'program' ran correctly, but it stayed, not closing the window under Cygwin and Python Windows. So it seems to me that this does not work. One more thing: How do I control the pause time if I do not know the execution time of an application? Thanks in advance. KB From donn at drizzle.com Mon Aug 8 01:00:20 2005 From: donn at drizzle.com (Donn Cave) Date: Mon, 08 Aug 2005 05:00:20 -0000 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> Message-ID: <1123477219.899534@yasure> Quoth "Kay Schluehr" : | Paul Rubin wrote: [ ... re where to go from Python ] |> Lately I'm interested in OCAML as a possible step up from Python. It |> has bogosity of its own (much of it syntactic) but it has static |> typing and a serious compiler, from what I understand. I don't think |> I can grok it from just reading the online tutorial; I'm going to have |> to code something in it, once I get a block of time available. Any |> thoughts? | | The whole ML family ( including OCaml ) and languages like Haskell | based on a Hindley-Milnor type system clearly make a difference. I | would say that those languages are also cutting edge in language theory | research. It should be definitely interesting to you. Since there is no | single language implementation you might also find one that supports | concepts you need most e.g. concurrency: | | http://cml.cs.uchicago.edu/ My vote would be Haskell first, then other functional languages. Learning FP with Objective CAML is like learning to swim in a wading pool -- you won't drown, but there's a good chance you won't really learn to swim either. Has an interesting, very rigorous OOP model though. Donn Cave, donn at drizzle.com From mohammed at aims.ac.za Thu Aug 18 07:30:45 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Thu, 18 Aug 2005 13:30:45 +0200 Subject: List of string In-Reply-To: References: Message-ID: <43047165.9090203@aims.ac.za> >------------------------------------------------------------------------ > > > > >Mohammed Altaj wrote: > > >>Hi All >> >>I am having problem with delete line if its belong to another one , example >> >> > >I think, you mean to remove all lines that are substrings of another >line. > >l = ['0132442\n', '13\n', '24\n'] >l = [e.strip() for e in l] > >i = 0 >while True: > try: > for j in range(len(l)): > if i == j: > continue > if l[j].find(l[i]) >= 0: > # line 'j' is superstring of line 'i' > del l[i] > break > else: # doesn't have superstring > i += 1 > except IndexError: > break > >Basically, I try all n*n combinations, and remove substring lines >"in-place". > >BranoZ > > > > > Thanks , but , this work for an ordered substrings , just like what we had ['0132442\n', '13\n', '24\n'] , I would like to remove all substrings from the list , example ['0134314244133', '132443', '234'] 2nd and 3rd strings are also substrings from the 1st one , so it should be removed Thanks From uval at rz.uni-karlsruhe.de Fri Aug 5 12:16:38 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-15?Q?Daniel_Sch=FCle?=) Date: Fri, 05 Aug 2005 18:16:38 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: Hi Terry, >>In my opinion it would also be nice to have the >>possibility to write it as >>c.abs() >>it looks more OO > > > Python is object based but not rigidly OO in syntax or looks. This is an > intentional design decision. Not being gratuitiously redundant is another. I agree, redundancy confuses people >>unfortunately there is no arg method to get the angle >>of the complex number > > > I agree that this is a deficiency. I would think .angle() should be a > no-param method like .conjugate(), though its internal implementation would > need access to the appropriate cmath functions. I think returning radians > might be enough though. I don't know what nomenclature is used in english speaking mathematical world for angle of a complex number I learned it in german as Arg(z) .. Arg standing for argument you see, we would have named it differently, hence making it difficult for the reader, eventually creating redundancy > You could submit to the SourceForge tracker a RFE > (Request For Enhancement) if not a patch. I never did, but I will see >>> c = 1 + 1j >>> def arg(c, angle_mode = "RAD"): ... if angle_mode not in ("RAD", "GRAD"): ... raise ValueError ... import math ... ret = math.atan2(c.imag, c.real) ... if angle_mode == "GRAD": ... return ret / math.pi * 180 ... return ret it's pretty easy and straightforward implementation while writing this, I was struck by an idea and reimplemented it as following >>> def arg(self, angle_mode = "RAD"): ... if angle_mode not in ("RAD", "GRAD"): ... raise ValueError ... import math ... ret = math.atan2(self.imag, self.real) ... if angle_mode == "GRAD": ... return ret / math.pi * 180 ... return ret ... >>> class Complex(complex): pass >>> Complex.arg = arg >>> c = Complex(1+1j) >>> c.arg(angle_mode = "GRAD") 45.0 later I realized that this represents "yet another implementation" which could be done by someone, thus again leading to possible redundancy and confuse people all this would not have happened when we would have arg or angle builtin in complex type >>I would also like to see some more functions to make >>calculations with complex number more convenient >>e.g. >>c = 27 >>c.pow(numerator = 1, denominator = 3, >> mode = cmath.EULER, angle_mode = cmath.GRAD) >>-> ((3,0), (3,120), (3,240)) > > > Wanting all roots is fairly specialized. sqrt(4) is 2, not (2, -2). it could be named .allroots(n) -> ((), (), ()) with n whole number indeed .pow() is not a good name for it, since z**x always yields one complex number if x is 2.5 or alike, it could be aproximated with n/m and use res = [] for i in z.allroots(m): res.append(i**n) I am not sure, this is correct iterpretation of z**2.5 I will need to ask in math newsgroup :) and approximation might not be good enough > Have you looked for complex math functions in numpy, numarray, scipy or > similar packages? It is possible that a cmath2 module, written in Python, > could be useful. I hope so I will google for cmath2, I never heard about it I am new to Numeric and numarray, I was playing with them and ufunc-tionsand matplotlab, as for SciPy I couldnt find any binary for 2.4 Python unfortunately :-/ Regards -- Daniel From gene.tani at gmail.com Fri Aug 12 18:38:26 2005 From: gene.tani at gmail.com (gene tani) Date: 12 Aug 2005 15:38:26 -0700 Subject: Why is this? In-Reply-To: References: Message-ID: <1123886306.197187.105740@g43g2000cwa.googlegroups.com> I think you got your answer. FWIW, questions like this i usually look 1st in the Cookbook (i.e. the Oreilly dead trees, 2nd edition). See Chap. 4 And: My gotcha list, http://www.ferg.org/projects/python_gotchas.html http://zephyrfalcon.org/labs/python_pitfalls.html http://zephyrfalcon.org/labs/beginners_mistakes.html http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html http://www.norvig.com/python-iaq.html http://www.faqts.com/knowledge_base/index.phtml/fid/245 http://amk.ca/python/writing/warts From news at NOwillmcguganSPAM.com Tue Aug 23 07:28:49 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Tue, 23 Aug 2005 12:28:49 +0100 Subject: Doubt C and Python In-Reply-To: References: Message-ID: <430b0872$0$21931$db0fefd9@news.zen.co.uk> praba kar wrote: > Dear All, > I want to know the link between c and python. > Some people with C background use Python instead > of programming in C.why? > Because I can create software many times faster. And its more fun. Will McGugan -- http://www.kelpiesoft.com From daniel.dittmar at sap.corp Thu Aug 11 12:04:13 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Thu, 11 Aug 2005 18:04:13 +0200 Subject: len(sys.argv) in (3,4) In-Reply-To: References: Message-ID: Daniel Sch?le wrote: > if __name__ == "__main__": > if len(sys.argv) not in (3,4): > print "usage: prog arg1 argv2 [-x]" > # etc ... > > while develeoping I had my interpeter running and reloaded module > now since I am ready, I wanted to run it from cmd windows shell > but it always prints "usage ..." > I added print len(sys.arg) and it prints 1 though I am provinding more > than 1 value Add import sys print sys.argv at the top of the script before any other import. Maybe one of the modules you're importing messes with sys.argv Daniel From lycka at carmen.se Thu Aug 18 05:58:23 2005 From: lycka at carmen.se (Magnus Lycka) Date: Thu, 18 Aug 2005 11:58:23 +0200 Subject: up to date books? In-Reply-To: References: Message-ID: John Salerno wrote: > hi all. are there any recommendations for an intro book to python that > is up-to-date for the latest version? It depends on what kind of books you like, and of course on your previous experience. I think "Python: Visual QuickStart Guide" by Chris Fehily is a rather nice beginner's book, even if it's from 2001. It's also pretty cheap. I don't have it at hand now, but I suspect that it doesn't cover new style classes, generators, or list (or generator) comprehensions, but it's still a good intro. If you like a high density book, Alex Martelli's "Python in a Nutshell" is great, and if you like to see a bunch of recipes, "Python Cookbook, 2nd ed" is good. The cookbook recipes are also on the net, but the book does add value to them. > would reading a book from a year or two ago cause me to miss much? Probably not. Most recent changes to Python, such as decorators, are things that beginners might want to leave until later... New standard modules, such as datetime, are covered in the standard library manual. From lemon97 at gmail.com Mon Aug 8 14:04:21 2005 From: lemon97 at gmail.com (lemon97 at gmail.com) Date: 8 Aug 2005 11:04:21 -0700 Subject: Splitting a string into groups of three characters In-Reply-To: References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: <1123524261.112017.41540@f14g2000cwb.googlegroups.com> Yes i know i made a mistake, >['Hell','o W','orl','d'] but you know what I mean lol, I'll probly use John Machin's def nsplit(s, n): return [s[k:k+n] for k in xrange(0, len(s), n)] It seems fast, and does not require any imports. But anyways, thank you for all your help, you rpck! :) From spammers-go-here at spam.invalid Mon Aug 15 00:28:16 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Mon, 15 Aug 2005 00:28:16 -0400 Subject: Dynamic autoscaling of axes with pyqwt ? Message-ID: <430019c9$0$18642$14726298@news.sunsite.dk> How does one enable dynamic autoscaling of the axes ? I am using setAxisAutoScale in an application which acquires data, and when the application ends, I do get correctly autoscaled axes, but not while the measurement is in progress. From billiejoex at fastwebnet.it Thu Aug 11 20:45:28 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Fri, 12 Aug 2005 02:45:28 +0200 Subject: pcapy help Message-ID: <000501c59ed7$22cc51a0$5904ff29@startdus> Hi man! I found a post of yours in wich you tell that you use pcapy python module to capture packets. I need to do something similar but unfortunately I can't find too much domentation (and example codes) about this library. Can you paste me a simple code in wich you use this module for simply sniff network traffic? I made a simple 'data over ICMP' client that sends packets containing strings: http://billiejoex.altervista.org/a1.txt ...now I have to develop a simple server that sniffs them. Greetings billiejoex -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Aug 1 08:05:05 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Aug 2005 14:05:05 +0200 Subject: Py: a very dangerous language References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> Message-ID: Harald Massa wrote: > Always go to bed exactly when you want to write the first lambda. Eureka. The Twentieth Pythonic Thesis has finally surfaced. Peter From haircut at gmail.com Wed Aug 31 20:00:37 2005 From: haircut at gmail.com (Adam Monsen) Date: 31 Aug 2005 17:00:37 -0700 Subject: time.strptime() for different languages In-Reply-To: References: <1125519061.261802.285840@o13g2000cwo.googlegroups.com> <1125522144.209140.266590@f14g2000cwb.googlegroups.com> Message-ID: <1125532837.936681.271510@g47g2000cwa.googlegroups.com> Excellent! Thank you, Fredrik! -- Adam Monsen http://adammonsen.com/ From onurb at xiludom.gro Fri Aug 26 06:29:32 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 26 Aug 2005 12:29:32 +0200 Subject: problem with classes In-Reply-To: <1125051555.534857.317790@g47g2000cwa.googlegroups.com> References: <1125051555.534857.317790@g47g2000cwa.googlegroups.com> Message-ID: <430eef0d$0$300$626a14ce@news.free.fr> cfgauss wrote: > I am having a strange problem with classes. I'm fairly sure the > problem is with classes, anyway, because when I re-write the program > without them, it works like I'd expect it to. > > When I run this program, at first, L[0].z[1] is 0, because z=[0,0]. > But after I run that loop to assign different values to L[1].z[0] and > L[1].z[1], somehow the value of L[0].z[1] has changed to 1. I have no > idea why this is happening, can anyone help me? > > class Stuff: > z=[0,0] This is a class attribute (shared by all instances of Stuff), not an instance attribute. To define instance attribute, the syntax is: class Stuff(object): def __init__(self): self.z = [0, 0] -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From nmichaud at jhu.edu Mon Aug 15 16:51:28 2005 From: nmichaud at jhu.edu (nmichaud at jhu.edu) Date: Mon, 15 Aug 2005 16:51:28 -0400 (EDT) Subject: Implementing class methods in C Message-ID: I am having a problem implementing some methods of a python class in C. The class is defined in python, but I would like to rewrite some methods in c. Here is an example of what I want to do: file _test.c: #include static PyObject * func2(PyObject *self, PyObject *args) { if (self == NULL) { PyErr_SetString(PyExc_SystemError, "self is NULL"); return NULL; } // Parse arguments if (!PyArg_ParseTuple(args, "")) { return NULL; } Py_INCREF(Py_None); return Py_None; } static PyMethodDef TestMethods[] = { {"func2", func2, METH_VARARGS, "func2."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC init_test(void) { (void) Py_InitModule("_test", TestMethods); } ---------------------------------------------------- test.py: class Test: def func1(self): print "I am in func 1" import _test import new Test.func2 = new.instancemethod(_test.func2, None, Test) del(new) t = Test() t.func2() When I run test.py, I get a SystemError exception (which is what I raise if self is NULL). I think my confusion lies in the use of PyObject* self in the function declaration. Shouldn't this be set to point to the instance of class Test that I am calling it from? Am I misunderstanding the purpose of PyObject* self? Thanks. Naveen --------------------------------------------------------------------- Naveen Michaud-Agrawal Program in Molecular Biophysics Johns Hopkins University (410) 614 4435 From andy at mkaeurope.com Fri Aug 19 08:44:15 2005 From: andy at mkaeurope.com (Andy W) Date: Fri, 19 Aug 2005 12:44:15 GMT Subject: Adobe COM with Python Message-ID: I'm wanting to automate Adove Acrobat Reader using Com thru Python and win32com, but i can't find any documentation for the Adobe stuff? Has anyone done anything with Acrobat COM ? I've searched Google groups and the web but am unable to find anything. Thanks Andy From peter at engcorp.com Thu Aug 25 10:13:13 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 25 Aug 2005 10:13:13 -0400 Subject: Newbie question: Sub-interpreters for CAD program In-Reply-To: References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: Terry Hancock wrote: > On Wednesday 24 August 2005 09:12 pm, Peter Hansen wrote: >>Or even http://www.pythoncad.org/ which, although probably for >>mechanical CAD work (I haven't looked at it, don't really know), is >>surely a good place to get ideas of what Python can do in this area. > > No, I doubt it. PythonCAD is a 2D mechanical CAD drawing system. > I don't think it would be anywhere near what this guy wants. They're > just different applications. He's looking for an electronic CAD system or > EDA, I'm pretty sure (or looking to write one, rather). As an engineer who's worked extensively in both kinds of systems (primarily designing microcontroller-based circuit boards), and a programmer who's stolen useful ideas from endless amounts of other people's code, I'll say only that I disagree with your implication that looking at PythonCAD will give him no useful ideas whatsoever about how certain aspects of CAD programs could be handled. PCB layout programs do, after all, have to do the basic work of displaying circuits (which as you know are generally shown as 2D drawings). -Peter From spe.stani.be at gmail.com Fri Aug 12 23:02:10 2005 From: spe.stani.be at gmail.com (spe.stani.be at gmail.com) Date: 12 Aug 2005 20:02:10 -0700 Subject: Python IDE's In-Reply-To: References: Message-ID: <1123898695.436939.81950@o13g2000cwo.googlegroups.com> You might try out the next version of SPE 0.7.5.b which will ship with wxGlade for GUI Design and the Python Debugger of Nir Aides. Since 0.7.5.a it's also possible to customize your keyboard shortcuts. Stani http://pythonide.stani.be http://pythonide.stani.be/screenshots From http Fri Aug 26 17:31:50 2005 From: http (Paul Rubin) Date: 26 Aug 2005 14:31:50 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> Message-ID: <7xslwwjsft.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > The try/except pattern is a pretty basic part of Python's design. One > could say the same about clutter for *every* function or method that raises > an exception on invalid input. Should more or even all be duplicated? Why > just this one? Someone must have thought str.find was worth having, or else it wouldn't be in the library. From cam.ac.uk at mh391.invalid Wed Aug 3 13:25:16 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Wed, 03 Aug 2005 18:25:16 +0100 Subject: Art of Unit Testing In-Reply-To: References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> Message-ID: Benjamin Niemann wrote: > Christoph Zwerschke wrote: > > >>Benjamin Niemann wrote: >> >>>Some (many?) people don't like the unittest module, because it is not >>>very pythonic - nothing to wonder as it has its root in the Java world. >>>That's probably one of the reasons why there are other (more pythonic) >>>unittesting frameworks for Python out there. >> >>So I think it would have been better that "unittest" had been named >>"PUnit" to make clear that it is a JUnit port and to allow a more >>pythonic testing framework to be added to the Python's standard lib. > > > It was called PyUnit before it was integrated into the stdlib. Dunno why it > was renamed... unittest describes exactly what it does. pyunit says that it is in Python (duh), and that it has something to do with units, which could be a whole number of things. I'm thankful that logging is called logging as well, rather than log4py. -- Michael Hoffman From autocrat132000 at yahoo.com Sun Aug 28 19:16:25 2005 From: autocrat132000 at yahoo.com (Beginner/Not Yet Programmer) Date: 28 Aug 2005 16:16:25 -0700 Subject: Question Message-ID: <1125270985.457418.17830@g44g2000cwa.googlegroups.com> I've never programmed before, so I thought I'd try and learn a bit by using some Python tutorials. I started using the tutorial at http://www.honors.montana.edu/~jjc/easytut/easytut/node3.html. It mentioned different forms of Python, specifically Command Line and IDLE. Being inexperienced, I'm not sure how to change from Command Line to IDLE, and I'm not sure which one I'm in when I start up the program. In my Python folder, the only applications I have are python.exe and pythonw.exe. Pythonw.exe won't run. So, I run python.exe, and I'm not sure whether it is IDLE, Command Line, or neither. Also, I'm unsure of how to save programs, considering when I run python.exe, it opens up a window which does not have the little bar with the "File", "Edit", "View" and "Help" buttons on it. If you can help me out at all, thank you. From bokr at oz.net Wed Aug 24 06:27:52 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 24 Aug 2005 10:27:52 GMT Subject: Externally-defined properties? References: Message-ID: <430c47ec.2286062163@news.oz.net> On Wed, 24 Aug 2005 01:15:03 -0500, Terry Hancock wrote: >Frankly, I was surprised this worked at all, but I tried >creating a property outside of a class (i.e. at the module >level), and it seems to behave as a property: > >>>> def get_x(ob): >... global x >... return str(x) >... >>>> def set_x(ob, value): >... global x >... x = int(value) >... >>>> def del_x(ob): >... global x >... del x >... >>>> def x_access(): >... return property(get_x, set_x, del_x, "X defined externally?") >... >>>> >>>> class Accessor(object): >... s_x = x_access() >... def __str__(self): >... print "Accessor has x = %s" % self.s_X >... >>>> a = Accessor() >>>> a.s_x = 3 >>>> a.s_x >'3' >>>> dir() >['Accessor', '__builtins__', '__doc__', '__name__', 'a', 'del_x', 'get_x', 'p', 'set_x', 'x', 'x_access'] >>>> x >3 > >(of course in the real example, x will probably be in an >entirely different module, used as a library -- the client code >just calls a function to get a property that is automatically >managed for it). > >So far, the only problem I see is that it only works if the >property is assigned to a new-type class attribute (otherwise, >the first assignment simply replaces the property). > >I'm thinking of using this to tie a property of a class to an >external data source (a joystick axis, in fact -- or at least >its last-polled value). > >There is a more convential way to do this, of course -- I could >just use a "get_value" function, but there is something attractive >about have a variable that is simply bound to the external >data source like this. It seems like a good way to encapsulate >functionality that I don't really want the high level class to >have to "think" about. > >I mention it here, because I've never seen a property used >this way. So I'm either being very clever, or very dumb, >and I would be interested in opinions on which applies. ;-) > >Am I about to shoot myself in the foot? > ISTM you are basically exploiting your freedom to define the getter/setter/deleter functions of a property any way you please. Another way, if you just want a proxy object whose property attributes access designated other objects' attributes, you could use a custom descriptor class, e.g., >>> class Indirect(object): ... def __init__(self, tgtattr, tgtobj): ... self.tgtattr = tgtattr ... self.tgtobj = tgtobj ... def __get__(self, inst, cls=None): ... if inst is None: return self ... return getattr(self.tgtobj, self.tgtattr) ... def __set__(self, inst, value): ... setattr(self.tgtobj, self.tgtattr, value) ... def __delete__(self, inst): ... delattr(self.tgtobj, self.tgtattr) ... A place to put properties: >>> class Accessor(object): pass ... An example object to access indirectly >>> class Obj(object): pass ... >>> obj = Obj() Making Accessor instance attribute 'xobj' access 'obj' attribute of Obj instance obj >>> Accessor.xobj = Indirect('obj', obj) An Accessor instance to use for the property attribute magic >>> a = Accessor() Set obj.obj = 123 indirectly >>> a.xobj = 123 Check >>> vars(obj) {'obj': 123} Set up access to an object attribute in a different module >>> import sys >>> Accessor.sin = Indirect('stdin', sys) >>> a.sin ', mode 'r' at 0x02E8E020> >>> Accessor.pi = Indirect('pi', __import__('math')) >>> a.pi 3.1415926535897931 >>> a.pi = 3 >>> a.pi 3 >>> import math >>> math.pi 3 I'd say there's possibilities for shooting yourself in the foot. Maybe passing a code to Indirect to enable get/set/del selectively would help. Regards, Bengt Richter From jrastrick at student.usyd.edu.au Wed Aug 24 00:54:40 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 23 Aug 2005 21:54:40 -0700 Subject: list insertion In-Reply-To: References: Message-ID: <1124859280.858982.136980@g47g2000cwa.googlegroups.com> What you've posted looks right, more or less. To get any sort of meaningful feedback, you really need to post a full version of your code, including the print statements, what's being printed, and why you think this shows the code is not working. What you've shown is far too little for anybody else to work with. Regards, Jordan Randy Bush: > i am trying to insert into a singly linked list > > hold = self.next > self.next = DaClass(value) > self.next.next = hold > > but i suspect (from print statement insertions) that the result > is not as i expect. as the concept and code should be very > common, as i am too old for pride, i thought i would ask. > > mahalo, > randy From dominant500 at comcast.net Fri Aug 19 22:37:42 2005 From: dominant500 at comcast.net (Mark) Date: 19 Aug 2005 19:37:42 -0700 Subject: Moinmoin config References: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> <18da$4304e393$506cf87a$23485@news.chello.at> Message-ID: <1124505462.437697.107950@z14g2000cwz.googlegroups.com> The missing link under /var/www/html was exactly the problem. Somehow missed this in the labyrinth of setup instructions. I have another question, and as of yet, have not found another discussion group for moinmoin, so sorry, but here goes: I have a table and would like the table borders to go away. Although it doesn't talk about border widths explicitliy, the HelpOnTables seems to point to this : But that does nothing to the border lines. Adjusting width in the same line does work to change the size of the table, but it doesn't seem to understand 'border'. Anyone know how to make the borders disappear? Thanks Mark From matt.hammond at rd.bbc.co.uk Fri Aug 19 09:06:52 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Fri, 19 Aug 2005 14:06:52 +0100 Subject: Problem (or even bug?) with Tkinter References: Message-ID: Thanks for that. I've tested your script and it seems to have the same problem, so I'll post your example across in comp.lang.tcl as you suggest. Seems I'm running tcl/tk 8.4.9, and wish 8.4 cheers Matt > I suspect a bug at tcl level. So can you execute the following tcl > script: > > ------- > entry .en1 > grid .en1 -row 0 -column 1 > > label .lb1 -text "CAN WRITE ->" > grid .lb1 -row 0 -column 0 > > > label .lb2 -text "CAN'T WRITE ->" > grid .lb2 -row 1 -column 0 > > entry .en2 > grid .en2 -row 1 -column 1 > ------- > > It is exactly the same as yours in tcl syntax. To execute it, just save > it to the file script.tcl and type in a shell: > wish script.tcl -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From deets at nospam.web.de Fri Aug 26 10:52:16 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Aug 2005 16:52:16 +0200 Subject: need a little help with time In-Reply-To: <1125065840.477157.43290@g47g2000cwa.googlegroups.com> References: <1125065840.477157.43290@g47g2000cwa.googlegroups.com> Message-ID: <3n8okuFdme4U1@uni-berlin.de> nephish at xit.net wrote: > Hey there. > i have a time string (created with strftime) then read from a file, > i am having some trouble understanding how to get the difference > between times. > i know i can structime(timestring) and get a time value, but i dont > know how to manipulate it. > > basically, if i have string 2005-08-24 09:25:58 > and another string 2005-08-24 09:28:58 > > how can i tell how many minutes, hours, seconds, days, months etc.. > have passed between the first string and the second ? > > or, if there is a good tutorial on this kind of thing, please post a > url. Look at the module datetime. Diez From mwm at mired.org Tue Aug 9 21:47:07 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 09 Aug 2005 21:47:07 -0400 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> Message-ID: <861x52lg10.fsf@bhuda.mired.org> geskerrett at hotmail.com writes: > I was wondering if anyone could make recomendations/comments about CVS > systems, their experiences and what perhaps the strengths of each. Perforce. it costs money, but it's worth it. My current client uses subversion, and I generally wind up cursing at it at least once a day. Perforce is much smarter about merges and dealing with branches. Also, if you like using Unix tools to do things like search your sources or build tags files, Perforce doesn't leave turds in your development tree. > Currently we have 2 developers but expect to grow to perhaps 5. You can use the unlicensed server with two developers (and two clients). I'd recommend giving it a try. If you don't like it, there are tools to convert the repository to subversion, which seems to be gettign the most support in your replies. > Most of the developement is Python, but some C, Javascript, HTML, etc. Perforce integrates really well with python - it can be told to output marshalled python objects. There's also a nice wrapping for the perforce library available from PyPI. Building tools to get perforce to enforce policy in Python is a snap. > The IDE what have been using/experimenting with are drPython and > eclipse with PyDev. Can't help about that. It integrates nicely with Emacs, and things that use MS's standard API for talking to source source code control systems on Windows. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From greggandliz1911 at comcast.net Sun Aug 14 20:46:26 2005 From: greggandliz1911 at comcast.net (Gregg Furukawa) Date: Sun, 14 Aug 2005 17:46:26 -0700 Subject: Freqmess string tension measure program for Pocket PC handheld devices? Message-ID: <000501c5a132$c52f8630$0200a8c0@GreggLiz> Hi Marc, In regards to your Freqmess (String tension measuring program), will you make a version that I can use on my Pocket PC handheld device (HP hx4700) which uses Window Mobile 2003 Second Edition operating system? This would be great since it would allow me to have a portable measuring device. Please let me know and have a great day :) Gregg Furukawa Salem, Oregon USA -------------- next part -------------- An HTML attachment was scrubbed... URL: From fakeaddress at nowhere.org Fri Aug 26 05:37:31 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 26 Aug 2005 09:37:31 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> Message-ID: Antoon Pardon wrote: > Bryan Olson schreef: > >>Steve Holden asked: >>>And what are you proposing that >>>find() should return if the substring isn't found at all? please don't >>>suggest it should raise an exception, as index() exists to provide that >>>functionality. >> >>There are a number of good options. A legal index is not one of >>them. > > IMO, with find a number of "features" of python come together. > that create an awkward situation. > > 1) 0 is a false value, but indexes start at 0 so you can't > return 0 to indicate nothing was found. > > 2) -1 is returned, which is both a true value and a legal > index. > > It probably is too late now, but I always felt, find should > have returned None when the substring isn't found. None is certainly a reasonable candidate. The one-past-the-end value, len(sequence), would be fine, and follows the preferred idiom of C/C++. I don't see any elegant way to arrange for successful finds always to return a true value and unsuccessful calls to return a false value. The really broken part is that unsuccessful searches return a legal index. My suggestion doesn't change what find() returns, and doesn't break code. Negative one is a reasonable choice to represent an unsuccessful search -- provided it is not a legal index. Instead of changing what find() returns, we should heal the special-case-when-index-is-negative-in-a-certain-range wart. -- --Bryan From uval at rz.uni-karlsruhe.de Fri Aug 5 12:24:26 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Fri, 05 Aug 2005 18:24:26 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: >>c = 1+1j >>c.arg(angle_mode = cmath.GRAD) -> 45.0 > > > Is that right? The result looks more like Degrees... maybe I confuse, in german one would say "45 Grad" I took a freedom to translate it directly :) well, my calculator shows a "D" which most likely stands for Degree, I cannot tell for sure -- Daniel From peter at somewhere.com Wed Aug 17 14:31:47 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 17 Aug 2005 20:31:47 +0200 Subject: Obfuscator for Python Code In-Reply-To: <1124298063.074422.252770@g14g2000cwa.googlegroups.com> References: <1124298063.074422.252770@g14g2000cwa.googlegroups.com> Message-ID: codecraig schrieb: > Is there any obfuscator out there that obfuscates the python code (byte > code i guess)??? http://www.lysator.liu.se/~ast rand/projects/pyobfuscate/ -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From google at phaedro.com Wed Aug 24 15:59:52 2005 From: google at phaedro.com (google at phaedro.com) Date: 24 Aug 2005 12:59:52 -0700 Subject: SocketServer and a Java applet listener Message-ID: <1124913592.821488.204350@g47g2000cwa.googlegroups.com> Dear newsgroup, I give up, I must be overseeing something terribly trivial, but I can't get a simple (Java) applet to react to incoming (python) SocketServer messages. Without boring you with the details of my code (on request available, though), here is what I do : I have a TCPServer and BaseRequestHandler . Connecting via telnet : everything goes OK. Connecting from Applet : problem 1 (worked around it) : java has some 'propietary' UTF-8 format, python's unicode doesn't seem to handle it correctly and I have to strip the first two bytes/chars , then all goes OK . problem 2: I have tried IMHO everything. In the BaseRequestHandler.handle() method, I want to update a list of clients in the server, i.e.: self.server.players[username] = self self := instance of the BaseRequestHandler, I only do this after succesfull connect , i.e. first time socket. I assume (wrongfully?) that I can now use the self.request socket for future transmissions to the client. In the applet, I start a thread that listens to the socket by eternally looping over: String line = self.din.readUTF() if (line == null) break; handle(line); self := instance of Thread self.din := DataInputStream(socket.getInputStream()); (It's a bit simplistic, but I am quite sure (well...) I got those things right, the issue seems to me to lie in some weird java-python-socket anomaly having to do with close()/flush() etc. ...) However, the handle(line) method only seems to get called when I destroy (close ?) the socket on the server side. I tried making it a wfile (socket.makefile) and calling the flush() method. Moreover, I searched and googled and couldn't find reference to a working implementation of a python SocketServer sending to a java Applet (socket listener). Would be much appreciated if anyone knows such a reference ? Any pointers to correct handling of the 'java propietary UTF-8 format' in python (xml.sax) would also be appreciated. Skipping the first two bytes really is a smelly workaround, I know, *deep sigh*... -- Thijs Cobben www.phaedro.com From mwm at mired.org Tue Aug 30 21:28:52 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 30 Aug 2005 21:28:52 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> <864q98b7k0.fsf@bhuda.mired.org> <43149abd.168178447@news.oz.net> Message-ID: <86aciyao8b.fsf@bhuda.mired.org> bokr at oz.net (Bengt Richter) writes: > On Tue, 30 Aug 2005 05:15:34 GMT, Bryan Olson wrote: >>Mike Meyer wrote: >> > Bryan Olson writes: >> >> > Bryan Olson writes: >> >> > Trivially, an 'if' statement that depends upon input >> >> >>data is statically predictable. Use of async I/O means makes the >> >> >>programs execution dependent upon external timing. >> >>Mike Meyer wrote: > [...] >> >> >> > [...] I'm calling the tools available in most programming >> >> > languages for dealing with it primitive. >> >> > We need better tools. >> >>Agreed, but if 'select' is someone's idea of the state of the >> >>art, they have little clue as to the tools already available. >> > >> > Well, share! >> >>Uh, where have you been? I keep explaining that concurrency >>systems have improved vastly in recent years. For a long time, >>the most sophisticated software services generally have used >>multiple lines of execution, and now that's mostly in the form >>of threads. No one actually disagrees, but they go right on >>knocking the modern methods. > > I think Mike is asking for references/citations/links to the > "concurrency systems" and "modern methods" you are talking about ;-) > (I'd be interested too ;-) Yup. I know systems are getting more concurrent. I also find that the tools in popular languages for dealing with concurrency suck. I know of some of these tools myself, but they either have restrictions on the problems they can solve (like async I/O) or don't integrate well with Python (like SCOOP). So I'm definitely interested in learning about other alternatives! http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From richardjones at optushome.com.au Wed Aug 10 01:13:55 2005 From: richardjones at optushome.com.au (richard) Date: Wed, 10 Aug 2005 15:13:55 +1000 Subject: Oreilly CodeZoo References: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> <42f6f81c$0$8993$afc38c87@news.optusnet.com.au> <4q2ks2-lpi.ln1@strongwill.g2ctech> Message-ID: <42f98d14$0$21677$afc38c87@news.optusnet.com.au> Jorge Godoy wrote: > A subtree with version numbers could solve the problem of storing > information for old versions when a new one is added. > > With regards to 4, I'd like to see the "Topic" category in the beginning > of the page -- this is what most people search, I guess -- and not at the > bottom of it. That's a good idea. Unfortunately, changing the sorting of the classifiers will be fun. Could I ask you to submit an RFE "bug" via the link on the pypi page? > Also, there's a discrepancy on the amount of packages stored. The > categorization page says there are 679 packages. The main page says there > are 852. I believe the categorization page does what I suggested and > disregard different versions of the same software. I think this (679) is > the correct number. Yep, this is related to your other comment regarding my 6th point. Also, I don't believe packages are included in the browse if they have no classifiers. > Ah! And an RSS feeder would be interesting, to know when there are new > packages or when a package has been upgraded... ;-) There's a top-level RSS feed, but not one per-package. > I hope you see this as a constructive feedback from someone that has just > screened the pages, getting to know it. Thanks! Richard From nospam at here.com Mon Aug 15 10:41:18 2005 From: nospam at here.com (Matt Feinstein) Date: Mon, 15 Aug 2005 10:41:18 -0400 Subject: Gotchas in user-space matplotlib install? References: <626hf1lp7k492cbcq4o1mqhe3hnaqpbhf5@4ax.com> <87d5okurgh.fsf@peds-pc311.bsd.uchicago.edu> <5f51g1hm6ajl5v0qnrqu1635nldjbvqp2g@4ax.com> <87d5ofxppq.fsf@peds-pc311.bsd.uchicago.edu> Message-ID: On Mon, 15 Aug 2005 09:02:57 -0500, John Hunter wrote: >>>>>> "Matt" == Matt Feinstein writes: > > Matt> All in all, not actually excruciating-- and now I have a > Matt> working version of matplotlib! Matt Feinstein > >Great! While this is all fresh in your mind, would you be able to add >a wiki entry at >http://www.scipy.org/wikis/topical_software/MatplotlibCookbook > >Thanks, I'm making notes on it now. The only thing that the installation really stumbled over was some includes-- the Python installation left me with a '/usr/people/mrf/python24/include' directory, which at the matplotlib installation had 'python' and 'python2.4' subdirectories-- numarray put its includes into the 'python2.4' subdirectory, while Numeric put its includes into the 'python' subdirectory. The matplotlib installer found the numarray includes but not the Numeric includes-- copying the Numeric includes into the 'python2.4' subdirectory got the ball rolling again. Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From onurb at xiludom.gro Tue Aug 23 06:10:29 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 23 Aug 2005 12:10:29 +0200 Subject: loop in python In-Reply-To: References: <20050823065501.GA24558@mrna.tn.nic.in> Message-ID: <430af616$0$13099$626a14ce@news.free.fr> Steve Holden wrote: (snip) > If you want a fast language, try Holden. I've just invented it. > Unfortunately it gets the answer to every problem wrong unless the > answer is 42, but boy it runs quickly. The code for the whole > interpreter (it's written in Python) follows: > > print 42 > keyboard ! -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From tim.peters at gmail.com Tue Aug 9 10:49:49 2005 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 9 Aug 2005 10:49:49 -0400 Subject: issues with doctest and threads In-Reply-To: <1123580365.838675.182080@g14g2000cwa.googlegroups.com> References: <1123490815.549233.116220@g14g2000cwa.googlegroups.com> <1123580365.838675.182080@g14g2000cwa.googlegroups.com> Message-ID: <1f7befae05080907492e2c6f9@mail.gmail.com> [Michele Simionato] > Thank you for your replies Jeff & Tim. The snippet I submitted is > unfortunate, since I was writing an example (for a Python course I am > going to give in September) to show that you cannot reliably assume > that you will get exactly 9 dots, because of the limitations of 'sleep'. > Mindlessly, I have cut & pasted that snippet, but my real question > was not "how many dots I get", it was: "why the error message talks > about 'thread' not being in the globals?" It's true that I can avoid it with > a thread.join() (which I had forgot), but still I really cannot understand the > reason for such message. Because the program is buggy: synchronizing threads isn't a "do it if you feel like it" thing, it's essential to correct threaded behavior. If you're going to show students bad thread practice, they're going to get mysteries a lot deeper and more damaging than this one <0.5 wink>. Add some more prints: """ >>> import time, threading >>> def example(): ... thread.out = [] ... while thread.running: ... time.sleep(.01) ... print [11] ... thread.out.append(".") ... print [12] ... print [13] >>> thread = threading.Thread(None, example) >>> thread.running = True; thread.start() >>> time.sleep(.1) >>> thread.running = False >>> print thread.out ['.', '.', '.', '.', '.', '.', '.', '.', '.'] """ if __name__ == "__main__": import doctest doctest.testmod() print [2] Here's a typical run on my box: File "blah.py", line 13, in __main__ Failed example: time.sleep(.1) Expected nothing Got: [11] [12] [11] [12] [11] [12] [11] [12] [11] [12] [11] [12] [11] [12] [11] [12] [11] [12] ********************************************************************** 1 items had failures: 1 of 7 in __main__ ***Test Failed*** 1 failures. [2] [11] Exception in thread Thread-1: Traceback (most recent call last): File "C:\Code\python\lib\threading.py", line 444, in __bootstrap self.run() File "C:\Code\python\lib\threading.py", line 424, in run self.__target(*self.__args, **self.__kwargs) File "", line 6, in example NameError: global name 'thread' is not defined Note that [2] is printed _while_ the spawned thread is still running ([13] is never printed): the call to doctest.testmod() is completely finished, but you're still letting a thread spawned _by_ doctest run. The environment doctest set up for that thread is gone too. Although it doesn't actually matter in this specific example, because the main thread (not just doctest) is also entirely done, the Python interpreter starts tearing itself down. Why that last doesn't matter in this example would take some time to explain; I don't think it's needed here, because the test case got into mortal trouble for an earlier reason. > Why it is so misleading? Simply because bad thread programming has allowed a thread to run beyond the time resources it relies on have vanished. It may sound harsh, but this is tough love : it's pilot error. > Can something be done about it? Properly synchronize the thread, to enforce what the code requires but cannot hope to obtain by blind luck. All it takes is the thread.join() I suggested. I don't understand why you're fighting that, because it's basic proper thread practice -- it's not like I suggested an obscure expert-level hack here. If a student doesn't know to join() a thread before they rely on that thread being done, their thread career will be an endless nightmare. All that said, this specific failure would _happen_ to go away too, if in doctest's DocTestRunner.run(), the final 'test.globs.clear()" were removed. If you feel it's necessary to let threads spawned by a doctest run beyond the time doctest completes, you can arrange to invoke DocTestRunner.run() with clear_globs=False. That's not an intended use case, but it will work. The intended use case is explained in run's docstring: The examples are run in the namespace `test.globs`. If `clear_globs` is true (the default), then this namespace will be cleared after the test runs, to help with garbage collection. If you would like to examine the namespace after the test completes, then use `clear_globs=False`. From bokr at oz.net Wed Aug 31 03:54:30 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 31 Aug 2005 07:54:30 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> Message-ID: <43156165.219034725@news.oz.net> On 31 Aug 2005 07:26:48 GMT, Antoon Pardon wrote: >Op 2005-08-30, Bengt Richter schreef : >> On 30 Aug 2005 10:07:06 GMT, Antoon Pardon wrote: >> >>>Op 2005-08-30, Terry Reedy schreef : >>>> >>>> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message >>>> news:7xy86k3r7n.fsf at ruckus.brouhaha.com... >>>> >>>>> Really it's x[-1]'s behavior that should go, not find/rfind. >>>> >>>> I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely >>>> useful, especially when 'x' is an expression instead of a name. >>> >>>I don't think the ability to easily index sequences from the right is >>>in dispute. Just the fact that negative numbers on their own provide >>>this functionality. >>> >>>Because I sometimes find it usefull to have a sequence start and >>>end at arbitrary indexes, I have written a table class. So I >>>can have a table that is indexed from e.g. -4 to +6. So how am >>>I supposed to easily get at that last value? >> Give it a handy property? E.g., >> >> table.as_python_list[-1] > >Your missing the point, I probably didn't make it clear. > >It is not about the possibilty of doing such a thing. It is >about python providing a frame for such things that work >in general without the need of extra properties in 'special' >cases. > How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ? That would give a consitent interpretation of seq[-1] and no errors for any value ;-) Regards, Bengt Richter From peter at engcorp.com Sat Aug 13 12:14:12 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 13 Aug 2005 12:14:12 -0400 Subject: thread limit in python In-Reply-To: References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> <1123859196.289006.200380@g44g2000cwa.googlegroups.com> Message-ID: Bryan Olson wrote: > Peter Hansen wrote: > > Probably, but I haven't yet seen anyone ask the real important question. > > What possible use could you have for more than 1000 *simultaneously > > active* threads? There are very likely several alternative approaches > > that will fit your use case and have better characteristics (e.g. higher > > performance, simpler code, safer architecture, etc). > > Threading systems have come a long way in the last decade or so, > and they're still advancing. 64-bit, multi-core processors make > mega-threading even more attractive. > > To read why zillions of threads are good, see: > http://www.usenix.org/events/hotos03/tech/vonbehren.html Judging by the abstract alone, that article promotes "user-level" threads, not OS threads, and in any case appears (with a quick scan) to be saying nothing more than that threads are not *inherently* a bad idea, just that current implementations suffer from various problems which they believe could be fixed. My question was in the context of the OP's situation. What possible use for 1000 OS threads could he have? (Not "could his requirements be answered with a non-existent proposed improved-performance implementation of threads?") > Prediction: Ten years from now, someone will ask that same > "What possible use..." question, except the number of threads > will be a million. Perhaps. And in ten years it will still be a valid question whenever the context is not fully known. Is the OP's situation IO-bound, CPU-bound, or just an experiment to see how many threads he can pile on the machine at one time? The fact that these threads are all sleeping implies the latter, though what he posted could have been a contrived example. I'm interested in the real requirements, and whether more than 1000 threads in this day and age (not some imaginary future) might not be a poor approach. (For the record, Bryan, I am a strong proponent of thread systems for many of the reasons the authors of that article put forth. None of which means my question was without merit.) -Peter From max at alcyone.com Fri Aug 5 15:37:18 2005 From: max at alcyone.com (Erik Max Francis) Date: Fri, 05 Aug 2005 12:37:18 -0700 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: Daniel Sch?le wrote: > maybe I confuse, in german one would say "45 Grad" > I took a freedom to translate it directly :) > well, my calculator shows a "D" > which most likely stands for Degree, I cannot tell for sure Probably. In English, you have degrees and gradians, which aren't the same thing; gradians are defined so that there are 400 gradians in a circle (so 100 gradians in a right angle). -- 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 am not afraid / To be a lone Bohemian -- Lamya From temposs at gmail.com Tue Aug 2 13:23:31 2005 From: temposs at gmail.com (temposs at gmail.com) Date: 2 Aug 2005 10:23:31 -0700 Subject: a pickle's pickle References: <1122998518.750304.191860@g44g2000cwa.googlegroups.com> Message-ID: <1123003411.326539.300220@g47g2000cwa.googlegroups.com> I intended to pickle the class instance I call trainer...from my code, also in the first post: trainerString = trainDB.read() trainer = loads(trainerString) except EOFError: trainer = TrainingMatrix() ... trainerString = dumps(trainer) ... So basically trainer always gets an existing TrainingMatrix(the class) pickled object if there is a file to read from, otherwise it just makes a new instance. Either way, the instance trainer is pickled at the end. Maybe I'm missing something... From talin at acm.org Fri Aug 12 15:44:11 2005 From: talin at acm.org (Talin) Date: Fri, 12 Aug 2005 12:44:11 -0700 Subject: Dictionary inheritance Message-ID: <42FCFC0B.8070903@acm.org> I want to make a dictionary that acts like a class, in other words, supports inheritance: If you attempt to find a key that isn't present, it searches a "base" dictionary, which in turn searches its base, and so on. Now, I realize its fairly trivial to code something like this using UserDict, but given that classes and modules already have this behavior, is there some built-in type that already does this? (This is for doing nested symbol tables and such.) --- Also, on a completely different subject: Has there been much discussion about extending the use of the 'is' keyword to do type comparisons a la C# (e.g. "if x is list:") ? -- Talin From steve at holdenweb.com Mon Aug 29 16:31:04 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Aug 2005 16:31:04 -0400 Subject: close failed: [Errno 0] No error goes to stdout In-Reply-To: <4312c4bc$1@news.bezeqint.net> References: <4311b9bf@news.bezeqint.net> <4312c4bc$1@news.bezeqint.net> Message-ID: <43137088.7050908@holdenweb.com> Yoav wrote: > I run a Java command line program. The point is, that it's not the > program that output this error message for sure. And I don't expect > popen3() to catch and report errors. I just want to keep my screen > output clean, and I expect popen3() to run the program and not let > anything slip to the screen, after all as I understood it is supposed to > capture STDERR and STDOUT, but maybe I didn' t understand it right (it's > quite probable). Anyway anyway I can do such a thing? > It would be helpful if you could verify your theory by running the program from the command line with standard AND error output redirection, verifying that no output at all apears on the console when you type cmd > /tmp/stdout 2>/tmp/stderr You are correct in supposing that popen3 is supposed to trap all stdout and stderr output. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From nidoizo at yahoo.com Sun Aug 7 16:22:11 2005 From: nidoizo at yahoo.com (Nicolas Fleury) Date: Sun, 07 Aug 2005 16:22:11 -0400 Subject: PEP: Specialization Syntax Message-ID: Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $ Last-Modified: $Date: 2003/09/22 04:51:49 $ Author: Nicolas Fleury Status: Draft Type: Standards Track Content-Type: text/plain Created: 24-Jul-2005 Python-Version: 2.5 Post-History: Abstract This PEP proposes a syntax in Python to do what is called in this document "specialization". It contains more than one proposal: - Extend square brackets syntax to allow a full call syntax, using a __specialize__ method, similarly to the __call__ method. - Extend function definition syntax to allow specialization of functions. - Parameterized types. Motivation In his controversial blog entry "Adding Optional Typing to Python -- Part II" [1], Guido Van Rossum introduced the idea of "parameterized types" in Python. The proposition was to use [square brackets] rather than to allow prototyping with __getitem__ method. However, the __getitem__ method is not flexible enough. It doesn't support keyword arguments and using multiple and default arguments can be pain, since the only argument received would be a tuple. Calling can also be error-prone if a tuple can be allowed as a first argument. This PEP proposes to enhance square brackets syntax to allow full-call syntax as with parenthesis. Note that Guido dropped the idea, for now, of parameterized types in a following blog entry [2]. This PEP introduces parameterized types only as a last step, and focus more on having a syntax to prototype them. This PEP can also serve as a place to discuss to feature of specialization independently. The term "specialization" is used in that document because "parameterized functions" would sound like an already available feature. As Guido pointed out [1], "generic" is neither a good term. Specialization is a term in that case borrowed from C++. The term alone is not perfect, since it refers to the action of passing arguments to a "parameterized type" (or function) to make it usable and a term must still be found to describe the "unspecialized" type or function. Another motivation to this PEP is the frequent usage in Python of functions to create functions. This pattern is often used to create callback functions and decorators, to only name these. However, the fact that both the creation and the use is using parenthesis can be confusing. Also, a programmer ends up naming two functions, when only the creating one is called by name and the created one is doing the job. Some programmers ends up naming the creating function with the name they would want to give to the created function, confusing even more the code using it. To fix this situation, this PEP proposes a syntax for function specialization. __specialize__ Special Member Function. The first element of this proposal is the addition of the __specialize__ special member function. The __specialize__ function can have the same signatures as __call__. When defined, the definition of __getitem__ has no effect, and __specialize__ will be called instead. The language grammar is extended to allow keyword arguments and no arguments. For example: class MyObject(object): def __specialize__(self, a=4, b=6, *args, **kwargs): pass obj = MyObject() obj[b=7, a=8, c=10] obj[] Note that when __specialize__ is defined, __setitem__, __getslice__ and __setslice__ are still used as before. The specializer Decorator To explain the syntaxes proposed in this PEP, the following decorator is used: class Specializer: def __init__(self, callableObj): self.callableObj self.__name__ = callableObj.__name__ def __specialize__(self, *args, **kwargs): self.callableObj(*args, **kwargs) def specializer(callableObj): return Specializer(callableObj) It takes a callable and make it callable with square brackets instead. Function Specialization A common pattern in Python is to use a function to create another function: def makeGetMemberFunc(memberName): def getMember(object): return getattr(object, memberName) return getMember foo(makeGetMemberFunc('xyz')) The second element of this proposal is to add a syntax so that the previous example can be replaced by: def getMember[memberName](object): return getattr(object, memberName) foo(getMember['xyz']) which is equivalent to: @specializer def getMember(memberName): def getMember(object): return getattr(object, memberName) return getMember foo(getMember['xyz']) Class Specialization The last element of this proposal is to add a syntax to pass arguments to class creation: class List[ElementType=object](list): ... This would be the equivalent to: @specializer def List(ElementType=object): class List(list): ... return List Note that the additional syntax is inserted before the inheritance, different than what was initially proposed [1]. The reason is that inheritance can need the specialization arguments, and it is more intuitive to use an argument after its introduction: class MyList[ElementType=object](List[ElementType]): ... Backward Compatibility The three propositions are backward compatible. Open Issues Instead of adding a __specialize__ method, the __getitem__ method could be changed to allow additional signatures: def __getitem__(self, *args, **kwargs): ... Should other operators that square brackets be used for specialization? References [1] Adding Optional Static Typing to Python -- Part II, Guido van Rossum http://www.artima.com/weblogs/viewpost.jsp?thread=86641 [2] Optional Static Typing -- Stop the Flames!, Guido van Rossum http://www.artima.com/weblogs/viewpost.jsp?thread=87182 Copyright This document has been placed in the public domain. From damir at agg.astranet.ru Mon Aug 8 01:22:36 2005 From: damir at agg.astranet.ru (Damir Hakimov) Date: Mon, 08 Aug 2005 09:22:36 +0400 Subject: error with examples (UDP broadcast) Message-ID: <42F6EC1C.2070608@agg.astranet.ru> Hi All! I'm writing a small programm which must send and service UDP broadcast packets. As start of it I looked at /usr/share/doc/python2.4/Examples/Demo/sockets/broadcast.py damir at debian-IBM:/usr/share/doc/python2.4/examples/Demo/sockets$ python2.4 broadcast.py Traceback (most recent call last): File "broadcast.py", line 14, in ? s.sendto(data, ('', MYPORT)) socket.error: (101, 'Network is unreachable') damir at debian-IBM:/usr/share/doc/python2.4/examples/Demo/sockets$ If I replace '' to '192.168.10.255' (this is my network's broadcast addres) it's working fine. Were is the truble? Damir. From mehdi.rabah at gmail.com Sun Aug 28 21:45:41 2005 From: mehdi.rabah at gmail.com (mehdi.rabah at gmail.com) Date: 28 Aug 2005 18:45:41 -0700 Subject: formal math ? In-Reply-To: <24a75$4311f00c$d8fe9c49$6023@PRIMUS.CA> References: <1125186266.843702.254220@f14g2000cwb.googlegroups.com> <24a75$4311f00c$d8fe9c49$6023@PRIMUS.CA> Message-ID: <1125279941.186762.192910@g44g2000cwa.googlegroups.com> Thanks you two. I was just thinking if it was possible. If I really want to do this, maybe the best way is to do an interface to python of an open source project I have just discovered : maxima. So long, From sonicsmooth at gmail.com Fri Aug 26 00:20:34 2005 From: sonicsmooth at gmail.com (sonicSpammersGoToHellSmooth) Date: 25 Aug 2005 21:20:34 -0700 Subject: Newbie question: Sub-interpreters for CAD program References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: <1125030034.537801.275040@f14g2000cwb.googlegroups.com> Hi, Actually I was thinking of doing the bulk of everything in Python, and then embedding a Python interpreter into the CAD program. Anything in C++ would be to speed up critical things, like rules checking, etc. I have looked at python cad (found it a year or two ago) and am inspired by it; I'm glad someone's done the legwork, although it's a long way from anything EDA related (well, the 2d stuff could be used for schematics). I have also looked at gEDA and found it lacked the "modern feel" I'm looking for. It seems people are stuck on batch processing of text descriptions, and NOT integrating completely the front-to-back design process. I'd like to write something that (eventually) would actually have an install program and run like a normal app, on Windoze or Linux. Most of my experience with open source software is that it's not user-oriented. Finally, if I write something that's cool, I may try to make money from it, which means I'm not sure how much I'm going to want to release to the general public. This means I can't use code from pythonCad, etc., if I want to keep it propietary. I could make it free for noncommercial use. Anyway, that's a long way off. My original question was about how to run an interpreter within the interpreter, and whether that's what needs to be done to have some scripting capabilities which separated the user's code from the main application. Michael From aisaac0 at verizon.net Wed Aug 10 10:38:04 2005 From: aisaac0 at verizon.net (David Isaac) Date: Wed, 10 Aug 2005 14:38:04 GMT Subject: FTP over SSL (explicit encryption) Message-ID: I am looking for a pure Python secure ftp solution. Does it exist? I would have thought that the existence of OpenSSL would imply "yes" but I cannot find anything. ftplib does not seem to provide any secure services. I know about fptutil http://codespeak.net/mailman/listinfo/ftputil but that does not seem to provide any secure services. (Btw, Matt Croydon's intro is helpful for newbies: http://postneo.com/stories/2003/01/01/beyondTheBasicPythonFtplibExample.html ) I know about M2Crypto http://sandbox.rulemaker.net/ngps/m2/ but that requires installing SWIG and OpenSSL. (If someone tells me they have found this trivial under Windows, I am willing to try ... ) I would have thought that this was a common need with a standard Python solution, so I suspect I'm overlooking something obvious. Hoping, Alan Isaac From steve at holdenweb.com Thu Aug 18 12:52:39 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Aug 2005 17:52:39 +0100 Subject: Python for Webscripting (like PHP) In-Reply-To: References: Message-ID: Peter Hansen wrote: > Alessandro Bottoni wrote: > >>(Python has even been told to be used by Yahoo! and Google, among others, >>but nobody was able to demonstrate this, so far) > > > Nobody, except Google's founders? > > http://www-db.stanford.edu/~backrub/google.html > > (Among many other references.) > > -Peter Plus, may I remind the world, PyCon DC 2005 had a keynote by far-from obscure Python supporter Greg Stein, an engineering manager at Google, giving a talk entitled "Python at Google". There's informal evidence that the Python secret is getting out. Sharpen up your resumes, guys, you may not have to limit Python to home usage soon :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From p at ulmcnett.com Mon Aug 1 13:57:37 2005 From: p at ulmcnett.com (Paul McNett) Date: Mon, 01 Aug 2005 10:57:37 -0700 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com><200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> Message-ID: <42EE6291.5010705@ulmcnett.com> Terry Reedy wrote: > "Ed Leafe" wrote in message > news:200508010830.27322.ed at leafe.com... >>I'm serious here: I want to know what people consider acceptable for a >>software package that relies on other packages. > To me, acceptability depends on the audience. Do you want to limit Dabo to > professional developers comfortable with sometimes cryptic traceback > messages or do you want to include people using Python as part of other > activities? My concern with putting another layer on top of Python's excellent traceback mechanism is that we could screw up and hide important exceptions, or otherwise make it harder for the seasoned Pythonista to get to the source of the issue. Nothing beats those tracebacks, ugly though they may seem to a newbie... perhaps we need both methods, and to default to the "nice" error handler. Your idea of checking for common missing pieces or misconfigurations on startup is a great idea though. Also, we do already provide for information and error logs, which get directed to stdout and stderr by default. Perhaps we just need to give slightly higher-level control of them, so that an individual developer can "set it and forget it" for each individual app. There are other settings as well, such as event logging, that are useful during testing - we should consolidate all these options into a setup screen of some sort. All in good time! -- Paul McNett http://paulmcnett.com From zen19725 at zen.co.uk Tue Aug 30 12:33:48 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Tue, 30 Aug 2005 17:33:48 +0100 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 30 Aug 2005 08:53:27 GMT, Bryan Olson wrote: > Specifically, to support new-style slicing, a class that > accepts index or slice arguments to any of: > > __getitem__ > __setitem__ > __delitem__ > __getslice__ > __setslice__ > __delslice__ > > must also consistently implement: > > __len__ > > Sane programmers already follow this rule. Wouldn't it be more sensible to have an abstract IndexedCollection superclass, which imlements all the slicing stuff, then when someone writes their own collection class they just have to implement __len__ and __getitem__ and slicing works automatically? -- Email: zen19725 at zen dot co dot uk From chrisj at rtems.org Thu Aug 4 10:29:19 2005 From: chrisj at rtems.org (Chris Johns) Date: Fri, 05 Aug 2005 00:29:19 +1000 Subject: Embedded python In-Reply-To: <42f20657$0$27904$626a14ce@news.free.fr> References: <42f20657$0$27904$626a14ce@news.free.fr> Message-ID: <42F2263F.8060803@rtems.org> nico wrote: > > Does anyone have embedded a python interpreter on a proprietary hardware ? Yes, http://www.cybertec.com.au/microcore.htm > I have a home made hardware running a home made OS. C is used as programming > language. I'd like to add a python interpreter to my system. > Any guidelines ? Maybe the RTEMS instructions will help: http://www.rtems.org/phpwiki/index.php/Python -- Chris Johns From listsub at wickedgrey.com Tue Aug 23 21:23:22 2005 From: listsub at wickedgrey.com (Eli Stevens (WG.c)) Date: Tue, 23 Aug 2005 18:23:22 -0700 Subject: Inline::Python, pyperl, etc. Message-ID: <430BCC0A.2000909@wickedgrey.com> The group I work with is trying to be language agnostic between Python and perl. We are trying to make it so that we are able to call our various APIs from one language or the other without having to care* what language the API was written in. I've been looking into: Inline::Python 0.22 http://search.cpan.org/~neilw/Inline-Python-0.22/Python.pod PyPerl 1.0.1 http://wiki.python.org/moin/PyPerl The interest in these projects seems to have died off about 2001, however. That, or they simply haven't needed to be updated for the last few Python versions. I've bumped into some snags with pyperl (can't import perl2.so? But it's right there in site-packages/ !), and I'm wondering if it's bitrot or a config error on my end. Similarly, with Inline::Python I end up getting strings passed into my python code when I expect integers (I posted about this on inline at perl.org, but things seem pretty dead over there). Is anyone actually using any of this stuff? Thanks for any feedback, Eli [*] Obviously this is a golden ideal. We're willing to make compromises to get things to work. From orome.the.valar at gmail.com Wed Aug 17 05:54:49 2005 From: orome.the.valar at gmail.com (sinan .) Date: Wed, 17 Aug 2005 12:54:49 +0300 Subject: question about threading Message-ID: <8c05f79c050817025473ec506d@mail.gmail.com> hi i have a program that listens socket connection and serial device. in main program i am creating a socket then calling a class to listen socket under while 1: , class soket(Thread): def __init__(self): Thread.__init__(self) self.host = '127.0.0.1' self.port = 4500 self.data = '' try: self.s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.s.bind((self.host,self.port)) self.s.listen(1) except: print 'error creating a socket !?!' def run(self): Thread.__init__(self) self.conn, self.addr = self.s.accept() self.data += self.conn.recv(1024) if not self.data: pass else: return trim(self.data) self.conn.close() in main after doing this , try: s = AboutSocket.soket() s.setDaemon(1) s.start() except: print 'Error occured while using Threaded Socket !?!' after creating a socket i put bot soket and serial listeners in same while 1: while 1: skcgelen = s.run() print '\n\nreceived data from socket : ' + skcgelen.__str__() okunan = serial_readline(ser,'[ETX]') print '\n\nreceived data : ' + okunan.__str__() # ser.write('[ACK]') # database_relation(db,okunan) this works but when i send message to serial, the program waits for socket to receive message, if i send a message to a socket it prints both socket message and serial device message, how can i work them separetly. i want to see the message from the serial if received immediately and socket if socket receives immediately. i`ll put these incoming message to the list dynamically. note: serial device listener is not threaded. thanks From gregpinero at gmail.com Fri Aug 26 14:33:31 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 26 Aug 2005 14:33:31 -0400 Subject: Embedding Python in other programs In-Reply-To: <312cfe2b05082609371c4e453c@mail.gmail.com> References: <312cfe2b050826084036db598f@mail.gmail.com> <312cfe2b05082609371c4e453c@mail.gmail.com> Message-ID: <312cfe2b05082611332bf4030e@mail.gmail.com> Oh, by the way, here's the VB code I'm using:
http://www.blendedtechnologies.com/wp-content/VB_uses_Python.zip I wonder if this question should go to some kind of VB list instead? -Greg On 8/26/05, Gregory Pi?ero wrote: > > Hey guys, > > This question inpsired me to try this in VB6. I did a search and copied > what I saw at > http://forums.devshed.com/t158692/s.html > > However I'm running into the same problem they are. When I try to run: > res = Python.PyRun_SimpleString("5+7") > > I get the error message: > Bad DLL calling convention (Error 49) > > Which VB help describes as: > > Arguments passed to a dynamic-link library (DLL) must exactly match those > expected by the routine. Calling conventions deal with number, type, and > order of arguments. This error has the following causes and solutions: > > - Your program is calling a routine in a DLL that's being passed the > wrong type of arguments. > > Make sure all argument types agree with those specified in the > declaration of the routine you are calling. > - Your program is calling a routine in a DLL that's being passed the > wrong number of arguments. > > Make sure you are passing the same number of arguments indicated in > the declaration of the routine you are calling. > - Your program is calling a routine in a DLL, but isn't using the > StdCall calling convention. > > If the DLL routine expects arguments by value, then make sure *ByVal > * is specified for those arguments in the declaration for the > routine. > - Your *Declare* statement for a Windows DLL includes *CDecl*. > > > Any ideas? > > -Greg > > > On 8/26/05, Gregory Pi?ero wrote: > > > > How do I get it into VB6? Now that's an answer that would save my life > > many times over. > > > > -Greg > > > > On 8/26/05, Alessandro Bottoni < alessandro.bottoni at infinito.it > wrote: > > > > > > Thomas Bartkus wrote: > > > > > > > Name: lib64python2.4-devel > > > > Summary: The libraries and header files needed for Python > > > development > > > > > > > > Description: The Python programming language's interpreter can be > > > extended > > > > with dynamically loaded extensions and can be embedded in other > > > programs. > > > > This package contains the header files and libraries needed to do > > > these > > > > types of tasks. > > > > ------------------------------------------------------ > > > > > > > > > > > > *** The Python programming language's interpreter ... can be > > > embedded in > > > > other programs. *** > > > > > > > > That's very intriguing! > > > > But I can't seem to locate much information about this. > > > > > > > > Can anyone direct me to greater enlightenment? > > > > Thomas Bartkus > > > > > > There is a section of the official documentation devoted to extending > > > and > > > embedding python: > > > > > > http://docs.python.org/ext/ext.html > > > > > > There are a few articles on this topics on the web, as well. Search > > > "embedding python" with Google. > > > ----------------------------------- > > > Alessandro Bottoni > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > -- > > Gregory Pi?ero > > Chief Innovation Officer > > Blended Technologies > > (www.blendedtechnologies.com ) > > > > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com ) > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From apardon at forel.vub.ac.be Tue Aug 30 03:12:05 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 30 Aug 2005 07:12:05 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: Op 2005-08-29, Steve Holden schreef : > Antoon Pardon wrote: >> Op 2005-08-27, Steve Holden schreef : >> >>>> >>>If you want an exception from your code when 'w' isn't in the string you >>>should consider using index() rather than find. >> >> >> Sometimes it is convenient to have the exception thrown at a later >> time. >> >> >>>Otherwise, whatever find() returns you will have to have an "if" in >>>there to handle the not-found case. >> >> >> And maybe the more convenient place for this "if" is in a whole different >> part of your program, a part where using -1 as an invalid index isn't >> at all obvious. >> >> >>>This just sounds like whining to me. If you want to catch errors, use a >>>function that will raise an exception rather than relying on the >>>invalidity of the result. >> >> >> You always seem to look at such things in a very narrow scope. You never >> seem to consider that various parts of a program have to work together. >> > Or perhaps it's just that I try not to mix parts inappropriately. I didn't know it was inappropriately to mix certain parts. Can you give a list of modules in the standard list I shouldn't mix. >> So what happens if you have a module that is collecting string-index >> pair, colleted from various other parts. In one part you >> want to select the last letter, so you pythonically choose -1 as >> index. In an other part you get a result of find and are happy >> with -1 as an indictation for an invalid index. Then these >> data meet. >> > That's when debugging has to start. Mixing data of such types is > somewhat inadvisable, don't you agree? The type of both data is the same, it is a string-index pair in both cases. The problem is that a module from the standard lib uses a certain value to indicate an illegal index, that has a very legal value in python in general. > I suppose I can't deny that people do things like that, myself included, It is not about what people do. If this was about someone implementing find himself and using -1 as an illegal index, I would certainly agree that it was inadvisable to do so. Yet when this is what python with its libary offers the programmer, you seem reluctant find fault with it. > but mixing data sets where -1 is variously an error flag and a valid > index is only going to lead to trouble when the combined data is used. Yet this is what python does. Using -1 variously as an error flag and a valid index and when people complain about that, you say it sounds like whining. -- Antoon Pardon From andrewm at object-craft.com.au Tue Aug 16 03:20:51 2005 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Tue, 16 Aug 2005 17:20:51 +1000 Subject: Albatross 1.32 released Message-ID: <20050816072051.4899F6F4064@longblack.object-craft.com.au> OVERVIEW Albatross is a small toolkit for developing highly stateful web applications. The toolkit has been designed to take a lot of the pain out of constructing intranet applications although you can also use Albatross for deploying publicly accessed web applications. In slightly more than 4500 lines of Python (according to pycount) you get the following: * An extensible HTML templating system similar to DTML including tags for: - Conditional processing. - Macro definition and expansion. - Sequence iteration and pagination. - Tree browsing. - Lookup tables to translate Python values to arbitrary template text. * Application classes which offer the following features: - Optional server side or browser side sessions. - The ability to place Python code for each page in a dynamically loaded module, or to place all page processing code in a single mainline. * The ability to deploy applications as CGI, FastCGI, mod_python or a pure python HTTP server by changing less than 10 lines of code. The toolkit application functionality is defined by a collection of fine grained mixin classes. Nine different application types and six different execution contexts are prepackaged, you are able to define your own drop in replacements for any of the mixins to alter any aspect of the toolkit semantics. Application deployment is controlled by your choice of either cgi, FastCGI, mod_python, or BaseHTTPServer Request class. It should be possible to develop a Request class for Medusa or Twisted to allow applications to be deployed on those platforms with minimal changes. Albatross comes with over 170 pages of documentation. HTML, PDF and PostScript formatted documentation is available from the toolkit homepage. The toolkit homepage: http://www.object-craft.com.au/projects/albatross/ The Albatross mailing list subscription and archives: http://object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users BUGFIXES SINCE 1.30: * To obtain a reference to the current frame, _caller_globals was raising and catching an exception, then extracting the tb_frame member of sys.exc_traceback. sys.exc_traceback was deprecated in python 1.5 as it is not thread-safe. It now appears to be unreliable in 2.4, so _caller_globals has been changed to use sys._getframe(). * If ctx.set_page() was called from within the start page, then the wrong page methods (page_enter, page_display, etc) would be called (those of the initial page, rather than the page requested via set_page). * Fixes to handling of missing RandomPage page modules. From rkern at ucsd.edu Sun Aug 7 13:46:05 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 10:46:05 -0700 Subject: Optional assignments ? In-Reply-To: <42f6456a$0$18641$14726298@news.sunsite.dk> References: <42f6456a$0$18641$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > Hi > > Is it possible to have something like : > > a,b,c,d=fn(that returns 10 return values) ? a,b,c,d = fn()[:4] -- 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 fabioz at esss.com.br Mon Aug 29 13:12:03 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Mon, 29 Aug 2005 14:12:03 -0300 Subject: ANN: PyDev 0.9.8 released In-Reply-To: <430632E3.9050403@esss.com.br> References: <42A720BD.5050701@esss.com.br> <42C175A5.5000206@esss.com.br> <42E6412A.4020905@esss.com.br> <430632E3.9050403@esss.com.br> Message-ID: <431341E3.6020103@esss.com.br> Hi All, PyDev - Python IDE (Python Development Enviroment for Eclipse) version 0.9.8 has just been released. Check the homepage (http://pydev.sourceforge.net/) for more details. Details for Release: 0.9.8 Major highlights: ------------------- * Jython integrated. * Jython debugger support added. Others that are new and noteworthy: ------------------------------------- * jython integration supports spaces for jython.jar and java install * jython code-completion support for new style objects (jython 2.2a1) has been enhanced. * many templates were added * the grammar evolved a lot, so, now you actually have decorators in the grammar, list comprehension on method calls and tuples and the new from xxx import (a,b,c) syntax. * pylint supports spaces * pylint is no longer distributed with pydev (it must be installed in the site-packages and its location must be specified in the preferences) * some problems regarding 'zombie processes' after eclipse exit with the shells used for code-completion should be fixed Special thanks --------------- This release would not be possible without help from: OctetString, for the financial support for making jython support possible! Vitor Oba for debugger patches! Cheers, Fabio -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From billiejoex at fastwebnet.it Tue Aug 30 17:07:59 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Tue, 30 Aug 2005 23:07:59 +0200 Subject: py2exe can't compile this program References: <1125415966$mail2nntp@hades.rz.uni-saarland.de> Message-ID: <5T3Re.2103$nT3.1935@tornado.fastwebnet.it> Really thank you. It works. From pinard at iro.umontreal.ca Sat Aug 20 14:35:52 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Sat, 20 Aug 2005 14:35:52 -0400 Subject: How to devise run-time pluggable classes? (MRO problem) Message-ID: <20050820183552.GA12077@phenix.progiciels-bpi.ca> Hi, everybody. I wish someone could advise me. I'm running in circles, trying to find an elegant way to devise run-time pluggable classes. It all goes around method resolution order, I guess. (We already use various solutions, but the maintenance burden is high.) We have a common module containing many basic classes, but for the sake of simplicity here, I'll use only Element and Connection. Next to this common module, we have many "plugin" modules importing it, and each plugin also defines an Element class having common.Element among its bases, and a Connection class having common.Connection among its bases. Or nearly, as some plugins just do not override common classes that just "fit" like they are. Plugins are really meant to enrich common classes. The common module and all plugins are part of a single package, but there are many other packages meant to provide work schemas, installed separately and maintained by different programmers. Each work schema package contains a core schema module which, after having imported the already installed common module above, defines tons of classes having either common.Element or common.Connection in their bases, relating them, and a schema class reaching everything, for applications to use. And finally, we have a flurry of applications. These applications import at least one and typically a few work schemas, and for each, specify _at run time_ which plugin to use (we use an URL-like syntax for specifying plugins, work schemas, and other various parameters, these URLs being read from configuration files while applications progress). So, while all work schemas are programmed to use classes from the common module, I would need at run time that all base classes be automatically "promoted" into plugin classes, depending on plugin as selected at run time, for being able to benefit from enriched methods. More or less, it might mean something like the virtual substitution of common classes by corresponding plugin classes whenever they appear in the class bases of work schemas, and consequently virtually altering the MRO of such classes so plugin methods override common methods, yet common methods staying available for fall back, that is, if not overridden by plugins. I feel ready to allow some complexity to the common module, but would like the overall approach to be as clean and unobtrusive as possible everywhere else, (that is, for plugins, work schemas, and applications). It ought to be overall simple. So, zealots: no Zope nor Twisted! :-). Another constraint is that the same work schema may be used at run-time with two different plugins, and this means that ideally, a work schema may not be altered (in a non-reentrant way) for a particular plugin. This is a lesser constraint, because it occurs only occasionally, and I presume that we could afford unusual stunts whenever necessary. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From aahz at pythoncraft.com Sun Aug 28 10:50:56 2005 From: aahz at pythoncraft.com (Aahz) Date: 28 Aug 2005 07:50:56 -0700 Subject: NASFiC? Message-ID: Anyone gonna be at NASFiC next weekend? Want a get-together? (NASFiC is a science fiction convention that will be in Seattle this time; for more info, see http://nasfic.org/) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From gregpinero at gmail.com Sun Aug 28 23:31:53 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Sun, 28 Aug 2005 23:31:53 -0400 Subject: Embedding Python in other programs In-Reply-To: <312cfe2b05082810296b988cc5@mail.gmail.com> References: <312cfe2b050826084036db598f@mail.gmail.com> <1125134294.509755.64030@g43g2000cwa.googlegroups.com> <1125208540.068217.10960@z14g2000cwz.googlegroups.com> <312cfe2b05082810296b988cc5@mail.gmail.com> Message-ID: <312cfe2b05082820317a3ff93b@mail.gmail.com> Guys, I am so lost. I followed the instructions exactly at http://www.python.org/windows/win32com/QuickStartServerCom.html But then when I opened up Visual Basic 6 and went to project>references, It is not listing anything like the helloworld com thingy I just registered? What do I need to do to use this com server thingy from within VB? I'd really appriciate any help. Thanks, Greg On 8/28/05, Gregory Pi?ero wrote: > Thanks Ravi, I'll take a look > > > On 27 Aug 2005 22:55:40 -0700, Ravi Teja wrote: > > http://www.python.org/windows/win32com/QuickStartServerCom.html > > > > If you are using ActivePython, that tutorial is included (PyWin32 > > documentation -> Python COM -> Overviews) along with the needed > > win32all module. > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com) > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From jgrahn-nntq at algonet.se Sun Aug 21 04:22:54 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 21 Aug 2005 08:22:54 GMT Subject: __del__ pattern? References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: On Tue, 16 Aug 2005 08:03:58 -0400, Peter Hansen wrote: > Tom Anderson wrote: >> On Mon, 15 Aug 2005, Peter Hansen wrote: >>> Using '' instead of 'localhost' means bind to *all* interfaces, not >>> just the loopback one. >> >> Doesn't '' mean 'bind to the *default* interface'? > > What does "default" mean, and is that definition in conflict with what I > said? > > The docs say it means INADDR_ANY. They don't say what that means, so > you'd have to read up on the C socket calls to learn more. > > Or some helpful soul will clarify for the class... :-) INADDR_ANY means "every network interface you can find". This includes the local loopback and all physical and logical network interfaces. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From knutsample at gmail.com Mon Aug 22 01:07:35 2005 From: knutsample at gmail.com (knutsample at gmail.com) Date: 21 Aug 2005 22:07:35 -0700 Subject: win32 - associate .pyw with a file extension... Message-ID: <1124687255.717835.145590@g49g2000cwa.googlegroups.com> Hello! I'm trying to associate a file extension to my wxPython script so that all I have to do is double click on the file and my python script will load up with the path of that file. For instance, I've associated all .py files to be opened up with emacs.exe. If I double click on a .py file, emacs.exe would open up with that file in its buffer. Is there a way to do this with a non-exe (wxPython script)? Everytime I try to associate a certain file extension (right clicking file->Open with->Choose program) with my python script (.pyw) windows states that I do not have a valid win32 program. Is there a way to do this with a python script? Thank you for your time. From spammers-go-here at spam.invalid Wed Aug 17 12:09:42 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 17 Aug 2005 12:09:42 -0400 Subject: Testing for presence of arguments References: <430353e1$0$18641$14726298@news.sunsite.dk> Message-ID: <43036157$0$18639$14726298@news.sunsite.dk> Peter Decker wrote: > On 8/17/05, Madhusudan Singh wrote: > >> I know how to set optional arguments in the function definition. Is there >> an intrinsic function that determines if a certain argument was actually >> passed ? Like the fortran 95 present() logical intrinsic ? >> >> My required functionality depends on whether a certain argument is >> specified at all. (Setting default values is *not* good enough.). > > Could you just write the function as: > > myFunc(*args, **kwargs): > > ...and then figure out what was passed? > Seems a lot simpler than the other module suggestion, but another person has posted a suggestion that is a lot more quick and elegant. Thanks anyways. I might find this useful in some as yet unknown context. From __peter__ at web.de Thu Aug 4 11:42:22 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Aug 2005 17:42:22 +0200 Subject: Python's CSV reader References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> <1123169310.391973.217860@o13g2000cwo.googlegroups.com> Message-ID: Stephan wrote: > Thank you all for these interesting examples and methods! You're welcome. > Supposing I want to use DictReader to bring in the CSV lines and tie > them to field names, (again, with alternating lines having different > fields), should I use two two DictReaders as in Christopher's example > or is there a better way? For a clean design you would need not just two DictReader instances, but one DictReader for every two lines. However, with the current DictReader implementation, the following works, too: import csv import sys reader = csv.DictReader(sys.stdin) for record in reader: print record reader.fieldnames = None Peter From max at alcyone.com Mon Aug 15 23:57:16 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 15 Aug 2005 20:57:16 -0700 Subject: How to obtain GMT offset? In-Reply-To: References: Message-ID: new pip wrote: > I'm using Windows os. If the current system date time is '28 Jun 2001 > 14:17:15 +0700', how can I obtain the value '+0700' using python? time.timezone gives you the timezone offset in minutes. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Many would be cowards if they had courage enough. -- Thomas Fuller From lemon97 at gmail.com Mon Aug 8 14:04:31 2005 From: lemon97 at gmail.com (lemon97 at gmail.com) Date: 8 Aug 2005 11:04:31 -0700 Subject: Splitting a string into groups of three characters References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: <1123524271.644157.52580@o13g2000cwo.googlegroups.com> Yes i know i made a mistake, >['Hell','o W','orl','d'] but you know what I mean lol, I'll probly use John Machin's def nsplit(s, n): return [s[k:k+n] for k in xrange(0, len(s), n)] It seems fast, and does not require any imports. But anyways, thank you for all your help, you rock! :) From billiejoex at fastwebnet.it Sun Aug 28 17:11:09 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Sun, 28 Aug 2005 23:11:09 +0200 Subject: aproximate a number Message-ID: Hi all. I'd need to aproximate a given float number into the next (int) bigger one. Because of my bad english I try to explain it with some example: 5.7 --> 6 52.987 --> 53 3.34 --> 4 2.1 --> 3 Regards From fakeaddress at nowhere.org Sat Aug 13 01:37:22 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 13 Aug 2005 05:37:22 GMT Subject: socket setdefaulttimeout In-Reply-To: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> Message-ID: Sheila King wrote: > I'm doing DNS lookups [...] it is important to make sure > that the socket doesn't just hang there waiting for a response. > > After a recent system upgrade to Python 2.4.1 (from 2.2.2) I thought I > could take advantage of the setdefaulttimeout in the socket module, to > limit the amount of time the sockets take for a lookup. > > As a test, I set the default timout ridiculously low. But it doesn't > seem to be having any effect. The timeout applies to network communication on that socket, but not to calls such as socket.gethostbyname. The gethostbyname function actually goes to the operating system, which can look up the name in a cache, or a hosts file, or query DNS servers on sockets of its own. Modern OS's generally have reasonably TCP/IP implementations, and the OS will handle applying a reasonable timeout. Still gethostbyname and its brethren can be a pain for single- threaded event-driven programs, because they can block for significant time. Under some older threading systems, any system call would block every thread in the process, and gethostbyname was notorious for holding things up. Some systems offer an asynchronous gethostbyname, but that doesn't help users of Python's library. Some programmers would keep around a few extra processes to handle their hosts lookups. Fortunately, threading systems are now much better, and should only block the thread waiting for gethostbyname. -- --Bryan From iamsidd at gmail.com Sun Aug 21 01:40:23 2005 From: iamsidd at gmail.com (Sidd) Date: 20 Aug 2005 22:40:23 -0700 Subject: Related To Threads Message-ID: <1124602823.281311.32710@g44g2000cwa.googlegroups.com> Hello, I want to write a thread in python which can be invoked for say 5 sec, within that the threads function would be to take input,is it possible because i tried it and found that raw_input() is blocking threads. From jeff at taupro.com Wed Aug 3 00:29:50 2005 From: jeff at taupro.com (Jeff Rush) Date: Tue, 02 Aug 2005 23:29:50 -0500 Subject: Request for Input re PyCon about Session Lengths Message-ID: <42F0483E.8060105@taupro.com> There is a discussion going on regarding how long the presentations should be for PyCon 2006. In the past the sessions have been 20 minutes of talk, 5 minutes of questions and 5 minutes to change rooms, grouped into 90-minute timeslots, with a 30-minute break btw each 90-minutes. There were comments last year that that 20-minutes was too short to cover much material, so there is a push to extend that to 50-minutes of talk, 5 minutes Q/A and 5 minutes to change rooms. Some however think sitting in a lecture for that long is excessive and that 20-minutes is sufficient to cover the high points of a topic and point interested people to online docs and forums. Others, particularly those new to a topic, hunger for more comprehensive coverage, something more akin to a class or tutorial. They may not be familiar with a topic and want more than a bullet list of what has changed on the project since the last PyCon. Note that there -will- be a day of tutorial prior to the main presentation days, but will that one day satisfy those people? And there is a view of mixing session lengths, dividing talks into "topic surveys (whats)" and "tutorials (hows)", with perhaps a survey to introduce a topic, say the Twisted Framework, and then on another track an in-depth session to actually teach Twisted programming. There is concern, however, that such mixing can complicate scheduling excessively. We would also like input from speakers themselves. This year some seemed uncomfortable or surprised to find they only had 20-minutes of actual presentation time. But not every talk needs more time. In 2006, there will be more speaking rooms available, in that the sprinting rooms will be available during the entire conference. Therefore there will be rooms for the usual tracks 1, 2 and 3, plus the 2 sprinting rooms, plus a non-sprinting "quiet" room. However, the idea of having possibly 5-6 tracks makes some parties believe too many choices will leave attendees unhappy. Others that our community is diverse and needs to support people with different presentation needs. If you have strong opinions about these matters, please send private email to either me (jeff at taupro.com) and/or the PyCon chairman (amk at amk.ca) and we'll summarize to the group, or join the pycon-organizers list and get involved directly: http://mail.python.org/mailman/listinfo/pycon-organizers Please read the archives to come up to speed on the various viewpoints. -Jeff Rush From john at castleamber.com Thu Aug 25 17:39:07 2005 From: john at castleamber.com (John Bokma) Date: 25 Aug 2005 21:39:07 GMT Subject: minimalist regular expression References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> Message-ID: "borges2003xx at yahoo.it" wrote: > Exists some tool, programs or some able to compute the minimal regular > expression, namely ,taking a series of regular exoression, the minimal > one that makes the same matching? > thanx in advance length? (define minimal) :-D. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From martin at v.loewis.de Fri Aug 12 18:19:07 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 13 Aug 2005 00:19:07 +0200 Subject: Pre-PEP Proposal: Codetags In-Reply-To: <42fb9f3b.1194361460@news.oz.net> References: <42FAF489.3010306@v.loewis.de> <42fb9f3b.1194361460@news.oz.net> Message-ID: <42FD205B.1080802@v.loewis.de> Bengt Richter wrote: >>Both elements seem to be missing your document: it does not propose >>changes to the Python language; instead, it proposes a specific >>way of writing comments (ie. something that is not relevant to the >>Python interpreter or libraries, only to the Python developer). > > > Erm, (cough) PEP 263 specifies comment syntax ;-) Indeed. However, it turns out that the syntax *is* relevant to the Python interpreter. So despite it looking like a comment, it is not. I personally had wished if it would have been proper syntax (and had proposed PEP 244 in that direction), however, the BDFL rejected that idea an preferred a comment-like syntax. Regards, Martin From rrr at ronadam.com Tue Aug 16 14:52:24 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 16 Aug 2005 18:52:24 GMT Subject: [Python-Dev] implementation of copy standard lib In-Reply-To: References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: Simon Brunning wrote: > On 8/14/05, Martijn Brouwer wrote: > >>After profiling a small python script I found that approximately 50% of >>the runtime of my script was consumed by one line: "import copy". >>Another 15% was the startup of the interpreter, but that is OK for an >>interpreted language. The copy library is used by another library I am >>using for my scripts. Importing copy takes 5-10 times more time that >>import os, string and re together! >>I noticed that this lib is implemented in python, not in C. As I can >>imagine that *a lot* of libs/scripts use the copy library, I think it >>worthwhile to implement this lib in C. >> >>What are your opinions? > > > I think that copy is very rarely used. I don't think I've ever imported it. > > Or is it just me? I use copy.deepcopy() sometimes, and more often [:] with lists. Dictionary objects have a copy method. All non mutable objects are copies. I too have wondered why copy isn't a builtin, and yet some builtin objects do make copies. Cheers, Ron From http Mon Aug 29 16:50:19 2005 From: http (Paul Rubin) Date: 29 Aug 2005 13:50:19 -0700 Subject: Using select on a unix command in lieu of signal References: <1125347796.648556.282610@g43g2000cwa.googlegroups.com> Message-ID: <7xr7ccv56c.fsf@ruckus.brouhaha.com> "rh0dium" writes: > Thanks much - Alternatively if anyone else has a better way to do what > I am trying to get done always looking for better ways. I still want > this to work though.. You don't have to use select, since you can use timeouts with normal socket i/o. So you could use threads. 3000 threads is a lot but not insanely so. From jeffrey.schwab at rcn.com Tue Aug 16 23:07:23 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Tue, 16 Aug 2005 23:07:23 -0400 Subject: get the return code when piping something to a python script? In-Reply-To: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> References: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> Message-ID: mhenry1384 wrote: > On WinXP, I am doing this > > nant.exe | python MyFilter.py > > This command always returns 0 (success) because MyFilter.py always > succeeds. ... > How do I set the return code from MyFilter.py based on the return of > nant.exe? Is this possible? I have googled around for an hour wihtout > success. I understand that I could have MyFilter.py call "nant.exe", > but for various reasons, that's not idea for my situation. It's probably not possible. The reason is that the left-most process in the pipe is not guaranteed to exit before the right-most process, so in general, there may not be any return code to get. If you're not too attached to cmd.exe, you might want to try a different shell that can provide a similar effect to what you requested. For example, in bash, you might set the pipefail option. $ ls nonesuch | ./return_zero.py ls: nonesuch: No such file or directory $ echo $? # Print the status of the last foreground pipe. 0 $ set -o pipefail $ ls nonesuch | ./return_zero.py ls: nonesuch: No such file or directory $ echo $? 2 From wierus at pocztowy.net Tue Aug 16 12:45:51 2005 From: wierus at pocztowy.net (wierus) Date: Tue, 16 Aug 2005 18:45:51 +0200 Subject: class-call a function in a function -problem Message-ID: Hello, i have a problem. I write my first class in python so i'm not a experience user. I want to call a function in another function, i tried to do it in many ways, but i always failed:( I supposed it's sth very simple but i can't figure what it is: ================================== class ludzik: x=1 y=2 l=0 def l(self): ludzik.l=ludzik.x+ludzik.y print ludzik.l def ala(self): print ludzik.x print ludzik.y ludzik.l() z=ludzik() z.ala() ==================================== k.py 1 2 Traceback (most recent call last): File "k.py", line 17, in ? z.ala() File "k.py", line 14, in ala ludzik.l() TypeError: unbound method l() must be called with ludzik instance as first argument (got nothing instead) i would be gratefull for resolving this problem for me.... From cappy2112 at gmail.com Wed Aug 10 13:27:29 2005 From: cappy2112 at gmail.com (Cappy2112) Date: 10 Aug 2005 10:27:29 -0700 Subject: Help with Regular Expressions In-Reply-To: References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> Message-ID: <1123694849.670138.97370@g47g2000cwa.googlegroups.com> Be careful with that book though, it's RE examples are Perl-centric and not exactly the same implementation that Python uses. However, it's a good place to start This will also be useful http://www.amk.ca/python/howto/regex/ From max2 at fisso.casa Thu Aug 25 04:35:03 2005 From: max2 at fisso.casa (max(01)*) Date: Thu, 25 Aug 2005 08:35:03 GMT Subject: pipes like perl In-Reply-To: References: Message-ID: many thanks to all the fellows who cared to answer! bye max From kimsj at mobile.snu.ac.kr Sat Aug 20 22:42:23 2005 From: kimsj at mobile.snu.ac.kr (James Sungjin Kim) Date: Sun, 21 Aug 2005 11:42:23 +0900 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> Message-ID: Robert Kern ? ?: > > Now go read the documentation. > Thanks to your comments, I read the corresponding helps searched by Google. (Sorry to say a specific search engine here, but I must say that it is really convinient.) Now I realized that Command 'lambda' is a similar to Command 'inline' in C++. In addition, Command 'iter' is something new but not much new to c engineers, since it is related to 'for loops', e.g., >>> s = 'abc'; it = iter(s); it.next() I would want to express my appreciation to Paul, Robert, Jeremy, Grant, and Bengt, who provide good guidelines to get the answers in newsgroups. -James From alan at alankemp.com Thu Aug 18 12:17:58 2005 From: alan at alankemp.com (Alan Kemp) Date: Thu, 18 Aug 2005 12:17:58 -0400 Subject: Put a url in a browsers address bar In-Reply-To: References: Message-ID: On Thu, 18 Aug 2005 12:01:16 -0400, Colin Gillespie wrote: > I would like to place a url in my browsers address bar, then execute. > How can do this? > > e.g. > > def goToGoogle(): > url = "www.google.com" > b = openBrowser() > b.goToUrl(url) > return True > def goToGoogle(): import webbrowser webbrowser.open("www.google.com"); Alan From tzot at sil-tec.gr Sat Aug 27 04:29:42 2005 From: tzot at sil-tec.gr (Christos Georgiou) Date: Sat, 27 Aug 2005 11:29:42 +0300 Subject: Python library/module for MSAccess References: <430fc532$1@nntp0.pdx.net> Message-ID: On Sat, 27 Aug 2005 04:45:25 GMT, rumours say that Stephen Prinster might have written: >Jonathon Blake wrote: > >> [ Editing/creating msaccess databases on a Linux Box, and WINE _not_ installed.] > >I'm pretty sure I don't understand what you are wanting to do. You say >you have "msaccess databases on a Linux Box" and you are not using the >Jet Database engine. As far as I know, MS Access is just a front-end to >databases, with Jet as the default backend (though it can connect to >many others). What backend database engine/storage format are you >using? There might be a python library for connecting to it, bypassing >Access altogether. I think the OP wants to *use* .mdb files on a linux system without using any msjet*.dll libraries. There is a (C language) project that can read .mdb databases-- it can't write them yet.[1] [1] http://mdbtools.sourceforge.net/ -- TZOTZIOY, I speak England very best. "Dear Paul, please stop spamming us." The Corinthians From grante at visi.com Mon Aug 1 17:10:12 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 01 Aug 2005 21:10:12 -0000 Subject: inheriting from datetime References: <1122929471.966054.146010@g44g2000cwa.googlegroups.com> Message-ID: <11et3tk70qbnh73@corp.supernews.com> On 2005-08-01, Rob Conner wrote: > So this is simple, why can't I run the following code? I've tried many > variances of this, but simply cannot inherit from datetime or > datetime.datetime. I get this on line 3. > TypeError: function takes at most 2 arguments (3 given) I think I posted this question a while back and the problem was that a datetime instance is not mutable, so the normal method of deriving a class didn't work.... A quick google... http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/5f2517ecf6fb2ce/ You need to override __new__ rather than __init__ -- Grant Edwards grante Yow! I'm ANN LANDERS!! I at can SHOPLIFT!! visi.com From godoy at ieee.org Tue Aug 9 21:00:18 2005 From: godoy at ieee.org (Jorge Godoy) Date: Tue, 09 Aug 2005 22:00:18 -0300 Subject: PyQt: Problem finding and showing a record in a QDataBrowser References: <0l1ks2-1rh.ln1@strongwill.g2ctech> Message-ID: Jorge Godoy wrote: > I have created an interface where I have a QDataBrowser and all of its > editing and navigating controls and one of the displayed controls is in a > QSpinBox. > > I have the navigation from current to next and previous records working > fine if I only use the data browser controls. I also can recover the > correct record if I type in a valid code at the spin box. Just to make the answer available to other that might have the same problem, I had to deactivate the framework code and handle the cursor from the databrowser manually. It also fixed a performance problem since I only have one record fetched and not all of them. This makes the answer time linear (database dependant, of course) no matter how many records I have on the database. -- Jorge Godoy From dejan.wirusrodiger at ck.t-com.hr Tue Aug 9 14:45:40 2005 From: dejan.wirusrodiger at ck.t-com.hr (Dejan Rodiger) Date: Tue, 09 Aug 2005 20:45:40 +0200 Subject: Does any one recognize this binary data storage format In-Reply-To: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com said the following on 9.08.2005 19:29: > Phone 1: 5616864700 > Hex On Disk: C0DBA8ECF441 5616864700(10)=14ECA8DBC(16) 14 EC A8 DB C leftshift by 4 bits (it will add 0 on last C) C0 DB A8 EC 14 00 write bytes from right to left C0 DB A8 EC F4 41 Add E041 > Phone 1: 8003346488 > Hex On Disk: 800396d0fd41 8003346488(10)=1DD096038(16) 1D D0 96 03 8 80 03 96 D0 1D 00 80 03 96 d0 fd 41 Add E041 But works only for Phone 1 :-) -- Dejan Rodiger - PGP ID 0xAC8722DC Delete wirus from e-mail address From exarkun at divmod.com Mon Aug 29 18:10:22 2005 From: exarkun at divmod.com (Jp Calderone) Date: Mon, 29 Aug 2005 18:10:22 -0400 Subject: Basic Server/Client socket pair not working In-Reply-To: <200508292130.51130.mail@tuxipuxi.org> Message-ID: <20050829221022.3914.1865723646.divmod.quotient.9910@ohm> On Mon, 29 Aug 2005 21:30:51 +0200, Michael Goettsche wrote: >Hi there, > >I'm trying to write a simple server/client example. The client should be able >to send text to the server and the server should distribute the text to all >connected clients. However, it seems that only the first entered text is sent >and received. When I then get prompted for input again and press return, >nothing gets back to me. Any hints on what I have done would be very much >appreciated! You aren't handling readiness notification properly. Twisted is a good way to not have to deal with all the niggling details of readiness notification. I haven't trotted out this example in a while, and it's /almost/ appropriate here ;) so... http://www.livejournal.com/users/jcalderone/2660.html Of course, that's highly obscure and not typical of a Twisted application. Nevertheless, I believe it satisfies your requirements. You might want to take a look at http://twistedmatrix.com/projects/core/documentation/howto/index.html for a gentler introduction, though. In particular, the client and server HOWTOs. I'll comment on your code below. > >Here's my code: > >############ SERVER ########## >import socket >import select > >mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >mySocket.bind(('', 11111)) >mySocket.listen(1) > >clientlist = [] > >while True: > connection, details = mySocket.accept() > print 'We have opened a connection with', details > clientlist.append(connection) > readable = select.select(clientlist, [], []) > msg = '' > for i in readable[0]: You'll need to monitor sockets for disconnection. The way you do this varies between platforms. On POSIX, a socket will become readable but reading from it will return ''. On Win32, a socket will show up in the exceptions set (which you are not populating). With the below loop, your server will go into an infinite loop whenever a client disconnects, because the chunk will be empty and the message will never get long enough to break the loop. > while len(msg) < 1024: > chunk = i.recv(1024 - len(msg)) > msg = msg + chunk Additionally, select() has only told you that at least /one/ recv() call will return without blocking. Since you call recv() repeatedly, each time through the loop after the first has the potential to block indefinitely, only returning when more bytes manage to arrive from the client. This is most likely the cause of the freezes you are seeing. Instead, call recv() only once and buffer up to 1024 (if this is really necessary - I do not think it is) over multiple iterations through the outermost loop (the "while True:" loop). > > for i in clientlist: > totalsent = 0 > while totalsent < 1024: > sent = i.send(msg) > totalsent = totalsent + sent This isn't quite right either - though it's close. You correctly monitor how much of the message you have sent to the client, since send() may not send the entire thing. However there are two problems. One is trivial, and probably just a think-o: each time through the loop, you re-send `msg', when you probably meant to send `msg[totalsent:]' to avoid duplicating the beginning of the message and losing the end of it. The other problem is that the send() call may block. You need to monitor each socket for write-readiness (the 2nd group of sockets to select()) and only call send() once for each time a socket appears as writable. > >############## CLIENT ################ >import socket >import select > >socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >socket.connect(("127.0.0.1", 11111)) > >while True: > text = raw_input("Du bist an der Reihe") > text = text + ((1024 - len(text)) * ".") > totalsent = 0 > while totalsent < len(text): > sent = socket.send(text) > totalsent = totalsent + sent Similar problem here as in the server-side send() loop - `send(text[totalsent:])' instead of sending just `text'. > > msg = '' > while len(msg) < 1024: > chunk = socket.recv(1024 - len(msg)) > msg = msg + chunk This is problematic too, since it means you will only be able to send one message for each message received from the server, and vice versa. Most chat sessions don't play out like this. > > print msg I encourage you to take a look at Twisted. It takes care of all these little details in a cross-platform manner, allowing you to focus on your unique application logic, rather than solving the same boring problems that so many programmers before you have solved. Hope this helps, Jp From darkpaladin79 at hotmail.com Wed Aug 31 20:45:14 2005 From: darkpaladin79 at hotmail.com (Ivan Shevanski) Date: Wed, 31 Aug 2005 20:45:14 -0400 Subject: Survey Tool In-Reply-To: <43164A0B.7090406@ntf.com.au> Message-ID: Wait. . .Do you want it on a website? I don't really understand you -Ivan _________________________________________________________________ Don?t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ From petr at tpc.cz Mon Aug 29 11:08:55 2005 From: petr at tpc.cz (McBooCzech) Date: 29 Aug 2005 08:08:55 -0700 Subject: py-serial + CSV In-Reply-To: References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> <1124820032.854336.278790@f14g2000cwb.googlegroups.com> Message-ID: <1125328135.355220.204960@g14g2000cwa.googlegroups.com> Thanks you all, guys, for your suggestions and help. Everything now works great :) Regards Petr Jakes From gregpinero at gmail.com Thu Aug 18 12:38:30 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Thu, 18 Aug 2005 12:38:30 -0400 Subject: (OT) Is there something that people can use instead of full blown Python to run Python programs? In-Reply-To: References: Message-ID: <312cfe2b05081809382d3a87b7@mail.gmail.com> I'm no expert, but I'm guessing you could compile a python with less libraries. I bet that would slim it down a lot. -Greg On 8/18/05, Nathan Pinno wrote: > > Hi all, > Is there something besides the full blown version of Python that people > can use to run Python programs, or do they have to use the full blown > version of it? > Thanks, > Nathan > --------------------------------------------------------------- > Early to bed, > Early to rise, > Makes a man healthy, wealthy, and wise. > --Benjamin Franklin > ------------------------------------------------------------------- > Languages I know: Python > Languages I am learning: C++. Java, Javascript > > -- > http://mail.python.org/mailman/listinfo/python-list > > > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From aregmi at gmail.com Wed Aug 31 19:38:09 2005 From: aregmi at gmail.com (Ananda Regmi) Date: Wed, 31 Aug 2005 17:38:09 -0600 Subject: problem wih vi.run Message-ID: Hello Everybody, I am running into a strange problem while running a vi through python. Below is my sample code. lv = win32com.client.Dispatch("LabVIEW.Application.7.1") file_path = 'C:\\Documents and Settings\\administrator\\My Documents\\Python Files\\testvi.vi' vi=lv.GetVIReference(file_path) vi.Run # it stays in this line until the vi finishes running. When the execution reached the above line, it gets stuck there. It proceeds to the next line of code only after the vi finishes running. But, I need to change some control value in the Run-Time of the vi. I was wondering if there is any option to select before running the VI which can distinguish between completely running the vi and just starting the vi to run and going to the next line of script. I tried using vi.Run(1), vi.Run(), and vi.Run(0). In all of the above cases, python execution gets stuck at very same place, the VI gets executed, and when it finishes running, I get an error in Python IDLE saying "'NoneType' object is not callable labview" and does not go any further. I was also wondering, if vi.Run(1) is the right way to do it and if I need some extra code to avoid that error and run it the way I want to run it. I really appreciate your help. Thanks, Ananda -------------- next part -------------- An HTML attachment was scrubbed... URL: From danieldsmith at gmail.com Thu Aug 11 12:52:24 2005 From: danieldsmith at gmail.com (danieldsmith at gmail.com) Date: 11 Aug 2005 09:52:24 -0700 Subject: thread limit in python Message-ID: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> hello all, i have run into a problem where i cannot start more than 1021 threads in a python program, no matter what my ulimit or kernel settings are. my program crashes with 'thread.error: can't start new thread' when it tries to start the 1021st thread. in addition to tweaking my ulimit settings, i have also verified that the version of glibc i'm using has PTHREAD_THREADS_MAX defined to be 16374. i have posted my test program below as well as the ulimit settings i was running it with. any help would be greatly appreciated. thanks in advance, dan smith import os import sys import time import threading num_threads = int(sys.argv[1]) def run (): # just sleep time.sleep(10000) for i in range(1,num_threads+1): print 'starting thread %d' %i t=threading.Thread (None, run) t.start() os._exit(1) core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited file size (blocks, -f) unlimited max locked memory (kbytes, -l) 4 max memory size (kbytes, -m) unlimited open files (-n) 1000000 pipe size (512 bytes, -p) 8 stack size (kbytes, -s) unlimited cpu time (seconds, -t) unlimited max user processes (-u) unlimited virtual memory (kbytes, -v) unlimited From bokr at oz.net Sun Aug 28 17:33:05 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 28 Aug 2005 21:33:05 GMT Subject: overload builtin operator References: <3n61u4F1fg2U1@individual.net> <431116ef.2601201920@news.oz.net> Message-ID: <431227bd.7666734@news.oz.net> On Sun, 28 Aug 2005 04:09:10 GMT, bokr at oz.net (Bengt Richter) wrote: [... a response to the OP's apparent desire to "overload the divide operator" with a call to his safediv function ...] The part that rewrote the the AugAssign could only work for plain name Augassign targets, so I introduced a helper function to generate a suitable assignment target node for attributes, subscripts, and slices as well. So the test (still very alpha) looks like the following now: ----< testdiv.py >------------------------------------------------------------------------- def test(): print 1.0/2.0 print 12/3 a=12; b=3 print a/b print 2**a/(b+1) try: print 'print 1/0 =>' print 1/0 except Exception, e: print '%s: %s' %(e.__class__.__name__, e) try: print 'print a/(b*(a-12)) =>' print a/(b*(a-12)) except Exception, e: print '%s: %s' %(e.__class__.__name__, e) try: print 'def foo(x=1/(b-3)): return x =>' def foo(x=1/(b-3)): return x print 'print foo() =>' print foo() except Exception, e: print '%s: %s' %(e.__class__.__name__, e) try: print 'b /= (a-12) =>' b /= (a-12) print 'b after b/=(a-12):', b except Exception, e: print '%s: %s' %(e.__class__.__name__, e) print 's=[15]; s[0] /= 3; print s =>' s=[15]; s[0] /= 3; print s class T(list): def __getitem__(self, i): print i; return 42 def __setitem__(self, i, v): print i, v def __div__(self, other): print self, other; return 4242 t = T() print 't.x=15; t.x /= 3; print t.x =>' t.x=15; t.x /= 3; print t.x print 't=T([15, 27]); t /= 3; print t =>' t=T([15, 27]); t /= 3; print t def foo(x, y): """for dis.dis to show code""" z = x/y x /= y x.a /= y x[z] /= y x[:] /= y if __name__ == '__main__': test() ------------------------------------------------------------------------------------------ Outputfrom run without conversion of / : ----< import_safediv.py >------------------------------------------------------------------ # import_safediv.py from arborist import import_editing_ast, get_augassign_tgt from compiler.ast import Div, CallFunc, Name, AugAssign, Assign def safediv(num, den): if den==0: result = 0*num else: result = num/den print 'safediv(%r, %r) => %r'%(num, den, result) return result def div2safediv(divnode): """replace Div nodes with CallFunc nodes calling safediv with same args""" return CallFunc(Name('safediv'),[divnode.left, divnode.right], None, None, divnode.lineno) def divaugass2safediv(auganode): if auganode.op != '/=': return auganode return Assign([get_augassign_tgt(auganode)], CallFunc(Name('safediv'),[auganode.node, auganode.expr], None, None, auganode.lineno)) callbacks = {Div:div2safediv, AugAssign:divaugass2safediv} def import_safediv(modname, verbose=False): modsafe = import_editing_ast(modname, callbacks, verbose) modsafe.safediv = safediv return modsafe if __name__ == '__main__': modsafe = import_safediv('testdiv', verbose=True) modsafe.test() ------------------------------------------------------------------------------------------- Result from using the above interactively: [14:21] C:\pywk\ut\ast>py24 Python 2.4b1 (#56, Nov 3 2004, 01:47:27) [GCC 3.2.3 (mingw special 20030504-1)] on win32 Type "help", "copyright", "credits" or "license" for more information. First import as usual and run test() >>> import testdiv >>> testdiv.test() 0.5 4 4 1024 print 1/0 => ZeroDivisionError: integer division or modulo by zero print a/(b*(a-12)) => ZeroDivisionError: integer division or modulo by zero def foo(x=1/(b-3)): return x => ZeroDivisionError: integer division or modulo by zero b /= (a-12) => ZeroDivisionError: integer division or modulo by zero s=[15]; s[0] /= 3; print s => [5] t.x=15; t.x /= 3; print t.x => 5 t=T([15, 27]); t /= 3; print t => [15, 27] 3 4242 Now import the import_safediv importer, to import with conversion of ast to effect translation of divides to safediv calls: Import and runs test() much as before: >>> from import_safediv import import_safediv >>> tdsafe = import_safediv('testdiv') >>> tdsafe.test() safediv(1.0, 2.0) => 0.5 0.5 safediv(12, 3) => 4 4 safediv(12, 3) => 4 4 safediv(4096, 4) => 1024 1024 print 1/0 => safediv(1, 0) => 0 0 print a/(b*(a-12)) => safediv(12, 0) => 0 0 def foo(x=1/(b-3)): return x => safediv(1, 0) => 0 print foo() => 0 b /= (a-12) => safediv(3, 0) => 0 b after b/=(a-12): 0 s=[15]; s[0] /= 3; print s => safediv(15, 3) => 5 [5] t.x=15; t.x /= 3; print t.x => safediv(15, 3) => 5 5 t=T([15, 27]); t /= 3; print t => [15, 27] 3 safediv([15, 27], 3) => 4242 4242 Look at the code generated by normal import first >>> import dis >>> dis.dis(testdiv.foo) 40 0 LOAD_FAST 0 (x) 3 LOAD_FAST 1 (y) 6 BINARY_DIVIDE 7 STORE_FAST 2 (z) 41 10 LOAD_FAST 0 (x) 13 LOAD_FAST 1 (y) 16 INPLACE_DIVIDE 17 STORE_FAST 0 (x) 42 20 LOAD_FAST 0 (x) 23 DUP_TOP 24 LOAD_ATTR 3 (a) 27 LOAD_FAST 1 (y) 30 INPLACE_DIVIDE 31 ROT_TWO 32 STORE_ATTR 3 (a) 43 35 LOAD_FAST 0 (x) 38 LOAD_FAST 2 (z) 41 DUP_TOPX 2 44 BINARY_SUBSCR 45 LOAD_FAST 1 (y) 48 INPLACE_DIVIDE 49 ROT_THREE 50 STORE_SUBSCR 44 51 LOAD_FAST 0 (x) 54 DUP_TOP 55 SLICE+0 56 LOAD_FAST 1 (y) 59 INPLACE_DIVIDE 60 ROT_TWO 61 STORE_SLICE+0 62 LOAD_CONST 1 (None) 65 RETURN_VALUE and then corresponding import_safediv (with same line numbers): >>> dis.dis(tdsafe.foo) 40 0 LOAD_GLOBAL 0 (safediv) 3 LOAD_FAST 0 (x) 6 LOAD_FAST 1 (y) 9 CALL_FUNCTION 2 12 STORE_FAST 3 (z) 41 15 LOAD_GLOBAL 0 (safediv) 18 LOAD_FAST 0 (x) 21 LOAD_FAST 1 (y) 24 CALL_FUNCTION 2 27 STORE_FAST 0 (x) 42 30 LOAD_GLOBAL 0 (safediv) 33 LOAD_FAST 0 (x) 36 LOAD_ATTR 4 (a) 39 LOAD_FAST 1 (y) 42 CALL_FUNCTION 2 45 LOAD_FAST 0 (x) 48 STORE_ATTR 4 (a) 43 51 LOAD_GLOBAL 0 (safediv) 54 LOAD_FAST 0 (x) 57 LOAD_FAST 3 (z) 60 BINARY_SUBSCR 61 LOAD_FAST 1 (y) 64 CALL_FUNCTION 2 67 LOAD_FAST 0 (x) 70 LOAD_FAST 3 (z) 73 STORE_SUBSCR 44 74 LOAD_GLOBAL 0 (safediv) 77 LOAD_FAST 0 (x) 80 SLICE+0 81 LOAD_FAST 1 (y) 84 CALL_FUNCTION 2 87 LOAD_FAST 0 (x) 90 STORE_SLICE+0 91 LOAD_CONST 1 (None) 94 RETURN_VALUE I guess this shows that code munging by AST rewriting is somewhat feasible, but you can probably expect to have to dig into dark corners ;-) I need to think through a few things I'm doing by intuition before I go much further... Regards, Bengt Richter From sjmachin at lexicon.net Mon Aug 15 07:56:37 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Aug 2005 21:56:37 +1000 Subject: How can I exclude a word by using re? In-Reply-To: <42ffa598$0$23697$636a15ce@news.free.fr> References: <1124031736.367193.219920@g44g2000cwa.googlegroups.com> <42ffa598$0$23697$636a15ce@news.free.fr> Message-ID: <430082f5$1@news.eftel.com> Bruno Desthuilliers wrote: > could ildg a ?crit : > >> Thank you. >> But what should I do if there are more than one hello and I only want >> to extract what's before the first "hello". > > > Read The Fine Manual ?-) > > >> For example, the raw >> string is "hi, how are you? hello I'm fine, thank you hello. that's it >> hello", I want to extract all the stuff before the first hello? > > > re.findall(r'^(.*)hello', your_string_full_of_hellos) Nice try, but it needs a little refinement to do what the OP asked for: >>> import re >>> h = "hi g'day hello hello hello" >>> re.findall(r'^(.*)hello', h) ["hi g'day hello hello "] >>> re.findall(r'^(.*?)hello', h) ["hi g'day "] >>> re.findall(r'^(.*?)hello', h)[0] "hi g'day " From tjreedy at udel.edu Wed Aug 10 00:37:48 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Aug 2005 00:37:48 -0400 Subject: Passing arguments to function - (The fundamentals are confusingme) References: <0S5Ke.5236$3p.2192@bignews3.bellsouth.net> Message-ID: "Christopher Subich" wrote in message news:0S5Ke.5236$3p.2192 at bignews3.bellsouth.net... > Dennis Lee Bieber wrote: >> In a more simplistic view, I'd reverse the phrasing... The name >> "x" is assigned to the object "y" (implying it is no longer attached to >> whatever used to have the name) I agree that this is the more useful way to see it. I intentionally said 'useful' rather than 'correct' since I consider the former to be the way to judge viewpoints. And I base the usefullness view on an informal (and yes, unscientific) mental tabulation of newbie confusions posted to c.l.p over several years. But better data could revise my judgment.. > No, because that'd imply that the object 'y' somehow keeps track of the > names assigned to it, I disagree with your implication and see it the other way. To me, 'the object is bound to a name' implies that the object can only be bound to one name while the name could have many objects bound to it, which is the opposite of the case. Analogy: in an elementary school, students are assigned to (bound to) a room. The name=>room binding is recorded in a list (the 'namespace', alphabetical for lookup of names) in the principal's office. The rooms do not have to have a list of the students assigned to them, even though one could be derived from the master list, as one could Put another way: 'the name is bound' implies pretty clearly that the name is acted up, and it is that acting upon that makes the object a (new) property of the name. Nothing need be done to the object itself. This is even clearer if 'bound' is expanded to 'associated with object-fetch information'. So 'x = y' means "associated name 'x' with the object-fetch information that name 'y' is currently associated with." >The object is the property of the name, not vice versa. I agree, and see the binding of the name (to the object, as explained above) as that which sets the property. Terry J. Reedy From pwatson at redlinepy.com Mon Aug 15 13:41:37 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 15 Aug 2005 12:41:37 -0500 Subject: Using for in one-liner In-Reply-To: <1124126384.664929.313090@g43g2000cwa.googlegroups.com> References: <3mbu82F15h18oU1@individual.net> <1124124590.563497.241560@g43g2000cwa.googlegroups.com> <4300CB9D.2020809@redlinepy.com> <1124126384.664929.313090@g43g2000cwa.googlegroups.com> Message-ID: <4300D3D1.6080909@redlinepy.com> BranoZ wrote: > In "man python" > "Here command may contain multiple statements separated by > newlines. Leading whitespace is significant in Python statements!" > > In "man bash" search for \n (/\\n) > Frankly, I know bash for 10 years, but this has surprised me, too. > > BranoZ Using a '$' before the string works in the ksh that is part of FC4. However, it does not work on the pdksh that is in FC3 and Cygwin. It also does not work on AIX ksh. $ print $'now' $now From mhellwig at xs4all.nl Thu Aug 4 06:59:25 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Thu, 04 Aug 2005 12:59:25 +0200 Subject: pain In-Reply-To: References: Message-ID: <42f1f51b$0$11068$e4fe514c@news.xs4all.nl> Mage wrote: >> > Thank you, I will check this out. My company will switch to a jsp site. Well I don't know your company and how many developers there are but I know this; a manager telling me what tools to use to do my job is a bad manager by definition because he should realize that the people who best know what tools to use are the peope who use the tools*. If by any chance a manager believes that his employees aren't qualified to make that decision for them self then he hired the wrong people, which makes him bad manager too. But perhaps there are other compelling reasons to switch to a jsp site, but since this is webbased, there are *tons* of ways to mix your favourite language with it, even as abstracted as having a jsp (proxy) page do nothing more then fetch its page from a python powered internal webserver. -- mph * Did you know that most good chef cooks have their own knive set? And what do you think is the reason a restaurant manager don't tell them to use the company in-house Amefa blades instead of his global knives? From sethjn at gmail.com Sat Aug 27 15:53:57 2005 From: sethjn at gmail.com (Seth Nielson) Date: Sat, 27 Aug 2005 14:53:57 -0500 Subject: gdbm dying wierdly In-Reply-To: References: Message-ID: Nevermind. The problem wasn't in gdbm. I had "exception" in stead of "Exception" in the try-except statement. -- SethN On 8/27/05, Seth Nielson wrote: > > Hi guys. > > I'm using a python script as a redirector for Squid. My python script uses > gdbm and exhibits some weird behavior. > > 1. If I run the script stand-alone, it loads the gdbm database file just > fine. > 2. If the script is launched from squid, when it tries to load the gdbm > database, it dies WITHOUT an exception! It just disappears! (signal maybe?) > > Please help! I'm up against the wall! > > -- Seth N. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Fri Aug 26 21:20:46 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 26 Aug 2005 21:20:46 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> <3n8ddiFbhg7U1@individual.net> Message-ID: <8664tsw4y9.fsf@bhuda.mired.org> John Bokma writes: > It's time consuming because there is (yet) no need for it. When I > started to use Usenet there where only a handful of clients (IIRC), nn > and another one (rn?) are the only ones that I can recall. By the time nn was out, there were a number of radically diffrent alternatives. The original news client (not NNTP - it predated that) was readnews. rn was the first alternative to gain any popularity. By the time it came out, there were alterntiave curses-based readers like notes and vnews. By the time nn came out, there were even X-based news readers available like xrn and xvnews. It may be that the site you were at only offered a few readers. But that's a different issue. All of this is from memory, of course - and may well be wrong. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From alessandro.bottoni at infinito.it Mon Aug 22 03:57:43 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Mon, 22 Aug 2005 07:57:43 GMT Subject: win32 - associate .pyw with a file extension... References: <1124687255.717835.145590@g49g2000cwa.googlegroups.com> Message-ID: knutsample at gmail.com wrote: > Hello! > > I'm trying to associate a file extension to my wxPython script so that > all I have to do is double click on the file and my python script will > load up with the path of that file. > > For instance, I've associated all .py files to be opened up with > emacs.exe. If I double click on a .py file, emacs.exe would open up > with that file in its buffer. > > Is there a way to do this with a non-exe (wxPython script)? Everytime > I try to associate a certain file extension (right clicking file->Open > with->Choose program) with my python script (.pyw) windows states that > I do not have a valid win32 program. Is there a way to do this with a > python script? Thank you for your time. As long as I can see, you are trying to associate your .pyw extension directly with your python script, let say "MyProgram.pyw". This cannot work because Windows does not know how to run MyProgram.pyw itself. You have to associate the .pyw extension with the python interpreter. The name of your script has to be passed to python on the command line (together with its command line parameter). That is, Windows has to be requested to executed this command line: c:/.../python_directory/python.exe MyProgram.pyw FirstParam SecondParam Most likely, you are trying to execute this, instead: c:/.../MyPrograDir/MyProgram.pyw FirstParam SecondParam HTH ----------------------------------- Alessandro Bottoni From saint.infidel at gmail.com Tue Aug 9 11:54:37 2005 From: saint.infidel at gmail.com (infidel) Date: 9 Aug 2005 08:54:37 -0700 Subject: What are modules really for? In-Reply-To: <42F8CC8F.7020500@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> Message-ID: <1123602877.802803.281500@g14g2000cwa.googlegroups.com> > I am very new to Python, but have done plenty of development in C++ and > Java. And therein lies the root of your question, I believe. > One thing I find weird about python is the idea of a module. Why is this > needed when there are already the ideas of class, file, and package? One reason is that functions need a place to exist too. In Java, every function, even "static" ones has to be a class method. In Python, "static" functions are best kept in a module. Another thing is that packages were a later addition to the language. > To my mind, although one CAN put many classes in a file, it is better to > put one class per file, for readability and maintainability. Personally I find it easier to maintain a set of related classes when they're all in the same file. I've got a few modules that I'm currently hacking on, each of which contains a handful of classes. Maybe it's just a matter of scale, since these are both fairly small libraries, but I just don't see any advantage to splitting them up into multiple files. > One can then create packages and libraries, using groups of files, one > class per file. Since Java's compiler enforces this, perhaps you've just come to accept it as "normal". > Python seems to let you group classes together in one file and call it a > module, but what for? What if one of your classes creates/manipulates other classes. If they're in the same module then they all exist in the same namespace and you don't have to have modules importing each other or such things. > I find that this, combined with mixins, makes it difficult to find out > where code is inherited from. Perhaps you are relying too much on inheritance, then? > With single inheritance in C++ or Java, if you wanted to see what a > method did and it appeared to be inherited, you would simply look in the > base class's file, and if necessary recurse up the inheritance hierarchy > until you found the method. > > With Python an inherited method could be in one of many base classes > and/or mixins and there seems no particular logic as to what the > filename would be. It shouldn't be too hard to figure out, unless someone was being intentially vague. You could always fire up the interpreter, import your class, and check it's .mro property (method resolution order), which lists the classes in the order they will be examined to find a method named at runtime. > Am I missing something? I just think you're thinking in terms of Java. You'll pick things up quickly, though :-) From bronger at physik.rwth-aachen.de Fri Aug 26 17:22:13 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Fri, 26 Aug 2005 23:22:13 +0200 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> Message-ID: <878xyoe6m2.fsf@wilson.rwth-aachen.de> Hall?chen! "Terry Reedy" writes: > "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message > news:7xmzn41ofc.fsf at ruckus.brouhaha.com... > >> "Terry Reedy" writes: >> >>> Str.find is redundant with the Pythonic exception-raising >>> str.index and I think it should be removed in Py3. >> >> I like having it available so you don't have to clutter your code >> with try/except if the substring isn't there. But it should not >> return a valid integer index. > > The try/except pattern is a pretty basic part of Python's design. > One could say the same about clutter for *every* function or > method that raises an exception on invalid input. Should more or > even all be duplicated? Why just this one? Granted, try/except can be used for deliberate case discrimination (which may even happen in the standard library in many places), however, it is only the second most elegant method -- the most elegant being "if". Where "if" does the job, it should be prefered in my opinion. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646 From uval at rz.uni-karlsruhe.de Fri Aug 5 09:44:25 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-15?Q?Daniel_Sch=FCle?=) Date: Fri, 05 Aug 2005 15:44:25 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: > I would also like to see some more functions to make > calculations with complex number more convenient > e.g. > c = 27 c = 27+0j From john at castleamber.com Fri Aug 26 21:47:31 2005 From: john at castleamber.com (John Bokma) Date: 27 Aug 2005 01:47:31 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <7xek8h5usm.fsf@ruckus.brouhaha.com> <86mzn4w74d.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > John Bokma writes: > >> Paul Rubin wrote: >> >>> Mike Meyer writes: >>>> > Another advantage is that evewry internet-enabled computer today >>>> > already comes with an HTML renderer (AKA browser) >>>> >>>> No, they don't. Minimalist Unix distributions don't include a browser >>>> by default. I know the BSD's don't, and suspect that gentoo Linux >>>> doesn't. >>> >>> Lynx? >> >> Emacs? > > Neither one is installed by default on the systems in question. Both > are available via the system packaging tools. > > fetch is installed on FreeBSD, but all it does is download the > contents of a URL - it doesn't render them. My brain does :-D -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From zen19725 at zen.co.uk Wed Aug 10 10:57:07 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 10 Aug 2005 15:57:07 +0100 Subject: Why is this? References: Message-ID: On Wed, 10 Aug 2005 12:40:54 +0200, Jiri Barton wrote: >Hi everyone, > >I have a problem with initialization. >>>> a, b = [[]]*2 >>>> a.append(1) >>>> b >[1] > >Why is this? Why does not this behave like the below: > >>>> a, b = [[], []] >>>> a.append(1) >>>> b >[] In your 1st example a and b point to copies of the same object, in the second example the point to two separate objects that happen to have the same repr() representation. Here's another example of the same thing: >>> c = [] >>> d = [c,c] >>> e = [[],[]] >>> d [[], []] >>> e [[], []] (d) and (e) appear to be the same (i.e. they have the same repr() form), but they are not. Consider: >>> e[1].append("spam") >>> e [[], ['spam']] But: >>> d[1].append("spam") >>> d [['spam'], ['spam']] The point is that in Python an object's repr() -- which stands for "representation" -- doesn't actually tell you how the object is represented inside the innards to the Python system. Incidently I am currently working on a programming language that fixes this problem. In my language "Unify", the equivalent of repr is called "storage manager format" (or SM-format) because if two values have the same SM-format it is guaranteed that the system will treat them identiacally. The SM-format can thus be used for serialisation, and incidently it is also the same format in which literals are written in a program. In Unify to specify an Array containing two separate empty Arrays would look like this: e := #(() ()) The code to add a value to one sub-array, and print the result is: e[1] @= 'spam'. // means same as Python d[1].append("spam") out << sm(e). // convert to SM-string, output it to stdout This would print this text: #(() (spam)) An array containing two copies of the same sub-array might look like this: d := #( () &[0] ) Where "&[0]" means "pointer to the 0th array subscript". -- Email: zen19725 at zen dot co dot uk From peter at engcorp.com Thu Aug 11 22:04:12 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 11 Aug 2005 22:04:12 -0400 Subject: command line reports In-Reply-To: References: <67Cdnd00Bo62PWbfRVn-1w@powergate.ca> <42fbb12b.1198953554@news.oz.net> Message-ID: Darren Dale wrote: > Thanks, I didnt realize that \r is different from \n. \r has is a byte with value 13, which is the Carriage Return (CR) control character in ASCII. \n has value 10 and is the Line Feed (LF) character. CR is named after the old teletypewriter operation involving moving the "carriage" back to one edge to restart typing text. It wasn't very useful without also moving to a new line (unless you wanted to cut your paper by repeatedly printing a line of hyphens), which is what LF was used for -- like rotating the platen (I think that's the word) on a typewriter up one line. Hitting the arm on a typewriter is like a CR plus a LF together, and this is immortalized in the CR/LF combination required still under Microsoft's most advanced operating systems, long after it's no longer necessary to have the two distinct characters. () Most operating systems have adopted the combined behaviour (go to start of line, move down one line) together under the LF character, since ASCII doesn't have a single "new line" character (though VT or Vertical Tab has been proposed for that since it has no other practical use these days). The CR character still generally does the "go to start of line" operation when used in the console, so it's pretty handy to "overwrite the previous line" as you wanted to. In rare situations, such as terminal software like Hyperterm, LF doesn't necessarily take you back to the start of a line but merely moves you down a single line at the same column position, much like its original/intended behaviour. -waxing-historically-and-97-percent-accurately y'rs, Peter From pwatson at redlinepy.com Mon Aug 1 11:49:36 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 01 Aug 2005 10:49:36 -0500 Subject: python ETL In-Reply-To: <1122898017.573173.189620@g14g2000cwa.googlegroups.com> References: <1122898017.573173.189620@g14g2000cwa.googlegroups.com> Message-ID: <3l6ukjF119dmqU1@individual.net> arielgr at gmail.com wrote: > Hi, > My company is involved in the development of many data marts and > data-warehouses, and I currently looking into migrating our old set of > tools (written in Korn) to a new, more dynamic and robust one. I am > looking into python as I have heard that it could be a good contestant > for the job, and wanted to know if anyone knew of an existing open > source project which implements ETL using python, or any libraries that > may ease the production of such tools. > > Thanks. Robert is right; you have not really given much information. However, I would have to assume that if homebrew shell scripts have been doing the work adequately, then the marts and warehouses are not very large and the datasets are primarily text rather than binary. If this is the case and you are only seeking incremental improvement, then Python would be a very good choice. Perl would also do the job. Just about any language would work. Yes, there are many reasons to choose Python. However, you would have to build any scalability and metadata management. If you seek a radical improvement, it is available, but I do not know of any free tools that will do it. A question like this will probably not be answered in a newsgroup post or even the exchange of a few emails. Choosing an effective tool for the organization is not a trivial process. It requires knowledge of both the tools and the organization's methodologies and processes. If you do not have staff who can do this, most companies find it is much cheaper and faster to pay someone who does know (a consultant) to assist them in assessing their requirements, tool selection, and forming an implementation plan. Yes, your company staff can learn a lot by experimenting and playing with several tools, but shareholders might not view that approach as the most effective. From fredrik at pythonware.com Wed Aug 31 09:14:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 15:14:24 +0200 Subject: Sockets: code works locally but fails over LAN References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> Message-ID: "n00m" wrote: > PEOPLE, WHY ON THE EARTH IT DOES NOT WORK OVER LAN ??? what happens if you change s1.bind((host, port)) to s1.bind(("", port)) ? From kimsj at mobile.snu.ac.kr Sun Aug 28 08:43:32 2005 From: kimsj at mobile.snu.ac.kr (James Kim) Date: Sun, 28 Aug 2005 21:43:32 +0900 Subject: Doubt C and Python In-Reply-To: <430b7335.1489472047@news.xs4all.nl> References: <430b7335.1489472047@news.xs4all.nl> Message-ID: Wouter van Ooijen (www.voti.nl) wrote: > I use Python when my time is most valuable (in most cases it is), in > the very few cases the computer's time is more valuable I write in > C/C++. In cases when the computer's time is more valuable, why not use CPython with C/C++ API? Only most time consuming parts can be replaced to C/C++ codes so as to increase the speed up to native C/C++ programs). -James (^o^) From jstroud at mbi.ucla.edu Mon Aug 1 15:00:35 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 1 Aug 2005 12:00:35 -0700 Subject: Dabo in 30 seconds? In-Reply-To: <1122901170.19618.296.camel@localhost.localdomain> References: <200508010830.27322.ed@leafe.com> <1122901170.19618.296.camel@localhost.localdomain> Message-ID: <200508011200.35374.jstroud@mbi.ucla.edu> On Monday 01 August 2005 05:59 am, Cliff Wells wrote: > But then I'm willing to > actually work a little to get what I want. ?For other it seems they > won't be happy unless you drive to their house and install it for them > (which only seems fair, cause if you hadn't volunteered to write such > crap then they wouldn't have had to be bothered with it in the first > place, damn you). ?Maybe you wouldn't mind tidying up a bit and washing > a few dishes while you're at it? ? Perhaps some of us are writing software with non-developer end-users in mind, and we kind of keep that mentality when evaluating modules our code uses. Do your end-users really want to figure out that the need to and how to install stylized text controls, whatever that is? -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From martijn at gamecreators.nl Thu Aug 25 05:25:41 2005 From: martijn at gamecreators.nl (martijn at gamecreators.nl) Date: 25 Aug 2005 02:25:41 -0700 Subject: newbie question: convert a list to one string In-Reply-To: References: <1124959699.071708.239210@g14g2000cwa.googlegroups.com> Message-ID: <1124961941.291656.209380@o13g2000cwo.googlegroups.com> Thanks that's what i need. From savvyside at aol.com Thu Aug 25 06:43:52 2005 From: savvyside at aol.com (michael) Date: Thu, 25 Aug 2005 10:43:52 GMT Subject: Command Line arguments References: <9gtqg1lkso6m6ukipku1ac7hk9sejhi3ld@4ax.com> Message-ID: On Thu, 25 Aug 2005 00:46:41 -0700, Tim Roberts wrote: > michael wrote: > >>I have a question about Windows based python (2.4 and later). >> >>For example, if I make a script called test.py like so: >> >>import sys >>print sys.argv >> >>then run it: >> >>python test.py this is a test >> >>I see a list with >> >>['test.py', 'this', 'is', 'a', 'test'] >> >> >>All is good! >> >>BUT... >> >>If i make .py extensions be run as exes (by setting the .py extension to >>be executable with PATHEXT setting in environment variables, the Python >>program will run, but NO arguments are passed! >> >>For example, after setting .py extension to be executable, i get this: >> >>test this is a test >> >>I get ['test.py]. NO arguments are passed. >> >>NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and >>earlier works FINE. > > It is a configuration problem. Bring up a Command Shell and run the assoc > and ftype commands like this: > > C:\Tmp>assoc .py > .py=Python.File > > C:\Tmp>ftype Python.File > Python.File="C:\Apps\Python24\python.exe" "%1" %* > > C:\Tmp> > > The KEY part of that is the %* at the end of the Python.File defintion. > That tells the system to insert the rest of the command line parameters at > that point. If you have ONLY the "%1", the command will run but no > parameters will be forwarded. If so, you can fix this by typing: > > C:\Tmp>ftype Python.File="C:\Apps\Python24\python.exe" "%1" %* > > Substituting your own path, of course. Tim, I can confirm you were right! Thank you very much. This will get us through the issue. I wonder why this was needed? One way or the other, you taught me something and I thank you. Michael Christopher From onurb at xiludom.gro Wed Aug 31 06:53:36 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 31 Aug 2005 12:53:36 +0200 Subject: Bicycle Repair Man usability In-Reply-To: <1125442092.912504.86760@g47g2000cwa.googlegroups.com> References: <1125440834.163913.49830@g44g2000cwa.googlegroups.com> <1125442092.912504.86760@g47g2000cwa.googlegroups.com> Message-ID: <43158c31$0$11580$626a14ce@news.free.fr> matt wrote: (snip) > I'd like to hear other's experiences with refactoring in python. Most > of the projects I work on are quite small relative to some of the Java > projects I've worked on. Python being much less verbose and much more dynamic than Java, the LOCs/functionnalities ratio can be very different. So what would be a medium-size project in Java usually become a small-size project in Python. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From kent37 at tds.net Tue Aug 2 11:00:57 2005 From: kent37 at tds.net (Kent Johnson) Date: Tue, 02 Aug 2005 11:00:57 -0400 Subject: finding sublist In-Reply-To: <1122991014.595476.5740@g47g2000cwa.googlegroups.com> References: <1122991014.595476.5740@g47g2000cwa.googlegroups.com> Message-ID: <42ef8a40$1_3@newspeer2.tds.net> giampiero mu wrote: > hi everyone > > my target is implement a function controlla(string - a binary string-) > that check if there is in a string two equal not overlapping > subsequences at least of length limitem: You can do this with a regular expression: >>> import re >>> r=re.compile(r'(?P.{4,}).*(?P=seq)') >>> r.match('abcaoeaeoudabc') >>> r.match('abcdaeaeuabcd') <_sre.SRE_Match object at 0x008D67E0> >>> _.group(1) 'abcd' >>> r.match('abcdefgaeaeuabcdefg') <_sre.SRE_Match object at 0x008D68E0> >>> _.group(1) 'abcdefg' Kent > > my code: > > def controlla(test): > # print test > limitem=4 > lunghezz=len(test) > > l1=lunghezz-limitem+1 > l2=lunghezz-limitem+1 > f=0 > > for ii in range(l1): > for kk in range(l2): > t1=test[ii:ii+limitem] > t2=test[kk:kk+limitem] > if abs(ii-kk)>=limitem : > if t1==t2 : > f=1 > if f==1 : > break > break > break > if f==0 : > return test > else: > return 'no' > > > the question is: Is there a faster way doing that? I don't know, > changing string into list or array, using map, or module, using > different loop, regular expression,funcional programming , list > comprehensions , sets, different looping techniques, i dont > know.......(!) > From cyril.bazin at gmail.com Fri Aug 12 07:35:13 2005 From: cyril.bazin at gmail.com (Cyril Bazin) Date: Fri, 12 Aug 2005 13:35:13 +0200 Subject: Help sorting a list by file extension In-Reply-To: References: <42fbf3be.1215996460@news.oz.net> Message-ID: Maybe simpler but not very much simpler: one line for each solution. And in your solution the lambda is evaluated at each comparaison of the sort algorithm isn't it? So your code seems less productive than the bengt's code which apply the same code as the lambda only one time by entry in the list. Cyril On 8/12/05, George Yoshida wrote: > > Bengt Richter wrote: > >>>>[name for dec,name in sorted((int(nm.split('.')[1]),nm) for nm in > namelist)] > > > > ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20 > '] > > Giving a key argument to sorted will make it simpler:: > > >>> sorted(namelist, key=lambda x:int(x.rsplit('.')[-1])) > > -- george > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lambacck at computer.org Tue Aug 2 12:15:48 2005 From: lambacck at computer.org (Chris Lambacher) Date: Tue, 2 Aug 2005 12:15:48 -0400 Subject: Terminate a thread that doesn't check for events In-Reply-To: <9CA58FB7E095F146AD3E7FE1E5855929042FAE@brain.klausatlanta.local> References: <9CA58FB7E095F146AD3E7FE1E5855929042FAE@brain.klausatlanta.local> Message-ID: <20050802161548.GA23973@computer.org> No. On Linux a separate thread is a separate process with shared memory. You can send a signal to a particular process and catch that signal as an indication that you need to terminate (perhapse something that is set up before running your long running process so that it is generic). In windows threads are separate beasts from processes(almost) and there are functions for terminating them (though I don't think gracefully). Unfortunately I can't comment on other platforms. -Chris On Tue, Aug 02, 2005 at 11:54:57AM -0400, Liu Shuai wrote: > Thanks for the reply Chris. > > Are you suggesting running the task in a *separate* process instead of a > separate *thread*? Because if that's the case, I will have to share data > (and possible memory) between that new process and my "master" process > since they depend on one other. > > Yeah I will sure post it if I can find an elegant solution. > > Thank you, > LS > > > -----Original Message----- > > From: Chris Lambacher [mailto:lambacck at computer.org] > > Sent: Tuesday, August 02, 2005 11:50 AM > > To: Liu Shuai > > Subject: Re: Terminate a thread that doesn't check for events > > > > Hi, > > > > There is no cross platform way to do this. You need to periodically > check > > a > > quit flag, or perform a platform specific action to terminate it. On > > Linux > > you can send the process a signal. On windows you will need to use > the > > win32all package. If you decide to go the later route, maybe you > could > > encapsulate the thread termination code in a module and share it with > the > > Python community. > > > > -Chris > > > > On Tue, Aug 02, 2005 at 09:51:31AM -0400, Liu Shuai wrote: > > > Can someone please comment on this? > > > > > > > > > > > > > --------------------------------------------------------------------- > > ----- > > > > > > From: python-list-bounces+sliu=kaneva.com at python.org > > > [mailto:python-list-bounces+sliu=kaneva.com at python.org] On Behalf > Of > > Liu > > > Shuai > > > Sent: Monday, August 01, 2005 4:29 PM > > > To: python-list at python.org > > > Subject: Terminate a thread that doesn't check for events > > > > > > > > > > > > Hi all, > > > > > > > > > > > > I am aware that similar and probably same questions have been > posted > > many > > > times, but I was unable to find a solution after reading a dozen > > threads > > > in the archive. So here it goes again. > > > > > > > > > > > > I have a thread that does some heavy task (hash calculation, for > > > instance). I need a mechanism that works *across platforms* to > stop > > that > > > calculation if user decides to exit. How can I do that? > > > > > > I can not do the standard "periodical checking" way since there > is > > only > > > one function/step call in my thread. > > > > > > > > > > > > Here is a snippet of my thread classes to help illustrate the > > problem: > > > > > > > > > > > > class Dispatcher(): > > > > > > def __init__(self): > > > > > > self.__worker = Worker() > > > > > > > > > > > > def start(self): > > > > > > self.__worker.start() > > > > > > > > > > > > def stop(): > > > > > > #how do i stop the worker? > > > > > > > > > > > > class Worker(threading.Thread): > > > > > > def __init__(self): > > > > > > > > > > > > def run(self): > > > > > > oneTimeConsumingCall() > > > > > > > > > > > > > > > > > > Thank you in advance for any suggestions/pointers. > > > > > > > > > > > > LS > > > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list From michele.simionato at gmail.com Wed Aug 24 03:07:33 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 24 Aug 2005 00:07:33 -0700 Subject: shelve non-transparency In-Reply-To: <7x8xyrho77.fsf_-_@ruckus.brouhaha.com> References: <7x8xyrho77.fsf_-_@ruckus.brouhaha.com> Message-ID: <1124867253.007551.238780@g47g2000cwa.googlegroups.com> The option writeback=True seems to work: # put something in the shelve import shelve class C(object): pass s = shelve.open("x.shelve") s["x"] = C() s.close() # read it s = shelve.open("x.shelve", writeback=True) c = s["x"] c.attr = 1 print s["x"].attr # => 1 s.close() Michele Simionato From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Fri Aug 12 05:01:13 2005 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Fri, 12 Aug 2005 11:01:13 +0200 Subject: win32com: use not possible as normal user Message-ID: <3m36qpF14jsl9U1@news.dfncis.de> Hello, I've installed Python 2.4 and the win32 extensions, using administrator rights, under Windows XP in "C:\Programme". As this is a directory without spaces I didn't expect any problems. But now I can't _use_ win32com as a normal user, because normal users can't write there: PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import win32com.client ... >>> import wdclass >>> kal = wdclass.easyWord() Traceback (most recent call last): File "", line 1, in ? File "h:\eigene dateien\abt\kalender\wdclass.py", line 10, in __init__ self.wdApp = win32com.client.Dispatch('Word.Application') File "C:\Programme\Python24\Lib\site-packages\win32com\client\__init__.py", line 96, in Dispatch return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx) File "C:\Programme\Python24\Lib\site-packages\win32com\client\__init__.py", line 38, in __WrapDispatch klass = gencache.GetClassForCLSID(resultCLSID) File "C:\Programme\Python24\Lib\site-packages\win32com\client\gencache.py", line 179, in GetClassForCLSID mod = GetModuleForCLSID(clsid) File "C:\Programme\Python24\Lib\site-packages\win32com\client\gencache.py", line 222, in GetModuleForCLSID mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor) File "C:\Programme\Python24\Lib\site-packages\win32com\client\gencache.py", line 262, in GetModuleForTypelib AddModuleToCache(typelibCLSID, lcid, major, minor) File "C:\Programme\Python24\Lib\site-packages\win32com\client\gencache.py", line 575, in AddModuleToCache _SaveDicts() File "C:\Programme\Python24\Lib\site-packages\win32com\client\gencache.py", line 64, in _SaveDicts f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb") IOError: [Errno 13] Permission denied: 'C:\\Programme\\Python24\\lib\\site-packages\\win32com\\gen_py\\dicts.dat' >>> Do I have to move my Python installation to another directory with write permissions for normal users? Or is there a simpler way? This might not be a problem for users with english Windows installations who can get bitten anyway by the space in "program files". But in my german installation I never had a reason to install Python outside of "Programme". Thanks for any help, Koczian -- Dr. Sibylle Koczian Universitaetsbibliothek, Abt. Naturwiss. D-86135 Augsburg e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE From grante at visi.com Tue Aug 23 10:41:04 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 23 Aug 2005 14:41:04 -0000 Subject: py-serial + CSV References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> Message-ID: <11gmdc0ofi88o1d@corp.supernews.com> On 2005-08-23, McBooCzech wrote: >>>> import serial >>>> s = serial.Serial(port=0,baudrate=4800, timeout=20) >>>> s.readline() > '$GPRMC,101236.331,A,5026.1018,N,01521.6653,E,0.0,328.1,230805,,*09\r\n' > > my next intention was to do something like this: > > import csv > r = csv.reader(s.readline()) > for currentline in r: > if currentline[0] == '$GPRMC': > print currentline[2] > print currentline[4] > > but it does not work For something that simple (the data itself doesn't contain any commas), it's probably easier to use the string's split method rahter than CSV. Try something like this: line = s.readline() words = line.split(',') -- Grant Edwards grante Yow! Now KEN and BARBIE at are PERMANENTLY ADDICTED to visi.com MIND-ALTERING DRUGS... From cfbolz at gmx.de Sun Aug 28 11:59:25 2005 From: cfbolz at gmx.de (Carl Friedrich Bolz) Date: Sun, 28 Aug 2005 17:59:25 +0200 Subject: Release of PyPy 0.7.0 Message-ID: <4311DF5D.2060804@gmx.de> pypy-0.7.0: first PyPy-generated Python Implementations ============================================================== What was once just an idea between a few people discussing on some nested mailing list thread and in a pub became reality ... the PyPy development team is happy to announce its first public release of a fully translatable self contained Python implementation. The 0.7 release showcases the results of our efforts in the last few months since the 0.6 preview release which have been partially funded by the European Union: - whole program type inference on our Python Interpreter implementation with full translation to two different machine-level targets: C and LLVM - a translation choice of using a refcounting or Boehm garbage collectors - the ability to translate with or without thread support - very complete language-level compliancy with CPython 2.4.1 What is PyPy (about)? ------------------------------------------------ PyPy is a MIT-licensed research-oriented reimplementation of Python written in Python itself, flexible and easy to experiment with. It translates itself to lower level languages. Our goals are to target a large variety of platforms, small and large, by providing a compilation toolsuite that can produce custom Python versions. Platform, Memory and Threading models are to become aspects of the translation process - as opposed to encoding low level details into a language implementation itself. Eventually, dynamic optimization techniques - implemented as another translation aspect - should become robust against language changes. Note that PyPy is mainly a research and development project and does not by itself focus on getting a production-ready Python implementation although we do hope and expect it to become a viable contender in that area sometime next year. Where to start? ----------------------------- Getting started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html PyPy Documentation: http://codespeak.net/pypy/dist/pypy/doc/ PyPy Homepage: http://codespeak.net/pypy/ The interpreter and object model implementations shipped with the 0.7 version can run on their own and implement the core language features of Python as of CPython 2.4. However, we still do not recommend using PyPy for anything else than for education, playing or research purposes. Ongoing work and near term goals --------------------------------- PyPy has been developed during approximately 15 coding sprints across Europe and the US. It continues to be a very dynamically and incrementally evolving project with many one-week meetings to follow. You are invited to consider coming to the next such meeting in Paris mid October 2005 where we intend to plan and head for an even more intense phase of the project involving building a JIT-Compiler and enabling unique features not found in other Python language implementations. PyPy has been a community effort from the start and it would not have got that far without the coding and feedback support from numerous people. Please feel free to give feedback and raise questions. contact points: http://codespeak.net/pypy/dist/pypy/doc/contact.html contributor list: http://codespeak.net/pypy/dist/pypy/doc/contributor.html have fun, the pypy team, of which here is a partial snapshot of mainly involved persons: Armin Rigo, Samuele Pedroni, Holger Krekel, Christian Tismer, Carl Friedrich Bolz, Michael Hudson, Eric van Riet Paap, Richard Emslie, Anders Chrigstroem, Anders Lehmann, Ludovic Aubry, Adrien Di Mascio, Niklaus Haldimann, Jacob Hallen, Bea During, Laura Creighton, and many contributors ... PyPy development and activities happen as an open source project and with the support of a consortium partially funded by a two year European Union IST research grant. Here is a list of the full partners of that consortium: Heinrich-Heine University (Germany), AB Strakt (Sweden) merlinux GmbH (Germany), tismerysoft GmbH(Germany) Logilab Paris (France), DFKI GmbH (Germany) ChangeMaker (Sweden), Impara (Germany) From 816168 at gmail.com Fri Aug 5 09:21:47 2005 From: 816168 at gmail.com (Kevin) Date: 5 Aug 2005 06:21:47 -0700 Subject: The ONLY thing that prevents me from using Python Message-ID: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> I have been using java (jsp/servlets), vb/asp and perl for a few years. Almost all my projects are web site development related, and many of my clients' web sites are hosted on those shared web hosting services. The problem is that it's difficult to find hosting services with Python installed and supported. And most hosting companies are reluctant to install it for you because they don't want to do the extra work(they would always say to me, why don't you use php or java or asp or per?). I have searched and found some companies that support Python. But still there are far few choices than other options. I am sure this issue has already been raised a billion times. I just feel very frustrated on this. I want to learn and use Python in my web projects. One day in last December I decided to learn Python, because of Bruce Eckel's recommendation on his web site (I started java with his book). After writing a few scripts (each with a hundred lines or less), I really liked Python, even though at first to me, it has a very different style and mindset from my accustomed java approach. I enjoyed the experience and was ready to delve into the OO and other aspect of Python. But because of the hosting issue, I stopped and since then have spent more time on php, and it seems that I would soon become a full time PHPer now. I really wish Python could be more widely available on web server machines. This is just my own experience and I would like to hear your comments. From kay.schluehr at gmx.net Wed Aug 31 08:52:40 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 Aug 2005 05:52:40 -0700 Subject: Bicycle Repair Man usability References: <1125439673.688666.264820@z14g2000cwz.googlegroups.com> Message-ID: <1125492760.029184.311500@g47g2000cwa.googlegroups.com> Sybren Stuvel wrote: > > -Get rid of extra variables by shifting them inline (e.g.: > > a=1;b=2;c=a+b --> c=1+2) > > This is already excess functionality IMO. I don't think that Rex talked about his programming style but about three and only three refactoring methods survived in BRM from ~30 Fowler described in his book. By the way I can't remember the one you picked up but I remember the reverse i.e. introducing intermediate variable names for readability and debugging purposes. Instead of writing f(g(h(...))) it is sometimes adaequate to write x = h(...) f(g(x)) I use this a lot in particular in C++. Optimzing compilers eliminate runtime penalties. This is of course different in CPython. In case of BRM I'm not sure why it is particular hard to implement "Move Method" for instance? BRM is shipped with a lot of testcases which is good but neither defines requirements nor leads a discussion about refactoring methods in Python. Needless to say that the code is not well documented. Kay From donn at drizzle.com Sun Aug 21 00:30:17 2005 From: donn at drizzle.com (Donn Cave) Date: Sun, 21 Aug 2005 04:30:17 -0000 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> Message-ID: <1124598617.52614@yasure> Quoth Mike Meyer : [... wandering from the nominal topic ...] | *) The most difficult task was writing horizontal microcode, which | also had serious concurrency issues in the form of device settling | times. I dealt with that by inventing a programming model that hid | most of the timing details from the programmer. It occasionally lost a | cycle, but the people who used it after me were *very* happy with it | compared to the previous model. My favorite concurrency model comes with a Haskell variant called O'Haskell, and it was last seen calling itself "Timber" with some added support for time as an event source. The most on topic thing about it -- its author implemented a robot controller in Timber, and the robot is a little 4-wheeler called ... "Timbot". Donn Cave, donn at drizzle.com From rkern at ucsd.edu Mon Aug 22 06:27:18 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 22 Aug 2005 03:27:18 -0700 Subject: while c = f.read(1) In-Reply-To: <1124702804.589011.257970@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124702804.589011.257970@o13g2000cwo.googlegroups.com> Message-ID: Greg McIntyre wrote: > The 2nd option has real potential for me. Although the total amount of > code is greater, it factors out some complexity away from the actual > job, so that code is not obscured by unnecessary compexity. IMHO that's > great practice. Please quote the message you are replying to. We have no idea what "the 2nd option" is. -- 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 richie at entrian.com Fri Aug 19 08:08:58 2005 From: richie at entrian.com (Richie Hindle) Date: Fri, 19 Aug 2005 13:08:58 +0100 Subject: Database of non standard library modules... In-Reply-To: References: Message-ID: <8sibg15flv938t6rjlr1mnertlfctajrdl@4ax.com> [Steve] > While cheeseshop might resonate with the Monty Python fans I have to > say I think the name sucks in terms of explaining what to expect. If I > ask someone where I can find a piece of code and the direct me to the > cheese shop, I might look for another language. +1 -- Richie Hindle richie at entrian.com From cyril.bazin at gmail.com Sat Aug 20 10:54:45 2005 From: cyril.bazin at gmail.com (Cyril Bazin) Date: Sat, 20 Aug 2005 16:54:45 +0200 Subject: [newbie]search string in tuples In-Reply-To: References: Message-ID: Try the code below. #------------------------------------------------- list=["airplane","car","boat"] select = None while select not in list: select=raw_input("Which vehicle?") #------------------------------------------------- Cyril On 8/20/05, Viper Jack wrote: > > Hi all, > i'm new to python programming so excuseme if the question is very stupid. > here the problem. > this code work > > list=["airplane"] > select=vars > while select != list[0]: > select=raw_input("Wich vehicle?") > > but i want check on several object inside the tuple so i'm trying this: > > list=["airplane","car","boat"] > select=vars > while select != list[0] or list[1] or list[2]: > select=raw_input("Wich vehicle?") > > but loops and doesn't want work. > I have tried with other methods (for) but nothings. > I haven't find nothing on this topic, so i asked here. > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From grante at visi.com Thu Aug 11 10:20:59 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 11 Aug 2005 14:20:59 -0000 Subject: What is Python?! References: <42fa51db$0$7802$626a14ce@news.free.fr> <42faccb9$1@news.orcon.net.nz> Message-ID: <11fmnmbprgbht42@corp.supernews.com> On 2005-08-11, Dennis Lee Bieber wrote: > On Thu, 11 Aug 2005 15:51:45 +1200, Evil Bastard > declaimed the following in comp.lang.python: > >> To me, the term is archic. What 'scripting language' means to me is: >> 1. insufficient facilities for general purpose or 'serious' programming >> 2. ability to get simple useful programs up and working quickly > [...] > To me, that is "scripting" -- using one program to feed commands > to another. Those applications that supplied a function library allowed > for usage closer to VBA/COM style... import the library, then call > functions directly. To me, a "scripting language" is one intended to "sumulate" a user: a language that is used to run other programs in more-or-less the same manner a normal user would. Something that is intended to be used to automate a sequence of operations that would otherwise be performed by a user typing or clicking in a UI. Bash is a scripting language. Python isn't. When compared with something like bash, in Python it's not particularly easy to run other programs and manipulate the programs' input/output streams. It can be done, but the semantics used to do so are identical to C (which nobody seems to think is a scripting language). Python is a general purposeprogramming language. -- Grant Edwards grante Yow! Hey, I LIKE that at POINT!! visi.com From mhellwig at xs4all.nl Thu Aug 4 06:24:05 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Thu, 04 Aug 2005 12:24:05 +0200 Subject: Secure email In-Reply-To: References: Message-ID: <42f1ecd3$0$11079$e4fe514c@news.xs4all.nl> whisper at oz.net wrote: > I need to write a .cgi that will take the content of an https GET or > POST and send it securely as email to an Outlook client. > > I think that OpenSSL is somewhere in this, but I'm not even sure how to > create the right certificate, how to use it to encrypt mail and how to > install a certificate in Outlook (>= 2000). > > Code snippets and pointers to tutorials greatly appreciated. I've got a > week to deploy this! > I think you want this more common approach for mail encryption: server: https CGI form --> mail wrapper --> PGP encryption/signing --> send client: recieve mail --> pgp decryption/verification --> read All parts are trivial except for pgp but you could get more information at http://www.openpgp.org/ -- mph From callmebill at gmail.com Fri Aug 5 11:10:06 2005 From: callmebill at gmail.com (callmebill at gmail.com) Date: 5 Aug 2005 08:10:06 -0700 Subject: Making a timebomb Message-ID: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> I have a server that right now runs infinitely. I'd like to make it die after some amount of time. I was thinking of having a timebomb thread that starts when the server starts. The timebomb sits, and sleeps for the specified timeout period (e.g., 5 hours), then does something to make the main thread terminate. But I'm too inexperienced to figure out what that thing is. Any suggestions? class TimeBomb( threading.Thread ): def run(self): timeout = 5 * 60 * 60 #-- 3 hours time.sleep( timeout ) MakeTheRestOfTheStuffDie() class MyServer: def __init__(self): TimeBomb().run() serve() From thomasbartkus at comcast.net Wed Aug 17 10:36:10 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Wed, 17 Aug 2005 09:36:10 -0500 Subject: Python as VBA replacement under Windows? References: Message-ID: <7cKdnQ8TVuYj157eRVn-oQ@telcove.net> "Wolfgang Keller" wrote in message news:mn.8a917d5881245f77.30301 at gmx.de... > Hello, > > this is a potentially veeery dumb question, but: > > - If an application supports VBA as a macro language, > - and if you can execute Python code from within a VBA script (how?) > - and if the application exposes its VBA scripting interface through > COM > > then it should be perfectly possible to entirely replace VBA in nearly > all Windows applications with Python, right? > > TIA, > > sincerely, > > Wolfgang Keller "perfectly possible"? Hmmmhh! Because the MS Office suite and a few (very few!) other applications expose their object models via COM, you can manipulate these programs with Python and other languages. No applicatoin "supports VBA as a macro language". Rather - VBA is bundled and integrated with MS Office in order to manipulate COM. You can use Python to do that too! However It is difficult to argue with the built in integrated editor/debugger behind Excel, Word, PowerPoint, et al with the scripts packaged seamlessly inside the application files. It's also difficult to argue with the myriad of built in VBA functions that are custom designed to ease the pain of working with Windows internals. On the other hand I can think of nothing that you can do with VBA but can not do with Python. It just takes a bit more effort and you need to know more of Windows internals in order to pull it off. "perfectly possible"? I'm still thinking :-) -Tom From benji at benjiyork.com Thu Aug 25 10:20:28 2005 From: benji at benjiyork.com (Benji York) Date: Thu, 25 Aug 2005 10:20:28 -0400 Subject: variable hell In-Reply-To: References: <430dc538@127.0.0.1> Message-ID: <430DD3AC.8080108@benjiyork.com> Peter Maas wrote: > >>> suffix = 'var' > >>> vars()['a%s' % suffix] = 45 > >>> avar > 45 Quoting from http://docs.python.org/lib/built-in-funcs.html#l2h-76 about the "vars" built in: The returned dictionary should not be modified: the effects on the corresponding symbol table are undefined. -- Benji York From steve at holdenweb.com Wed Aug 31 22:10:09 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Aug 2005 21:10:09 -0500 Subject: OpenSource documentation problems In-Reply-To: <200508312026.04152.hancock@anansispaceworks.com> References: <43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net> <200508312026.04152.hancock@anansispaceworks.com> Message-ID: <43166301.9060401@holdenweb.com> Terry Hancock wrote: > On Wednesday 31 August 2005 07:05 pm, Michael Sparks wrote: > >>When people complain /in here/ about the documentation not being perfect for >>python I personally find it sad and ironic. It's sad because it says to the >>person who spent their time (when they could be doing something else) that >>they wasted it, the docs are worthless etc - when they clearly *haven't* >>wasted their time and the docs are worthwhile. It's ironic though because >>they're criticising themselves. After all they understand how the docs can >>be better and the docs are shared. Unless they contribute back they're >>actually attacking themselves as much as the person who "wastes" their time >>writing "worthless" docs. > > > There is one criticism however, which I think is valid, which could > be fixed, and which would probably leverage community effort better: > it could probably be a lot easier to contribute to the documentation. > > I haven't attempted it myself, but my understanding is that there > is something of a learning curve to producing documentation using > the docutils. This has the effect of excluding anyone from > contributing who is not willing to overcome that learning curve. > > In order to make that tradeoff worthwhile, the potential contributor > must have a pretty serious objection to the documentation and/or a > fairly large amount of changes that they want to make. Furthermore, > they have to have convinced themselves that it's worthwhile, which > means they have to be acknowledging that they will contribute > significantly in the future. All of which adds up to not many people > taking the trouble to improve the documentation. > Probably it should simply be made better-known that patches to the documentation don't have to be in the correct source form (docutils aren't used, by the way, it's a LaTeX-based system). I've seen statements by both Fred Drake and Skip Montanaro that they would be happy to accept text and put it in the right format. Every page of the docs links to "About this document", which contains the following: """If you are able to provide suggested text, either to replace existing incorrect or unclear material, or additional text to supplement what's already available, we'd appreciate the contribution. There's no need to worry about text markup; our documentation team will gladly take care of that.""" So the learning curve needn't bother the casual contributor, but I suspect that few such potential contributors know about this. > For those who do, of course, the current implementation is fine. > But if the argument is that more community involvement is needed, > then maybe the system needs to be more efficient at capturing > that effort, by lowering the barriers to contribution. > > Perhaps this just reduces to "there ought to be a wiki"? > Well, perhaps the Wiki at http://wiki.python.org/moin/ should also be better-publicized, then? I agree that maintaining documentation is a generic problem of the open source world, but it's a sad fact of life that generally people are better-motivated to complain about documentation (and almost everything else) than to help improve it. Given that often people appear on this list for the first time without having used Google or the docs to try and find an answer to their questions, these complaints are likely to continue indefinitely ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kent37 at tds.net Thu Aug 4 09:47:49 2005 From: kent37 at tds.net (Kent Johnson) Date: Thu, 04 Aug 2005 09:47:49 -0400 Subject: Metaclasses and class variables In-Reply-To: References: Message-ID: <42f21c0f$1_1@newspeer2.tds.net> Christopher Subich wrote: > Jan-Ole Esleben wrote: > >> class Meta(type): >> def __new__(cls, name, bases, d): >> d['classvar'] = [] >> return type.__new__(cls, name, bases, d) > > > The problem is that __new__ is called upon object construction, not > class definition, but you're trying to set the class variables at > definition-time. The metaclass __new__() is called on class creation (the class is the object being constructed) but not until after the body of the class definition is executed; the dictionary passed to __new__() contains the methods and class variables defined by the class statement. See http://www.python.org/2.2/descrintro.html#metaclasses Kent From sp1d3rx at gmail.com Thu Aug 18 11:42:34 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 18 Aug 2005 08:42:34 -0700 Subject: pickle.load not working? In-Reply-To: References: <1123884180.348659.247960@z14g2000cwz.googlegroups.com> Message-ID: <1124379754.569717.25810@f14g2000cwb.googlegroups.com> oh, well how do I make "derek" be an instance of 'chatuser' ? From franz.steinhaeusler at gmx.at Mon Aug 8 05:17:39 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Mon, 08 Aug 2005 11:17:39 +0200 Subject: How to use DrPython plugins References: <1123340639.474121.17060@g14g2000cwa.googlegroups.com> Message-ID: On 6 Aug 2005 08:03:59 -0700, "RunLevelZero" wrote: >Well I think you should post in this forum and you will get your answer >more quickly. > >http://sourceforge.net/forum/?group_id=83074 > Hi RunLevelZero, I have changed the Codemarks meanwhile. For testing, one could edit: plugins\default.idx and add manually the plugins: for example plugins\default.idx: CodeCompletion -- Franz Steinhaeusler From spam.csubich+block at block.subich.spam.com Tue Aug 9 10:30:13 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 10:30:13 -0400 Subject: don't understand instanse creation In-Reply-To: References: Message-ID: Maksim Kasimov wrote: > > Hello, > > i have a class, such as below. > when i try to make instances of the class, > fields __data1 and __data2 gets different values: __data1 behaves like private field, __data2 - like static > which is the thing i've missed? Firstly, you get interesting behaviour of data1 and data2 because they're defined as mutable objects in the class sitself. All instances of that class then share the same binding to the list, so appending to it in one instance will show up in other instances. (Incidentally, be sure what you really want is name-mangled private variables, it's fairly uncommon for instance variables and methods to be private in Python code). Your second issue is why data1 behaves differently. This line: > self.__data1 = self.__data2[:] is the culprit. Here, you assing __data1 to a *new* list, generated by copying __data2 (the : slice -- slices create a shallow copy, not a reference, of lists). This rebinds the name __data1 to a new object, so the __data1 in the class definition is never modified like __data2 (with the .append). You can demonstrate this by looking at the 'address' of the lists. Modify the constructor thusly: class my: __data1 = [] __data2 = [] def __init__(self): print "__data1: ", self.__data1, object.__repr__(self.__data1) print "__data2: ", self.__data2, object.__repr__(self.__data1) for i in time.localtime(): self.__data2.append(i) self.__data1 = self.__data2[:] print "__data1: ", self.__data1, object.__repr__(self.__data1) print "__data2: ", self.__data2, object.__repr__(self.__data1) And your tests now become: >>> m1 = my() __data1: [] __data2: [] __data1: [2005, 8, 9, 10, 5, 54, 1, 221, 1] __data2: [2005, 8, 9, 10, 5, 54, 1, 221, 1] >>> m2 = my() __data1: [] __data2: [2005, 8, 9, 10, 5, 54, 1, 221, 1] __data1: [2005, 8, 9, 10, 5, 54, 1, 221, 1, 2005, 8, 9, 10, 5, 56, 1, 221, 1] __data2: [2005, 8, 9, 10, 5, 54, 1, 221, 1, 2005, 8, 9, 10, 5, 56, 1, 221, 1] Notice how the 'address' of __data1 changes after executing the constructor. This change, made in __init__, is reflected only in that instance's copy of the name. Also notice how __data2 in both m1 and m2 share the same address; this is why changes in one instance are reflected in the others. From yoav_artzi at il.vio.com Thu Aug 25 09:26:38 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Thu, 25 Aug 2005 16:26:38 +0300 Subject: RE Despair - help required In-Reply-To: References: <430d8883@news.bezeqint.net> Message-ID: <430dc5e3$1@news.bezeqint.net> Thanks guys. Issue solved. I am also going to give Microsoft a call about it. Any other issues you want me to raise while I am talking to them? Cheers. Robert Kern wrote: > Yoav wrote: > >>I am trying the following: >> >>re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") >> >>and I get a return of NoneType, and I have no idea why. I know that I >>missing something here, but I really can't figure out why (I bet it's >>something obvious). I also tried this RE on KODOS and it works fine >>there, so I am really puzzled. >> >>Any ideas? > > > Look at the second string. It has "\r" in the middle of it where you > really want "\\r" (or alternatively r"c:\ret_files"). > From uval at rz.uni-karlsruhe.de Fri Aug 5 09:42:41 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-15?Q?Daniel_Sch=FCle?=) Date: Fri, 05 Aug 2005 15:42:41 +0200 Subject: why no arg, abs methods for comlex type? Message-ID: Hello all, I often have to deal with complex numbers using python iteractive as calculator I wonder why there are no methods like arg, abs well one can use c = 1+1j abs(c) In my opinion it would also be nice to have the possibility to write it as c.abs() it looks more OO unfortunately there is no arg method to get the angle of the complex number of course it easy to write one on your own (that's what I have done for myself) but differnt people will create and reinvite the wheel over and over again while reading alien code one will have to spend 2 seconds remembering the function names etc consider c = 1+1j c.arg(angle_mode = cmath.GRAD) -> 45.0 or c.arg(angle_mode = cmath.RAD) -> 0.7853.. I would also like to see some more functions to make calculations with complex number more convenient e.g. c = 27 c.pow(numerator = 1, denominator = 3, mode = cmath.EULER, angle_mode = cmath.GRAD) -> ((3,0), (3,120), (3,240)) what do you think about it? maybe there exists some proposals aiming this goal? -- Daniel From rafi at free.fr Tue Aug 23 17:49:32 2005 From: rafi at free.fr (rafi) Date: Tue, 23 Aug 2005 23:49:32 +0200 Subject: Reading just a few lines from a text file In-Reply-To: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> References: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> Message-ID: <430b99e2$0$27523$636a15ce@news.free.fr> tkpmep at hotmail.com wrote: > I have a text file with many hundreds of lines of data. The data of > interest to me, however, resides at the bottom of the file, in the last > 20 lines. Right now, I read the entire file and discard the stuff I > don't need. I'd like to speed up my program by reading only the last 20 > lines. How do I do this? > > Thomas Philips > If you are using a Unix: tail -20 file.txt -- rafi "Imagination is more important than knowledge." (Albert Einstein) From yoav_artzi at il.vio.com Thu Aug 25 10:03:56 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Thu, 25 Aug 2005 17:03:56 +0300 Subject: RE Despair - help required In-Reply-To: References: <430d8883@news.bezeqint.net> Message-ID: <430dcea0$1@news.bezeqint.net> Don't think it will do much good. I need to get them from a file and extract the last folder in the path. For example: if I get "c:\dos\util" I want to extract the string "\util" Fredrik Lundh wrote: > "Yoav" wrote: > >>I am trying the following: >> >>re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") >> >>and I get a return of NoneType, and I have no idea why. I know that I >>missing something here, but I really can't figure out why > > > instead of struggling with weird REs, why not use Python's standard > filename manipulation library instead? > > http://docs.python.org/lib/module-os.path.html > > > > > From jonhewer at gmail.com Fri Aug 19 04:49:34 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Fri, 19 Aug 2005 09:49:34 +0100 Subject: Database of non standard library modules... Message-ID: Is there an online database of non standard library modules for Python? Quite often people who email this list are after a module to do a certain task. If it doesn't exist I think that an online database, to which people could add details of modules, and which people could search, would be an extremely valuable resource. Just wondering if anyone could tell me if something like this exists (probably does), and if not, I'll get to work :) Cheers Jon From reinhold-birkenfeld-nospam at wolke7.net Sat Aug 6 15:33:17 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sat, 06 Aug 2005 21:33:17 +0200 Subject: Decline and fall of scripting languages ? In-Reply-To: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> Message-ID: <3lkhjuF1306nuU1@individual.net> Kay Schluehr wrote: > No good news for scripting-language fans: > > http://www.phpmag.net/itr/news/psecom,id,23284,nodeid,113.html The study was conducted by Evans Data Corporation. Look here: http://www.evansdata.com/n2/about_us_clients.shtml Do you see the PSF or Larry Wall on the list? Reinhold From claudio.grondi at freenet.de Fri Aug 26 18:14:25 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Fri, 26 Aug 2005 22:14:25 -0000 Subject: Why does min(A, B) not raise an error if A, B actually can't be compared? References: <3n95grFfp1fU2@individual.net> <1125084040.571865.154920@o13g2000cwo.googlegroups.com> Message-ID: <3n9bigFgm5aU1@individual.net> Thanks to Raymond for his reply. If I understand him right, there is no problem with min() as such, but with the definition of the class, which when used in min() should define at least __cmp__(). I have attached code with another class PythonObject_classWithDefined__cmp__: where the behaviour of min() is like I would expect it. Using classes without defined __cmp__ in comparison operations violates the directive: "Explicit is better than implicit" and is just to be considered bad programming style or to name it more directly, just a way of obfuscating code, right? The still open question for me then is: Why does min() not raise an error in case there is no comparison function definition for the feeded objects available? Claudio ATTACHMENT: class PythonObject_classWithDefined__cmp__: def __init__(self, value = 1): self.value = value #:def def __cmp__(self, otherInstance): if ( self.value < otherInstance.value ): return -1 elif(self.value == otherInstance.value ): return 0 else: return 1 #:if/else #:def #:class PythonObject_classWithDefined__cmp__instanceA = PythonObject_classWithDefined__cmp__() PythonObject_classWithDefined__cmp__instanceB = PythonObject_classWithDefined__cmp__() print "min(A,B) is A: " print "in case of classes with defined __cmp__() as parameter: " + str(min(PythonObject_classWithDefined__cmp__instanceA, PythonObject_classWithDefined__cmp__instanceB) is PythonObject_classWithDefined__cmp__instanceA) print "min(B,A) is A: " print "in case of classes with defined __cmp__() as parameter: " + str(min(PythonObject_classWithDefined__cmp__instanceB, PythonObject_classWithDefined__cmp__instanceA) is PythonObject_classWithDefined__cmp__instanceA) outputs: min(A,B) is A: in case of classes with defined __cmp__() as parameter: True min(B,A) is A: in case of classes with defined __cmp__() as parameter: False "Raymond Hettinger" schrieb im Newsbeitrag news:1125084040.571865.154920 at o13g2000cwo.googlegroups.com... > Claudio Grondi wrote: > > Is there any deeper reason I don't understand > > explaining why does min(A,B) behave different > > for classes than for lists? > > Yes, the sort order for lists is determined by their contents. With > your example, the lists have identical contents, so min() returns the > first minimum value encountered which is A for min(A,B) and B for > min(B,A). > > For instances, the sort order is determined by custom __cmp__ or rich > comparision methods. In the absence of those, the default ordering is > determined by the object's id. In your example, the default is used > and either object may be returned as the minimum depending on which > object id is a higher number (that is an implementation and state > dependent). Since the two objects have unique ids, min() will > consistently find one to be lower than the other irrespective of > argument order, if min(A,B) is A, then min(B,A) will also be A. > > The best way to develop your understanding here is view the object ids > for the instances and experiment with the results of A etc. > > Then write a simple, pure python version of min() that returns the > first occurence of the lowest valued element. Trace through its > execution and all will become clear. > > > Raymond > From aisaac0 at verizon.net Tue Aug 9 22:05:00 2005 From: aisaac0 at verizon.net (David Isaac) Date: Wed, 10 Aug 2005 02:05:00 GMT Subject: MultiFile object does not iterate Message-ID: Why is a MultiFile object not an iterator? For example if mfp = multifile.MultiFile(fp)I cannot dofor line in mfp: do_somethingRelated:MultiFile.next seems badly named.(Something like next_section would be better.)Is this just historical accident or am I missing the point?Thanks,Alan Isaac From rfmeraz at gmail.com Thu Aug 18 13:47:25 2005 From: rfmeraz at gmail.com (rfmeraz at gmail.com) Date: 18 Aug 2005 10:47:25 -0700 Subject: up to date books? In-Reply-To: References: Message-ID: <1124387245.217235.171530@g49g2000cwa.googlegroups.com> I would suggest Alex Martelli's "Python in a Nutshell" or the "Python Cookbook" as the best Python books from Oreilly. I also like M. Pilgrim's "Dive into Python". From jeff.maitland at gmail.com Wed Aug 31 16:30:02 2005 From: jeff.maitland at gmail.com (Jeffrey Maitland) Date: Wed, 31 Aug 2005 16:30:02 -0400 Subject: Arguement error Message-ID: <6829832e050831133030a012f9@mail.gmail.com> Hello folks, I am wondering why I am getting this error. when I try to run a script. TypeError: translate() takes at most 3 arguments (10 given) but the thing is the method translate actually accepts 10 arguements. That is what is confusing me. Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From reinhold-birkenfeld-nospam at wolke7.net Sun Aug 28 15:24:50 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sun, 28 Aug 2005 21:24:50 +0200 Subject: What are new-style classes? In-Reply-To: References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> Message-ID: <3nehc2F15ainU1@individual.net> Terry Hancock wrote: > On Sunday 28 August 2005 04:47 am, Vaibhav wrote: >> I recently heard about 'new-style classes'. I am very sorry if this >> sounds like a newbie question, but what are they? I checked the Python >> Manual but did not find anything conclusive. Could someone please >> enlighten me? Thanks! > > "New style" classes are becoming the standard in Python, and must > always be declared as a subclass of a new style class, including built-in > classes. [Warning, advanced stuff ahead!] That's not entirely true. New-style classes need not be derived from a new- style class, they need to use the metaclass "type" or a derived. So you can also declare a new-style class as class new_class: __metaclass__ = type Or, if you want to switch a whole module with many classes to new-style, just set a __metaclass__ = type globally. Reinhold From tjreedy at udel.edu Sun Aug 7 22:24:51 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 7 Aug 2005 22:24:51 -0400 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com><7xmznuxh61.fsf@ruckus.brouhaha.com><87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xoe8a6q24.fsf at ruckus.brouhaha.com... bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: >Actually that proliferation is one of the culprits in Python being a >pain to deal with. I'm personally not a GUI fetishist and Tkinter has >been good enough for the client-side GUI's I've needed to write (I'm >more web-oriented most of the time). But the reason for that >proliferation is other people are dissatisfied with Tkinter. Do you have any data to support that? Seriously. Consider Hypothesis 1: someone learned Python and Tkinter, felt dissatisfied with Tkinter, went searching the universe for an alternative, found GTK, and wrote PyGTK, perhaps learning C in the process. Hypothesis 2: a C-programmer who is a satisfied user of GTK (on *nix, presumably) learns Python. "Neat, but I also want to keep using GTK." Which he can because it is relatively easy. Repeat H1 and H2 for every wrapping. You believe in H1. I suspect H2 is more often true, but admit I have no data. > That by itself says the stdlib is lacking. I have an alternate interpretation. There is a Python wrapping for as many C libraries as there are because Python is neat and wrapping is fairly easy and the rewards great. When I learned Python several years ago, being able to interactively drive and easily script foreign libraries was touted as one of its killer applications. Numerical Python, wrapping BLAS, LINPACK, and FTPPACK was a prime example. So in a sense, you are criticizing Python for being successful at what I believe was one of its design goals. But go ahead. Lots of choices can be a nuisance. Just check out the supermarkets. (But so is too few choices ;-) Terry J. Reedy From noreply at gcgroup.net Mon Aug 29 19:20:09 2005 From: noreply at gcgroup.net (William Gill) Date: Mon, 29 Aug 2005 23:20:09 GMT Subject: a list of Checkbuttons Message-ID: OK I'm tired, I've got a cold, and my brain isn't working very well. I have a result set ( a tuple of tuples) from a db. Each element has two elements; classification number, and classification heading. i.e. result=((001,'heading one'),(002,'heading two'),...) classification numbers may not be in numerical order, and may skip numbers, so they are not good as an index. I want to create tkinter Checkbuttons that allow me to select which apply to the record I'm editing. What comes to my sub-par mind is to create a list and assign Checkbuttons to each element. something like: classifications = [] for count, classification in enumerate(result): classifications.append( (IntVar(),classification[0]) ) Checkbutton(master, text=str(classification[0])+': '+classification[1] , variable=classifications[-1]).grid(row=count) then to collect which boxes are checked: for check in classifications: if check[0].get() == 1: print 'classification number %s selected" % check[1][0] Is this the smartest way to do this? It should work, but will I be able to understand this 6 months from now? Thanks, Bill From steve at holdenweb.com Fri Aug 26 22:13:30 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Aug 2005 22:13:30 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: Bryan Olson wrote: > Steve Holden wrote: > > Bryan Olson wrote: > >> Antoon Pardon wrote: > > >> > It probably is too late now, but I always felt, find should > >> > have returned None when the substring isn't found. > >> > >> None is certainly a reasonable candidate. > [...] > >> The really broken part is that unsuccessful searches return a > >> legal index. > >> > > We might agree, before further discussion, that this isn't the most > > elegant part of Python's design, and it's down to history that this tiny > > little wart remains. > > I don't think my proposal breaks historic Python code, and I > don't think it has the same kind of unfortunate subtle > consequences as the current indexing scheme. You may think the > wart is tiny, but the duct-tape* is available so let's cure it. > > [*] http://www.google.com/search?as_q=warts+%22duct+tape%22 > > > >> My suggestion doesn't change what find() returns, and doesn't > >> break code. Negative one is a reasonable choice to represent an > >> unsuccessful search -- provided it is not a legal index. Instead > >> of changing what find() returns, we should heal the > >> special-case-when-index-is-negative-in-a-certain-range wart. > >> > >> > > What I don't understand is why you want it to return something that > > isn't a legal index. > > In this case, so that errors are caught as close to their > occurrence as possible. I see no good reason for the following > to happily print 'y'. > > s = 'buggy' > print s[s.find('w')] > > > Before using the result you always have to perform > > a test to discriminate between the found and not found cases. So I don't > > really see why this wart has put such a bug up your ass. > > The bug that got me was what a slice object reports as the > 'stop' bound when the step is negative and the slice includes > index 0. Took me hours to figure out why my code was failing. > > The double-meaning of -1, as both an exclusive stopping bound > and an alias for the highest valid index, is just plain whacked. > Unfortunately, as negative indexes are currently handled, there > is no it-just-works value that slice could return. > > If you want an exception from your code when 'w' isn't in the string you should consider using index() rather than find. Otherwise, whatever find() returns you will have to have an "if" in there to handle the not-found case. This just sounds like whining to me. If you want to catch errors, use a function that will raise an exception rather than relying on the invalidity of the result. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From apardon at forel.vub.ac.be Mon Aug 22 04:41:13 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 22 Aug 2005 08:41:13 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-19, Donn Cave schreef : > In article , > Antoon Pardon wrote: > ... >> But '', {}, [] and () are not nothing. They are empty containers. > > Oh come on, "empty" is all about nothing. No it is not. There are situation where False or None should be treated differently from an empty sequence. Empty can mean, "nothing yet" which should be treated differently from "nothomg more". >> And 0 is not nothing either it is a number. Suppose I have >> a variable that is either None if I'm not registered and a >> registration number if I am. In this case 0 should be treated >> as any other number. >> >> Such possibilities, make me shy away from just using 'nothing' >> as false and writing out my conditionals more explicitly. > > Sure, if your function's type is "None | int", then certainly > you must explicitly check for None. The fact is that python doesn't know which type a function is. So why does python guess that zero should be treated as false. > That is not the case with > fileobject read(), nor with many functions in Python that > reasonably and ideally return a value of a type that may > meaningfully test false. In this case, comparison (==) with > the false value ('') is silly. No is is not. The comparison with the specific false value makes it easier for the reader of the code to find out what to expect. I also find the use of '' as false in this context wrong. A read can be used on all kind of objects including a network connection. Returning '' on a network read would be IMO the most natural answer to say, the network connection is still open but no data is available for the moment. '' here would mean "nothing yet" while '' is now made into "nothing more" -- Antoon Pardon From fredrik at pythonware.com Tue Aug 30 17:43:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Aug 2005 23:43:07 +0200 Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk><4314c264.178329924@news.oz.net> <4314cf38$0$18648$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > time.time() seems to report (using %e to format the o/p) a fixed number of > the order ~1e9. you're confused. time.time() reports the wall time in fractional seconds since the epoch (usually jan 1, 1970). if you take the difference between two calls, you'll find that the resolution on a linux box is well over 100 kHz. From klaus.roedel at vipco.de Tue Aug 30 04:48:55 2005 From: klaus.roedel at vipco.de (klaus.roedel at vipco.de) Date: 30 Aug 2005 01:48:55 -0700 Subject: wxnotebook and tooltips Message-ID: <1125391735.125714.316340@g49g2000cwa.googlegroups.com> Hi, I've implemented a wxnotebook on my application. I can set a tooltip for the complete notebook, but I want to set for every page a tooltip, so that the user can get additionally information over it before he change it. Is this possible with python and wxwidgets? Thanks for any help. Greets Klaus From steve.horsley at gmail.com Mon Aug 29 07:19:37 2005 From: steve.horsley at gmail.com (Steve Horsley) Date: Mon, 29 Aug 2005 12:19:37 +0100 Subject: SocketServer and a Java applet listener In-Reply-To: <1125296874.552905.313490@g43g2000cwa.googlegroups.com> References: <1124913592.821488.204350@g47g2000cwa.googlegroups.com> <1125296874.552905.313490@g43g2000cwa.googlegroups.com> Message-ID: google at phaedro.com wrote: > Steve Horsley schreef: > > >>Probably the same problem. If you didn't send a 2 byte length >>indicator first, then java's readUTF() will have tried to >>interpret the first 2 bytes that you did actually send as the >>string length, and may well simply be waiting patiently for the >>rest to arrive. >> > > I just couldn't get read/writeUTF and python unicode to interface, so I > refactored the applet's socketlistener to convert the > socket.getInputStream to a BufferedInputReader on which I call the > readline() method. > I still skip the first two bytes in the python receiver which seems > harmless since python doesn't use the byte length. > On both sides I have other way to know when the end-of-message has been > reached. A timeout mechanism provides some safety for partial > transmission handling. > I would encourage you to re-think this. There are two normal ways to delineate messages in the byte-stream: An explicit length indication up front (which java read/writeUTF chooses), or a unique end-of-message indication at the end such as your readline() for strings that end in linefeed. HTTP is an interesting mixture of these - the header contains a content-length line telling you how long the payload is, but the header itslef is variable length, terminated by a blank line. In chunked encoding, there is a variable number of chunks, and the last chunk is marked as such in the header. Anyway, either approach is good. But using timing to separate messages is Bad. There is always the chance that you will get bitten by strange timings happening later on. If you choose to go for the java read/writeUTF approach, the 2-byte length indicator goes Most Significant Byte first, so a 100 char string would be preceded by 00 64 ... Also, the indicator gives the number of bytes after encoding, not the number of characters before encoding. Steve From pcaro8a at yahoo.com Thu Aug 18 10:35:39 2005 From: pcaro8a at yahoo.com (pcaro8a) Date: Thu, 18 Aug 2005 14:35:39 -0000 Subject: New to python Message-ID: Hi, I am new to python I am trying to install the numeric library and I get the following error: error: Python was built with version 6 of Visual Studio, and extensions need to be built with the same version of the compiler, but it isn't installed. Do I need Visual Studio to make this work or is there any other reason for this message? Thanks, I appreciate you help. Paola From norm at normgoertzen.com Wed Aug 31 21:03:38 2005 From: norm at normgoertzen.com (Norm Goertzen) Date: Thu, 01 Sep 2005 01:03:38 GMT Subject: Considering moving from PowerBuilder to Python Message-ID: I've posted a previous question about IDEs and got some good feedback, thanks, but it does seem that everyone has their own favourite IDE -- in other words, no IDE was repeatedly recommended. So, is there any data on the popularity of IDEs (most users), or is there a chart comparing the most popular versions. I'M NOT AFRAID TO SPEND SOME MONEY TO GET THE RIGHT IDE (but I don't want to change products once I've chosen). Also, can I use Sybase's SQL Anywhere with Python? I'm really only interested in programming for Windows XP. But I also really would like to find something very close to Sybase's patented datawindow technology -- it's a real time-saver. Finally, is there any (realistic) way to mix PowerBuilder and Python? For instance write a Python shell that calls PowerBuilder methods (or vice versa). Thanks again, Norm From peter at somewhere.com Wed Aug 17 14:34:00 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 17 Aug 2005 20:34:00 +0200 Subject: Obfuscator for Python Code In-Reply-To: References: <1124298063.074422.252770@g14g2000cwa.googlegroups.com> Message-ID: Peter Maas schrieb: > codecraig schrieb: > >> Is there any obfuscator out there that obfuscates the python code (byte >> code i guess)??? > > http://www.lysator.liu.se/~ast rand/projects/pyobfuscate/ Delete space: http://www.lysator.liu.se/~astrand/projects/pyobfuscate/ -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From brian at sweetapp.com Thu Aug 11 12:08:00 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 11 Aug 2005 18:08:00 +0200 Subject: Writing a small battleship game server in Python In-Reply-To: <200508111746.15668.mail@tuxipuxi.org> References: <200508111746.15668.mail@tuxipuxi.org> Message-ID: <42FB77E0.7000401@sweetapp.com> Michael Goettsche wrote: > What would be a good, but still easy way to write such a server? You could use SimpleXMLRPCServer. A client call sequence could like this: >>> s = xmlrpclib.Server('http://...') >>> token = s.join_game() # blocks until another player joins >>> s.send_board( ... ['...pppa...', ... '......a...', ... '.d....a...', ... '.d....a.ss', ... '.d....a...']) >>> s.get_other_board(token) # blocks until other player sends board ['...........', '...........', '...........', '...........', '...........'] >>> s.fire(2,2) 'Hit!' >>> s.get_other_board(token) ['...........', '.H.........', '...........', '...........', '...........'] >>> s.get_my_board(token) # blocks until other guy shoots ['...pppa...', '......a...', '.d....a...', '.d....A.ss', # uppercase if hit '.d....a...']) Just designed in 2 minutes - but you get the idea. Cheers, Brian From bokr at oz.net Mon Aug 8 13:25:22 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 08 Aug 2005 17:25:22 GMT Subject: PEP: Specialization Syntax References: <42f695f8.864310192@news.oz.net> Message-ID: <42f79137.928629067@news.oz.net> On Sun, 07 Aug 2005 21:41:33 -0400, Nicolas Fleury wrote: >Bengt Richter wrote: [...] >> But here the problem is not in the __getitem__ method: >> >> >>> c.__getitem__(kw='key word arg') >> (<__main__.C object at 0x02EF498C>, (), {'kw': 'key word arg'}) >> >> It's just that square bracket expression trailer syntax does not >> allow the same arg list syntax as parenthesis calling trailer syntax. > >I totally agree and that's what I mean. The formulation of the PEP is >wrong, I should almost not talk about __getitem__ since as you said it >can have any signature. The PEP is about extending [] syntax to call >automtically __getitem__ function with more complex signatures. > >>> Should other operators that square brackets be used for >>> specialization? >> >> Didn't quite parse that ;-) You mean list comprehensions? Or ?? > >I mean should angle brackets <> like in C++, or another operator, be >used instead? I am getting the feeling that your PEP is about a means to do something C++-like in python, not necessarily to enhance python ;-) IOW, it seems like you want the [] to do something like C++ in templates? (BTW, I have nothing against giving python new capabilities (quite the reverse), but not by grafting limbs from other animals ;-) Maybe you want hidden name-mangling of function defs according to arg types and corresponding dispatching of calls? I am afraid I am still not clear on the fundamental motivation for all this ;-) > >Regards and thx for your feedback, You're welcome. Regards, Bengt Richter From steve at REMOVETHIScyber.com.au Mon Aug 1 12:47:39 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 02 Aug 2005 02:47:39 +1000 Subject: need for speed References: <1122888516.815400.116220@f14g2000cwb.googlegroups.com> Message-ID: On Mon, 01 Aug 2005 02:28:36 -0700, borges2003xx at yahoo.it wrote: > hi everyone > can someone suggest me where find a lot programming tricks for > achieving the top speed in python? There is only one programming trick you need to know about making code run fast. Never even waste one second on optimising code before it is working, or before you have tested it and profiled it and know (1) that it IS slow; and (2) WHERE it is slow. Why would you waste your valuable time making bugs run faster? Why waste time and effort to speed up something that is already fast enough? In other words: Make your code work. Make it work right. Then, and only then, make it run fast -- and only if it isn't already fast. Now that you have written your code, and you have made it work right, please tell us what the code is, and the results of profiling the code, and we will help you speed it up. -- Steven From peter at engcorp.com Tue Aug 30 21:55:26 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 30 Aug 2005 21:55:26 -0400 Subject: Uploading images via cgi? In-Reply-To: References: Message-ID: Chris Dewin wrote: > How do I go about writing a cgi script, that will enable the client to > upload things to a directory on my website? > > I would also like to write a script that enables the client to delete > items in that directory if they want. Given that it's unix server, how do > I go about ensuring the files are written to that dir with the right > permissions? What did you learn when you tried a few of the more obvious searches with Google (including the word "python" in the search)? You must have learned _something_ but still have questions, so please tell us what you already know so we can skip over the easy stuff. Knowing what you've already discovered will avoid having everyone here repeat all the same answers (which you can easily find in the Google Groups archives) to what is a fairly common sort of question. -Peter From ed at leafe.com Tue Aug 9 09:25:29 2005 From: ed at leafe.com (Ed Leafe) Date: Tue, 9 Aug 2005 09:25:29 -0400 Subject: [ANN] Dabo 0.4 Released Message-ID: <200508090925.29121.ed@leafe.com> We are pleased to announce Dabo 0.4, the fourth major release of our data application framework. The Dabo framework is a true 3-tier design, with data access and UI code separated from your business logic. And since it's Python, and uses wxPython for its UI, it is completely cross-platform, having been tested on Linux, Windows and OS X. Download from http://dabodev.com/download This is the first major release of Dabo that doesn't involve major changes to the way things work; nearly all the changes were bugfixes and 'under-the-hood' tightening up of the code. I suppose that this is a good sign, and indicates that we have progressed further than a '0.4' version indicates, but we are being deliberately conservative with our version numbering. Nearly all the changes involve the UI layer, demonstrating both the complexity of wrapping a UI toolkit as well as the maturity and stability of our business object and database layers. Anyone interested in contributing to Dabo, or who just want to find out what it is all about is encouraged to join our mailing lists: dabo-users: for those interested in learning how to work with Dabo to create applications, and for general help with Dabo. http://leafe.com/mailman/listinfo/dabo-users dabo-dev: for those interested in the ongoing development of Dabo. This list contains lots of lively discussion on design issues, as well as notices of all commits to the code repository. http://leafe.com/mailman/listinfo/dabo-dev Here is a brief summary of what's new in Dabo 0.4: The dGrid class has been re-written. It allows you to directly work with Column and Header objects, where setting properties of these objects changes the appearance and behavior of the grid. It also has several convenience methods, such as 'buildFromDataSet()', which allows you to pass it a set of data, and have the grid construct itself to properly display that data. Added the property 'HeaderBackgroundColor' to the Column class to control the background color of that column's header. Added the ability to edit values in a grid, which is toggled by a single boolean property of the grid named 'Editable'. Created basic renderer and editor classes for various data types that allow you to control how values are displayed and edited, respectively. Created several visual variations of the 'pageframe' object (called a 'Notebook' in wxPython). The standard 'dPageFrame' uses tabs to select the various pages, but now there are also 'dPageList', which uses a listbox to select its pages, and 'dPageSelect', which uses a dropdown list. There is also a new class 'dPageNoTabs', which, as its name suggests, has no visible means of changing pages. This class is used for those situations where you only want to change pages programmatically (e.g., a wizard form). Updated the DataNav framework to take advantage of these pageframe changes. The Form class has two new attributes: 'pageFrameStyle', which is one of 'Tabs', 'List' or 'Select'; and 'tabPosition', which is one of 'Top', 'Bottom', 'Left' or 'Right'. Simplified many of the functions that previously required creating instances of the various dialog types, showing them, and then later destroying them. Now, instead of going through all that, simply make a call such as 'dabo.ui.getColor("green")', and Dabo will display a Color Selection dialog, default to the color you specified, and then return the color the user selected, or None if they canceled. The new functions (all part of dabo.ui) are: getFont(), getColor(), getString(), getFile(), getSaveAs() and getFolder(). Also moved the common informational dialogs here: areYourSure(), info() and stop(). Added the 'fontMetric()' method to the UI module. Specify a string, as well as the font properties you want to use to display that string, and it returns a (width, height) tuple for that string in that font. Added two properties to all controls that allow you to programmatically interact with the sizers that determine how that control appears: ControllingSizer and ControllingSizerItem. Added support for the Decimal class that was added in Python 2.4. Code written to run in Python 2.3 will still work, though. Created the dToolBar class for displaying toolbars associated with forms. We're still working on creating independent floating toolbars. And, of course, lots of bug fixes and code tweaks! The Dabo Demo project is largely unchanged, although the demos have been updated to take advantage of changes to the underlying framework. There are now three basic demos in the 'tutorial' directory that help to demonstrate the basics of creating applications in Dabo. The Dabo IDE project has also been updated to version 0.2, and I feel that this version number is accurate. We're still exploring the best way to create Dabo classes visually, and have made some great progress, but this is still very much an unfinished product. The Class Designer has progressed to the point where you can lay out a form using a sizer-centric approach, modify the properties of controls and their sizers from a simple property sheet, save your design to a file, and then later re-edit that design from that file. And the nascent Report Designer is also progressing, but like all early efforts, is still subject to major API changes. -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From gene.tani at gmail.com Mon Aug 1 20:39:00 2005 From: gene.tani at gmail.com (gene tani) Date: 1 Aug 2005 17:39:00 -0700 Subject: namespaces In-Reply-To: References: <42EC9690.2040301@tiscali.it> <7x3bpvxlsr.fsf@ruckus.brouhaha.com> Message-ID: <1122943140.666650.89370@o13g2000cwo.googlegroups.com> re-read page 74 of the nutshell about "." and __dict__. this bit about philosophical differences in dictionary lookups vs. sending a message to an object might help http://onestepback.org/index.cgi/Tech/Ruby/PythonAndRuby.rdoc From gandalf at geochemsource.com Mon Aug 15 08:39:41 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Mon, 15 Aug 2005 14:39:41 +0200 Subject: Windows 32 service problem (ImportError) Message-ID: <43008D0D.4000509@geochemsource.com> Hi All! I have a running service (a small web server) implemented in python, running as a win32 service. I wrote another program that is very similar to the web server but I cannot start the service. From the event log, I can read this traceback: ------------- Python could not import the service's module File "T:\Python\Projects\NamedConnector\Service.py", line 17, in ? from Processor import * File "c:\Python\Projects\NamedConnector\Processor.py", line 35, in ? from mess import MessageSocket File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ? import zlib exceptions.ImportError: dynamic module does not define init function (initzlib) ------------- Facts: 1. I'm using the same module (MessageSocket) for my web server 2. The web server runs fine as a service Where is the problem? Please help. Les From robin at SPAMREMOVEjessikat.fsnet.co.uk Mon Aug 29 14:51:54 2005 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Mon, 29 Aug 2005 18:51:54 +0000 Subject: Cygwin font problems In-Reply-To: References: Message-ID: <4313594A.2060700@jessikat.fsnet.co.uk> Steve Holden wrote: > Is anyone aware of (a fix for) problems I'm having getting PIL 1.1.5 to > create bitmaps using TrueType and openType fonts? When I create an image > using the standard PIL fonts everything seems fine, but when I use > ImageFont.truetype(, ) no text is drawn. > > setup.py reports from debug print statements that it's finding freetype21. > > The same code using (Fredrik's pre-built binary) on Windows runs > correctly and produces correct images. > > Cygwin runs Python 2.4.1, Windows runs 2.4. Any light on this mystery > gratefully received. > > regards > Steve Could PIL have been compiled without freetype support perhaps? -- Robin Becker From benji at benjiyork.com Wed Aug 3 09:10:39 2005 From: benji at benjiyork.com (Benji York) Date: Wed, 03 Aug 2005 09:10:39 -0400 Subject: trying to parse non valid html documents with HTMLParser In-Reply-To: <42f09837$0$4042$636a15ce@news.free.fr> References: <42efc9ae$0$12924$636a15ce@news.free.fr> <42f09837$0$4042$636a15ce@news.free.fr> Message-ID: <42F0C24F.7060507@benjiyork.com> florent wrote: > True, I just want to extract some data from html documents. But the > problem is the same. The parser looses the position he was in the string > when he encounters a bad tag. Are you saying that Beautiful Soup can't parse the HTML? If so, I'm sure the author would like an example so he can "fix" it. -- Benji York From jcarlson at uci.edu Sun Aug 14 17:38:02 2005 From: jcarlson at uci.edu (Josiah Carlson) Date: Sun, 14 Aug 2005 14:38:02 -0700 Subject: Python and games Message-ID: <20050814143213.7841.JCARLSON@uci.edu> Perhaps some of you would get a kick out of this. - Josiah Like XML, scripting was extremely useful as both a mod tool and an internal development tool. If you don't have any need to expose code and algorithms in a simple and safe way to others, you can argue that providing a scripting language is not worth the effort. However, if you do have that need, as we did, scripting is a no brainer, and it makes complete sense to use a powerful, documented, cross-platform standard such as Python. Python, like many good technologies, soon spreads virally throughout your development team and finds its way into all sorts of applications and tools. In other words, Python begins to feel like a big hammer and coding tasks look like nails. - Mustafa Thamer, Firaxis Games (talking about Civilization IV) Page 18, August 2005 Game Developer magazine From the.g.man.x at gmail.com Sun Aug 7 17:15:54 2005 From: the.g.man.x at gmail.com (Erik the Red) Date: 7 Aug 2005 14:15:54 -0700 Subject: Euclid's Algorithm in Python? In-Reply-To: References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> Message-ID: <1123449353.962000.217120@g14g2000cwa.googlegroups.com> So, I did the following: --- a=input("Give me an integer") b=input("Give me another integer") def gcd(a,b): if a < b: a, b = b, a while b != 0: a, b = b, a % b return a --- But, in the xterm, it terminates after "Give me another integer." Is Euclid's Algorithm supposed to be implemented in such a way as to be used as a tool to find the GCD of two integers, or have I misinterpreted the intent of the algorithm? From john at castleamber.com Fri Aug 26 17:50:59 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 21:50:59 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> <3n8ddiFbhg7U1@individual.net> Message-ID: Denis Kasak wrote: > John Bokma wrote: >> Ulrich Hobelmann wrote: >> >>> John Bokma wrote: >>>> http://www.phpbb.com/mods/ >>> >>> Great. How can I, the user, choose, how to use a mod on a given web >>> server? >> >> Ask the admin? > > And that is, in your opinion, completely comparable to running your > own, private client? Oh, but if you want your own private client, feel free to come up with one. I for one would welcome an XML interface to for example phpBB. (Not sure if such a thing exists). So I agree with you for a part. However, how many people, do *need* a kill file? Most boards have active moderators. Also, in my experience, most boards are a tighter knit crowd with less need for kill filing. > Is the admin obliged to install the mod? No, but in my experience, they listen. > Is the admin > even reachable? Of course. >> Otherwise: fetch HTML, parse it, restructure it, and have the >> application run a local webserver. Python, Perl, piece of cake. > > You seem to be forgetting that we are mainly talking about end users > here No, I am not. Most end users of those boards don't *require* what you want, you look at a board from a programmers point of view. And hence, as a programmer you *can* do such things. > who most probably will not have the sufficient expertise to do all moreover he/she doesn't care. > that. And even if they do, it's still time consuming. If I am not happy with my Usenet client, I have the same problem. I like Xnews for example, but AFAIK it's closed source. I don't know of any open source Windows client that comes close to Xnews. It's time consuming because there is (yet) no need for it. When I started to use Usenet there where only a handful of clients (IIRC), nn and another one (rn?) are the only ones that I can recall. Like I said, it's not that hard to create a SOAP/XML-RPC interface to, for example phpBB. Maybe it's already there. The tools are there. And a next step could be to create a wrapper, one end acts as a local nntp server, the other end talks using XML with phpBB. Once that's written, you could use (probably within limits) a Usenet client :-) Now this seems to be cross posted in several comp.lang groups. Anyone? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From jstroud at mbi.ucla.edu Mon Aug 1 14:34:14 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 1 Aug 2005 11:34:14 -0700 Subject: Dabo in 30 seconds? In-Reply-To: <200508010830.27322.ed@leafe.com> References: <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> Message-ID: <200508011134.14398.jstroud@mbi.ucla.edu> On Monday 01 August 2005 05:30 am, Ed Leafe wrote: > Should we have defensive code for every possible broken installation? We > use a lot of the Python standard library modules, many dbapi-compliant > modules, and, of course, wxPython. If someone mis-installs one of the > pre-requisites, do you expect Dabo to catch that and present you with a > diagnostic message? I'm serious here: I want to know what people consider > acceptable for a software package that relies on other packages. I don't know. Defense code sounds like a PITA. But maybe give a hint in the INSTALL file, or a link to the proper wxPython install? These are the obvious things that might help people like me at least get to the point where we can see what your software does. Take a look at the SciPy module for good instructions. It would have been hell without the precise list of prerequisites in the INSTALL.txt file. James From markuskeinspam at johalla.de Tue Aug 23 04:52:29 2005 From: markuskeinspam at johalla.de (Markus) Date: Tue, 23 Aug 2005 10:52:29 +0200 Subject: Running multiple console processes and watching their output In-Reply-To: <43097ddf$1@news.bezeqint.net> References: <43097ddf$1@news.bezeqint.net> Message-ID: <430b005a$1@news.knipp.de> If you are under UNIX, try the 'screen' command. Markus From martijn at gamecreators.nl Thu Aug 25 04:48:19 2005 From: martijn at gamecreators.nl (martijn at gamecreators.nl) Date: 25 Aug 2005 01:48:19 -0700 Subject: newbie question: convert a list to one string Message-ID: <1124959699.071708.239210@g14g2000cwa.googlegroups.com> H! I'm searching for the fastest way to convert a list to one big string. For example: test = ['test','test2','test3'] print unlist(test) > test test2 test3 (string) I know I can make a loop like below but is that the fastest/best option ? def unlist(test): output='' for v in test: output = output+" "+v return output Thanks for helping, GC-Martijn From samgurung at gmail.com Tue Aug 2 00:53:26 2005 From: samgurung at gmail.com (linuxfreak) Date: 1 Aug 2005 21:53:26 -0700 Subject: Newer than a Newbe In-Reply-To: References: Message-ID: <1122958406.623954.117430@f14g2000cwb.googlegroups.com> Look at Karrigell. Its a web framework for Python http://karrigell.sourceforge.net From john at castleamber.com Fri Aug 26 07:21:32 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 11:21:32 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: Denis Kasak wrote: > Mike Schilling wrote: >> >> Threaded mail-readers too, screen-based editors , spell-checkers, all >> useless frills. > > Interestingly enough, I have explained my opinion in the part of the > post you have trimmed. On the other hand, things you mentioned are far > from being useless. They introduce no intrinsical slowdown due to > increased bandwidth consumation, nor potential security problems. You can't be sure: errors in the handling of threads can cause a buffer overflow, same for spelling checking :-D > They > have no downsides I can possibly think of Some people never use them, and hence they use memory and add risks. > and have many advantages. They > are useful. HTML on Usenet is not. Of course can HTML be useful on Usenet. The problem is that it will be much more often abused instead of used. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From orome.the.valar at gmail.com Fri Aug 12 10:44:41 2005 From: orome.the.valar at gmail.com (sinan .) Date: Fri, 12 Aug 2005 17:44:41 +0300 Subject: simpli int/str problem Message-ID: <8c05f79c05081207443094dc67@mail.gmail.com> hi all, i have a string and int values in same dictionary like this dict = {'str_name': 'etc' , 'int_name' : 112 } the error occures when do this SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + dict['str_name'] + "', '" + dict['int_name'] + "')" cursor.execute(SQL) python does not accep dict['int_name'] in SQL variable but when i convert this variable to the str , python accepts but i cannot insert that into database because database only accept int in `BH ` thanks. From jepler at unpythonic.net Sat Aug 6 19:44:00 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sat, 6 Aug 2005 18:44:00 -0500 Subject: Syntax error after upgrading to Python 2.4 In-Reply-To: References: <1123323206.151000.309140@g49g2000cwa.googlegroups.com> Message-ID: <20050806234356.GA22724@unpythonic.net> On Sat, Aug 06, 2005 at 05:15:22PM -0400, Terry Reedy wrote: > In any case letting developers add new features is part of the price of > getting unpaid bug fixes for free software. But note that PSF does not > make you to upgrade. Here is the current list of possible downloads. > [a mere 8 versions] Oh, don't give such a short list! Here's what I found on the python.org ftp site: # in /pub/python (most with a set of a/b/rc tarballs too) drwxrwsr-x 2 1004 1004 512 Aug 23 2001 2.0 drwxrwsr-x 3 1004 1004 512 Aug 06 2001 2.0.1 drwxrwsr-x 3 1004 1004 512 Aug 06 2001 2.1 drwxrwsr-x 4 1004 1004 512 Aug 16 2001 2.1.1 drwxrwsr-x 4 1010 1004 512 Feb 08 2002 2.1.2 drwxrwsr-x 3 1010 1004 512 Apr 23 2002 2.1.3 drwxrwsr-x 5 1004 1004 512 Apr 23 2002 2.2 drwxrwsr-x 4 1015 1004 512 Apr 23 2002 2.2.1 drwxrwsr-x 4 1005 1004 512 Aug 06 2003 2.2.2 drwxrwsr-x 4 1004 1004 512 Jun 13 2003 2.2.3 drwxrwsr-x 4 1005 1004 512 Dec 16 2004 2.3 drwxrwsr-x 4 1010 1004 512 Sep 24 2003 2.3.1 drwxrwxr-x 4 1010 1004 512 Oct 18 2003 2.3.2 drwxrwxr-x 4 1010 1004 512 Feb 03 2004 2.3.3 drwxrwxr-x 4 1010 1004 512 May 27 2004 2.3.4 drwxrwxr-x 4 1010 1004 512 Mar 20 22:35 2.3.5 drwxrwxr-x 4 1010 1004 512 Nov 30 2004 2.4 drwxrwxr-x 4 1010 1004 512 Apr 03 08:10 2.4.1 # in /pub/python/src -rw-rw-r-- 1 1005 1004 1907724 Dec 26 2001 python-1.2.tar.gz -rw-rw-r-- 1 1005 1004 2037062 Dec 26 2001 python-1.3.tar.gz -rw-rw-r-- 1 1005 1004 2252481 Dec 26 2001 python-1.4.tar.gz -rw-rw-r-- 1 1005 1004 2259957 Dec 26 2001 python-1.5.1.tar.gz -rw-rw-r-- 1 1005 1004 2533053 Dec 26 2001 python-1.5.2.tar.gz -rw-rw-r-- 1 1005 1004 2465663 Dec 26 2001 python-1.5.2b1.tar.gz -rw-rw-r-- 1 1005 1004 2515142 Dec 26 2001 python-1.5.2b2.tar.gz -rw-rw-r-- 1 1005 1004 2543715 Dec 26 2001 python-1.5.2c1.tar.gz -rw-rw-r-- 1 1005 1004 2904353 Dec 26 2001 python-1.5.tar.gz -rw-rw-r-- 1 1005 1004 4114315 Dec 26 2001 python-1.6.tar.gz -rw-rw-r-- 1 1005 1004 3784124 Dec 26 2001 python-1.6b1.tar.gz -rw-rw-r-- 1 1005 1004 4066781 Dec 26 2001 python-2.0.tar.gz -rw-rw-r-- 1 1005 1004 4178895 Dec 26 2001 python-2.0b1.tar.gz -rw-rw-r-- 1 1005 1004 3962932 Dec 26 2001 python-2.0b2.tar.gz -rw-rw-r-- 1 1005 1004 3997787 Dec 26 2001 python-2.0c1.tar.gz -rw-rw-r-- 1 1005 1004 1137661 Mar 19 2002 python1.0.1.tar.gz -rw-rw-r-- 1 1005 1004 1465876 Mar 19 2002 python1.1.tar.gz And then there's CVS... Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From aahz at pythoncraft.com Sat Aug 13 15:45:18 2005 From: aahz at pythoncraft.com (Aahz) Date: 13 Aug 2005 12:45:18 -0700 Subject: Spaces and tabs again References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> Message-ID: In article <1123927648.058674.213380 at g44g2000cwa.googlegroups.com>, wrote: > >I know that some people likes tabs, and other people likes spaces, so >probably a single standard cannot be enforced, but I think the python >compiler must generate an error (and stop compiling) when the >sourcecode of a module contains both spaces and tabs to indent the >lines of code (and comments lines too?). Python 3.0 will prohibit tabs. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From mwm at mired.org Thu Aug 25 00:56:10 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 25 Aug 2005 00:56:10 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> Message-ID: <86slwymx79.fsf@bhuda.mired.org> Bryan Olson writes: > Mike Meyer wrote: > > Bryan Olson writes: > >>Mike Meyer wrote: > >> > The rule I follow in choosing my tools is "Use the least complex tool > >> > that will get the job done." > >>Even if a more complex tool could do the job better? > > In that case, the simpler model isn't necessarily getting the job > > done. I purposely didn't refine the word "job" just so this would be > > the case. > I didn't ask about any particular case. You stated a general > rule you follow, and I think that rule is nuts. You're entitled to write code as complex and unmanagable as you wish. Me, I'll stick with the simplest thing that solve the problem. > >>Now I've gotten off-topic. Threads are winning, and the industry > >>is going to multiple processors even for PC-class machines. > >>Might as well learn to use that power. > > I own too many orphans to ever confuse popularity with technical > > superiority. > The issue here is whether to confuse reality with what one might > wish reality to be. Let's see. Reality is that writing correct programs is hard. Writing correct programs that use concurrency is even harder, because of the exponential explosion of the order that operations can happen in. Personally, I'm willing to use anything I can find that makes those tasks easier. > > I've learned how to use threads, and done some > > non-trivial thread proramming, and hope to never repeat that > > experience. It was the second most difficult programming task I've > > ever attempted(*). > Great -- lets see it! Can you point out what parts were so > hard? How would you have solved the same problems without > threads? Google for "aws amiga web server". Somebody is liable to still have the source around. The hard part was dealing with the making sure that every sequence of operations that actually happened was correct, of course. The web server I wrote after that used async i/o, thus avoiding the problem completely. > > As I said above, the real problem isn't threads per > > se, it's that the model for programming them in popular languages is > > still primitive. So far, to achieve the non-repitition goal, I've used > > async I/O, restricted my use of real threads in popular languages to > > trivial cases, and started using servers so someone else gets tod eal > > with these issues. > Then maybe we should listen to those other people. Yes, we probably should. I do. The problem is, the designers of popular languages apparently don't, so I'm stuck with lousy tools like thread libraries (meaning you get no compile-time help in avoiding the problems that plague concurrent programs) and Java's pseudo-monitors. > Is there a successful single-line-of-execution async-I/O based > server that provides a service as sophisticated as the modern > relational- database engines? Why do you think that is? I don't know - is there? There have certainly been some sophisticated network servers using async I/O and a single thread of execution. Are they as sophisticated as a modern relational database? I dunno. Then again, I already know that async i/o with a single thread of execution isn't as powerful as threads, so there are almost certainly problem areas where it isn't suitable and threads are. So what? That doesn't make the async I/O model any less useful. Of course, if you're only able to learn one tool, you should probably learn the most powerful one you can. But just because you only know how to use a hammer doesn't automatically make everything you encounter a nail. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From could.net at gmail.com Mon Aug 8 23:05:36 2005 From: could.net at gmail.com (could ildg) Date: Tue, 9 Aug 2005 11:05:36 +0800 Subject: How to determine that if a folder is empty? In-Reply-To: References: Message-ID: <311b5ce1050808200557a53d45@mail.gmail.com> On 8/8/05, Peter Hansen wrote: > could ildg wrote: > > I want to check if a folder named "foldername" is empty. > > I use os.listdir(foldername)==[] to do this, > > but it will be very slow if the folder has a lot of sub-files. > > Is there any efficient ways to do this? > > I'm just curious to know under what circumstances where it's important > to know whether a directory is empty it's also important that the > operation occur with lightning speed... I want to know this because I want to zip a directory and all of its sub-files and sub-directories to a zip file. zipfile module of python will not automatically include the empty directories, so I have to check if a dir is empty and do this manually. I did this with java, it's very fast, but when I do this with python. I use the code to backup a directory every morning after I get up. It is not import if it's fast or not. I just want to know whether their is better solutions. import os,zipfile from os.path import join from datetime import date def zipfolder(foldername,filename): """ zip folder foldername and all its subfiles and folders into a zipfile named filename. """ zip=zipfile.ZipFile(filename,"w",zipfile.ZIP_DEFLATED) for root,dirs,files in os.walk(foldername): for dir in dirs: #now I don't check any more whether a dir is empty zif=zipfile.ZipInfo(join(root,dir)+"/") zip.writestr(zif,"") for filename in files: print "compressing ",join(root,filename) zip.write(join(root,filename)) zip.close() print "Finished compressing." > > Reinhold's suggestion to delete the folder was interesting in this > respect... isn't that (prior to deleting a folder) just about the only > time one cares if it's empty, normally? And in this case you don't need > to do the check, as Reinhard shows, so performance isn't an issue. > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list > From max at alcyone.com Thu Aug 11 02:26:40 2005 From: max at alcyone.com (Erik Max Francis) Date: Wed, 10 Aug 2005 23:26:40 -0700 Subject: what's the exactly newsgroup url of python-list? In-Reply-To: References: Message-ID: Ben Finney wrote: > You may be confused. > > is a URL to a Usenet newsgroup, as > evidenced by the 'news:' schema part. If your web browser is > configured properly to invoke a newsreader (such as Thunderbird) for > 'news:' URLs, your newsrreader will then attempt to get the > comp.lang.newsgroup from your default NNTP server. > > python-list is a mailing list. There's a relation between them which you're not mentioning, which is that all posts to the mailing list are gated to the newsgroup and vice versa. They are not completely unrelated entities. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Make it come down / Like molasses rain -- Sandra St. Victor From newsgroups at jhrothjr.com Wed Aug 3 10:12:35 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 3 Aug 2005 08:12:35 -0600 Subject: Art of Unit Testing (Acceptance Tests) References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: <11f1k6t4eqr5l87@news.supernews.com> "Christoph Zwerschke" wrote in message news:dcpt45$64r$1 at online.de... > Peter Hansen wrote: >> What's wrong with using Python's existing "global" support, and just >> having your test case setUp() call a global setup routine which checks >> whether that global setup work has already been done and, if not, does it >> once and sets a flag to say that it has now been done? I've done this >> easily in the few cases where I've wanted this behaviour. It doesn't >> seem complex enough to warrant adding to the standard unit test support. > > Actually I already thought about doing it that way, but then I thought it > is so ugly, there must be a simpler solution ;-) > >> If you're going to quote XP rules of thumb, the tests should be >> independent and very fast, and if you have a setup code that is taking a >> long time, it's likely a "code smell" of some kind, and you should be >> fixing the design which prevents you writing these tests with minimal and >> quick setup. Are these really like "acceptance" tests? If they were >> unit tests, they should take only a few minutes to run, total, and you >> should be running them all *many* times a day, not twice. > > You're right. I think wanting to have a more global initialization > indicates that you are acutally not wanting to do a "unit" test, but a > more global test of the overall system, something like an acceptance or > integration test, i.e. you are trying to abuse unittest for something it > was not intended to be used for. > > Maybe since unittest is the only testing framework included with the > standard lib, people tend to use it for all testing purposes. If you only > have a hammer, everything looks like a nail. An excellent point, even though it's somewhat blunted by the inclusion of doctest in the core. Another point to ponder is that the originators of xUnit, Kent Beck and Erich Gamma, did not intend it to be used for acceptance testing. That ecological niche is filled by FIT. The Python port of Fit can be acquired from the file libraries of the FitNessse or Extremeprogramming Yahoo mailing lists. I'll get it onto the CheeseShop (what used to be the Python Package Index) one of these days Real Soon Now. (Arlo gave me a good shove at Agile2005 in that direction.) The FIT developers are working on standardizing the specs, and expensive setups and teardown are definitely on the agenda. In fact, that's one of my work items... Unit testing usually does not require expensive setups and teardowns, at least if you're not working on real tangled legacy code. Acceptance testing does. Meanwhile, there's a book and two web sites: fit.c2.com and www.fitnesse.org to look at. John Roth Python Fit > > -- Christoph From richie at entrian.com Wed Aug 31 04:39:21 2005 From: richie at entrian.com (Richie Hindle) Date: Wed, 31 Aug 2005 09:39:21 +0100 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: <1125425945.667967.181000@g49g2000cwa.googlegroups.com> References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125425945.667967.181000@g49g2000cwa.googlegroups.com> Message-ID: [n00m] > WHY ON THE EARTH <'module' object has no attribute 'AF_INET'> ??? Because you have a socket.py in d:\python23\00 which is being picked up instead of Python's own socket module. You shouldn't give your modules the same name as Python's own modules. -- Richie Hindle richie at entrian.com From steve at holdenweb.com Mon Aug 22 08:21:58 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 13:21:58 +0100 Subject: while c = f.read(1) In-Reply-To: <1124705414.704694.241960@f14g2000cwb.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> <1124705414.704694.241960@f14g2000cwb.googlegroups.com> Message-ID: Greg McIntyre wrote: > John Machin wrote: > >>>Is some way to make this code more compact and simple? It's a bit >>>spaghetti. >> >>Not at all, IMHO. This is a simple forward-branching exit from a loop in >>explicable circumstances (EOF). It is a common-enough idiom that doesn't >>detract from readability & understandability. Spaghetti is like a GOTO >>that jumps backwards into the middle of a loop for no discernable reason. > > > While that is true, I had high hopes that I could do this: > > while c = f.read(1): # ... > > And relative to that, it is more complex. And although I am nit-picking > to try to simplify this code, I wanted to understand why Python works > in this way (even if that's just "historical reasons"), and check to > see if there was not some shorter more modern Pythonic alternative. > Guido explicitly decided he wanted a clear differentiation between expressions and statements, and that assignment was to be a statement. The logic behind this design decision is documented in http://www.python.org/doc/faq/general.html#why-can-t-i-use-an-assignment-in-an-expression which may have already been mentioned in this thread. > I did actually like Robert Kern's suggestion which used an iterator and > a function to factor out the complexity of setting it up. I think that > is actually better code than the original. > There are many elegant ways to express iterative solutions in Python, and generator expressions are frequently useful in this context as well. > It matches my philosophy in programming of pushing complexity *out* of > the code which does the actual job, even if it means writing a few > support functions/classes/whatever. I know they can be re-used and > refined and I know that it is the code that does the actual job that is > most likely to be rewritten in future revisions of the code with shifts > in requirements. > You are likely to be happy with Python, then. Most Python programmers are pragmatists. > > >>You have a bit of a misunderstanding here that needs correcting: >> >>In "if " and "while ", is NOT restricted to being in >>(True, False). See section 5.10 of the Python Reference Manual: > > > I'm sorry! I realise that now and I'm sorry to have caused the traffic > I did. Thank you for pointing it out to me though - it's pretty > fundamental Python! > Yes, but it's a common question from newcomers (hence its appearance in the FAQ), and there's usually some interesting discussion when it comes up. Fortunately c.l.py isn't the kind of place you will usually experience "Read the FAQ!" abuse. We try to remember that Python's popularity is growing so fast that about a third of readers at any time are likely to be newbies to Python (albeit many of them are experienced in other programming languages). > *Greg thumbtacks a note to his forehead* > Ouch! > > >>How about >> for c in f.read(): >>? >>Note that this reads the whole file into memory (changing \r\n to \n on >>Windows) ... performance-wise for large files you've spent some memory >>but clawed back the rather large CPU time spent doing f.read(1) once per >>character. The "more nicely" factor improves outasight, IMHO. > > > I would if only I had any kind of guarrantee on the file size but I > don't - this code is for reading a header out of a binary file which > uses delimiters and escape characters to mark out its fields. I didn't > design the format, but after cleaning up the code that deals with it, I > may *re*design it. ;) > If you *know* that the header is MAX characters maximum you could try for c in f.read(MAX): ... > > >>Mild curiosity: what are you doing processing one character at a time >>that can't be done with a built-in function, a standard module, or a >>3rd-party module? > > > Our company is designing a new file type. *sigh*. Confidentiality > prevents me from saying any more, too. If that bugs you because it's > not open source, sorry I need a job. Don't worry though, I'm developing > an open source remote GUI for the code management system we're using > called Aegis (http://aegis.sf.net). It's not sufficiently implemented > yet to warrant posting publically (I'd describe its current state as > "framework") but if anybody reading this is interested then give me a > yell and it'll have a public project page or something overnight. ;) > Good luck. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jstroud at mbi.ucla.edu Tue Aug 2 22:56:26 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 2 Aug 2005 19:56:26 -0700 Subject: using httplib for authentication Message-ID: <200508021956.26015.jstroud@mbi.ucla.edu> Hello All, I want to use python to download files from sites where authentication is required. The page appears to send a form with the login and pass by post. I would like to log in and keep this session open within python and download a number of files automatically. Could anyone kindly point me in the right direction? I have discovered httplib and read the documentation and looked at the examples, but they don't seem helpful for this. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From jeremy+complangpython at jeremysanders.net Fri Aug 12 05:12:40 2005 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Fri, 12 Aug 2005 10:12:40 +0100 Subject: Psyco & Linux References: <2EUKe.193369$5V4.19467@pd7tw3no> Message-ID: Fausto Arinos Barbuto wrote: > The specifics of my system are: > > Athlon AMD-64 3300+ > SuSE 9.3 Professional (64-bit) > Python 2.4 > gcc/g++ 3.3.5 Ummm... I thought psyco only supported 32 bit systems. I haven't seen anything else to suggest otherwise. See http://psyco.sourceforge.net/psycoguide/req.html Maybe you could recompile your python in 32 bit mode. You may find that native 64 bit python is faster than 32 bit psyco however! -- Jeremy Sanders http://www.jeremysanders.net/ From mensanator at aol.com Thu Aug 18 02:01:18 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 17 Aug 2005 23:01:18 -0700 Subject: question about binary and serial info In-Reply-To: <1124339226.523475.257400@z14g2000cwz.googlegroups.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <1124337614.259032.4970@g14g2000cwa.googlegroups.com> <1124339226.523475.257400@z14g2000cwz.googlegroups.com> Message-ID: <1124344877.985737.40510@g44g2000cwa.googlegroups.com> nephish at xit.net wrote: > yeah, i think i got that down, i need help with getting the hex to > binary, then splitting the byte up to compare each bit against the bit > in another byte. The & operator does all 8 comparisons simultaneously. So if the serial port byte is A, the reference byte is B then AB = A & B has only 1 bits where both A and B had 1's in their respective positions. Now, you can test AB for a particular bit position (say bit 3) by testbit3 = AB & 2**3 If testbit3 > 0 then the bit was a 1. > unless i am not understanding this stuff with the bitwise right. there > wasn't a lot in the python library reference about it. The GMPY module has some interesting bit functions. Popcount can tell you how many of the AB bits are 1 without specifying which ones: >>> for i in range(16): print gmpy.popcount(i), 0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 Hamming distance tells you how many bits differ between two numbers (again, without telling you which ones) >>> for i in range(16): print gmpy.hamdist(i,7), 3 2 2 1 2 1 1 0 4 3 3 2 3 2 2 1 If one operand is 0, then Hamming distance is the same as popcount. And then there's scan1 which will tell you the bit bit position of the first 1 bit. >>> A = 48 >>> B = 255 >>> AB = A & B >>> print gmpy.scan1(AB) 4 So the first 1 bit is bit 4, which means bits 0, 1, 2 and 3 are all 0. > thanks From Scott.Daniels at Acm.Org Fri Aug 12 13:36:25 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 12 Aug 2005 10:36:25 -0700 Subject: Using globals with classes In-Reply-To: <42fc2e42$0$18637$14726298@news.sunsite.dk> References: <42fc2e42$0$18637$14726298@news.sunsite.dk> Message-ID: <42fcd271$1@nntp0.pdx.net> Madhusudan Singh wrote: > .... I am using qwtplot to display a running plot : > > void Form3::runningplot(n,plottitle,xname,x,y1name,y1,y2name,y2) > { ^^ I presume this is just some untranslated stuff ^^ > if n==1 : > > plotkey1=self.runningqwtPlot.insertCurve(y1name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yLeft) > > plotkey2=self.runningqwtPlot.insertCurve(y2name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yRight) > self.runningqwtPlot.setTitle(plottitle) > self.runningqwtPlot.setXGrid(True) > self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yLeft) > self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yRight) > self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.xBottom) > self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yLeft,y1name) > self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yRight,y2name) > self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.xBottom,xname) > self.runningqwtPlot.setCurveData(plotkey1,x,y1,n) > self.runningqwtPlot.setCurveData(plotkey2,x,y2,n) > self.runningqwtPlot.replot() > else : > self.runningqwtPlot.setCurveData(plotkey1,x,y1,n) > self.runningqwtPlot.setCurveData(plotkey2,x,y2,n) > self.runningqwtPlot.replot() > } The way I'd normally accomplish this is to separate the setup and use by defining a class: class CurvePlot(object): def __init__(self, plot, plottitle, xname, y1name, y2name, key1=None, key2=None): self.plot = plot if key1 is None: key1 = plot.insertCurve(y1name, plot.xBottom, plot.yLeft) self.key1 = key1 if key2 is None: key2 = plot.insertCurve(y2name, plot.xBottom, plot.yRight) self.key2 = key2 plot.setTitle(plottitle) plot.setXGrid(True) plot.setAxisAutoScale(plot.yLeft) plot.setAxisAutoScale(plot.yRight) plot.setAxisAutoScale(plot.xBottom) plot.setAxisTitle(plot.yLeft, y1name) plot.setAxisTitle(plot.yRight, y2name) plot.setAxisTitle(plot.xBottom, xname) def curve(self, x, y1, n) self.plot.setCurveData(self.key1, x, y1, n) self.plot.setCurveData(self.key2, x, y2, n) self.plot.replot() And then calling it like: cplot = CurvePlot(self.runningqwtPlot, plottitle, xname, y1name, y2name) cplot.curve(n, x, y1, y2) > I also have a global variable named "globaldebug" that when set to True, > shows some diagnostic information as different slots are called. That too > fails with the same error : > > NameError: global name 'globaldebug' is not defined What you probably don't understand is that "globals" are per-module, not program-wide. If you write a global from inside a function or method, you need to declare "global varname" inside the function or method in which you do the writing. Simply using (reading) a global in a module does not require the "global" declaration. --Scott David Daniels Scott.Daniels at Acm.Org From bedouglas at earthlink.net Sun Aug 7 12:19:10 2005 From: bedouglas at earthlink.net (bruce) Date: Sun, 7 Aug 2005 09:19:10 -0700 Subject: amazon web services/api... Message-ID: <07f501c59b6b$bec9cf70$0301a8c0@Mesa.com> hi... has anybody ever played/successfully with the amazon- web services/api? i'm trying to figure out how i can use the browsenodeid to generate ISBN information for a book. the examples i've seen on various sites haven't been much help yet. thanks -bruce bedouglas at earthlink.net From devlai at gmail.com Thu Aug 11 23:30:14 2005 From: devlai at gmail.com (Devan L) Date: 11 Aug 2005 20:30:14 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <1123817414.665062.282500@g49g2000cwa.googlegroups.com> Fausto Arinos Barbuto wrote: > Ray wrote: > > > 1. Where are the access specifiers? (public, protected, private) > > AFAIK, there is not such a thing in Python. > > ---Fausto Well, technically you can use _attribute to mangle it, but technically speaking, there are no public, protected, or private things. From deets at nospam.web.de Tue Aug 23 18:19:21 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Aug 2005 00:19:21 +0200 Subject: how to deal with space between numbers In-Reply-To: References: Message-ID: <3n1ln9F1928n5U1@uni-berlin.de> > Thanks a lot for your valuable answer, i like the way you code , but i > would like to use my own, so if it is possible for you and if you have > time, please could you fix my code, so that i can do what i want. > Because i am using the this out put to another one , and i have the same > problem. I will really appreciate it !!! Sorry to say so - but your code (and general approach, removing spaces that is) is utterly flawed. Try to wrap your head around the concepts presented to you and rework your code. Regards, Diez From mrose at azplanningcenter.com Wed Aug 17 19:52:24 2005 From: mrose at azplanningcenter.com (Mike Rose) Date: Wed, 17 Aug 2005 16:52:24 -0700 Subject: GIS Related Scripting Issue Message-ID: <21234D0B49BFB444AEB633CF9CAF2AC7172C98@tpc2003server> I am currently using ArcGIS 9.1 and was referred to this list to ask my question. I am using a python script to loop through a series of features, select all polygons that are within 5 miles, run statistics on those selected polygons, then append the values to a new database(dbf). I am not sure if I am going about this correctly or not, but my script is definitely not working. I am getting an error when it tries to append to the dbf. Here is what I have so far. I would really appreciate any help that someone could provide. Thanks in advance! # ------------------------------------------------------------------------ --- # final_hopefully.py # Created on: Tue Aug 16 2005 04:39:33 PM # (generated by ArcGIS/ModelBuilder) # ------------------------------------------------------------------------ --- # Import system modules import sys, string, os, win32com.client # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx") # Local variables... bgrps_data = "bgrps_data" bgrps_data__2_ = "bgrps_data" half_mile_parcels = "half_mile_parcels" bgrps_data__3_ = "bgrps_data" exported_data2_dbf = "C:\\Temp\\data2.dbf" bgrps_data__4_ = "bgrps_data" half_mile_parcels__2_ = "half_mile_parcels" exported_data1_dbf = "C:\\Temp\\data1.dbf" exported_data_dbf = "C:\\Temp\\data.dbf" exported_data_dbf__2_ = "C:\\Temp\\data.dbf" #Loop through each record gp.Workspace= "C:\\Temp\\test.mdb" # Process: Select Layer By Location (2)... gp.SelectLayerByLocation_management(bgrps_data__4_, "WITHIN_A_DISTANCE", half_mile_parcels__2_, "26400 Feet", "NEW_SELECTION") # Process: Summary Statistics (2)... gp.Statistics_analysis(bgrps_data__3_, exported_data2_dbf, "AGE_PERC MEAN;home_perc MEAN", "") try: fcs = gp.listfeatureclasses() #Loop through the list of feature classes fcs.Reset() fc = fcs.Next() while fc != "": # Process: Select Layer By Location... gp.SelectLayerByLocation_management(bgrps_data__2_, "WITHIN_A_DISTANCE", half_mile_parcels, "26400 Feet", "NEW_SELECTION") # Process: Summary Statistics (3)... gp.Statistics_analysis(bgrps_data, exported_data1_dbf, "AGE_PERC MEAN;home_perc MEAN", "") # Process: Append... gp.Append_management("C:\\temp\data2.dbf", exported_data_dbf__2_, "TEST") #Move to the next fc in the list fc = fcs.Next() except: gp.addmessage(gp.getmessages(2)) print gp.getmessages(2) Michael Rose GIS Specialist The Planning Center ph. (520) 623.6146 fx. (520) 622.1950 http://www.azplanningcenter.com mrose at azplanningcenter.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From bignose+hates-spam at benfinney.id.au Thu Aug 18 20:02:20 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 19 Aug 2005 10:02:20 +1000 (EST) Subject: Really virtual properties References: <87slx7c4g5.fsf@wilson.rwth-aachen.de> Message-ID: Torsten Bronger wrote: > Hall?chen! > > When I use properties in new style classes, I usually pass get/set > methods to property(), like this: > > x = property(get_x) Better is to make it clear that 'get_x' is not intended to be called directly. You can do this through the convention of naming the function '_get_x', or use this recipe for a namespace-clean approach: Sean Ross: "This recipe suggests an idiom for property creation that avoids cluttering the class space with get/set/del methods that will not be used directly." > If I overwrite get_x in a derived class, any access to x still calls > the base get_x() method. Is there a way to get the child's get_x() > method called instead? Not using the built-in property type. Here is a recipe for a LateBindingProperty that does what you ask: Steven Bethard: "This recipe provides a LateBindingProperty callable which allows the getter and setter methods associated with the property to be overridden in subclasses." -- \ "Any sufficiently advanced bug is indistinguishable from a | `\ feature." -- Rich Kulawiec | _o__) | Ben Finney From strick_nine at comcast.net Fri Aug 19 10:04:33 2005 From: strick_nine at comcast.net (Tom Strickland) Date: Fri, 19 Aug 2005 09:04:33 -0500 Subject: Newbie Question Message-ID: <6rGdnSpFWa5se5jeRVn-vw@comcast.com> I have a file that contains many lines, each of which consists of a string of comma-separated variables, mostly floats but some strings. Each line looks like an obvious tuple to me. How do I save each line of this file as a tuple rather than a string? Or, is that the right way to go? Thank you. Tom Strickland From chris.levis at gmail.com Wed Aug 17 10:23:42 2005 From: chris.levis at gmail.com (chris) Date: 17 Aug 2005 07:23:42 -0700 Subject: get the return code when piping something to a python script? In-Reply-To: <1124285138.352319.298070@g47g2000cwa.googlegroups.com> References: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> <1124285138.352319.298070@g47g2000cwa.googlegroups.com> Message-ID: <1124288622.340686.73660@g47g2000cwa.googlegroups.com> I use the following when I have an external command to do: #---------------------------------------------------- def doCommand( cmd,forked=False,runFrom=None ): """ Do a command, and return the (stdout+stderr) and the exit status. This was written to work both on Windows and *nix, and in the limited testing to which it has been subjected, it works well. """ import sys; import os; exitcode = None; output = None; origin = None; if runFrom: origin = os.getcwd() try: os.chdir( runFrom ); except: pass; # "forked" to us means "run in background and forget about it". The # method of execution is the same on both windows and unix if forked: theCommand = cmd.split()[0]; theArgs = cmd.split(); # Include the cmd itself in the v. # Guaranteed to be a list. # P_DETACH: we don't want the process to be our child, and # we don't want to know what happens to it... Some father! exitstatus = os.spawnve( os.P_DETACH,theCommand,theArgs,os.environ ); # if we're not spawning off a separate child, then we do care about # the results of the process, and execution is different between # windows and unix else: if( sys.platform == "win32" ): import win32pipe; (stdin,stdout) = win32pipe.popen4( cmd,'t' ); stdin.close(); output = stdout.read(); try: exitcode = stdout.close() or 0; except IOError: exitcode = ( -1 ); else: import commands; ( exitstatus,output ) = commands.getstatusoutput(cmd) #---- exitstatus is a smashing of the return value and any signal # sent back from the child process... break them out. exitcode = (( exitstatus >> 8) & 0xFF ); signal = ( exitstatus & 0xFF ); if runFrom: #return( 0,"Returning to %s from %s" %(origin,os.getcwd()) ) os.chdir( origin ); return( exitcode,output ); #----------------------------------------------------------- From fredrik at pythonware.com Tue Aug 23 14:34:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 20:34:24 +0200 Subject: DeprecationWarning: Non-ASCII character '\xf3' References: Message-ID: "jau" wrote: > print "hello world" > > i get this output > > hello world > sys:1: DeprecationWarning: Non-ASCII character '\xf3' in file > C:\Workspace\J&J\src\es\jau\main.py on line 2, but no encoding declared; > see http://www.python.org/peps/pep-0263.html for details > > the article mentioned above didn't explain so much for me. the error message means that Python found an \xF3-character on the second line in your main program (\xF3 is usually "latin small letter o with acute", or "?") the document you were referred to says Python will default to ASCII as standard encoding if no other encoding hints are given. (in other words, Python wants you to use plain ASCII in your source code, unless otherwise specified). and continues To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file: #!/usr/bin/python # -*- coding: -*- (in other words, if you want to keep using non-ASCII characters, you need to add a line like # -*- coding: iso-8859-1 -*- and make sure it's the first or second line in your script. if you didn't mean to add it, just get rid of it and try again. if eclipse doesn't display the character, check the file using notepad or some other editor) From fredrik at pythonware.com Tue Aug 23 15:25:20 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 21:25:20 +0200 Subject: Sequential XML parsing with xml.sax References: <1124823628.332677.73660@o13g2000cwo.googlegroups.com> Message-ID: peter at hardy.dropbear.id.au wrote: > The API reference isn't clear on whether parseString can only handle > discrete bits of valid XML the documentation says that "parse" expects an XML document, and that "parseString" is the same thing, but parses from a buffer. it's probably easier to pass a BZ2File instance to "parse", but if you insist on doing incremental SAX parsing, the IncrementalParser class might be what you need: http://www.python.org/doc/current/lib/module-xml.sax.xmlreader.html http://www.python.org/doc/current/lib/incremental-parser-objects.html From claudio.grondi at freenet.de Sat Aug 20 16:01:13 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Sat, 20 Aug 2005 20:01:13 -0000 Subject: unpacking TAR 1.14/ 1.15 archives on Windows (first step towards own static HTML version of Wikipedia) References: <3mnhu1F17b3j4U1@individual.net> <4306cf8d$0$15269$9b622d9e@news.freenet.de> <3mp0ouF17gb2qU1@individual.net> <3mp16gF17vuggU1@uni-berlin.de> Message-ID: <3mp9l6F183bohU1@individual.net> Thank you both (Martin and Diez) for your help. The 17 GByte TAR archive was unpacked without problems the way you suggested. Let's summarize: # Python tarfile module can't extract files from newer TAR archives (archived with tar 1.14 or later) # The core of my problems was, that I was not aware how easy it is to install and work with Cygwin and that to get Cygwins tar.exe to work it is necessary to use the provided Cygwin bash-3.00 shell an NOT the Windows command shell (DOS-box) . The receipt for unpacking Wikipedia media files provided as TAR archives when using Microsoft Windows is: Step 1. download http://sources.redhat.com/cygwin/setup.exe Step 2a. run the downloaded setup.exe which goes online and lets you choose which packages should be installed Step 2b. select for the installation additional to suggested ones the tar package version 1.15 Step 3. use the Cygwin icon on the Desktop or in Start-Programs- Cygwin-Cygwin Bash Shell to start a Cygwin shell and type : bash-3.00$ ./bin/tar.exe --extract --directory=/cygdrive/i/wikipedia/en/media -f /cygdrive/j/download.wikimedia.org/archives/images/en/20050530_upload.tar where i: and j: are the drive letters of appropriate Windows drives. The media files stored in TAR archive j: \download.wikimedia.org\archives\images\en\20050530_upload.tar will be unpacked to i:\wikipedia\en\media directory Step 4. wait, wait, wait ... (how long depends most on speed of your harddrives, on my system with USB drives appr. one hour) Step 5. BE HAPPY :)) and enjoy it, because you have mastered a step towards your own static HTML version of Wikipedia. The problems with extracting the content from the MySQL database dumps will kill you soon - and if not, especially for non-english languages (like German, Polish, Russian) and with math-formulas converted to pictures, all done on a Windows system __PLEASE__ share your know-how with me !!! (the only useful information I found on Internet about it were postings within the thread I initiated a longer time ago myself http://www.pythonforum.org/ftopic19424_Wikipedia___conversion_of_in_SQL_database_stored_data_to_HTM.html ) Claudio "Diez B. Roggisch" schrieb im Newsbeitrag news:3mp16gF17vuggU1 at uni-berlin.de... > Claudio Grondi wrote: > > remember. I work in a Windows command shell > > (DOS-box) and mount says: > > j: on /cygdrive/j , but I don't know how to write > > the entire path > > "j:\o\archives\images\dump.tar", > > so that the file can be found by tar.exe and > > unpacked to "i:\images" . > > tar.exe --extract --directory=tmp -f j:/o/archives/images/dump.tar > > results in: > > /usr/bin/tar: j\:/o/archives/images/dump.tar: Cannot open: Input/Output > > error > > telling > > tar.exe --extract --directory=tmp -f /cygdrive/j/o/archives/images/dump.tar > > doesn't work either. > > > Try the cygpath-command like this: > > echo `cygpath c:\\some\\windows\\path` > > That should yield > > /cygdrive/c/some/windows/path > > Alternatively, do somethink like this > > mkdir -p /mnt/j > > mount j: /mnt/j > > Then /mnt/j should be the root for all files under j: > > HTH Diez From edvard+news at majakari.net Thu Aug 25 09:14:05 2005 From: edvard+news at majakari.net (Edvard Majakari) Date: Thu, 25 Aug 2005 16:14:05 +0300 Subject: HTML/text formatting question References: <1123083202.047304.256330@g14g2000cwa.googlegroups.com> Message-ID: <87d5o2xioy.fsf@majakari.net> "Dr. Who" writes: > This seems clunky and my next step was going to be to define generic > functions which would generate the surrounding html tags only when > passed the proper argument. I was wondering if there was a better way > to do this with a standard Python library. It looked like formatter > might but that it also might be too low-level. You could use something like this: class HTMLFormatter: def __init__(self, tag, contents=None, **kwargs): self.tag = tag self._content = contents self.attrs = dict() self._set_attrs(kwargs) def _set_attrs(self, attrs): self.attrs = attrs if '_class' in self.attrs: self.attrs['class'] = self.attrs['_class'] del self.attrs['_class'] def set_content(self, contents, **kwargs): """ Set content of HTML element to contents. >>> f = HTMLFormatter('a') >>> f.set_content('cat', href='http://www.cat.org') >>> str(f) 'cat' >>> str(HTMLFormatter('td', 'cat')) 'cat' >>> str(HTMLFormatter('p', 'kitty kit', _class='cat')) '

kitty kit

' >>> str(HTMLFormatter('br')) '
' """ self._content = contents if kwargs: self._set_attrs(kwargs) def set_attribute(self, attr, val): """Set/update attribute 'attr' to 'val'.""" self.attrs[attr] = val def add_content(self, contents): """Add content to element. >>> p = HTMLFormatter('p', 'name of the cat is ') >>> p.add_content('meow') >>> str(p) '

name of the cat is meow

' >>> p = HTMLFormatter('td') >>> p.add_content('cat') >>> str(p) 'cat' """ if self._content is None: self._content = '' self._content = "%s%s" % (self._content, str(contents)) def contents(self): """Get contents of object. >>> p = HTMLFormatter('p', 'nice doggy dog') >>> p.contents() 'nice doggy dog' >>> p.add_content(HTMLFormatter('em', 'called wuff')) >>> p.contents() 'nice doggy dogcalled wuff' """ return self._content def __str__(self): open_tag = '%s' % self.tag if self.attrs: attrs = self.attrs.items() attrs.sort() attrs_str = ' '.join(['%s="%s"' % (k, v) \ for k,v in attrs]) open_tag = '%s %s' % (self.tag, attrs_str) if self._content is not None: return '<%s>%s' % (open_tag, self._content, self.tag) else: return '<%s/>' % open_tag Doctest strings show examples how to use it. For serious HTML building stuff it needs fiddling with, but should be handy for tiny projects. -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli Deo Gloria! $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n"; From CantankerousOldGit at gmail.com Sun Aug 7 08:02:01 2005 From: CantankerousOldGit at gmail.com (Cantankerous Old Git) Date: Sun, 07 Aug 2005 13:02:01 +0100 Subject: Making a timebomb In-Reply-To: References: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> Message-ID: Peter Hansen wrote: > Cantankerous Old Git wrote: > >> callmebill at gmail.com wrote: >> >>> I have a server that right now runs infinitely. I'd like to make it >>> die after some amount of time. >> >> >> The proper way to do it is to have the timer set a flag that the other >> threads check regularly. The threads can then clean up and exit asap. >> >> The dirty way, which can leave corrupt half-written files and other >> nasties, is something like sys.exit(). > > > sys.exit() won't help you if your server is running in the main thread, > nor if your server thread is not marked as a daemon, but that does raise > another possibility. Instead of doing serve() in the main thread, spawn > off a child thread to do the serving, and call setDaemon(True) on it. > Then the _main_ thread can do sys.exit() and the server thread will be > terminated (somewhat messily perhaps) -- even if it is blocked in an > accept() call or some other external blocking call. I assume you know that I actually meant System.exit(). Why do you think that won't help? From yoav_artzi at il.vio.com Wed Aug 24 08:59:40 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Wed, 24 Aug 2005 15:59:40 +0300 Subject: Variables in REs In-Reply-To: <1124881322.542897.215790@g43g2000cwa.googlegroups.com> References: <430c43cd$1@news.bezeqint.net> <1124881322.542897.215790@g43g2000cwa.googlegroups.com> Message-ID: <430c6e1a$1@news.bezeqint.net> Such a sweet and simple way. Thanks. tooper wrote: > Use os.sep to get / or \ or whatever character used to build pathes on > the os you're working on > From kimsj at mobile.snu.ac.kr Thu Aug 18 23:03:01 2005 From: kimsj at mobile.snu.ac.kr (James Sungjin Kim) Date: Fri, 19 Aug 2005 12:03:01 +0900 Subject: how do i add a new path into sys.path? In-Reply-To: References: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> Message-ID: Steve Holden wrote: > sys.path.append(r"C:\Temp") In this case, do I need to save the refined path, i.e, the original paths + the new path (r"C:\Temp"), by using some command in order to use it permanently. if yes, it would be greatly appreciated to noitce the correspoding command and the usage of it. -James From mekstran at scl.ameslab.gov Wed Aug 24 11:07:32 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Wed, 24 Aug 2005 10:07:32 -0500 Subject: Email client in Pyhton In-Reply-To: References: Message-ID: <20050824100732.1c8179f9.mekstran@scl.ameslab.gov> On Wed, 24 Aug 2005 20:15:01 +0530 (IST) knaren at midascomm.com wrote: > now i am planning to write a bear minimum email client in > pyhton. i found the smtp module of python could serve my > pupose. I can send message using mails using the smtp lib. > Now i'm looking for some modules which can help me in > fetching the mails from the mailserver and managing folders. Check out the POP and IMAP modules (poplib and imaplib), the email package, and the mailbox and mhlib modules (all in the standard library). I seem to recall seeing a maildir module somewhere, but can't find it now. IIRC, many of the mailbox modules (such as mailbox and mhlib) are read-only, but they should provide a good starting point. > I also look for some existing mail client, written in python > which wud serve my cause. Mahogany Mail isn't written in Python, but it uses wxWidgets and has an embedded Python interpreter. A quick Google for "python email client" (sans quotes) revealed the following useful links: http://sourceforge.net/projects/usablemail/ http://mail.python.org/pipermail/python-list/2003-August/177139.html -Michael From python at rcn.com Mon Aug 1 00:38:36 2005 From: python at rcn.com (Raymond Hettinger) Date: 31 Jul 2005 21:38:36 -0700 Subject: python-dev summary for 2005-07-01 to 2005-07-15 References: Message-ID: <1122871116.841646.147910@g43g2000cwa.googlegroups.com> > This is the seventh summary written by the python-dev summary cabal of > Steve Bethard, Tim Lesher, and Tony Meyer. Thanks guys. The work is excellent and appreciated. Raymond From james.kew at gmail.com Thu Aug 4 02:58:27 2005 From: james.kew at gmail.com (James Kew) Date: Wed, 3 Aug 2005 23:58:27 -0700 Subject: COM makepy problem References: Message-ID: "Alexander Eisenhuth" wrote in message news:dcqj38$abr$1 at online.de... > ActivePython 2.4.1 > Windows XP > > I write a COM Server in VC++ 6.0 using ATL. So far so good. While I > develop I got sometimes strange behaviour with makepy utility. Today > again. :-( > > SyntaxError: invalid syntax I've had the same problems; this pywin32 bug describes it: http://sourceforge.net/tracker/index.php?func=detail&aid=1166627&group_id=78018&atid=551954 I've found no way to avoid it except by downgrading to Python 2.4. James From brian at sweetapp.com Thu Aug 11 09:42:20 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 11 Aug 2005 15:42:20 +0200 Subject: What are modules really for? In-Reply-To: <42F9BC7D.1050300@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <42FB55BC.70608@sweetapp.com> N.Davis wrote: > Functions existing in a module? Surely if "everything is an object" > (OK thats Java-talk but supposedly Python will eventually follow this > too) There is a difference between everything being an object and everything being an instance of a class. In Python, every runtime entity is an object but not everything is a class instance. In Java, there are runtime-accessable entities that are neither objects nor class instances. > then there should be nothing in a module thats not part of a class. Even > a static method is simply a class function that operates on the > "collection of all instances" rather than a single instance. Really? What instances do the static methods in the Java Math class operate on? Not Math instances, of course. So what is the rational for them being packaged in the Math class? Cheers, Brian From tjreedy at udel.edu Wed Aug 17 17:15:45 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Aug 2005 17:15:45 -0400 Subject: Lists of list References: <43032885.7050908@aims.ac.za> Message-ID: "Mohammed Altaj" wrote in message news:43032885.7050908 at aims.ac.za... > I am having problem with delete line if its belong to another one , > example > ['0132442\n', '13\n', '24\n'] > the 2nd and 3rd are already in the first line , how can do this !!! You have a list of strings, not a list of lists. Anyway, I can't understand your question. You will probably have to give more information. tjtr From mensanator at aol.com Tue Aug 30 01:32:40 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 29 Aug 2005 22:32:40 -0700 Subject: trictionary? In-Reply-To: <43138b58.98701114@news.oz.net> References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> <1125280480.602131.269670@g49g2000cwa.googlegroups.com> <43138b58.98701114@news.oz.net> Message-ID: <1125379960.440081.17580@g43g2000cwa.googlegroups.com> Bengt Richter wrote: > On 28 Aug 2005 18:54:40 -0700, "mensanator at aol.com" wrote: > > >Steven Bethard wrote: > >> Adam Tomjack wrote: > >> > Steven Bethard wrote: > >> > ... > >> >> Using a two element list to store a pair of counts has a bad code > >> >> smell to me. > >> > ... > >> > > >> > Why is that? > >> > >> Note that "code smell"[1] doesn't mean that something is actually wrong, > >> just that it might be. In Python, pairs are usually handled with > >> tuples[2], but tuples would be inconvenient in this case, since the > >> first value must be modified. Declaring a class with two attributes as > >> you suggested is often a good substitute, but if the OP's code is really > >> what it looks like, I get another code smell because declaring a class > >> to be used by only 10 lines of code seems like overkill. > >> > >> I also get a code smell from a dict holding two-element lists because > >> I've been writing in Python and answering questions on the Python-list > >> for a couple of years now, and I've never needed one yet. ;-) > >> > >> STeVe > >> > >> [1]http://en.wikipedia.org/wiki/Code_smell > >> [2]http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types > > > >Could you do me a favor and see what this smells like? > > > >I put some data in a csv file (with headers) and this will > >bring it in quite simply as a dictionary with [names] as > >keys and an attribute dictionary as the value. > > > >py_monsters.csv: > > > >name,hardiness,agility,friend,courage,room,weight,special_def_odds,armor,weapon,odds,dice,side,hits,reaction,desc > >PIRATE,5,20,0,10,26,300,0,0,11,60,1,10,0,"not met",You see a man with a > >beard and a brass ring in his ear. He is wearing clothes made of silk > >and is wielding a very fancily engraved sword. > > > > > >import csv > >temp1 = [] > >temp2 = [] > >reader = csv.reader(file(r"py_monsters.csv")) > >for rec in reader: > > temp1.append(rec) > >for i in temp1[1:]: > > temp2.append((i[0],dict(zip(temp1[0][1:],i[1:])))) > >monsters = dict(temp2) > > > >This gives me what I want > > > >[('PIRATE', {'reaction': 'not met', > >'agility': '20', > >'room': '26', > >'weight': '300', > >'armor': '0', > >'weapon': '11', > >'hits': '0', > >'side': '10', > >'special_def_odds': '0', > >'courage': '10', > >'hardiness': '5', > >'desc': 'You see a man with a beard and a brass ring in his ear. > >He is wearing clothes made of silk and is wielding a very fancily > >engraved sword.', > >'odds': '60', > >'friend': '0', > >'dice': '1'})] > > > >so that I can now write code like > > > >if monsters['PIRATE']['reaction']=='not met': > > print monsters['PIRATE']['desc'] > > I think if the field names are legal python names, I would rather write that 'if ...' > without all that line noise ;-) E.g., using simple classes (and effectively using > their attribute instance dicts essentially the way you used raw dicts), you could write > > if monsters.PIRATE.reaction == 'not met': > print monsters.PIRATE.desc > > Also, if the reaction, agility, etc list is fixed, you could use __slots__ for > better efficiency. Also, your __init__ method for the latter could convert > strings to ints for handier use later (unless csv already does that in the mode > you are using). No, it doesn't as I found out shortly after posting that. What was I thinking? I've got it fixed for the moment, but that idea of classes sounds interesting. > > From the above code I infer that you can do define the requisite classes, so > I'll leave it to you ;-) Guess I'll have to actually start reading the manuals. > Note that attribute access opens the door to having > default values as class variables, and using properties to retrieve dynamically > calculated values by name. If you are not familiar with those aspects of classes, > your progammer.agility value can increase markedly with a little study ;-) > > E.g., a name like monsters.random_elf could live right > alongside PIRATE and return one a randomly selected elf from a an internal list > of elves or via random selection from a list of elf names defined at the same > level as PIRATE, etc. etc. You could also dynamically configure these guys > according to distance to food and time since last meal, and if you are > carrying food, etc. > > With suitable classes you could put instances in various "spaces" defined > by other classes, that define geometric or social or other interactions. Well, this is a port of The Wonderful World of Eamon, which isn't quite that ambitious, but thanks for the idea about classes. It's one of those many things I just skim past without ever understanding. Now would be a good time to start learning it. > > > > >instead of using stupid index numbers. > > > >But the loader seems to have a kind of perl-like odor to it, > >i.e., next week I won't understand what it does. > > > If you have to do something tricky, choose names wisely and > comment the non-obvious ;-) > > Regards, > Bengt Richter From nicolas.couture at gmail.com Mon Aug 29 16:23:18 2005 From: nicolas.couture at gmail.com (Nicolas Couture) Date: 29 Aug 2005 13:23:18 -0700 Subject: Basic Server/Client socket pair not working In-Reply-To: References: Message-ID: <1125346998.655741.248830@z14g2000cwz.googlegroups.com> Michael Goettsche wrote: > Hi there, > > I'm trying to write a simple server/client example. The client should be able > to send text to the server and the server should distribute the text to all > connected clients. However, it seems that only the first entered text is sent > and received. When I then get prompted for input again and press return, > nothing gets back to me. Any hints on what I have done would be very much > appreciated! > > Here's my code: > > ############ SERVER ########## > import socket > import select > > mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > mySocket.bind(('', 11111)) > mySocket.listen(1) > > clientlist = [] > > while True: > connection, details = mySocket.accept() > print 'We have opened a connection with', details > clientlist.append(connection) > readable = select.select(clientlist, [], []) > msg = '' > for i in readable[0]: for i in readable: > while len(msg) < 1024: > chunk = i.recv(1024 - len(msg)) > msg = msg + chunk > > for i in clientlist: > totalsent = 0 > while totalsent < 1024: > sent = i.send(msg) > totalsent = totalsent + sent > > ############## CLIENT ################ > import socket > import select > > socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > socket.connect(("127.0.0.1", 11111)) > > while True: > text = raw_input("Du bist an der Reihe") > text = text + ((1024 - len(text)) * ".") > totalsent = 0 > while totalsent < len(text): > sent = socket.send(text) > totalsent = totalsent + sent > > msg = '' > while len(msg) < 1024: > chunk = socket.recv(1024 - len(msg)) > msg = msg + chunk > > print msg From mwh at python.net Thu Aug 11 08:29:28 2005 From: mwh at python.net (Michael Hudson) Date: Thu, 11 Aug 2005 12:29:28 GMT Subject: signals (again) References: <1123713622.727375.206270@f14g2000cwb.googlegroups.com> Message-ID: "bill" writes: > I see this (or similar) question occasionally looking back through the > archive, but haven't yet seen a definitive answer, so I'm going to ask > it again. > > Consider the following: > > while True: > do_something_to_files_in_directory(fd) > fcntl(fd, F_NOTFIY, DN_CREATE) > signal.pause() > > > How do you deal with the signal that occurs after the fcntl and before > the pause? I don't think you can, sorry. Cheers, mwh -- Get out your salt shakers folks, this one's going to take more than one grain. -- Ator in an Ars Technica news item From martin at v.loewis.de Sun Aug 21 03:25:19 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 21 Aug 2005 09:25:19 +0200 Subject: pythonXX.dll size: please split CJK codecs out In-Reply-To: References: Message-ID: <43082c5f$0$31577$9b622d9e@news.freenet.de> Giovanni Bajo wrote: > I don't think I fully understand the reason why additional .pyd modules were > built into the .dll. OTOH, this does not help anyone, since: The reason is simple: a single DLL is easier to maintain. You only need to add the new files to the VC project, edit config.c, and be done. No new project to create for N different configurations, no messing with the MSI builder. In addition, having everything in a single DLL speeds up Python startup a little, since less file searching is necessary. > Can we at least undo this unfortunate move in time for 2.5? I would be grateful > if *at least* the CJK codecs (which are like 1Mb big) are splitted out of > python25.dll. IMHO, I would prefer having *more* granularity, rather than > *less*. If somebody would formulate a policy (i.e. conditions under which modules go into python2x.dll, vs. going into separate files), I'm willing to implement it. This policy should best be formulated in a PEP. The policy should be flexible wrt. to future changes. I.e. it should *not* say "do everything as in Python 2.3", because this means I would have to rip off the modules added after 2.3 entirely (i.e. not ship them at all). Instead, the policy should give clear guidance even for modules that are not yet developed. It should be a PEP, so that people can comment. For example, I think I would be -1 on a policy "make python2x.dll as minimal as possible, containing only modules that are absolutely needed for startup". Regards, Martin From paul.sherwood at gmail.com Wed Aug 17 08:00:52 2005 From: paul.sherwood at gmail.com (paul.sherwood at gmail.com) Date: 17 Aug 2005 05:00:52 -0700 Subject: Iterparse and ElementTree confusion In-Reply-To: <1124269934.194818.51940@f14g2000cwb.googlegroups.com> References: <1124269934.194818.51940@f14g2000cwb.googlegroups.com> Message-ID: <1124280052.498229.46110@g47g2000cwa.googlegroups.com> Further to the above.... I pass my found element 'Product' to ElementTree's handy print all function def print_all(element): root = element #Create an iterator iter = root.getiterator() #Iterate for element in iter: #First the element tag name print "Element:", element.tag #Next the attributes (available on the instance itself using #the Python dictionary protocol if element.keys(): print "\tAttributes:" for name, value in element.items(): print "\t\tName: '%s', Value: '%s'"%(name, value) #Next the child elements and text print "\tChildren:" #Text that precedes all child elements (may be None) if element.text: text = element.text text = len(text) > 40 and text[:40] + "..." or text print "\t\tText:", repr(text) if element.getchildren(): #Can also use: "for child in element.getchildren():" for child in element: #Child element tag name print "\t\tElement", child.tag #The "tail" on each child element consists of the text #that comes after it in the parent element content, but #before its next sibling. if child.tail: text = child.tail text = len(text) > 40 and text[:40] + "..." or text print "\t\tText:", repr(text) if the element i pass to the above is from root = ElementTree(file='somefile.xml') iter = root.getiterator() #Iterate for element in iter: if element.tag == 'Product': print_all(element) I print all of my required element's attributes, children, children's children, etc However if i pass the element i get from iterparse for event, elem in iterparse(filename): if elem.tag == "Products": print_all(elem) else: elem.clear() i only get the attributes for and a list of its children, no further iteration into the children and the children's children what am i missing? From richard at nospam.com Sat Aug 6 08:22:22 2005 From: richard at nospam.com (Richard Townsend) Date: Sat, 6 Aug 2005 13:22:22 +0100 Subject: Putting function references in a Queue Message-ID: <1mh1u4qoeju2f.1suxwcnapp086$.dlg@40tude.net> I've been experimenting putting a reference to a function into a Queue object and was wondering what actually gets put in the Queue - is it the function's code object? If I read from the Queue in a different module, it appears that I don't need to import the module that defines the function - or any module that it uses - is this generally true, or are there some conditions to be aware of? The scenario I'm working on has child threads doing some tasks and then sending back tuples (done, function, args, kwargs) via the Queue, to be called in the main thread. The Python code is ultimately embedded in a C/Motif app. -- Richard From nomysterymeat at hotmail.com Thu Aug 4 05:02:14 2005 From: nomysterymeat at hotmail.com (import newbie) Date: 4 Aug 2005 02:02:14 -0700 Subject: Idiots guide to fonts with tKinter Message-ID: <1123146134.391156.258760@g43g2000cwa.googlegroups.com> Hi all, I'm a programming dabbler trying learn Python, and I've got a few questions. Mainly: Where can I find a good open-source library or tutorial (preferably free) that explains how to easily manipulate text in a tKinter window? Basically, I want to be able to do anything that HTML can do (or close to it) but without the HTML. :-) My "newbie dream project" is to piece together a functional, WYSIWYG text editor that can handle at least three fonts: Times New Roman, Arial and Courier (bold, italics and underlined). I know, I know. That's pretty ambitious. But that's my goal for Python. So....what's the easiest way to get there? What steps should I take? I'm not in any rush, I just want some help along the way... From clever.developer at gmail.com Wed Aug 24 15:18:45 2005 From: clever.developer at gmail.com (Subir) Date: 24 Aug 2005 12:18:45 -0700 Subject: Exploring outlook using python Message-ID: <1124911125.270274.291090@g47g2000cwa.googlegroups.com> Hi, I am new to this group. I am trying to build an application to see all the contents of the outlook accounts (USING MAPI). Does anyone has any information regarding this ? From spam.csubich+block at block.subich.spam.com Tue Aug 9 13:39:38 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 13:39:38 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: <0S5Ke.5236$3p.2192@bignews3.bellsouth.net> Dennis Lee Bieber wrote: > In a more simplistic view, I'd reverse the phrasing... The name > "x" is assigned to the object "y" (implying it is no longer attached to > whatever used to have the name) No, because that'd imply that the object 'y' somehow keeps track of the names assigned to it, which is only true from a refcount perspective -- and only on some Python implementations at that. The object is the property of the name, not vice versa. From eurleif at ecritters.biz Sat Aug 20 15:22:01 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 20 Aug 2005 19:22:01 GMT Subject: Sandboxes In-Reply-To: References: Message-ID: 42 wrote: > I was wondering if it would be effective to pre-parse incoming scripts > and reject those containing "import"? getattr(__builtins__, '__imp' + 'ort__')('dangerousmodule') From http Tue Aug 30 04:34:32 2005 From: http (Paul Rubin) Date: 30 Aug 2005 01:34:32 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> Message-ID: <7xpsrvhlgn.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > > Really it's x[-1]'s behavior that should go, not find/rfind. > > I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely > useful, especially when 'x' is an expression instead of a name. There are other abbreviations possible, for example the one in the proposed PEP at the beginning of this thread. > But even > if -1 were not a legal subscript, I would still consider it a design error > for Python to mistype a non-numeric singleton indicator as an int. OK, .find should return None if the string is not found. From haircut at gmail.com Wed Aug 31 17:32:23 2005 From: haircut at gmail.com (Adam Monsen) Date: 31 Aug 2005 14:32:23 -0700 Subject: "zoning" a naive datetime object / daylight savings Message-ID: <1125523943.582080.101730@f14g2000cwb.googlegroups.com> Say I have the following datetime[1] object: >>> from datetime import datetime >>> d = datetime(2005, 8, 10, 15, 43) I happen to know this is a local time from the Netherlands[2], so I assume the tzinfo (if it were present) should indicate Central European Summer Time[3] ("Summer" indicates daylight savings). How do I convert this date/time information to UTC? Using pytz[4], it appears that I should be able to do the following: >>> from datetime import datetime >>> from pytz import timezone >>> Netherlands = timezone('Europe/Paris') >>> d = datetime(2005, 8, 10, 15, 43).replace(tzinfo=Netherlands) But this object has unexpected timezone information, and converts to UTC by losing 9 minutes instead of 2 hours! >>> d.tzinfo >>> d.astimezone(timezone('UTC')) datetime.datetime(2005, 8, 10, 15, 34, tzinfo=) What I would *expect* to see is this: >>> d.tzinfo >>> d.astimezone(timezone('UTC')) datetime.datetime(2005, 8, 10, 13, 43, tzinfo=) Any pointers? I feel like pytz/python should be smart enough to know that since the date/time is 15:43 on August 10th, 2005 in the Europe/Paris timezone that daylight savings is in effect, and the equivalent UTC datetime object should contain a time two hours prior. At least, that's what I like to happen. Also, anyone know if there is a more appropriate choice for timezone than "Europe/Paris" for times in the Netherlands? Thank you, -Adam References: 1. http://docs.python.org/lib/datetime-datetime.html 2. http://en.wikipedia.org/wiki/Netherlands 3. http://en.wikipedia.org/wiki/Central_European_Time 4. http://pytz.sf.net -- Adam Monsen http://adammonsen.com/ From noreply at gcgroup.net Wed Aug 31 23:14:46 2005 From: noreply at gcgroup.net (William Gill) Date: Thu, 01 Sep 2005 03:14:46 GMT Subject: graphical or flow charting design aid for python class development? In-Reply-To: <1125517510.138456.175480@z14g2000cwz.googlegroups.com> References: <8ckRe.3276$v83.327@newssvr33.news.prodigy.com> <1125517510.138456.175480@z14g2000cwz.googlegroups.com> Message-ID: gene tani wrote: > Have you looked at class browser module? Not the graphical tool you're > looking for, but maybe a good start No, it's not graphical, but it looks like I may be able to use it to put together a nice outline, or summary of my modules. It's worth exploring, thanks. Bill > > http://www.python.org/doc/2.0.1/lib/module-pyclbr.html > > William Gill wrote: > >>Being somewhat new to Python, and having a tendency to over complicate >>things in my class design, I was wondering if anyone can suggest a >>simple graphical or flowcharting tool that they use to organize their >>class and program design? Because of a 55 mph head-on accident a few >>years back, I have short term memory problems, so flipping back and >>forth between pages of code is next to impossible for me to keep >>straight. A simple graphical model would allow me to 'see' everything >>in one view, and better organize my resulting code. I have had limited >>success using pydoc to view my classes, but it's not really much help in >>development, just review, and sometimes there is too much info. >> >>I have used editors for other languages that allow the view to expand >>and collapse functions/methods (like message threads here on the board), >>which help, but I haven't seen anything like this for python. >> >>Thanks for any suggestions. >> >>Bill > > From jgrahn-nntq at algonet.se Thu Aug 4 13:55:04 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 4 Aug 2005 17:55:04 GMT Subject: python ETL References: <1122898017.573173.189620@g14g2000cwa.googlegroups.com> <3l6ukjF119dmqU1@individual.net> Message-ID: On Mon, 01 Aug 2005 10:49:36 -0500, Paul Watson wrote: > arielgr at gmail.com wrote: >> Hi, >> My company is involved in the development of many data marts and >> data-warehouses, and I currently looking into migrating our old set of >> tools (written in Korn) to a new, more dynamic and robust one. ... > However, I would have to assume that if homebrew shell scripts have been > doing the work adequately, then the marts and warehouses are not very > large and the datasets are primarily text rather than binary. > > If this is the case and you are only seeking incremental improvement, > then Python would be a very good choice. Perl would also do the job. > Just about any language would work. Yes, there are many reasons to > choose Python. However, you would have to build any scalability and > metadata management. > > If you seek a radical improvement, it is available, but I do not know of > any free tools that will do it. A question like this will probably not > be answered in a newsgroup post or even the exchange of a few emails. > > Choosing an effective tool for the organization is not a trivial > process. It requires knowledge of both the tools and the organization's > methodologies and processes. If you do not have staff who can do this, > most companies find it is much cheaper and faster to pay someone who > does know (a consultant) to assist them in assessing their requirements, > tool selection, and forming an implementation plan. But remember: sometimes, a bunch of shell scripts or a Python script is the right tool for the problem. Sometimes, I think a bunch of shell scripts is the right tool for a lot of the problems people throw XMLthis, XMLthat, .NET, SQL servers, consultants and money at. There is no real reason (with the little information we have[1]) to believe that the original poster is making his employer a disservice by looking at doing things himself, in plain old Python, instread of letting someome tear down and rebuild whatever workflow/methodology/process stuff they have right now. /Jorgen [1] Unless "ETL" and "data mart" carry some deep meaning which I've missed, that is. -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From mwm at mired.org Thu Aug 11 19:13:10 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 11 Aug 2005 19:13:10 -0400 Subject: Python supports LSP, does it? References: Message-ID: <86pssk6pa1.fsf@bhuda.mired.org> Gregory Bond writes: > phil hunt wrote: >> Let q(x) be a property provable about objects x of type T. Then >> q(y) should be true for objects y of type S where S is a subtype of T >> To me, this is nonsense. Under this definition any subtype must >> behave the same as its parent type, becausde if it doesn't there >> will be some q(y) that are different to q(x). > > Not necessarily..... the set of operations on y could be a superset of > the set of operations on x. So you could have q(y) == q(x) (for all q > applicable to x) but there could be w(y) that has no w(x). In C++ > terms, this implies no virtual functions. No, it doesn't imply no virtual functions. It just restrains their behavior severely. You do have to agree that you can't prove things about code that raises exceptions, though. To deal with that in q(x), you provide a domain for x over which q(x) doesn't raise exceptions. You can then implement a subclass that overrides methods involved in q(x), so long as they behave the same for all x. However, for some y not in x, q(y) may now be a provable property rather than an exception. For instance, a class that has a method that takes the square root of an argument could have properties that can only be proven for non-complex values of that argument. A subclass could extend the method to deal with complex values for that argument without violating the LSP. > Which is not to say that I'm disagreeing with your basic point: > insisting on q(y) == q(x) for all q will greatly limit your use of > polymorphism, unless you are 'sensible' (or perhaps what a > mathematician would call 'loose') about how you define your "q"s! Well, insisting that all existing program remain correct in the face of introducing new types will greatly limit your use of polymorphism. The LSP is more strict than that. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steven.bethard at gmail.com Mon Aug 29 13:03:22 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 29 Aug 2005 11:03:22 -0600 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <7xslwwjsft.fsf@ruckus.brouhaha.com> Message-ID: Antoon Pardon wrote: > I think a properly implented find is better than an index. See the current thread in python-dev[1], which proposes a new method, str.partition(). I believe that Raymond Hettinger has shown that almost all uses of str.find() can be more clearly be represented with his proposed function. STeVe [1]http://mail.python.org/pipermail/python-dev/2005-August/055781.html From cyril.bazin at gmail.com Thu Aug 4 19:07:34 2005 From: cyril.bazin at gmail.com (Cyril Bazin) Date: Fri, 5 Aug 2005 01:07:34 +0200 Subject: Parallel arithmetic? In-Reply-To: <7xll3h72av.fsf@ruckus.brouhaha.com> References: <42f298d6$1_5@alt.athenanews.com> <7xll3h72av.fsf@ruckus.brouhaha.com> Message-ID: Hello, I propose 3 solutions. If someone have time to waste, he can make a benchmark to know which is the fastest and give us the results on the list. Solution 1: import itertools c = [a_i-b_i for a_i, b_i in itertools.izip(a, b)] Solution 2: c = map(operator.sub, a, b) #"map" will be removed from the next versions of python. So, it's not a good solution. Solution 3: import itertools c = list(itertools.imap(operator.sub, a, b)) These solutions give you a list. Depending on your usage, an iterator can be better. Cyril On 04 Aug 2005 15:41:28 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > > "Terrance N. Phillip" writes: > > Given a and b, two equal length lists of integers, I want c to be > > [a1-b1, a2-b2, ... , an-bn]. > > c = [a[i] - b[i] for i in xrange(len(a))] > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From renting at astron.nl Fri Aug 26 04:48:26 2005 From: renting at astron.nl (Adriaan Renting) Date: Fri, 26 Aug 2005 10:48:26 +0200 Subject: variable hell Message-ID: I was responding to rafi's suggestion, I had not received the "exec 'a%s = %s' % (count,count)" response yet at that time. The "exec 'a%s = %s' % (count,value)" works fine. >Not in my Python. > >---snip--- > >why using the eval? > >exec ('a%s=%s' % (count, value)) > >should be fine > >-- >rafi --- I appologize for any top-posting, and improper inlining, I'm using groupwise --- >>>"Martin v. L?wis" 08/26/05 10:19 am >>> Adriaan Renting wrote: >Not in my Python. > > >>>>for count in range(0, 10): > >... value = count >... exec("'a%s=%s' % (count, value)") >... > >>>>dir() > >['__builtins__', '__doc__', '__name__', 'count', 'value'] You did not copy the suggestion properly: >>>for count in range(0, 10): ... exec 'a%s = %s' % (count,count) ... >>>dir() ['__builtins__', '__doc__', '__file__', '__name__', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'count'] >>>a5 5 (you can put additional parentheses around the string, but not additional quotation marks) Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list From spam.csubich+block at block.subich.spam.com Tue Aug 9 19:55:26 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 19:55:26 -0400 Subject: Does any one recognize this binary data storage format In-Reply-To: <11fi98edg5mha3f@corp.supernews.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> Message-ID: Grant Edwards wrote: > That would just be sick. I can't imagine anybody on an 8-bit > CPU using FP for a phone number. Nobody on an 8-bit CPU would have a FPU, so I'll guarantee that this is done using only 8 or 16-bit (probably 8) integer math. From godoy at ieee.org Wed Aug 17 20:06:36 2005 From: godoy at ieee.org (Jorge Godoy) Date: Wed, 17 Aug 2005 21:06:36 -0300 Subject: Moinmoin config References: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> Message-ID: <620dt2-fmu.ln1@strongwill.g2ctech> Mark wrote: > Hi, > > I have Moinmoin 1.3.4 installed and working on Linux RHEL3.0. However, > all screen elements are lined up on the left hand side. How can I get > it displayed like the wiki at: Mark, Mine looks like yours when I have problems with some Apache process. I haven't tracked the problem down yet, but it works perfectly with 2.0.53, but it doesn't work with Apache 2.0.54 on a SuSE 9.3 Professional box. I have the following packages installed: apache2-2.0.53-9.2 apache2-doc-2.0.53-9 apache2-example-pages-2.0.53-9 apache2-mod_perl-2.0.0-4 apache2-mod_php4-4.3.10-14.6 apache2-mod_python-3.1.3-42 apache2-mod_ruby-1.2.4-3 apache2-prefork-2.0.53-9.2 I hope it helps. Be seeing you, -- Jorge Godoy From polytechnique at gmail.com Sat Aug 20 08:22:25 2005 From: polytechnique at gmail.com (DENG) Date: 20 Aug 2005 05:22:25 -0700 Subject: python html In-Reply-To: <1124461883.116486.44570@o13g2000cwo.googlegroups.com> References: <1124461883.116486.44570@o13g2000cwo.googlegroups.com> Message-ID: <1124540545.510748.168350@g43g2000cwa.googlegroups.com> try this http://miex.tigris.org i wrote this for checking bad html, correct them and optimize them From luismgz at gmail.com Thu Aug 4 22:40:59 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 4 Aug 2005 19:40:59 -0700 Subject: Py: a very dangerous language In-Reply-To: References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> Message-ID: <1123209659.123369.286840@f14g2000cwb.googlegroups.com> This is great! It's absolutely useless, like a real therapist, but it's free! From zen19725 at zen.co.uk Wed Aug 3 08:50:26 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 13:50:26 +0100 Subject: Art of Unit Testing References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: On Tue, 02 Aug 2005 17:18:51 -0400, Peter Hansen wrote: > >If you're going to quote XP rules of thumb, the tests should be >independent and very fast, and if you have a setup code that is taking a >long time, it's likely a "code smell" of some kind, and you should be >fixing the design which prevents you writing these tests with minimal >and quick setup. Are these really like "acceptance" tests? If they >were unit tests, they should take only a few minutes to run, total, Eek! Seconds, more like. -- Email: zen19725 at zen dot co dot uk From gene.tani at gmail.com Fri Aug 12 18:42:22 2005 From: gene.tani at gmail.com (gene tani) Date: 12 Aug 2005 15:42:22 -0700 Subject: Jargons of Info Tech industry In-Reply-To: <864q9uzwin.fsf@drjekyll.mkbuelow.net> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <864q9uzwin.fsf@drjekyll.mkbuelow.net> Message-ID: <1123886542.867055.302560@f14g2000cwb.googlegroups.com> the other canonical responses: - killfile killfile killfile - nothing to see here ... keep moving - don't cross-post your replies, don't rile the perl users. From john at castleamber.com Fri Aug 26 21:51:21 2005 From: john at castleamber.com (John Bokma) Date: 27 Aug 2005 01:51:21 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> <3n8ddiFbhg7U1@individual.net> <8664tsw4y9.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > John Bokma writes: >> It's time consuming because there is (yet) no need for it. When I >> started to use Usenet there where only a handful of clients (IIRC), nn >> and another one (rn?) are the only ones that I can recall. > > By the time nn was out, there were a number of radically diffrent > alternatives. The original news client (not NNTP - it predated that) > was readnews. rn was the first alternative to gain any popularity. By > the time it came out, there were alterntiave curses-based readers like > notes and vnews. By the time nn came out, there were even X-based news > readers available like xrn and xvnews. I recall something like pine? (or was that mail, and was there something pine related for usenet?) > It may be that the site you were at only offered a few readers. Probably more correct: I now and then used telnet to connect, so uhm.. no X. And more important, I didn't look further :-) > But > that's a different issue. > > All of this is from memory, of course - and may well be wrong. Those were the days, thanks. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From bokr at oz.net Tue Aug 9 13:17:37 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 09 Aug 2005 17:17:37 GMT Subject: namespaces References: <42EC9690.2040301@tiscali.it> <42ED9175.1050006@REMOVEMEcyber.com.au> <7xzms29ucn.fsf@ruckus.brouhaha.com> Message-ID: <42f8e1b5.1014771994@news.oz.net> On 31 Jul 2005 21:03:36 -0700, Paul Rubin wrote: >Steven D'Aprano writes: >> Most languages can create self-modifying code. That's not the >> question. The question is whether developers should write >> self-modifying code, not whether language designers should prohibit it. > >There was no self-modifying code in that closure example. >Self-modifying code means something entirely different. > >Closures are a tried and true technique that are thematic in Lisp >programming (Python tends to use class instances instead). They take >some getting used to, just like, say, recursion. And like almost >anything, they can be abused. But they're a completely legitimate >approach to lots of types of problems. > >See the book "Structure and Interpretation of Computer Programming" >for an intro to programming based on closures. If you are referring to the code that defines translate with a def and also internally defines the same global translate with an internal def that binds globally (because of the global declaration) when it executes, then I agree, translate is not "self"-modifying, but it is self's-global-binding-modifying, which seems like a close cousin to self-modification ;-) Note that the global binding changes after the first execution: >>> def translate( text ): ... import string ... all=string.maketrans('','') ... badcars=all.translate(all,string.letters+string.digits) ... TABLE = string.maketrans(badcars,'_'*len(badcars)) ... global translate ... def translate( text ): ... return text.translate(TABLE) ... return translate( text ) ... >>> dir() ['__builtins__', '__doc__', '__name__', 'translate'] Here is what translate is bound to after the above def: >>> import dis >>> dis.dis(translate) 2 0 LOAD_CONST 0 (None) 3 IMPORT_NAME 0 (string) 6 STORE_FAST 2 (string) 3 9 LOAD_FAST 2 (string) 12 LOAD_ATTR 1 (maketrans) 15 LOAD_CONST 1 ('') 18 LOAD_CONST 1 ('') 21 CALL_FUNCTION 2 24 STORE_FAST 1 (all) 4 27 LOAD_FAST 1 (all) 30 LOAD_ATTR 3 (translate) 33 LOAD_FAST 1 (all) 36 LOAD_FAST 2 (string) 39 LOAD_ATTR 4 (letters) 42 LOAD_FAST 2 (string) 45 LOAD_ATTR 5 (digits) 48 BINARY_ADD 49 CALL_FUNCTION 2 52 STORE_FAST 3 (badcars) 5 55 LOAD_FAST 2 (string) 58 LOAD_ATTR 1 (maketrans) 61 LOAD_FAST 3 (badcars) 64 LOAD_CONST 2 ('_') 67 LOAD_GLOBAL 7 (len) 70 LOAD_FAST 3 (badcars) 73 CALL_FUNCTION 1 76 BINARY_MULTIPLY 77 CALL_FUNCTION 2 80 STORE_DEREF 0 (TABLE) 7 83 LOAD_CLOSURE 0 (TABLE) 86 LOAD_CONST 3 (",line 7>) 89 MAKE_CLOSURE 0 92 STORE_GLOBAL 3 (translate) 9 95 LOAD_GLOBAL 3 (translate) 98 LOAD_FAST 0 (text) 101 CALL_FUNCTION 1 104 RETURN_VALUE Execute once: >>> translate('something') 'something' Now check what translate is bound to: >>> dis.dis(translate) 8 0 LOAD_FAST 0 (text) 3 LOAD_ATTR 1 (translate) 6 LOAD_DEREF 0 (TABLE) 9 CALL_FUNCTION 1 12 RETURN_VALUE I.e., the original globally bound translate replaces its global binding with the closure it creates on first execution, and also uses that closure to get the first result, which is a little tricky, I'd say ;-) Regards, Bengt Richter From EP at zomething.com Fri Aug 5 03:08:20 2005 From: EP at zomething.com (EP) Date: Thu, 4 Aug 2005 23:08:20 -0800 Subject: IronPython 0.9 Released In-Reply-To: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> References: <1123008098.834003.22090@g47g2000cwa.googlegroups.com> Message-ID: <20050804230820.1518126954.EP@zomething.com> "Luis M. Gonzalez" Announced: > IronPython 0.9 Released(8/2/2005 10:28:41 AM) > > http://www.microsoft.com/downloads/details.aspx?familyid=cf5ae627-5df1-4f8a-ba8b-d64f0676f43f&displaylang=en > MS website says: """System Requirements * Supported Operating Systems: Windows Server 2003; Windows XP You must install the .NET Framework Version 2.0 Redistributable Package Beta 2 prior to installing IronPython.""" And """Important: You cannot install two different language versions of the .NET Framework on the same machine. Attempting to install a second language version of the .NET Framework will cause the following error to appear: "Setup cannot install Microsoft .NET Framework because another version of the product is already installed." If you are targeting a non-English platform or if you wish to view .NET Framework resources in a different language, you must download the appropriate language version of the .NET Framework language pack.""" So, one has to uninstall their stable .NET Framework to install a beta .NET Framework to try out a beta release of a new Python? Would this not be of concern to folks who actually build ontop of .NET (and want to be sure their current code / applications / tools work)? It is really all or none with MS, isn't it? If the language/application is not ready for prime time, why would someone commit to beta code and a beta framework upon which other applications depend? I may have the wrong perspective on all this, but it really befuddles me. [Bring on PyPy] From fakeaddress at nowhere.org Fri Aug 19 11:37:41 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 19 Aug 2005 15:37:41 GMT Subject: global interpreter lock In-Reply-To: References: Message-ID: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> km wrote: > Hi all, > > is true parallelism possible in python ? or atleast in the > coming versions ? is global interpreter lock a bane in this > context ? No; maybe; and currently, not usually. On a uniprocessor system, the GIL is no problem. On multi- processor/core systems, it's a big loser. -- --Bryan From __peter__ at web.de Fri Aug 12 10:30:41 2005 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Aug 2005 16:30:41 +0200 Subject: Where can be a problem? References: <1123827773.392501.155760@z14g2000cwz.googlegroups.com> <1123853944.966310.23340@g49g2000cwa.googlegroups.com> Message-ID: Lad wrote: > Peter, > I tried exactly this > ######## > import re > Results=[] > data1=' href="detailaspxmember=15016&mode=advert" href="detailaspxmember=15017&mode=advert" ' > ID = re.compile(r'^.*=(\d+)&.*$',re.MULTILINE) > Results=re.findall(ID,data1) > print "Results are= ",Results > ######### > and received > Results are= ['15017'] > > Not all numbers > > What exactly did you get? With /exactly/ this, I get: $ cat lad1.py import re Results=[] data1='' ID = re.compile(r'^.*=(\d+)&.*$',re.MULTILINE) Results=re.findall(ID,data1) print "Results are= ",Results $ python lad1.py File "lad1.py", line 3 data1='''' ID = re.compile(r'^.*=(\d+)&.*$',re.MULTILINE) Results=re.findall(ID,data1) print "Results are= ",Results $ python lad2.py Results are= ['15015', '15016', '15017'] Peter From darkcowherd at gmail.com Wed Aug 3 00:24:56 2005 From: darkcowherd at gmail.com (Dark Cowherd) Date: Wed, 3 Aug 2005 09:54:56 +0530 Subject: Standards not standard In-Reply-To: <86vf2oevxv.fsf@bhuda.mired.org> References: <86vf2oevxv.fsf@bhuda.mired.org> Message-ID: <5f4d3cb505080221241e82f820@mail.gmail.com> > > I really think that the community needs a lot more of STANDARDS not > > a STANDARD GUI > > Standards happen in one of two ways. Either an 800-lb gorrilla > establishes them by fiat, or a group of people interested in having > their code play well together hashes out something after they've all > taken a crack at implementing it. The latter is slowly happening in > the Python community. But it's a slow process. > > -- OK let me talk in specifics instead of abstractions. Lets take a GUI. Consider something like wxGlade or XRCed which generates a XML resource file and then wxPython works from it. Suppose the python community works on defining a standard XML resource file. Then all wrappers for GUI libraries in Python can optionally support this XML resource file. So if you are unfortunate enough to have to develop GUI applications :-) you use the standard XML resource file and pick the wrapper and the toolkit that you like. Then for some reason - you have to switch wrapper or toolkit - you dont have a major crisis, you only have a minor crisis. ;-) Of course the wrappers and toolkits are free to provide additional functionality which the developers using those toolkits may or may not choose to use. I think this is what has happened with the DBAPI 2.0 for e.g. kinterbasdb provides DBAPI 2.0 compliant methods for access to firebird and also other non-standard methods. This is a GOOD THING and my suggestion is that this GOOD THING must propogate into other areas like GUI and the Web Toolkits. -- DarkCowherd From bokr at oz.net Sun Aug 28 00:09:10 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 28 Aug 2005 04:09:10 GMT Subject: overload builtin operator References: <3n61u4F1fg2U1@individual.net> Message-ID: <431116ef.2601201920@news.oz.net> On Thu, 25 Aug 2005 16:12:20 +0200, Reinhold Birkenfeld wrote: >Shaun wrote: >> Hi, >> >> I'm trying to overload the divide operator in python for basic arithmetic. >> eg. 10/2 ... no classes involved. >> >> I am attempting to redefine operator.__div__ as follows: >> >> # my divide function >> def safediv(a,b): >> return ... >> >> # reassign buildin __div__ >> import operator >> operator.__div__ = safediv >> >> The operator.__dict__ seems to be updated OK but the '/' operator still >> calls buildin __div__ > >It won't work that way. You cannot globally modify the behaviour of an operator, >but you can customize how an operator works for your type. > >Consider: > >class safeint(int): > def __div__(self, other): > return safediv(self, other) > >safeint(10)/2 > You are right that you cannot globally modify the behaviour of an operator in the sense the OP seems to be envisioning, but with some trouble I think it would be possible to interfere with the translation of '/' to become 'safediv(, )' by transforming the AST during a custom import process, such that wherever a Div node is found, a CallFunc node is substituted. E.g., for a node like Div((Name('numerator'), Name('denominator'))) substitute another node like CallFunc(Name('safediv'), [Name('numerator'), Name('denominator')], None, None) where the Name('numerator') and Name('denominator') in the latter are actually the Div node's .left and .right, so as to operate on the same args (which can be abitrary expression-representing subtrees). Of course, you probably also want to replace AugAssign(Name('a'), '/=', Name('b')) with Assign([AssName('a', 'OP_ASSIGN')], CallFunc(Name('safediv'), [Name('a'), Name('b')], None, None)) Unfortunately, the AST tree does not seem to be designed to be edited easily wrt _replacing_ nodes found by walking via flattened lists vs. just _using_ them in order. I think I can create special walker that can do replacements of nodes found anywhere, and calling node-type-specific or default supplied callbacks to supply replacements for original nodes passed to them, but this will require a number of specialized visitor methods etc., so I will have to get back to this later. But at least the OP and you nudged me into thinking about AST rewriting again ;-) (also affects my @@sourcedeco ideas ;-) ... this didn't go out due to news server problem, so I'll add some clips from what I did re ast editing: ----< testdiv.py >------------------------------------------------------------------------- def test(): print 1.0/2.0 print 12/3 a=12; b=3 print a/b print 2**a/(b+1) try: print 'print 1/0 =>' print 1/0 except Exception, e: print '%s: %s' %(e.__class__.__name__, e) try: print 'print a/(b*(a-12)) =>' print a/(b*(a-12)) except Exception, e: print '%s: %s' %(e.__class__.__name__, e) try: print 'def foo(x=1/(b-3)): return x =>' def foo(x=1/(b-3)): return x print 'print foo() =>' print foo() except Exception, e: print '%s: %s' %(e.__class__.__name__, e) try: print 'b /= (a-12) =>' b /= (a-12) print 'b after b/=(a-12):', b except Exception, e: print '%s: %s' %(e.__class__.__name__, e) if __name__ == '__main__': test() ------------------------------------------------------------------------------------------- Outputfrom run without conversion of / : 0.5 4 4 1024 print 1/0 => ZeroDivisionError: integer division or modulo by zero print a/(b*(a-12)) => ZeroDivisionError: integer division or modulo by zero def foo(x=1/(b-3)): return x => ZeroDivisionError: integer division or modulo by zero b /= (a-12) => ZeroDivisionError: integer division or modulo by zero ----< import_safediv.py >------------------------------------------------------------------ # import_safediv.py from importast import importast from compiler.ast import Div, CallFunc, Name from compiler.ast import AugAssign, Assign, AssName def safediv(num, den): if den==0: result = 0*num else: result = num/den print 'safediv(%r, %r) => %r'%(num, den, result) return result def div2safediv(divnode): """replace Div nodes with CallFunc nodes calling safediv with same args""" return CallFunc(Name('safediv'),[divnode.left, divnode.right], None, None, divnode.lineno) def divaugass2safediv(auganode): if auganode.op != '/=': return auganode assname =auganode.node.name return Assign([AssName(assname, 'OP_ASSIGN')], CallFunc(Name('safediv'),[Name(assname), auganode.expr], None, None, auganode.lineno)) callbacks = {Div:div2safediv, AugAssign:divaugass2safediv} def import_safediv(modname, verbose=False): return importast(modname, callbacks, verbose) if __name__ == '__main__': import sys modname, args = sys.argv[1], sys.argv[2:] verbose = (args[0:] and args[0]=='-verbose') or False modsafe = import_safediv(modname, verbose) modsafe.safediv = safediv if hasattr(modsafe, 'test'): modsafe.test() ------------------------------------------------------------------------------------------- Result from running the above and specifying testdiv as the module to import and enforce safediv on, and run test() on: safediv(1.0, 2.0) => 0.5 0.5 safediv(12, 3) => 4 4 safediv(12, 3) => 4 4 safediv(4096, 4) => 1024 1024 print 1/0 => safediv(1, 0) => 0 0 print a/(b*(a-12)) => safediv(12, 0) => 0 0 def foo(x=1/(b-3)): return x => safediv(1, 0) => 0 print foo() => 0 b /= (a-12) => safediv(3, 0) => 0 b after b/=(a-12): 0 Note that the exceptions went away ;-) It was much messier than it should have been, and the code is not very efficient, but at least it's a kind of proof of concept ;-) Regards, Bengt Richter From accepted at ukr.net Wed Aug 3 05:24:58 2005 From: accepted at ukr.net (Michael Rybak) Date: Wed, 3 Aug 2005 12:24:58 +0300 Subject: 2-player game, client and server at localhost In-Reply-To: References: Message-ID: <46573572.20050803122458@ukr.net> I was a bit unhappy to read this, because what you describe here is just what I've tried yesterday in my test-game with 2 balls, so if I've pointed that out, you wouldn't have to say I DLB> don't understand threading either, it appears. :'( Thank you very much for putting so much effort in making things clear to me, *this* email of your made everything clear as never. Still I have problems, and hope you still don't mind me asking. Some comments: >> while 1: >> render() >> inp = get_player_input() >> thread.start_new(send_inp, (inp,)) >> thread.start_new(accept_opponents_inp, ()) DLB> You don't understand threading either, it appears. Here you are DLB> starting a new thread for each input you want... and >> while still_no_opponents_input_from_previous_iteration() >> time.sleep(0.05) DLB> You're still focused on a turn based system, it looks like... Now, that's *not* how I'm tending to do it; that's what I was thinking of while trying the turn-based approach, and describing here; Christopher Subich asked how it was done initially, so I brought my hanging system out of shame again, and added something I was thinking about to improve it, while I already realize that's not the way to go - from your previous comprehensive posts. DLB> There should just be AN input thread, started at the very beginning, DLB> and it should just wait for input, then update the global state so DLB> the "update step" can do whatever. As stated above, that's how I'm trying it right now. Still, if doing it turn-base, I would have to create a new thread every time. I have some other questions though - please see below. DLB> Also, recommend you use threading, not thread as the module. Surely will, why? DLB> SERVER DLB> An input thread would look something like: DLB> while True: DLB> data = socket.read() #assumes both clients write to same socket DLB> #otherwise use a select(client_socket_list) DLB> #followed by socket.read for the flagged socket(s) DLB> parse data DLB> lock global DLB> save in global state variables DLB> unlock global Now, few questions. Do I need to time.sleep(0.xxx) in any of these while True: loops, not to overwhelm CPU? I can measure the time at beginning and end of each iteration to make things happen fixed number of times per second, but should I? And another: do I get it right that instead of "lock global" you mean: while global.locked: time.sleep(0.001) lock global And I also wonder how do I make sure that 2 threads don't pass this "while" loop simultaneously and both try locking global. There is a probability, not? Now, for update thread: DLB> That is all DLB> Update thread DLB> while True: DLB> lock global DLB> copy state variables to local DLB> unlock global DLB> compute new world state (check for collisions -- "bullet" hits) DLB> for c in client_list DLB> send world state to c In my yesterday experiment, I have a separate thread for each of 2 clients, and what I do there is: def thr_send_status(player_sock): while 1: t, sub_addr = player_sock.recvfrom(128) #player ready to accept player_sock.sendto(encode_status(g.get_status()), sub_addr) I'm reading 1 byte from client every time before sending new update to him. OK, Ok, I know that's not good, ok. Now, I like your idea much more, where you say we first measure the processing speed of each client, and send data to every client as often as he can process it: DLB> Slow client receives the first at T0, but the last (packet 100) comes in DLB> at T0+60. Fast client receives all packets in T0+10... DLB> It took 60 seconds to receive 10 seconds of data. Client sends DLB> back to server a rate of 6. Other client sends back rate of 1. DLB> Server now uses a modulo function on packet sends... DLB> for c in client DLB> if t mod c.rate = 0 DLB> send current world packet to client Yes, this I great, but what if speed changes? Should I retest this around every 10 seconds? I mean, server sending too much data to a client is ok for server, but very bad for a client, since it starts hanging and loses synchronization, unless I use a timestamp to throw away late states (I think I need to re-read all your previous posts, you've explained about synchronizing already). While thinking about this, I've decided to go the wrong way, and to wait for confirmation from client before sending next pack. Still, it shouldn't slow anything a lot, because client does this: def thr_get_status(self, g, player_sock, player_id): while 1: player_sock.sendto("!", addr) #ready self.local_status = decode_status(player_sock.recvfrom(128)[0]) g.set_status(self.local_status) So they simply exchange data all the time in separate threads, even through separate sockets (not to dispatch the confirmations from different players into corresponding threads via global flags), which makes the "ready" thing ok from speed point of view, but I prefer your way, quoted above, so my question is still valid - do I remeasure speed? I'm also almost sure it's wrong to have separate sockets and threads for each player, you say I should select()/dispatch instead, but I'm afraid of that some *thing* being wrong with select() for Windows. Somehow, I'm doing a lot of thins the wrong way :( Before describing another problem I've encountered, I thought I'd remind you of what my test game is: each player controls it's ball by moving mouse pointer, towards which his ball starts moving; that's it. When I first tried this with threads, 1 client ran nearly perfect. But when running 2 clients via localhost, they eat cpu away, and bad things happen. Now, you see, sending user motions to server appears to be faster (or at least not slower) than getting new status, so, as a result, I have the following picture: I place my pointer somewhere, and the ball runs to it, and then runs a bit beyond it, because by the moment server knows the ball is already at my pointer, client still thinks it's not. Several seconds later, thins "a bit beyond" becomes "a lot beyond", and finally both balls run away from game field, being helpless; seems like I/O thread being much more productive than send_status one? I thought that the reason is my stupid "ready" check before every status update, and removed it. As a result, even single client via local host was very slow, but no artifacts. This all was when I had *no* time.sleeps in the while 1: loops. So I added time.sleep(0.005) to server's send_status loop and to client's send_user_action loop. Things became better, but still balls are spinning around the mouse pointer instead of running under it. Every time client tries moving towards the mouse, it's ball is already at another place at server, and it runs in wrong direction. Obviously, if I have these problems in such a primitive test at localhost, I shouldn't even try running it online with the Snakes :( Thanks again for being this helpful, Dennis, and thank you for your patience! -- Best Regards, Michael Rybak mailto:accepted at ukr.net Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From ed at leafe.com Mon Aug 1 16:12:45 2005 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Aug 2005 16:12:45 -0400 Subject: Wheel-reinvention with Python In-Reply-To: References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> Message-ID: <200508011612.45942.ed@leafe.com> On Monday 01 August 2005 15:21, Mark Roseman wrote: > FWIW, some people may find this page interesting, which gives you an > idea what "standard" Tk looks like on OS X, and then with adopting the > "tile" extension to Tk and a few other tweaks, which is on its way to > becoming a standard part of Tk: > ? ? ? http://wiki.tcl.tk/14522 That's certainly an improvement. But when we reviewed the various toolkits a year and a half ago, we just looked at the standard Tk stuff. -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From pydecker at gmail.com Sun Aug 14 09:29:50 2005 From: pydecker at gmail.com (Peter Decker) Date: Sun, 14 Aug 2005 09:29:50 -0400 Subject: What does the word "quiet" mean in this paragraph? In-Reply-To: <311b5ce105081405453299b71b@mail.gmail.com> References: <311b5ce105081405453299b71b@mail.gmail.com> Message-ID: On 8/14/05, could ildg wrote: > The paragraph is as below, I mark the word quiet with *** ***. > ___________________________________ > One problem with distributed applications is that if no data arrives > over a long period of time, you need to wonder why. On one hand, it > could be that the other program just hasn't had any information to > send recently. On the other hand, the other program could have > crashed. TCP handles this problem by allowing you to send an "Are you > still alive?" message every so often to ***quiet*** connections. The > way is to call setKeepAlive() with a value of true. > ___________________________________ > Please tell me what does the word "quiet" mean, Thank you~ It means that the remote application has sent any data recently: 'if no data arrives over a long period of time'. We commonly say that two programs 'talk' to each other, or that one program 'tells' the other when it has received input. If these programs aren't 'saying' anything, they're considered to be 'quiet'. The paragraph you quoted is concerned with determining why the remote app hasn't 'said' anything in a while: has it crashed, or is it really not getting any data to relay. -- # p.d. From devlai at gmail.com Wed Aug 10 04:30:44 2005 From: devlai at gmail.com (Devan L) Date: 10 Aug 2005 01:30:44 -0700 Subject: sorting question In-Reply-To: References: Message-ID: <1123662644.955191.93570@g47g2000cwa.googlegroups.com> Ksenia Marasanova wrote: > Hi, > > I have a list that contains nodes from a tree. Each node is a class > instance, but I'll use dictionary here to simplify the example. > So the list looks like this: > [ > {'id': 1, > 'name': 'Parent node', > 'ord_number': 1, > 'parent_id': 0, > 'url': '/parentnode/'}, > {'id': 2, > 'name': 'My node', > 'ord_number': 1, > 'parent_id': 1, > 'url': '/parentnode/mynode/'} > ] > > Where 'ord_number' is the "sibling index". It's not always properly > filled in; sometimes it's the same for several siblings, or doesn't > starts with 1. > > I want to sort this list with the following rules: > 1. The parent must always come before the children in the list > 2. Nodes with the same parent must be sorted by 'ord_number' > > The first rule is easy, cause I can use 'url' for it. List with nodes > is coming from the database, so I just do "ORDER BY url". > The second rule is kind of tricky to do in the database. I probably > would need to do something like "ORDER BY > cut_off_lastpart_from_url(url), ord_number". But there seems to be no > native string function in Postgres to do it easily, so I desided to > sort it in Python. > > So I've come up with this: > > def cmp_tree(x, y): > if x['parent_id'] == y['parent_id']: > return cmp(x['ord_number'], y['ord_number']) > else: > return cmp(x['url'], y['url']) > > nodes.sort(cmp_tree) > > but it doesn't work as expected. Apparently I don't have a clue about > how sorting function work :( > > Can anybody help? > > -- > Ksenia class Node: def __init__(self, name, url, order, pid, id): self.name = name self.url = url self.order = order self.pid = pid self.id = id def __repr__(self): return self.url def mycmp(x,y): if x.pid == y.pid: if x.order != y.order: return cmp(x.order,y.order) return cmp(x.url,y.url) return cmp(x.pid,y.pid) a = Node('ham','/test/ham/',1,0,1) b = Node('eggs','/test/ham/eggs/',1,1,2) c = Node('bacon','/test/ham/bacon/',1,1,3) d = Node('spam','/test/ham/bacon/spam/',1,3,4) Does this work for you? I haven't tested it much. From uomart at ihug.co.nz Sat Aug 27 20:37:45 2005 From: uomart at ihug.co.nz (Jon) Date: 27 Aug 2005 17:37:45 -0700 Subject: Automatic language translation Message-ID: <1125189465.485171.18780@g47g2000cwa.googlegroups.com> Does python have a module that will translate between different spoken languages? My python program displays all of its messages in English currently and my boss wants it to default to Korean now. Any ideas how to go about doing this? From pyragine_sraige at freenet.de Wed Aug 10 09:42:28 2005 From: pyragine_sraige at freenet.de (pyragine_sraige at freenet.de) Date: Wed, 10 Aug 2005 15:42:28 +0200 Subject: newbie q: Visualizing py-classes in UML automatically Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- Hi "Py's", is there anyone who has written a kind of converter (?) for visualizing python-classes with "poseidon for uml"? I couldn't find a plug-in-hint(?) on the HP; or am I looking wrong? A good hint to another free tool would be also nice. (I only want to see if I am totally wrong with self-made diagrams.) Sorry for disturbing and thanks for listening, Jana. 1 Million Singles in Ihrer Nahe. Finden Sie Ihren Traumpartner bei Deutschlands beliebtester Partnerboerse: http://singles.freenet.de/index.html?pid=11512 From txdiversity at hotmail.com Tue Aug 23 04:22:31 2005 From: txdiversity at hotmail.com (James) Date: 23 Aug 2005 01:22:31 -0700 Subject: Doubt C and Python In-Reply-To: References: <200508221700.10647.hancock@anansispaceworks.com> Message-ID: <1124785351.793496.93990@o13g2000cwo.googlegroups.com> > Some people with C background use Python instead > of programming in C.why? Becuase it is much more efficient. -James From rkern at ucsd.edu Fri Aug 5 10:22:27 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 05 Aug 2005 07:22:27 -0700 Subject: An editable buffer for the Python shell (similar to '\e' on sql prompts) In-Reply-To: <5a309bd305080507132e1cba43@mail.gmail.com> References: <5a309bd305080507132e1cba43@mail.gmail.com> Message-ID: Steve wrote: > Hi, > When working in the python command shell, I often end up writing more > than 10+ lines of indented code before making a stupid typo. This got > irritating enough for me to do something about it. So, here's an > 'InteractiveConsole with an editable buffer'. > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438813 > > Just thought some one else also would find this useful. See also ipython and pyrepl. http://ipython.scipy.org http://codespeak.net/pyrepl/ -- 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 johnny.karlsson at gmail.com Mon Aug 22 07:34:39 2005 From: johnny.karlsson at gmail.com (johnny.karlsson at gmail.com) Date: 22 Aug 2005 04:34:39 -0700 Subject: sending binary files to a 16 micro controller. Message-ID: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> Hi, I'm working on a project were a need to be able to upload firmware to a microcontroller based Ethernet device. But because of the memory constraints the controller can only handle packages of 300 bytes each time. So therefore the firmware file must be sent in chunks and i need a header in each file describing which part of the file it is I'm sending. Could anyone give me some pointer on how a could accomplish that in python? I'm talking about the client that uploads the software to the device via TCP. Best regards Johnny Karlsson From pink at odahoda.de Sun Aug 28 17:54:33 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Sun, 28 Aug 2005 23:54:33 +0200 Subject: Dynamic image creation for the web... References: Message-ID: Tompa wrote: > Benjamin Niemann odahoda.de> writes: >> You are almost there. > I don't feel so... > >> Your create_image.py does not return anything to the >> browser yet. > Yes, I am aware of that but I do not what to return. > >> First return proper HTTP headers, e.g. >> >> sys.stdout.write('Status: 200 OK\r\n') >> sys.stdout.write('Content-type: image/gif\r\n') >> sys.stdout.write('\r\n') > > Ok, but if possible I'd rather not return anything HTTP/HTML-related from > my create_image.py file. When the browser fetches the images for displaying, it performs just another HTTP request, and you must reply with a valid HTTP response. The Content-type header is the absolute minimum that must always be returned. (IIRC the 'Status' can be omitted, if it's 200). >> Then check the PIL docs to find out, how to output the image to >> sys.stdout (instead of writing to a file). >> > Ok, then I get this: > > from PIL import Image, ImageDraw > import sys > > im = Image.new("P", (600, 400)) > draw = ImageDraw.Draw(im) > draw.rectangle((0, 0) + im.size, fill="blue") > > sys.stdout.write('Status: 200 OK\r\n') > sys.stdout.write('Content-type: image/gif\r\n') > sys.stdout.write('\r\n') > > im.save(sys.stdout, "GIF") > > But this does not work. > I also tested to skip the HTTP-header stuff and just write the gif to > sys.stdout, believing that that would work. But not so... Works perfectly here... What does the error.log of the webserver say? > Hmm, I'm a newbie to Python (as you already probably have noticed ;-) so I > don't know what else I should try. Any hints are welcome! > > /Tompa -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From felix at keyremovethisghost.com Tue Aug 2 21:59:02 2005 From: felix at keyremovethisghost.com (Felix Collins) Date: Wed, 03 Aug 2005 13:59:02 +1200 Subject: HELP:sorting list of outline numbers In-Reply-To: References: Message-ID: Robert Kern wrote: > Felix Collins wrote: > > Use the "key" keyword argument to list.sort(). > > In [1]: outline = ['1.12', '1.1', '1', '1.2'] > > In [2]: outline.sort(key=lambda x: map(int, x.split('.'))) > > In [3]: outline > Out[3]: ['1', '1.1', '1.2', '1.12'] > Is this new in 2.4? I have to use 2.3 as I'm working with Trac. Traceback (most recent call last): File "", line 1, in -toplevel- keys.sort(key=lambda x: map(int, x.split('.'))) TypeError: sort() takes no keyword arguments Thanks Scott and Robert for your quick help. This list is amazing! Regards, Felix From prabapython at yahoo.co.in Sat Aug 6 03:45:30 2005 From: prabapython at yahoo.co.in (praba kar) Date: Sat, 6 Aug 2005 08:45:30 +0100 (BST) Subject: Sample code to build rfc822 mail message building In-Reply-To: Message-ID: <20050806074530.919.qmail@web8404.mail.in.yahoo.com> Dear All, I am new to python world. I have pasted my code which I used it to build rfc822 format mails for webbased mailing system task(which is like to yahoo.com web interface). Now I am asking some suggestions and guidence regarding this below code. Still What way I can improve this code. If anyone find error kindly let me know how to correct it. # This function to handle attachment files def addAttachment(filename,ctype): #mimetypes guesses the type of file and stores it in ctype maintype, subtype = ctype.split('/', 1) if not os.path.exists(filename): return 0 fp = open(filename, 'rb') #open the file if maintype == 'text': #check for maintype value and encode and return according to the # type of file attach = MIMEText(fp.read(),_subtype=subtype) elif maintype == 'message' and subtype == "rfc822": attach = email.message_from_file(fp) attach = MIMEMessage(attach) elif maintype == 'message' and subtype <> "rfc822": attach = email.message_from_file(fp) elif maintype == 'image': attach = MIMEImage(fp.read(),_subtype=subtype) elif maintype == 'audio': attach = MIMEAudio(fp.read(),_subtype=subtype) else: #print maintype, subtype #if it does not equal any of the #above we print to screen and encode and return attach = MIMEBase(maintype, subtype) #the encoded value attach.set_payload(fp.read()) encode_base64(attach) fp.close() filename = os.path.basename(filename) attach.add_header('Content-Disposition', 'attachment',filename=filename) return attach #This function base I try to build email message def create_mail(domain, user, form, from_name): to = cc = bcc = subject = body = '' attachments = [] send_addresses = '' if form.has_key('to'): to = form['to'].value.strip() send_addresses = to if form.has_key('cc'): cc = form['cc'].value.strip() send_addresses = to + ',' + cc if form.has_key('bcc'): bcc = form['bcc'].value.strip() send_addresses = to + ',' + cc + ',' + bcc if form.has_key('subject'): subject = form['subject'].value if form.has_key('body'): body = form['body'].value if form.has_key('attachments[]'): attachments = form.getlist("attachments[]") if not len(attachments) > 0: # This header is for non Multipart message # I want to know reduce below redundant code msg = MIMEBase('text','html') msg['Return-Path'] = user+'@'+domain msg['Date'] = formatdate(localtime=1) msg['Subject'] = subject msg['From'] = from_name msg['To'] = to msg["Cc"] = cc msg.set_payload(body) # Guarantees the message ends in a newline msg.epilogue = '' else: msg = MIMEMultipart() msg['Return-Path'] = user+'@'+domain msg['Date'] = formatdate(localtime=1) msg['Subject'] = subject msg['From'] = from_name msg['To'] = to msg["Cc"] = cc body = MIMEText(body) #Here is the bod msg.attach(body) # Guarantees the message ends in a newline msg.epilogue = '' for eachfile in attachments: row = eachfile.split(':') att_name = row[0] att_type = row[1] filename = domaindir + '/' + domain + '/' + user + '/temp/upload/' + att_name if addAttachment(filename,att_type): attach = addAttachment(filename,att_type) msg.attach(attach) # To send message to all the send_addresses for eachid in send_addresses.split(","): fh = os.popen('/bin/sendmail %s'% (eachid),'w') fh.write(msg.as_string()) fh.close() __________________________________________________________ Free antispam, antivirus and 1GB to save all your messages Only in Yahoo! Mail: http://in.mail.yahoo.com From noreply at gcgroup.net Sun Aug 21 14:28:03 2005 From: noreply at gcgroup.net (William Gill) Date: Sun, 21 Aug 2005 18:28:03 GMT Subject: tkinter text widget question Message-ID: The tkinter text widget uses indexes to identify row:column offsets within the text, but it seems counter intuitive to have to convert row and column integers to a string like "0.1'. It's great that index can take a string, but what about looping through rows and columns? Am I missing a way to use integers directly, or should I create a class that takes the two integers and returns them formatted as the proper string? Thanks Bill From mark at markroseman.com Mon Aug 1 15:26:55 2005 From: mark at markroseman.com (Mark Roseman) Date: Mon, 01 Aug 2005 15:26:55 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <7xd5ozv1ng.fsf@ruckus.brouhaha.com> <7xek9e5ywq.fsf@ruckus.brouhaha.com> Message-ID: > How can I embed a browser in Tk (I mean a real browser, like Mozilla, > Safari, or even Exploder)? At all? On any platform? This has always > been the tradeoff for Tk. Try this as one example: http://wiki.tcl.tk/4094 > Tk is great for learning, easy to write small, basic interfaces, less > great for deploying real world apps with sophisticated interfaces. I've > often felt that Tk was the VB of GUI toolkits: terrific for knocking out > simple stuff, but starts to bite you in the *** when you try to do the > hard stuff. wxPython is the opposite: it has a steeper learning curve, > but once you know it, you can do amazing things. For me, the long term > benefits are far more important to me than how low the startup costs > are. I'd respectfully disagree (having done large, real-world Tk apps). You're right that Tk has a slow learning curve, which makes it easy to knock out simple interfaces really quickly - and generally ones that are not too impressive looking. You can do more sophisticated ones, and ones that blend properly into the platforms you're working on - however, the amount of effort and learning curve increase substantially. This is because you end up needing to do a lot more fiddling, looking at or using any of a large number of add-on packages, etc.). Mark From renting at astron.nl Thu Aug 18 03:04:23 2005 From: renting at astron.nl (Adriaan Renting) Date: Thu, 18 Aug 2005 09:04:23 +0200 Subject: win32pipe.popen3 Message-ID: Well, on Linux I use select first to see if there's something to read. Maybe this works on Windows too? This is my code: fd = os.open(filename, os.O_NONBLOCK) ready = select.select([fd], [], [], 0.25) ## timeout after 0.25 seconds. if fd in ready[0]: text = os.read(fd, 1024) lines = text.split('\n') for line in lines: print line else: print '-' os.close(fd) You can maybe use select.poll too. >>>"Jakob Simon-Gaarde" 08/17/05 7:51 pm >>> Follow-up on a thread from 1999 (see below) Well now it is 2005 and the operating system I'm using is Windows Server 2003, and I can still see that the same problem persists with: win32pipe.popen2() win32pipe.popen3() win32pipe.popen4() while win32pipe.popen() does almost what you want. >>>import win32pipe >>>win32pipe.popen('cmd') >>>r=win32pipe.popen('cmd') >>>r.readline() 'Microsoft Windows XP [Version 5.1.2600]\n' >>>r.readline() '(C) Copyright 1985-2001 Microsoft Corp.\n' >>>r.readline() '\n' >>>r.readline() 'C:\\backup\\TRPython241\\trpython>' Although I think the last readline ought to return None since no carriage return has been issued yet, it is better than popen2,popen3 and popen4, which all just block the parent process. The current behaviour of win32pipe.popen2(), win32pipe.popen3() and win32pipe.popen4() would be acceptable for me if I knew a way to test if there was something ready for reading, but I can't see how to do that test, therfore I don't know when to stop reading from output :( Is there a solution for this, can I poll/test for ready-read on popen3 I/O objects. Best regards Jakob Simon-Gaarde --------------------------- >From a thread in 1999 High Arpard, thanx for help but I got probs with that popen3 under Win95: 'o.readlines()' doesn't return anymore. To find out I checked it line per line: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>import win32pipe >>>i,o,e=win32pipe.popen3('ver', 'b') >>>o.readline() '\015\012' >>>o.readline() 'Windows 95. [Version 4.00.1111]\015\012' >>>o.readline() '\015\012' >>>o.readline() Don't know why, but it never;-) returns. Perhaps it may be a bug in win32pipe, that it doesn't return becourse readline couldn't find CarriageReturn/EOF? I took win32pipe.popen('ver','r') for a better solution. That works fine. greetings, Holger -- http://mail.python.org/mailman/listinfo/python-list From http Thu Aug 4 01:18:05 2005 From: http (Paul Rubin) Date: 03 Aug 2005 22:18:05 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> Message-ID: <7xr7damgaa.fsf@ruckus.brouhaha.com> Mike Meyer writes: > No, it's not a discussion about estimates. The average household in > a G8 country has more computers that don't run Windows - and in fact > don't have GUIs at all - than otherwise. This is a fact of life. Most of those computers aren't programmable in Python ;) From c at cdot.de Tue Aug 2 16:47:31 2005 From: c at cdot.de (Chris) Date: Tue, 02 Aug 2005 22:47:31 +0200 Subject: Printing Docstrings Without Importing In-Reply-To: <1122904223.528701.55420@f14g2000cwb.googlegroups.com> References: <1122746909.441941.226760@o13g2000cwo.googlegroups.com> <42ed90cf.273165611@news.oz.net> <1122904223.528701.55420@f14g2000cwb.googlegroups.com> Message-ID: Fuzzyman wrote: > This seems to scratch several people's itches. As I understand it it is something like generating "pythondoc" like javadoc? Should be pretty easy to develop something a bit more polished than Bengt's solution (or based on it of course) with maybe similar to javadoc framesets for a navigational list etc. But usn't there something like that from the docutils project (I must admit I should have googled for it but have not have the time yet). I was looking for something to but found only epydoc yet with yet another of its own markup, docutils being something like a standard for python (at least that's what I thought) would be really nice for it. chris sorry if i totally misunderstood the question... From spam.csubich+block at block.subich.spam.com Thu Aug 11 02:52:46 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Thu, 11 Aug 2005 02:52:46 -0400 Subject: Unicode regular expressions -- buggy? Message-ID: <8ACKe.1469$Rm3.756@bignews4.bellsouth.net> I don't think the python regular expression module correctly handles combining marks; it gives inconsistent results between equivalent forms of some regular expressions: >>> sys.version '2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]' >>>re.match('\w',unicodedata.normalize('NFD',u'\xf1'),re.UNICODE).group(0) u'n' >>>re.match('\w',unicodedata.normalize('NFC',u'\xf1'),re.UNICODE).group(0) u'\xf1' In the above example, u'\xf1' is n-with-tilde (?). NFC happens to be a no-op, and NFD decomposes it into u'n\u0303', which splits out the tilde as a combining mark. Is this a limitation-by-design, or a bug? If the latter, is it already known/to-be-fixed? From http Tue Aug 30 05:12:22 2005 From: http (Paul Rubin) Date: 30 Aug 2005 02:12:22 -0700 Subject: array of arrays question References: <1125392269.199866.64910@f14g2000cwb.googlegroups.com> Message-ID: <7xd5nvokjt.fsf@ruckus.brouhaha.com> "Meo" writes: > Somebody understand what's going on here? Yes, []*3 gives you three references to the same empty list, not three separate empty lists. You need something like [[] for i in xrange(3)] to get separate lists. Another example: a = [1,2,3] b = a a[0] = 5 print b # prints [5,2,3] Do you understand now? From ameyer2 at yahoo.com Tue Aug 30 19:23:26 2005 From: ameyer2 at yahoo.com (ameyer2 at yahoo.com) Date: 30 Aug 2005 16:23:26 -0700 Subject: Question about threading.Lock().aquire(waitflag) Message-ID: <1125444206.724537.154030@f14g2000cwb.googlegroups.com> It's not clear to me from the Python docs whether waitflag is treated as a boolean or as a number. Running on Windows, I get two different behaviors from the following calls to acquire: aLock = threading.Lock() ... # Thread 0 # This one often succeeds aLock.acquire(1) ... # Thread 1 # When this one would fail in a different thread aLock.acquire(2) but the behaviors aren't what I would expect if waitflag were a timeout value. If the argument to acquire is a true/false flag, the behaviors for values of 1 and 2 ought to be the same. If it's not a true/false flag, what is it? It's not clear to me that it's a timeout value - wait this many seconds and then fail if the lock can't be acquired. What I really need is a timed lock - which I can implement myself by calling acquire(0) and sleeping and looping for some time until it succeeds or times out. But if Python already supports this, I'd rather do it the Python way. Thanks. From onurb at xiludom.gro Mon Aug 22 03:37:55 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 22 Aug 2005 09:37:55 +0200 Subject: Decorator and Metaclasses Documentation In-Reply-To: References: Message-ID: <430980d6$0$4892$626a14ce@news.free.fr> Mike C. Fletcher wrote: (snip) > Though the don't go into extreme detail on decorators (they are > basically syntactic sugar for a particular type of descriptor). > Err... Could you elaborate on this ? Decorators are syntactic sugar for function wrapping, while descriptors are a 'protocol' to hook into attribute lookup, so I don't really see how one can describe the first in terms of the second... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From supercomputer at gmail.com Wed Aug 3 11:37:38 2005 From: supercomputer at gmail.com (supercomputer at gmail.com) Date: 3 Aug 2005 08:37:38 -0700 Subject: MySQL help In-Reply-To: <5jvte1hvuouu4uedcku773gos2nnumpt9p@4ax.com> References: <1122922717.658701.29410@g14g2000cwa.googlegroups.com> <5jvte1hvuouu4uedcku773gos2nnumpt9p@4ax.com> Message-ID: <1123083458.295581.60310@g14g2000cwa.googlegroups.com> Hey Dennis thanks for the tips I haven't had a chance to take another stab at that code yet but I think I may try some of your suggestions. The SQL statements are valid but something doesn't appear to work right I may try and switch them to what you're suggesting and see if that helps with my problem. Thanks, From greg at puyo.cjb.net Mon Aug 22 05:47:10 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 22 Aug 2005 02:47:10 -0700 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: <1124704030.812735.221000@g44g2000cwa.googlegroups.com> I've always accepted the None vs. 0 as a cavaet of the added convenience but I think it's ultimately worth it. Sorry, I didn't want to start a "nothing values evaluate to false" argument. I'll go read python-dev archives a bit and see if there's anything useful for me to know. Thanks From deets at nospam.web.de Tue Aug 23 04:13:14 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Aug 2005 10:13:14 +0200 Subject: What's the difference between built-in func getattr() and normal call of a func of a class In-Reply-To: <1124784437.974574.12480@o13g2000cwo.googlegroups.com> References: <1124784437.974574.12480@o13g2000cwo.googlegroups.com> Message-ID: <3n044rF18pnpkU1@uni-berlin.de> Johnny wrote: > Hi, > > I wonder what is the difference between the built-in function > getattr() and the normal call of a function of a class. Here is the > details: > > getattr( object, name[, default]) > > Return the value of the named attributed of object. name must be a > string. If the string is the name of one of the object's attributes, > the result is the value of that attribute. For example, getattr(x, > 'foobar') is equivalent to x.foobar. If the named attribute does not > exist, default is returned if provided, otherwise AttributeError is > raised. > > Is that to say the only difference between the two is that no > matter the specific function exists or not the built-in func will > always return a value, but "class.function" will not? No, it will only return _always_ a value if you provide a default one. If not, they have the exact same semantics. What you've got here is something usually called "syntactic sugaring" - a specialized syntax that performs certain instructions that _could_ be done by hand - but the concise syntax is (supposedly, and certainly in this case) easier to read/write/understand. There are others - e.g. list comprehensions or a < b < c. Regards, Diez From rlb at hoekstra-uitgeverij.nl Tue Aug 23 11:04:04 2005 From: rlb at hoekstra-uitgeverij.nl (Richard Bos) Date: Tue, 23 Aug 2005 15:04:04 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> Message-ID: <430b3a9d.5547434@news.xs4all.nl> "Mike Schilling" wrote: > "l v" wrote in message > news:1124804082_1011 at spool6-east.superfeed.net... > > Xah Lee wrote: > >> (circa 1996), and email should be text only (anti-MIME, circa 1995), > > > > I think e-mail should be text only. I have both my email and news readers > > set to display in plain text only. It prevents the marketeers and > > spammers from obtaining feedback that my email address is valid. A > > surprising amount of information can be obtained from your computer by > > allowing HTML and all of it's baggage when executing on your computer. > > Phishing comes to my mind first and it works because people click the link > > without looking to see where the link really takes them. > > A formatting-only subset of HTML would be useful for both e-mail and Usenet > posts. Used to be that the formatting-only subset of HTML was called HTML. Used to be that people were wise to itinerant kooks such as the OP. Richard From mwm at mired.org Fri Aug 26 20:33:54 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 26 Aug 2005 20:33:54 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <7xek8h5usm.fsf@ruckus.brouhaha.com> Message-ID: <86mzn4w74d.fsf@bhuda.mired.org> John Bokma writes: > Paul Rubin wrote: > >> Mike Meyer writes: >>> > Another advantage is that evewry internet-enabled computer today >>> > already comes with an HTML renderer (AKA browser) >>> >>> No, they don't. Minimalist Unix distributions don't include a browser >>> by default. I know the BSD's don't, and suspect that gentoo Linux >>> doesn't. >> >> Lynx? > > Emacs? Neither one is installed by default on the systems in question. Both are available via the system packaging tools. fetch is installed on FreeBSD, but all it does is download the contents of a URL - it doesn't render them. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From spammers-go-here at spam.invalid Sat Aug 13 16:56:35 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sat, 13 Aug 2005 16:56:35 -0400 Subject: Using globals with classes References: <42fc2e42$0$18637$14726298@news.sunsite.dk> <42fcd271$1@nntp0.pdx.net> Message-ID: <42fe5e70$0$18640$14726298@news.sunsite.dk> Scott David Daniels wrote: > Madhusudan Singh wrote: >> .... I am using qwtplot to display a running plot : >> > The way I'd normally accomplish this is to separate the setup and use > by defining a class: > How would one enable dynamic autoscaling of the axes ? I am using setAxisAutoScale, and when the application ends, I do get correctly autoscaled axes, but not while the measurement is in progress. From jspoerri+keyword+python.8e28f8+keyword+b582c4.6549c2 at earthlink.net Wed Aug 10 09:51:02 2005 From: jspoerri+keyword+python.8e28f8+keyword+b582c4.6549c2 at earthlink.net (Joshua Spoerri) Date: Wed, 10 Aug 2005 09:51:02 -0400 Subject: mixins that don't down-call? Message-ID: <20050810135102.GA3012@localhost.localdomain> Anybody have an idea for how to do python mixins that don't down-call? Thanks ( Mixins from different vendors might use the same method names for unrelated features, but should continue to work sensibly. It's fine to have one mixin method override another in its "public" interface, but overriding a mixin's internal methods in its "protected" interface should only happen under explicit extension. e.g. def simplyMixin(*classes): c = copy.copy(classes[0]) c.__bases__ += classes[1:] return c() class artist: def draw(self): ... class cowboy: def draw(self): ... def drawAndShoot(): self.draw() ... artisticCowboy = simplyMixin(artist, cowboy)() artisticCowboy.draw() #draw a picture artisticCowboy.drawAndShoot() #take out gun and fire it ) From smitty_one_each at bigfoot.com Wed Aug 24 03:33:38 2005 From: smitty_one_each at bigfoot.com (Chris Smith) Date: Wed, 24 Aug 2005 03:33:38 -0400 Subject: Binary Trees in Python References: Message-ID: <871x4j94bx.fsf@bigfoot.com> >>>>> "[diegueus9]" == [diegueus9] Diego Andr?s Sanabria writes: [diegueus9]> Hello!!! I want know if python have binary trees and [diegueus9]> more? The latest boost, 1.33, says it has a python wrapper for the boost graph library. Boost explicitely states that it's experimental, but my emerge was successful. See http://boost.org -Chris From michael at stroeder.com Thu Aug 4 07:22:39 2005 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 04 Aug 2005 13:22:39 +0200 Subject: Secure email In-Reply-To: <42f1f719$0$11062$e4fe514c@news.xs4all.nl> References: <42f1ecd3$0$11079$e4fe514c@news.xs4all.nl> <42f1f719$0$11062$e4fe514c@news.xs4all.nl> Message-ID: Martin P. Hellwig wrote: > Michael Str?der wrote: > >> Martin P. Hellwig wrote: >> >>> I think you want this more common approach for mail encryption: >>> >>> server: >>> https CGI form --> mail wrapper --> PGP encryption/signing --> send >>> >>> client: >>> recieve mail --> pgp decryption/verification --> read >> >> This would require an additional PGP-plugin for Outlook. Outlook can >> decrypt S/MIME messages out-of-the-box. > > Yes indeed, although I personaly find pgp a bit more elegant your > solution would be the best for the OP. Whether S/MIME or PGP is used depends very much on the security policy the application has to comply with and the rest of the system environment we both know very little about. Therefore I can't see what's more "elegant" with PGP in general and how you can tell what the "best solution" is for the original poster. Ciao, Michael. From gregpinero at gmail.com Mon Aug 8 17:58:08 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Mon, 8 Aug 2005 17:58:08 -0400 Subject: Splitting a string into groups of three characters In-Reply-To: References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: <312cfe2b05080814588fae5db@mail.gmail.com> I guess this question has already been thouroughly answered but here is my version: def split(string,n): outlist=[] for bottom in range(0,len(string),n): top=min(bottom+n,len(string)) outlist.append(string[bottom:top]) return outlist On 8/8/05, William Park wrote: > lemon97 at gmail.com wrote: > > Hi, > > > > Is there a function that split a string into groups, containing an "x" > > amount of characters? > > > > Ex. > > TheFunction("Hello World",3) > > > > Returns: > > > > ['Hell','o W','orl','d'] > > > > > > Any reply would be truly appreciated. > > Look into 're' module. Essentially, split using '...', but return the > separator as well. Then, remove empty items. In Bash shell, you would > do > a="Hello World" > set -- "${a|?...}" # extract '...' separators > pp_collapse # remove null items > printf '{%s}\n' "${@}" > > Translating to Python is left as homework. > > -- > William Park , Toronto, Canada > ThinFlash: Linux thin-client on USB key (flash) drive > http://home.eol.ca/~parkw/thinflash.html > BashDiff: Super Bash shell > http://freshmeat.net/projects/bashdiff/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From bkhl at stp.lingfil.uu.se Mon Aug 1 17:12:09 2005 From: bkhl at stp.lingfil.uu.se (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) Date: Mon, 01 Aug 2005 23:12:09 +0200 Subject: Standard Threads vs Weightless Threads References: <1122887842.555209.208860@o13g2000cwo.googlegroups.com> Message-ID: <87k6j5uzti.fsf@lucien.dreaming> Christopher Subich writes: > the primary benefit (on uniprocessor systems) that if one thread > executes a blocking task (like IO writes) another thread will receive > CPU attention. On multiprocessor systems, of course, the benefit is that threads can run on separate CPUs. This could possibly be addressed by transparently running one OS thread for each CPU, each containing a set of light weight threads, and I hear people are thinking about that for Erlang (light weight processes language extravaganza). In the meanwhile, you can of course solve this by running two separate instances of your program that communicates with each other somehow. Another benefit is that you can have more threads than the limit the OS imposes on you, and they can also be made quite a bit less memory consuming. Some language implementations manages to deal with hundreds of thousands, and in some cases even millions, of threads this way. > They're not in the standard library because implementing microthreads > has thus far required a very large rewrite of the CPython architecture > -- see Stackless Python. Ruby's built-in threading also work something like this (if I understand Stackless Python correctly). (http://www.rubycentral.com/book/tut_threads.html) Personally, though, I think treating treating light weight threads as separate processes (which can only pass messages in between each other, but do not share scope in any way), like Erlang, seems to make dealing with massive concurrency easier. -- Bj?rn Lindstr?m Student of computational linguistics, Uppsala University, Sweden From twic at urchin.earth.li Mon Aug 15 07:50:02 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Mon, 15 Aug 2005 12:50:02 +0100 Subject: Permutation Generator In-Reply-To: References: Message-ID: On Mon, 15 Aug 2005, Matt Hammond wrote: > Just satisfied my curiosity wrt this problem, so I might as well share :-) > >>>> def permute(list): How about: def permutation(l, i): "Makes the ith permutation of the sequence l." # leave out the reverses if you don't care about the order of the permutations l_ = []; l_[:] = l; l_.reverse() m = [] for j in xrange(len(l_)): m.append(l_.pop((i % len(l_)))) i = i / (len(l_) + 1) m.reverse() return m def factorial(n): if (n == 1): return 1 else: return n * factorial((n - 1)) def permute(l): for i in xrange(factorial(len(l))): yield permutation(l, i) >>> for o in permute([1,2,3]): print o ... [1, 2, 3] [1, 3, 2] [2, 3, 1] [2, 1, 3] [3, 1, 2] [3, 2, 1] The thing i like about doing it this way is that you can use permutation(l, i) to make arbitrary permutations on their own, should you ever need to do that. Also, it gives you an easy way to make only the even permutations of a list - just feed even numbers into permutation(l, i) (i think!). This could be useful if you wanted to build an alternating group for some obscure discrete mathematics purpose. tom -- The future is still out there, somewhere. From mwh at python.net Mon Aug 1 08:39:20 2005 From: mwh at python.net (Michael Hudson) Date: Mon, 01 Aug 2005 12:39:20 GMT Subject: Changing interpreter's deafult output/error streams References: Message-ID: "Ira" writes: > OK let me rephrase, > > the standard error stream (and if I'm not mistaken also the one that > PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go > ahead and write the following in python... Ah, OK, I think you're mistaken, and PyErr_Print prints to the C level FILE* stderr (I agree my first post was confusing on this point, sorry about that...). Cheers, mwh -- jemfinch: What's to parse? A numeric code, perhaps a chicken, and some arguments -- from Twisted.Quotes From lycka at carmen.se Tue Aug 2 13:00:21 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 02 Aug 2005 19:00:21 +0200 Subject: time.clock() or time.time() In-Reply-To: References: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> Message-ID: Shane Hathaway wrote: > time.time() measures real time, while time.clock() measures the time the > CPU dedicates to your program. I suppose that varies with the platform... "help(time.clock)" says: Help on built-in function clock: clock(...) clock() -> floating point number Return the CPU time or real time since the start of the process or since the first call to clock(). This has as much precision as the system records. Another thing to notice is that depending on OS, either time.time() or time.clock() might have much higher precision than the other. For Linux on Intel at least, you'll probably want to always use time.time(). On Windows, you're likely to prefer time.clock(), to measure relative times, since time.time() will have too low resolution for measuring short thingies. Be aware that time.clock() will restart at 0 now and then though. I.e. t1=time.clock();f();t2=time.clock() will have t1>t2 now and then. Using time.time(), that won't happen until after I retire... :) For Linux, see "man 2 time" and "man 3 clock". From steve at holdenweb.com Sat Aug 27 16:31:26 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Aug 2005 16:31:26 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <7xirxri3x5.fsf@ruckus.brouhaha.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> <7xirxri3x5.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Steve Holden writes: > >>A corrected find() that returns None on failure is a five-liner. > > > If I wanted to write five lines instead of one everywhere in a Python > program, I'd use Java. We are arguing about trivialities here. Let's stop before it gets interesting :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From programmer.py at gmail.com Wed Aug 3 13:58:10 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Wed, 3 Aug 2005 12:58:10 -0500 Subject: Printing Docstrings Without Importing In-Reply-To: <1122904223.528701.55420@f14g2000cwb.googlegroups.com> References: <1122746909.441941.226760@o13g2000cwo.googlegroups.com> <42ed90cf.273165611@news.oz.net> <1122904223.528701.55420@f14g2000cwb.googlegroups.com> Message-ID: On 1 Aug 2005 06:50:23 -0700, Fuzzyman wrote: > This seems to scratch several people's itches. Has anyone tried this doxygen filter: http://i31www.ira.uka.de/~baas/pydoxy/ I really like doxygen but am not sure if this is worth the trouble. jw From http Sun Aug 21 06:10:19 2005 From: http (Paul Rubin) Date: 21 Aug 2005 03:10:19 -0700 Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> <3mr0lbF1840unU1@individual.net> Message-ID: <7xd5o7a9dg.fsf@ruckus.brouhaha.com> Reinhold Birkenfeld writes: > Don't forget > > for line in f: > for c in line: > # do stuff As mentioned before, that's careless programming, since it can read the whole file into memory if the file contains no newlines. From nid_oizo at yahoo.com_removethe_ Mon Aug 8 16:18:50 2005 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Mon, 08 Aug 2005 16:18:50 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <42f79137.928629067@news.oz.net> References: <42f695f8.864310192@news.oz.net> <42f79137.928629067@news.oz.net> Message-ID: Bengt Richter wrote: > On Sun, 07 Aug 2005 21:41:33 -0400, Nicolas Fleury wrote: >>I mean should angle brackets <> like in C++, or another operator, be >>used instead? > > I am getting the feeling that your PEP is about a means to do something C++-like > in python, not necessarily to enhance python ;-) IOW, it seems like you > want the [] to do something like C++ in templates? Yes, exactly. Actually Guido also mentionned pointy brackets: http://www.artima.com/weblogs/viewpost.jsp?thread=86641 > (BTW, I have nothing against giving python new capabilities (quite the reverse), > but not by grafting limbs from other animals ;-) If I look at a very recent blog entry of Guido, it seems the idea is still in the air: http://www.artima.com/weblogs/viewpost.jsp?thread=92662 > Maybe you want hidden name-mangling of function defs according to arg types > and corresponding dispatching of calls? I am afraid I am still not clear > on the fundamental motivation for all this ;-) I wrote the PEP to see if was the only one that would benefit from generic types *before* having optional static typing in the language. It seems I'm the only one;) According to blog entry 86641, Guido himself is prototyping with __getitem__. However, I cannot do the same, because the framework I use is much more complete and keyword arguments are a must. Regards, Nicolas From bokr at oz.net Tue Aug 16 14:56:20 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 16 Aug 2005 18:56:20 GMT Subject: Reading portions of a wave file References: <4gcMe.1474$Q82.1316@tornado.socal.rr.com> Message-ID: <430232af.1625265368@news.oz.net> On Tue, 16 Aug 2005 02:33:36 GMT, Nadie wrote: >Greeting list readers, > >I noticed that the wave read object has an *implementation dependent* >setpos(pos) method. When reading audio files, it is useful to be able >to set the position to a specific sample. While setpos(pos) may do this >on certain implementations (haven't tried it), it would not be a >reliable way to do it in a platform independent manner. How do you know this? I don't know either way, but superficially it looks like the wave.py author tried to do "the right thing." > >Is anyone familiar with an alternative wave package that would let one >arbitrarily access portions of a wave file? Clearly, one can read in up >to the desired point, but when the file is very large, this becomes an >inappropriate way of doing things. Why don't you at least try setpos, and fix it if there's a problem? Or report on the problem you _actually_ encounter, which could be useful. That much can't be much harder than looking for an alternative, and may inspire others to help make/find a workable solution for you. Regards, Bengt Richter From wierob at gmx.de Mon Aug 15 05:43:21 2005 From: wierob at gmx.de (Robert Wierschke) Date: Mon, 15 Aug 2005 11:43:21 +0200 Subject: client server question In-Reply-To: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> References: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> Message-ID: John schrieb: > I have a simple script that runs a server where one client can connect. > I would like to make it so that many clients can connect to one server > on the same port. Where can I find how to do this? > > Thanks, > --j > use sockets. the socket accept mehtoh returns a new socket (so now you hava one "server socket" and a connection between to "client sockets" one used by the requesting client and one created at the server side (retrund from accept) ). you should start a new thread/process with this new socket to handle the client request and use the "old" server socket again with the accept method to wait for the next client to connect. From http Tue Aug 30 01:52:08 2005 From: http (Paul Rubin) Date: 29 Aug 2005 22:52:08 -0700 Subject: Writing Multithreaded Client-Server in Python. References: <1125376325.572881.163770@g44g2000cwa.googlegroups.com> Message-ID: <7x3bos55vb.fsf@ruckus.brouhaha.com> "Sidd" writes: > I tried finding and example of multithreaded client-serve program in > python. Can any one please tell me how to write a multithreaded > client-server programn in python such that > 1.It can handle multiple connections > 2.It uses actual threads and not select() or some other function If you mean multiple threads on the server side, see the SocketServer module and its ThreadingMixin class. You may have to look at the source code since up until recently the docs were incomplete. There is a big helpful comment at the top of SocketServer.py which recently got merged into the library reference manual. From steve.morin at gmail.com Tue Aug 16 12:45:19 2005 From: steve.morin at gmail.com (steve morin) Date: Tue, 16 Aug 2005 12:45:19 -0400 Subject: String functions deprication Message-ID: http://www.python.org/doc/2.4.1/lib/node110.html These methods are being deprecated. What are they being replaced with? Does anyone know? Steve From mscottschilling at hotmail.com Thu Aug 25 13:00:06 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Thu, 25 Aug 2005 17:00:06 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: "Rich Teer" wrote in message news:Pine.SOL.4.58.0508250932360.5888 at zen.rite-group.com... > On Thu, 25 Aug 2005, Mike Schilling wrote: > >> Another advantage is that evewry internet-enabled computer today already >> comes with an HTML renderer (AKA browser), so that a message saved to a >> file >> can be read very easily. > > I think you're missing the point: email and Usenet are, historically have > been, and should always be, plain text mediums. Gosh, if you say they should be, there's no point trying to have an intelligent discussion, is there? From christoph.rackwitz at gmail.com Sun Aug 21 16:37:59 2005 From: christoph.rackwitz at gmail.com (Christoph Rackwitz) Date: 21 Aug 2005 13:37:59 -0700 Subject: Please Criticize My Code In-Reply-To: References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> <1124557167.256292.61220@g44g2000cwa.googlegroups.com> Message-ID: <1124656679.384400.65220@z14g2000cwz.googlegroups.com> Why not? Because the regex isn't compiled? Don't tell me not to do something, tell me why i should'nt do it. From prabapython at yahoo.co.in Mon Aug 22 06:15:23 2005 From: prabapython at yahoo.co.in (praba kar) Date: Mon, 22 Aug 2005 11:15:23 +0100 (BST) Subject: Reg Python Byte code In-Reply-To: Message-ID: <20050822101523.54728.qmail@web8402.mail.in.yahoo.com> Dear All, Python 2.3 creates byte code with *.pyc extention. But Python 2.4 creates bytes code with *.pyo. Is there any difference between *.pyc and *.pyo?. Actually After python compiled a program then that program will run from the *.pyc byte code. If I delete that byte code what will be happen.? If I delete *.pyc byte code in the python 2.3 then It will create again *.pyc byte code. But If I delete *.pyo byte code in the python 2.4 then It will not create again *.pyo. Why this difference. If I delete byte code of the python. I want to know Whether it will affect the performance of the programme or not. Kindly clear me all the doubts regarding byte code of python. with regards Prabahar ____________________________________________________ Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html From steve at holdenweb.com Mon Aug 22 08:04:05 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 13:04:05 +0100 Subject: Reg Python Byte code In-Reply-To: <20050822101523.54728.qmail@web8402.mail.in.yahoo.com> References: <20050822101523.54728.qmail@web8402.mail.in.yahoo.com> Message-ID: praba kar wrote: > Dear All, > > Python 2.3 creates byte code with *.pyc > extention. But Python 2.4 creates bytes code with > *.pyo. Is there any difference between *.pyc > and *.pyo?. > Yes. The .pyo files are optimized by removing certain features that aren't essential to execution (things like doc strings). > Actually After python compiled a program > then that program will run from the *.pyc byte > code. If I delete that byte code what will be > happen.? > The next time you import the module concerned the interpreter will recreate the .pyc file. > If I delete *.pyc byte code in the python > 2.3 then It will create again *.pyc byte code. > But If I delete *.pyo byte code in the python > 2.4 then It will not create again *.pyo. Why > this difference. > There is no difference between 2.3 and 2.4 in their treatment of .pyc and .pyo files. The .pyo files are used when you give the interpreter the -O option to indicate you want optimized performance. Most people happily live without ever using this option, but in certain cases it can save some run time. > If I delete byte code of the python. > I want to know Whether it will affect the > performance of the programme or not. > The interpreter will have to take the time to re-create the .pyc on imported modules. If the files can't be created (due to permission problems or whatever) the module has t be recompiled each execution. > Kindly clear me all the doubts regarding > byte code of python. > > with regards > Prabahar > > Hope this helps. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From dacut at kanga.org Mon Aug 8 13:04:38 2005 From: dacut at kanga.org (David Cuthbert) Date: Mon, 08 Aug 2005 13:04:38 -0400 Subject: How to determine that if a folder is empty? In-Reply-To: <86k6iwmvh0.fsf@bhuda.mired.org> References: <3loeiiF139eh3U1@individual.net> <86k6iwmvh0.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Just out of curiosity, is there an OS out there where you can have the > permissions needed to delete a directory without having the > permissions needed to create it appropriately? Not an OS, but AFS has a wider set of permissions (RLIDWKA - which, if I remember correctly, are read, look, index, delete, write, lock, administrate). From http Sat Aug 6 23:22:34 2005 From: http (Paul Rubin) Date: 06 Aug 2005 20:22:34 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <42F4F2D3.80804@tiscali.it> Message-ID: <7x7jeye8hx.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > Actually, it is the reinvention of classes: > > class enclosing(object): > def __init__(self): > self.var = 2 > def enclosed(self): > self.var = 4 Actually, having to wrap classes around operation as simple as variable binding is a reinvention of Java ;-). From peter at engcorp.com Fri Aug 5 22:10:49 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 05 Aug 2005 22:10:49 -0400 Subject: Making a timebomb In-Reply-To: References: <1123254605.828544.147590@g47g2000cwa.googlegroups.com> Message-ID: Cantankerous Old Git wrote: > callmebill at gmail.com wrote: > >> I have a server that right now runs infinitely. I'd like to make it >> die after some amount of time. > > The proper way to do it is to have the timer set a flag that the other > threads check regularly. The threads can then clean up and exit asap. > > The dirty way, which can leave corrupt half-written files and other > nasties, is something like sys.exit(). sys.exit() won't help you if your server is running in the main thread, nor if your server thread is not marked as a daemon, but that does raise another possibility. Instead of doing serve() in the main thread, spawn off a child thread to do the serving, and call setDaemon(True) on it. Then the _main_ thread can do sys.exit() and the server thread will be terminated (somewhat messily perhaps) -- even if it is blocked in an accept() call or some other external blocking call. -Peter From could.net at gmail.com Thu Aug 4 05:24:23 2005 From: could.net at gmail.com (could ildg) Date: Thu, 4 Aug 2005 17:24:23 +0800 Subject: Does pyparsing support UNICODE strings? In-Reply-To: <311b5ce105080401495341f43d@mail.gmail.com> References: <311b5ce10508040013750360e6@mail.gmail.com> <311b5ce105080401495341f43d@mail.gmail.com> Message-ID: <311b5ce1050804022415ecc1f8@mail.gmail.com> OK, I make it. It's right, it can work fine with unicode. pyparsing is great. Thanks. On 8/4/05, could ildg wrote: > I want to parse some Chinese words. > It seems that pyparsing doesn't work for me. > Thank you. > I have to use re directly, although it's harder, but it'll always work. > > On 8/4/05, Robert Kern wrote: > > could ildg wrote: > > > pyparsing is very convenient to use. But I want to find some a py tool > > > to parse non-English strings. Does pyparsing support UNICODE strings? > > > If not, can someone tell me what py tool can do it? Thanks in advance. > > > > Try it! > > > > # vim:fileencoding=utf-8 > > > > from pyparsing import Word > > > > text = "????????, ?????!".decode('utf-8') > > alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce)) > > > > greet = Word(alphas) + u',' + Word(alphas) + u'!' > > greeting = greet.parseString(text) > > print greeting > > > > -- > > 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 > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > From could.net at gmail.com Tue Aug 16 01:42:38 2005 From: could.net at gmail.com (could ildg) Date: Tue, 16 Aug 2005 13:42:38 +0800 Subject: How can I exclude a word by using re? In-Reply-To: <1124165702.590364.107410@o13g2000cwo.googlegroups.com> References: <430085e8$1@news.eftel.com> <1124165702.590364.107410@o13g2000cwo.googlegroups.com> Message-ID: <311b5ce1050815224230ce521@mail.gmail.com> Thank you, you code using pyparsing works very well. Now I got the "number" and the "url". But I still want to get the "name". I'll turn to pyparsing and see how to get the "name" from the html. But I hope you can enlighten me for one more time since I'm not farmiliar with the pyparsing module. On 15 Aug 2005 21:15:02 -0700, Paul McGuire wrote: > Given the example re that you've been trying to get working, here is a > pyparsing approach that might be more, um, approachable. > Unfortunately, since I don't have the URL of the page you are working > with, I'm unable to test this before posting. > > Good luck, > -- Paul > > # getMP3s.py > # get pyparsing at http://pyparsing.sourceforge.net > # > > from pyparsing import * > import urllib > > #~ > r=re.compile(ur'valign=top>(?P?\d{1,2})]*>?\s{0,2}' > > #~ ur'' > #~ ur'(?P.+)',re.UNICO?DE|re.IGNORECASE) > > tdStart,tdEnd = makeHTMLTags("td") > aStart,aEnd = makeHTMLTags("a") > > number = Word(nums) > valign = CaselessLiteral("valign=top>") > > mp3Entry = valign + number.setResultsName("number") + tdEnd + \ > tdStart + SkipTo(aStart) + aStart + \ > SkipTo(tdEnd) + tdEnd > > # get list of mp3's > targetURL = "http://whatever" > targetPage = urllib.urlopen( targetURL ) > targetHTML = targetPage.read() > targetPage.close() > > for toks,s,e in mp3Entry.scanString(targetHTML): > print toks.number, toks.starta.href > > -- > http://mail.python.org/mailman/listinfo/python-list > From patrick.down at gmail.com Wed Aug 17 18:26:40 2005 From: patrick.down at gmail.com (Patrick Down) Date: 17 Aug 2005 15:26:40 -0700 Subject: Moinmoin config In-Reply-To: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> References: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> Message-ID: <1124317599.992955.242880@g44g2000cwa.googlegroups.com> Mark wrote: > Hi, > > I have Moinmoin 1.3.4 installed and working on Linux RHEL3.0. However, > all screen elements are lined up on the left hand side. How can I get > it displayed like the wiki at: Well, this is probably a better question for the moin lists but I have seen this behavior before. I would check the data_underlay_dir = './underlay/' line in your wikiconfig.py file. If it's not getting the right templates it won't format the page right. This is the only advice I can give. Beyond this I don't know what else you can try. > > http://moinmoin.wikiwikiweb.de/HelpOnConfiguration > > instead of this ? -> > > LANShieldOS Release Notes > Search: > > * MarkRuedy > * UserPreferences > > * HelpOnEditing > * HelpContents > * HelpForBeginners > * UserPreferences > > * FrontPage > * RecentChanges > * FindPage > * HelpContents > > * Edit > * Show Changes > * Get Info > * Subscribe > * > > FrontPage From gandalf at geochemsource.com Wed Aug 24 03:12:56 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Wed, 24 Aug 2005 09:12:56 +0200 Subject: FileIO problem In-Reply-To: <1124866383.975225.261840@o13g2000cwo.googlegroups.com> References: <1124866383.975225.261840@o13g2000cwo.googlegroups.com> Message-ID: <430C1DF8.4040602@geochemsource.com> Try this: gclas = raw_input("What is the class:") def Princlas(): count = 0 while count != 1000: count = count + 1 return "Admin forceclass %s %s " % ( count , gclas ) #asks for file name a = raw_input("What is new file name:") out_file = open(a,"w") #this is the input of text out_file.write(Princlas()) out_file.close() >i know i need to get it to a string but i dont know how? > Your functions should RETURN a string, with the "return" statement. Another issue: you cannot write the function itself, only its result: out_file.write(Princlas()) instead of out_file.write(Princlas) From cantabile.03 at wanadoo.fr Wed Aug 10 12:10:37 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Wed, 10 Aug 2005 18:10:37 +0200 Subject: gettext again In-Reply-To: References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> <42f77cb6$0$25055$8fcfb975@news.wanadoo.fr> <42f9273d$0$22313$8fcfb975@news.wanadoo.fr> Message-ID: <42fa26fd$0$22311$8fcfb975@news.wanadoo.fr> stasz a ?crit : > On Tue, 09 Aug 2005 23:59:26 +0200, cantabile wrote: > > >>stas a ?crit : >> >> >>>As a reminder, make sure that you install gettext in the namespace >>>of your toplevel module. > > [....] > >>Noticed something : >>I must import test2.py AFTER gettext.install('test1') and even then, if >>test3.py imports test2.py, messages won't be translated in test3.py. I >>have to import test3.py in test1.py too. >>Is this normal behaviour or is there something I'm missing (again) ? > > Hmm, perhaps I missed something, namespaces can be sometimes hard > to get right. > Let's see: > > test1 imports and installs gettext. > Now test1 holds the gettext reference. > test1 imports test2 and test3 and 'inherits' test1 namespace > test2 and test3 have access to test1 namespace and the gettext. > > So in (pseudo) Python code test1 would looks like this: > > import gettext > gettext.install(test)# assuming test.mo holds all the strings > import test2, test3 > > Another approach would be to place the whole gettext install stuff > in a separate module wrapped in a function which can be imported > by every module that wants language support. > (That's the approach I always use) > > Contents of utils.py > (Code is not tested, it's to show the principals) > > import locale, gettext > def set_gettext(mo_location='/usr/share/locale'): > locale.setlocale(locale.LC_ALL) > gettext.install('test1', mo_location) > > Now in your modules you could do this: > > In test1.py: > from utils import set_gettext > set_gettext()# remember gettext.install installs '_' in the > # current namespace, in this case test1. > import test2, test 3 > > In test4.py > from utils import set_gettext > set_gettext() > .... > .... > > Now test1 and test2 get their gettext from test1 while test4 import > gettext from utils.py which installs the same mo file as it did in > test1, test2 and test3. > > >>PS : your project looks nice ! > > Thanks. > > BTW, the principal of gettext in utils.py is also implemented in > the gvr project, so you have a real life example there :-) > > Stas > Thanks for the explanation, very clear, as usual. Cheers :) From limodou at gmail.com Fri Aug 5 07:27:38 2005 From: limodou at gmail.com (limodou) Date: Fri, 5 Aug 2005 19:27:38 +0800 Subject: Some question about setuptools module Message-ID: <505f13c05080504272fdaa303@mail.gmail.com> I'm new to setuptools. One question is: Recently I want to use setuptools for a project. My command line is just like : python setup.py sdist --formats=gztar But I found some deleted files also included in the package. These files are .pyc suffixed. I use subversion. I checked the setuptools' code, and found that setuptools indeed follows the .svn/entries file, but it only retrieves files, and check if the file is exist. But in my entries file, just like: You can see the "deleted" field is "true", so the file should not be included in the package, even through the file is exist. So I think maybe the .pyc, .pyo file should be omited. The another question is: I have below directory structure: A/ setup.py B/ __init__.py b.py t.txt .svn/ entries So B is a package dir. But as I run setup.py, the t.txt is not include in the package. I followed the source code and found it was because that dir A hasn't in version control, i.e. there is not .svn directory in dir A, so the setuptools could not traversal the subdirectory. I don't know how to write my setup.py script. I'm sorry may be this letter is not suit for this maillist. -- I like python! My Donews Blog: http://www.donews.net/limodou New Google Maillist: http://groups-beta.google.com/group/python-cn From paragate at gmx.net Tue Aug 23 08:59:28 2005 From: paragate at gmx.net (Wolfgang Lipp) Date: Tue, 23 Aug 2005 14:59:28 +0200 Subject: [Python-Dev] Revised PEP 349: Allow str() to return unicode strings In-Reply-To: <430AFCC7.9030402@egenix.com> References: <20050822213142.GA5702@mems-exchange.org> <430AFCC7.9030402@egenix.com> Message-ID: just tested the proposed implementation on a unicode-naive module basically using import sys import __builtin__ reload( sys ); sys.setdefaultencoding( 'utf-8' ) __builtin__.__dict__[ 'str' ] = new_str_function et voil?, str() calls in the module are rewritten, and print u'd?sseldorf' does work as expected(*) (even on systems where i have no access to sitecustomize, like at my python-friendly isp's servers). --- * my expectation is that unicode strings do print out as utf-8, as i can't see any better solution. i suggest to make this option available e.g. via a module in the standard lib to ease transition for people in case the pep doesn't make it. it may be applied where deemed necessary and left ignored otherwise. if nobody thinks the reload hack is too awful and this solution stands testing, i guess i'll post it to the aspn cookbook. after all these countless hours of hunting down ordinal not in range, finally i'm starting to see some light in the issue. _wolf On Tue, 23 Aug 2005 12:39:03 +0200, M.-A. Lemburg wrote: > Thomas Heller wrote: >> Neil Schemenauer writes: >> >> >>> [Please mail followups to python-dev at python.org.] >>> >>> The PEP has been rewritten based on a suggestion by Guido to change >>> str() rather than adding a new built-in function. Based on my >>> testing, I believe the idea is feasible. It would be helpful if >>> people could test the patched Python with their own applications and >>> report any incompatibilities. >>> >> >> >> I like the fact that currently unicode(x) is guarateed to return a >> unicode instance, or raises a UnicodeDecodeError. Same for str(x), >> which is guaranteed to return a (byte) string instance or raise an >> error. >> >> Wouldn't also a new function make the intent clearer? >> >> So I think I'm +1 on the text() built-in, and -0 on changing str. > > Same here. > > A new API would also help make the transition easier from the > current mixed data/text type (strings) to data-only (bytes) > and text-only (text, renamed from unicode) in Py3.0. > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From me at privacy.net Tue Aug 9 10:00:47 2005 From: me at privacy.net (Dan Sommers) Date: Tue, 09 Aug 2005 10:00:47 -0400 Subject: don't understand instanse creation References: Message-ID: On Tue, 09 Aug 2005 16:39:51 +0300, Maksim Kasimov wrote: > Hello, > i have a class, such as below. > when i try to make instances of the class, > fields __data1 and __data2 gets different values: __data1 behaves like private field, __data2 - like static > which is the thing i've missed? > thanks for help. > ==================================================== > import time > class my: > __data1 = [] > __data2 = [] > def __init__(self): > print "__data1: ", self.__data1 > print "__data2: ", self.__data2 > for i in time.localtime(): > self.__data2.append(i) The above line changes the existing class attribute __data2, which is shared by all instances of this class. > self.__data1 = self.__data2[:] The above line creates a new instance attribute __data1, and binds it to a copy of __data2. > print "__data1: ", self.__data1 > print "__data2: ", self.__data2 [ example snipped ] HTH, Dan -- Dan Sommers From jepler at unpythonic.net Sun Aug 21 13:06:31 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sun, 21 Aug 2005 12:06:31 -0500 Subject: Best way to 'touch' a file? In-Reply-To: <1378C457-DCBF-4C3B-B33E-0FAC6439DF25@sbcglobal.net> References: <1378C457-DCBF-4C3B-B33E-0FAC6439DF25@sbcglobal.net> Message-ID: <20050821170627.GB26190@unpythonic.net> On Unix, 'touch' is basically a wrapper around utime(2), available in python as os.utime. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From yajushrestha at gmail.com Sun Aug 14 16:35:20 2005 From: yajushrestha at gmail.com (ys) Date: 14 Aug 2005 13:35:20 -0700 Subject: Intalling psycopg Message-ID: <1124051720.882466.237840@g43g2000cwa.googlegroups.com> Hi I am getting "ImportError: No module named psycopg" i downloaded windows binary from http://stickpeople.com/projects/python/win-psycopg/ It is intalled in python24\lib\site-packages\psycopg2\ please help! Thanks YS From donn at u.washington.edu Tue Aug 9 15:00:57 2005 From: donn at u.washington.edu (Donn Cave) Date: Tue, 09 Aug 2005 12:00:57 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> Message-ID: In article , Michael Hudson wrote: > Donn Cave writes: > > > On the contrary, there are a couple. Ghc is probably the > > leading implementation these days, and by any reasonable > > measure, it is serious. > > > > Objective CAML is indeed not a pure functional language. > > *cough* unsafePerformIO *cough* (Hope that cough isn't anything serious.) The way I understand it, you'd be a fool to use unsafePerformIO in a way that would generally compromise functional purity. It really is "unsafe", inasmuch as it violates central assumptions of the language evaluation model. Some people take "pure" too seriously. In this context, functional purity just means that we know that in principle, the value of an expression is constant - given the same inputs to a function, we always expect the same result. It doesn't mean "free from blemish." unsafePerformIO is a sort of blemish, I suppose, but it's a pure functional language in my book. Donn Cave, donn at u.washington.edu From steve at holdenweb.com Sun Aug 21 18:04:52 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Aug 2005 23:04:52 +0100 Subject: Python Light Revisted? In-Reply-To: <1124568446.496146.247180@g47g2000cwa.googlegroups.com> References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: Steve M wrote: > I agree with you in part and disagree in part. > > I don't see the point to making the distribution any smaller. 10MB for > the installer from python.org, 16MB for ActiveState .exe installer. How > is 5MB "lightweight" while 10MB isn't? The Windows XP version of Java > at java.com is 16+ MB, and the .NET framework is, well, I don't know > how big, but I doubt it's much less than 10MB. > I really don't think that it's worth trying to compress the standard distribution any further, given that it isn't really bloatware. I can see the point for embedded systems and the like, but for generic PC use there isn't really a problem. > Also I think it's a terrible idea to distribute without pieces of the > standard library if the distribution is meant to be developed against > for arbitrary applications. (If you just want a slimmed down Python for > one specific application, use py2exe - I think it only includes > whatever gets imported for your program to run.) And excluding zip > while including Twisted? I don't get it. Besides, how do you know > Twisted doesn't import XML-RPC? I could see an enlarged Python that > includes Twisted along with the standard library, and in fact > ActiveState's includes win32 stuff. There's another such > mega-distribution around, the name of which escapes me at the moment. > But removing zip from the standard library so you can save 20kb seems > foolish. (Again, unless it is for one specific application, in which > case py2exe should do the trick, although I could be wrong about that > since I've never used it.) > > Now, what I do agree with is a Python that can be run from a folder > without having to be installed on the system. That could have lots of > benefits, if the details with pythonpath and whatever could be sorted > out. For example I haven't upgraded to 2.4 yet because I have 20 > different packages (e.g. SOAPpy, ZODB, whatever) installed on WinXP, > many of which required me selecting my 2.3 installation when I > installed them. I have no idea what will happen to all those if I run > the ActiveState installer for 2.4. I seem even to remember reading that > I have to un-install 2.3 before installing 2.4. I don't want to > re-install those 20 packages. Anyway I haven't had time to research it > and it isn't pressing, even though I'd like to start trying decorators > and generator expressions. > Someone recently produced a distribution capable of running from a CD and designed to make it easy to use Python on machines where it wasn't actually installed. That might be a useful starting point too, but I can't find the right incantation to get Google to bring it up. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From cct at tavaresstudios.com Sun Aug 21 01:19:37 2005 From: cct at tavaresstudios.com (Chris Tavares) Date: Sun, 21 Aug 2005 05:19:37 GMT Subject: urllib leaves sockets open? Message-ID: Hi all. I'm currently tracking down a problem in a little script[1] I have, and I was hoping that those more experienced than myself could weigh in. The script's job is to grab the status page off a DLink home router. This is a really simple job: I just use urllib.urlopen() to grab the status page. The router uses HTTP Basic authentication, so I've subclassed FancyURLOpener to supply the credentials. This all worked fine with an older router, but with the newer model there's a long delay between sending the authentication information and actually getting the response back. When just going in via a brower, there is no such delay. I did a little work with a tracing proxy, and I noticed something interesting. urllib first makes an HTTP request without authentication information. This gets back an HTTP 401 error code, as expected. urllib then opens a second socket, and sends the Authentication header, again just as expected. Here's what I noticed: The socket for the first request that failed is still connected. It looks like what's happening is that the router's only allowing a single HTTP connection at a time. As a result, the second, authenticated request, doesn't get it's response until there's some kind of timeout and the first socket disconnects. Is this normal behavior for urllib? Is there a way to force that initial socket closed earlier? Is there something else I need to do? Thanks for any insight, -Chris [1] The script in question is: router_address = "xxx" router_port = 80 router_user = "user" router_password = "password" class DI604Opener( urllib.FancyURLopener ): def prompt_user_passwd( self, host, realm ): return ( router_user, router_password ) urllib._urlopener = DI604Opener() # # Kick off the process when run from the command line # if __name__ == "__main__": status_page = urllib.urlopen( "http://%s:%s/status.htm" % ( router_address, router_port ) ) print status_page.read() From peter at engcorp.com Wed Aug 17 22:35:54 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 17 Aug 2005 22:35:54 -0400 Subject: stopping a python windows service In-Reply-To: <1124284846.064888.276430@g43g2000cwa.googlegroups.com> References: <1124230320.593335.288650@g44g2000cwa.googlegroups.com> <1124284846.064888.276430@g43g2000cwa.googlegroups.com> Message-ID: DK wrote: > I may have taken your code example too literally. I tried putting in > the check for 'shutdownEvent.isset()' but it's failing at run time. > It's looking for a global variable, I guess. Or perhaps "it" is just looking for correct capitalization, since Python is case sensitive. Try shutdownEvent.isSet() instead. -Peter From claudio.grondi at freenet.de Sat Aug 20 13:30:35 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Sat, 20 Aug 2005 17:30:35 -0000 Subject: Version of TAR in tarfile module? TAR 1.14 or 1.15 port to Windows? References: <3mnhu1F17b3j4U1@individual.net> <4306cf8d$0$15269$9b622d9e@news.freenet.de> Message-ID: <3mp0ouF17gb2qU1@individual.net> Martin, thank you for your response. I see, that I have to test myself if the tarfile module can do what I need, so I did and I have evidence, that the Python tarfile module is not able to see all the files inside the TAR archives created on Linux with TAR 1.14 . The Python tarfile module stops to go through the TAR archive somewhere already at the beginning, like the other tools I have used, did. I have no understanding what Cygwin, MinGW (do I put MinGW in the right context?) are and do, but I gave Cygwin a try and installed it selecting also the tar package version 1.15 for installation. I tried to run the tar.exe, but in the beginning it was not able to do anything for me. I haven't given up and after hours of trying to find the reason for this I found that: the tar.exe seems to have no access to any files not inside the [%SystemDrive%\Cygwin\usr] directory on my system drive e: , where Cygwin is installed. Is there a way to go around this, because I have to uncompress a 17 GByte file and my system drive has only 3 GByte of free storage space. I have in mind, that it could have something to do with the mount command, but this is all I can remember. I work in a Windows command shell (DOS-box) and mount says: j: on /cygdrive/j , but I don't know how to write the entire path "j:\o\archives\images\dump.tar", so that the file can be found by tar.exe and unpacked to "i:\images" . tar.exe --extract --directory=tmp -f j:/o/archives/images/dump.tar results in: /usr/bin/tar: j\:/o/archives/images/dump.tar: Cannot open: Input/Output error telling tar.exe --extract --directory=tmp -f /cygdrive/j/o/archives/images/dump.tar doesn't work either. Claudio "Martin v. L?wis" schrieb im Newsbeitrag news:4306cf8d$0$15269$9b622d9e at news.freenet.de... > Claudio Grondi wrote: > > What TAR version is built into the tarfile module? > > None: the tarfile module is not built on top of > GNU tar. Instead, it is a complete reimplementation. > > > Is there a TAR 1.14 or 1.15 port to Windows > > available in Internet for download (which URL)? > > http://sources.redhat.com/cygwin/ > > Regards, > Martin From peter at engcorp.com Tue Aug 16 09:37:42 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 16 Aug 2005 09:37:42 -0400 Subject: looping list problem In-Reply-To: References: Message-ID: Jon Bowlas wrote: > Ok so I changed it to this: > > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > hiddennavelements = navstring.split(' ') > for hiddennavelement in hiddennavelements: > yield hiddennavelements > > But I get the following error- Line 5: Yield statements are not allowed. Please post the full traceback (cut and paste). Don't just retype the error message like that. -Peter From fraca7 at free.fr Wed Aug 17 05:31:49 2005 From: fraca7 at free.fr (fraca7) Date: Wed, 17 Aug 2005 11:31:49 +0200 Subject: Read from stdouton Popen on WinXP? In-Reply-To: <1124228881.128382.118050@g47g2000cwa.googlegroups.com> References: <1124228881.128382.118050@g47g2000cwa.googlegroups.com> Message-ID: <43030406$0$7820$626a14ce@news.free.fr> mhenry1384 a ?crit : > I am trying to run a program and filter the output on Windows XP. > Since I want to filter the output, I'd like to read it a line at a time > and only print the lines I care about. > [snip] I had the exact same problem yesterday. This is an obvious use case for the "bufsize" parameter to os.popen4, except that the Windows implementation doesn't accept anything but -1... The only way I can see out of this is to use win32api to launch the process through CreateProcess, then perform asynchronous I/O on its stdout using the OVERLAPPED structure in a call to ReadFile... Ugly... From bignose+hates-spam at benfinney.id.au Mon Aug 15 08:58:37 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 15 Aug 2005 22:58:37 +1000 (EST) Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <1124090875.292874.199610@o13g2000cwo.googlegroups.com> Message-ID: Brian Victor wrote: > jbperez808 at yahoo.com wrote: > > Torsten Bronger wrote: > >> I've been having a closer look at wxPython which is not Pythonic at > >> all and bad documented. Probably I'll use it nevertheless. > > Aye. Couldn't agree more. > > You know, whenever someone mentions wxPython being badly documented, > I have to wonder whether they know about the nearly 2000 page PDF of > wxWidgets documentation, which is available in html at > http://www.wxwidgets.org/manuals/2.6.1/wx_contents.html All of which is oriented toward C++ programmers, with all the language assumptions inherent to that. > wxPython has the same API as wxWidgets, except where indicated in > that manual. If in doubt, you can also consult > http://wxpython.org/docs/api/ That being part of the problem. Putting pieces together in C++ is quite a different mindset to putting them together in Python. > I apologize if you already know about these things, but I find > myself continually surprised that "wxPython is badly documented" has > become conventional wisdom when I have never found that to be the > case. Quantity of documentation doesn't equal quality. That said, the wxPython 2.6 release saw a renewed push toward getting comprehensive API documentation online; it's coming together, slowly. It still feels like wxPython is a second-class citizen in the wx world. -- \ "I was the kid next door's imaginary friend." -- Emo Philips | `\ | _o__) | Ben Finney From mwm at mired.org Mon Aug 29 21:48:30 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 29 Aug 2005 21:48:30 -0400 Subject: OpenSource documentation problems References: Message-ID: <86slws9oup.fsf@bhuda.mired.org> "Adriaan Renting" writes: > Marked -1 Flamebait, but I'll respond anyway. Yup. > I do agree that a lot of OSS projects seem to lack somewhat in the > documentation department, compared to a lot of commercial software. You know what? My experience is just the opposite. Commercial software (at lest for Windows and OS X end user applications) often comes with *no* documentation whatsoever. The few exceptions I've encountered seldom installed it - if you wanted to look at it, you had to get the distribution media and copy it by hand. Instead, you get online help. While the latter is valuable, it's not a substitute for good documentation. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From spammers-go-here at spam.invalid Wed Aug 17 12:07:34 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 17 Aug 2005 12:07:34 -0400 Subject: Testing for presence of arguments References: <430353e1$0$18641$14726298@news.sunsite.dk> Message-ID: <430360a8$0$18639$14726298@news.sunsite.dk> Benji York wrote: > Madhusudan Singh wrote: >> I know how to set optional arguments in the function definition. Is there >> an intrinsic function that determines if a certain argument was actually >> passed ? Like the fortran 95 present() logical intrinsic ? > > People generally use a value that isn't a valid option, often None. > > def my_func(a, b, c=None): > if c is None: > do something > > If None is a valid value, make one that isn't: > > unspecified = object() > > def my_func(a, b, c=unspecified): > if c is unspecified: > do something > -- > Benji York Now, that was a very good suggestion. Thanks. From chrispatton at gmail.com Sun Aug 28 04:19:03 2005 From: chrispatton at gmail.com (chris patton) Date: 28 Aug 2005 01:19:03 -0700 Subject: py to exe: suggestions? Message-ID: <1125217143.451511.25310@g43g2000cwa.googlegroups.com> I need to convert a python file to an '.exe'. I've tried py2exe, and I don't like it because you have to include that huge dll and libraries. Thanks for the Help!! From pink at odahoda.de Sun Aug 28 09:11:28 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Sun, 28 Aug 2005 15:11:28 +0200 Subject: Dynamic image creation for the web... References: Message-ID: Tompa wrote: > Hi, > > I would like to create images on the fly as a response to an http request. > I can do this with PIL like this (file create_gif.py): > from PIL import Image, ImageDraw > > print 'Status: 200 OK' > print 'Content-type: text/html' > print > print 'Python Dynamic Image Creation > Test' print '' > im = Image.new("P", (600, 400)) > draw = ImageDraw.Draw(im) > draw.rectangle((0, 0) + im.size, fill="blue") > im.save("images/tmp.gif"); > print '' > print '' > > > However, I would like to 1) avoid saving the image in a file on disk and > 2) separate the HTLM code from the python image creation code. > > Something like this is what I have in mind: > (file index.html): > > > Python Dynamic Image Creation > > Image created on the fly... > > > and in file create_image.py: > from PIL import Image, ImageDraw, ImageFont > im = Image.new("P", (600, 400)) > draw = ImageDraw.Draw(im) > draw.rectangle((0, 0) + im.size, fill="blue") > > > Unfortunately this does not work :-( > What is missing? You are almost there. Your create_image.py does not return anything to the browser yet. First return proper HTTP headers, e.g. sys.stdout.write('Status: 200 OK\r\n') sys.stdout.write('Content-type: image/gif\r\n') sys.stdout.write('\r\n') (Your prints above are mostly equivalent, but do not output the correct \r\n as line terminator - at least on UNIX style systems. Most webservers tolarate this, if it's coming from a CGI - but doing it right and not relying on a certain server behaviour is not bad anyway ;) Then check the PIL docs to find out, how to output the image to sys.stdout (instead of writing to a file). -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From e-huss at netmeridian.com Wed Aug 24 22:51:31 2005 From: e-huss at netmeridian.com (Eric Huss) Date: Wed, 24 Aug 2005 19:51:31 -0700 (PDT) Subject: subpackage import problem In-Reply-To: References: Message-ID: On Sun, 21 Aug 2005, Robert Kern wrote: > Eric Huss wrote: > > I'm having a problem with packages within packages. Here's an example: > > > > foo/ > > foo/__init__.py: empty file > > foo/sub/__init__.py: > > from foo.sub.B import B > > foo/sub/A.py: > > class A: > > pass > > foo/sub/B.py > > import foo.sub.A > > class B(foo.sub.A): > > pass > > > > Trying to "import foo.sub" will result in this error: > > > >>>>import foo.sub > > > > Traceback (most recent call last): > > File "", line 1, in ? > > File "foo/sub/__init__.py", line 1, in ? > > from foo.sub.B import B > > File "foo/sub/B.py", line 3, in ? > > class B(foo.sub.A): > > AttributeError: 'module' object has no attribute 'sub' > > I imagine it has something to do with the timing of imports. Python is > executing the contents of foo/sub/B.py while it's trying to create the > module object foo.sub. You can get around it, though. > > Try this in foo/sub/B.py : > > from foo.sub.A import A > class B(A): > pass > > That works for me (Python 2.4.1, OS X). Hi! I wanted to say thank you for responding. Your suggestion works for me. After sending my message I found some related bugs on sourceforge (http://sourceforge.net/tracker/?func=detail&aid=992389&group_id=5470&atid=105470 and http://sourceforge.net/tracker/?func=detail&aid=966431&group_id=5470&atid=105470). It's unfortunate that it doesn't work, and it sounds like the fix would require a major amount of work in import.c, which means it will probably never be fixed (and if I made a big patch, I doubt it would be committed). -Eric From onurb at xiludom.gro Wed Aug 10 15:13:29 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 10 Aug 2005 21:13:29 +0200 Subject: What is Python?! In-Reply-To: References: Message-ID: <42fa51db$0$7802$626a14ce@news.free.fr> Roy Smith wrote: > Robert Wierschke wrote: > >> a scripting language or a "normal" language like C++ etc. > > > It is difficult to define exactly what a "scripting language" is and isn't, You can tell buy the most common use. bash is a scripting language, javascript is a scripting language, perl is a scripting language, php is a scripting language, Python is *not* a scripting language !-) > but I think most people would classify it as a scripting language. It can be used for scripting too, yes. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From tiang_ono at yahoo.com Sun Aug 14 20:48:14 2005 From: tiang_ono at yahoo.com (Titi Anggono) Date: Sun, 14 Aug 2005 17:48:14 -0700 (PDT) Subject: py2exe: no exe produced? In-Reply-To: <1123996227.332130.219450@o13g2000cwo.googlegroups.com> Message-ID: <20050815004814.44074.qmail@web30712.mail.mud.yahoo.com> I never use python2.4, I use python 2.3 and here is (maybe it works). For example, the hello.py is under directory C:\Python23\latihan\ and put the setup.py under that directory ------------------------------------------ #setup.py from distutils.core import setup import py2exe setup(console=["hello.py"]) ------------------------------------------- C:\Python23\latihan>python setup.py py2exe --- guoxiaotian at gmail.com wrote: > I tried py2exe the latest version with python 2.4 on > windows. > > the setup script looks like this: > ___________________________________________ > > # setup.py > from distutils.core import setup > import py2exe > > setup(name="Hello", > scripts=["f:\python\hello.py"],) > > ____________________________________________ > > when I run the script, the output looks like > > F:\Python>python setup.py py2exe > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From donald.welch at NOSPAM.hp.com Mon Aug 15 18:03:33 2005 From: donald.welch at NOSPAM.hp.com (Don) Date: Mon, 15 Aug 2005 15:03:33 -0700 Subject: Invoking GUI for app running in background with a keypress References: <1124130042.3819.37.camel@localhost.localdomain> Message-ID: <4301116c@usenet01.boi.hp.com> Mathias Dahl wrote: > Jeremy Moles writes: > >> If you want to get crazy you can poll() on one of the evdev nodes >> (/dev/input/event*) and behave accordingly. I do this in a C application >> we use to do the exact same thing you're talking about. >> >> Each successful read from the device returns a 16-byte input_event >> struct (or similar, I'm going from memory here) that represents a key >> action. >> >> A google search returned this: >> >> http://svn.navi.cx/misc/trunk/python/evdev/evdev.py > > Thanks for the pointer. That sounds crazy indeed! Maybe a bit too > crazy (low-level) for me... :) > > I tested the code very briefly: > > $ python evdev.py /dev/input/event0 > > Traceback (most recent call last): > File "evdev.py", line 549, in ? > demo() > File "evdev.py", line 35, in demo > dev = Device(sys.argv[1]) > File "evdev.py", line 91, in __init__ > self.fd = os.open(filename, os.O_RDWR | os.O_NONBLOCK) > OSError: [Errno 13] Permission denied: '/dev/input/event0' > > Loggin in (su:ing) as root solves that problem but I'm not sure I want > to require the user being root to be able to run my program. > > Anyway, thanks again for the hint! > > /Mathias Could you make the script setuid? http://nob.cs.ucdavis.edu/~bishop/secprog/ -Don From supercomputer at gmail.com Mon Aug 1 16:40:20 2005 From: supercomputer at gmail.com (supercomputer at gmail.com) Date: 1 Aug 2005 13:40:20 -0700 Subject: MySQL help In-Reply-To: <%qvHe.29361$TR5.2357@news.edisontel.com> References: <1122922717.658701.29410@g14g2000cwa.googlegroups.com> <%qvHe.29361$TR5.2357@news.edisontel.com> Message-ID: <1122928820.626224.201480@g49g2000cwa.googlegroups.com> I wasn't aware of the replace command I'll take a look at that tomorrow and see if it helps. Thanks >quick tip: are you aware of the mysql's REPLACE command? > From peter at engcorp.com Sat Aug 6 09:20:27 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 06 Aug 2005 09:20:27 -0400 Subject: Syntax error after upgrading to Python 2.4 In-Reply-To: <1123323206.151000.309140@g49g2000cwa.googlegroups.com> References: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> <1123323206.151000.309140@g49g2000cwa.googlegroups.com> Message-ID: <3v6dnb_ozNQJJGnfRVn-qA@powergate.ca> Fernando wrote: > I reinstalled version 2.3.5 and everything works fine now. It's > definately something related to the latest version. No problem in software is definite until you actually know what the solution is. I'd suspect something other than a simple problem in 2.4 itself, since otherwise it is highly likely others would already have encountered it. Since a SyntaxError is raised during compilation (during import) and not execution, it should be possible to get that even on another machine without all the related code. Care to email me a copy of that file and I'll investigate it for you? I have both 2.3 and 2.4 installed and it shouldn't take long for me to figure out what the problem is, or at least to prove that it is not a 2.4 issue. If you can't do that, try removing all the code except the "class" line and that one method in the class. It should still give a syntax error for the same line. > > This is one of the main resons I finally gave up using Python and > switched to Smalltalk. You can't concentrate on your work while someone > is permanently introducing changes to your tool. Python has one of the absolute best backwards-compatibility records in the history of software, IMHO. While I can't offer a comparison with Smalltalk, I really doubt Smalltalk has been (or could be) significantly better unless it hasn't changed at all in 30 years... Still, someone has to be the first to find each bug, and maybe you've discovered one in 2.4. Let me have that file (or a reduced version of it that still generates the problem) and I'll prove one of us wrong. :-) -Peter From zarnovican at gmail.com Wed Aug 17 18:56:09 2005 From: zarnovican at gmail.com (BranoZ) Date: 17 Aug 2005 15:56:09 -0700 Subject: Lists of list In-Reply-To: References: Message-ID: <1124319369.108571.62470@g49g2000cwa.googlegroups.com> Mohammed Altaj wrote: > Hi All > > I am having problem with delete line if its belong to another one , example I think, you mean to remove all lines that are substrings of another line. l = ['0132442\n', '13\n', '24\n'] l = [e.strip() for e in l] i = 0 while True: try: for j in range(len(l)): if i == j: continue if l[j].find(l[i]) >= 0: # line 'j' is superstring of line 'i' del l[i] break else: # doesn't have superstring i += 1 except IndexError: break Basically, I try all n*n combinations, and remove substring lines "in-place". BranoZ From rkern at ucsd.edu Sun Aug 7 10:55:21 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 07:55:21 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <7xpsspq0re.fsf@ruckus.brouhaha.com> References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: > >>>That would imply that it included the Ruby language. Nothing stops the >>>Ruby on Rails packagers from making the Ruby on Rails distro a >>>superset of the Ruby distro, after all. >> >>So you agree with me then? That _was_ exactly my point, after all. Not >>that you read it. After all, you might have been replying to some >>completely different posting - who could know? > > I don't understand what you're getting at. Either the RoR > distribution includes the Ruby language or else it doesn't. No. A *particular* Ruby on Rails distribution includes the Ruby language. You can get Ruby on Rails by itself if you happen to already have Ruby installed. People who aren't just evaluating Ruby on Rails for the first time will probably be using the regular distribution. You'll notice, very distinctly, in big letters at the top of http://download.rubyonrails.com : "Rails is primarily distributed through RubyGems ? the soon-to-be official packaging format for Ruby libs/apps" > From that > other post, I have the impression that it does, but I don't care > enough about Ruby to want to go check into it. > > Or is your point that some third party could make a moby Python distro > that includes more runtime stuff than the python.org distro includes? > Yes, they could; that it's happened with Ruby and not with Python http://www.enthought.com/python/ http://download.enthought.com/MacEnthon/ReadMe.html I even pointed you to the last one, earlier. > suggests that Ruby is doing a better job attracting people to do stuff > like that. I don't think the Ruby language is as nice as Python, so > the difference must be in the culture surrounding the language, rather > than the language itself. Python culture often strikes me as > seriously dysfunctional. See the "reinventing the wheel" thread of > the previous week or so, which was full of gnashers arguing that a > convenient unified distro isn't necessary since users should have > enough tenacity to download and configure umpteen separate components > themselves. As a maintainers of a convenient unified distro, I have to say that it's a losing strategy. No matter how much you include, for every person that tells you, "Thank you, you've made my Python experience better," there are three who say, "Thanks, but could you also include Package X?" or "Thanks, but Package Y is much better at doing foo than Package Z? Could you include it next time?" or "When are you going to update Package W to the latest version?" You can't satisfy everyone or even a whole lot of people with a single massive installer. People want different things. I want VTK installed because I need 3D visualization; I couldn't care less about web applications. But lots of other people care very deeply about web applications and don't want to waste 100 MB of disk space on 3D visualization libraries. When "one-click installation" entails downloading 150 MB of compressed data for every update, the convenience begins to pall a bit. Fortunately, there's a better approach, and it's coming soon. The next iteration of MacEnthon, at least, is going to be based on Python eggs and easy_install.py. Python eggs are, more or less, Python's answer to Ruby's gems. http://peak.telecommunity.com/DevCenter/PythonEggs http://peak.telecommunity.com/DevCenter/EasyInstall -- 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 maksim.kasimov at gmail.com Tue Aug 9 10:24:11 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Tue, 09 Aug 2005 17:24:11 +0300 Subject: don't understand instanse creation In-Reply-To: References: Message-ID: i see, thaks you very match! Dan Sommers wrote: > On Tue, 09 Aug 2005 16:39:51 +0300, > Maksim Kasimov wrote: > > >>Hello, > > >>i have a class, such as below. >>when i try to make instances of the class, >>fields __data1 and __data2 gets different values: __data1 behaves like private field, __data2 - like static >>which is the thing i've missed? > > >>thanks for help. > > >>==================================================== > > > >>import time >>class my: > > >> __data1 = [] >> __data2 = [] > > >> def __init__(self): > > >> print "__data1: ", self.__data1 >> print "__data2: ", self.__data2 > > >> for i in time.localtime(): >> self.__data2.append(i) > > > The above line changes the existing class attribute __data2, which is > shared by all instances of this class. > > >> self.__data1 = self.__data2[:] > > > The above line creates a new instance attribute __data1, and binds it to > a copy of __data2. > > >> print "__data1: ", self.__data1 >> print "__data2: ", self.__data2 > > > [ example snipped ] > > HTH, > Dan > -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From sybrenUSE at YOURthirdtower.com.imagination Sun Aug 21 20:23:42 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 22 Aug 2005 02:23:42 +0200 Subject: Python dutch References: Message-ID: Dragonfly enlightened us with: > Do you have a python lesson book in dutch version on your site? I'd suggest learning English. The programming language is based on English anyway. Besides, everybody in The Netherlands learns English at school. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From mwm at mired.org Wed Aug 10 21:50:07 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 10 Aug 2005 21:50:07 -0400 Subject: Is there a way of executing a command in a string? References: Message-ID: <86pssli6nk.fsf@bhuda.mired.org> Jeff Schwab writes: > Jerry He wrote: >> Hi, suppose I have the following string >> cmdstr = "b = lambda s: s*s" >> Is there a way to execute this string other than >> copying it onto a file and then importing it? > > >>> exec "b = lambda s: s*s" > >>> b Jeff forgot to warn you that exec is a *dangerous* function. Don't use it on data that you aren't 100% sure of the origin of. Better yet, avoid it if at all possible. If you'll tell us why you think you need to do this, possibly we can help you avoid using exec. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From EP at zomething.com Tue Aug 2 05:22:55 2005 From: EP at zomething.com (EP) Date: Tue, 2 Aug 2005 01:22:55 -0800 Subject: Dabo in 30 seconds? In-Reply-To: <1122914843.19618.343.camel@localhost.localdomain> References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <8ur1s2-r5t.ln1@strongwill.g2ctech> <1122914843.19618.343.camel@localhost.localdomain> Message-ID: <20050802012255.1482418023.EP@zomething.com> Jorge Godoy opined: > > We can find several problems, almost all of them can be solved with > > the admin's creativity. In response to which Cliff Wells posted an interpreter session: > >>> import creativity > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named creativity > >>> > > Nope. Not included with Python. Can't be used. Does anyone remember where all the modules in The Path originated from? Joesusedgui modules mingle with the standard library on my machine, and as long as the import statements work, maybe it doesn't matter. Which, again, is Python? Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 *********************************************** IDLE 1.1.1 >>> import creativity >>> creativity.whatis() Creativity is everywhere, even more so in the abysss >>> cheers From rkern at ucsd.edu Mon Aug 22 17:41:23 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 22 Aug 2005 14:41:23 -0700 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> <7x8xyw2z17.fsf@ruckus.brouhaha.com> Message-ID: Steve Holden wrote: > Robert Kern wrote: >>Coincidentally, those are exactly the reasons why I posted it in the >>first place. I care not a whit about decluttering the newgroup, an >>impossible task. > > It's clear that you care not a whit about it. Unfortunately the only way > to preserve bandwidth on this (or any other) chanell is for those with > nothing to say to not say it. Folks, if you want to preserve bandwidth from being wasted on irrelevant posts (like this one), delete your newsreader. USENET *is* clutter. Sometimes useful clutter. Entertaining clutter. *Shiny* clutter. But clutter. If you care about efficient use of bandwidth, this is not the place for you. James asked a question in such a way that I didn't think it would get answered. Judging from the other non-responses to his post, I was right. I showed him the way to ask questions such that they *will* get answered, and he came back, did so, and got his questions answered. That's worth 5 kb. -- 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 apardon at forel.vub.ac.be Fri Aug 5 03:50:09 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 5 Aug 2005 07:50:09 GMT Subject: Euclid's Algorithm in Python? References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> Message-ID: Op 2005-08-05, Jordan Rastrick schreef : > Raising an assertion error for a < b is a bit of overkill, since its > not really a case of bad input. So normally you see Euclid done like > this: > > def gcd(a,b): # All lowercase for a function is a bit more > conventional. > if a < b: > a, b = b, a # Ensures a >= b by swapping a and b if nessecary > while b != 0: # Note parentheses are unnessecary here in python > a, b = b, a % b > return a > > A bit more concise and no less readable (IMO). The if test is unnecessary. Should a be smaller than b, the two values will be swapped by the while body. -- Antoon Pardon From mwh at python.net Tue Aug 30 06:00:58 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 30 Aug 2005 10:00:58 GMT Subject: Release of PyPy 0.7.0 References: <4311ea97$0$1276$ed2619ec@ptn-nntp-reader02.plus.net> <1h20uj1.y52kzk1che9j9N%dial#####$$NOSPAM##$#$##tone@gmail.com> <43121002$0$97118$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: Michael Sparks writes: > Valentino Volonghi aka Dialtone wrote: > >> Michael Sparks wrote: >> >>> Would it be useful for people to start trying out their modules/code to >>> see if they work with this release, and whether they can likewise be >>> translated using the C/LLVM backends, or would you say this is too early? >>> (I'm more thinking in terms of it providing real world usecases in the >>> hope of finding things that don't work - rather than anything else) >> >> This is not how it works. > > I beg to differ - it is how it can work (just not the default or currently > recommended). The chance of any random module you have written being rpython is more or less zero, so it's not _that_ interesting for you to try to compile them with PyPy. > """You can also use the translate_pypy.py script to try out several smaller > programs, e.g. a slightly changed version of Pystone: > cd pypy/translator/goal > python translate_pypy.py targetrpystone > """ > > Which is pretty cool of course. For those of interest running pystone with > the pypy compiled native binary has the following results for pystones on > my machine: > > michaels at linux:~/pypy-0.7.0/pypy/translator/goal> ./pypy-c > debug: entry point starting > debug: argv -> ./pypy-c > debug: importing code > debug: calling code.interact() > Python 2.4.1 (pypy 0.7.0 build) on linux2 > Type "help", "copyright", "credits" or "license" for more information. > (InteractiveConsole) >>>>> from test import pystone >>>>> pystone.main(1000) > Pystone(1.1) time for 1000 passes = 13.97 > This machine benchmarks at 71.582 pystones/second >>>>> > > The same results for CPython: > michaels at linux:~/pypy-0.7.0/pypy/translator/goal> python > Python 2.4 (#1, Mar 22 2005, 21:42:42) > [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from test import pystone >>>> pystone.main() > Pystone(1.1) time for 50000 passes = 1.58 > This machine benchmarks at 31645.6 pystones/second > > Obviously therefore anyone seeking to translate their existing code from > python to an executable directly using pypy would not be doing it for > performance reasons (again, something I'm aware of watching the > updates come out and having run svn checkouts at previous times). No, you're still operating at the wrong level here (very easily done). This is the _translated PyPy_ interpreting pystone. If you run a _translated pystone_ you'll (hopefully) get a different, faster answer. In expected order of execution speed: interpreted pypy interpreting pystone translated pypy interpreting pystone cpython interpreting pystone translated pystone > Anyway, whether it's sensible or not I'm going to play with translating some > of my modules :) Whatever floats your boat :) Cheers, mwh -- Ability to type on a computer terminal is no guarantee of sanity, intelligence, or common sense. -- Gene Spafford's Axiom #2 of Usenet From no at spam Mon Aug 22 11:34:42 2005 From: no at spam (D H) Date: Mon, 22 Aug 2005 10:34:42 -0500 Subject: Sandboxes In-Reply-To: References: Message-ID: 42 wrote: > Or is this a hopeless cause? > > Finally, either way, would anyone recommend a different script engine > that might be more suitable for what I'm trying to accomplish that I > might not have looked at. I don't need much; it needs to work with C#, > and be able to easily interact with 'published' interface. I'd also like > to leverage a "popular" language instead of something obscure. You need a scripting language that is completely implemented in .NET (i.e. "managed"). Try Boo: http://boo.codehaus.org/ And then from your C# host, use the .NET security API for restricting what the script is allowed to do. See the example below, as well as msdn docs on SecurityPermissionFlag, PermissionSet, SetAppDomainPolicy... http://www.gamedev.net/community/forums/topic.asp?topic_id=264462&whichpage=1� And here are docs on using boo as an embedded scripting language: http://boo.codehaus.org/Boo+as+an+embedded+scripting+language From ptmcg at austin.rr.com Tue Aug 23 07:29:30 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 23 Aug 2005 04:29:30 -0700 Subject: Sanitizing untrusted code for eval() In-Reply-To: <3mv2a0F18cpprU1@uni-berlin.de> References: <3muhfnF18o689U1@uni-berlin.de> <430a1a45$1@nntp0.pdx.net> <3mv2a0F18cpprU1@uni-berlin.de> Message-ID: <1124796570.410355.279110@g49g2000cwa.googlegroups.com> Here's the pyparsing rendition - about 24 lines of code, and another 30 for testing. For reference, here's the JSON "bnf": object { members } {} members string : value members , string : value array [ elements ] [] elements value elements , value value string number object array true false null Download pyparsing at http://pyparsing.sourceforge.net. -- Paul from pyparsing import * TRUE = Keyword("true") FALSE = Keyword("false") NULL = Keyword("null") jsonString = dblQuotedString.setParseAction( removeQuotes ) jsonNumber = Combine( Optional('-') + ( '0' | Word('123456789',nums) ) + Optional( '.' + Word(nums) ) + Optional( Word('eE',exact=1) + Word(nums+'+-',nums) ) ) jsonObject = Forward() jsonValue = Forward() jsonElements = delimitedList( jsonValue ) jsonArray = Group( Suppress('[') + jsonElements + Suppress(']') ) jsonValue << ( jsonString | jsonNumber | jsonObject | jsonArray | TRUE | FALSE | NULL ) memberDef = Group( jsonString + Suppress(':') + jsonValue ) jsonMembers = delimitedList( memberDef ) jsonObject << Dict( Suppress('{') + jsonMembers + Suppress('}') ) lineComment = '//' + restOfLine jsonComment = FollowedBy('/') + ( cStyleComment | lineComment ) jsonObject.ignore( jsonComment ) testdata = """ { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": [{ "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML", "markup"] }] } } } """ results = jsonObject.parseString(testdata) import pprint pprint.pprint( results.asList() ) print results.glossary.title print results.glossary.GlossDiv print results.glossary.GlossDiv.GlossList.keys() Prints out (I've inserted blank lines to separate the output from the different print statements): [['glossary', ['title', 'example glossary'], ['GlossDiv', ['title', 'S'], ['GlossList', [['ID', 'SGML'], ['SortAs', 'SGML'], ['GlossTerm', 'Standard Generalized Markup Language'], ['Acronym', 'SGML'], ['Abbrev', 'ISO 8879:1986'], ['GlossDef', 'A meta-markup language, used to create markup languages such as DocBook.'], ['GlossSeeAlso', ['GML', 'XML', 'markup']]]]]]] example glossary [['title', 'S'], ['GlossList', [['ID', 'SGML'], ['SortAs', 'SGML'], ['GlossTerm', 'Standard Generalized Markup Language'], ['Acronym', 'SGML'], ['Abbrev', 'ISO 8879:1986'], ['GlossDef', 'A meta-markup language, used to create markup languages such as DocBook.'], ['GlossSeeAlso', ['GML', 'XML', 'markup']]]]] ['GlossSeeAlso', 'GlossDef', 'Acronym', 'GlossTerm', 'SortAs', 'Abbrev', 'ID'] From fakeaddress at nowhere.org Tue Aug 9 20:06:01 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 00:06:01 GMT Subject: Creating a virtual file system In-Reply-To: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> References: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> Message-ID: Atila Olah wrote: > My question is: How do I implement a virtual partition that acts like a > real file-system and is compleatly transparent to other programs? > Should I make a virtual file allocation table for a FAT32 partition or > simulate an NTFS? Or even further: How do I create a junction (or a > hard link) to it in "My network places" or in "Entire Network"? Hmmm... I seem to rememeber ... Ah, here... On: http://ask.slashdot.org/article.pl?sid=04/06/01/1810201 'Petard' and 'Foolhard' note that the Microsoft Windows IFS (Installable File System) Developer's Kit costs like $900. Doing it well would be a large and expensive project. Read their posts for more discouragement. > Thanks forward for help. Not exactly helpful was I? Sorry. -- --Bryan From lycka at carmen.se Tue Aug 2 12:34:51 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 02 Aug 2005 18:34:51 +0200 Subject: a pickle's pickle In-Reply-To: <1122998518.750304.191860@g44g2000cwa.googlegroups.com> References: <1122998518.750304.191860@g44g2000cwa.googlegroups.com> Message-ID: temposs at gmail.com wrote: > class TrainingMatrix: > matrix = [] > estimator = {} > wordInfo = {} > contextInfo = {} > totalWordsProcessed = 0 > numWords = 0 > numContexts = 0 > matrixWords = 0 Is there some confusion between the scope of the class object and the scopes of the instance objects perhaps? Are you aware of this distinction? See below: >>> class X: ... m=0 ... >>> X.m 0 >>> x=X() >>> x.m 0 >>> x.m += 5 >>> x.m 5 >>> X.m 0 Are you pickling the class object or an instance? If you are pickling the class: Why? Is the data really in the class object? If you are pickling an instance: Is the data in the class object? Is the data in another instance object? From sven-erik.tiberg at ltu.se Thu Aug 11 11:35:46 2005 From: sven-erik.tiberg at ltu.se (mitt) Date: Thu, 11 Aug 2005 17:35:46 +0200 Subject: Python DLL creation in MSVS.net Message-ID: <42fb7265$0$179$cc7c7865@news.luth.se> Hi. Trying to create dll's to interface python scripts to CHAI3D http://www.chai3d.org/ "Computer Haptics & Active Interfaces for 3D VR worlds". Any hint or docs that could be of use? Currently using the book "mit Python programieren" from dpunkt.verlag. -- Sven-Erik Tiberg -- Lulea Univ. of Technology. Sweden From fredrik at pythonware.com Thu Aug 11 08:25:17 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 11 Aug 2005 14:25:17 +0200 Subject: what's the exactly newsgroup url of python-list? References: Message-ID: Ben Finney wrote: > is a URL to a Usenet newsgroup, as > evidenced by the 'news:' schema part. If your web browser is > configured properly to invoke a newsreader (such as Thunderbird) for > 'news:' URLs, your newsrreader will then attempt to get the > comp.lang.newsgroup from your default NNTP server. footnote: if you have no such server, things won't work. for an excellent way to read the python mailing list via a news- reader even if you don't have access to a "real" NNTP server, see http://gmane.org/ (quick instructions: point the newsreader to "news.gmane.org", and look for the group "gmane.comp.python.general".) From saint.infidel at gmail.com Fri Aug 26 11:09:41 2005 From: saint.infidel at gmail.com (infidel) Date: 26 Aug 2005 08:09:41 -0700 Subject: question on "import __main__" In-Reply-To: References: Message-ID: <1125068981.559246.66940@g44g2000cwa.googlegroups.com> > import __main__ > if __name__!='__main__': > print 1 > > print 2 > > when i run test.py, i got > 2 > on the screen. > > now, i have some question about the code, 1. since no __main__ module at > all, why it's legal to write "import __main__"? __main__ is the module that the interpreter starts executing. So "import __main__" is legal, though I'm guessing it doesn't really do anything because the module is already loaded (since it's running). > 2. since if running a script independently, the __name__ should be > '__main__', why it's not in the above code? But it is. From patrick.m.lahey at aero.org Tue Aug 23 14:53:33 2005 From: patrick.m.lahey at aero.org (patrick.m.lahey at aero.org) Date: 23 Aug 2005 11:53:33 -0700 Subject: where does __class__ come from? Message-ID: <1124823213.701488.57580@z14g2000cwz.googlegroups.com> Newbie here... Ok, the following code: class Base: _count = 0 def __init__(self): self.__class__._count += 1 print dir(self) x = Base() the output is: ['__doc__', '__init__', '__module__', '_count'] Notice that __class__ is no where to be seen! Where does __class__ come from, what does it mean and what else is being hidden? I am used to using dir(...) to figure out what I can play with. Clearly that does not always work... :-( Thanks! From learningProgramming at gmail.com Thu Aug 25 21:22:49 2005 From: learningProgramming at gmail.com (Learning Python) Date: 25 Aug 2005 18:22:49 -0700 Subject: argument matching question In-Reply-To: References: <1125018189.157888.113500@g47g2000cwa.googlegroups.com> Message-ID: <1125019369.333450.230160@g43g2000cwa.googlegroups.com> thanks, got it. I want to test the **name option for argument matching. From apardon at forel.vub.ac.be Sun Aug 14 10:41:42 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 14 Aug 2005 14:41:42 GMT Subject: Euclid's Algorithm in Python? References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> <1123461062.574511.278540@g43g2000cwa.googlegroups.com> <42f6aef7.870709213@news.oz.net> Message-ID: On 2005-08-08, Bengt Richter wrote: > On 7 Aug 2005 17:31:02 -0700, "Jordan Rastrick" wrote: > >>Good point. I suppose I'd only ever seen it implemented with the if >>test, but you're right, the plain while loop should work fine. Silly >>me. >> >>def gcd(a,b): >> while b != 0: >> a, b = b, a%b >> return a >> >>Even nicer. >> > what is the convention for handling signed arguments? E.g., As far as I understand the convention is it doesn't make sense to talk about a gcd if not all numbers are positive. I would be very interested if someone knows what the gcd of 3 and -3 should/would be. -- Antoon Pardon From peter at engcorp.com Mon Aug 22 12:28:12 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Aug 2005 12:28:12 -0400 Subject: split function In-Reply-To: References: Message-ID: Mohammed Altaj wrote: > I am reading data from file using readlines() to list , my question > is how to deal with space between any two numbers , I mean , my data What do you mean by "deal with"? Please describe the input and the desired output, or what operations you are trying to perform, or something. "Deal with" could mean anything, so it means nothing. > looks like > 1 3 > 3 4 > 5 2 > 6 1 > > I tried to with my data as it, but i couldn't , so i removed the spaces > 13 > 34 > 52 > 61 > > But when i deal with large number > 9 !!!! , i tried to use split > function , but doesn't work , I can attach my code if its good idea to do ,, It would probably be a good idea to attach some code, if it's not too long (no longer than 100 lines or so, preferably less). I'm afraid that I'm having trouble understanding what you want, and I suspect many other people are too. I also recommend showing an example, with input and output, of what you want to achieve: the "before and after" picture. An example goes a long way towards communicating one's goal. -Peter From uval at rz.uni-karlsruhe.de Wed Aug 10 17:02:28 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Wed, 10 Aug 2005 23:02:28 +0200 Subject: providing arguments to base.__init__ In-Reply-To: <1123707423.615710.196290@g43g2000cwa.googlegroups.com> References: <1123707423.615710.196290@g43g2000cwa.googlegroups.com> Message-ID: Rob Conner schrieb: > seems like you are not running the correct wavePlayer. make sure you > don't have 2 wavePlayer vars. > I am not sure I understand right wavePlayer.py is a module I wrote myself and placed to site-packages so there is no other wavePlayer module I put a class wavePlayer into it and after import wavePlayer p = wavePlayer.wavePlayer() I got this error Regards, Daniel From tjreedy at udel.edu Wed Aug 31 23:19:29 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2005 23:19:29 -0400 Subject: OpenSource documentation problems References: <43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net> <200508312026.04152.hancock@anansispaceworks.com><43166301.9060401@holdenweb.com> Message-ID: "Robert Kern" wrote in message news:df5oa1$v53$1 at sea.gmane.org... > Or perhaps more to the point, that http://pydoc.amk.ca/frame.html should > be better-publicized. This seems to be an experiment that has not been updated since 2.3.4. tjr From accepted at ukr.net Mon Aug 1 11:07:59 2005 From: accepted at ukr.net (Michael Rybak) Date: Mon, 1 Aug 2005 18:07:59 +0300 Subject: 2-player game, client and server at localhost In-Reply-To: References: Message-ID: <1119810365.20050801180759@ukr.net> Again, thank you very much for your help. DLB> The server should basically handle the multiple client DLB> connection logic, and determination of interactions between movable DLB> objects -- collision detection, for example (and I don't mean in the DLB> terms of graphics rendering but in terms of object one at current DLB> movement intersecting object two moving at some other vector). My problem is: there are about 30 movable objects, so transferring all their coordinates is much more traffic consuming (about 150 bytes per transfer) rather than sending only user's motions (10 bytes per transfer). But on the other hand, sending user's motions between two non-server-neither-clients means that I needed stricted synchronization, which means the turn-based approach, as you've said. DLB> I'm also NOT a game programmer, so I'm not sure how well most of DLB> them separate screen updates from I/O, but I'd turn the above loop into DLB> something like: DLB> create screen thread DLB> create I/O thread DLB> {screen thread} DLB> loop: DLB> compute/display screen using snapshot of "local status" DLB> {I/O thread} DLB> loop DLB> if keyboard has activity DLB> read data DLB> send data to server DLB> if server has activity DLB> read data DLB> update local status DLB> Note that the keyboard, in this simple example, never affects DLB> the local (client) display -- only the status sent back by the server is DLB> used. Okay, you may need to process things like "quit" locally . Well, this look really elegant, but will need me some time to rewrite my networking that way. Thank's a lot, I'll let you know when it works. [..snip..] ]DLB> The server looks like: DLB> loop DLB> if new client connect DLB> add client to list of clients DLB> send client current status DLB> if data from client DLB> update world state (collision detects, damage, etc.) DLB> for c in client list DLB> send current status DLB> if client disconnect DLB> remove client from list consider this part: DLB> if data from client DLB> update world state (collision detects, damage, etc.) DLB> for c in client list DLB> send current status the problem is - I should do this not "if data from client", but every 50 milliseconds or so, because objects are still moving when not affected by users. To give you a better idea of what my game is: Each player controls a snake, which is 2 to 12 balls connected to each other with ropes; by mouse motions you move the snake's head, and the rest of the body moves adhering normal physics. The objective/gameplay is unimportant here, but if you're curios - all the balls of your snake are bullets, and right-clicking releases current tail. So, you have to spin around, and release the tail in appropriate moment so it reaches your opponent, causing as much damage as much impulse it had. There are health-pots and other stuff on game field of course. So, you see - server will have to send current status as much time per second, as much fps I want, and that's quite a lot of data. I'd also like to mention (if I haven't already) that I have a 33.6 modem, while the friend I'm testing with has a 2 Mbit dedicated line, if this is the right term. I also was advised (by Peter Hansen) to try using Twisted, Pyro os something like that. I've looked at Pyro, and tried using it, without a lot of success compared to what I have now. I'm starting a new topic here, describing my experiment. DLB> Recall my warning -- I'm not a game programmer; this is just how DLB> /I'd/ consider implementing something like this. You're being very helpful anyway :) DLB> -- DLB> > ============================================================== < DLB> > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < DLB> > wulfraed at dm.net | Bestiaria Support Staff < DLB> > ============================================================== < DLB> > Home Page: < DLB> > Overflow Page: < -- Best Regards, Michael Rybak mailto:accepted at ukr.net From see.my at signature.net Tue Aug 16 13:49:17 2005 From: see.my at signature.net (=?ISO-8859-2?Q?Mateusz_=A3oskot?=) Date: Tue, 16 Aug 2005 19:49:17 +0200 Subject: GUI tookit for science and education In-Reply-To: References: Message-ID: Thank you all for valuable responses. I think I will stick to Tk and Tkinter. Cheers -- Mateusz ?oskot, mateusz (at) loskot (dot) net Registered Linux User #220771 From u.hobelmann at web.de Fri Aug 12 07:39:45 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Fri, 12 Aug 2005 13:39:45 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <3m3g41Fuodd2U1@individual.net> J?rgen Exner wrote: > Just for the records at Google et.al. in case someone stumbles across Xah's > masterpieces in the future: > Xah is very well known as the resident troll in many NGs and his > 'contributions' are less then useless. And you are the resident troll-reply service, posting this reply every time? > Best is to just ignore him. You just broke that rule. > But for heaven's sake unless you want to embarrass yourself really badly > don't take any of his postings serious because he has proven again and again > that he has no clue whatsoever about computer science or programming. Fine. Many people don't. Whoever takes the time to read Xah's postings (I don't) will probably be able to find that out by himself. -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From fakeaddress at nowhere.org Fri Aug 26 14:46:27 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 26 Aug 2005 18:46:27 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> Message-ID: <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Steve Holden wrote: > Bryan Olson wrote: >> Antoon Pardon wrote: >> > It probably is too late now, but I always felt, find should >> > have returned None when the substring isn't found. >> >> None is certainly a reasonable candidate. [...] >> The really broken part is that unsuccessful searches return a >> legal index. >> > We might agree, before further discussion, that this isn't the most > elegant part of Python's design, and it's down to history that this tiny > little wart remains. I don't think my proposal breaks historic Python code, and I don't think it has the same kind of unfortunate subtle consequences as the current indexing scheme. You may think the wart is tiny, but the duct-tape* is available so let's cure it. [*] http://www.google.com/search?as_q=warts+%22duct+tape%22 >> My suggestion doesn't change what find() returns, and doesn't >> break code. Negative one is a reasonable choice to represent an >> unsuccessful search -- provided it is not a legal index. Instead >> of changing what find() returns, we should heal the >> special-case-when-index-is-negative-in-a-certain-range wart. >> >> > What I don't understand is why you want it to return something that > isn't a legal index. In this case, so that errors are caught as close to their occurrence as possible. I see no good reason for the following to happily print 'y'. s = 'buggy' print s[s.find('w')] > Before using the result you always have to perform > a test to discriminate between the found and not found cases. So I don't > really see why this wart has put such a bug up your ass. The bug that got me was what a slice object reports as the 'stop' bound when the step is negative and the slice includes index 0. Took me hours to figure out why my code was failing. The double-meaning of -1, as both an exclusive stopping bound and an alias for the highest valid index, is just plain whacked. Unfortunately, as negative indexes are currently handled, there is no it-just-works value that slice could return. -- --Bryan From paolo_veronelli at libero.it Fri Aug 12 07:28:23 2005 From: paolo_veronelli at libero.it (Paolino) Date: Fri, 12 Aug 2005 13:28:23 +0200 Subject: __getattribute__ for class object In-Reply-To: References: Message-ID: <42FC87D7.3080807@libero.it> Sylvain Ferriol wrote: > hello > when i define __getattribute__ in a class, it is for the class instances > but if i want to have a __getattribute__ for class attributes > > how can i do that ? > Skating on thin ice eh.Read something on metaclasses. class Meta(type): def __getattribute__(klass,attr): value=type.__getattribute__(klass,attr) print attr,'==',value return value class Foo(object): __metaclass__=Meta a=2 Foo.a Paolino From peter at engcorp.com Thu Aug 11 08:26:39 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 11 Aug 2005 08:26:39 -0400 Subject: Creating Palm OS programs with python? In-Reply-To: References: Message-ID: djanvk at gmail..com wrote: > QUick question: > > Is it possible to create a palm os program to use on a PDA with > python? Practically speaking, no. I did find it relatively easy to install and learn enough of Plua to write a useful app for my old Palm V, however, and Lua isn't so far from Python that you feel like you've travelled to a foreign country to do it. -Peter From rafi at free.fr Mon Aug 22 17:04:01 2005 From: rafi at free.fr (rafi) Date: Mon, 22 Aug 2005 23:04:01 +0200 Subject: loop in python In-Reply-To: References: Message-ID: <430a3db7$0$12396$626a14ce@news.free.fr> km wrote: > Also the first thing any newbie to python asks me is abt "raw speed > in comparison with similar languages like perl" when i advocate > python to perl. Always the same chorus... Just tell the newbies that speed is not on their top list. If most of the world's computer programs where running two times slower but with two times less bugs, imagine how many hours we would benefit... -- rafi "Imagination is more important than knowledge." (Albert Einstein) From tjreedy at udel.edu Fri Aug 5 21:30:07 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 5 Aug 2005 21:30:07 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: wrote in message news:1123270841.195692.21470 at g47g2000cwa.googlegroups.com... > I've heard 2 people complain that word 'global' is confusing. I did to at first. > Perhaps 'modulescope' or 'module' would be better? Global is an somewhat short adjective that plausibly becomes a noun when pluralized. That is hard to match. I have thought of 'modular' as the actual meaning of 'global', but 'modulars' does not sound as good to me. > Am I the first peope to have thought of this and suggested it? You are the first people I remember making at least the 'modulescope' suggestion. Searching the newsgroup archive at Google would make sure ;-). > Is this a candidate for Python 3000 yet? Unlikely. I suspect that global meaning global to the module (as opposed to the collection of modules or compilation units) is established CS usage. Terry J. Reedy From alanmk at hotmail.com Mon Aug 29 14:58:09 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Mon, 29 Aug 2005 19:58:09 +0100 Subject: python xml DOM? pulldom? SAX? In-Reply-To: References: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> Message-ID: [Alan Kennedy] >>SAX is perfect for the job. See code below. [Fredrik Lundh] > depends on your definition of perfect... Obviously, perfect is the eye of the beholder ;-) [Fredrik Lundh] > using a 20 MB version of jog's sample, and having replaced > the print statements with local variable assignments, I get the > following timings: > > 5 lines of cElementTree code: 7.2 seconds > 60+ lines of xml.sax code: 63 seconds > > (Python 2.4.1, Windows XP, Pentium 3 GHz) Impressive! At first, I thought your code sample was building a tree for the entire document, so I checked the API docs. It appeared to me that an event processing model *couldn't* obtain the text for the node when notified of the node: the text node is still in the future. That's when I understood the nature of iterparse, which must generate an event *after* the node is complete, and it's subdocument reified. That's also when I understood the meaning of the "elem.clear()" call at the end. Only the required section of the tree is modelled in memory at any given time. Nice. There are some minor inefficiencies in my pure python sax code, e.g. building the stack expression for every evaluation, but I left them in for didactic reasons. But even if every possible speed optimisation was added to my python code, I doubt it would be able to match your code. I'm guessing that a lot of the reason why cElementTree performs best is because the model-building is primarily implemented in C: Both of our solutions run python code for every node in the tree, i.e. are O(N). But yours also avoids the overhead of having function-calls/stack-frames for every single node event, by processing all events inside a single function. If the SAX algorithm were implemented in C (or Java) for that matter, I wonder if it might give comparable performance to the cElementTree code, primarily because the data structures it is building are simpler, compared to the tree-subsections being reified and discarded by cElementTree. But that's not of relevance, because we're looking for python solutions. (Aside: I can't wait to run my solution on a fully-optimising PyPy :-) That's another nice thing I didn't know (c)ElementTree could do. enlightened-ly'yrs, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From gregpinero at gmail.com Tue Aug 9 12:32:15 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 9 Aug 2005 12:32:15 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: <312cfe2b05080909324b1929db@mail.gmail.com> Ahh, so it's a mutable thing. That makes sense that I can't change a mutable object and thus can't affect it outside of the function. Does that mean Python functions aren't always byref, but are sometimes byval for nonmutables? -Greg On 8/9/05, Dennis Lee Bieber wrote: > On Tue, 9 Aug 2005 10:53:15 -0400, Gregory Pi?ero > declaimed the following in comp.lang.python: > > Is this the third time this week that this has come > up? > > > Hey guys, would someone mind giving me a quick rundown of how > > references work in Python when passing arguments into functions? The > > code below should highlight my specific confusion: > > > They work just like they do everywhere else... > > Read the manuals on mutable and immutable objects. (I'd suggest > language reference chapter 3 and 4, library reference chapter 2.3.6, > 2.3.7) > > "names" in Python are movable labels attached to objects; they > are not fixed locations in memory to which object are copied; hence they > do not behave like variables in traditional languages. > > > > > bool1=True > > immutable object -- "bool1" is a label attached to a fixed > object > > > lst1=[1,2,3] > > > mutable object -- "lst1" is a label attached to a box > containing objects > > > def func1(arg1): arg1.append(4) > > > > "arg1" is a label attached to whatever object was passed in... > .append is an operation that changes what is /inside/ that > object > > > def func2(arg1): arg1=False > > > "arg1" is a label attached to whatever was passed in... > Assignment (especially of an immutable object) takes that label > OFF of the object that was passed in, and moves it the object of the > assignment. It does not move the label that is outside the call. > > > >>func1(lst1) > > >>lst1 > > [1,2,3,4] > > > "lst1" is the label of the box; inside of func1, that box has > two labels: "lst1" and "arg1". You used the "arg1" label to locate the > box, and then you changed what was inside the box. Outside the function, > you used the "lst1" label to find the /same/ box and report what was > inside it. > > > >>func2(bool1) > > >>bool1 > > True > > > "bool1" is the label of a non-box -- a "true". Inside the > function "true" has initially two labels: "bool1" and "arg1". You then > moved the "arg1" label from "true" to a different object "false". > "bool1" does not move, and still references the "true". > > > -- > > ============================================================== < > > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > > wulfraed at dm.net | Bestiaria Support Staff < > > ============================================================== < > > Home Page: < > > Overflow Page: < > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From dacut at kanga.org Mon Aug 8 18:51:38 2005 From: dacut at kanga.org (David Cuthbert) Date: Mon, 08 Aug 2005 18:51:38 -0400 Subject: python for microcontrollers In-Reply-To: <7xd5oof5qj.fsf@ruckus.brouhaha.com> References: <42f7c8d4$1@news.orcon.net.nz> <7xd5oof5qj.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > I don't think you want to do this. Runtime type tags and the overhead > of checking them on every operation will kill you all by themselves. > Processors like that haven't been used much as Lisp targets either, > for the same reasons. Pick a different language. I was thinking that you could avoid this by adding some type inference to Python and/or reducing everything to two basic types (strings and ints), but the end result would require a lot of work and not look much like Python. For a PIC, I'm not even sure I'd want to use C++. Then again, I'm not much of a fan of BASIC stamp modules, either, so... From http Sat Aug 6 20:27:33 2005 From: http (Paul Rubin) Date: 06 Aug 2005 17:27:33 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <87wtn245qo.fsf@wilson.rwth-aachen.de> <86slxpyxp2.fsf@bhuda.mired.org> <873bporhgm.fsf@wilson.rwth-aachen.de> <86mznvyge7.fsf@bhuda.mired.org> Message-ID: <7xhde2twui.fsf@ruckus.brouhaha.com> Mike Meyer writes: > Is there a free language you consider successful? I can't think of any > that are a lot more (i.e. - an order of magnitude) successful than > Python that aren't derived from C. SQL > Have you noticed that languages with really cool features aren't very > popular? Unification, prototypes, real macros, and dataflow variables > all come to mind. Lisp, except I'm not sure what you mean by dataflow variables. Does that mean logic variables like in Oz? > Some of the languages that sport these features even > come with an integrated GUI/IDE, but they have at most 99 projects > mentioning them on sourceforge - assuming they are listed at all. You could have said the same thing for dynamic types and GC not that long ago. Users are couthing up. From mensanator at aol.com Sun Aug 7 21:35:24 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 7 Aug 2005 18:35:24 -0700 Subject: Euclid's Algorithm in Python? References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> <1123449353.962000.217120@g14g2000cwa.googlegroups.com> Message-ID: <1123464924.738713.199180@g14g2000cwa.googlegroups.com> Erik the Red wrote: > So, I did the following: > --- > a=input("Give me an integer") > b=input("Give me another integer") > > def gcd(a,b): > > if a < b: > a, b = b, a > while b != 0: > a, b = b, a % b > return a > --- > But, in the xterm, it terminates after "Give me another integer." > > Is Euclid's Algorithm supposed to be implemented in such a way as to be > used as a tool to find the GCD of two integers, or have I > misinterpreted the intent of the algorithm? Personally, I would just use a math library that includes GCD and probably does it more efficiently that I could. An example of which is GMPY, the GNU Multiple Precision C library with a Python wrapper. But if I wanted to roll my own, I would implement the Extended Euclidean Algorithm which produces some usefull information that can be used to solve a Linear Congruence in addition to finding the GCD. A Linear Congruence would be X*A = Z (mod Y) where "=" means "is congruent to". Given X, Y and Z, A can be solved IIF GCD(X,Y) divides Z. If you use the Extended Euclidean Algorithm to find GCD(X,Y) you will have the additional parameters needed to solve the Linear Congruence (assuming it is solvable). For example, I run into problems of the form G = (X*A - Z)/Y where I want to find an integer A such that G is also an integer (X, Y and Z are integers). Lucky for me, the RHS can be directly converted to a Linear Congruence: X*A = Z (mod Y). And in my particular problems, X is always a power of 2 and Y always a power of 3 so the GCD(X,Y) is always 1 which will always divide Z meaning my problems are _always_ solvable. And GMPY has a function that directly solves Linear Congruence: divm(a,b,m): returns x such that b*x==a modulo m, or else raises a ZeroDivisionError exception if no such value x exists (a, b and m must be mpz objects, or else get coerced to mpz) So the first integer solution to 35184372088832*A - 69544657471 ------------------------------ 19683 is >>> A=collatz_functions.gmpy.divm(69544657471,35184372088832,19683) >>> A mpz(15242) Checking, >>> G = divmod(35184372088832*15242-69544657471,19683) >>> G (27245853265931L, 0L) Of course, what the gods give they also take away. It turns out that the GMPY divm() function has a bug (whether in the underlying GMP C code or the Python wrapper I don't know). It has a memory leak when called repeatedly with large numbers making it useless to me. But I caught another lucky break. GMPY also provides a modulo inverse function from which one can easily derive the linear congruence. And this function doesn't exhibit the memory leak. But luck favors the prepared mind. I was able to come up with a workaround because I had gone to the trouble of working up an Extended Euclidean Algorithm prior to discovering that I didn't need it. But during the course of which, I also learned about modulo inverse which was the key to the workaround. From polytechnique at gmail.com Tue Aug 30 10:44:48 2005 From: polytechnique at gmail.com (DENG) Date: 30 Aug 2005 07:44:48 -0700 Subject: how to join two Dictionary together? Message-ID: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> dict1={...something...} dict2={...somethind else ..} dict1 + dict2 that's does works ..:(, it's not like List... anyone can tell me how to get it? thanks in advance From ptmcg at austin.rr.com Fri Aug 12 01:38:10 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 11 Aug 2005 22:38:10 -0700 Subject: How do these Java concepts translate to Python? References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <1123825090.739153.189890@o13g2000cwo.googlegroups.com> Instance variables are typically defined in __init__(), but they can be added to an object anywhere. The only exception is when defining the magic __slots__ class variable to pre-define what the allowed instance variables can be. class A: pass a = A() a.instVar1 = "hoo-ah" a.instVar2 = "another" Try that in C++ or Java! -- Paul From onurb at xiludom.gro Wed Aug 17 10:04:14 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 17 Aug 2005 16:04:14 +0200 Subject: looping list problem In-Reply-To: References: Message-ID: <430343df$0$5476$636a15ce@news.free.fr> Fredrik Lundh wrote: > Jon Bowlas wrote: (snip) >>But I get the following error- Line 5: Yield statements are not allowed. > > > umm. I might be missing something, but I cannot find any trace of that > error message in the Python interpreter source code. it doesn't even look > like a Python traceback. did you perhaps forget to tell us that you're using > some fancy web framework that uses Python in its own idiosyncratic way? Some fancy web framework named Zope, I guess... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From rkern at ucsd.edu Wed Aug 17 22:11:36 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 17 Aug 2005 19:11:36 -0700 Subject: GUI tookit for science and education In-Reply-To: References: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> Message-ID: James Sungjin Kim wrote: > Robert Kern wrote: > >>... Once you move outside of that box and start doing real >>programming, Python (with Numeric, ipython, matplotlib, scipy, et al.) >>beats MATLAB handily. > > As one who is really newbie on Python, In MATLAB we can represent the > codes for the matrix manipulation as really like mathematical forms, e.g., > > MATLAB> H = U*D*V' > > It definitely makes the science programmer easier and faster to write > their codes. Careful there. That's a huge generalization. Most scientific programmers don't only do matrix manipulations. MATLAB makes matrix manipulation easier, not writing scientific programs in general. Like I said, if you're only doing exactly what MATLAB was designed for, interactive manipulation of matrices, then MATLAB will be easier. MATLAB pays a price for that convenience, though. Its facilities for writing more general programs (by which I mean anything beyond "H = U*D*V'"; that includes most "scientific" programs) are severely lacking. Once a MATLAB program gets large enough that it doesn't fit into one file, it's unreadable, and if I'm given one that I need to read/use/modify for my research, I refuse. Life is just too damn short. I'd rather rewrite the thing myself in Python; indeed, I *have* on a few occasions. I can do a whole lot more in Python much easier. If that means I have to do H = dot(U, dot(D, transpose(V))) or (if U, D, V are scipy.mat() instances) H = U*D*V.T then I'm more than happy with that tradeoff. The small syntactic conveniences MATLAB provides are dwarfed by the intrinsic power of Python. -- 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 kst-u at mib.org Sun Aug 14 13:37:05 2005 From: kst-u at mib.org (Keith Thompson) Date: Sun, 14 Aug 2005 17:37:05 GMT Subject: Jargons of Info Tech industry ... and Xah Lee (I mean Jerry) Springer References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: Alex writes: > Xah Lee wrote: [SSSNNNIIIPPP!!!] > I've extracted the preceding castigating snippets from Mr. Lee's > Jargon "thesis". [SSSNNNIIIPPP!!!] *Please stop posting followups to this off-topic nonsense. Just ignore it. Responding to spam is spam; responding to a troll gives him exactly what he wants and annoys the heck out of the rest of us. +-------------------+ .:\:\:/:/:. | PLEASE DO NOT | :.:\:\:/:/:.: | FEED THE TROLLS | :=.' - - '.=: | | '=(\ 9 9 /)=' | Thank you, | ( (_) ) | Management | /`-vvv-'\ +-------------------+ / \ | | @@@ / /|,,,,,|\ \ | | @@@ /_// /^\ \\_\ @x@@x@ | | |/ WW( ( ) )WW \||||/ | | \| __\,,\ /,,/__ \||/ | | | jgs (______Y______) /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ============================================================== Followups redirected appropriately. -- Keith Thompson (The_Other_Keith) kst-u at mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. From johnjsal at NOSPAMgmail.com Thu Aug 18 18:24:35 2005 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Thu, 18 Aug 2005 18:24:35 -0400 Subject: up to date books? In-Reply-To: <1124401205.450291.176170@g44g2000cwa.googlegroups.com> References: <1124401205.450291.176170@g44g2000cwa.googlegroups.com> Message-ID: Thank you very much for that response! aleaxit at gmail.com wrote: > John Salerno wrote: > ... > >>Just one more quick question: I'm basically learning programming for >>fun, and I'm concentrating on C# right now. Python seems interesting, >>but I was wondering if I should even bother. Would it supplement C# in >>any way, or can C# do everything Python can? > > > C# and Python are both Turing-complete (net of limitations to finite > amounts of storage, in the real world), so of course "they can do" > exactly the same things as each other in some pretty strong sense -- so > can machine language, Fortran, ... > > Exactly because of this, this is hardly ever a sensible question to > ask. It clearly can be more _convenient and practical_ to "do some > thing" in C# than machine language, because C# is a higher-level > language than machine language, which increases your productivity (this > applies to most tasks, but for a few things, such as some > interrupt-response routines in embedded systems, machine language can > instead be vastly more practical and productive). > > Similarly, Python is a higher-level language than C#, which further > increases your productivity (and again this applies to most tasks, but > for a few lower-level things C# may in fact be more practical and > productive). > > Besides considerations connected to the language themselves, similar > issues (pushing the same way) apply to their implementations -- Python > vs C# as well as C# vs machine language. As far as I know, to deploy > C# applications you need a dotNet runtime (or perhaps a Mono runtime, > if you find it robust enough for your purposes); with machine language > you'd be restricted to a particular family of CPUs (or emulators > thereof, such as VirtualPC to emulate intel CPUs under MacOSX with > PowerPC CPUs). Similarly, with Python you can deploy on the same > runtimes as you can with C# (using the IronPython implementation, which > compiles Python to Microsoft CLR intermediate-code) -- but > alternatively you can deploy to JVMs (with the Jython implementation), > to a variety of architectures and OSs using a Python-dedicated > runtime/VM (with the classic, CPython implementation), to some Nokia > cellphones (Series 60 ones, I believe) using the Python runtime which > Nokia has developed and released, one day to the Parrot VM, etc, etc... > in practice, therefore, Python pervades more niches than C#, and thus > offers more practical deployment options, just like C# is more > pervasive and deployable than machine language. However, I believe the > language-level (and therefore programmer-productivity) issue will be > even more important in most cases. > > > Alex > From whp at wp.pl Fri Aug 26 09:32:31 2005 From: whp at wp.pl (Wojciech Halicki-Piszko) Date: Fri, 26 Aug 2005 15:32:31 +0200 Subject: How to know if connection is active when using telnetlib? Message-ID: How to know if connection is active after telnetlib.Telnet.open(host,port)? From bob at greschke.com Wed Aug 3 00:06:29 2005 From: bob at greschke.com (Bob Greschke) Date: Tue, 2 Aug 2005 22:06:29 -0600 Subject: Setting a drive's volume label References: Message-ID: <2NmdnaO6zf9Q323fRVn-pQ@nmt.edu> Looks like the "label" system command will do it in Windows. That's good enough for this exercise. So, in Linux...??? "Bob Greschke" wrote in message news:geydnbyQRpbtiW3fRVn-tw at nmt.edu... > ...the name for a drive (hard or removable) that shows up when, for > example, a USB flash drive is recognized by the system. I don't know if > this shows up somewhere in Linux. > > Can this be set from Python? I guess it would be some MFC call in Windows > (I don't know anything about doing that), and some ??? call in Linux? > Could use both. > > Thanks! > > Bob > > From martin at v.loewis.de Sun Aug 21 10:34:28 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 21 Aug 2005 16:34:28 +0200 Subject: Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out) In-Reply-To: References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <8xWNe.24050$HM1.696102@twister1.libero.it> Message-ID: <430890f5$0$16648$9b622d9e@news.freenet.de> Giovanni Bajo wrote: >>I'm sure Martin would be happy to consider a patch to make the build >>system more efficient. :) > > Out of curiosity, was this ever discussed among Python developers? Would > something like scons qualify for this? OTOH, scons opens nasty > self-bootstrapping issues (being written itself in Python). No. The Windows build system must be integrated with Visual Studio. (Perhaps this is rather, "dunno: is it integrated with VS.NET 2003?") When developing on Windows, you really want all the support you can get from VS, e.g. when debugging, performing name completion, etc. To me, this makes it likely that only VS project files will work. > Before considering a patch (or even a PEP) for this, the basic requirements > should be made clear. I know portability among several UNIX flavours is one, > for instance. What are the others? Clearly, the starting requirement would be that you look at the build process *at all*. The Windows build process and the Unix build process are completely different. Portability is desirable only for the Unix build process; however, you might find that it already meets your needs quite well. Regards, Martin From peter at engcorp.com Wed Aug 10 07:28:53 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Aug 2005 07:28:53 -0400 Subject: python for microcontrollers In-Reply-To: <42f98b24$1@news.orcon.net.nz> References: <42f7c8d4$1@news.orcon.net.nz> <7xd5oof5qj.fsf@ruckus.brouhaha.com> <42f91c1c$1@news.orcon.net.nz> <42f98b24$1@news.orcon.net.nz> Message-ID: <2uydneEHCfjBeGTfRVn-oQ@powergate.ca> Evil Bastard wrote: > Peter Hansen wrote: >>grabbing >>an off the shelf Forth might be a more productive use of your time. > > Heh, methinks one might be misunderstanding the Forth culture. Lacking entirely in any knowledge of it whatsoever would be a more accurate description. "Ignorant of" is even shorter, though no less accurate. ;-) > Forth can, and so often does, disappear up its own ring-hole in the > blink of an eye. Its hardcore extensibility is so often its own downfall > since. with the way many people work with it. it earns its reputation as > a 'write-only language' over and over again. Quite often, to understand > a piece of Forth code, you have to crawl in and out of all the author's > body cavities many times. Okay, fine. I can accept that Forth code can be inscrutable. A belief that that would be the case is one reason I've actually never really done any Forth. But I thought _you_ were the one who brought up Forth, so clearly you can't be against it on basic principles. > What I'm saying is that it often takes less time to write a Forth than > to properly learn and understand someone else's implemention. In this > way, Forth is like undergarments - you can admire those worn by others, > but you sure as hell don't want to wear them yourself. :P Okay, but this implies either that Forth implementations are written in Forth (and no, e.g. C) or that people who implement Forth in, say, C let their Forth-inspired inclination to write inscrutable code bleed over into their C code as well. So unless you're the only person around able to resist writing a poor implementation of Forth, I'm still puzzled why you would want to write your own when existing implementations could actually be just as readable and useful (or more so?) than whatever you could whip up as a one-off for this project. (Not trying to argue, just understand, because it looks like you're conflating Forth programs with Forth implementations, or perhaps I'm even more ignorant than noted above and am missing a key point. :-) -Peter From fakeaddress at nowhere.org Tue Aug 9 21:30:56 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 01:30:56 GMT Subject: zipped socket In-Reply-To: References: <1123474441.944938.165170@g49g2000cwa.googlegroups.com> Message-ID: jepler at unpythonic.net wrote: > As far as I know, there is not a prefabbed solution for this problem. One > issue that you must solve is the issue of buffering (when must some data you've > written to the compressor really go out to the other side) and the issue of > what to do when a read() or recv() reads gzipped bytes but these don't produce any > additional unzipped bytes---this is a problem because normally a read() that > returns '' indicates end-of-file. > > If you only work with whole files at a time, then one easy thing to do is use > the 'zlib' encoding: > >>> "abc".encode("zlib") > "x\x9cKLJ\x06\x00\x02M\x01'" > >>> _.decode("zlib") > 'abc' > ... but because zlib isn't self-delimiting, this won't work if you want to > write() multiple times, or if you want to read() less than the full file That's basically a solved problem; zlib does have a kind of self-delimiting. The key is the 'flush' method of the compression object: some_send_function( compressor.flush(Z_SYNC_FLUSH) ) The Python module doc is unclear/wrong on this, but zlib.h explains: If the parameter flush is set to Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far. There's also Z_FULL_FLUSH, which also re-sets the compression dictionary. For a stream socket, we'd usually want to keep the dictionary, since that's what gives us the compression. The Python doc states: Z_SYNC_FLUSH and Z_FULL_FLUSH allow compressing further strings of data and are used to allow partial error recovery on decompression That's not correct. Z_FULL_FLUSH allows recovery after errors, but Z_SYNC_FLUSH is just to allow pushing all the compressor's input to the decompressor's output. -- --Bryan From simon.brunning at gmail.com Mon Aug 15 10:54:06 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Mon, 15 Aug 2005 15:54:06 +0100 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: <8c7f10c6050815075443fc446a@mail.gmail.com> On 8/15/05, Rocco Moretti wrote: > Which lead me to the question - what's the difference between a library > and a framework? If you call its code, it's a library. If it calls yours, it's a framework. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From jan.danielsson at gmail.com Wed Aug 10 11:18:05 2005 From: jan.danielsson at gmail.com (Jan Danielsson) Date: Wed, 10 Aug 2005 17:18:05 +0200 Subject: Documentation Message-ID: <42fa1a9f$1@griseus.its.uu.se> Hello all, What is the proper way to document a class in Python? I have written a few python libraries that I would like to document. I'm doing a lot of this: class Foo(object): """ This is a class which blah, blah, blah... It's features are blah, blah, blah... """ def addStuff(self): """ This method does blah, blah, blah... """ I'm going to assume that Python has some "official" tool which can be used to automatically create documentation for a .py-file (like Java does), but what do I need to do to support it, and how does it work? -- Kind Regards, Jan Danielsson Te audire no possum. Musa sapientum fixa est in aure. From paolo_veronelli at tiscali.it Sat Aug 6 13:26:43 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Sat, 06 Aug 2005 19:26:43 +0200 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <42F4F2D3.80804@tiscali.it> seberino at spawar.navy.mil wrote: > I've heard 2 people complain that word 'global' is confusing. > > Perhaps 'modulescope' or 'module' would be better? > > Am I the first peope to have thought of this and suggested it? > > Is this a candidate for Python 3000 yet? > > Chris I don't think the global keyword is useful actually. What's so special in a module nemespace to be priviledged like that. The point IMO is accessing names defined somewhere in the enclosing namespaces. def enclosing(): var=2 def enclosed(): outer var=4 this is the base of something useful. as it is now you neeed def enclosing(): class Var:_=2 def enclosed(): Var._=4 or like others suggested def enclosing(): var=[] var[0]=2 def enclosed(): var[0]=4 which is like saying python is not working It's ok to mark non locals,but why var=4 is not searched outside and var[0]=4 yes? I think there is only one or none possible solution to an 'outer' statement which is the first bound name matching the 'outer' vars name in the chain of enclosing namespaces. Why every instance doesn't point to its namespace and every namespace to its namespace? Unpythonic ? Illogicities to my eyes or at least non-linerities that makes 'global' an interesting strangeness to talk about. And that namespaces should start being easy sooner or later. Regards Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From me at jonbowlas.com Tue Aug 16 12:55:17 2005 From: me at jonbowlas.com (Jon Bowlas) Date: Tue, 16 Aug 2005 17:55:17 +0100 Subject: looping list problem In-Reply-To: Message-ID: Many thanks for your help, worked a treat Jon -----Original Message----- From: python-list-bounces+me=jonbowlas.com at python.org [mailto:python-list-bounces+me=jonbowlas.com at python.org] On Behalf Of Peter Otten Sent: 16 August 2005 17:25 To: python-list at python.org Subject: RE: looping list problem Jon Bowlas wrote: > Incidentally I'm doing this in zope. Many posters (including me) in this newsgroup don't do zope, so your best option is to ask on a zope-related mailing list. > I was hoping that this would loop through the elements in the list > returned by the hiddens function comparing them with the id of the current > value of c (bert) and if they are the same then it should ignore it and > move onto the next one, but it doesn't seem to do anything. > Ok, so I've adapted my script calling it a hiddens() function and included > it inside my get_tree_html function which creates my navigation: > > pub = context.get_publication() > obj = context.aq_inner > fpath = context.getPhysicalPath() > > def hiddens(): > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > return navstring.split(' ') > > def get_tree_html(node, endobj): > tree = '' > endpath = endobj.getPhysicalPath() > for c in node.get_ordered_publishables(): > if not c.is_published(): > continue > bert=c.getId(); > if bert=="index_right": > continue > if bert=="images": > continue > # this is where I loop through he elements returned by my hiddens > # function, comparing them with the value of bert Replace these lines > for element in hiddens(): > if element==bert: > continue # with the next hidden element with if bert in hiddens(): continue # with the next publishable c A 'continue' statement only affects the innermost loop, and as you don't have any code that follows it in the for-element-loop it didn't have any effect. Peter -- http://mail.python.org/mailman/listinfo/python-list From Gail.Harris at instantiated.ca Tue Aug 16 22:43:13 2005 From: Gail.Harris at instantiated.ca (Gail E. Harris) Date: Tue, 16 Aug 2005 22:43:13 -0400 Subject: Sep 9 is the last day for reduced rates for OOPSLA 2005 Message-ID: OOPSLA 2005 is being held in San Diego, Oct 16 to 20. Invited speakers include: Robert Hass, Martin Fowler, Gerald Jay Sussman Grady Booch, Jimmy Wales, Mary Beth Rosson, David P. Reed The conference features 29 research papers, 58 tutorials by leaders in their fields, 23 Workshops, 5 Panel discussion sessions, 9 Practitioner reports, Onward!, DesignFest, Lightning Talks, Posters, Demonstrations, 4 special symposia, and more... There is also a contest for promoting OOPSLA where you can win a suite for the conference week. More details are available at www.oopsla.org. -- Gail E. Harris, MSc, PMP Principal, Solution Delivery & Emerging Technology Instantiated Software Inc. http://www.Instantiated.CA Gail.Harris at Instantiated.CA (416) 573-0469 DISCLAIMER: The information contained in this e-mail may be confidential and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorized. If you are not the intended recipient please notify us immediately by returning e-mail to the originator. From daniel at dittmar.net Mon Aug 1 16:04:51 2005 From: daniel at dittmar.net (Daniel Dittmar) Date: Mon, 01 Aug 2005 22:04:51 +0200 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <8ur1s2-r5t.ln1@strongwill.g2ctech> Message-ID: <3l7dl2F111tulU1@uni-berlin.de> Jorge Godoy wrote: > We can find several problems, almost all of them can be solved with the > admin's creativity. You must distinguish between solving technical problems once a course has ben set and choosing such a course in the first place. The latter has to deal also with the risks of the unknown. Of course what is unknown can be influenced somewhat by getting information. Daniel From nospam at nospam.nospam Sat Aug 13 01:25:07 2005 From: nospam at nospam.nospam (Steve Jorgensen) Date: Fri, 12 Aug 2005 22:25:07 -0700 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: <7r0rf1p2ov2d6dpjqcomq5mn683962cc6f@4ax.com> Since Python does not use manifest typing, there's not much you can do about this, but typeless languages like this are great if you're using a process that finds the errors the compiler would otherwise find. I'm referring, of course, to Test Driven Development (TDD). If you do TDD, you won't miss compile-time checking much. In fact, the extra kruft that manifest typing requires is an annoying burden when doing TDD, so Python is a breath of fresh air in this regard. On 10 Aug 2005 08:53:15 -0700, "Qopit" wrote: >Hi there, > >I'm pretty new to Python and am trying to figure out how to get "will >this code compile?"-like code checking. To me this is a pretty basic >language/environment requirement, especially when working with large >projects. It is *much* better to catch errors at "compile-time" rather >than at run-time. > >One thing I've "found" is the PyChecker module (conveniently embedded >in SPE), but it doesn't seem to do that great of a job. For example, >the following simple program checks out perfectly as far as PyChecker >is concerned: > >#---- >def tester(a,b,c): > print "bogus test function",a,b,c >tester(1,2,3) #this runs fine >tester(1,2) #this obviously causes a run-time TypeError exception >#---- > >It seems to me that this should be an obvious catch for PyChecker. I >suppose you could argue that you don't want PyChecker to bark at you >any time an exception would be raised since you may intentionally be >causing exceptions, but this one seems a pretty simple and obvious one >to catch. > >My questions are: >- Am I missing something with my tester example? >- Are there other code-checking options other than PyChecker? > >Any other comments appreciated (aside from things like "just right good >code that doesn't have bugs like that" :) ). > >Thanks! From john at castleamber.com Fri Aug 26 07:19:09 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 11:19:09 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> Message-ID: Ulrich Hobelmann wrote: > What I hate about most are the sites that don't even *mention* that > they want cookies. Often I have to wonder, reinput input fields etc. > and then after ten minutes trying *bang*, the idea, maybe to allow > cookies for that site. So your browser doesn't warn you? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From ndbecker2 at gmail.com Wed Aug 10 08:09:16 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Aug 2005 08:09:16 -0400 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com wrote: > I was wondering if anyone could make recomendations/comments about CVS > systems, their experiences and what perhaps the strengths of each. > > Currently we have 2 developers but expect to grow to perhaps 5. > > Most of the developement is Python, but some C, Javascript, HTML, etc. > > The IDE what have been using/experimenting with are drPython and > eclipse with PyDev. > > For a python newsgroup, you are required to consider mercurial. It's not ready for production use yet, but is making rapid progress, and many (including myself) are using it. From cliff at develix.com Tue Aug 9 01:17:19 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 08 Aug 2005 22:17:19 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <7xek94z752.fsf@ruckus.brouhaha.com> References: <1123422959.086345.76190@g49g2000cwa.googlegroups.com> <7xek94z752.fsf@ruckus.brouhaha.com> Message-ID: <1123564639.7189.134.camel@localhost.localdomain> On Mon, 2005-08-08 at 10:10 -0700, Paul Rubin wrote: > Cliff Wells writes: > > The second presentation (I don't recall the speaker's name) specifically > > covered metaprogramming (writing DSLs) and one of the things I found > > interesting was that despite Ruby having far more syntax than Python in > > general, the resulting Ruby-based DSLs presented had far *less* syntax > > than had they been written in Python. This is undoubtedly the reason > > why Rails is apparently completely usable even if one knows very little > > Ruby. > > Interesting. But if we can generalize from that, then Lisp should be > ruling the web. Well, that is perhaps the other key feature: the Ruby/Rails community seems pretty friendly and eager to help people jump to their side of the fence (much like the Python community, btw), whereas Lisp community is an oxymoron. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From n00m at narod.ru Wed Aug 31 13:28:42 2005 From: n00m at narod.ru (n00m) Date: 31 Aug 2005 10:28:42 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125425945.667967.181000@g49g2000cwa.googlegroups.com> <1125478316.530781.315540@g44g2000cwa.googlegroups.com> <1125490472.670850.247240@g49g2000cwa.googlegroups.com> Message-ID: <1125509322.964828.27510@o13g2000cwo.googlegroups.com> Richie; Steve; Thanks for your replies! > o The command you're typing into the command prompt > o The error message you're getting > o The full traceback > o The code you're trying to run, or if it's too big then the piece that > the last line of the traceback refers to 1. D:\>python23\python d:\python23\socket6.py [Enter] It's OK so far. Python code is launched and starts listening to port 1434 (see the code below; it's the same code as in my neibouring topic). Now I launch a vbs script (which will connect to port 1434). I.e. I just double-click "my.vbs" file. And... voila! In a moment & silently console window closes without any error messages (or I just don't see them). But VBS reports a network error. Tested on win2k and win98. In IDLE it works ABSOLUTELY FINE! Prints statements in the code do exactly what they must do. import socket, thread host, port = '127.0.0.1', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433)) s1.bind((host, port)) s1.listen(1) cn, addr = s1.accept() def VB_SCRIPT(): while 1: data = cn.recv(4096) if not data: return s2.send(data) print 'VB_SCRIPT:' + data + '\n\n' def SQL_SERVER(): while 1: data = s2.recv(4096) if not data: return cn.send(data) print 'SQL_SERVER:' + data + '\n\n' thread.start_new_thread(VB_SCRIPT,()) thread.start_new_thread(SQL_SERVER,()) From max at alcyone.com Thu Aug 25 13:22:08 2005 From: max at alcyone.com (Erik Max Francis) Date: Thu, 25 Aug 2005 10:22:08 -0700 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: Mark Dickinson wrote: > Questions: > > (1) Can anyone else reproduce this behaviour, or is it just some quirk > of my setup? > (2) Any possible explanations? Is there some optimization that kicks > in at a certain number of lines, or at a certain length of > bytecode? > (3) If (2), is there some way to force the optimization, so that I can > get the speed increase without having to add the extra lines? I see no difference in execution times, as expected. The most likely explanation is simply that other things were going on on your system when you ran the first test, but not the second test, resulting in the discrepancy. In other words, the speed change had nothing to do with your dummy lines. -- 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 never was a good war or a bad peace. -- Benjamin Franklin From dan at cellectivity.com Tue Aug 16 13:00:50 2005 From: dan at cellectivity.com (Dan) Date: Tue, 16 Aug 2005 18:00:50 +0100 Subject: String functions deprication Message-ID: <1124211650.6359.3.camel@localhost.localdomain> > http://www.python.org/doc/2.4.1/lib/node110.html > > These methods are being deprecated. What are they being replaced > with? They're being made methods of the string class itself. For example: >>> s = 'any old string' >>> string.split(s, ' ') # Old way ['any', 'old', 'string'] >>> s.split() # New way ['any', 'old', 'string'] -- You know, I've been real busy. - Mike Foster, then-governor of Louisiana, when asked the name of his newborn seventh grandchild. From kay.schluehr at gmx.net Wed Aug 31 14:59:38 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 Aug 2005 11:59:38 -0700 Subject: Yielding a chain of values References: <4314bf65.177562962@news.oz.net> <3nk0e4F1snjcU2@individual.net> <4314e9fe.188467011@news.oz.net> <431553db.215568641@news.oz.net> <3nli8nF23ge4U1@individual.net> <1125490081.383463.322120@z14g2000cwz.googlegroups.com> <3nm4n7F26v7eU2@individual.net> Message-ID: <1125514778.955076.255950@z14g2000cwz.googlegroups.com> Reinhold Birkenfeld wrote: > Kay Schluehr wrote: > > Reinhold Birkenfeld wrote: > > > >> > x = [ yield r for r in iterable ] > >> > >> Which is quite different from > >> > >> x = (yield) in iterable > >> > >> which is currently (PEP 342) equivalent to > >> > >> _ = (yield) > >> x = _ in iterable > >> > >> So, no further tinkering with yield, I'm afraid. > >> > >> Reinhold > > > > Is the statement > > > > yield from iterable > > > > also in danger to be ambigous? > > > > The resolution of "(yield) from iterable" into > > > > _ = (yield) > > x = _ from iterable > > > > would not result in valid Python syntax. > > Right. > > Problem is, how would you define the "from" syntax: Is its use as > an expression allowed? What value does it have, then? > > Reinhold Do you mention statements like this? x = (yield from [1,2,3]) I do think that such "yield-comprehensions" may be valid and raise a StopIteration exception after being called three times by means of next() or send(). Kay From siona at chiark.greenend.org.uk Fri Aug 19 11:38:35 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 19 Aug 2005 16:38:35 +0100 (BST) Subject: Newbie Question References: <6rGdnSpFWa5se5jeRVn-vw@comcast.com> Message-ID: Tom Strickland wrote: >I have a file that contains many lines, each of which consists of a string >of comma-separated variables, mostly floats but some strings. Each line >looks like an obvious tuple to me. How do I save each line of this file as a >tuple rather than a string? Or, is that the right way to go? Depending on exactly what format you've got, either .split(',') on the line, or if this is insufficient look at the csv module. You'll then need some way of turning the list of strings both of these will give you into the mixed float/string tuple you want, which could be somewhat tedious. Without knowing what these lines look like, or what they represent, I can't begin to guess how you might go about it. Actually, I can -- I'd start by considering whether a dict might be more appropriate than a tuple and use csv.DictReader. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From deets at nospam.web.de Fri Aug 26 06:13:10 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Aug 2005 12:13:10 +0200 Subject: DOM text In-Reply-To: References: Message-ID: <3n889kFb1liU1@uni-berlin.de> Richard Lewis wrote: > > I admit I haven't tried very much code yet, but I'm not sure how I'm > going to handle situations like: the user wants to insert a link in the > middle of a paragraph. How can I use the DOM to insert a node into the > middle of some text? Am I right in thinking that the DOM will reference > a whole text node but nothing smaller? You have to split the text-node, and add the two resulting noedes together with the new link-node (or whatever node you want there, can be a whole tree) in the correct order to the parent of the two node. If unsure what that means, create two simple documents and parse these to dom to see how that works. Diez From jennifer_wild38 at yahoo.com Wed Aug 17 15:46:22 2005 From: jennifer_wild38 at yahoo.com (Jennifer) Date: Wed, 17 Aug 2005 19:46:22 -0000 Subject: looking to GIVE my first oral favor Message-ID: im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me From tim.golden at viacom-outdoor.co.uk Tue Aug 23 08:41:07 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue, 23 Aug 2005 13:41:07 +0100 Subject: X-Platform method of remote execution of Windows programs Message-ID: <9A28C052FF32734DACB0A288A3533991044D21E3@vogbs009.gb.vo.local> [utabintarbo at gmail.com] | It seems as if I am doomed to use additional software on the windows | box. Damn! 'Fraid so. If your question is: given a vanilla Windows box, can I invoke an executable on the Windows box from a Linux box? I believe the later versions of Windows run or can run Terminal Services by default, which can be invoked by the Remote Desktop protocol, but not -- I think -- any kind of Shell. Could be wrong. Of course, there are a thousand and one ways of doing this if you're prepared to have a long-running process (in Python or anything else which takes your fancy) which you can connect to with some command or other. Obvious possibilities in the Python line are: Pyro, XML-RPC, a socket server, Twisted, and so on. But you probably knew that. | The "unclarity" is in the authentication for the remote box. If I wish | to start a process on a remote box with another user's credentials | (other than the user I am logged in as), I am unsure as to how to | accomplish this. Anything you can add to the docs concerning | this would | be greatly appreciated. Thanks for the info. The answer is to use the slightly ungainly connect_server function. I've added an example on the cookbook page: http://timgolden.me.uk/python/wmi_cookbook.html#connect_as_a_named_user and I'd encourage you, if you haven't already, to look at the docstring documentation for the module, which is sometimes more useful than what I've got on the site. (Note to self: must do something about that). I have an oft-promised and not-yet-released version 1.0 of this module, which has a slightly tidier connection function, allowing you to call just one method (.connect, in fact) in which you can specify whatever combination of username, security context, namespace, etc. is allowed by the underlying calls. Not there yet, though. Hope that helps. 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 t-meyer at ihug.co.nz Wed Aug 31 20:25:01 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Thu, 1 Sep 2005 12:25:01 +1200 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. In-Reply-To: Message-ID: > While it may not adequately credit the implementation > language, Was this "it" the PCW article or SpamBayes? If the latter, please let spambayes-dev at python.org know how you think Python should be more appropriately credited; we are certainly trying to do this. (Python is mentioned all over the website, the "Python Powered" logo is integrated into what passes for a SpamBayes logo, and all donations to the project go to the PSF). =Tony.Meyer From mitsura at skynet.be Fri Aug 12 07:47:20 2005 From: mitsura at skynet.be (mitsura at skynet.be) Date: 12 Aug 2005 04:47:20 -0700 Subject: Help with wxPython Message-ID: <1123847240.639930.147270@o13g2000cwo.googlegroups.com> Hi, I have encountered an annoying problem with wx.Choice from wx.Python. Basically, what I want to do is create a drop down box with a set of choices (so far so good). The problem is that when the drop down box is created, the first entry in the list of the drop down box is empty and you need to drop down in the list to make your choice. I was looking for an option that allows to set a default/preset choice in the list. This is important because I have written an apps where you can set the properties of objects (cars) via drop down list and choose between a set of pre-defined choices. However, if the set the properties of the car (color, model, ...) via the Edit Properties windows but later you which to change a properties it would be nice to see the choices you made in de dropdown list and not a blank a first choice. It seems trivial do. Any help very much appreciated. Kris From onurb at xiludom.gro Wed Aug 24 13:57:35 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 24 Aug 2005 19:57:35 +0200 Subject: FileIO problem In-Reply-To: References: <1124866383.975225.261840@o13g2000cwo.googlegroups.com> Message-ID: <430cb511$0$3814$636a15ce@news.free.fr> Laszlo Zsolt Nagy wrote: > Try this: > > gclas = raw_input("What is the class:") > def Princlas(): > count = 0 > while count != 1000: > count = count + 1 > return "Admin forceclass %s %s " % ( count , gclas ) have you tried your code ? Obviously, no, else you would have seen that it always return on the first iteration. 2 solutions : passing the output stream to the function, or having the function returning a string. # solution 1 def prin_clas(gclas, out, nblines=1000): for count in xrange(nblines): out.write("Admin forceclass %d %s\n" % ( count , gclas )) a = raw_input("What is new file name:") out_file = open(a,"w") gclas = raw_input("What is the class:") prin_clas(gclas, out_file) out_file.close() # solution 2 def prin_clas(gclas, nb_lines=1000): result = [] for count in xrange(nblines): result.append("Admin forceclass %d %s" % ( count , gclas )) return "\n".join(result) a = raw_input("What is new file name:") out_file = open(a,"w") gclas = raw_input("What is the class:") out_file.write(prin_clas(gclas)) out_file.close() -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From http Mon Aug 8 01:41:25 2005 From: http (Paul Rubin) Date: 07 Aug 2005 22:41:25 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> Message-ID: <7xwtmx7zp6.fsf@ruckus.brouhaha.com> "Donn Cave" writes: > My vote would be Haskell first, then other functional languages. > Learning FP with Objective CAML is like learning to swim in a > wading pool -- you won't drown, but there's a good chance you > won't really learn to swim either. Has an interesting, very > rigorous OOP model though. I'm not sure what you mean by that about OCAML. That its functional model is not pure enough? I'd like to look at Haskell as well, but I have the impression that its implementation is not as serious as OCaml's, i.e. no native-code compiler. From john at castleamber.com Thu Aug 25 22:11:04 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 02:11:04 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <7xek8h5usm.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Mike Meyer writes: >> > Another advantage is that evewry internet-enabled computer today >> > already comes with an HTML renderer (AKA browser) >> >> No, they don't. Minimalist Unix distributions don't include a browser >> by default. I know the BSD's don't, and suspect that gentoo Linux >> doesn't. > > Lynx? Emacs? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From fperez.net at gmail.com Tue Aug 2 15:09:08 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Tue, 02 Aug 2005 13:09:08 -0600 Subject: Dabo in 30 seconds? References: <200508010830.27322.ed@leafe.com> <200508011220.41469.ed@leafe.com> <42EFB4CF.5070205@ulmcnett.com> Message-ID: Paul McNett wrote: > Fernando Perez wrote: >> If you are interested, just get ipython and grab the files for this, it's >> all >> BSD licensed. You can also browse the SVN repo here if you want to look at >> the code: >> >> http://ipython.scipy.org/svn/ipython/ipython/trunk/IPython/ >> >> The relevant files are ultraTB.py and CrashHandler.py. > > Thanks Fernando, consider your excellent code stolen! :) I'll probably > make a flag that defaults to ultraTB but that can also be set to leave > sys.excepthook as-is. Best of both worlds! Glad to be of use! I should probably ship this standalone, as I'm sure a lot of projects could use it, and the tracebacks are a hell of a lot better than what you get with python's default printouts. So little time... By all means contact me with complaints/bugs if you run into problems with this code. Cheers, f From http Fri Aug 26 15:35:51 2005 From: http (Paul Rubin) Date: 26 Aug 2005 12:35:51 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: <7xmzn41ofc.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > I agree in this sense: the use of any int as an error return is an > unPythonic *nix-Cism, which I believe was copied therefrom. Str.find is > redundant with the Pythonic exception-raising str.index and I think it > should be removed in Py3. I like having it available so you don't have to clutter your code with try/except if the substring isn't there. But it should not return a valid integer index. From gene.tani at gmail.com Mon Aug 1 20:04:10 2005 From: gene.tani at gmail.com (gene tani) Date: 1 Aug 2005 17:04:10 -0700 Subject: Python IDE's In-Reply-To: References: <20050731205901.53A6E1E4005@bag.python.org> Message-ID: <1122941050.357257.218840@g14g2000cwa.googlegroups.com> (instead of saying "google is your bud", & because this ? isn't readily FAQ-able) i suggest Google Advanced Searching c.l.py for "python IDE intellisense" or "code completion" or "regex debugger" or "contextual help" or "whatever_feature" (each feature has about 15 codenames, keep at it), maybe throw in your O/S of choice. 2005 threads have volumes written about vim,emacs,eclipse, eric, komodo, wing, Jedit, SPE, KDevelop, others. Then send feedback to the wiki: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments (oh, and don't expect a perfect Visual Studio/IntelliJ/eclipse for java workalike) From sjmaster at gmail.com Fri Aug 12 23:12:21 2005 From: sjmaster at gmail.com (Steve M) Date: 12 Aug 2005 20:12:21 -0700 Subject: Psyco & Linux In-Reply-To: <1123889744.376148.136180@g49g2000cwa.googlegroups.com> References: <2EUKe.193369$5V4.19467@pd7tw3no> <1123889744.376148.136180@g49g2000cwa.googlegroups.com> Message-ID: <1123902741.294608.5620@g49g2000cwa.googlegroups.com> > c/codegen.h:19:3: #error "sorry -- I guess it won't work like that on 64-bits machines" The first error output by gcc suggests the 64-bit OS might be the problem. But I don't actually know what that error means. From jepler at unpythonic.net Thu Aug 4 12:44:12 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 4 Aug 2005 11:44:12 -0500 Subject: Fail codecs.lookup() on 'mbcs' and 'tactis' In-Reply-To: References: <3lelp7F12526dU1@individual.net> Message-ID: <20050804164412.GB19009@unpythonic.net> On Thu, Aug 04, 2005 at 03:59:01PM +0100, Richard Brodie wrote: > I suppose, for consistency, it should ideally raise LookupError, though Maybe so. If that was the poster's point, then I completely missed it. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From cmedcoff at hotmail.com Tue Aug 2 13:04:23 2005 From: cmedcoff at hotmail.com (chuck) Date: 2 Aug 2005 10:04:23 -0700 Subject: pre subprocess module help Message-ID: <1123002263.313300.73300@f14g2000cwb.googlegroups.com> I need to execute a command shell process obtain the return code and capture stdout from that shell process. I've done this with 2.4 using subprocess. How do I do it with 2.3? From matthewharrison at gmail.com Mon Aug 29 16:29:33 2005 From: matthewharrison at gmail.com (matt) Date: 29 Aug 2005 13:29:33 -0700 Subject: python and ajax References: Message-ID: <1125347373.340555.78400@g14g2000cwa.googlegroups.com> Steve- I recently ported version 1.3 of cpaint to python. Soon after version 2.0 was released and I haven't really looked at it since. The 1.3 stuff was really simple though if you understand cgi, then you just implement a endpoint for your request to call. The javascript side is really the only thing new (might be a little learning if you having done much js). I think that more advanced ajax libraries like dojo or openrico are probably better suited to more complicated ajax use. Though they are more focused on the js frontend stuff. From aisaac0 at verizon.net Fri Aug 12 12:22:10 2005 From: aisaac0 at verizon.net (David Isaac) Date: Fri, 12 Aug 2005 16:22:10 GMT Subject: FTP over SSL (explicit encryption) References: Message-ID: "Alan Isaac" wrote in message news:CMTKe.6597$0d.5053 at trnddc03... > http://www.lag.net/paramiko/ > However it requires the PyCrypto module. > http://www.amk.ca/python/code/crypto > > Can you briefly outline how to use this as a client > to upload and down files from a server using SFTP? OK, the mechanics are pretty easy. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(20) sock.connect((hostname, port)) my_t = paramiko.Transport(sock) my_t.connect(hostkey=None ,username=username, password=password, pkey=None) my_chan = my_t.open_session() my_chan.get_pty() my_chan.invoke_shell() my_sftp = paramiko.SFTP.from_transport(my_t) Now my_sftp is a paramiko sftp_client. See paramiko's sftp_client.py to see what it can do. Alan Isaac From rkern at ucsd.edu Fri Aug 19 07:22:05 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 19 Aug 2005 04:22:05 -0700 Subject: while c = f.read(1) In-Reply-To: <20050819141113.69536258.jk@ospaz.ru> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <20050819141113.69536258.jk@ospaz.ru> Message-ID: en.karpachov at ospaz.ru wrote: > import itertools > f = open("blah.txt", "r") > for c in itertools.chain(*f): > print c > # ... > > The "f" is iterable itself, yielding a new line from the file every time. > Lines are iterable as well, so the itertools.chain iterates through each > line and yields a character. As far as I can tell, that code is just going to read the whole file in when Python does the *arg expansion. What's the point? -- 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 tjreedy at udel.edu Fri Aug 12 20:10:18 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Aug 2005 20:10:18 -0400 Subject: Bug on Python2.3.4 [FreeBSD]? References: Message-ID: "Donn Cave" wrote in message news:donn-BC56BC.16011812082005 at gnus01.u.washington.edu... > I don't think Python pretends to have any intentions here, > it has to take what it gets from the C library fopen(3) > function. BSD man pages generally say a+ positions the > stream at end of file (period.) They claim conformance > with the ISO C90 standard. I couldn't dig up a (free) copy > of that document, so don't know what it says on this matter. STandard C, by Plauger & Brodie says that 'a' plus whatever else means all writes start at the current end-of-file. TJR From sjmachin at lexicon.net Thu Aug 11 16:24:08 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 06:24:08 +1000 Subject: Regular expression to match a # In-Reply-To: References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> Message-ID: <42fbb3e8@news.eftel.com> Jeff Schwab wrote: > John Machin wrote: > >> Search for r'^something' can never be better/faster than match for >> r'something', and with a dopey implementation of search [which >> Python's re is NOT] it could be much worse. So please don't tell >> newbies to search for r'^something'. > > > How else would you match the beginning of a line in a multi-line string? I beg your pardon -- I should have qualified that: """ So please don't tell newbies to search for r'^something' when match of r'something' does the job. """ From bokr at oz.net Sun Aug 7 18:25:34 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 07 Aug 2005 22:25:34 GMT Subject: Chopping off spaces at both ends References: <42f63fac$0$18648$14726298@news.sunsite.dk> <1123434873.203001.207220@f14g2000cwb.googlegroups.com> Message-ID: <42f68922.861024257@news.oz.net> On 7 Aug 2005 10:14:33 -0700, "Kay Schluehr" wrote: >Use the strip() method. > >Example: > >>>> "\t abc \n".strip() >"abc" > >Variants are lstrip() and rstrip(). > and also occasionally useful: >>> 'abc123cab'.strip('bca') '123' I.e., a strip argument as an unordered set of characters that causes stripping so long as characters at the end(s) of the string being stripped are found that are in the set. Regards, Bengt Richter From jo at johannageiss.de Mon Aug 29 11:17:04 2005 From: jo at johannageiss.de (jog) Date: 29 Aug 2005 08:17:04 -0700 Subject: python xml DOM? pulldom? SAX? Message-ID: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> Hi, I want to get text out of some nodes of a huge xml file (1,5 GB). The architecture of the xml file is something like this bla blablabla .... I want to combine the text out of page:title and page:revision:text for every single page element. One by one I want to index these combined texts (so for each page one index) What is the most efficient API for that?: SAX ( I don?t thonk so) DOM or pulldom? Or should I just use Xpath somehow. I don`t want to do anything else with his xml file afterwards. I hope someone will understand me..... Thank you very much Jog From mekstran at scl.ameslab.gov Fri Aug 19 14:11:39 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Fri, 19 Aug 2005 13:11:39 -0500 Subject: Idempotent XML processing Message-ID: On Aug 19, 2005, at 12:11 PM, Will McCutchen wrote: >> In my current project, I am working with XML data in a protocol that >> has >> checksum/signature verification of a portion of the document. >> ... >> the server sends me XML with empty elements as full open/close tags, >> but toxml() serializes them to the XML empty element (), so >> the checksum winds up not matching. > > Does it even make sense to use a checksum to verify XML, since there > are basically[1] infinite ways to validly write equivalent XML data? > > [...] > > Again, I'm sorry because I didn't provide any real useful information, > I just tried to poke holes in your current project. I would agree that this mechanism doesn't make much sense. It certainly doesn't seem to fit well within the conventions most parsing ideologies; I don't know what parsing mechanism the protocol authors had in mind. Unfortunately, I did not write the protocol... I must merely speak it. - Michael From lv at aol.com Tue Aug 23 13:03:47 2005 From: lv at aol.com (l v) Date: Tue, 23 Aug 2005 12:03:47 -0500 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> Message-ID: <1124816780_7123@spool6-east.superfeed.net> Mike Schilling wrote: > "l v" wrote in message > news:1124804082_1011 at spool6-east.superfeed.net... > >>Xah Lee wrote: >> >>>(circa 1996), and email should be text only (anti-MIME, circa 1995), >> >>I think e-mail should be text only. I have both my email and news readers >>set to display in plain text only. It prevents the marketeers and >>spammers from obtaining feedback that my email address is valid. A >>surprising amount of information can be obtained from your computer by >>allowing HTML and all of it's baggage when executing on your computer. >>Phishing comes to my mind first and it works because people click the link >>without looking to see where the link really takes them. > > > A formatting-only subset of HTML would be useful for both e-mail and Usenet > posts. > > I would *agree* (your news reader may bold that last word) Len ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From bokr at oz.net Sun Aug 7 21:35:47 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 08 Aug 2005 01:35:47 GMT Subject: Fat and happy Pythonistas (was Re: Replacement for keyword'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com><11f84j8elj07271@news.supernews.com><861x57wrui.fsf@bhuda.mired.org><11f9f9u2enfsi58@news.supernews.com><11f9u843r0fts5b@news.supernews.com><86br4avf5t.fsf@bhuda.mired.org> <11fakjctean9u8a@news.supernews.com> Message-ID: <42f6b12e.871276739@news.oz.net> On Sun, 7 Aug 2005 18:37:42 -0400, "Terry Reedy" wrote: > >"John Roth" wrote in message >news:11fakjctean9u8a at news.supernews.com... >> http://martinfowler.com/articles/languageWorkbench.html > >This clarified your proposal for Python considerably. So I note that now >and especially once the AST compiler is completed, you are quite free to >start a Python AST Extension (PASTE) project quite independently of Guido >and the PSF developers. Build an AST-based editor like Fowler described, >with transient text presentations. (And pick your preferred GUI for doing >so.) Or design a system for translating domain-specific languages into >PyASTs, from whence they can be compiled to bytecode and run. > (Not implying that you need this for your edification ;-) I think the relationship of abstract entities and their concrete representations is very interesting. And it is useful to note that the representation of an AST in computer memory with a python interpreter looking at the AST node representations involves another layer of concrete representation. And the interpreter is an abstraction with a concrete representation, etc. down to the CPU as interpreter of of instructions etc., and the CPU being an abstraction made concrete my aggregating concrete elements chosen for their physical nature as representations of abstractions and behaving so as to transform concrete states in ways that reflect the transformations of the corresponding abstractions. And so forth ;-) IOW, a compiled python program AST in the abstract, would be the same abstraction even if both compiler and tree represention were done in lisp and you had lispython instead of cpython etc. Or whether we kept track of everything scribbling in beach sand with our toes. BTW, maybe this is a place to mention the concept of an AST decorator, that works like a function decorator except that it is prefixed with @@ instead of @ and it operates at compile time when the AST becomes available, but before it gets translated to code, and what gets passed to the decorator is the AST and the node of its own call (which it would typically eliminate from the AST as it does whatever else it is programmed to do). Which means that the decorator must already be compiled and avaiable at that point, so it can be looked up somewhere by the name. The idea is that this form of decoration could transform the AST arbitrarily before code generation, and be a very flexible tool for mischief of course, but also useful tricky things IWT. Regards, Bengt Richter From tjreedy at udel.edu Fri Aug 26 17:15:30 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Aug 2005 17:15:30 -0400 Subject: Language translation possible in python? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> <003301c5a972$21bd30e0$5700a8c0@rmse> Message-ID: "Jon Monteleone" wrote in message news:003301c5a972$21bd30e0$5700a8c0 at rmse... >I have a program that currently displays all of its messages and >instructions in only > English. My boss wants me to change it all to Korean. Is there a python > module that will > automatically translate my English to Korean? You could write something that autosubmitted things to a translation site like babelfish, Or just catenate all strings into one text and submit that. There is a system (that I have not used) for internaionalizing code that keeps messages to be translated in a separate resource file. Name excapes me at the moment though. Terry J. Reedy From steve at holdenweb.com Mon Aug 15 07:35:13 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Aug 2005 12:35:13 +0100 Subject: help with mysql cursor.execute() In-Reply-To: References: <8XMLe.878$Z%6.698@newssvr17.news.prodigy.com> <42ff9415$1@nntp0.pdx.net> Message-ID: William Gill wrote: > I have been testing and it seems that: > > 1- Cursor.execute does not like '?' as a placeholder in sql > The particular format required by each DBI-compatible module should be available as the module's "paramstyle" variable. mxODBC, for example, uses the "qmark" style, but MySQLdb uses "format". > 2- Cursor.execute accepts '%s' but puts the quotation mark around the > substitution. > > sql = 'select * from %s where cusid = ? ' % name > Cursor.execute(sql, (recID,)) > > still fails, but: > > sql = 'select * from basedata where cusid = %s ' > Cursor.execute(sql, (recID,)) > > works regardless of recID being a string or an int. Obviously this > stems from trying to parameterize the table name. > That's correct, as Scott has pointed out (with a good explanation of why). > If I use: > > sql = 'select * from %s where cusid = %%s ' % name > Cursor.execute(sql, (recID,)) > > It makes 1 substitution in the first line, and another in the execute() > > sql = 'select * from %s where cusid = %%s ' % name > # sql now == 'select * from basedata where cusid = %s ' > Cursor.execute(sql, (recID,)) > > and it works. > That's right: you are now building a table-dependent query (i.e. the table name is hard-wired in the SQL string) parameterized to the required value for cusid. > Between your comments re: column names and table names , and the notes > in cursor.py, I was able to figure it out. > > FYI I wanted to create a tableHandler class that could be extended for > individual tables. That's why the query needs to accept variables for > tablename. You might want to take a look at how some existing object-mappers achieve this - Ian Bicking's sqlobject module might be a good place to start. regards Steve > > Thanks. > > Bill > > Scott David Daniels wrote: > >>William Gill wrote: >> >> >>>I have been trying to pass parameters as indicated in the api. >>>when I use: >>> sql= 'select * from %s where cusid = %s ' % name,recID) >>> Cursor.execute(sql) >>>it works fine, but when I try : >>> sql= 'select * from %s where cusid like %s ' >>> Cursor.execute(sql,(name,recID)) >>>or >>> sql= 'select * from ? where cusid like ? ' >>> Cursor.execute(sql,(name,recID)) >>>it fails. >>>Can someone help me with the semantics of using parameterized queries? >> >> >>Neither column names nor table names can be parameters to >>fixed SQL. Values are what you fiddle with. This squares with >>the DBMS being allowed to plan the query before looking at the >>parameters (deciding which indices to use, which tables to join >>first, ...), then reusing the plan for identical queries with >>different values. MySQL may not take advantage of this two-step >>approach, but the DB interface is designed to allow it, so >>the parameterization is constrained. >> >>See if something like this works: >> >> sql = 'select * from %s where cusid like ? ' % name >> Cursor.execute(sql, (recID,)) >> >>--Scott David Daniels >>Scott.Daniels at Acm.Org -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From eurleif at ecritters.biz Thu Aug 25 21:20:57 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Fri, 26 Aug 2005 01:20:57 GMT Subject: argument matching question In-Reply-To: <1125018189.157888.113500@g47g2000cwa.googlegroups.com> References: <1125018189.157888.113500@g47g2000cwa.googlegroups.com> Message-ID: Learning Python wrote: > A code like this: > > def adder(**varargs): > sum=varargs[varargs.keys()[0]] > for next in varargs.keys()[1:]: > sum=sum+varargs[next] > return sum > > print adder( "first","second",'third') > > How to pass arguments to a functions that use dictionary collection? Like adder(foo="bar", bar="baz"), but I think you really want a function like this: def adder(*args): sum = args[0] for value in args[1:]: sum += value return sum From renting at astron.nl Fri Aug 19 03:10:20 2005 From: renting at astron.nl (Adriaan Renting) Date: Fri, 19 Aug 2005 09:10:20 +0200 Subject: time.clock() problem under linux (precision=0.01s) Message-ID: One of the limits of at least IBM compatible PC's is that in general they are not more accurate as about 1/64 th of a second if I recall correctly. I think this is the default tick size of the BIOS clock. Next to that the BIOS clock itself doesn't need to be very accurate, I can easily drift like an hour a year. Oh, and on top of that: If you are in a multi taksing operating system this complicates matters even further. This explains it very well: http://www.beaglesoft.com/mainfaqclock.htm Adriaan. >>>"Szabolcs Nagy" 08/18/05 1:07 pm >>> I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i tested timer functions capabilities with a short script: import time import os def test_timer_func(func): print 'min time-time: %.10f'%min(abs(func()-func()) for i in xrange(10**5)) print 'max time-time: %.10f'%max(abs(func()-func()) for i in xrange(10**5)) dt = 0.0 loopcount = 0 t = func() while dt==0.0: dt = func() - t loopcount += 1 print "min measurable loop time : %.10f"%dt print 'loopcount while dt==0 :',loopcount print '\n time.clock()' test_timer_func(time.clock) print '\n time.time()' test_timer_func(time.time) print '\n os.times()' ot = os.times test_timer_func(lambda:ot()[4]) My output is: time.clock() min time-time: 0.0000000000 max time-time: 0.0100000000 min measurable loop time : 0.0100000000 loopcount while dt==0 : 2703 time.time() min time-time: 0.0000019073 max time-time: 0.0000460148 min measurable loop time : 0.0000050068 loopcount while dt==0 : 1 os.times() min time-time: 0.0000000000 max time-time: 0.0100000007 min measurable loop time : 0.0099999998 loopcount while dt==0 : 2515 So the precision of time.clock is 0.01s under my ubuntu linux system, which means it's not suitable for benchmarking. (i want to benchmark the fps in my pygame+pyode program and it needs at least 0.001s precision) time.time seems much better solution, but python manual sais: "not all systems provide time with a better precision than 1 second" Should i use time.clock or time.time to be more crossplatform? Is time.time ok for windows? (time()-time() != 0.0) nszabolcs -- http://mail.python.org/mailman/listinfo/python-list From tdelaney at avaya.com Mon Aug 1 18:59:37 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Tue, 2 Aug 2005 08:59:37 +1000 Subject: Is this Pythonic? Message-ID: <2773CAC687FD5F4689F526998C7E4E5F0742A4@au3010avexu1.global.avaya.com> Peter Hansen wrote: > Change those to "raise NotImplementedError('blah')" instead and you'll > be taking the more idiomatic approach. One thing I've noticed, which I may raise on python-dev ... NotImplementedError does *not* play well with super() ... class A (object): def test (self): raise NotImplementedError class B (object): def test (self): print 'B' super(B, self).test() class C (B, A): def test (self): print 'C' super(C, self).test() It's actually worse than AttributeError, because the method actually exists. In both cases though you need to know when you create the base class how it's going to be used to work out whether a super() call is needed. One option is to do a try: except (AttributeError, NotImplementedError). Yuk - talk about hiding errors :( Tim Delaney From phil at riverbankcomputing.co.uk Fri Aug 12 13:39:01 2005 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Fri, 12 Aug 2005 18:39:01 +0100 Subject: Supressing argument renaming in the Qt Designer -> pyuic workflow In-Reply-To: <42fb8ca3$0$18647$14726298@news.sunsite.dk> References: <42fb8ca3$0$18647$14726298@news.sunsite.dk> Message-ID: <200508121839.01638.phil@riverbankcomputing.co.uk> On Thursday 11 August 2005 6:36 pm, Madhusudan Singh wrote: > Hi > > Some of the functions I defined inside Qt Designer need to have some values > passed to them. > > For instance : > > Code : > > void Form3::runningplot(n,plottitle,xname,x,y1name,y1,y2name,y2) > > is translated by pyuic to > > Python code : > > def runningplot(self,a0,a1,a2,a3,a4,a5,a6,a7): > > Now, while I understand that the first argument of the function has to be > "self", the change in the names of the parameters in the function > definition (and no corresponding change in the function body - which I > would not expect anyways) messes up everything. > > Is there a way to tell pyuic to not translate plottitle -> a0, xname -> a1, > etc., but keep the names as they are ? No, there is no way to do this at the moment. Phil From Scott.Daniels at Acm.Org Sun Aug 14 15:47:24 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 14 Aug 2005 12:47:24 -0700 Subject: help with mysql cursor.execute() In-Reply-To: <8XMLe.878$Z%6.698@newssvr17.news.prodigy.com> References: <8XMLe.878$Z%6.698@newssvr17.news.prodigy.com> Message-ID: <42ff9415$1@nntp0.pdx.net> William Gill wrote: > I have been trying to pass parameters as indicated in the api. > when I use: > sql= 'select * from %s where cusid = %s ' % name,recID) > Cursor.execute(sql) > it works fine, but when I try : > sql= 'select * from %s where cusid like %s ' > Cursor.execute(sql,(name,recID)) > or > sql= 'select * from ? where cusid like ? ' > Cursor.execute(sql,(name,recID)) > it fails. > Can someone help me with the semantics of using parameterized queries? Neither column names nor table names can be parameters to fixed SQL. Values are what you fiddle with. This squares with the DBMS being allowed to plan the query before looking at the parameters (deciding which indices to use, which tables to join first, ...), then reusing the plan for identical queries with different values. MySQL may not take advantage of this two-step approach, but the DB interface is designed to allow it, so the parameterization is constrained. See if something like this works: sql = 'select * from %s where cusid like ? ' % name Cursor.execute(sql, (recID,)) --Scott David Daniels Scott.Daniels at Acm.Org From sjmachin at lexicon.net Fri Aug 19 19:53:32 2005 From: sjmachin at lexicon.net (John Machin) Date: Sat, 20 Aug 2005 09:53:32 +1000 Subject: trying to check the creation date of a file In-Reply-To: References: Message-ID: <430670fb@news.eftel.com> David Fickbohm wrote: > People, > > I am trying to determine the creation date of files in a folder. > I am using the following code to find the folder and confirm that files > exist in the folder. Presumably you meant "intend to use the following pseudocode" (not "am using the following code") -- many of the statements (marked XXX below) are just not valid Python. > If someone could give me an idea how to check a > creation date it would be appreciated. > Thanks > dave > > def delete_old_files (t:\dm\~\users) XXX > # find files and delete files created more than XX number of days > ago > update_exist = 0 Did you mean "file_delete = 0"? > > input_dir = t:\dm\~\users\xxxx.yyyyyy\zzzz XXX > > if os.path.exists (input_dir) : > files = os.listdir (input_dir) > else: > print "Unable to find input file dir: %s !!!" % input_dir > sys.exit(2) > > if len(files): Not necessary -- "for file in files" does nothing gracefully if files is empty. If it were necessary, "if not files:" is suggested as an alternative to "if len(files)". > for file in files : > > file = os.path.join(input_dir) #all files in output > directory will be csv or xls, can be deleted if old enough I think you mean "file = os.path.join(input_dir, file)" > > if os.path.isfile(file): #need to check ext not file, file > name changes each day > if re.search(t:\dm\~\users\xxxxx\) and #creation date XXX You don't need the re module to check if the file's extension is "csv" or "xls" > gt x number of days ago > t:\dm\~\users\davef.input_list.delete(file) XXX > > file_delete = 1 > > if file_delete: > > print "\n file deleted: \n%s" % > str(t:\dm\~\users\xxxxx.input_list) > > return file_delete Now, to answer your question: You have obviously read the docs on the os module; what did you not understand about os.stat()? I suggest you contemplate the following real-not-pseudo-code and then examine the relevant sections of the docs for os.stat(), the stat module, and the time module. C:\junk>type st_ctime.py import os, stat, time def get_create_time(path): int_time = os.stat(path)[stat.ST_CTIME] str_time = time.ctime(int_time) return str_time if __name__ == "__main__": import glob, sys for arg in sys.argv[1:]: for path in glob.glob(arg): create_time = get_create_time(path) print path, create_time C:\junk>st_ctime.py *c*.py checkmodules.py Fri Jun 24 22:32:57 2005 ivancodecs.py Mon Jul 11 10:03:23 2005 st_ctime.py Sat Aug 20 09:22:00 2005 C:\junk> From lshuai at kaneva.com Tue Aug 2 11:54:57 2005 From: lshuai at kaneva.com (Liu Shuai) Date: Tue, 2 Aug 2005 11:54:57 -0400 Subject: Terminate a thread that doesn't check for events Message-ID: <9CA58FB7E095F146AD3E7FE1E5855929042FAE@brain.klausatlanta.local> Thanks for the reply Chris. Are you suggesting running the task in a *separate* process instead of a separate *thread*? Because if that's the case, I will have to share data (and possible memory) between that new process and my "master" process since they depend on one other. Yeah I will sure post it if I can find an elegant solution. Thank you, LS > -----Original Message----- > From: Chris Lambacher [mailto:lambacck at computer.org] > Sent: Tuesday, August 02, 2005 11:50 AM > To: Liu Shuai > Subject: Re: Terminate a thread that doesn't check for events > > Hi, > > There is no cross platform way to do this. You need to periodically check > a > quit flag, or perform a platform specific action to terminate it. On > Linux > you can send the process a signal. On windows you will need to use the > win32all package. If you decide to go the later route, maybe you could > encapsulate the thread termination code in a module and share it with the > Python community. > > -Chris > > On Tue, Aug 02, 2005 at 09:51:31AM -0400, Liu Shuai wrote: > > Can someone please comment on this? > > > > > > > > --------------------------------------------------------------------- > ----- > > > > From: python-list-bounces+sliu=kaneva.com at python.org > > [mailto:python-list-bounces+sliu=kaneva.com at python.org] On Behalf Of > Liu > > Shuai > > Sent: Monday, August 01, 2005 4:29 PM > > To: python-list at python.org > > Subject: Terminate a thread that doesn't check for events > > > > > > > > Hi all, > > > > > > > > I am aware that similar and probably same questions have been posted > many > > times, but I was unable to find a solution after reading a dozen > threads > > in the archive. So here it goes again. > > > > > > > > I have a thread that does some heavy task (hash calculation, for > > instance). I need a mechanism that works *across platforms* to stop > that > > calculation if user decides to exit. How can I do that? > > > > I can not do the standard "periodical checking" way since there is > only > > one function/step call in my thread. > > > > > > > > Here is a snippet of my thread classes to help illustrate the > problem: > > > > > > > > class Dispatcher(): > > > > def __init__(self): > > > > self.__worker = Worker() > > > > > > > > def start(self): > > > > self.__worker.start() > > > > > > > > def stop(): > > > > #how do i stop the worker? > > > > > > > > class Worker(threading.Thread): > > > > def __init__(self): > > > > > > > > def run(self): > > > > oneTimeConsumingCall() > > > > > > > > > > > > Thank you in advance for any suggestions/pointers. > > > > > > > > LS > > > -- > > http://mail.python.org/mailman/listinfo/python-list From AlexGreif.2609394 at bloglines.com Mon Aug 22 05:04:10 2005 From: AlexGreif.2609394 at bloglines.com (AlexGreif.2609394 at bloglines.com) Date: 22 Aug 2005 09:04:10 -0000 Subject: PIL: retreive image resolution (dpi) Message-ID: <1124701450.2814660508.20677.sendItem@bloglines.com> Hi, I looked at the PIL Image class but cannot see a posibility to retreive the image resolution dots per inch (or pixels per inch) Could somebody please tell me how to get these metadata infos in PIL? thanks, Alex. From aisaac0 at verizon.net Sun Aug 14 14:54:58 2005 From: aisaac0 at verizon.net (David Isaac) Date: Sun, 14 Aug 2005 18:54:58 GMT Subject: FTP over SSL (explicit encryption) References: Message-ID: <6sMLe.3055$%K4.765@trnddc09> "Eric Nieuwland" wrote in message news:mailman.2951.1123698786.10512.python-list at python.org... > I'm having a look at FTP/S right now. That's a little > more complicated, but it seems doable. > If I succeed, I guess I'll donate the stuff as an extension to ftplib. Just found this: http://trevp.net/tlslite/ I haven't even had time to try it, but I thought you'd want to know. Cheers, Alan Isaac From tjreedy at udel.edu Thu Aug 4 14:41:50 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 4 Aug 2005 14:41:50 -0400 Subject: PEP-343 - Context Managment variant References: <313379598.20050804110933@intercable.ru> Message-ID: "falcon" wrote in message news:313379598.20050804110933 at intercable.ru... > def Synhronised(lock,func): > lock.acquire() > try: > func() > finally: > lock.release() > .... > lock=Lock() > def Some(): > local_var1=x > local_var2=y > local_var3=Z > def Work(): > global local_var3 > local_var3=Here_I_work(local_var1,local_var2,local_var3) > Synhronised(lock,Work) > return asd(local_var3) When posting code, I (try to remember to) either cut and paste code that works or label it as untested, imcomplete, hypothetical, pseudo, or somesuch. The above will not work as posted because several names are undefined. Even with that fixed, or bindings assumed, Work() will not work (and would not work as expected even if it did) because global statements have no connection with enclosed local variables. Read http://docs.python.org/ref/global.html with the understanding that 'globals' means the module global namespace as returned by globals(). Hence the attempt to read local_var3 as a global will raise a NameError (given the absence of a global binding) and the setting of local_var3 as a global will not affect the local variable of Some with the same name. Hence the latter would keep the original value Z even if things did work. One possible revision (obviously not tested ;-): add local_var4 = [] # in the obvious place and rewrite the rest as def Work(): local_var4[0] = Here..... Synchronized(...) return asd(local_var4[0]) > It was complicated because : > 1. We must declare closure (local function) before using it You must create any object before you use it, and bind any name to some object before you ask for the object bound to that name. > 2. We must declare local vars, to which we wish assign in "global" > statement Wrong. See above. You cannot rebind enclosed local variables, only modify the associated object (if mutable, as in my suggested revision above). > 3. We cannot create variable local to outter function in closure, > so we must create it before and declare in [it] global You can declare a currently unlocally bound name to be global but once you create a local variable (bind an object to a name in the local namespace, or give instructions for that to happen) you cannot just redeclare it to be global. > So one can say: "that is because there're no block lambda". (I can be > wrong) I stopped reading here, so have no further comment. Terry J. Reedy From irmen.NOSPAM at xs4all.nl Mon Aug 22 14:02:34 2005 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 22 Aug 2005 20:02:34 +0200 Subject: network programming In-Reply-To: References: Message-ID: <430a133d$0$11065$e4fe514c@news.xs4all.nl> John Walton wrote: > Hello, everyone. I just began school, and they > already assigned us science fair. Since I'm in 8th > grade, I get to do demonstrations for our projects. > I'm probably going to demonstrate Python's networking > capabilities by writing a simple instant messenger > program. I only have a few problems: > > 1. I know squat about Python network Programming > > 2. I know nothing about networks > > So if any of you know of a good Python Networking > Tutorial or a website with lots of information on > networks and networking, please reply. Thanks! Is it the purpose of your project to delve into the gory details of network programming (or sockets)? If not, it might be extremely helpful to just not tire yourself with endless technical debugging sessions, and instead opt for the use of a high-level communication mechanism like XML-RPC or Pyro... --Irmen From djanvk at gmail..com Wed Aug 10 20:14:40 2005 From: djanvk at gmail..com (djanvk at gmail..com) Date: Thu, 11 Aug 2005 00:14:40 GMT Subject: Creating Palm OS programs with python? Message-ID: QUick question: Is it possible to create a palm os program to use on a PDA with python? THanks From solafidefarms at gmail.com Sat Aug 20 13:58:13 2005 From: solafidefarms at gmail.com (SolaFide) Date: 20 Aug 2005 10:58:13 -0700 Subject: TKinter Message-ID: <1124560693.691175.250000@g49g2000cwa.googlegroups.com> I want to create the window and contents in a class, and then use a separate function to write text to the buttons. Then when it clicks a button, I want it to call a check() function to see if that was the right button and then write some new stuff to the buttons. So far it displays the window all right, but it doesn't write the text I want it to. I am calling Tk().mainloop() inside the class; is that the problem? Thanks! B From rkern at ucsd.edu Fri Aug 26 06:10:25 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 26 Aug 2005 03:10:25 -0700 Subject: DOM text In-Reply-To: <1125050185.2182.241533364@webmail.messagingengine.com> References: <1125050185.2182.241533364@webmail.messagingengine.com> Message-ID: Richard Lewis wrote: > Hello Pythoners, > > I'm currently writing some Python to manipulate a semi-structured XML > document. I'm using DOM (minidom) and I've got working code for > transforming the document to HTML files and for adding the 'structured' > elements which populate the higher regions of the tree (i.e. near the > root). > > What I have to do next is write some code for working with the 'less > structured' elements towards the 'leaf ends' of the tree. These are > rather like little sub-documents and contain a mixture of text with > inline formatting (for links, font styles, headings, paragraphs etc.) > and objects (images, media files etc.). You might find that the more Pythonic XML modules are better suited to handling mixed content. I've been using lxml and ElementTree quite successfully. Amara should also be particularly well-suited to handling mixed content, but I haven't used it in anger, yet. -- 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 jeffrey.schwab at rcn.com Sat Aug 20 16:49:24 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sat, 20 Aug 2005 16:49:24 -0400 Subject: Please Criticize My Code In-Reply-To: <1124557167.256292.61220@g44g2000cwa.googlegroups.com> References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> <1124557167.256292.61220@g44g2000cwa.googlegroups.com> Message-ID: Christoph Rackwitz wrote: > i guess, it is pythonchallenge.com level 10? > if so, i used this thing: > > import re > def enc(s): > return ''.join('%s%s' % (len(a[0]),a[0][0]) for a in > re.findall('((.)\\2*)', s)) > Don't do that! From lemon97 at gmail.com Wed Aug 3 20:25:03 2005 From: lemon97 at gmail.com (lemon97 at gmail.com) Date: 3 Aug 2005 17:25:03 -0700 Subject: START YOUR OWN BIZ MAKING THOUSANDS USING PAYPAL!!! References: <1123094538.845205.48660@g44g2000cwa.googlegroups.com> Message-ID: <1123115103.061156.87630@o13g2000cwo.googlegroups.com> ) rg_n... at yahoo.com 2) hotp... at excite.com 3) waynecha... at gmail.com 4) Ffrankte... at aol.com 5) bizmind... at yahoo.com 6) priya... at gmail.com The following addresses above, ARE all yours! You are just another SCAMMER. And the method for making this money, is completely idiotic. Here is my example: Bob at hotmail.com Jim at hotmail.com Kelly at hotmail.com Gill at hotmail.com Bill at hotmail.com Each spend $6.00 dollars totalling $36.00 dollars. If they each received a fair portion of the total, they would get their $6.00 dollars back. Nobody would make any money. From peter at monicol.co.uk Fri Aug 12 07:57:38 2005 From: peter at monicol.co.uk (Peter Mott) Date: Fri, 12 Aug 2005 12:57:38 +0100 Subject: Why is this? In-Reply-To: References: Message-ID: <42fc8eb4$0$38045$bed64819@news.gradwell.net> If I use concatenation + instead of multiplication * then I get the result that Jiri expected: >>> L = [[]] + [[]] >>> L[1].append(1) >>> L [[], [1]] With * both elements are changed: >>> L = [[]] * 2 >>> L[1].append(1) >>> L [[1], [1]] Alex Martelli says in his excellent Nutshell book that + is concatenation and that "n*S is the concatenation of n copies of S". But it seems not so. Surely, from a logical point of view, S + S should be the same as S * 2? Peter The excellent Martelli Python Nutshell says that multiplication S*n is "the concatenation of n copies of S" so S+S and S*2 would be expected to be the same. It seems though that they are not but that * creates a list Jiri Barton wrote: > Hi everyone, > > I have a problem with initialization. > >>>>a, b = [[]]*2 >>>>a.append(1) >>>>b > > [1] > > Why is this? Why does not this behave like the below: > > >>>>a, b = [[], []] >>>>a.append(1) >>>>b > > [] > > And, just to add to my confusion: > > >>>>[[]]*2 > > [[], []] > >>>>[[], []] == [[]]*2 > > True > > Thanks in advance for the explanation. > jbar > > > BTW, if it matters... > Python 2.4.1 (#2, Mar 30 2005, 20:41:35) > [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 > > > From draghuram at gmail.com Thu Aug 18 10:31:42 2005 From: draghuram at gmail.com (draghuram at gmail.com) Date: 18 Aug 2005 07:31:42 -0700 Subject: creating/modifying sparse files on linux In-Reply-To: <4303e125.1735463644@news.oz.net> References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> <4303e125.1735463644@news.oz.net> Message-ID: <1124375502.322338.149620@g47g2000cwa.googlegroups.com> My goal is very simple. Have a mechanism to create sparse files and modify them by writing arbitratry ranges of bytes at arbitrary offsets. I did get the information I want (xrange instead of range, and a simple way to generate 1Mb string in memory). Thanks for pointing out about using "len" as variable. It is indeed silly. My only assumption from underlying OS/file system is that if I seek past end of file and write some data, it doesn't generate blocks for data in between. This is indeed true on Linux (I tested on ext3). Thanks, Raghu. From nicolas.riesch at genevoise.ch Wed Aug 10 09:06:09 2005 From: nicolas.riesch at genevoise.ch (nicolas_riesch) Date: 10 Aug 2005 06:06:09 -0700 Subject: how to write thread-safe module ? and pytz Message-ID: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> Does someone know if the module pytz (http://sourceforge.net/projects/pytz/) is thread-safe ? I have not seen it explicitely stated, and just wanted to be sure, as I want to use it. That's because in the file pytz/tzinfo.py, I see global variables _timedelta_cache, _datetime_cache, _ttinfo_cache, which are dictionnaries and are used as cache. I always thought that you must protect shared data with locks when multithreading, but I don't see any lock anywhere in pytz. However, pytz seems to work well with multiple threads creating various timezone objects at the same time. I don't understand where the trick is, that allows multiple threads to access this module without any locking and that all this seems to work without any problem... Does this mean that there is a means to write a module that is thread-safe, without importing the threading module and creating locks ? Or have I not understood something ...? Can someone give me a hint ? From Michael.Coll-Barth at VerizonWireless.com Tue Aug 30 11:02:14 2005 From: Michael.Coll-Barth at VerizonWireless.com (Michael.Coll-Barth at VerizonWireless.com) Date: Tue, 30 Aug 2005 11:02:14 -0400 Subject: how to join two Dictionary together? Message-ID: <20050830151206.3D1FB1E4004@bag.python.org> update works like append for lists a = {} a['a']='a' a['c']='c' b={} b['b'] = 'b' c={} c.update(a) c.update(b) -----Original Message----- From: python-list-bounces+michael.coll-barth=verizonwireless.com at python.org [mailto:python-list-bounces+michael.coll-barth=verizonwireless.com at pytho n.org]On Behalf Of DENG Sent: Tuesday, August 30, 2005 10:45 AM To: python-list at python.org Subject: how to join two Dictionary together? dict1={...something...} dict2={...somethind else ..} dict1 + dict2 that's does works ..:(, it's not like List... anyone can tell me how to get it? thanks in advance -- http://mail.python.org/mailman/listinfo/python-list ___________________________________________________________________ The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. From tjreedy at udel.edu Tue Aug 2 15:16:25 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 2 Aug 2005 15:16:25 -0400 Subject: bug in python/numarray References: <5.1.1.5.2.20050802103138.04c79d50@are.berkeley.edu> Message-ID: wrote in message news:5.1.1.5.2.20050802103138.04c79d50 at are.berkeley.edu... > Hi, there, > > I got different results by running the same lines of code on windows and > debian. Here is the code: > > a = kroneckerproduct(ones((4195,1)), identity(12)) I don't know what this does, but wonder if it uses a lot of memory. > print a.mean() > > This works perfectly well in windows but it gave the following error > while > running it in debian: Were you running on one dual boot machine (with the same memory available to each OS) or on two different machines, especially with different amounts of memory. > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line > 1137, in mean > return self.sum()/(self.nelements()*1.0) > File "/usr/lib/python2.4/site-packages/numarray/numarraycore.py", line > 1133, in sum > return ufunc.add.reduce(ufunc.add.areduce(self, type=type).flat, > type=type) > IndexError: too many indices. > > But if I reduce the number 4195 to 419, it works. Try using binary search (ie, try 2200 next) to pin down the exact breakdown point (as in 2123 works, 2124 does not) if there is one, or whether the breakdown is run dependent. Unload other apps and non-essential background process to see if that changes anything > Is it a bug in Python or Numarray? If it is not a resource issue, assume the latter since it crashed in Numarray. I think its maintainers would want to know about it. Terry J. Reedy From johnnyandfiona at hotmail.com Tue Aug 23 04:16:43 2005 From: johnnyandfiona at hotmail.com (Johnny) Date: 23 Aug 2005 01:16:43 -0700 Subject: What's the difference between built-in func getattr() and normal call of a func of a class In-Reply-To: <3n044rF18pnpkU1@uni-berlin.de> References: <1124784437.974574.12480@o13g2000cwo.googlegroups.com> <3n044rF18pnpkU1@uni-berlin.de> Message-ID: <1124785003.288006.235460@z14g2000cwz.googlegroups.com> Diez B. Roggisch wrote: > No, it will only return _always_ a value if you provide a default one. > If not, they have the exact same semantics. > > What you've got here is something usually called "syntactic sugaring" - > a specialized syntax that performs certain instructions that _could_ be > done by hand - but the concise syntax is (supposedly, and certainly in > this case) easier to read/write/understand. > > There are others - e.g. list comprehensions or a < b < c. > > Regards, > > Diez Cool~ Thanks for showing me the "syntactic sugaring":) From tjreedy at udel.edu Fri Aug 26 15:28:29 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Aug 2005 15:28:29 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: "Bryan Olson" wrote in message news:7sJPe.573$MN5.131 at newssvr25.news.prodigy.net... > The double-meaning of -1, as both an exclusive stopping bound > and an alias for the highest valid index, is just plain whacked. I agree in this sense: the use of any int as an error return is an unPythonic *nix-Cism, which I believe was copied therefrom. Str.find is redundant with the Pythonic exception-raising str.index and I think it should be removed in Py3. Therefore, I think changing it now is untimely and changing the language because of it backwards. Terry J. Reedy From spam-trap-095 at at-andros.demon.co.uk Fri Aug 5 09:42:34 2005 From: spam-trap-095 at at-andros.demon.co.uk (Andrew McLean) Date: Fri, 5 Aug 2005 14:42:34 +0100 Subject: Python's CSV reader References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> <1123169310.391973.217860@o13g2000cwo.googlegroups.com> Message-ID: In article <1123169310.391973.217860 at o13g2000cwo.googlegroups.com>, Stephan writes >Thank you all for these interesting examples and methods! You are welcome. One point. I think there have been at least two different interpretations of precisely what you task is. I had assumed that all the different "header" lines contained data for the same fields in the same order, and similarly that all the "detail" lines contained data for the same fields in the same order. However, I think Peter has answered on the basis that you have records consisting of pairs of lines, the first line being a header containing field names specific to that record with the second line containing the corresponding data. It would help of you let us know which (if any) was correct. -- Andrew McLean From steve at holdenweb.com Fri Aug 26 22:16:23 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Aug 2005 22:16:23 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <878xyoe6m2.fsf@wilson.rwth-aachen.de> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> Message-ID: Torsten Bronger wrote: > Hall?chen! > > "Terry Reedy" writes: > > >>"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message >>news:7xmzn41ofc.fsf at ruckus.brouhaha.com... >> >> >>>"Terry Reedy" writes: >>> >>> >>>>Str.find is redundant with the Pythonic exception-raising >>>>str.index and I think it should be removed in Py3. >>> >>>I like having it available so you don't have to clutter your code >>>with try/except if the substring isn't there. But it should not >>>return a valid integer index. >> >>The try/except pattern is a pretty basic part of Python's design. >>One could say the same about clutter for *every* function or >>method that raises an exception on invalid input. Should more or >>even all be duplicated? Why just this one? > > > Granted, try/except can be used for deliberate case discrimination > (which may even happen in the standard library in many places), > however, it is only the second most elegant method -- the most > elegant being "if". Where "if" does the job, it should be prefered > in my opinion. > Of course. But onc you (sensibly) decide to use an "if" then there really isn't much difference between -1, None, () and sys.maxint as a sentinel value, is there? Which is what I've been trying to say all along. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From ms at cerenity.org Wed Aug 31 20:05:19 2005 From: ms at cerenity.org (Michael Sparks) Date: Thu, 01 Sep 2005 01:05:19 +0100 Subject: OpenSource documentation problems References: Message-ID: <43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net> Bryan Olson wrote: > A plausible theory. I have some possibly-illustrative examples > of what I ran into within the last few weeks. Did you take what you learnt, and use that to create better documentation to be posted on python's SF project as a patch? (Not aimed at you, just a preface, and you also provided the right "starter point" to my main comment :) > Whatever else one says about open-source documentation, keeping > it current is a major unsolved problem. I agree. However, the reason for this is very simple: most people who write open source software (especially so AFAICT with python) do so on their own time. In my experience its very difficult to get professional programmers when they're being paid to write good documentation, and this is /despite/ the possible alternatives. Add in the fact that part of the problem is that ability to write good code doesn't always equate to the ability to write good documentation. Also add in that the desire to write code isn't always accompanied by the desire to write documentation. Taking all that into account if it's difficult to get people who are paid to do these things to write decent documentation (which is why people hire tech writers), I find it suprising that people expect open source developers to spend their own time producing high quality documentation, which may in fact be a skill some of them lack. Ironically though I do think the problem of documentation has been half solved in the open source world, and it really boils down (IMO) to companies like O'Reilly who appear to try and target popular not-best-documented open source projects and provide the motivation that results in good documentation. As things go, python is pretty well documented IMO. Sure there's weak areas, but considering this is all stuff people have done largely on their own time, and anyone who's written docs knows it's not fun. The best way to repay those who have spent the time writing what can be viewed as a first draft is to provide corrections. If you (generic, not just you personally) don't have the time, effort, inclination or effort to summarise and feedback a documentation patch *why should anyone else* ? When people complain /in here/ about the documentation not being perfect for python I personally find it sad and ironic. It's sad because it says to the person who spent their time (when they could be doing something else) that they wasted it, the docs are worthless etc - when they clearly *haven't* wasted their time and the docs are worthwhile. It's ironic though because they're criticising themselves. After all they understand how the docs can be better and the docs are shared. Unless they contribute back they're actually attacking themselves as much as the person who "wastes" their time writing "worthless" docs. (Again, not specifically aimed at you, but unless you've actually contributed back the results of your findings, you have to realise that any reasons or excuses that apply to you may also apply to anyone/everyone in the group and it's therefore suprising we have any docs ! :-) Best Regards, Michael. From usenet at isbd.co.uk Fri Aug 26 07:30:19 2005 From: usenet at isbd.co.uk (usenet at isbd.co.uk) Date: 26 Aug 2005 11:30:19 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <430D7366.C2126F6D@yahoo.com> Message-ID: <3n8cqbFb539U3@individual.net> In comp.lang.perl.misc John Bokma wrote: > > > They > > have no downsides I can possibly think of > > Some people never use them, and hence they use memory and add risks. > So they can choose a newsreader that doesn't have these facilities, no extra memory use, no risk. -- Chris Green From john at castleamber.com Thu Aug 25 17:35:38 2005 From: john at castleamber.com (John Bokma) Date: 25 Aug 2005 21:35:38 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: usenet at isbd.co.uk wrote: > In comp.lang.perl.misc John Bokma wrote: >> >> > the argument that usenet should never change seems a little >> > heavy-handed and anachronistic. >> >> No, simple since there *are* alternatives: web based message boards. >> Those alternatives *do* support HTML formatting (often the subset >> mentioned > > ... and generally these "web based message boards" (i.e. forums I > assume you mean) have none of the useful tools that Usenet offers and > are much, much slower. Yup, Slow because of all the HTML and avatars. And you suggest to introduce such a thing to Usenet? And which useful tools do you require? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From fakeaddress at nowhere.org Wed Aug 31 18:35:12 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 22:35:12 GMT Subject: Command-line arguments; was -- same thing In-Reply-To: References: Message-ID: Peter Hansen wrote: > I would approach this as a usability issue for your users, rather than > from the point of view of which is "a little messier" in the code. I agree, yet in my own programs, the command-option support tends to suck. I think I can work out function/class/module interfaces well enough, but command-lines, not so much. Anyone know of a good command-option style-guide for cross- platform apps? -- --Bryan From webraviteja at gmail.com Sat Aug 27 05:18:14 2005 From: webraviteja at gmail.com (webraviteja at gmail.com) Date: 27 Aug 2005 02:18:14 -0700 Subject: Embedding Python in other programs References: <312cfe2b050826084036db598f@mail.gmail.com> Message-ID: <1125134294.509755.64030@g43g2000cwa.googlegroups.com> Steve, He said VB6 not VB.NET Greg, Just write COM servers in Python and call them from VB6. No need to embed. Lot easier too. From darkcowherd at gmail.com Mon Aug 1 01:03:12 2005 From: darkcowherd at gmail.com (Dark Cowherd) Date: Mon, 1 Aug 2005 10:33:12 +0530 Subject: Standards not standard Message-ID: <5f4d3cb505073122032fde0017@mail.gmail.com> Hi, Multiple threads running currently about reinventing the wheel, Multiple GUI's etc. Being able to write a usable GUI is key task for all programmers today - read. ESR's http://www.catb.org/~esr/writings/cups-horror.html And look at ESR's reason to come over to Python - he wanted to write a GUI !!! I love the Delphi Environment and the Python language. So I would like to share here why I find the Delphi environment so productive. They have taken key concepts and defined standards for them and shipped a default implementation. To illustrate - They have the concept of a TDataset which is sort of like a cursor in the DBAPI. They have their default implementations but ANYBODY can write their own class which is TDataset compatible. Then they define how widgets should interact with TDataset. Now anybody can write a widget which interacts with any TDataset. So this means that anybody can write a widget and know that it will work with any Dataset. There are literally hundreds of open source projects using Delphi - You can take any open source widget that you like and hook it up with any open source TDataset that you like. It will work first time without any problem. And a sort of MVP is inbuilt. You can for example tie a dataset with a chart and grid on the same screen. Type in the grid and see the chart change. All this with zero code. Made my eyes bug out the first time I saw this. Wishful thinking here about Python. Suppose I like templating system from framework A. but prefer framework B. What if I could drop the existing templating in Framework B and use the templating from A. Somebody pointed out Java is just as "bad' with lots of Web frameworks but the key here as mentioned in http://www.python.org/peps/pep-0333.html is interoperability. I think the Python community did a great job with DBAPI 2.0 Rather than more code projects the community should work towards putting interface standards in such a way that for e.g. I could use Zope's templating and twisted as framework and kinterbas for data access and it should all work together because all of them are writing to the same standards. The language is so elegant with introspection and mixins and so many other things. And nowdays the pattern community has helped us all focus so much on designing for interoperability. I really think that the community needs a lot more of STANDARDS not a STANDARD GUI Just my thoughts. -- DarkCowherd From rkern at ucsd.edu Wed Aug 10 03:04:00 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 10 Aug 2005 00:04:00 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <20050808005104.862503556.EP@zomething.com> Message-ID: Michael Hudson wrote: > Michael Hudson writes: > >>Robert Kern writes: >> >>>What I'm trying to say is that posting to c.l.py is absolutely >>>ineffective in achieving that goal. Code attracts people that like >>>to code. Tedious, repetitive c.l.py threads attract people that like >>>to write tedious, repetitive c.l.py threads. >> >>+1 QOTW, though I may be too late > > Not only was I late, I was unoriginal! Oh well. That's okay, so was the quote! -- 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 apardon at forel.vub.ac.be Mon Aug 29 04:32:03 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 29 Aug 2005 08:32:03 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <7xslwwjsft.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-08-27, Terry Reedy schreef : > > "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message > news:7xslwwjsft.fsf at ruckus.brouhaha.com... >> "Terry Reedy" writes: >>> The try/except pattern is a pretty basic part of Python's design. One >>> could say the same about clutter for *every* function or method that >>> raises >>> an exception on invalid input. Should more or even all be duplicated? >>> Why >>> just this one? >> >> Someone must have thought str.find was worth having, or else it >> wouldn't be in the library. > > Well, Guido no longer thinks it worth having and emphatically agreed that > it should be added to one of the 'To be removed' sections of PEP 3000. I think a properly implented find is better than an index. If we only have index, Then asking for permission is no longer a possibility. If we have a find that returns None, we can either ask permission before we index or be forgiven by the exception that is raised. -- Antoon Pardon From rkern at ucsd.edu Sun Aug 7 00:20:54 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 21:20:54 -0700 Subject: Proposed new collection methods In-Reply-To: References: <86d5oqvfqf.fsf@bhuda.mired.org> Message-ID: Jeff Schwab wrote: > Robert Kern wrote: > >>Robert Kern wrote: >> >>>Christopher Subich wrote: >>> >>>>Dear Zeus no. Find can be defined as: >>>>def find(self, test=lambda x:1): >>>> try: >>>> item = (s for s in iter(self) if test(s)).next() >>>> except StopIteration: >>>> raise ValueError('No matching items in list') >>> >>>I would prefer that a find() operation return as soon as it locates an >>>item that passes the test. This generator version tests every item. >> >>Pardon me, I am retarded. > > Why are you retarded? Isn't the above code O(n)? > > Forgive me for not understanding, I'm still awfully new to Python > (having come from Perl & C++), and I didn't see an explanation in the FAQ. (s for s in iter(self) is test(s)) is a generator expression. It is roughly equivalent to def g(self, test=lambda x: True): for s in iter(self): if test(s): yield s Now, if I were to do item = g(self, test).next() the generator would execute the code until it reached the yield statement which happens when it finds the first item that passes the test. That item will get returned, and execution does not return to the generator again. That implementation does indeed return as soon as it locates the first item, so yes, I was being retarded. -- 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 gagaguy at gmail.com Wed Aug 3 22:42:45 2005 From: gagaguy at gmail.com (gagaguy at gmail.com) Date: 3 Aug 2005 19:42:45 -0700 Subject: quetion about "+=" and "runtime" Message-ID: <1123123365.511751.14470@g43g2000cwa.googlegroups.com> 1.i saw "+=" in a program code,but i haven't see it before,neither can i find it in a cook,who can tell me the usage of "python0" 2.how can i know how long does a program run? From jrastrick at student.usyd.edu.au Thu Aug 4 23:13:11 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 4 Aug 2005 20:13:11 -0700 Subject: Euclid's Algorithm in Python? In-Reply-To: References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> Message-ID: <1123211591.741161.297570@g49g2000cwa.googlegroups.com> Raising an assertion error for a < b is a bit of overkill, since its not really a case of bad input. So normally you see Euclid done like this: def gcd(a,b): # All lowercase for a function is a bit more conventional. if a < b: a, b = b, a # Ensures a >= b by swapping a and b if nessecary while b != 0: # Note parentheses are unnessecary here in python a, b = b, a % b return a A bit more concise and no less readable (IMO). If you really want to check for actual bad input, youre better off testing, for example, than a and b are both greater than 0.... jepler at unpythonic.net wrote: > Well, this article > http://pythonjournal.cognizor.com/pyj1/AMKuchling_algorithms-V1.html > was the first hit on google for '"euclid's algorithm" python'. > > It contains this function: > def GCD(a,b): > assert a >= b # a must be the larger number > while (b != 0): > remainder = a % b > a, b = b, remainder > return a > > Jeff From enleverlesO.OmcO at OmclaveauO.com Mon Aug 22 17:02:21 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Mon, 22 Aug 2005 23:02:21 +0200 Subject: PIL: retreive image resolution (dpi) References: <1124709169.824131.49120@g44g2000cwa.googlegroups.com> Message-ID: <430a3d69$0$7841$8fcfb975@news.wanadoo.fr> Hi ! The size of a image is an element ; but resolution is another. It is the link, between the image and the reality. Size AND resolution can to give the scale. Exemple : when you scan a document, the size (in pixels) is not sufficient, for to reproduce the document. Size + resolution, yes. @-salutations Michel Claveau From exarkun at divmod.com Wed Aug 31 10:51:08 2005 From: exarkun at divmod.com (Jp Calderone) Date: Wed, 31 Aug 2005 10:51:08 -0400 Subject: Sockets: code works locally but fails over LAN In-Reply-To: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> Message-ID: <20050831150120.3914.1807095062.divmod.quotient.10568@ohm> On 31 Aug 2005 06:03:00 -0700, n00m wrote: >import socket, thread >host, port = '192.168.0.3', 1434 >s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >s2.connect((host, 1433)) >s1.bind((host, port)) >s1.listen(1) >cn, addr = s1.accept() > >def VB_SCRIPT(): > while 1: > data = cn.recv(4096) > if not data: return > s2.send(data) > print 'VB_SCRIPT:' + data + '\n\n' > >def SQL_SERVER(): > while 1: > data = s2.recv(4096) > if not data: return > cn.send(data) > print 'SQL_SERVER:' + data + '\n\n' > >thread.start_new_thread(VB_SCRIPT,()) >thread.start_new_thread(SQL_SERVER,()) This is about the same as: mktap portforward --port 1434 --host 192.168.0.3 --dest_port 1433 twistd -f portforward.tap You'll find the code behind these two commands here: and here: And of course, the main Twisted site is . Some differences between portforward.tap and your code include: portforward.tap will accept multiple connections, rather than just one. portforward.tap won't print out all the bytes it receives (I assume this is just for debugging purposes anyway - if not, a simple modification will cause it to do this). portforward.tap won't non-deterministically drop traffic, since Twisted checks the return value of send() and properly re-transmits anything which has not actually been sent. Hope this helps, Jp From nyamatongwe+thunder at gmail.com Thu Aug 11 03:01:22 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Thu, 11 Aug 2005 07:01:22 GMT Subject: new python debugger In-Reply-To: <1123740657.066728.39080@g43g2000cwa.googlegroups.com> References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> <1123740657.066728.39080@g43g2000cwa.googlegroups.com> Message-ID: <6JCKe.79023$oJ.14896@news-server.bigpond.net.au> Nir: > Winpdb is still a BETA despite the version number which is 1.0.1 > so I will appreciate feedback on bugs, unexpected behavior, or > suggestions. Value tips when you hover over variables in the editor would be useful. A hovering user can be detected with the wxEVT_STC_DWELLSTART notification. Neil From joe_public34 at yahoo.com Thu Aug 4 10:15:47 2005 From: joe_public34 at yahoo.com (joe_public34) Date: Thu, 04 Aug 2005 14:15:47 -0000 Subject: Getting HTML from a loaded page in Firefox Message-ID: How can I use Python to get the HTML source for a webpage that is already loaded into Firefox? So far, all I've seen is reference to building Mozilla and XPCOM, but if there's any other way, I want to know. I already tried import win32com.client mb = win32com.client.Dispatch('MOZILLACONTROLLib.Application') Thanks. (using Python 2.4 on Windows) From vincent at visualtrans.de Mon Aug 15 13:57:46 2005 From: vincent at visualtrans.de (vincent wehren) Date: Mon, 15 Aug 2005 19:57:46 +0200 Subject: zlib + Windows 32 service problem (ImportError) References: <43008D0D.4000509@geochemsource.com> Message-ID: "Laszlo Zsolt Nagy" schrieb im Newsbeitrag news:mailman.3098.1124117300.10512.python-list at python.org... | Sorry, I realized that the import zlib was not executed from my | (working) service. | So here is the question: why can't I use zlib from a win32 service? Is | there any way to make it working? | | >------------- | >Python could not import the service's module | > File "T:\Python\Projects\NamedConnector\Service.py", line 17, in ? | > from Processor import * | > File "c:\Python\Projects\NamedConnector\Processor.py", line 35, in ? | > from mess import MessageSocket | > File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ? | > import zlib | >exceptions.ImportError: dynamic module does not define init function | >(initzlib) | >------------- | | | I had a similar problem where a zlib.dll that is *not a Python extension* is in sys.path *before* zlib.pyd. Python will try to import this zlib.dll and find the dll doesn't export a initzlib: for more info see http://mail.python.org/pipermail/python-list/2004-October/thread.html#248107 HTH, Vincent Wehren From hancock at anansispaceworks.com Sun Aug 28 16:49:37 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sun, 28 Aug 2005 15:49:37 -0500 Subject: python image thumbnail generator? In-Reply-To: References: Message-ID: <200508281549.37201.hancock@anansispaceworks.com> On Saturday 27 August 2005 09:06 pm, Chris Dewin wrote: > I'm thinking it would be nice and easy, if we could just upload a jpg into > a dir called "gallery/". When the client clicks the "gallery" link, a > cgi script could search the gallery/ dir, and create thumbnails of any > jpeg images that don't already have a thumbnail associated with them. The > script could then generate a page of clickable thumbnails. This is trivial to do with Zope. I wrote a "VarImage" product for it that will do the image manipulation you want handily. I never really created a "gallery" product for it because it's so trivial to do with a regular Zope folder and a couple of scripts, but I would be happy to share my Gallery template with you if your interested. The current version of VarImage even implements things like HTTP_REFERER blocking (or watermarking if you prefer), to discourage remote-linking of your images, etc. An online example can be seen here: http://narya.net/Gallery Not sure about CGI methods of doing it, though. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From adsheehan at eircom.net Tue Aug 23 05:44:31 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 23 Aug 2005 02:44:31 -0700 Subject: Urgent: Embedding Python problems - advice sought In-Reply-To: References: <1124236492.970194.270970@g47g2000cwa.googlegroups.com> Message-ID: <1124790271.085414.219470@g49g2000cwa.googlegroups.com> Thanks Michael. I will look into the areas you have suggested... Alan From mwm at mired.org Sat Aug 27 15:20:03 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 27 Aug 2005 15:20:03 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: <861x4fuqzg.fsf@bhuda.mired.org> axel at white-eagle.invalid.uk writes: > In comp.lang.perl.misc John Bokma wrote: >> Chris Head wrote: >>> What advantages would those be (other than access from 'net cafes, but >>> see below)? >> And workplaces. Some people have more then one computer in the house. My >> partner can check her email when I had her over the computer. When I >> want to check my email when she is using it, I have to change the >> session, fire up Thunderbird (which eats away 20M), and change the >> session back. > Not a Windows solution, but I find the 'screen' utility invaluable as > I can have my email, news, and an editor open in different screens > and then when I need to move to a different machine, I can simply > detach and reattach screen without disturbing anything that > might be running. For a more portable solution, check out VNC. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From luismgz at gmail.com Mon Aug 1 09:01:37 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 1 Aug 2005 06:01:37 -0700 Subject: need for speed References: <1122888516.815400.116220@f14g2000cwb.googlegroups.com> Message-ID: <1122898795.323295.12780@g14g2000cwa.googlegroups.com> borges2003xx at yahoo.it wrote: > hi everyone > can someone suggest me where find a lot programming tricks for > achieving the top speed in python? > thanks everyone for patience Check this out: http://wiki.python.org/moin/PythonSpeed/PerformanceTips From justin.vanwinkle at gmail.com Fri Aug 26 12:21:07 2005 From: justin.vanwinkle at gmail.com (justin.vanwinkle at gmail.com) Date: 26 Aug 2005 09:21:07 -0700 Subject: problems with tarfile.open and tar.bz2 In-Reply-To: References: <1125072329.310958.20650@g43g2000cwa.googlegroups.com> Message-ID: <1125073267.626311.111050@g43g2000cwa.googlegroups.com> r is supposed to autodetect the archive type. However, even changing it to 'r:bz2' produces an identical error. From richie at entrian.com Tue Aug 30 10:48:19 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 30 Aug 2005 15:48:19 +0100 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. In-Reply-To: References: Message-ID: [Alan] > SpamBayes has won the Personal Computer World (pcw.co.uk) Editors Choice > award for anti-spam software Yay! Do we get one of those cheesy medals to put on our website? 8-) -- Richie Hindle richie at entrian.com From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 31 13:14:06 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 31 Aug 2005 19:14:06 +0200 Subject: What are new-style classes? In-Reply-To: References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> <3nk08hF1snjcU1@individual.net> <3nm4kkF26v7eU1@individual.net> Message-ID: <3nm6quF26e60U1@individual.net> Steve Holden wrote: > Reinhold Birkenfeld wrote: >> Terry Hancock wrote: >> >>>On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote: >>> >>>>The customary way is to use "class new_class(object):". There's no advantage in using >>>>__metaclass__ except that you can set it globally for all classes in that module >>>>(which can be confusing on its own). >>>> >>>>My comment mostly referred to "new-style classes must be declared as a subclass of >>>>a new-style class", which is not true. >>> >>>Nonsense. >> >> >> Given the rest of your post, I assume that this isn't meant as it sounds. Remember, I'm >> German, so please bear with my sense of humour. ;) >> > German? Humour? Surely some mistake :-) Hm, should have added "if any" above... > not-talking-about-the-war-ly y'rs - steve No surprise it was the Brits who discovered the world's deadliest joke. Reinhold From pifpafpuf at gmx.de Thu Aug 4 09:35:29 2005 From: pifpafpuf at gmx.de (HK) Date: 4 Aug 2005 06:35:29 -0700 Subject: jython: PythonInterpreter runs script, wrong classpath Message-ID: <1123162529.009152.150160@g47g2000cwa.googlegroups.com> Hi, I am using ant to run junit to run a java class that uses a PythonInterpreter to execute a script. The script complains about a "ImportError: cannot import name ..." despite the fact that junit, on behalf of ant -v pretends to be using exactly the right classpath. Obviously the classpath does not make it into the PythonInterpreter. Question: Is there a sys variable which tells me where the PythonInterpreter searches for (or lets the JVM search for) classes? Thanks, Harald. From mom.myggen at gmail.com Thu Aug 25 04:08:26 2005 From: mom.myggen at gmail.com (OllieZ) Date: 25 Aug 2005 01:08:26 -0700 Subject: same menu point is activated Message-ID: <1124957306.899701.223010@g49g2000cwa.googlegroups.com> Hi all Im trying to learn wxpython by some samples and Ive come across this. After change EVT_MENU lines from EVT_MENU(self, ID_OPEN, self.OnOpen) to self.Bind(wx.EVT_MENU, self.OnOpen) It can run, but the menu points all trigger the openfile dialog. Seems like the last bind rules them all. What am i doing wrong? All the best OllieZ Code below import wx import os ID_ABOUT=101 ID_OPEN=102 ID_BUTTON1=110 ID_EXIT=200 class MainWindow(wx.Frame): def __init__(self,parent,id,title): self.dirname='' wx.Frame.__init__(self,parent,wx.ID_ANY, title, style=wx.DEFAULT_FRAME_STYLE| wx.NO_FULL_REPAINT_ON_RESIZE) self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE) self.CreateStatusBar() # A Statusbar in the bottom of the window # Setting up the menu. filemenu= wx.Menu() filemenu.Append(ID_OPEN, "&Open"," Open a file to edit") filemenu.AppendSeparator() filemenu.Append(ID_ABOUT, "&About"," Information about this program") filemenu.AppendSeparator() filemenu.Append(ID_EXIT,"&Exit"," Terminate the program") # Creating the menubar. menuBar = wx.MenuBar() menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content. self.Bind(wx.EVT_MENU, self.OnAbout) self.Bind(wx.EVT_MENU, self.OnExit) self.Bind(wx.EVT_MENU, self.OnOpen) # EVT_MENU(self, ID_OPEN, self.OnOpen) self.sizer2 = wx.BoxSizer(wx.HORIZONTAL) self.buttons=[] for i in range(0,6): self.buttons.append(wx.Button(self, ID_BUTTON1+i, "Button &"+`i`)) self.sizer2.Add(self.buttons[i],1,wx.EXPAND) # Use some sizers to see layout options self.sizer=wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.control,1,wx.EXPAND) self.sizer.Add(self.sizer2,0,wx.EXPAND) #Layout sizers self.SetSizer(self.sizer) self.SetAutoLayout(1) self.sizer.Fit(self) self.Show(1) def OnAbout(self,e): d = wx.MessageDialog( self, " A sample editor \n" " in wxPython","About Sample Editor", wx.OK) # Create a message dialog box d.ShowModal() # Shows it d.Destroy() # finally destroy it when finished. def OnExit(self,e): self.Close(True) # Close the frame. def OnOpen(self,e): """ Open a file""" dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN) if dlg.ShowModal() == wx.ID_OK: self.filename=dlg.GetFilename() self.dirname=dlg.GetDirectory() f=open(os.path.join(self.dirname, self.filename),'r') self.control.SetValue(f.read()) f.close() dlg.Destroy() app = wx.PySimpleApp() frame = MainWindow(None, -1, "Sample editor") app.MainLoop() From dominant500 at comcast.net Wed Aug 17 19:09:10 2005 From: dominant500 at comcast.net (Mark) Date: 17 Aug 2005 16:09:10 -0700 Subject: Moinmoin config In-Reply-To: <1124317599.992955.242880@g44g2000cwa.googlegroups.com> References: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> <1124317599.992955.242880@g44g2000cwa.googlegroups.com> Message-ID: <1124320150.919204.129210@f14g2000cwb.googlegroups.com> Hi Patrick, Sorry about the cross post, but I could not find a moin list. Do you have a sub folder or a better name? I searched for moin and for wiki but only found some actual wikis and some groups with only a few members. Anyway, I checked my data_underlay_dir and it is valid and contains one subdir, called pages, which has a huge set of subdirs. Do you know where else I can turn? Thanks Mark From mwm at mired.org Sat Aug 27 15:03:10 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 27 Aug 2005 15:03:10 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> <3n8di6Fbhg7U2@individual.net> <3n8sqaFch6kU1@individual.net> <86ek8gw6js.fsf@bhuda.mired.org> <3napv5Fl7hrU2@individual.net> Message-ID: <8664trurrl.fsf@bhuda.mired.org> Ulrich Hobelmann writes: > Mike Meyer wrote: >> Try turning off JavaScript (I assume you don't because you didn't >> complain about it). Most of the sites on the web that use it don't >> even use the NOSCRIPT tag to notify you that you have to turn the >> things on - much less use it to do something useful. > I had JS off for a long time, but now so many websites expect it, and > even make browsing more convenient, that I grudgingly accepted it. ;) I've turned it on because I'm using an ISP that requires me to log in via a javascript only web page. They have a link that claims to let non-JS browsers log in, but it doesn't work. My primary browser doesn't support JavaScript or CSS, and is configured with images turned off, mostly because I want the web to be fast. What it does have is the ability to launch one of three different external browsers on either the current page or any link on the page, so those faciities are a few keystrokes away. The default browser on my mac has all that crap turned on, but I dont have anything I consider either import or sensitive on it, and the only client who has data on it considers such thinsg an acceptable risk. >> Sturgeon's law applies to web sites, just like it does to everything >> else. > Yep. Filtering is the future in the overloaded world. And to the best of my knowledge, Google filters out content that my primary desktop browser can't display. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From zen19725 at zen.co.uk Mon Aug 8 11:36:05 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 8 Aug 2005 16:36:05 +0100 Subject: PEP: Specialization Syntax References: <42F66FF2.7010901@v.loewis.de> <1123481295.549324.99810@g49g2000cwa.googlegroups.com> <4iEJe.5130$651.540962@weber.videotron.net> <1123493200.390420.160040@g44g2000cwa.googlegroups.com> Message-ID: On 8 Aug 2005 02:26:40 -0700, Kay Schluehr wrote: > >I have to admit that i don't actually understand what you want? Me neither. I don't see the point of this. -- Email: zen19725 at zen dot co dot uk From caseyhHAMMER_TIME at istar.ca Thu Aug 25 00:57:35 2005 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Thu, 25 Aug 2005 04:57:35 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: <4njqg11l1qlbco8ikd6eovv8aog68hinsr@4ax.com> >contained in the range [start, end) Does range(start, end) generate negative integers in Python if start >= 0 and end >= start? -- Regards, Casey From john at castleamber.com Fri Aug 26 07:22:31 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 11:22:31 GMT Subject: minimalist regular expression References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> <1125049935.989992.80290@z14g2000cwz.googlegroups.com> Message-ID: "borges2003xx at yahoo.it" wrote: > the shortest description in regex way Which is? Oh, and please quote the previous message and author. Reply under the part you are replying too, etc. Even with Google this is possible. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From gagaguy at gmail.com Thu Aug 4 00:00:49 2005 From: gagaguy at gmail.com (gagaguy at gmail.com) Date: 3 Aug 2005 21:00:49 -0700 Subject: quetion about "+=" and "runtime" In-Reply-To: References: <1123123359.768132.112990@g47g2000cwa.googlegroups.com> Message-ID: <1123128049.701735.249620@g49g2000cwa.googlegroups.com> 1.i have look " += " up,but i can't find it.is it ofthen used? 2.i saq a result like this in a web page: $ time python permute2.py 56789 3 Got 120 items. Maximum at 87596 ,product 84000 real 0m0.057s user 0m0.050s sys 0m0.000s $ time python permute3.py 56789 3 Got 120 items. Maximum at 87596 ,product 84000 real 0m0.040s user 0m0.030s sys 0m0.010s i wanna know how to call out this From ray_usenet at yahoo.com Fri Aug 12 10:59:36 2005 From: ray_usenet at yahoo.com (Ray) Date: 12 Aug 2005 07:59:36 -0700 Subject: Python's Exception, and Capitalization In-Reply-To: References: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> Message-ID: <1123858776.576754.318620@o13g2000cwo.googlegroups.com> D H wrote: > Yeah, the python standard library has been built by lots of different > people. It wasn't designed by one entity using one standard like the > java standard library or .NET/Mono class library. Um, OK, so is it customary in modern Python programs to follow Java convention? then methods/functions should be written someMethod() or myFunction()? > > 2. I'm quite baffled that you either have try/except, or try/finally. > > Apparently that will be fixed sometime: > http://python.miscellaneousmirror.org/peps/pep-0341.html Ah, okay. I'm quite surprised to see the date--it was _that_ recent! :) But currently, how have you--Python guys who code for a living--been handling this case? I know that you can put another try inside a try, but obviously the need for that is not common enough in idiomatic Python program (or else this would have been a PEP in, say, 2000). Cheers Ray From m.boeren at guidance.nl Thu Aug 25 10:15:45 2005 From: m.boeren at guidance.nl (Marc Boeren) Date: Thu, 25 Aug 2005 16:15:45 +0200 Subject: RE Despair - help required Message-ID: <0C77C7530EA52A4EBD1C47C80D1D291E364B82@sbs.GuidanceBV.local> Hi, > Don't think it will do much good. I need to get them from a file and > extract the last folder in the path. For example: > if I get "c:\dos\util" > I want to extract the string "\util" Still, os.path is your friend: import os filepath = r'C:\dos\util' base, last = os.path.split(filepath) print base # 'C:\dos' print last # 'util' print os.sep+last # '\util' Don't forget to read > > http://docs.python.org/lib/module-os.path.html for some more info! Regards, Mc! From jason at tishler.net Fri Aug 12 09:03:08 2005 From: jason at tishler.net (Jason Tishler) Date: Fri, 12 Aug 2005 09:03:08 -0400 Subject: How to quit a Windows GUI program gracefully with Python under Cygwin? In-Reply-To: <1123841222.202745.259280@f14g2000cwb.googlegroups.com> References: <1123761153.401824.43040@g49g2000cwa.googlegroups.com> <1123791622.954340.74930@o13g2000cwo.googlegroups.com> <1123841222.202745.259280@f14g2000cwb.googlegroups.com> Message-ID: <20050812130308.GA4032@tishler.net> On Fri, Aug 12, 2005 at 03:07:02AM -0700, KB wrote: > After I confirmed 'Alt-F4' would terminate and close a win32 > application running independently, > I installed 'SendKeys' module and tested with the following code under > both Cygwin and Python Windows If you installed the SendKeys binary, then it will not work with Cygwin Python since it is a Windows Python shared extension module. It may be possible to port SendKeys to Cygwin. Unfortunately, this may not 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 jrastrick at student.usyd.edu.au Mon Aug 15 21:23:27 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 15 Aug 2005 18:23:27 -0700 Subject: How can I exclude a word by using re? In-Reply-To: References: <430085e8$1@news.eftel.com> Message-ID: <1124155407.625957.24000@g14g2000cwa.googlegroups.com> could ildg said: > I want to use re because I want to extract something from a html. It > will be very complicated without using re. But while using re, I > found that I must exlude a hole word "", certainly, there are > many many "" in this html. Actually, for properly processing html, you shouldn't really be using regular expressions, precisely because the problem is complicated - regular expressions are too simple and can't properly model a language like HTML, which is generated by a context free grammar. If thats only meaningless technical mumbo-jumbo to you, never mind - the important point is you shouldn't really use an re. Trust me :) What you want for a job like is an HTML parser. Theres one in the standard library; if it doesnt suit, there are plenty of third party ones. I like Beautiful Soup: http://www.crummy.com/software/BeautifulSoup/ If you insist on using an re, well I'm sure someone on this group will figure out a solution to your issue thats as good as you're going to get... > > My re is as below: > _____________________________________________ > r=re.compile(ur'valign=top>(?P\d{1,2})]*>\s{0,2}' > ur'' > ur'(?P.+)',re.UNICODE|re.IGNORECASE) > _____________________________________________ > There should be over 30 matches in the html. But I find nothing by > re.finditer(html) because my last line of re is wrong. I can't use > "(?P.+)" because there are many many "" in the html > and I just want the ".*" to match what are before the firest "". > So I think if there is some idea I can exclude a word, this will be > done. Assume there is "NOT(WORD)" can do it, I just need to write the > last line of the re as "(?P(NOT())+)". > But I still have no idea after thinking and trying for a very long time. > > In other words, I want the "" of "(?P.+)" to be > exactly the first "" in this match. And there is more than one > match in this html, so this must be done by using re. > > And I can't use any of your idea because what I want I deal with is a > very complicated html, not just a single line of word. > > I can copy part of the html up to here but it's kinda too lengthy. > On 8/15/05, John Machin wrote: > > could ildg wrote: > > > In re, the punctuation "^" can exclude a single character, but I want > > > to exclude a whole word now. for example I have a string "hi, how are > > > you. hello", I want to extract all the part before the world "hello", > > > I can't use ".*[^hello]" because "^" only exclude single char "h" or > > > "e" or "l" or "o". Will somebody tell me how to do it? Thanks. > > > > (1) Why must you use re? It's often a good idea to use string methods > > where they can do the job you want. > > (2) What do you want to have happen if "hello" is not in the string? > > > > Example: > > > > C:\junk>type upto.py > > def upto(strg, what): > > k = strg.find(what) > > if k > -1: > > return strg[:k] > > return None # or raise an exception > > > > helo = "hi, how are you? HELLO I'm fine, thank you hello hello hello. > > that's it" > > > > print repr(upto(helo, "HELLO")) > > print repr(upto(helo, "hello")) > > print repr(upto(helo, "hi")) > > print repr(upto(helo, "goodbye")) > > print repr(upto("", "goodbye")) > > print repr(upto("", "")) > > > > C:\junk>upto.py > > 'hi, how are you? ' > > "hi, how are you? HELLO I'm fine, thank you " > > '' > > None > > None > > '' > > > > HTH, > > John > > -- > > http://mail.python.org/mailman/listinfo/python-list > > From spammers-go-here at spam.invalid Fri Aug 12 01:06:24 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Fri, 12 Aug 2005 01:06:24 -0400 Subject: Using globals with classes Message-ID: <42fc2e42$0$18637$14726298@news.sunsite.dk> Hi I am relatively new to Python. I am using Qt Designer to create a UI for a measurement application that I use. Everything seems to be clear but the use of globals (defined in the module that is generated using pyuic, that contains the form class). I am using qwtplot to display a running plot : void Form3::runningplot(n,plottitle,xname,x,y1name,y1,y2name,y2) { if n==1 : plotkey1=self.runningqwtPlot.insertCurve(y1name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yLeft) plotkey2=self.runningqwtPlot.insertCurve(y2name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yRight) self.runningqwtPlot.setTitle(plottitle) self.runningqwtPlot.setXGrid(True) self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yLeft) self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yRight) self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.xBottom) self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yLeft,y1name) self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yRight,y2name) self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.xBottom,xname) self.runningqwtPlot.setCurveData(plotkey1,x,y1,n) self.runningqwtPlot.setCurveData(plotkey2,x,y2,n) self.runningqwtPlot.replot() else : self.runningqwtPlot.setCurveData(plotkey1,x,y1,n) self.runningqwtPlot.setCurveData(plotkey2,x,y2,n) self.runningqwtPlot.replot() } where the above routine is called repeatedly to display real time data. Now, plotkey1 and plotkey2 need to remain unchanged between successive invocations of setCurveData() and replot() above. I have defined these as globals (in the Form settings comment field with Python: as usual). However, when I run it, I get an error indicating that plotkey1 and plotkey2 are unknown outside. I also have a global variable named "globaldebug" that when set to True, shows some diagnostic information as different slots are called. That too fails with the same error : NameError: global name 'globaldebug' is not defined Is there a way to make a Python function "remember" the values of certain variables ? Or use fortran 95 like use module, only : varname, type of within a def ? From mwm at mired.org Fri Aug 12 21:07:09 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 12 Aug 2005 21:07:09 -0400 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> <42FB55BC.70608@sweetapp.com> Message-ID: <86r7cy63wi.fsf@bhuda.mired.org> Magnus Lycka writes: > Terry Reedy wrote: >> However, everything is an instance of a class or type. > Except whitespace, comments, operators and statements! > (Did I miss anything?) What makes you think operators qualify as exceptions? >>> type(operator.add) If you're talking about the character used to represent that operator - well, I don't think there's any way to derive the underlying object from that character. In fact, that's true for everything else you list. Maybe the properly refined version of Terry's statement should be: Everything you can manipulate is an instance of a class or a type. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From txdiversity at hotmail.com Sat Aug 20 02:13:44 2005 From: txdiversity at hotmail.com (James) Date: 19 Aug 2005 23:13:44 -0700 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <1124518424.490288.105620@o13g2000cwo.googlegroups.com> > for data in iter(lambda:f.read(1024), ''): > for c in data: What are the meanings of Commands 'iter' and 'lambda', respectively? I do not want you to indicate merely the related help pages. Just your ituitive and short explanations would be enough since I'm really newbie to Python. -James From mwh at python.net Wed Aug 10 05:16:35 2005 From: mwh at python.net (Michael Hudson) Date: Wed, 10 Aug 2005 09:16:35 GMT Subject: Syntax error after upgrading to Python 2.4 References: <1123323206.151000.309140@g49g2000cwa.googlegroups.com> <3lshlhF13sd3oU1@individual.net> Message-ID: Reinhold Birkenfeld writes: > Michael Hudson wrote: >> jepler at unpythonic.net writes: >> >>> On Sat, Aug 06, 2005 at 05:15:22PM -0400, Terry Reedy wrote: >>>> In any case letting developers add new features is part of the price of >>>> getting unpaid bug fixes for free software. But note that PSF does not >>>> make you to upgrade. Here is the current list of possible downloads. >>>> >>> [a mere 8 versions] >>> >>> Oh, don't give such a short list! Here's what I found on the python.org ftp site: >> >> [...] >> >>> And then there's CVS... >> >> Which doesn't build for the really early versions. I think >> python1.0.1.tar.gz is as old as it's easy to get. > > Can we assume that the 0.9.1 version Guido posted to alt.sources does build? Dunno! > Google Groups for "Python 0.9.1 group:alt.sources". Oh good grief, "Python 0.9.1 part 01/21", I'm much to lazy to sort all that out today... still, would be nice if someone did; in ftp:anonymous at python.org:/pub/python/src/README we find: Older sources ============= If you find an older Python release (e.g. 0.9.8), we're interested in getting a copy! webmaster at python.org Cheers, mwh -- I must be missing something. It is not possible to be this stupid. you don't meet a lot of actual people, do you? From mwm at mired.org Tue Aug 30 22:07:31 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 30 Aug 2005 22:07:31 -0400 Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk> <4314c264.178329924@news.oz.net> <4314cf38$0$18648$14726298@news.sunsite.dk> Message-ID: <863boqamfw.fsf@bhuda.mired.org> Madhusudan Singh writes: > No, no. All I am looking for is for the system to report its time with > better resolution. I know it is possible on my hardware, because I can get > at very precise timings using Fortran 95 intrinsics in my other code. Then you could always write a C extensions module that calls an F95 routine to get that information. Your F95 compiler does interface with C, doesn't it? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From spammers-go-here at spam.invalid Fri Aug 5 21:42:22 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Fri, 05 Aug 2005 21:42:22 -0400 Subject: GUI programming, embedding, real time plots, etc. Message-ID: <42f4157f$0$18643$14726298@news.sunsite.dk> Hi I am still a rookie at python (can do some basic programming with the language), and have been using python gpib and matplotlib to control my instruments and do real time plots. Since I have more than one instrument to control, I was thinking of writing a GUI using Tkinter (looked at Page, but it not have a debian package and I saw quite a few bugs listed - Tkinter seems mature). I have some questions : 1. In using matplotlib (my code essentially involved creating a plot and show()'ing it inside a loop), the color of the plot changed. Is there a way to tell matplotlib to not treat each new invocation as a new plot, but to really overwrite the old one ? 2. Is it possible to embed the matplotlib o/p in the o/p GUI ? 3. Are there some other caveats that I should be aware of in using matplotlib ? From jennifer_wild38 at yahoo.com Sat Aug 6 15:19:58 2005 From: jennifer_wild38 at yahoo.com (Jennifer) Date: Sat, 06 Aug 2005 19:19:58 -0000 Subject: looking to GIVE my first oral favor Message-ID: im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me From cliff at develix.com Mon Aug 1 06:44:07 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 03:44:07 -0700 Subject: python SMTP server In-Reply-To: References: <1122759885.881136.186360@g47g2000cwa.googlegroups.com> Message-ID: <1122893047.19618.278.camel@localhost.localdomain> On Mon, 2005-08-01 at 12:28 +0200, Benjamin Niemann wrote: > Cliff Wells wrote: > > As an aside, I will say that many SMTP servers that service home users > > (i.e. Comcast, et al) limit the amount of mail that you can send within > > a defined period. > > Or completely block outgoing traffic on port 25 except to their own relay... Luckily I haven't encountered this with Comcast Cable (I use my own mailserver [requires smtpauth] directly from home as Comcast seems to have issues with mail and DNS on occasion). If I ever do, I'll immediately switch to one of the local DSL providers who support Linux. Better for MTA's to block dynamic/home IP's using dnsbls than have the ISP limit what you can do with your home computer. > > By using a local SMTP server to proxy, your app can > > queue up a large amount of mail in a much shorter period. It won't > > necessarily go out any faster, but at least your app won't be tied up > > waiting for the mail to be accepted. So there is perhaps one useful > > (beyond learning and fun) application for using a local SMTP server. > > It would be interesting what the intention of the OP is. I just stumpled > upon a similar problem. The prog I'm currently working on has a function to > report crashes back to me. Originally these reports where sent by mail - no > problem on UNIX/Linux hosts where you can assume to have a working MDA on > localhost. But what to do on Windows systems?!? Ask for a SMTP server > during installation? Confusing as the program itself is totally unrelated > to email. In this case you _could_ deliver the mail directly to my MX > host... But instead of this I installed a small CGI on my website that > sends the mails to me and gets the data via HTTP POST from my app. You can also use port redirection to bypass this sort of thing. Send on port 10025 instead and direct your MTA to listen on both ports. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From whp at wp.pl Fri Aug 26 18:06:46 2005 From: whp at wp.pl (Wojciech Halicki-Piszko) Date: Sat, 27 Aug 2005 00:06:46 +0200 Subject: How to know if connection is active when using telnetlib? References: Message-ID: > If open() doesn't throw an exception then you should have a connection you can > start reading/writing with. Unless you have some special meaning for > 'active'? > > I'm just basing this on reading telnetlib.py. > > Eddie Well, in fact what I meant is: I won't to check wether established connection is still active. I have a reading thread and when I send 'quit' command to a server it (guess what:)) disconnects. So I get plenty of unwanted output, I want to avoid this. So the problem is how can I inform my reader thread it is not longer wanted when _server_ disconnects me? To my defense: repetition is mother of science (in case you did answer and I did not get it first time). From bokr at oz.net Tue Aug 23 18:07:34 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 23 Aug 2005 22:07:34 GMT Subject: split function References: Message-ID: <430b9c7d.2242175868@news.oz.net> On Mon, 22 Aug 2005 22:14:55 +0200, Mohammed Altaj wrote: > >Dear all > >Sorry , I confused between two things , what i said in the last e-mail i >already managed to do using C code , But what i need to do using python >is : my input data : > >0 2 3 4 >1 2 4 >2 3 >3 4 > >what i suppose to do is , using the first line and start searching >number by number ,first i have 0 search in the rest of lines if there is >0 print out the all numbers except 0 , after that , start searching >using the 2ed element in the first line which is 2 , in the 2ed line we >have 1 , 4 . in the 3rd line we have 3 , in the 4th line we do not have >2. And so on for 3 and 4 , and also for the 2nd , 3rd lines , so the >output should be > >0 2 1 4 3 3 2 4 4 1 2 3 >1 2 3 4 3 >2 3 >3 4 > >And i managed to do this , but i did in the case of no space between >numbers,when i am reading from file , like >0234 >124 >23 >34 > >I want my code be able to deal with the space between numbers , and this >is my code again >def belong_to(x,a): > c=-1 > for i in range(len(a)-1): > if x==int(a[i]): > c=i > return c > >def list_belong(x,a): # This function to check if this line > c=-1 # line has been searched before or not > for i in range(len(a)): > if a[i]==x: > c=1 > break > return c > >x=0 >occur=[] > >in_file=open('data.dat','r') >out_file=open('result.dat','w') >fileList = in_file.readlines() >for k in fileList: > v=k > occur.append(k) > n=len(v)-1 > for i in range(n): > temp=int(v[i]) > print temp, > out_file.write(str(temp)) > for line in fileList: > if v!=line: > if list_belong(line,occur)!=1: > if belong_to(temp,line) != -1: > j=belong_to(temp,line) > for i in range(len(line)-1): > if i!=j: > print line[i], > out_file.write(line[i]) > > > > print > out_file.write("\n") > >out_file.close() >in_file.close() > > >Thanks > Does this do what you want? (except that it writes to stdout and doesn't print)? (note that I get 234 instead of 23 on the 3rd line of output) >>> # test with string file input and stdout output ... import StringIO >>> in_file = StringIO.StringIO("""\ ... 0 2 3 4 ... 1 2 4 ... 2 3 ... 3 4 ... """) >>> import sys >>> out_file = sys.stdout >>> >>> lines = [''.join(line.split()) for line in in_file] # clean out spaces and '\n' >>> for i, line in enumerate(lines): ... for digit in line: ... out_file.write(digit) ... for followingline in lines[i+1:]: ... if digit not in followingline: continue ... line_sans_digit = followingline.replace(digit,'') ... out_file.write(line_sans_digit) ... out_file.write("\n") ... 021433244123 12343 234 34 Also note that I eliminated all duplicate digits from a selected line, rather than just the first match. Easy to change. Regards, Bengt Richter From juho.vuori at helsinki.fi Wed Aug 31 06:20:21 2005 From: juho.vuori at helsinki.fi (Juho Vuori) Date: Wed, 31 Aug 2005 13:20:21 +0300 Subject: strange behaviour of str() Message-ID: <0wfRe.15342$uD6.2810@reader1.news.jippii.net> Hello, I'm wondering about the following behaviour of str() with strings containing non-ASCII characters: str(u'foo') returns 'foo' as expected. str('l??') returns 'l??' as expected. str(u'l??') raises UnicodeEncodeError Is this behaviour sane? Possibly, but not documented at all. Somehow you'd expect str() to never fail. I'm hesitating about sending a bug report about a third party application, which fails because it is relaying on this. Cheers, Juho Vuori From ptmcg at austin.rr.com Fri Aug 19 14:28:30 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 19 Aug 2005 11:28:30 -0700 Subject: BeautifulSoup In-Reply-To: References: Message-ID: <1124476110.532924.32090@g47g2000cwa.googlegroups.com> Steve - Is there a chance you could post a before and after example, so we can see just what you are trying to do instead of talking conceptually all around it and making us guess? If you are just doing some spot translations of specific values in an HTML file, you can probably get away with a simple (but readable) program using pyparsing. -- Paul From finite.automaton at gmail.com Tue Aug 9 15:21:59 2005 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 9 Aug 2005 12:21:59 -0700 Subject: Import question References: <1123614152.482652.72900@g44g2000cwa.googlegroups.com> Message-ID: <1123615319.592605.323370@f14g2000cwb.googlegroups.com> Circular import issues can usually be resolved by moving import statements into the bodies of functions which aren't executed when the module itself is imported. Simple example: ---- fileA.py ------ import fileB as fb foo = 10 # we're going to access foo from fileB fb.do_something_with_foo() ---- fileB.py ------ def do_something_with_foo(): import fileA as fa # import is INSIDE the function print "foo is ", fa.foo ---------------------- From renting at astron.nl Mon Aug 29 10:07:20 2005 From: renting at astron.nl (Adriaan Renting) Date: Mon, 29 Aug 2005 16:07:20 +0200 Subject: variable hell Message-ID: Oops, you're completely right. I'm sorry, it is indeed my mistake. I was thinking people were telling me I was quoting Martin wrong, while I was quoting Rafi wrong. I'll promise not quote anybody anymore until I have an e-mail program that can quote/copy properly. As reading it in one window, then typing it in another to test it, then copying it back, obviously introduced a PEBKAC error. Adriaan Renting From fredrik at pythonware.com Wed Aug 31 18:03:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 1 Sep 2005 00:03:06 +0200 Subject: OpenSource documentation problems References: Message-ID: Bryan Olson wrote: > [...] > > What additions to that string would you suggest? > > Since "help *is* pydoc.help, or at least...", the call could > show the same thing as help(pydoc.help) >>> import pydoc >>> help is pydoc.help False > or at least inform the user that more of the story is available > from help(pydoc.help). >>> help Type help() for interactive help, or help(object) for help about object. >>> help() Welcome to Python 2.4! This is the online help utility. If this is your first time using Python, you should definitely check out the tutorial on the Internet at http://www.python.org/doc/tut/. /.../ (if you read and followed the instructions, you wouldn't have to post quite as many "THIS IS BROKEN! THE SKY IS FALLING!" posts.) From damir at agg.astranet.ru Wed Aug 17 00:55:31 2005 From: damir at agg.astranet.ru (Damir Hakimov) Date: Wed, 17 Aug 2005 08:55:31 +0400 Subject: base64.encode and decode not correct In-Reply-To: <4301D507.3070509@agg.astranet.ru> References: <4301D507.3070509@agg.astranet.ru> Message-ID: <4302C343.5020808@agg.astranet.ru> Damir b wrote: >Hi *! > >I found a strange bug in base64.encode and decode, when I try to encode >- decode a file 1728512 bytes lenth. >Is somebody meet with this? I don't attach the file because it big, but >can send to private. > >Which solution for transfer file (binary data) via string-only object? > >Damir. > > > Sorry, guis. I made a mistake. I open and encode file on Linux and save and decode it on Windows without "b" in mode. I found it 5 minutes past I sent last message when I try to use binascii.hexlify and took the same result. Thanks to all. From agentriot at gmail.com Mon Aug 22 01:25:49 2005 From: agentriot at gmail.com (Ricardo Sanchez) Date: 21 Aug 2005 22:25:49 -0700 Subject: Uploading images to imageshack.us with Python In-Reply-To: <1124688164.318336.55370@z14g2000cwz.googlegroups.com> References: <1124688164.318336.55370@z14g2000cwz.googlegroups.com> Message-ID: <1124688349.177133.170420@o13g2000cwo.googlegroups.com> I forgot to add that I'm behind a proxy, but I think that is irrelevant. If you are not behind a proxy replace this line: print post_multipart('proxy-a.mains.nitech.ac.jp', 8080, 'http://imageshack.us/index.php', params, files) with print post_multipart('imageshack.us', 80, '/index.php', params, files) From shaung at netspace.net.au Fri Aug 26 22:55:40 2005 From: shaung at netspace.net.au (Shaun) Date: 26 Aug 2005 19:55:40 -0700 Subject: overload builtin operator In-Reply-To: <430ee1bc.2456509954@news.oz.net> References: <3n61u4F1fg2U1@individual.net> <430ee1bc.2456509954@news.oz.net> Message-ID: <1125111340.539382.194610@g44g2000cwa.googlegroups.com> Thanks for your replies, obviously this isn't a simple thing to do so I'll take a different tack. The exact problem I am trying to solve here is to avoid the ZeroDivisionError in division. I have c++ code which delegates to python to calculate expressions on table cells. The values of the table cell are arbitary numbers and the expressions to be calculated are fairly simple python arithmetic and math functions. The problem being that some users want an expression like '(100/x)+ 3' where x=0 to return 3. So that dividing a number by zero results in 0. Apart from parsing the expression string myself and checking for divide by zero I can't find another way to solve the problem. Hopefully someone out there has some ideas. Thanks, Shaun. From hancock at anansispaceworks.com Thu Aug 25 02:13:18 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 25 Aug 2005 01:13:18 -0500 Subject: Newbie question: Sub-interpreters for CAD program In-Reply-To: References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: <200508250113.18691.hancock@anansispaceworks.com> On Wednesday 24 August 2005 09:12 pm, Peter Hansen wrote: > Terry Hancock wrote: > >>I have a strong EE and hardware background (hence my need to write a > >>CAD program that doesn't piss me off), but not a CS background. > > > > You probably ought to consider starting with something existing like > > the Gnu EDS project -- but I'm assuming you probably already know > > about that. > > Or even http://www.pythoncad.org/ which, although probably for > mechanical CAD work (I haven't looked at it, don't really know), is > surely a good place to get ideas of what Python can do in this area. No, I doubt it. PythonCAD is a 2D mechanical CAD drawing system. I don't think it would be anywhere near what this guy wants. They're just different applications. He's looking for an electronic CAD system or EDA, I'm pretty sure (or looking to write one, rather). Anybody that says he's not "looking for a CAD program" but "looking for a CAD program that doesn't piss me off" is probably a power-user. ;-D Not a reflection on PythonCAD, though -- it's a pretty cool project, I recommend it to anyone interested in exploring general purpose 2D CAD drawing systems. Among other advantages, it is written in Python, so probably somewhat easier to script (haven't tried, though), and it uses a self-defined XML format for CAD drawings, which is an interesting standards move, given that free CAD formats have hitherto been pretty limited, leaving professionals stuck with proprietary binary formats, and not very happy with them (there are technical reasons for not liking the DXF format which is a free format, albeit created by AutoDesk). At present I believe that PythonCAD is about on par with QCAD, but I'd bet on PythonCAD for potential, because of these design advantages. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From opengeometry at yahoo.ca Tue Aug 2 12:29:38 2005 From: opengeometry at yahoo.ca (William Park) Date: Tue, 02 Aug 2005 12:29:38 -0400 Subject: Why Tcl/Tk? References: <97c93$42e80da0$d8fe9d88$9743@PRIMUS.CA> Message-ID: Thomas Bartkus wrote: > > "William Park" wrote in message > news:97c93$42e80da0$d8fe9d88$9743 at PRIMUS.CA... > > Jerry He wrote: > > > I'm a little curious, why does most scripting > > > languges(i.e. python and ruby) use Tcl/Tk rather than > > > wx or Fox as its standard GUI? Although I did notice > > > that the Vpython IDE that uses Tkinker starts up a lot > > > faster than the DrPython IDE that uses wxpython. But > > > that makes no sense, Tk is based on Tcl, a scripting > > > language, but wx is written in C++. > > > > Old habits die hard. Soon, these folks will die off, and we'll be left > > with GTK+ or wxWidgets. > > > > Ahhh! That devilish little "or" > > If we only knew which one :-) > Thomas Bartkus If you're C, then GTK+. If you're C++, then wxWidgets. Since I do C mostly, I looked into GTK+ (actually, stared at the doc for 2 weeks and absorbed what I can through osmosis) and decided to include GTK+ interface into Bash shell. Here is the result: http://home.eol.ca/~parkw/index.html#gtk -- William Park , Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From fred at adventistcare.org Tue Aug 16 17:19:09 2005 From: fred at adventistcare.org (Sells, Fred) Date: Tue, 16 Aug 2005 17:19:09 -0400 Subject: FW: python oldie, SWIG newbie needs help Message-ID: <777056A4A8F1D21180EF0008C7DF75EE03317582@sunbelt.org> -----Original Message----- From: Sells, Fred Sent: Tuesday, August 16, 2005 5:09 PM To: python-list at python.org Subject: python oldie, SWIG newbie needs help I've been trying all day to get a simple SWIG generated interface to a simple (but ugly) piece of c++ code provided to us by the gov't. I've tried google, and every variation on the examples I can think of. I'm really under the gun to get this working and would appreciate someone showing me the error of my ways. We're running python 2.3 redhat 9 and gcc although the code is c++, it does not use classes and the only function I need to access is "RugCacl". My typical error messages are shown below and the files attached. I've tried SWIG with and without --shadow. If my last line of the .i file is %include rug520.cpp, I don't get an error on import, but the RugCalc function is undefined. $ python rug520.py Traceback (most recent call last): File "rug520.py", line 5, in ? import _rug520 ImportError: /home/frsells/dll/_rug520.so: undefined symbol: RugCalc part of the c++ code is below; the whole file was bigger than the mail handler would accept. #include "rug520.h" #include #include #include #include #define LINUX char masItemVal[108][5]; void LoadValue( char * sMdsRecord, int location, int length, char * masItemValue ) { for ( int i=0; i -------------- next part -------------- A non-text attachment was scrubbed... Name: rug520.h Type: application/octet-stream Size: 783 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: rug520.i Type: application/octet-stream Size: 379 bytes Desc: not available URL: From alengarbage at yahoo.com Fri Aug 12 00:17:31 2005 From: alengarbage at yahoo.com (Lenny G.) Date: 11 Aug 2005 21:17:31 -0700 Subject: constructing bytestrings Message-ID: <1123820251.064105.280190@g44g2000cwa.googlegroups.com> I use 's = os.read(fd, 12)' to grab 12 bytes from a file. Now, I want to create a string, s1, which contains 16-12=4 bytes: 4,0,0,0, followed by the contents of s. I know how to 's1 = "\x04\x00\x00\x00"' and how to 's3 = s1+s', but I don't know how to construct s1 dynamically (i.e., given N, construct "N" followed by N-1 "0", where "N" and "0" are single byte values with N<16). How do I do this? From mediocre_person at hotmail.com Thu Aug 4 18:37:53 2005 From: mediocre_person at hotmail.com (Terrance N. Phillip) Date: Thu, 04 Aug 2005 17:37:53 -0500 Subject: Parallel arithmetic? Message-ID: <42f298d6$1_5@alt.athenanews.com> Given a and b, two equal length lists of integers, I want c to be [a1-b1, a2-b2, ... , an-bn]. I can do something like: c = [0] * len(a) for ndx, item in enumerate(a): c[ndx] = item - b[ndx] But I'm wondering if there's a better way, perhaps that avoids a loop? Nick. (I seem to recall from my distant past that this sort of thing was dead easy with APL... c = a-b, more or less.) N From cassity.home at sbcglobal.net Sun Aug 28 11:51:03 2005 From: cassity.home at sbcglobal.net (APCass) Date: Sun, 28 Aug 2005 15:51:03 GMT Subject: NooB Question Message-ID: How do you execute a .py in Linux with KDE? If I double click on my program it opens Kwrite, for editing. From haircut at gmail.com Wed Aug 31 17:02:24 2005 From: haircut at gmail.com (Adam Monsen) Date: 31 Aug 2005 14:02:24 -0700 Subject: time.strptime() for different languages In-Reply-To: References: <1125519061.261802.285840@o13g2000cwo.googlegroups.com> Message-ID: <1125522144.209140.266590@f14g2000cwb.googlegroups.com> No, this doesn't seem to work, and I can't find anything in the documentation indicating that it should. >>> import os >>> os.getenv('LANG') 'nl_NL' >>> import time >>> time.strptime("10 augustus 2005 om 17:26", "%d %B %Y om %H:%M") Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/_strptime.py", line 292, in strptime raise ValueError("time data did not match format: data=%s fmt=%s" % ValueError: time data did not match format: data=10 augustus 2005 om 17:26 fmt=%d %B %Y om %H:%M -- Adam Monsen http://adammonsen.com/ From steve at ferg.org Fri Aug 26 12:13:35 2005 From: steve at ferg.org (Steve) Date: 26 Aug 2005 09:13:35 -0700 Subject: Experience regarding Python tutorials? In-Reply-To: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> Message-ID: <1125072815.753219.62420@g47g2000cwa.googlegroups.com> Python is an excellent place to start. Avoid Perl at all costs. There is a new beginners book on Python that looks interesting. It is from WROX (the red cover folks) and called "Beginning Python". http://www.amazon.com/exec/obidos/tg/detail/-/0764596543/qid=1125072498/sr=1-1/ref=sr_1_1/002-4477837-1552864?v=glance&s=books From onurb at xiludom.gro Mon Aug 22 11:25:18 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 22 Aug 2005 17:25:18 +0200 Subject: loop in python In-Reply-To: References: Message-ID: <4309ee5f$0$7620$626a14ce@news.free.fr> km wrote: > Hi all, > > Why is it that the implementation of empty loop so slow in python when compared to perl ? > > #i did this in python (v 1.5) Python 1.5.2 was released in april 1999. Current Python version is 2.4.1. Please consider upgrading - unless of course you just want to troll... > for x in xrange(1000): > print x This is not an empty loop. An empty loop is for x in xrange(1000): pass > Is python runtime slow at all aspects when compared to perl ? Is your question serious or are you just trolling ? > I really wonder what makes python slower than perl ? I really wonder what makes my old P133/32mo running w98 slower that my more recent XP1200/256mo running gentoo/linux. > Is there any proposal to make python faster in future versions ? The future is already here.... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From mwm at mired.org Mon Aug 22 14:28:58 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 22 Aug 2005 14:28:58 -0400 Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <43057145.1837895163@news.oz.net> <1124702613.567210.239460@o13g2000cwo.googlegroups.com> Message-ID: <863bp1q105.fsf@bhuda.mired.org> "Greg McIntyre" writes: > My files are large, hence 1 character at a time, not f.read(). There are alternatives between the two. You could read in a chunk of reasonable size for your platform. Say 10meg on a recent workstation, or 100meg on a current workstation. > This is code from another employee and I'm just in the stages of going > through it and doing a basic clean-up before I get on to a proper > efficiency assessment, hence I don't want to change the way it works, > just make it as short and lucid as I can. Well, the thing that has been hinted around but not explicitly stated is that doing thing one character at a time in Python is a "code smell", by which I mean it's an indication that there could be a better way to do things, and it's probably worthwhile spending a little time looking for it. On the other hand, if you've already planned another pass over the code, that might be the time to look into this. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From peter at engcorp.com Wed Aug 10 07:36:34 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Aug 2005 07:36:34 -0400 Subject: Catching stderr output from graphical apps In-Reply-To: References: Message-ID: Bryan Olson wrote: > Here's a module to show stderr output from console-less Python > apps, and stay out of the way otherwise. I plan to make a ASPN > recipe of it, but I thought I'd run it by this group first. For what it's worth, I believe you've basically duplicated the functionality available in wxPython in the standard App object. -Peter From pd at traxon.com Wed Aug 24 13:41:20 2005 From: pd at traxon.com (Paul Dale) Date: Wed, 24 Aug 2005 19:41:20 +0200 Subject: Should I move to Amsterdam? In-Reply-To: References: Message-ID: <430CB140.5080608@traxon.com> >But yes, the Netherlands is a highly civilised country - up there with >Denmark and Canada, and above the UK, France or Germany, IMNERHO. I'm not >going to bother comparing it to the US! > > How strange that you put Canada so high on your list. From dimitri.pater at gmail.com Tue Aug 16 18:16:21 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Wed, 17 Aug 2005 00:16:21 +0200 Subject: Help! In-Reply-To: <20050816220927.A0C7B16415C@ws1-4.us4.outblaze.com> References: <20050816220927.A0C7B16415C@ws1-4.us4.outblaze.com> Message-ID: Hi, the MS-DOS Prompt is actually the Python shell: >>> Now type: >>> print "Hello Ert" and it returns: Hello Ert Your first Python program! Do yourself a favour and google for "python tutorials" good luck, dimitri On 8/17/05, Ert Ert wrote: > > When ever i try to open python it opens as a MS-DOS Prompt I do not know > what else to do i need your help so if you could please help. Oh and this is > the second time i emailed you so please do not send me back an automated > message thank you. > > -- > > ___________________________________________________________ > Sign-up for Ads Free at Mail.com > http://www.mail.com/?sr=signup > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- All truth passes through three stages. First, it is ridiculed. Second, it is violently opposed. Third, it is accepted as being self-evident. Arthur Schopenhauer ----- Please visit dimitri's website: www.serpia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From apardon at forel.vub.ac.be Wed Aug 31 03:13:12 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Aug 2005 07:13:12 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: Op 2005-08-30, Steve Holden schreef : > Antoon Pardon wrote: >> Op 2005-08-29, Steve Holden schreef : >> >>>Antoon Pardon wrote: >>> >>>>Op 2005-08-27, Steve Holden schreef : >>>> >>>> >>>>>If you want an exception from your code when 'w' isn't in the string you >>>>>should consider using index() rather than find. >>>> >>>> >>>>Sometimes it is convenient to have the exception thrown at a later >>>>time. >>>> >>>> >>>> >>>>>Otherwise, whatever find() returns you will have to have an "if" in >>>>>there to handle the not-found case. >>>> >>>> >>>>And maybe the more convenient place for this "if" is in a whole different >>>>part of your program, a part where using -1 as an invalid index isn't >>>>at all obvious. >>>> >>>> >>>> >>>>>This just sounds like whining to me. If you want to catch errors, use a >>>>>function that will raise an exception rather than relying on the >>>>>invalidity of the result. >>>> >>>> >>>>You always seem to look at such things in a very narrow scope. You never >>>>seem to consider that various parts of a program have to work together. >>>> >>> >>>Or perhaps it's just that I try not to mix parts inappropriately. >> >> >> I didn't know it was inappropriately to mix certain parts. Can you >> give a list of modules in the standard list I shouldn't mix. >> >> >>>>So what happens if you have a module that is collecting string-index >>>>pair, colleted from various other parts. In one part you >>>>want to select the last letter, so you pythonically choose -1 as >>>>index. In an other part you get a result of find and are happy >>>>with -1 as an indictation for an invalid index. Then these >>>>data meet. >>>> >>> >>>That's when debugging has to start. Mixing data of such types is >>>somewhat inadvisable, don't you agree? >> >> >> The type of both data is the same, it is a string-index pair in >> both cases. The problem is that a module from the standard lib >> uses a certain value to indicate an illegal index, that has >> a very legal value in python in general. >> > Since you are clearly feeling pedantic enough to beat this one to death > with a 2 x 4 please let me substitute "usages" for "types". But it's not my usage but python's usage. > In the case of a find() result -1 *isn't* a string index, it's a failure > flag. Which is precisely why it should be filtered out of any set of > indexes. once it's been inserted it can no longer be distinguished as a > failure indication. Which is precisely why it was such a bad choice in the first place. If I need to write code like this: var = str.find('.') if var == -1: var = None each time I want to store an index for later use, then surely '-1' shouldn't have been used here. >>>I suppose I can't deny that people do things like that, myself included, >> >> >> It is not about what people do. If this was about someone implementing >> find himself and using -1 as an illegal index, I would certainly agree >> that it was inadvisable to do so. Yet when this is what python with >> its libary offers the programmer, you seem reluctant find fault with >> it. > I've already admitted that the choice of -1 as a return value wasn't > smart. However you appear to be saying that it's sensible to mix return > values from find() with general-case index values. I'm saying it should be possible without a problem. It is poor design to return a legal value as an indication for an error flag. > I'm saying that you > should do so only with caution. The fact that the naiive user will often > not have the wisdom to apply such caution is what makes a change desirable. I don't think it is naive, if you expect that no legal value will be returned as an error flag. >>>but mixing data sets where -1 is variously an error flag and a valid >>>index is only going to lead to trouble when the combined data is used. >> >> >> Yet this is what python does. Using -1 variously as an error flag and >> a valid index and when people complain about that, you say it sounds like >> whining. >> > What I am trying to say is that this doesn't make sense: if you want to > combine find() results with general-case indexes (i.e. both positive and > negative index values) it behooves you to strip out the -1's before you > do so. Any other behaviour is asking for trouble. I would say that choosing this particular return value as an error flag was asking for trouble. My impression is that you are putting more blame on the programmer which fails to take corrective action, instead of on the design of find, which makes that corrective action needed in the first place. -- Antoon Pardon From nospam at nospam.com Mon Aug 22 23:45:50 2005 From: nospam at nospam.com (42) Date: Tue, 23 Aug 2005 03:45:50 GMT Subject: Sandboxes References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: In article , eurleif at ecritters.biz says... > 42 wrote: > > FWIW I've already given up on making python secure. I agree that odds > > are extremely high that I've missed something. I'm just curious to see > > what one of the holes I left is, preferably without wading through > > hundreds of pages :) > > f = [x for x in [].__class__.__bases__[0].__subclasses__() if > x.__name__=='file'][0] > f('/path/to/important/file', 'w').close() > Thanks. Still it clearly falls within the the scope of what I wanted to remove: the built in reflection/metadata functions. I just didn't read enough of the language spec to know there were more of them hidden here and there than what were listed in keywords and built-in functions. But they are a finite set. Evidently I'm not the one to do it, but someone who knew python better, could probably enumerate the reflection stuff more effectively than me. I already gave up, but I don't think its a dead concept. From paolo_veronelli at tiscali.it Thu Aug 11 06:47:54 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Thu, 11 Aug 2005 12:47:54 +0200 Subject: set of sets Message-ID: <42FB2CDA.2040106@tiscali.it> I thought rewriting __hash__ should be enough to avoid mutables problem but: class H(set): def __hash__(self) return id(self) s=H() f=set() f.add(s) f.remove(s) the add succeeds the remove fails eventually not calling hash(s). Thanks for help Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From bill.mill at gmail.com Fri Aug 5 09:35:47 2005 From: bill.mill at gmail.com (Bill Mill) Date: Fri, 5 Aug 2005 09:35:47 -0400 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> Message-ID: <797fe3d4050805063553b7333d@mail.gmail.com> > I really wish Python could be more widely available on web server > machines. This is just my own experience and I would like to hear your > comments. > I would like a pony... no, wait, even better, a unicorn! Peace Bill Mill bill.mill at gmail.com PS (the gist is, why don't you offer some constructive comments, instead of ones we can do nothing about?) From yoav_artzi at il.vio.com Sun Aug 28 09:23:25 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Sun, 28 Aug 2005 16:23:25 +0300 Subject: close failed: [Errno 0] No error goes to stdout Message-ID: <4311b9bf@news.bezeqint.net> I use the following code to the console output: def get_console(cmd): try: p_in, p_out, p_err = os.popen3(cmd) except: pass out_str = '' for obj in p_out: out_str = out_str + obj for obj in p_err: out_str = out_str + obj return out_str for some reason some exceptions (stderr outputs) are not captured by the try method, and slip to the screen. Any one has any idea on how can prevent from any output that I don't want to? The output I get on these exceptions is: close failed: [Errno 0] No error thanks. From mwm at mired.org Fri Aug 5 22:02:15 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 05 Aug 2005 22:02:15 -0400 Subject: pain References: <11f2846qlu2kpc9@corp.supernews.com> <86wtn1yzuu.fsf@bhuda.mired.org> <42f3b777$1_3@newspeer2.tds.net> Message-ID: <86iryjyg9k.fsf@bhuda.mired.org> Kent Johnson writes: > Mike Meyer wrote: >> The compiled jython will pay a performance penalty for being >> dynamic. Where Java knows the type of objects, and can deduce the >> correct method to call at compile time (well, some of the time, >> anyway), the jython code will have to do a method search at run time. > > Yes, the compiled code makes heavy use of the Jython runtime to get anything done. > > *But* most of the hard work will probably be done by Java code in > libraries you call. For example a Swing UI, XML parsing, database > calls, etc all will happen in Java code. One would hope so. That's how you get good performance out of CPython apps - you arrange for the heavy lifting to be done by libraries written in C. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From albalmer at att.net Mon Aug 29 13:13:45 2005 From: albalmer at att.net (Alan Balmer) Date: Mon, 29 Aug 2005 10:13:45 -0700 Subject: Jargons of Info Tech industry References: <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: <1gg6h1lah2su96huukfobvgmcbnrp43514@4ax.com> On Fri, 26 Aug 2005 16:47:10 GMT, Chris Head wrote: >This point I agree with. There are some situations - 'net cafes included >- - where thick e-mail clients don't work. Even so, see below. I use Portable Thunderbird, on a USB memory stick. All I need is a USB port and an internet connection. -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From hongqn at gmail.com Fri Aug 12 12:47:58 2005 From: hongqn at gmail.com (Qiangning Hong) Date: Sat, 13 Aug 2005 00:47:58 +0800 Subject: need help with my append syntax In-Reply-To: <1123864268.248317.23940@g44g2000cwa.googlegroups.com> References: <1123864268.248317.23940@g44g2000cwa.googlegroups.com> Message-ID: <42FCD2BE.3030405@gmail.com> yaffa wrote: > dear folks, > > i'm trying to append a semicolon to my addr string and am using the > syntax below. for some reason the added on of the ; doesn't work. > when i print it out later on it only shows the original value of addr. > > addr = incident.findNextSibling('td') > addr.append('%s;') Is addr is really a string? AFAIK, strings havn't an append methond. use += to extend strings: .>>> addr = 'abc' .>>> addr += '%s;' .>>> addr 'abc%s;' -- Qiangning Hong I'm usually annoyed by IDEs because, for instance, they don't use VIM as an editor. Since I'm hooked to that, all IDEs I've used so far have failed to impress me. -- Sybren Stuvel @ c.l.python Get Firefox! From grante at visi.com Sat Aug 13 13:02:47 2005 From: grante at visi.com (Grant Edwards) Date: Sat, 13 Aug 2005 17:02:47 -0000 Subject: how to append semicolon to a variable References: <1123946072.577232.218530@o13g2000cwo.googlegroups.com> Message-ID: <11fs9tn73j02298@corp.supernews.com> On 2005-08-13, yaffa wrote: > i have the following lines of python code: > > couch = incident.findNextSibling('td') > price = couch.findNextSibling('td') > sdate = price.findNextSibling('td') > city = sdate.findNextSibling('td') > strUrl = addr.b.string > currently what this ends up doing is creating something like this > > couch3201/01/2004newyork > > now what i want to do is add a semicolon after the couch, price, sdate, > city so that i get something like this > > couch;32;01/01/2004;new york Try this: s = ';'.join([couch,price,sdate,city]) print s > p.s. i tried couch = couch + ';' > and then i tried couch = couch + ";" both of those should have worked fine. > and then i tried couch = couch.append ';' 1) The append() method of a sequence doesn't return anything. 2) You call methods using () 3) String are immutable, and therefore don't have an append method. Perhaps you ought to read through the tutorial? -- Grant Edwards grante Yow! LOOK!!! I'm WALKING at in my SLEEP again!! visi.com From steve at holdenweb.com Sat Aug 20 06:30:39 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 20 Aug 2005 11:30:39 +0100 Subject: Database of non standard library modules... In-Reply-To: <11gcnlkt3q2bk53@news.supernews.com> References: <11gcnlkt3q2bk53@news.supernews.com> Message-ID: Nigel Rowe wrote: > Steve Holden wrote: > > >>Robert Kern wrote: >> >>>Jon Hewer wrote: >>> >>> >>>>Is there an online database of non standard library modules for Python? >>> >>> >>>http://cheeseshop.python.org/pypi >>> >> >>While cheeseshop might resonate with the Monty Python fans I have to say >>I think the name sucks in terms of explaining what to expect. If I ask >>someone where I can find a piece of code and the direct me to the cheese >>shop, I might look for another language. >> >>regards >> Steve > > > To be fair, it's really the "Python Package Index", it just happens to be > stored on a machine called cheeseshop. > > You are being more that fair! The page in question reads: """ Cheese Shop: Home The Python Cheese Shop is a repository of software for the Python programming language. Customer: Now then, some cheese please, my good man. Owner: (lustily) Certainly, sir. What would you like? Customer: Well, eh, how about a little red Leicester. Owner: I'm, a-fraid we're fresh out of red Leicester, sir. There are currently 874 packages in the Cheese Shop. You may: * Search * Browse the tree of packages * View a flat list of all packages * Submit package information (note that you must register to submit) """ followed by a list of 20 recent additions. This is simply inane web design, and is a significant reason why Python isn't always taken seriously. The words "Python Package Index" don't appear anywhere in the body text. The relevant nav bar section is headed "Cheese Shop Actions", which is more or less guaranteed to confuse many people whose first language isn't English, and many (not in the know about Monty Python) whose first language *is* English. Contras with www.cpan.org, which starts: """ Comprehensive Perl Archive Network 2005-08-20 online since 1995-10-26 2957 MB 263 mirrors 4541 authors 8522 modules Welcome to CPAN! Here you will find All Things Perl. """ followed by a really good, and not overcrowded, set of links that make it quite clear how to find various important features of the site. No in-jokes, no distractions, just what the reader wants. User perceptions are altered in negative ways by stuff like the cheese shop, and while I firmly believe there's a place for humour in life, I don't believe it should get in the way of progress towards total world domination :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From simon.brunning at gmail.com Tue Aug 23 10:53:29 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Tue, 23 Aug 2005 15:53:29 +0100 Subject: Convert float to string ... In-Reply-To: References: Message-ID: <8c7f10c6050823075322a54e59@mail.gmail.com> On 8/23/05, Konrad M?hler wrote: > How can i convert a float value into a string value? > > string_value1 = string(float_value) + ' abc' string_value1 = str(float_value) + ' abc' -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From pwatson at redlinepy.com Sun Aug 14 22:48:02 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Sun, 14 Aug 2005 21:48:02 -0500 Subject: Spaces and tabs again In-Reply-To: References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> <6spsf1hr7i0ho9fa0ptauhst1s61jkig13@4ax.com> Message-ID: <43000262.7050209@redlinepy.com> Dan Sommers wrote: > On Sun, 14 Aug 2005 01:04:04 GMT, > Dennis Lee Bieber wrote: > > >>On 13 Aug 2005 13:18:21 -0700, sigzero at gmail.com declaimed the following >>in comp.lang.python: > > >>>Are you kidding? You are going to MANDATE spaces? >>> >> >> After the backlash, Python 4.0 will ban leading spaces and require >>tabs > > > Why not petition the unicode people to include PYTHON INDENT and PYTHON > DEDENT code points, and leave the display up to the text editors? ;-) > > Regards, > Dan The Unicode people will correctly point out that there is already a Unicode codepoint assignment which can be used for this purpose. It is even in the BMP portion of the C0 controls group. 0009 = HORIZONTAL TABULATION From orome.the.valar at gmail.com Sat Aug 13 07:52:45 2005 From: orome.the.valar at gmail.com (sinan .) Date: Sat, 13 Aug 2005 14:52:45 +0300 Subject: simpli int/str problem In-Reply-To: <42fcd9ee$1@nntp0.pdx.net> References: <8c05f79c05081207443094dc67@mail.gmail.com> <42fcd9ee$1@nntp0.pdx.net> Message-ID: <8c05f79c050813045222f6b077@mail.gmail.com> i thank you all, first of al ill change my dictinary variable name :) then ill use %s and %d . and thanks for other examples,these examples enchance my python-way thinking. :) On 8/12/05, Scott David Daniels wrote: > Paolino wrote: > > sinan . wrote: > > > >> hi all, > >> i have a string and int values in same dictionary like this > >> dict = {'str_name': 'etc' , 'int_name' : 112 } > Bad idea to call this "dict" -- that is a system-defined name > for the dictionary type. I'll use "holder" below. > > >> the error occures when do this > >> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + dict['str_name'] + "', > >> '" + dict['int_name'] + "')" > ^^ I suspect this should be: > SQL = "INSERT INTO TABLENAME(AH, BH) VALUES (... > >> cursor.execute(SQL) > >> python does not accep dict['int_name'] in SQL variable but when i > >> convert this variable to the str , python accepts but i cannot insert > >> that into database because database only accept int in `BH ` > >> thanks. > > > Try use: > > SQL = "INSERT INTO (`AH`, `BH` ) VALUES > > ('%s,%d)"%(dict['str_name'],dict['int_name']) > This will work, but the DB interface allows you to leave the > variable formatting to it. Depending on the parameter style > your DB interface supports, you may use at least one of: > > cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(?, ?)", > [(holder['str_name'], holder['int_name'])]) > or > cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(:1, :2)", > [(holder['str_name'], holder['int_name'])]) > ### I think, it _might_ be ...(0, :1)", > or > cursor.execute("INSERT INTO TABLENAME(AH, BH) " > "VALUES(:str_name, :int_name)", > holder) > > --Scott David Daniels > Scott.Daniels at Acm.Org > -- > http://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Tue Aug 16 16:48:04 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2005 22:48:04 +0200 Subject: 'import copy' too slow?, was Re: [Python-Dev] implementation of copy standard lib References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: [Martijn Brouwer] > Importing copy takes 5-10 times more time that > import os, string and re together! If your measurement isn't flawed, try again after replacing the following import in copy.py try: from org.python.core import PyStringMap except ImportError: PyStringMap = None with just PyStringMap = None The import is expected to fail on CPython -- and it may take a long time depending on what you have in your path. Peter From mikael at isy.liu.se Mon Aug 29 03:38:38 2005 From: mikael at isy.liu.se (Mikael Olofsson) Date: Mon, 29 Aug 2005 09:38:38 +0200 Subject: aproximate a number In-Reply-To: <43122d6d$0$97103$ed2619ec@ptn-nntp-reader03.plus.net> References: <43122d6d$0$97103$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: Michael Sparks wrote: > def approx(x): > return int(x+1.0) I doubt this is what the OP is looking for. >>> approx(3.2) 4 >>> approx(3.0) 4 Others have pointed to math.ceil, which is most likely what the OP wants. /Mikael Olofsson Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE]) Link?pings universitet ----------------------------------------------------------------------- E-Mail: mikael at isy.liu.se WWW: http://www.dtr.isy.liu.se/en/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com Vi s?ker tenorer och basar! From Scott.Daniels at Acm.Org Mon Aug 15 14:57:01 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 15 Aug 2005 11:57:01 -0700 Subject: Py_DECREF Question: In-Reply-To: References: Message-ID: <4300d9bf$1@nntp0.pdx.net> Jeremy Moles wrote: > When I add an object created locally to a mapping or sequence ... > I need to call Py_DECREF on the object, right? ... for example: > PyObject* list = Py_Buildvalue("[]"); > ... > PyObject* num = Py_BuildValue("i", 10); > PyList_Append(list, num); > ... > > ... does anyone have any tools and/or recommendations for detecting > memory leaks when writing extension modules in C? ... Here's how to answer this for yourself: PyObject* list = Py_Buildvalue("[]"); int precount; ... PyObject* num = Py_BuildValue("i", 10); precount = num.ob_refcnt; PyList_Append(list, num); ... If you need to do the DECREF, precount should exceed num.ob_refcnt. If they match, the "PyList_Append" call "stole" your reference. --Scott David Daniels Scott.Daniels at Acm.Org From johan at pulp.se Wed Aug 3 12:52:29 2005 From: johan at pulp.se (Johan Lindberg) Date: 3 Aug 2005 09:52:29 -0700 Subject: finding sublist References: <1122991014.595476.5740@g47g2000cwa.googlegroups.com> <1123003985.735221.119630@g44g2000cwa.googlegroups.com> <1123011702.830491.224500@g43g2000cwa.googlegroups.com> Message-ID: <1123087949.185607.105760@o13g2000cwo.googlegroups.com> > thanks everyone. only a question. there is a way to advantage of binary > sequences? I doubt you'll find any way to optimize the code that somehow only applies to binary sequences. You still have to find each possible subsequence of minimum length within the sequence and compare it to all other possible subsequences and that's what's going to take most of the time. If you haven't already, check out psyco (http://psyco.sourceforge.net/). It will most definitely make your code run faster. BR Johan Lindberg johan at pulp.se From nid_oizo at yahoo.com_removethe_ Mon Aug 8 04:03:21 2005 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Mon, 08 Aug 2005 04:03:21 -0400 Subject: PEP: Specialization Syntax In-Reply-To: <1123481295.549324.99810@g49g2000cwa.googlegroups.com> References: <42F66FF2.7010901@v.loewis.de> <1123481295.549324.99810@g49g2000cwa.googlegroups.com> Message-ID: <4iEJe.5130$651.540962@weber.videotron.net> Kay Schluehr wrote: > def makeClass(cls_name, **kw): > return type(cls_name,(), kw) > >>>>MyObject = makeClass("MyObject",a=8) >>>>MyObject As said to Bengt, a place is needed to write the class definition. There's no need for metaclass in that case: def makeType(a, b, c=someDefault): arguments = locals() class MyObject: pass # Complete definition here MyObject.__dict__.update(arguments) return MyObject Regards, Nicolas From max at alcyone.com Mon Aug 8 23:25:29 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 08 Aug 2005 20:25:29 -0700 Subject: Pickling limitation with instances defining __cmp__/__hash__? In-Reply-To: <5OKdnav6rfDWOV3fRVn-hQ@speakeasy.net> References: <5OKdnav6rfDWOV3fRVn-hQ@speakeasy.net> Message-ID: Erik Max Francis wrote: > I've come across a limitation in unpickling certain types of complex > data structures which involve instances that override __hash__, and was > wondering if it was known (basic searches didn't seem to come up with > anything similar) and if there is a workaround for it short of > restructuring the data structures in question. Replying to my own (old) post here, I finally got back to this and found the best solution was to define surrogate set and dictionary classes that internally used the IDs as keys, eliminating the circular dependency. Examples of SafeSet and SafeDict serving this purpose follow, though note that I only defined the methods that I used, rather than the full and complete interfaces for sets and dictionaries (though it should serve as an example for those who need to do more): class SafeSet(_ReprMixin): @staticmethod def ider(thing): return thing.id def __init__(self, ider=None): if ider is not None: self.ider = ider self._map = {} # id -> thing def __len__(self): return len(self._map) def __contains__(self, thing): return self.ider(thing) in self._map def add(self, thing): key = self.ider(thing) if self._map.has_key(key): assert self._map[key] is thing self._map[key] = thing def remove(self, thing): del self._map[self.ider(thing)] def pop(self): iterator = self._map.iterkeys() next = iterator.next() return self._map.pop(next) def clear(self): self._map.clear() def copy(self): return copy.copy(self) def update(self, sequence): for thing in sequence: self.add(thing) def difference(self, other): thisSet = set(self._map.iterkeys()) otherSet = set(other._map.iterkeys()) newSet = thisSet.difference(otherSet) safeSet = SafeSet() for key in newSet: safeSet.add(self._map[key]) return safeSet def __iter__(self): return self._map.itervalues() def __str__(self): return 'set(' + str(self._map.keys()) + ')' class SafeDict(_ReprMixin): @staticmethod def ider(thing): return thing.id def __init__(self, ider=None): if ider is not None: self.ider = ider self._keys = {} # id -> key self._values = {} # id -> value def __len__(self): return len(self._keys) def __contains__(self, thing): return self.ider(thing) in self._keys def __getitem__(self, thing): return self._values[self.ider(thing)] def __setitem__(self, thing, value): key = self.ider(thing) self._keys[key] = thing self._values[key] = value def __delitem__(self, thing, value): key = self.ider(thing) del self._keys[key] del self._values[key] def keys(self): return self._keys.values() def iterkeys(self): return self._keys.itervalues() def values(self): return self._values.values() def itervalues(self): return self._values.itervalues() def items(self): return [(self._keys[x], self._values[x]) for x in self._keys] def iteritems(self): return ((self._keys[x], self._values[x]) for x in self._keys) def clear(self): self._keys.clear() self._values.clear() def copy(self): return copy.copy(self) def update(self, mapping): for key, value in mapping.iteritems(): self[key] = value def has_key(self, thing): return self._keys.has_key(self.ider(thing)) def get(self, thing, default=None): return self._values.get(self.ider(thing), default) def setdefault(self, thing, default): key = self.ider(thing) if key in self._keys: return self._values[key] else: self._keys[key] = thing self._values[key] = default def __iter__(self): return self._keys.itervalues() def __str__(self): return str(self._values) -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis The only completely consistent people are the dead. -- Aldous Huxley From deets at web.de Fri Aug 12 04:22:56 2005 From: deets at web.de (Diez B. Roggisch) Date: 12 Aug 2005 01:22:56 -0700 Subject: Using globals with classes In-Reply-To: <42fc2e42$0$18637$14726298@news.sunsite.dk> References: <42fc2e42$0$18637$14726298@news.sunsite.dk> Message-ID: <1123834976.441590.317320@g47g2000cwa.googlegroups.com> > Is there a way to make a Python function "remember" the values of certain > variables ? Or use fortran 95 like use module, only : varname, type of > within a def ? I'm not sure what you are trying to do here - but it seems to me that you are not properly designing your application. You really shouldn't use the Designers code-insertion features. The reason is simple: you the have two tools to write code in instead of one (your editor/IDE). And you don't make plotkey* global - use instance variables. So I'm going to describe how I dow work with PyQt: - I create a Widget in the designer - compile it using pyuic - _extend_ it - write my code in the extended version So I end up with something like this (I use modules to separate classes): ui/plot.ui ui/plot.py views/plot.py where views/plot.py looks like this: class Plot(ui.plot.Plot): def __init__(self, *args): ui.plot.Plot.__init__(self, *args) self.plotkey1 = def update(self): # access self.plotkey here HTH, DIez From cliff at develix.com Mon Aug 1 14:20:43 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 11:20:43 -0700 Subject: Dabo in 30 seconds? In-Reply-To: <42EE6291.5010705@ulmcnett.com> References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> <42EE6291.5010705@ulmcnett.com> Message-ID: <1122920443.19618.347.camel@localhost.localdomain> On Mon, 2005-08-01 at 10:57 -0700, Paul McNett wrote: > Terry Reedy wrote: > > "Ed Leafe" wrote in message > > news:200508010830.27322.ed at leafe.com... > > >>I'm serious here: I want to know what people consider acceptable for a > >>software package that relies on other packages. > > > To me, acceptability depends on the audience. Do you want to limit Dabo to > > professional developers comfortable with sometimes cryptic traceback > > messages or do you want to include people using Python as part of other > > activities? > > My concern with putting another layer on top of Python's excellent > traceback mechanism is that we could screw up and hide important > exceptions, or otherwise make it harder for the seasoned Pythonista to > get to the source of the issue. Nothing beats those tracebacks, ugly > though they may seem to a newbie... perhaps we need both methods, and to > default to the "nice" error handler. That sounds great. And fwiw, even "seasoned" developers like to be pointed directly to the problem if at all possible. For instance, it may be clear from the traceback *what* the error is, but unless you RTFM or are intimately familiar with wx, you may not immediately know how to solve it. Even if the traceback ended with an appropriate link to the FAQ, that would be outstanding. BTW, I'm with Terry: these discussions have definitely convinced me to give Dabo a try. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From n00m at narod.ru Wed Aug 31 14:17:47 2005 From: n00m at narod.ru (n00m) Date: 31 Aug 2005 11:17:47 -0700 Subject: Code run from IDLE but not via double-clicking on its *.py In-Reply-To: References: <1125402893.124342.54690@g47g2000cwa.googlegroups.com> <1125425945.667967.181000@g49g2000cwa.googlegroups.com> <1125478316.530781.315540@g44g2000cwa.googlegroups.com> <1125490472.670850.247240@g49g2000cwa.googlegroups.com> Message-ID: <1125512267.240716.144300@g49g2000cwa.googlegroups.com> Steve Holden wrote: > Now, let's see ... [presses fingers to temples and exercises psychic > powers] ... ah yes, its because you're DOING SOMETHING WRONG :-) I just admire this sort of humour! Made me chuckling and (even) laughing. From onurb at xiludom.gro Sat Aug 13 10:47:42 2005 From: onurb at xiludom.gro (bruno modulix) Date: Sat, 13 Aug 2005 16:47:42 +0200 Subject: Dictionary inheritance In-Reply-To: <1123876661.376716.141160@g44g2000cwa.googlegroups.com> References: <1123876661.376716.141160@g44g2000cwa.googlegroups.com> Message-ID: <42fe080f$0$18692$636a15ce@news.free.fr> Devan L wrote: > Talin wrote: > >>I want to make a dictionary that acts like a class, in other words, >>supports inheritance: (snip) > > Dictionaries aren't classes? They are. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From jrastrick at student.usyd.edu.au Sun Aug 7 20:31:02 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 7 Aug 2005 17:31:02 -0700 Subject: Euclid's Algorithm in Python? In-Reply-To: References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> Message-ID: <1123461062.574511.278540@g43g2000cwa.googlegroups.com> Good point. I suppose I'd only ever seen it implemented with the if test, but you're right, the plain while loop should work fine. Silly me. def gcd(a,b): while b != 0: a, b = b, a%b return a Even nicer. From fredrik at pythonware.com Tue Aug 30 10:33:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Aug 2005 16:33:07 +0200 Subject: regexps with unicode-aware characterclasses? References: <43146512.5000101@ofai.at> Message-ID: Stefan Rank wrote: > I know that there is a re.U switch that makes \w match all unicode word > characters, but there are no subclasses of that ([[:upper:]] or preferably \u). unicode character classes are not supported by the current RE engine. it's usually possible to work around this by matching all characters ("\w") in Unicode mode ("(?u)"), and postprocessing the result to get rid of invalid matches. From lycka at carmen.se Tue Aug 16 05:48:37 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 16 Aug 2005 11:48:37 +0200 Subject: Wheel-reinvention with Python In-Reply-To: References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <1124090875.292874.199610@o13g2000cwo.googlegroups.com> Message-ID: David E. Konerding DSD staff wrote: > Actually, the real problem with the wxWidgets documentation is that it doesn't tell you > *how* to do things. It does only a barely adequate job as an API reference, but what it lacks is > an extensive howto. I waste too much of my time dinking around deep in wxPython demos trying to figure out > what is the 'right way' to do things. Robin Dunn does an amazing job in answering questions on the mailing list, but the fact that it's Robin himself who responds to so many questions does suggest a problem. I guess it would be really good if someone (not me ;^) would wade through his postings to the mailing list and turn that into some kind of documents. The fact that his excellent, more or less daily postings are so badly needed does indicate a problem, either with the design of the toolkit, or with the docs. I'm not sure which. When will that wxpython book appear? From pwatson at redlinepy.com Fri Aug 5 11:51:35 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Fri, 05 Aug 2005 10:51:35 -0500 Subject: newbie question; output from simple print statement In-Reply-To: <1123254554.417700.22650@o13g2000cwo.googlegroups.com> References: <1123254554.417700.22650@o13g2000cwo.googlegroups.com> Message-ID: <42F38B07.3050805@redlinepy.com> epost2 at gmail.com wrote: > Can someone explain to me the output of this simple script? I wonder > why ['test1.txt'] is printed before "files in c:\", and also why None > shows up? > > ________________ > in file test.py: > > def main(): > > print "files in c:\ :%s" % ListFiles("c:\") > > def ListFiles(path): > for root,dirs,files in os.walk(path): > print files > > if __name__ == "__main__": > main(): > > ________________ > output: > > C:\> python test.py > ['test1.txt'] > files in c:\ :None The function ListFiles() is being called first. This produces the result that will be used to replace the %s of the print statement. In this case, the return value is None, so nothing is printed. How to Think Like a Computer Scientist http://www.ibiblio.org.obp/thinkCSpy/ From aahz at pythoncraft.com Thu Aug 11 13:04:15 2005 From: aahz at pythoncraft.com (Aahz) Date: 11 Aug 2005 10:04:15 -0700 Subject: Regular expression to match a # References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> Message-ID: In article <42fb45d7$1 at news.eftel.com>, John Machin wrote: > >Search for r'^something' can never be better/faster than match for >r'something', and with a dopey implementation of search [which Python's >re is NOT] it could be much worse. So please don't tell newbies to >search for r'^something'. You're somehow getting mixed up in thinking that "^" is some kind of "not" operator -- it's the start of line anchor in this context. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From gene.tani at gmail.com Sun Aug 21 15:28:55 2005 From: gene.tani at gmail.com (gene tani) Date: 21 Aug 2005 12:28:55 -0700 Subject: network programming In-Reply-To: References: Message-ID: <1124652535.363491.231760@o13g2000cwo.googlegroups.com> If i had started in 8th grade, I'd be Guido MartelliPeters by now! Anyway, these people claim to have 125 tutorials, it'll take at least a couple hours to work thru http://www.awaretek.com/tutorials.html From sybrenUSE at YOURthirdtower.com.imagination Sun Aug 28 04:43:37 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Sun, 28 Aug 2005 10:43:37 +0200 Subject: py to exe: suggestions? References: <1125217143.451511.25310@g43g2000cwa.googlegroups.com> Message-ID: chris patton enlightened us with: > I need to convert a python file to an '.exe'. I've tried py2exe, and > I don't like it because you have to include that huge dll and > libraries. Then what would you expect? The whole Python interpreter is needed if you want to run Python programs. It's more a smart packaging process than a compilation of Python code into an executable. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From mwh at python.net Wed Aug 17 05:10:12 2005 From: mwh at python.net (Michael Hudson) Date: Wed, 17 Aug 2005 09:10:12 GMT Subject: [Python-Dev] implementation of copy standard lib References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: Simon Brunning writes: > I think that copy is very rarely used. I don't think I've ever imported it. > > Or is it just me? Not really. I've used it once that I can recall, to copy a kind of generic "default value", something like: def value(self, v, default): if hasattr(source, v): return getattr(source, v) else: return copy.copy(default) (except not quite, there would probably be better ways to write exactly that). Cheers, mwh -- glyph: you're evil, too washort: I try not the good kind of evil the other kind -- from Twisted.Quotes From westside_indie at yahoo.com Sun Aug 21 23:50:26 2005 From: westside_indie at yahoo.com (John Walton) Date: Sun, 21 Aug 2005 20:50:26 -0700 (PDT) Subject: Network Programming Information Message-ID: <20050822035026.8228.qmail@web31009.mail.mud.yahoo.com> Hello. It's me again. Thanks for all the help with the Python Networking Resources, but does anyone know what I'll need to know to write a paper on Network Programming and Python. Like terminology and all that. Maybe I'll have a section on socketets, TCP, Clients (half of the stuff I don't even know what it means). So, does anyone know any good websites with Network Programming information. Thanks! John __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From http Sat Aug 27 00:05:00 2005 From: http (Paul Rubin) Date: 26 Aug 2005 21:05:00 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> Message-ID: <7xslww10ur.fsf@ruckus.brouhaha.com> Steve Holden writes: > Of course. But onc you (sensibly) decide to use an "if" then there > really isn't much difference between -1, None, () and sys.maxint as > a sentinel value, is there? Of course there is. -1 is (under Python's perverse semantics) a valid subscript. sys.maxint is an artifact of Python's fixed-size int datatype, which is fading away under int/long unification, so it's something that soon won't exist and shouldn't be used. None and () are invalid subscripts so would be reasonable return values, unlike -1 and sys.maxint. Of those, None is preferable to () because of its semantic connotations. From kimsj at mobile.snu.ac.kr Wed Aug 17 20:17:40 2005 From: kimsj at mobile.snu.ac.kr (James Sungjin Kim) Date: Thu, 18 Aug 2005 09:17:40 +0900 Subject: GUI tookit for science and education In-Reply-To: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> References: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> Message-ID: Michele Simionato wrote: > My vote is for ipython + matplotlib. Very easy and very powerful. Is it really easier than to use MATLAB(TM)? -James From ray_usenet at yahoo.com Fri Aug 12 10:41:51 2005 From: ray_usenet at yahoo.com (Ray) Date: 12 Aug 2005 07:41:51 -0700 Subject: How do these Java concepts translate to Python? In-Reply-To: References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: <1123857710.987790.285330@o13g2000cwo.googlegroups.com> Roy Smith wrote: > Quick answer; there are none, all attributes are public. > > Slightly longer answer; if you name an attribute with two leading > underscores (i.e. "__myPrivateData"), there is some name mangling that goes > on which effectively makes the attribute private. There are ways around > it, but you have to know what you're doing and deliberately be trying to > spoof the system (but, then again, exactly the same can be said for C++'s > private data). Well yeah... if you really want it, in Java you can do that too via reflection. Just that I'm not used to it yet so I feel a bit jittery with so much power on my hands! > Soapbox answer; private data is, in some ways, a useful tool, but it is not > part and parcel of object oriented programming. I've had people (mostly > C++/Java weenies) that Python is not an OOPL because it does not enforce > data hiding. "Feh", I say to them. Feh... those weenies don't know what they're talkin about. From rex.eastbourne at gmail.com Thu Aug 11 17:04:51 2005 From: rex.eastbourne at gmail.com (Rex Eastbourne) Date: 11 Aug 2005 14:04:51 -0700 Subject: Printing literal text of an argument Message-ID: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> Hi all, I've written the following simple macro called debug(aname, avalue) that prints out the name of an expression and its value: def debug(aname, avalue): print aname, 'is': pprint.pprint(avalue) An example call is: debug('compose(f1,f2)', compose(f1,f2)) Writing the exact same thing twice (one in quotes and the other not) sets off an alarm in my head. Is there a way to make this function take only one argument, and use both its value and its literal form? On a slightly different topic, is it also possible to make the macro print the line number where the function was first called? Thanks, Rex From johnnyandfiona at hotmail.com Tue Aug 23 04:07:18 2005 From: johnnyandfiona at hotmail.com (Johnny) Date: 23 Aug 2005 01:07:18 -0700 Subject: What's the difference between built-in func getattr() and normal call of a func of a class Message-ID: <1124784437.974574.12480@o13g2000cwo.googlegroups.com> Hi, I wonder what is the difference between the built-in function getattr() and the normal call of a function of a class. Here is the details: getattr( object, name[, default]) Return the value of the named attributed of object. name must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised. Is that to say the only difference between the two is that no matter the specific function exists or not the built-in func will always return a value, but "class.function" will not? From kay.schluehr at gmx.net Wed Aug 31 08:08:01 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 Aug 2005 05:08:01 -0700 Subject: Yielding a chain of values References: <4314bf65.177562962@news.oz.net> <3nk0e4F1snjcU2@individual.net> <4314e9fe.188467011@news.oz.net> <431553db.215568641@news.oz.net> <3nli8nF23ge4U1@individual.net> Message-ID: <1125490081.383463.322120@z14g2000cwz.googlegroups.com> Reinhold Birkenfeld wrote: > > x = [ yield r for r in iterable ] > > Which is quite different from > > x = (yield) in iterable > > which is currently (PEP 342) equivalent to > > _ = (yield) > x = _ in iterable > > So, no further tinkering with yield, I'm afraid. > > Reinhold Is the statement yield from iterable also in danger to be ambigous? The resolution of "(yield) from iterable" into _ = (yield) x = _ from iterable would not result in valid Python syntax. Kay From noreply at gcgroup.net Fri Aug 12 14:12:04 2005 From: noreply at gcgroup.net (William Gill) Date: Fri, 12 Aug 2005 18:12:04 GMT Subject: problem extending tkSimpleDialog.Dialog In-Reply-To: References: Message-ID: I'm still hammering away, and have found that when I change: class testWidget(Frame): def __init__(self, master): Frame.__init__(self) self.createWidgets() def createWidgets(self): Label(self,text="testWidget").grid() to: def __init__(self, master): Frame.__init__(self) self.x=master self.createWidgets() def createWidgets(self): Label(self.x,text="testWidget").grid() It seems to work correctly. However my actual widget, an extended Frame widget, still doesn't work correctly. This seems to confirm what I thought about addressing the correct parent, but I still haven't figured it out completely. Unless someone can give me a clue, I guess I can keep modifying testWidget(Frame) to add the components of my original until I can see where it breaks down. On the surface it looks like I'm not passing the correct master reference to my frame. Bill William Gill wrote: > I have created a widget that extends Frame() and contains labels, > checkboxes, and entrys. I am trying to use tkSimpleDialog.Dialog to > create a modal display of this widget, but am running into some > (addressing) problems. My widget displays in the parent widget, not the > tkSimpleDialog.Dialog? I hope this snippet is enough to help, as my > actual code is really too hard to follow. > > class showtestWidget(tkSimpleDialog.Dialog): > def body(self,master): > Label(master,text="showPhoneNums").grid() > testWidget(self).grid() > > class testWidget(Frame): > def __init__(self, master): > Frame.__init__(self) > self.createWidgets() > def createWidgets(self): > Label(self,text="testWidget").grid() > > When the parent script instantiates showtestWidget() it should create a > transient dialog containing a label with the text "showPhoneNums". It > does, but the label containing the text "testWidget" is being created in > the parent widget, not the dialog. > > It seems obvious to me that I'm addressing the wrong parent somehow, > since the label (probably the testWidget) is being created, but in the > wrong place. > > I tried changing testWidget(self).grid() to testWidget(master).grid(), > just to see if that helped, but it made no difference. > > Can someone show me where I went wrong? > > Bill > > From jeffrey.schwab at rcn.com Tue Aug 23 08:34:00 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Tue, 23 Aug 2005 08:34:00 -0400 Subject: Doubt C and Python In-Reply-To: References: Message-ID: praba kar wrote: > Dear All, > I want to know the link between c and python. > Some people with C background use Python instead > of programming in C.why? For me, the choice is typically among C++, Perl, Python, and Java. The arguments for Python relative to these languages are: 1. Python's standard library includes a lot of functionality not in the C++ standard library. 2. Python's syntax is the cleanest of these languages. 3. I don't have to compile Python, so I can test changes much more quickly that with C++ or Java. 4. System calls made from Python are more likely to be portable among the platforms I use most (WindowsXP, AIX, Linux, and MacOSX) than system calls from C++. 5. Scripting is easier in Python than in Java, particularly with regard to environment variables and process control. Of course, these are only my opinions. I am particularly not an expert on Python or Java. From wuwei23 at gmail.com Wed Aug 31 20:13:03 2005 From: wuwei23 at gmail.com (alex23) Date: 31 Aug 2005 17:13:03 -0700 Subject: change date format In-Reply-To: References: <1125483862.377521.107730@f14g2000cwb.googlegroups.com> <200508311236.49648.lars@gustaebel.de> Message-ID: <1125533583.606398.5770@g43g2000cwa.googlegroups.com> Fredrik Lundh wrote: > perhaps, but why is he posting apache questions to the python list? The real question is why is he asking for our help at all, given: Xah Lee wrote: > Fuck the Python programing morons. - alex23 From reinhold-birkenfeld-nospam at wolke7.net Sun Aug 21 05:43:07 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sun, 21 Aug 2005 11:43:07 +0200 Subject: while c = f.read(1) In-Reply-To: <430579A4.1060800@lexicon.net> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <430579A4.1060800@lexicon.net> Message-ID: <3mr0lbF1840unU1@individual.net> John Machin wrote: > ... AND it's about time that list is updated to include False explicitly > -- save nitpicking arguments about whether False is covered by > "numeric zero of all types" :-) Done. >> If I try: >> >> f = open("blah.txt", "r") >> while (c = f.read(1)) != '': >> # ... work on c >> >> I get a syntax error also. :( >> >> Is this related to Python's expression vs. statement syntactic >> separation? How can I be write this code more nicely? >> >> Thanks >> > > How about > for c in f.read(): > ? > Note that this reads the whole file into memory (changing \r\n to \n on > Windows) ... performance-wise for large files you've spent some memory > but clawed back the rather large CPU time spent doing f.read(1) once per > character. The "more nicely" factor improves outasight, IMHO. > > Mild curiosity: what are you doing processing one character at a time > that can't be done with a built-in function, a standard module, or a > 3rd-party module? Don't forget for line in f: for c in line: # do stuff Reinhold From noreply at gcgroup.net Wed Aug 31 11:40:52 2005 From: noreply at gcgroup.net (William Gill) Date: Wed, 31 Aug 2005 15:40:52 GMT Subject: graphical or flow charting design aid for python class development? Message-ID: <8ckRe.3276$v83.327@newssvr33.news.prodigy.com> Being somewhat new to Python, and having a tendency to over complicate things in my class design, I was wondering if anyone can suggest a simple graphical or flowcharting tool that they use to organize their class and program design? Because of a 55 mph head-on accident a few years back, I have short term memory problems, so flipping back and forth between pages of code is next to impossible for me to keep straight. A simple graphical model would allow me to 'see' everything in one view, and better organize my resulting code. I have had limited success using pydoc to view my classes, but it's not really much help in development, just review, and sometimes there is too much info. I have used editors for other languages that allow the view to expand and collapse functions/methods (like message threads here on the board), which help, but I haven't seen anything like this for python. Thanks for any suggestions. Bill From mwm at mired.org Mon Aug 1 23:49:05 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 01 Aug 2005 23:49:05 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <8664uqhkfj.fsf@bhuda.mired.org> Message-ID: <86hde9f172.fsf@bhuda.mired.org> Cliff Wells writes: > On Sun, 2005-07-31 at 14:58 -0400, Mike Meyer wrote: >> And what do I use to bundle my application for Unix? Most of the >> things I build get installed on Unix servers. > You install GUI apps on Unix *servers*? Yup. Thanks to the wonders of X, I can run GUI apps on servers and have them display on my desktop. Or my OS X laptop. I normally leave a gkrellm running on most of my servers. Of course, the problem under discussion isn't restricted to GUI apps. Anytime I use a third party library, I have to deal with how end users are going to get it. > Regardless, when you say "Unix", what do you mean? You may as well say > "OS" as this term has little meaning. Linux (which flavor)? BSD? SCO? > HPUX? OS/X? Minix? Whichever way, I suspect that a bit of distutils > hacking would solve your problem. I think the post I replied to covered the OS X case - there's an application bundler available for it already. I want distributions that will work on all three major BSD variants and most Linux distrubtions - in particular, anything that uses deb's, rpm's or emerge. If you want to choose one in particular, try ubuntu Linux. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From oren.tirosh at gmail.com Sat Aug 27 07:37:07 2005 From: oren.tirosh at gmail.com (Oren Tirosh) Date: 27 Aug 2005 04:37:07 -0700 Subject: Virtual Slicing References: Message-ID: <1125142627.041514.13520@o13g2000cwo.googlegroups.com> Bryan Olson wrote: > I recently wrote a module supporting value-shared slicing. I > don't know if this functionality already existed somewhere, In the Numarray module slices are a view into the underlying array rather than a copy. http://www.stsci.edu/resources/software_hardware/numarray From kimsj at mobile.snu.ac.kr Wed Aug 17 21:44:10 2005 From: kimsj at mobile.snu.ac.kr (James Sungjin Kim) Date: Thu, 18 Aug 2005 10:44:10 +0900 Subject: GUI tookit for science and education In-Reply-To: References: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> Message-ID: Robert Kern wrote: > ... Once you move outside of that box and start doing real > programming, Python (with Numeric, ipython, matplotlib, scipy, et al.) > beats MATLAB handily. As one who is really newbie on Python, In MATLAB we can represent the codes for the matrix manipulation as really like mathematical forms, e.g., MATLAB> H = U*D*V' It definitely makes the science programmer easier and faster to write their codes. Moreover, from some recent versions JIT has been included in MATLAB, which speeds up near to C/C++ programs. -James From michaels at rd.bbc.co.uk Wed Aug 3 11:57:34 2005 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Wed, 03 Aug 2005 16:57:34 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: I've reordered the q's slightly to avoid repetition... Also by answering this question first, it may put the rest of the answer into context better. phil hunt wrote: > At what stage of completion is it? This is something we deliberately try to reflect in the version number. Yes, you can build network servers and new protocols relatively simply at the moment. Yes, you can integrate with pygame in a limited useful fashion at present. Yes we have audio playback. However we don't have yet... (some examples) * Decent GUI integration yet. * /Full/ pygame integration. * Nice integration with pymedia * Direct support for Dirac. Which aside from other things means you can't build (say) a video & SMIL playback system trivially, yet. As a result that's why the version number is 0.2 - whilst you /can/ do a lot, there's a lot more to do. Clearly that also naturally implies that we don't expect any end user to be looking at the site. (The low version number will normally scare them away) >>The project aims to make it simple to build networked multimedia >>systems (eg audio, video, interactive systems), > > There's plenty of software that facilitates networking, for example > Python already has software for tcp and http clients/servers, and > for xmlrpc remote procedure calls. There is indeed. > So what does Kamaelia do that's extra? I imagine it's to to with > streaming large amounts of data. For example, a streaming video or > audio player. Or VoIP, perhaps. It's designed to make bolting things together to make these sorts of system simpler and easier. At the same time it's designed to encourage writing code in a way that makes it simpler. The natural side effect of this is the system might make it easier to take advantage of multiple CPU systems as they come online, since it makes a system naturally concurrent. As the original announcement said "Kamaelia is designed as a testbed". And by testbed I mean testbed as it testing out new ideas, see if they work and see if they pan out. (Not as in a testing suite) Probably the best way of describing the difference is this... After my talk about Kamaelia at Europython, I had an long chat with Tommi Virtinan about integration between Kamaelia and Twisted. I haven't had a chance to follow up with him yet regarding how this would work, though I have set a line in the sand aiming to have easy integration between Kamaelia and Twisted before Kamaelia hits version 1.0.0. The impression I got from Tommi was that he was most interested in the communications aspect - the fact we can bolt together systems in a manner directly akin to Unix pipelines, though I suspect he found the graphines aspect more interesting. Or as someone asking a similar question at Open Tech exclaimed after I finally managed to explain it better to them "Ooooh - you're trying to make concurrency EASY!". > OK, so what do the components in the pipelines do? What sort of data > do they hold? Unix pipelines act on ascii files; I assume you are > do this on audio and visual data. What langauage will the ele,ments > in thne pipelines be written it? I assume some will be in C/C++ for > speed. Components are object instances of python classes. The data passed between components are object instances. Clearly these python classes can be written in python, C, C++, pyrex etc. Currently all of Kamaelia's components are python based. Some existing components make calls into some related C libraries via python bindings.. An example of writing a component using Pyrex can be found here: * http://kamaelia.sourceforge.net/PyrexComponents.html >>It is designed as a practical toolkit, such that you can build systems >>such as: > When you say "you" who do you mean? Generally I expect the readership of c.l.p/python-list at python.org to be programmers. Python is generally easy to pick up and having asked someone who's not done much programming beforehand (beyond a small amount of VB and Access), and is pre-university to use the system to build a simple streaming system prototyping visualising PVR content on a mobile (and watching them succeed), they seem relatively reasonable examples. At some point, the ability to allow non-programmers to bolt together Kamaelia systems would be desirable, but a first step is making it simpler for programmers to bolt together systems. We currently have an interactive visualisation tool(*), and the logical extension of that is a tool that allows systems to be bolted together without knowing any code. (*) http://kamaelia.sourceforge.net/AxonVisualiser.html It'd be an interesting side project for someone to take forward, and might be low hanging fruit in terms of projects. (Especially if viewed initially as a tool for assisting development, rather than replacing development) > Is the audience programmers or > less technical people? A project that allows non-technical people > to build complex network applications is an ambitious one, but not > impossible (I'd find it very impressive and very exciting, > particularly if it runs on devices such as mobile phones). It's a little ambitious at this stage, yes. >> * Ogg Vorbis streaming server/client systems (via vorbissimple) >> * Simple network aware games (via pygame) >> * Quickly build TCP based network servers and clients > > What sort of servers and clients? Whatever you feel like. If you want a server to split and serve audio, you could do that. if you want a server to spit out fortune cookies, you can do that. (Useful only really as an alternative to a chargen test protocol IMO) >> * Quickly build Multicast based network servers and clients > Serving what? Could I use it, for example, to build an n-player > encrypted VoIP server to allow people to do conference calls over > the Internet? You could do that probably. (Though we don't have a component for audio capture (though a read file adaptor reading from /dev/audio might work depending on your platform I suppose) and audio encoding at the moment, so those would probably be the core components to integrate. If you want to use multicast over the wide area internet you'd also have to convince all the people using the system to use ISPs that support multicast......) > (I mean proper encryption here, the sort GCHQ or the NSA can't break) I'd be impressed if that could be written, using anything really. (Can't implies never) >>The basic underlying metaphor of a component us like an office worker >>with inboxes and outboxes, with deliveries occuring between desks, > That metaphor brings up an image (at least to me) that the sorts of > data that can be communicated are things like documents, > spreadsheets, business graphs, memos. They could indeed. The underlying framework doesn't differentiate between data nor have any realtime aspect embedded in the system at present. Just because we're focussing on systems that have a realtime element and are multimedia based, this does not mean the system is limited to that. > May I suggest a different metaphor? [hifi] I'll think about it. It's closer to the model that pysonic seems to take, and it implies a functional transform - ie /just/ dataflow - rather than connected processing units that /might/ take time to do processing. > OK, I get the straming part of it. But what asbout non-streaming > stuff? What other protocols are necessary? One example is peer to peer mesh setup. People normally think of P2P as a distribution mechanism. However, the underlying approach also very good at setting up communications meshes. This could be of use in many areas, such as GRID based systems for distributed rendering, application layer multicast, and network multicast island joining. Due to the illegal /uses/ of P2P, much work in this area is difficult to reuse due to defensive coding. Decoupling development of protocols from use of those protocols is generally a wide idea IMO. >>Is that clearer ? >> >>A short summary of all that could be: [ new descscription followed by useful comments, we'll take them on board, I think I've answered most points inline ] > "innovative". This actually has two meanings. One is "is new / > allows new things to be built". Bingo. It could be argued the other is misuse as buzzword. > That's certainly less lines of code than it would take in Tkinter. > And easier to follow. We're looking at tkinter as well. (Some tests at tkinter integration are in CVS) >>And you have a simple presentation tool ! > Now I'm confused. Is Kamaelia a GUI builder? Multimedia systems have many aspects. They include taking in audio/video and spitting out audio/video/pictures/text/... Take a look a SMIL if you're curious - it's a system that Kamaelia would be incomplete if it made decoding/display/interpretation of SMIL difficult. We also have to be able to demonstrate system to other people inside the BBC in a way non-technical people understand. That means showing structures in a friendly dynamic way, showing pictures, playing sounds (hence visualisation - looking inside running systems). That means we need ways of integrating with systems like pygame & other toolkits. If however I'm talking outside the BBC I'll try to give examples which people might find interesting - such as building a presentation tool. The blocks are very much like Lego & K'Nex and adding in a new block enables all sorts of new applications. For example, we could take the text ticker, combine that with a text feed and have a personal autocue/teleprompter. Alternatively someone could use it to have subtitles (say) at the opera displayed on a Nokia 770 (maemo) based device. > Ah, so now I'm guessing it allows me to write networked PyGame > applications, where with just a few lines of code I can have > networked streaming video on my pyGame screen... am I right? As yet, no. When we hit version 1.0, yes. Why? Because we haven't built components for video decode & display (and that's the only reason). That's why I don't mention video normally - I prefer to focus on where we are when announcing things, rather than where we're going (leaving that to more appropriate forums). >>Why wouldn't you use it? When Twisted is appropriate (Twisted is a >>more mature framework). > > The problem with Twisted, IME, is I don't understand the documentation. I can't help there, sorry. There *is* a twisted book coming out shortly, which might be worth looking into (or getting from a library), if you're interested... Finally, please note: Kamaelia is part of an R&D project - not all of the results will pan out. Some might, some might not. Unless you aim for the Stars though you won't get to Mars. Best Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk, http://kamaelia.sourceforge.net/ British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From sybrenUSE at YOURthirdtower.com.imagination Tue Aug 23 08:13:15 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Tue, 23 Aug 2005 14:13:15 +0200 Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon enlightened us with: > The problem with interpreting empty as false is that empty just > means no data now. But no data now can mean no data yet or it can > mean no more data. The problem is not so much as having empty > interpreted as false but that people don't seem to think about which > false value would be more appropiate in particular circumstances. By no means can you take all possible future alterations in account. You have to make assumptions somewhere. > IMO reading '' from network connection is the most natural result > when no data is ready and this should be treated differently from an > EOF which would indicate the connection was closed. > > But how can you do this when somewhere else '' is used as an > indication for an EOF. That's called "a protocol". If another protocol is used than the software is written for, it'll break. This has nothing to do with accepting something as False or True. > And it is IMO this kind of comments that lead to '' being used as an > EOF. And who cares if it is? In a blocking environment, it seems pretty okay to me. A read() call could block, waiting for more data to arrive. If there is none because the connection is down, for instance, it could return ''. Of course, raising an exception would be better in such a case, and it would also remove any ambiguity. > I have yet to see a mathematical work where 0, or any kind of empty > sequence is treated as false. In that case, properly define your variables to hold either booleans or numbers, and only test booleans in an "if var:" clause, and only test numbers in an "if var != 0:" clause. > a bytestring when data is available, > '' when no data is available > None when the connection was closed Seems pretty nice to me. In such a case, one could do: data = network.read() if data: handleData(data) if data is None: handleClosedConnection() I don't see a problem here. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From pythonmailing at web.de Mon Aug 1 08:12:19 2005 From: pythonmailing at web.de (Marek Kubica) Date: Mon, 1 Aug 2005 14:12:19 +0200 Subject: Dabo in 30 seconds? References: <200507311709.18243.jstroud@mbi.ucla.edu> Message-ID: <1g2nyhxkcx7e1.nbdusdzvfa7o.dlg@40tude.net> Hello! On Sun, 31 Jul 2005 17:38:44 -0700 James Stroud wrote: > On Sunday 31 July 2005 05:14 pm, Robert Kern wrote: >> You can't blame Dabo for this one. Your wxPython install is broken. > > Yes, but my Tkinter install works just fine. But you chose wx: dabo.ui.loadUI("wx") "Why can't I compile my linux kernel? I know, my gcc is broken, but my Python runs fine?" SCNR. greets, Marek From hancock at anansispaceworks.com Sat Aug 27 17:56:03 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sat, 27 Aug 2005 16:56:03 -0500 Subject: Newbie question: Sub-interpreters for CAD program In-Reply-To: References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: <200508271656.03258.hancock@anansispaceworks.com> On Saturday 27 August 2005 03:21 am, David MacQuigg wrote: > The discouraging thing about the EDA tools situation is that no matter > how loudly design engineers complain about the poor quality of the > proprietary tools they are using, there is very little interest in > participating in an open-source project. They just can't see how it > would ever do what their expensive tools do now. Yes. I think this is analogous to the problems with word processors and office workers. The concern is driven I think by a fear of incompatibility. It's certainly difficult to deal with the reality that many people in business insist on distributing information in whatever nasty variant of .doc format their word processor happens to spit out, and it's not easy to be sure you can read it. Similarly, if you can't read AutoCAD formatted CAD files in a mechanical design business, you're basically screwed. That's a strong motivation to keep using AutoCAD no matter how awful the program itself is. It will take a really big, long-term push by a fair number of interested people to give a free alternative a chance against such an entrenched existing proprietary application. In the long term, it would be worth it, but a lot of people have to back it for a long time, and that's hard to organize. > There is a similar lack of interest in the academic community. None > of this is likely to lead to publications in scholarly journals. I'm confused by what you meant by this. Are you saying that academics are afraid of using or creating open source CAD tools, or that they have a lack of interest in tools development, because it won't generate papers (directly anyway)? -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From richie at entrian.com Fri Aug 26 10:59:00 2005 From: richie at entrian.com (Richie Hindle) Date: Fri, 26 Aug 2005 15:59:00 +0100 Subject: Does any1 use pcapy module on win32 platforms? In-Reply-To: References: Message-ID: [billiejoex] > Hi. I'm trying to use pcapy module on Windows XP prof sp2 [...] > On Windows machines the findalldevs() function (an output on the bottom) > gives an unicode object that can't be processed by open_live function > that tipically accept strings. > > >>> pcapy.findalldevs() > [u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e\u6972\u4e63\u6964\u5773\u6e6 > [...] For what it's worth, I can run that on my XP Professional SP2 machine and it works perfectly: >>> pcapy.findalldevs() [u'\\Device\\NPF_{15310604-FCFC-4016-9D36-14DAA948A600}', u'\\Device\\NPF_{62280C1D-DC5C-42AF-BA0F-6BDB48418CA5}'] I'm using WinPcap 3.0. My packet.dll is stamped as version 3.0.0.18. Maybe you're running a different version? -- Richie Hindle richie at entrian.com From python at rcn.com Fri Aug 26 17:38:15 2005 From: python at rcn.com (Raymond Hettinger) Date: 26 Aug 2005 14:38:15 -0700 Subject: Why does min(A, B) not raise an error if A, B actually can't be compared? References: <3n95grFfp1fU2@individual.net> <1125084040.571865.154920@o13g2000cwo.googlegroups.com> <3n9bigFgm5aU1@individual.net> Message-ID: <1125092295.323783.6550@o13g2000cwo.googlegroups.com> [Claudio Grondi] > The still open question for me then is: > Why does min() not raise an error in case > there is no comparison function definition > for the feeded objects available? Actually, there is a comparison function for class instances. Unfortunately, the default method is not very useful in your case. It works a bit like this: def __cmp__(self, other): return cmp(id(self), id(other)) This is mildly useful as it allows distinct objects to have an ordering relation. Raymond From spam.csubich+block at block.subich.spam.com Sun Aug 7 03:58:13 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Sun, 07 Aug 2005 03:58:13 -0400 Subject: Proposed new collection methods In-Reply-To: References: <86d5oqvfqf.fsf@bhuda.mired.org> Message-ID: Jeff Schwab wrote: > Robert Kern wrote: >> Now, if I were to do >> >> item = g(self, test).next() >> >> the generator would execute the code until it reached the yield >> statement which happens when it finds the first item that passes the >> test. That item will get returned, and execution does not return to >> the generator again. [snip] > Wow, that's cool! Very reminiscent of C++ input iterators, but a lot > cleaner and shorter. Thanks. Read up on the __iter__ and __next__ methods that can be implemented by objects; Python objects have a very nice way of becoming (and returning) iterators. Generator functions and expressions are magic ways of doing some Really Common Things as iterators. From larry.bates at websafe.com Thu Aug 25 10:36:32 2005 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 25 Aug 2005 09:36:32 -0500 Subject: Fighting Spam with Python In-Reply-To: References: Message-ID: <430DD770.9020302@websafe.com> Before you do too much work you should probably check out: http://spambayes.sourceforge.net/ There has already been a lot of work done on this project. FYI, Larry David MacQuigg wrote: > Are you as mad about spam as I am? Are you frustrated with the > pessimism and lack of progress these last two years? Do you have > faith that an open-source project can do better than the big companies > competing for a lock-in solution? If so, you might be interested in > the Open-Mail project. > > I'm writing some scripts to check incoming mail against a registry of > reputable senders, using the new authentication methods. Python is > ideal for this because it will give mail-system admins the ability to > experiment with the different methods, and provide some real-world > feedback sorely needed by the advocates of each method. So far, we > have SPF and CSV. See http://purl.net/macquigg/email/python for the > latest project status. > > I welcome anyone who is interested in helping, expecially if you have > some experience with mail transfer programs, like Sendmail or Postfix, > or spam filtering programs, like SpamAssassin. My Python may not be > the best, so I welcome suggestions there also. We need to make these > scripts a model of clarity. > > -- > Dave > From johnny.karlsson at gmail.com Mon Aug 22 11:39:50 2005 From: johnny.karlsson at gmail.com (johnny.karlsson at gmail.com) Date: 22 Aug 2005 08:39:50 -0700 Subject: sending binary files to a 16 micro controller. In-Reply-To: References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <11gjn8k74pb6uc0@corp.supernews.com> Message-ID: <1124725190.368311.306720@z14g2000cwz.googlegroups.com> I'm going to try the timed wait alternative, if i get it the application to work properly i'll post the results in this group and the code if anyone want's it. It's such a contrast to code a tcp-server for the microcontroller (MC9S12NE64) in C and coding in python :-) I really hope embedded python takes of again! From tim.golden at viacom-outdoor.co.uk Thu Aug 11 10:46:36 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 11 Aug 2005 15:46:36 +0100 Subject: net view /domain Message-ID: <9A28C052FF32734DACB0A288A3533991044D21B0@vogbs009.gb.vo.local> [usenet at mail-2-me.com] | Hi! | | Is there a module I can use for "net view /domain" so list all | available domains and workgroups in a windows-network? I'm looking for | something like win32net.NetServerEnum, because I don't really want to | do this by "popen". I think this will do it. (The WinNT object hierarchy usually repays a look; I keep forgetting it's there). TJG import win32com.client network = win32com.client.GetObject ("WinNT:") for group in network: print group.name ________________________________________________________________________ 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 alan at alankemp.com Thu Aug 18 12:44:28 2005 From: alan at alankemp.com (Alan Kemp) Date: Thu, 18 Aug 2005 12:44:28 -0400 Subject: (OT) Is there something that people can use instead of full blown Python to run Python programs? In-Reply-To: <312cfe2b05081809382d3a87b7@mail.gmail.com> References: <312cfe2b05081809382d3a87b7@mail.gmail.com> Message-ID: On Thu, 18 Aug 2005 12:38:30 -0400, Gregory Pi?ero wrote: > I'm no expert, but I'm guessing you could compile a python with less > libraries. I bet that would slim it down a lot. > > -Greg > > > On 8/18/05, Nathan Pinno wrote: >> >> Hi all, >> Is there something besides the full blown version of Python that people >> can use to run Python programs, or do they have to use the full blown >> version of it? >> Thanks, >> Nathan Alternativly, use something like http://starship.python.net/crew/theller/py2exe/ to convert into a native executable. Of course this depends on whether your question was intended as "how can people run some python script", or "how can people run my python script". Alan From a-steinhoff at web.de Wed Aug 24 10:08:34 2005 From: a-steinhoff at web.de (Armin Steinhoff) Date: Wed, 24 Aug 2005 16:08:34 +0200 Subject: Should I move to Amsterdam? In-Reply-To: References: Message-ID: Adriaan Renting wrote: > Well, I'm not sure if Amsterdam is nice, but the Netherlands is o.k., except for the weather. > I'd like to descripbe it as 49 weeks of autumn, 1 week of spring, 1 week of summer, 1 week of winter. > Currently my employer only has an opening for a Microwave Antenna designer though, sorry no Python coders. > http://www.astron.nl/astron/jobs/index.htm > > Seems like a nice column, I'll read it completely some other time. > > >>>>"Wade" 08/24/05 2:31 pm >>> > > http://www.slate.com/id/2124561/entry/2124562/ > > Nice little series by Seth Stevenson for Americans daydreaming about > emigration. Somewhere, anywhere ... maybe Amsterdam? > > I've never been to the Netherlands myself, but it >sounds very civilized. What a joke ... Amsterdam is 'civilized' since several hundreds of years :) --Armin > > Extra Python connection, besides the obvious one: Is "gezellig" related > to the Zen of Python? ( > http://wordcraft.infopop.cc/eve/ubb.x/a/tpc/f/6351024471/m/2041067571/r/3901049571 > ) > > -- Wade Leftwich > Ithaca, NY > From deets at nospam.web.de Sat Aug 27 14:08:40 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 27 Aug 2005 20:08:40 +0200 Subject: Modify a C++ instance from the embed python interpreter In-Reply-To: <1h1yl9h.1x14zs71pjw5fyN%wezzy@despammed.com> References: <1h1yl9h.1x14zs71pjw5fyN%wezzy@despammed.com> Message-ID: <3nboh6Fq4aqU1@uni-berlin.de> Wezzy wrote: > Hi, is there a tool that automatically expose an object to python? i > have an instance of a C++ (or ObjC) object and i want to pass it to the > embed interpreter that runs inside my program. > Python code have to call c++ method and register some callback. > > I know that swig helps when python creates c++ instance but i've the > instance and i want to use it with python. That is the same case, wrt SWIG - the objects methods get accessed by functions like int Object_foo(Object *s) { return s->foo(); } So passing a exiting object reference to such a function will work. You might also consider using SIP, it appears to me to be much more OO. Diez From amk at amk.ca Wed Aug 31 12:32:42 2005 From: amk at amk.ca (A.M. Kuchling) Date: Wed, 31 Aug 2005 11:32:42 -0500 Subject: OpenSource documentation problems References: Message-ID: On Wed, 31 Aug 2005 12:14:35 GMT, > I use dir() all the time; help() not so much. Typing help(help) > shows: > > Help on _Helper in module site: > > Type help() for interactive help, or help(object) for help > about object. > > That strikes me as not-particularly-helpful. Surely it should at > least direct the user to 'pydoc.help'. help *is* pydoc.help, or at least a trivial wrapper around it, so I don't see the purpose of mentioning that. The purpose of the wrapper is so naive user can just type 'help' at an interpreter prompt: >>> help Type help() for interactive help, or help(object) for help about object. >>> What additions to that string would you suggest? > Three weeks ago, in trying to explain a point about Python's > zlib module, I discovered that the doc was wrong. > http://groups.google.com/group/comp.lang.python/msg/20609fff71a2ed02 I don't think I'd change the Python docs to try to explain this, because I have no confidence that we can get the details correct. BerkeleyDB, curses, and the 'os' module pose similar problems. For example, people sometimes ask for more detail about POSIX functions, but no one wants to write a Python-specific version of "Advanced Programming in the Unix Environment". --amk From no at spam Sat Aug 6 15:01:36 2005 From: no at spam (D H) Date: Sat, 06 Aug 2005 14:01:36 -0500 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: <1123302161.191230.209140@g43g2000cwa.googlegroups.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <1123302161.191230.209140@g43g2000cwa.googlegroups.com> Message-ID: seberino at spawar.navy.mil wrote: > I'm not saying 'modulescope' and 'module' are the only alternatives or > even > the best anyone can come up with. > > 'global' has the connotation of being visible *EVERYWHERE* > where in Python it is just visible in one module's space. > > Can you think of a better alternative or do you believe > 'global' is the best possible? > When designing a language meant to be easy to use as well as powerful feature-wise, you have to weighh between things like technical accuracy of a term (which you are focusing on), how much typing it takes, how easy it is to remember and spell correctly, and how the term is commonly understood and used. Sometimes python takes one of those considerations to the extreme (like "def") or has a uncommon view of "common understanding" (like "lambda"). But global is the best term I can think of for the way it is used, and it is by far the most common term used for these kind of variables in numerous other languages including vb, php, ruby, etc. From renting at astron.nl Wed Aug 17 10:48:03 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 17 Aug 2005 16:48:03 +0200 Subject: Read from stdouton Popen on WinXP? Message-ID: As far as I understand it, the buffering is indeed happening in the .exe, depending on what it "thinks" it's stout is connected to. There's nothing the operating system, or Python can do about it, if the .exe was created using #include . This might help: http://www.cplusplus.com/ref/cstdio/ http://htmlhelp.sunsite.dk/page.php/9/ch13s20.html http://pexpect.sourceforge.net/ Especially read the FAQ of Pexpect, it's quite clear. It took me some time to figure it out too, and I'm not realy happy about it, but I suppose that the advantage is, that it's all K&R compatible in this way. I find that as long as one of the stdin/out/err are connected to a terminal, stdio will use them as character devices. This is why .exe | more works I think: more's stdout$err are a terminal, therefore it's std is a character device, and then the pipe is a character device, and then the .exe will have stdout as a character device. I do not know al the intricate details, but for me Pexpect works, and it's FAQ is quite clear, but AFAIK there are no pseudo-terminals on Windows, so you'll need to find a different trick. Adriaan. >>>Matthew Henry 08/17/05 3:42 pm >>> On 8/17/05, Adriaan Renting wrote: that only works on Unix. The problem is the way stdout in C works: >- If connected to a character device, it will flush after each line. >- If connected to a block device it will flush only after it's buffer is full. Any kind of pipe or file is a block device. > >As this is how stdout works even your OS can't help, because as long as the application doesn't flush, the output doesn't even arrive at the pipe or file. Thanks for the info. I am a longtime C++ programmer, but all GUI stuff so I'm afraid I don't really understand how the stdio stuff works. >From the cmd prompt, I can pipe the output of the .exe to "more" and see it work in realtime. Thus I presume the buffering is happening on the Python end (or the stdio library that Python is using). Not in the .exe. So, assuming that's true, why would it help to have the created process flush its buffer? Does that put some kind of special character in the buffer that tells Python's stdio library to clear out its buffer? Or is my assumption incorrect, and the buffering is happening in the .exe and the cmd shell is working some magic to get at the output? Know of a good (online) reference that explains how stdin, stdout, stderr really works under the covers? Especially under Windows? From alessandro.bottoni at infinito.it Wed Aug 17 03:48:55 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Wed, 17 Aug 2005 07:48:55 GMT Subject: Creating a graphical interface on top of SSH. How? References: <1124201425.891035.281220@g44g2000cwa.googlegroups.com> Message-ID: John F. wrote: > I want to write a client app in Python using wxWindows that connects to > my FreeBSD server via SSH (using my machine account credentials) and > runs a python or shell script when requested (by clicking a button for > instance). > > Can someone give me some advice on how to create a "graphical shell" > per se? Well, a "graphical shell" is just a wxWidgets application that exposes a few widgets (buttons, list, whatever). Each widget has a "event" associated to it and this event can trigger whatever command, even a remote command on your FreeBSD server (via ssh). As a consequence: - create your user interface (I suggest you to use wxPython and wxGlade for this) - associate to each and every widget a "event handler" - make your event handlers call your scripts on your FreeBSD machine via SSH (use PySSH or Conch for this) Python has a couple of good implementation of SSH: http://pyssh.sourceforge.net/ http://twistedmatrix.com/projects/conch/ Both of them are well documented. You can find a small example here: http://www.palovick.com/code/python/python-ssh-client.php Do not use wxWidgets directly. You would have to re-create a lot of Python-wxWidgets integration that already exists. Use wxPython instead (www.wxpython.org). There is a quite good GUI builder for wxPython that is called wxGlade. It can generate XML files that are easier to maintain than C o Python code. CU ----------------------------------- Alessandro Bottoni From ptmcg at austin.rr.com Fri Aug 12 11:02:01 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 12 Aug 2005 08:02:01 -0700 Subject: simpli int/str problem References: Message-ID: <1123858921.857374.51780@g43g2000cwa.googlegroups.com> I just did this sort of thing the other day! Your database only accepts ints for BH, but remember, you are building an SQL *string* to be executed. To show SQL that your BH value is an int, not a string, do not enclose it in quotes. (Another style hint: don't name dict's "dict", as this will mask the actual type name. Let's try "vDict" for now, meaning "value dict".) SQL = "INSERT INTO XYZ('AH', 'BH' ) VALUES ('" + vDict['str_name'] + \ "', " + str(vDict['int_name']) + ")" In my program, I found it a bit easier to follow if I used string interpolation (the string % operation), and named format fields. Try this: SQL = "INSERT INTO XYZ('AH', 'BH' ) VALUES ('%(str_name)s', %(int_name)d)" % vDict Again, note that the string value is surrounded by quotes, but the integer value is not. Also, you will need to replace XYZ with the actual table name. :) -- Paul From rich.teer at rite-group.com Fri Aug 26 10:36:29 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Fri, 26 Aug 2005 14:36:29 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> Message-ID: On Fri, 26 Aug 2005, John Bokma wrote: > people from www to Usenet or vice versa is beyond me. If 80% of the current > Usenet users stop posting, Usenet is not going to die :-D Heh. Quite the opposite, I reckon: it would get much better (higher SNR)! :-) -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From kjmacken at gmail.com Tue Aug 30 16:17:48 2005 From: kjmacken at gmail.com (kjm) Date: 30 Aug 2005 13:17:48 -0700 Subject: pyGame - Logitech rumble pad input OS X (10.3.9) Message-ID: <1125433068.933904.63570@g49g2000cwa.googlegroups.com> Hi everyone, I have recently acquired a Logitech Rumble pad to use as an input device. I have been having trouble getting the event que to respond that a button or hat arrow has been pressed. This is on a system running OS 10.3.9. I have modified/written a small piece of code that initializes the joystick, and pygame does recognize it. I was wondering if someone has a small snippet of code to get me going? I have posted the code I'm using to initialize the joystick, plus it's output below. Versions are: Version checklist: Python version 2.3 (OK) extra Python info: (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] Numeric version 24.0b1 (OK) PyOpenGL (package "OpenGL") version 2.0.2.01 (OK) pygame version 1.7.0 (OK) Python Imaging Library (package "Image") version 1.1.5 (OK) any help is appreciated. Cheers, kjm [begin code] ------------------------------------------------- import pygame import pygame.display import pygame.joystick from pygame.locals import * pygame.display.init() pygame.joystick.init() #initialize joystick module pygame.joystick.get_init() #verify initialization (boolean) joystick_count = pygame.joystick.get_count()#get number of joysticks print('%d joystick(s) connected' %joystick_count)#print number joystick_object = pygame.joystick.Joystick(0) #create an instance of a joystick #first joystick is [0] in the list #haven't had much luck with multiple joysticks joystick_object.get_name() print joystick_object.get_name() #grab joystick name - flightstick, gravis... #can (and is in this case) be done before initialization joystick_object.init() joystick_object.get_init() #verify initialization (maybe cool to do some #error trapping with this so game doesn't crash num_axes = joystick_object.get_numaxes() num_buttons = joystick_object.get_numbuttons() print 'Joystick has %d axes and %d buttons' %(num_axes,num_buttons) pygame.event.pump() #necessary for os to pass joystick events xaxis = joystick_object.get_axis(0) yaxis = joystick_object.get_axis(1) wheel = joystick_object.get_axis(2) trigger = joystick_object.get_button(0) top = joystick_object.get_button(1) #from above, you have number of axes and buttons #could assign more if your joystick has more print '%f %f %f %d %d' %(xaxis, yaxis, wheel, trigger, top) #print values to console for debugging #analog channels (axes) range -1 to 1 #digital channels (buttons) are 1 or 0 joystick_object.quit() #destroy objects and clean up pygame.joystick.quit() [/code] ------------------------------------------------------------------ [begin output] [XXXXXXX at viridian 16:10:26]$ python testjoy.py 1 joystick(s) connected Logitech Cordless RumblePad 2 Joystick has 4 axes and 12 buttons -1.000000 -1.000000 -1.000000 0 0 [XXXXX at viridian 16:10:32]$ [/output] From varunhiremath at iitm.ac.in Fri Aug 26 11:21:15 2005 From: varunhiremath at iitm.ac.in (Varun Hiremath) Date: Fri, 26 Aug 2005 20:51:15 +0530 Subject: Problem with Pythoncard Message-ID: <20050826152115.GA6945@god.godsdomain> Hello everybody, I was trying to install pythoncard on my system and I got this error. I am using an unstable version of Debian. Can someone tell me what the error could be. Is it because I am usingUnstable version of Debian I am getting this error or is it because of some other reason. I hope I am mailing this error to the right mailing list if not pls let me know. ********************************** apt-get install pythoncard Reading Package Lists... Done Building Dependency Tree... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. Since you only requested a single operation it is extremely likely that the package is simply not installable and a bug report against that package should be filed. The following information may help to resolve the situation: The following packages have unmet dependencies: pythoncard: Depends: python-pythoncard (= 0.8.1-2) but it is not going to be installed Depends: pythoncard-tools (= 0.8.1-2) but it isnot going to be installed E: Broken packages ********************************* -- ----------------------------------------------- Varun Hiremath 461, Jamuna Hostel IIT Madras, Chennai - 600 036 mob : +919840299732 ----------------------------------------------- My Webpage : http://www.ae.iitm.ac.in/~ae03b032 ----------------------------------------------- From lycka at carmen.se Tue Aug 23 06:15:36 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 23 Aug 2005 12:15:36 +0200 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon wrote: > Following a well defined specification is not contradictory > to guessing. It may just mean that the guess was formalized > into the specification. If you want the behaviour of Python to change, you should write a PEP. It always felt natural to me to interpret empty as false, but I could be wrong. It's strange that this flaw managed to go unnoticed for so long though... If Python is too "wild" for your taste, you might like OCaml. > Well then I must say people here give beauty too high a priority. > Because there seems a tendency to beautify others code when > snippets are posted here. Often enough such snippets > don't give enough inoformation to know whether "if var is True:" > can be replaced by "if var:" or whether other beautifications are > appropiate. You might be right about that. I didn't really notice. I think the typical comment is to replace "if s != '':" with "if s:" in contexts where s is always a string, or to replace "if expr != False:" with "if expr": in cases where "expr" is an expression that returns True or False etc. In some cases, obvious bugs, such as "if (a and b) == True:" where the programmer should have written "if (a and b):" are pointed out. Many of us have a solid mathematical education, and in that world it's considered good behaviour to simplify expressions and remove redundancy. If we see things such as redundant pieces in logic expressions, functions ending in "return None", returns directly after a raise, or other meaningless constructs, it suggests that someone might be doing something they don't understand, and then it's helpful to try to point that out. It's really important to understand what we do when we're programming, not just repeat mantras or wave dead chickens. If people mechanically learn "I shouldn't use '!= False' in if-statements in Python", we've failed in trying to help them. If people learn what Python considers true and false, what the boolean operators return, and understands how to use these things in an effective way, we've succeeded. Another aspect of this particular idiom is that it's often better to use the exception system in Python for exceptional situations, than to use one variable to carry several different kinds of information. Concerning interfaces between different pieces of code, it's a good approach to assume as little as possible, but to be clear about what we assume. From nephish at xit.net Thu Aug 18 05:18:28 2005 From: nephish at xit.net (nephish at xit.net) Date: 18 Aug 2005 02:18:28 -0700 Subject: question about binary and serial info In-Reply-To: <1124354848.599569.78070@z14g2000cwz.googlegroups.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <1124337614.259032.4970@g14g2000cwa.googlegroups.com> <1124339226.523475.257400@z14g2000cwz.googlegroups.com> <1124344877.985737.40510@g44g2000cwa.googlegroups.com> <1124354848.599569.78070@z14g2000cwz.googlegroups.com> Message-ID: <1124356708.653116.80150@g49g2000cwa.googlegroups.com> oh wait, i found it. i found how to do the conversions and thanks to you the operators. appreciate everything, shawn From jstroud at mbi.ucla.edu Fri Aug 12 00:55:11 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 11 Aug 2005 21:55:11 -0700 Subject: Jargons of Info Tech industry In-Reply-To: <8j4of1t3h7cvuc6s0svvreu971peeh9qc7@4ax.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <8j4of1t3h7cvuc6s0svvreu971peeh9qc7@4ax.com> Message-ID: <200508112155.11702.jstroud@mbi.ucla.edu> Xah Lee is a known troll. You are retarded to reply to his drivel. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From fumanchu at amor.org Sun Aug 7 20:19:25 2005 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 7 Aug 2005 17:19:25 -0700 Subject: WSGI-server in the standard distro? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3772715@exchange.hqamor.amorhq.net> > Having a HTTP 1.0/1.1-compliant production-grade > WSGI-only server in the distro would be sweet :-) > > I might be demanding a bit much here, but still ... To "demand" it might be a bit much, but to "expect" it...? ;) I don't think anyone's going to drop what they're doing and go code such a server because it's been demanded; even if they did, it would need a long-ish period of time in which it was tested by the community in production scenarios. However, since our hypothetical server is not yet in the standard library, who would use it in production? Catch-22. An alternative would be to allow one or more of the servers which have been written for CherryPy or Django to see some use "in the wild", and have each go through its own series of bugfixes and performance improvements, driven by direct need. When they have done so, we can compare them and drop one into the standard library with far fewer unknowns. I'm obviously biased (being on the CherryPy team), but I think the "winner" will be Peter Hunt's WSGI server for CherryPy. It was designed from the beginning to be framework-agnostic; that is, there's nothing CherryPy-specific in the module. Peter has said multiple times that he'd like it to become the standard WSGI server, and that his desire is for other frameworks to adopt it wholesale. Django should certainly grab it right away; performance-wise, it beats the pants off the reference server that comes with wsgiref (which is what they based their WSGI server on). If there are any licensing or other issues keeping django from using the CherryPy WSGI server, swing by irc://irc.oftc.net/cherrypy and we'll get them worked out in a hurry. Robert Brewer System Architect Amor Ministries fumanchu at amor.org From paul at boddie.org.uk Wed Aug 31 18:33:39 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 31 Aug 2005 15:33:39 -0700 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. References: <1125502430.504110.134500@f14g2000cwb.googlegroups.com> Message-ID: <1125527619.029487.207160@g47g2000cwa.googlegroups.com> Alan Kennedy wrote: > I personally put great store in the fact that PCW awarded the Editors > Choice award to SpamBayes, because it's based on actually *using* the > software, rather than doing a simple feature comparison. We can be thankful for that, at least. And you're right about SpamBayes being a great opportunity for Python developers and the community. > I didn't notice any complaints when PCW ran a story this time last year > about Michael Sparks, python and python's use in the BBC's future > distribution plans for digital TV. Well, I didn't even notice the story! ;-) But then, my exposure to such newsstand magazines has diminished substantially over the past ten years. Paul From aspk88 at gmail.com Wed Aug 10 23:09:40 2005 From: aspk88 at gmail.com (He, Aspk) Date: Thu, 11 Aug 2005 11:09:40 +0800 Subject: what's the exactly newsgroup url of python-list? Message-ID: <42FAC174.5030506@gmail.com> My thunderbir cant connect to comp.lang.python as the python.org page saying. From could.net at gmail.com Thu Aug 4 05:50:12 2005 From: could.net at gmail.com (could ildg) Date: Thu, 4 Aug 2005 17:50:12 +0800 Subject: Does pyparsing support UNICODE strings? In-Reply-To: <20050804173916.A769.SADDLE@gmail.com> References: <20050804172923.A763.SADDLE@gmail.com> <311b5ce10508040233b76e550@mail.gmail.com> <20050804173916.A769.SADDLE@gmail.com> Message-ID: <311b5ce10508040250140d8732@mail.gmail.com> I tested his code in a file test2.py: # -*- coding: UTF-8 -*- from pyparsing import Word text = "????????, ?????!".decode('utf-8') alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce)) greet = Word(alphas) + u',' + Word(alphas) + u'!' greeting = greet.parseString(text) print greeting After run this, I got the following result: [u'\u039a\u03b1\u03bb\u03b7\u03bc\u03ad\u03c1\u03b1', u',', u'\u03ba\u03cc\u03c3\u03bc\u03b5', u'!'] I use windows xp sp2 simple Chinese, python 2.41,my code is as below: # -*- coding: UTF-8 -*- from pyparsing import CharsNotIn text = u"??????, ??????!" greet = CharsNotIn(u',!') + u',' + CharsNotIn(u',!') + u'!' greeting = greet.parseString(text) for x in greeting: print x.encode("cp936") #or x.encode("gbk") And the result is as below: ?????? , ?????? ! Everything works just correctly. On 8/4/05, saddle wrote: > the code what posted by Rober Kern > > from pyparsing import Word > text = "????????, ?????!".decode('utf-8') > alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce)) > greet = Word(alphas) + u',' + Word(alphas) + u'!' > greeting = greet.parseString(text) > print greeting > > > my system default is cp936, Simp Chinese. > > On Thu, 4 Aug 2005 17:33:16 +0800 > could ildg ????: > > could.net> So what's you code? > could.net> and what's you system default encoding? > could.net> > could.net> On 8/4/05, saddle wrote: > could.net> > hello, but i can't run the script. could u told me what's the trick pls? > could.net> > here is the error output. > could.net> > > could.net> > D:\python\test>pyp > could.net> > sys:1: DeprecationWarning: Non-ASCII character '\xce' in file D:\python\test\py > could.net> > .py on line 3, but no encoding declared; see http://www.python.org/peps/pep-026 > could.net> > .html for details > could.net> > Traceback (most recent call last): > could.net> > File "D:\python\test\pyp.py", line 9, in ? > could.net> > greeting = greet.parseString(text) > could.net> > File "C:\Python24\Lib\site-packages\pyparsing.py", line 616, in parseString > could.net> > loc, tokens = self.parse( instring.expandtabs(), 0 ) > could.net> > File "C:\Python24\Lib\site-packages\pyparsing.py", line 558, in parse > could.net> > loc,tokens = self.parseImpl( instring, loc, doActions ) > could.net> > File "C:\Python24\Lib\site-packages\pyparsing.py", line 1387, in parseImpl > could.net> > loc, exprtokens = e.parse( instring, loc, doActions ) > could.net> > File "C:\Python24\Lib\site-packages\pyparsing.py", line 562, in parse > could.net> > loc,tokens = self.parseImpl( instring, loc, doActions ) > could.net> > File "C:\Python24\Lib\site-packages\pyparsing.py", line 873, in parseImpl > could.net> > raise exc > could.net> > pyparsing.ParseException: Expected "," (at char 5), (line:1, col:6) > could.net> > On Thu, 4 Aug 2005 17:24:23 +0800 > could.net> > could ildg ????: > could.net> > > could.net> > could.net> OK, I make it. > could.net> > could.net> It's right, it can work fine with unicode. > could.net> > could.net> pyparsing is great. > could.net> > could.net> Thanks. > could.net> > could.net> > could.net> > could.net> On 8/4/05, could ildg wrote: > could.net> > could.net> > I want to parse some Chinese words. > could.net> > could.net> > It seems that pyparsing doesn't work for me. > could.net> > could.net> > Thank you. > could.net> > could.net> > I have to use re directly, although it's harder, but it'll always work. > could.net> > could.net> > > could.net> > could.net> > On 8/4/05, Robert Kern wrote: > could.net> > could.net> > > could ildg wrote: > could.net> > could.net> > > > pyparsing is very convenient to use. But I want to find some a py tool > could.net> > could.net> > > > to parse non-English strings. Does pyparsing support UNICODE strings? > could.net> > could.net> > > > If not, can someone tell me what py tool can do it? Thanks in advance. > could.net> > could.net> > > > could.net> > could.net> > > Try it! > could.net> > could.net> > > > could.net> > could.net> > > # vim:fileencoding=utf-8 > could.net> > could.net> > > > could.net> > could.net> > > from pyparsing import Word > could.net> > could.net> > > > could.net> > could.net> > > text = "????????, ?????!".decode('utf-8') > could.net> > could.net> > > alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce)) > could.net> > could.net> > > > could.net> > could.net> > > greet = Word(alphas) + u',' + Word(alphas) + u'!' > could.net> > could.net> > > greeting = greet.parseString(text) > could.net> > could.net> > > print greeting > could.net> > could.net> > > > could.net> > could.net> > > -- > could.net> > could.net> > > Robert Kern > could.net> > could.net> > > rkern at ucsd.edu > could.net> > could.net> > > > could.net> > could.net> > > "In the fields of hell where the grass grows high > could.net> > could.net> > > Are the graves of dreams allowed to die." > could.net> > could.net> > > -- Richard Harter > could.net> > could.net> > > > could.net> > could.net> > > -- > could.net> > could.net> > > http://mail.python.org/mailman/listinfo/python-list > could.net> > could.net> > > could.net> > could.net> -- > could.net> > could.net> http://mail.python.org/mailman/listinfo/python-list > could.net> > > could.net> > > could.net> > > could.net> -- > could.net> http://mail.python.org/mailman/listinfo/python-list > > > From tjreedy at udel.edu Wed Aug 10 18:53:34 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Aug 2005 18:53:34 -0400 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com><1123609818.770605.267740@g14g2000cwa.googlegroups.com> Message-ID: "Aahz" wrote in message news:ddd6q9$h9c$1 at panix1.panix.com... > In article , > Terry Reedy wrote: >>For what it is worth, the Python developers are discussing moving the >>Python codebase to subversion, though other options were discussed. The >>result so far is PE 347 Migrating the Python CVS to Subversion. > > While you're technically correct, at this point it's closer to "planning > the move to Subversion". No, I was exactly correct as to what I stated. The difference between 'discussing' and 'planning' is pretty small and the fact that some might be 'planning' does not negate 'discussing'. In fact, alternatives were still being discussed as of earlier today, with Guido sharing his experience with Perforce. Terry J. Reedy From H.Duerer at gmx.net Wed Aug 17 12:02:33 2005 From: H.Duerer at gmx.net (Holger Duerer) Date: Wed, 17 Aug 2005 17:02:33 +0100 Subject: SOAP and XMLRPC References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Message-ID: <87slx8o8km.fsf@ronaldann.demon.co.uk> >>>>> "Daniel" == dcrespo writes: Daniel> Someone knows if is there possible to have a Python SOAP Daniel> or XMLRPC server that works with VB? Sure, why not? What have you tried that didn't work? Getting SOAP libraries to interoperate is often a pain but usually possible unless you want to be able to have more than one type of library for clients. Daniel> My examples are: [...] Good. So you seem to have the Python side going. Are you asking in the Python group for help with VB? Or do you have a VB solution/attempt that you can't get your Python server to work with? In the former case I suggest you contact a VB group in the latter that you post infos on what you have tried already so we don't have to guess. As an additional pointer, I can tell you that I have had success with getting a PocketSOAP client to talk to a SoapPy server. You may want to give that a try. Holger From http Mon Aug 29 04:32:05 2005 From: http (Paul Rubin) Date: 29 Aug 2005 01:32:05 -0700 Subject: OpenSource documentation problems References: Message-ID: <7xhdd9ta7u.fsf@ruckus.brouhaha.com> "Adriaan Renting" writes: > He seems to think the GNU man pages are nice, but I find them very > awkward as they have no hierarchical organization, and most miss examples. The GNU man pages are an afterthought to meet expectations of Un*x users who were used to man pages and the man command. The good GNU docs are in texinfo format, not man pages. They have lots of examples and they hierarchical structure and were designed to be navigated with a pre-www hypertext browser or alternatively generate printed manuals. These days there are also programs to render them as html so you can navigate them with web browses. > I do agree that a lot of OSS projects seem to lack somewhat in the > documentation department, compared to a lot of commercial > software. I would give the man page of gcc as an example, it's just > one 6600 line blurb. The other part where a lot of OSS seems to be > lacking is user interface design. The man page only exists for the sake of users who insisted on having a doc in that inferior format. The "official" gcc doc is at: http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/ > The big question is: how to attract more doc writers to the OSS movement? It's traditionally been a problem. The FSF has hired a number of tech writers over the years, and paid them to write docs. That's one way. From rkern at ucsd.edu Sun Aug 7 05:05:59 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 02:05:59 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <7xmznuxh61.fsf@ruckus.brouhaha.com> References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Robert Kern writes: > >>No it's not wrong to want these things. The problem is that we're not >>lacking in people posting this *same exact complaint* every month or >>so. We *are* lacking in people implementing these things. > > Eh? Nah, we keep getting lame excuses on why those things aren't > needed and users should just supply tenacity and expect to suffer and > they should stop being wimps, and having to locate, download, and > figure out how to use a dozen packages from all over the internet > really isn't more hassle than a one-click install with unified > documentation for everything. *I'm* not giving those excuses. I'm doing the work to assist in my area of interest. http://download.enthought.com/MacEnthon/ReadMe.html >>If you want to see these nice accoutrements, *stop posting here and >>get to work*! > > Eh again--says who? You? Yes, me. I've been doing the legwork. > Most of those functions for Python are > already floating around the net. It's simply a matter in many cases > of deciding to include them in the distro. The problem is an attitude > that making things too easy for users is un-Pythonic. If you think > it's just a matter of writing code, you're not on the side you think > you're on. I said nothing about writing code except as part of a list of several things that this thread won't accomplish. I certainly don't think that it *just* involves writing code. -- 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 jan.danielsson at gmail.com Mon Aug 29 10:11:14 2005 From: jan.danielsson at gmail.com (Jan Danielsson) Date: Mon, 29 Aug 2005 16:11:14 +0200 Subject: What are new-style classes? In-Reply-To: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> Message-ID: <4313176a$1@griseus.its.uu.se> Vaibhav wrote: > I recently heard about 'new-style classes'. I am very sorry if this > sounds like a newbie question, but what are they? I checked the Python > Manual but did not find anything conclusive. Could someone please > enlighten me? Thanks! In short: They have inherited "object" from somewhere. (This is probably technically inaccurate, but it's the only thing I have seen which defines a 'new-style class'). What it means *practically*, is that you can use properties. For a long while I didn't really understand the point or properties, until I needed them. I have written a flowcharting application in Python. All objects on the flowchat are derived from a base object which has the attribute "text" (all objects have some form of, sometimes internal only, title). Problem is that when some objects change text, I want to perform some recalculations. So I wrote a "text" property, which - in its settext-method - does all the calculations if required. That way, the application can till use: obj.text = 'Blah' ..and still have the chance to act on the text change. I could have simply written a setText() method, but imho properties are neater - but that's just a matter of opinion. -- Kind Regards, Jan Danielsson Te audire no possum. Musa sapientum fixa est in aure. From rkern at ucsd.edu Mon Aug 8 01:59:53 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 07 Aug 2005 22:59:53 -0700 Subject: Metaclasses and new-style classes In-Reply-To: <3756d9750508071541192a00e0@mail.gmail.com> References: <3756d9750508071541192a00e0@mail.gmail.com> Message-ID: Jan-Ole Esleben wrote: > Hi! > > I've just posted a question about metaclasses in ZOPE on the ZOPE > list, and one of the replies said that metaclasses (at least > "painless" metaclasses) cannot be used without new-style classes (or > rather, that they don't work where you cannot explicitly use new-style > classes). I haven't so far been able to find _anything_ on the subject > - what is true here? http://docs.python.org/ref/metaclasses.html http://www.python.org/2.2.3/descrintro.html In short, yes. The preferred method for making metaclasses requires new-style classes. There is an older method which uses what is called the Don Beaudry hook; Zope used to use it extensively before Python 2.2. You should avoid using that older method and stick to new-style classes. -- 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 R.Brodie at rl.ac.uk Mon Aug 22 11:10:50 2005 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 22 Aug 2005 16:10:50 +0100 Subject: sending binary files to a 16 micro controller. References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <11gjn8k74pb6uc0@corp.supernews.com> Message-ID: "Grant Edwards" wrote in message news:11gjn8k74pb6uc0 at corp.supernews.com... > It's very probable that the TCP stack will combine chunks and > send out full Ethernet frames (4K bytes). > > You're probably going to have to either put a time delay in the > loop, or wait for each chunk to be acknowledged before sending > the next one. Yes, although it would be a rather perverse design from the controller point of view (it's not clear to me whether that is a given). From cliff at develix.com Tue Aug 2 07:35:30 2005 From: cliff at develix.com (Cliff Wells) Date: Tue, 02 Aug 2005 04:35:30 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <87oe8gdbof.fsf@wilson.rwth-aachen.de> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> Message-ID: <1122982530.19618.524.camel@localhost.localdomain> On Tue, 2005-08-02 at 09:45 +0200, Torsten Bronger wrote: > Yes, this is what I meant with "legacy code". C and C++ are > actually special-purpose. They are good for controlling a computer > but not for implementing an idea. Their current vitality on almost > all software areas arise from the fact that they had been extremely > successful before Java, C#, and VB came into play. Unfortunately your assertion is patently false. C and C++ are very much general-purpose languages. It is a logical contradiction to assert that Java, C#, VB and Python are general-purpose languages while C and C++ are not when the former were implemented using the latter. Being implemented in C, Python can do nothing that C cannot. It can certainly make it *easier* to do things, but it conveys no new abilities other than that of meeting deadlines ;) As an aside, I don't disagree with what I think is your main point: higher-level abstractions make more advanced ideas feasible. You simply state it far too strongly. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From jjl at pobox.com Fri Aug 26 19:20:05 2005 From: jjl at pobox.com (John J. Lee) Date: Fri, 26 Aug 2005 23:20:05 GMT Subject: Fighting Spam with Python References: Message-ID: <87ek8gs34c.fsf@pobox.com> David MacQuigg writes: [...] > I haven't used Spambayes, but my experience with Spamnix (an offshoot > of Spam Assassin) is that statistical filters always have a few false > rejects. In my case, that's about two per week. [...] That is precisely the problem that Bayesian filtering was designed to solve. AFAIK, Spam Assassin is a non-Bayesian filter. (Though I think I heard they were thinking of grafting on Bayesian filtering to their existing algorithms, I'm not sure if they did it, or even if that's actually a sane thing to do.) [David, in an earlier email] > reject. 15% will get an immediate accept without filtering, because > the sender is authenticated and has a good reputation. Eventually, > all reputable senders will join the 15%, and the 5% will shrink to > where we can ignore it. Two questions you seem to be implicitly assuming particular answers to: Is widespread authentication a good thing? Does it solve any problem not solved by Bayesian filtering plus good mail client support? My first reaction is to answer "no" to both questions, so to regard your effort as harmful. Might be interesting to hear why you think it's a good thing, though. John From sp1d3rx at gmail.com Tue Aug 30 16:47:38 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 30 Aug 2005 13:47:38 -0700 Subject: variable hell In-Reply-To: References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> Message-ID: <1125434858.783283.202090@g47g2000cwa.googlegroups.com> Steve, can I quote you on that? "You can lead an idiot to idioms, but you can't make him think!" -- Steve Holden 2005 From steve at holdenweb.com Wed Aug 24 07:56:29 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Aug 2005 07:56:29 -0400 Subject: reg packages examples In-Reply-To: <20050823123704.94820.qmail@web8403.mail.in.yahoo.com> References: <1124799829.184333.275660@g14g2000cwa.googlegroups.com> <20050823123704.94820.qmail@web8403.mail.in.yahoo.com> Message-ID: praba kar wrote: > Dear All, > > I want to know about Modules and packages. > I can understand about Modules but I cannot understand > about Packages. Kindly let me > know about Packages with small example. > I can understand conceptually but I don't know > how to write programmatically. > > regards > Prabahar > Prabahar: In your headers I see "In-Reply-To: <1124799829.184333.275660 at g14g2000cwa.googlegroups.com>". This means that people will see your message as part of another thread. It's better not to do that if you want your message to be read in the proper context. A package is simply a directory containing an __init__.py file, which is executed when the package is imported. Sub-packages are subdirectories of the package main directory containing __init__.py files, which will be executed when the sub-package is imported. Packages can also contains modules, which are regular Python files that are executed when the module is imported. So, in brief, packages are just a way to let you organize your code in to a set of mutually dependent modules and sub-packages, making source maintenance easier and allowing selective import of parts of the implemented functionality. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From tjreedy at udel.edu Fri Aug 5 10:57:17 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 5 Aug 2005 10:57:17 -0400 Subject: why no arg, abs methods for comlex type? References: Message-ID: "Daniel Sch?le" wrote in message news:dcvqc2$8oi$1 at news2.rz.uni-karlsruhe.de... > I wonder why there are no methods like arg, abs > well one can use > c = 1+1j > abs(c) > > In my opinion it would also be nice to have the > possibility to write it as > c.abs() > it looks more OO Python is object based but not rigidly OO in syntax or looks. This is an intentional design decision. Not being gratuitiously redundant is another. > unfortunately there is no arg method to get the angle > of the complex number I agree that this is a deficiency. I would think .angle() should be a no-param method like .conjugate(), though its internal implementation would need access to the appropriate cmath functions. I think returning radians might be enough though. You could submit to the SourceForge tracker a RFE (Request For Enhancement) if not a patch. > I would also like to see some more functions to make > calculations with complex number more convenient > e.g. > c = 27 > c.pow(numerator = 1, denominator = 3, > mode = cmath.EULER, angle_mode = cmath.GRAD) > -> ((3,0), (3,120), (3,240)) Wanting all roots is fairly specialized. sqrt(4) is 2, not (2, -2). > what do you think about it? > maybe there exists some proposals aiming this goal? Have you looked for complex math functions in numpy, numarray, scipy or similar packages? It is possible that a cmath2 module, written in Python, could be useful. Terry J. Reedy From nick at craig-wood.com Tue Aug 23 08:29:50 2005 From: nick at craig-wood.com (Nick Craig-Wood) Date: 23 Aug 2005 12:29:50 GMT Subject: Revised PEP 349: Allow str() to return unicode strings References: <20050822213142.GA5702@mems-exchange.org> Message-ID: Thomas Heller wrote: > I like the fact that currently unicode(x) is guarateed to return a > unicode instance, or raises a UnicodeDecodeError. Same for str(x), > which is guaranteed to return a (byte) string instance or raise an > error. I guess its analogous to this... >>> int(100000000000000L) 100000000000000L > Wouldn't also a new function make the intent clearer? > > So I think I'm +1 on the text() built-in, and -0 on changing str. Couldn't basestring() perform this function? Its kind of what basestring is for isn't it? -- Nick Craig-Wood -- http://www.craig-wood.com/nick From darkcowherd at gmail.com Fri Aug 12 13:17:01 2005 From: darkcowherd at gmail.com (Dark Cowherd) Date: Fri, 12 Aug 2005 22:47:01 +0530 Subject: UCALC equivalent Message-ID: <5f4d3cb5050812101715bb679e@mail.gmail.com> http://www.ucalc.com/mathparser/index.html There is a great library called UCALC which allows you to set up an expression and evaluate it for e.g. you an define an expression by calling a function in UCALC then call it with various values of x for e.g. see this page http://www.ucalc.com/mathparser/sample6.html It is very fast. I have used it in VB when there is lot of number crunching to be done. Is there a Python equivalent. I looked at numPy and SciPy sites (just skimmed through) did'nt seem to have what I wanted. Any pointers? -- DarkCowherd From python at rcn.com Sat Aug 20 12:50:46 2005 From: python at rcn.com (Raymond Hettinger) Date: 20 Aug 2005 09:50:46 -0700 Subject: Sandboxes In-Reply-To: References: Message-ID: <1124556646.394024.116520@g47g2000cwa.googlegroups.com> > Googling for information on securing Python in a "sandbox" seems > indicate that there are some built in features, but they aren't really > trustworthy. Is that correct? > > For my purposes, I really just want to let users run in a sandbox, with > access to only the language, manipuate a few published objects in the > application (and perhaps give them some string and math libraries if > applicable). It depends on your desired level of security. If you want to make it hacker-proof, it is a lost cause. If you're creating an environment that just offers protection against accidents, that can be done. From gene.tani at gmail.com Mon Aug 8 01:19:47 2005 From: gene.tani at gmail.com (gene tani) Date: 7 Aug 2005 22:19:47 -0700 Subject: Decline and fall of scripting languages ? In-Reply-To: <7xbr4agti2.fsf@ruckus.brouhaha.com> References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123392742.576632.59400@z14g2000cwz.googlegroups.com> <7xbr4agti2.fsf@ruckus.brouhaha.com> Message-ID: <1123478387.355392.138290@o13g2000cwo.googlegroups.com> (throw Martin Fowler and Paul Graham into google blender) http://www.billkatz.com/node/42 http://osteele.com/archives/2005/03/ruby-and-laszlo From hpk at trillke.net Tue Aug 30 06:36:48 2005 From: hpk at trillke.net (holger krekel) Date: Tue, 30 Aug 2005 12:36:48 +0200 Subject: Release of PyPy 0.7.0 In-Reply-To: <1h20uj1.y52kzk1che9j9N%dial#####$$NOSPAM##$#$##tone@gmail.com> References: <4311ea97$0$1276$ed2619ec@ptn-nntp-reader02.plus.net> <1h20uj1.y52kzk1che9j9N%dial#####$$NOSPAM##$#$##tone@gmail.com> Message-ID: <20050830103648.GA28663@solar.trillke.net> Hi Valentino, Michael, all, On Sun, Aug 28, 2005 at 20:46 +0200, Valentino Volonghi aka Dialtone wrote: > Michael Sparks wrote: > > Would it be useful for people to start trying out their modules/code to see > > if they work with this release, and whether they can likewise be translated > > using the C/LLVM backends, or would you say this is too early? (I'm more > > thinking in terms of it providing real world usecases in the hope of > > finding things that don't work - rather than anything else) > > This is not how it works. Pypy doesn't translate your code to C/LLVM. > Currently PyPy can only translate a pretty simple subset of python > called RPython which has a very C-like syntax (but without memory > management code). This is needed to allow type inference inside the > interpreter code. This is mostly true but maybe a bit misleading. The subset of Python that we can translate does not involve special syntax. For example we can translate http://codespeak.net/pypy/dist/pypy/translator/goal/richards.py and gain some speed up by a factor of 70 over interpretation with CPython. The "RPython" limitation mainly refers to the way how dynamically you use Python and how unambigously your values flow across your functions and methods. Also you cannot, for example, create classes dynamically while creating instances is, of course, no problem. Also, we support all Python control flow statements. For a more detailed list, look at: http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#rpython-definition-not The real culprit is that we don't currently intend to try offering a tool that can automatically translate Python modules to C because we are still experimenting with and targeting our own Python interpreter and tackling the challenges that arise out of translating this efficiently. It's a matter of focus of the current dev group and not one of technical feasibility. If one or more people would want to care for producing, testing and documenting such a tool on top of our current code base then the next weeks might be good for that as we intend to go for some cleanup refactorings anyway. > The code in your application is application code and can be whatever you > want, you may try to translate it to C/LLVM but it won't be that good of > course because the annotator is not that intelligent. See above. You can try to translate python programs with a bit of effort and determination to find your way :-) > Just In Time compilation a-la-psyco is planned before the 1.0 release of > pypy. We don't have a fixed version roadmap but indeed, we plan to work on JIT compilation and other niceties rather soon now. cheers, holger From denis.kasak at gmail.com Thu Aug 25 23:52:15 2005 From: denis.kasak at gmail.com (Denis Kasak) Date: Fri, 26 Aug 2005 05:52:15 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: Mike Schilling wrote: > > I see a difference between "X would be useful for A, B, and C" and "Y will > always be the only proper way." > > Don't you? Y would not be useful because of the bandwidth it consumes, the malware it would introduce, the additional time spent focusing on the format rather than quality of the content and, frankly, because it's useless. As Rich already said, if one wants to look at neatly formatted content, one can always visit the web. Usenet is meant to be an information-sharing facility, and I cannot see *any* reason why it should be exposed to all the disadvantages stated in numerous places in thread to gain a pale "advantage" such as flashy content. We already have a World Wide Web, no need to make Usenet it's clone. -- Denis From kenneth.m.mcdonald at sbcglobal.net Fri Aug 26 16:36:07 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Fri, 26 Aug 2005 15:36:07 -0500 Subject: Any projects to provide Javascript-style client-side browser access via Python? In-Reply-To: <7xacj4o46t.fsf@ruckus.brouhaha.com> References: <7xacj4o46t.fsf@ruckus.brouhaha.com> Message-ID: On Aug 26, 2005, at 3:04 PM, Paul Rubin wrote: > Python isn't a good choice as a browser language because it doesn't > have enough security. Hostile scripts can take over the interpreter > too easily. > > There was a Python-based browser effort called Grail which I don't > think got very far. > > Personally I think there are very few good uses for complex client > side browser scripts. Most sites that use Javascript don't really > need to. > My belief is that if HTML/CSS/DOM can add a few more (admittedly difficult) features, then it will become a serious contender for fairly complex UI programs, i.e. ones that don't access web pages--it will be a replacement for existing UI libraries such as for Windows or OS X, wxWindows, Qt, etc. And if that's the case, then the security issue is irrelevant, and similarly, the need to be able to write significant programs becomes much greater. Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From noway at sorry.com Sun Aug 21 07:29:56 2005 From: noway at sorry.com (Giovanni Bajo) Date: Sun, 21 Aug 2005 11:29:56 GMT Subject: Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out) References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <8xWNe.24050$HM1.696102@twister1.libero.it> Message-ID: Michael Hoffman wrote: >> FWIW, this just highlights how ineffecient your build system is. >> Everything you currently do by hand could be automated, including >> MSI generation. > > I'm sure Martin would be happy to consider a patch to make the build > system more efficient. :) Out of curiosity, was this ever discussed among Python developers? Would something like scons qualify for this? OTOH, scons opens nasty self-bootstrapping issues (being written itself in Python). Before considering a patch (or even a PEP) for this, the basic requirements should be made clear. I know portability among several UNIX flavours is one, for instance. What are the others? -- Giovanni Bajo From me at privacy.net Fri Aug 26 09:35:58 2005 From: me at privacy.net (Dragan Cvetkovic) Date: Fri, 26 Aug 2005 09:35:58 -0400 Subject: Usenet, HTML References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8366F9vvsU1@individual.net> <3n8ch4Fb539U1@individual.net> Message-ID: John Bokma writes: > usenet at isbd.co.uk wrote: >> They don't have killfiles or scoring > > You can install a mod to kill people. Gee, didn't know that it's that powerful. One more reason not to use web forums :-) Dragan -- Dragan Cvetkovic, To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer !!! Sender/From address is bogus. Use reply-to one !!! From westside_indie at yahoo.com Sun Aug 21 12:28:22 2005 From: westside_indie at yahoo.com (John Walton) Date: Sun, 21 Aug 2005 09:28:22 -0700 (PDT) Subject: network programming Message-ID: <20050821162823.93986.qmail@web31013.mail.mud.yahoo.com> Hello, everyone. I just began school, and they already assigned us science fair. Since I'm in 8th grade, I get to do demonstrations for our projects. I'm probably going to demonstrate Python's networking capabilities by writing a simple instant messenger program. I only have a few problems: 1. I know squat about Python network Programming 2. I know nothing about networks So if any of you know of a good Python Networking Tutorial or a website with lots of information on networks and networking, please reply. Thanks! __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From zen19725 at zen.co.uk Thu Aug 11 07:03:58 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Thu, 11 Aug 2005 12:03:58 +0100 Subject: What is Python?! References: <42fa51db$0$7802$626a14ce@news.free.fr> <42faccb9$1@news.orcon.net.nz> Message-ID: On Thu, 11 Aug 2005 15:51:45 +1200, Evil Bastard wrote: > >I guess a language could be called a 'scripting language' if: > - the source code can be executed directly, and/or > - source need not be converted to a separate file in a > non-human-readable format before it can be executed, and/or > - a change to the source file automatically causes a change in > runtime behaviour > >By these, Python is most definitely a scripting language, and joins Perl >and PHP. Whereas changes to java source files don't change runtime >behaviour. It wouldn't be particularly difficult to invoke Java by a shell script that checks to see if source has changed and if so recompiles it. If such a script became part of standard Java, would Java then be a scripting language? -- Email: zen19725 at zen dot co dot uk From dickinsm at verizon.net Thu Aug 25 14:05:02 2005 From: dickinsm at verizon.net (Mark Dickinson) Date: Thu, 25 Aug 2005 18:05:02 GMT Subject: Speed quirk: redundant line gives six-fold speedup References: Message-ID: In article , Bill Mill wrote: > One of my own: what in the world made you think "maybe I'll add 29 > dummy global variables to speed things up?" You mean this isn't a well-known optimization technique? :) I was refactoring the code, and after making a particular function redundant I noticed that removing the code for that function produced the slow down described. Then I naturally experimented to try to figure out what I had to put back in to recover the original speed. Not that I really care about the speed itself, but I'd dearly like to understand what's at work here. Mark From cliff at develix.com Tue Aug 2 00:33:48 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 21:33:48 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <868xzleztf.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> Message-ID: <1122957228.19618.475.camel@localhost.localdomain> On Tue, 2005-08-02 at 00:18 -0400, Mike Meyer wrote: > Or maybe you could switch to Jython, and just use swing? Man, c.l.py is getting *mean* ;) -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From pydecker at gmail.com Wed Aug 17 11:34:22 2005 From: pydecker at gmail.com (Peter Decker) Date: Wed, 17 Aug 2005 11:34:22 -0400 Subject: Testing for presence of arguments In-Reply-To: <430353e1$0$18641$14726298@news.sunsite.dk> References: <430353e1$0$18641$14726298@news.sunsite.dk> Message-ID: On 8/17/05, Madhusudan Singh wrote: > I know how to set optional arguments in the function definition. Is there an > intrinsic function that determines if a certain argument was actually > passed ? Like the fortran 95 present() logical intrinsic ? > > My required functionality depends on whether a certain argument is specified > at all. (Setting default values is *not* good enough.). Could you just write the function as: myFunc(*args, **kwargs): ...and then figure out what was passed? -- # p.d. From mirnazim at gmail.com Tue Aug 9 01:33:10 2005 From: mirnazim at gmail.com (Mir Nazim) Date: 8 Aug 2005 22:33:10 -0700 Subject: Point and click GUI builder for Python In-Reply-To: <1123348044.677983.211380@g47g2000cwa.googlegroups.com> References: <42f430ea$0$18643$14726298@news.sunsite.dk> <1123348044.677983.211380@g47g2000cwa.googlegroups.com> Message-ID: <1123565590.375700.75140@g44g2000cwa.googlegroups.com> neuruss neuruss wrote: > Madhusudan Singh wrote: > > Is there such a thing for python ? Like Qt Designer for instance ? > > The easiest way to create Python GUI apps: PythonCard. > It is based on wxPython by it has a higher level of abstraction. > You just drag and drop widgets on a form and code the events like you > woud in Visual Basic or Delphi. > IMHO, it's easier, simpler, more intuitive and stable than Boa > Constructor. Add to it wxGlade.sourceforge.net. But remember it is only a UI designer(does it pretty well) not an IDE. I fee wxGlade+SPE(http://www.stani.be/python/spe/blog/) are a better combo than PythonCard. Mir Nazim. www.PlanetNazim.com From paolo_veronelli at tiscali.it Sun Aug 7 03:26:18 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Sun, 07 Aug 2005 09:26:18 +0200 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?) In-Reply-To: References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <42F4F2D3.80804@tiscali.it> Message-ID: <42F5B79A.1050507@tiscali.it> Terry Reedy wrote: > "Paolino" wrote in message > news:42F4F2D3.80804 at tiscali.it... > >>seberino at spawar.navy.mil wrote: >>I don't think the global keyword is useful actually. >>What's so special in a module nemespace to be priviledged like that. > > > The specialness of globals and locals was part of Python's original simple > namespace design, and is still reflected in exec statements and eval > functions, as well as in nested functions. > > >>The point IMO is accessing names defined somewhere in the enclosing >>namespaces. > > > Accessing such names is already possible, even *after* the outer function > returns and the rest of its execution context is deleted. > > >>def enclosing(): >> var=2 >> def enclosed(): >> outer var=4 > > > This is rebinding, rather than merely accessing. Similar, but even more > problematical would be initial binding in outer from inner: > > def enclosing(): > def enclosed(): > outer var = 4 > > >>this is the base of something useful. > > > Actually, it is the reinvention of classes: > > class enclosing(object): > def __init__(self): > self.var = 2 > def enclosed(self): > self.var = 4 > This is using some really 'featured' namespace called class to do things which are useful to all namespaces.So not a solution but a hack. Also 'self' is something really away from my example.A cloned namespace of the class probably. Working hard with python namespaces is hacking: probably this makes us masters of python, when using namespaces should be a base knowledge. > There was a long discussion on the pydev list a couple of years ago re > adding rebinding in addition to access (of outer variables). I think, in > the end, Guido concluded that there was no compelling reason, as of then, > to add another general mechanism for private, sharable, rebindable > variables. > > >>I think there is only one or none possible solution to an outer statement > > > There were lots of proposals for both the exact syntax and semantics of > outer binding/rebinding. > You cut the phrase and the meaning of it. The only one solution I'm talking about is this: Stated 'outer var' in a namespace, jumping out of the namespace we found ourselves in another namespace. If 'var' is bound there, that's the solution to the 'outer' ,if not we jump out again.If the 'var' is never found we can raise an UnboundOuter error probably. Regards Paolino ___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com From haircut at gmail.com Wed Aug 31 16:11:01 2005 From: haircut at gmail.com (Adam Monsen) Date: 31 Aug 2005 13:11:01 -0700 Subject: time.strptime() for different languages Message-ID: <1125519061.261802.285840@o13g2000cwo.googlegroups.com> Anyone know of something that works like time.strptime(), but for other languages? Specifically, Dutch (ex: "31 augustus 2005, 17:26") and German? Thinking out loud... since "31 augustus 2005, 17:26" is only different by month name, I suppose I could just substitute the month name using a translation table for English to Dutch month names. -- Adam Monsen http://adammonsen.com/ (crossposted to Seattle Python Users List) From jeffrey.schwab at rcn.com Tue Aug 9 22:55:54 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Tue, 09 Aug 2005 22:55:54 -0400 Subject: Recommendations for CVS systems In-Reply-To: References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> <20050810021120.GA25296@alcyon.progiciels-bpi.ca> Message-ID: Mike Meyer wrote: > Well, the only thing that subversion does that I'd call bad is leave > turds in my development directory. I'm tired of having to tell > commands to ignore .svn files. Of course, Perforce is the only source > control system I know of that doesn't do this. ClearCase is really good about this, too, though expensive. It definitely requires a different mindset from CVS and Subversion. I'm told Vesta is ClearCase-like. If anyone here has used it recently, I would love to hear their opinion. From onurb at xiludom.gro Wed Aug 31 05:04:56 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 31 Aug 2005 11:04:56 +0200 Subject: Adding bound methods dynamically... CORRECTED In-Reply-To: <1125462130.670127.206220@g44g2000cwa.googlegroups.com> References: <4o4ah1h2r53gll81jinueaugpqi7rq7hsj@4ax.com> <7s5ah1t7t2qvseneigb6p1jv9igcl4diri@4ax.com> <1125462130.670127.206220@g44g2000cwa.googlegroups.com> Message-ID: <431572ba$0$27027$626a14ce@news.free.fr> Devan L wrote: > Kevin Little wrote: > >>I want to dynamically add or replace bound methods in a class. (snip) > I'm not an expert, but why do you need to dynamically add or replace > bound methods? To modify the behaviour at runtime ?-) There are a lot of idioms/patterns in dynamic languages that seems somewhat alien at first, then become an obvious solution. When I discovered first-class functions and anonymous functions with Python some years ago, I wondered what could be the use of such things. Now I couldn't live without... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From pwatson at redlinepy.com Mon Aug 15 12:29:52 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 15 Aug 2005 11:29:52 -0500 Subject: Using for in one-liner Message-ID: <3mbu82F15h18oU1@individual.net> Can a for loop be used in a one-liner? What am I missing? $ python -c "import sys;print ''.join([line for line in sys.stdin.readlines()])," now is the time now is the time $ python -c "import sys;for line in sys.stdin.readlines(): print line," File "", line 1 import sys;for line in sys.stdin.readlines(): print line, ^ SyntaxError: invalid syntax $ python -c "import sys;for i in range(5): print i," File "", line 1 import sys;for i in range(5): print i, ^ SyntaxError: invalid syntax From gry at ll.mit.edu Fri Aug 12 10:23:46 2005 From: gry at ll.mit.edu (gry at ll.mit.edu) Date: 12 Aug 2005 07:23:46 -0700 Subject: Catching stderr output from graphical apps In-Reply-To: References: <1123697339.925135.161200@g47g2000cwa.googlegroups.com> Message-ID: <1123856626.852626.236030@g43g2000cwa.googlegroups.com> Linux -2.4.20 (x86), Python 2.3.3. I did exactly as you suggested. After the stderr.write, a window pops up with title "Error Stream from run of errorwindow.pyc". The window is otherwise blank. Nothing more happens when I do the "x=7+nosuchvariable", I just get the next python ">>>" prompt, but no error messages. When I try to exit the python, e.g. sys.exit(), it hangs and I have to Control-C. After the control-C, the "Error Stream..." window goes away. Any more suggestions? Perhaps we should take this to email, instead of newsgroup? This *is* something I would like to be able to use, if we can get it working. -- George From gerrit at nl.linux.org Sat Aug 27 16:28:11 2005 From: gerrit at nl.linux.org (Gerrit Holl) Date: Sat, 27 Aug 2005 22:28:11 +0200 Subject: pre-PEP: Object-oriented file module In-Reply-To: References: Message-ID: <20050827202811.GA12540@topjaklont.student.utwente.nl> Kenneth McDonald wrote: > Subject: pre-PEP: Object-oriented file module Please have a look at http://topjaklont.student.utwente.nl/creaties/path/pep-xxxx.html if you haven't done so already. Gerrit. -- Temperature in Lule?, Norrbotten, Sweden: | Current temperature 05-08-27 22:20:00 11.8 degrees Celsius ( 53.3F) | -- In the councils of government, we must guard against the acquisition of unwarranted influence, whether sought or unsought, by the military-industrial complex. The potential for the disastrous rise of misplaced power exists and will persist. -Dwight David Eisenhower, January 17, 1961 From http Fri Aug 26 17:35:03 2005 From: http (Paul Rubin) Date: 26 Aug 2005 14:35:03 -0700 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> Message-ID: <7xoe7kjsag.fsf@ruckus.brouhaha.com> zen19725 at zen.co.uk (phil hunt) writes: > >Let's see. Reality is that writing correct programs is hard. Writing > >correct programs that use concurrency is even harder, because of the > >exponential explosion of the order that operations can happen > >in. Personally, I'm willing to use anything I can find that makes > >those tasks easier. > > Indeed so. Use threading (or whatever) when one has to, use an > asynchronous single-threaded process whenever you can. This is silly. You could say the exact same thing about if statements. The number of paths through the program is exponential in the number of if statements executed. So we better get rid of if statements. Really, the essence of programming is to find ways of organizing the program to stay reliable and maintainable in the face of that combinatorial explosion. That means facing the problem and finding solutions, not running away. The principle is no different for threads than it is for if statements. From lycka at carmen.se Mon Aug 22 08:17:48 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 22 Aug 2005 14:17:48 +0200 Subject: sending binary files to a 16 micro controller. In-Reply-To: References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> Message-ID: Magnus Lycka wrote: > header_template = 'Chunk %05i, %03i bytes' BTW, if the header is binary, you probably want to have a look at the struct module. http://docs.python.org/lib/module-struct.html From robiweb90 at liamg.com.invalid Sat Aug 6 05:36:56 2005 From: robiweb90 at liamg.com.invalid (Micetto Nero) Date: Sat, 06 Aug 2005 09:36:56 GMT Subject: Point and click GUI builder for Python In-Reply-To: <42f430ea$0$18643$14726298@news.sunsite.dk> References: <42f430ea$0$18643$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > Is there such a thing for python ? Like Qt Designer for instance ? pyGTK http://glade.gnome.org/ http://gazpacho.sicem.biz/ wxPython http://boa-constructor.sourceforge.net/ You can even use Qt Designer with pyQt http://www.riverbankcomputing.co.uk/pyqt/ -- robiweb90 [at] gmail [dot] com "Nessuno pu? fabbricare una macchina tanto intelligente che possa essere usata da uno sciocco" - Confucio From volpadri at aliceposta.it Wed Aug 24 06:51:28 2005 From: volpadri at aliceposta.it (volpadri at aliceposta.it) Date: 24 Aug 2005 03:51:28 -0700 Subject: jython debugger Message-ID: <1124880688.306010.10820@g49g2000cwa.googlegroups.com> Hi, I am looking for an ide debugger for jython: is there someone with some suggestions ? Thanks, Adriano From richardlewis at fastmail.co.uk Fri Aug 26 06:55:31 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Fri, 26 Aug 2005 11:55:31 +0100 Subject: ideas for university project ?? In-Reply-To: References: Message-ID: <1125053731.5697.241536656@webmail.messagingengine.com> On Fri, 26 Aug 2005 11:49:34 +0100, "Jon Hewer" said: > > Areas of interested include AI, distributed systems. Have you considered looking at Semantic Web stuff? Its all still experimental but its quite AI and very distributed. Cheers, Richard From cct at tavaresstudios.com Sun Aug 21 18:42:37 2005 From: cct at tavaresstudios.com (Chris Tavares) Date: Sun, 21 Aug 2005 22:42:37 GMT Subject: urllib leaves sockets open? References: <7xek8nc0l2.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7xek8nc0l2.fsf at ruckus.brouhaha.com... > "Chris Tavares" writes: > > Is this normal behavior for urllib? Is there a way to force that initial > > socket closed earlier? Is there something else I need to do? > > I'd say open a sourceforge bug. There may be a way around it with the > fancy opener methods of urllib2, but it's a bug if regular urllib > opens a second socket without closing the first one. For http 1.1 > it should be able to use just one socket anyway. Thanks, I'll do some poking around in urllib first and see if I can narrow it down. Is there a way to do HTTP 1.1 with urllib? The docs say 0.9 and 1.0 only. Thanks, -Chris From rkern at ucsd.edu Tue Aug 30 06:58:20 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 30 Aug 2005 03:58:20 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> < Message-ID: Bryan Olson wrote: > Currently, user-defined classes can implement Python > subscripting and slicing without implementing Python's len() > function. In our proposal, the '$' symbol stands for the > sequence's length, so classes must be able to report their > length in order for $ to work within their slices and > indexes. > > Specifically, to support new-style slicing, a class that > accepts index or slice arguments to any of: > > __getitem__ > __setitem__ > __delitem__ > __getslice__ > __setslice__ > __delslice__ > > must also consistently implement: > > __len__ > > Sane programmers already follow this rule. Incorrect. Some sane programmers have multiple dimensions they need to index. from Numeric import * A = array([[0, 1], [2, 3], [4, 5]]) A[$-1, $-1] The result of len(A) has nothing to do with the second $. -- 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 chad.hughes at pnl.gov Thu Aug 11 19:36:35 2005 From: chad.hughes at pnl.gov (Hughes, Chad O) Date: Thu, 11 Aug 2005 16:36:35 -0700 Subject: Can't start new thread Message-ID: <42C7E766869C42408F0360B7BF0CBD9B019D60CA@pnlmse27.pnl.gov> > I am trying to understand what is causing python to raise this error > when I create a number of threads: > > thread.error: can't start new thread > > I have been told that it is due to the default thread size (1 MB), but > I have recompiled python defining an alternate threadsize, and I am > not seeing any changes. I defined the THREAD_STACK_SIZE in the > thread_pthread.h file. > > Any ideas? > > Here is the code I am using to test the number of threads I can get > running. It maxis out at 1031. I have tested it on two systems, one > with 1GB of ram and another with 2GB of RAM. > > import threading > import time > > class Mythread(threading.Thread): > def __init__(self): > self.__live = True > threading.Thread.__init__(self, target=self.runLoop) > def runLoop(self): > while self.__live: > time.sleep(.1) > def stop(self): > self.__live = False > > threads = [] > max = raw_input("max: ") > if max == 'None': > max = None > else: > max = int(max) > > while True: > print len(threads) > t = Mythread() > t.start() > threads.append(t) > if len(threads) == max: > break > > print 'all running' > > while True: > answer = raw_input("stop now? ") > if answer in ['Y','y']: > break > > print "stopping" > for t in threads: > t.stop() > > print "joining" > for t in T: > t.join() > > while True: > answer = raw_input("Quit now? ") > if answer in ['Y','y']: > break > > print "done" -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sun Aug 7 11:01:38 2005 From: http (Paul Rubin) Date: 07 Aug 2005 08:01:38 -0700 Subject: Python -- (just) a successful experiment? References: <1123422959.086345.76190@g49g2000cwa.googlegroups.com> Message-ID: <7xll3dpz8t.fsf@ruckus.brouhaha.com> "Paul Boddie" writes: > > Why do web scripters still cling to their Perl, even in corporate > > environments? > > Ignorance. One could argue that Python should be promoted more, but > Perl had the "cool tool" buzz a good ten years ago. Such habits don't > fade away very quickly. I don't think it's ignorance. Some people really do like Perl better than Python. I can sort of understand why, even though I don't feel that way myself. > > Why hasn't Python made inroads against Java? > > I would guess that most people deploying Java want to be able to buy > and deploy some big name product with the pretense that they can always > switch to another big name product later on, all in the name of > "multiple vendor support". Come on, this is silly, Java is a lot more cumbersome for doing small, quick projects, but Python doesn't have the language discipline or the library support to do heavyweight projects that Java can. There is nothing like JSSE in Python. There is no JDBC replacement unless you get a third party module from somewhere. There is no MQ. CPython doesn't support multiprocessing (multiple threads on parallel processors, due to the GIL). Python's documentation is full of holes. Python's runtime library is full of holes. Almost every time I use a Python module that I haven't used before, I find bugs. Java is tastelessly designed and clumsy, but its language spec is very thorough and its implementation (including libraries) is complete and well-documented. Python is great for recreational projects and prototyping. It's not yet mature enough for deploying complex, critical applications, though maybe it's getting there (PyPy will be an important step). I'm not trying to bash Python--I know how hard it is to write and maintain a complex system that doesn't have gaps. And the Python developers did some very nice work with rather limited resources. But the magnitude of sheer grunt power that went into Java just completely overwhelms what went into Python. > > Why is Ruby, and Ruby on Rails, getting such strong play? > Relentless hype from blogging celebrities? That's an interesting explanation and might be true for all I know. But it does look like RoR has capabilities that Python (out of the box) doesn't. > > Applications like Zope and Plone help drive more people toward the > > language, though the competition is stiff. > > If you've tried Plone, you must have noticed that it too installs > itself nicely, I looked at Zope a little bit and didn't find it attractive. Plone sounds more interesting and I hope to check it out sooner or later. From usenet at mail-2-me.com Thu Aug 11 10:38:06 2005 From: usenet at mail-2-me.com (usenet at mail-2-me.com) Date: 11 Aug 2005 07:38:06 -0700 Subject: net view /domain Message-ID: <1123771086.505804.208490@f14g2000cwb.googlegroups.com> Hi! Is there a module I can use for "net view /domain" so list all available domains and workgroups in a windows-network? I'm looking for something like win32net.NetServerEnum, because I don't really want to do this by "popen". Kind regards Dirk From cantabile.03 at wanadoo.fr Sun Aug 7 20:56:35 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Mon, 08 Aug 2005 02:56:35 +0200 Subject: gettext again In-Reply-To: References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> Message-ID: <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> stasz a ?crit : > On Sun, 07 Aug 2005 21:33:21 +0200, cantabile wrote: > > >>stasz a ?crit : >> >>>On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote: >>> >>> >>> >>>>Hi, >>>>I'm failing to make it work but can't find out what's wrong. Here's what >>>>I do : >>> >>>[....] >>> >>> >>>>How come ? What's wrong with what I am doing ? >>> >>>Start with this little howto about gettext. >>>http://childsplay.sourceforge.net/translate-howto.html >>> >>>And then do this in your test.py: >>>http://www.python.org/doc/2.4.1/lib/node330.html >>> >>>You should read the part about gettext in the Python Library Reference >>>it's really good :-) >>> >>>Good luck, >>>Stas Z >>> >>> >> >>Well, I must be dumb, because I did exactly that and it still doesn't >>work... >> >>BTW, I have no pygettext module. I asked here and somebody said it was >>deprecated and now included in xgettext. >>And I've read the Python doc about gettext about ten times, but it seems >>quite outdated since it calls pygettext (as staded above)... >> >>I've read the info pages of gettext too (quite a long work). > > Ok, you should use xgettext to create a .po file from your test1.py. > Translate that file and use msgfmt to compile it into a .mo file. > Copy this .mo file to /usr/share/locale/fr/LC_MESSAGES/ > > >>Here's my test1.py file again : >> >>=========================== >>import gettext, os, locale >> >>locale.setlocale(locale.LC_ALL) >>gettext.install('test1.py', '/usr/share/locale') > > test1.py is wrong, you must give the name of the .mo file. > It must be: gettext.install('test1.mo', '/usr/share/locale') > Assuming you have called the mo file like that. > > Stas Z > > Well, I did this exactly... and still no go. Is this sequence correct : 1? xgettext test1.py 2? mv messages.po messages.pot 3? msginit 4? Translate msgstr"" in fr_FR at euro.po file 5? msgfmt -o test1.mo fr_FR at euro.po 6? cp test1.mo /usr/share/locale/LC_MESSAGES 7? python test1.py This is what I did, without success. Must be bewitched :(( From dmqatpobox.com Thu Aug 25 01:46:28 2005 From: dmqatpobox.com (David MacQuigg) Date: Wed, 24 Aug 2005 22:46:28 -0700 Subject: Fighting Spam with Python Message-ID: Are you as mad about spam as I am? Are you frustrated with the pessimism and lack of progress these last two years? Do you have faith that an open-source project can do better than the big companies competing for a lock-in solution? If so, you might be interested in the Open-Mail project. I'm writing some scripts to check incoming mail against a registry of reputable senders, using the new authentication methods. Python is ideal for this because it will give mail-system admins the ability to experiment with the different methods, and provide some real-world feedback sorely needed by the advocates of each method. So far, we have SPF and CSV. See http://purl.net/macquigg/email/python for the latest project status. I welcome anyone who is interested in helping, expecially if you have some experience with mail transfer programs, like Sendmail or Postfix, or spam filtering programs, like SpamAssassin. My Python may not be the best, so I welcome suggestions there also. We need to make these scripts a model of clarity. -- Dave From gyromagnetic at gmail.com Thu Aug 25 13:29:40 2005 From: gyromagnetic at gmail.com (gyromagnetic at gmail.com) Date: 25 Aug 2005 10:29:40 -0700 Subject: algorithm for non-dimensionalization Message-ID: <1124990980.137239.243470@g44g2000cwa.googlegroups.com> Hi, I am trying to non-dimensionalize some data I have obtained. There are no 'standard' dimensionless groups for my application, so I would like to obtain the 'best' non-dimensional groups based on some statistical measures of the resulting transformed data. At this point, I am looking for a way to generate dimensionless groupings from a set of base units. I would like to have a way to output all dimensionless groups that comprise no more than some specified number of fundamental (or base) units. For instance, if I have data like the following: dat1(length), dat2(time), dat3(length), dat4(length/time), dat5(length^2) and I want dimensionless groups with no more than four base units, I would like a result like the following: dat1/dat3, dat1/(dat2*dat4), dat5/(dat1*dat3), dat5/(dat2*dat4*dat1), ... I plan to code this in Python, and would appreciate any thoughts you might have about algorithms or approaches to carry out this task. Thank you. -g From ksenia.marasanova at gmail.com Wed Aug 10 08:33:15 2005 From: ksenia.marasanova at gmail.com (Ksenia Marasanova) Date: Wed, 10 Aug 2005 14:33:15 +0200 Subject: sorting question In-Reply-To: References: Message-ID: <130df193050810053317054b26@mail.gmail.com> 2005/8/10, Peter Otten <__peter__ at web.de>: > I think you cannot get away with your first rule, but have to operate on the > full path instead. Otherwise the position of inner nodes would sometimes be > determined by their url and sometimes by their ord_number *during* *the* > *same* *sort*. Rrr.. of course, you're right! Thanks. Your code works great, I only made one slightly change: def get_key(self): return [(node.id, node.ord_number) for node in self.get_path()] Because of errors in my tree some siblings has the same ord_number. -- Ksenia From apardon at forel.vub.ac.be Wed Aug 17 03:23:29 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Aug 2005 07:23:29 GMT Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: Op 2005-08-16, Peter Hansen schreef : > Antoon Pardon wrote: >> Why has one made a difference in search policy for finding a >> variable based on whether the variable is rebound or not >> in the first place. > > Do you really not understand the reason, or do you simply disagree with > it? How can I understand something that was never explained to me. Each time I saw this coming up people answered the technical question about the difference between rebinding and accessing or modification. I haven't seen anyone answer the question asnwer at this level. > It's a choice with rational thought behind it. Then please explain this rational thought instead of just asserting that it is present. -- Antoon Pardon From lambacck at computer.org Tue Aug 2 13:35:37 2005 From: lambacck at computer.org (Chris Lambacher) Date: Tue, 2 Aug 2005 13:35:37 -0400 Subject: pre subprocess help needed In-Reply-To: <1123002300.258761.316950@g44g2000cwa.googlegroups.com> References: <1123002300.258761.316950@g44g2000cwa.googlegroups.com> Message-ID: <20050802173537.GA24485@computer.org> There is a version of subprocess for 2.3. http://www.lysator.liu.se/~astrand/popen5/ http://effbot.org/downloads/#subprocess On Tue, Aug 02, 2005 at 10:05:00AM -0700, chuck wrote: > I need to execute a command shell process obtain the return code and > capture stdout from that shell process. I've done this with 2.4 using > subprocess. How do I do it with 2.3? > > -- > http://mail.python.org/mailman/listinfo/python-list From richardlewis at fastmail.co.uk Fri Aug 26 11:30:32 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Fri, 26 Aug 2005 16:30:32 +0100 Subject: Problem with Pythoncard In-Reply-To: <20050826152115.GA6945@god.godsdomain> References: <20050826152115.GA6945@god.godsdomain> Message-ID: <1125070232.30705.241554828@webmail.messagingengine.com> On Fri, 26 Aug 2005 20:51:15 +0530, "Varun Hiremath" said: > Hello everybody, > I was trying to install pythoncard on my system and I got this > error. I am using an unstable version of Debian. Can someone tell me > what the error could be. Is it because I am usingUnstable version of > Debian I am getting this error or is it because of some other > reason. > > I hope I am mailing this error to the right mailing list if not pls > let me know. > I've just tried this and got exactly the same error. It looks like the problem is that it depends on libwxgtk2.5.3-python which doesn't exist (see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=313479). Debian unstable is migrating to wxWindows 2.6. You might just have to wait! Cheers, Richard From matt.hammond at rd.bbc.co.uk Wed Aug 10 07:16:46 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Wed, 10 Aug 2005 12:16:46 +0100 Subject: Why is this? References: Message-ID: Hi Jiri, On Wed, 10 Aug 2005 11:40:54 +0100, Jiri Barton wrote: > I have a problem with initialization. >>>> a, b = [[]]*2 >>>> a.append(1) >>>> b > [1] > > Why is this? Why does not this behave like the below: > >>>> a, b = [[], []] >>>> a.append(1) >>>> b > [] In the first case, you make a list containing a single empty list. The "*2" operation duplicates the item in that list. So now both a and b contain the same instance of an empty list. Whereas in the second case, you explicity declare two separate instances of an empty list. The append method modifys the existing list object - it changes the values it holds inside itself. Therefore, in the first example, because a and b both refer to the same object, changing 'a' will will appear to also change 'b'. The same is not true of the second example, because they are different objects. A simpler example: >>> a = [] >>> b = [] >>> c = b Now lets try some tests: >>> a == b True >>> b == c True Ok - so this shows that a and b, and b and c are equal _in the sense that they amount to the same value_. But that doesn't mean they are the same actual object: >>> a is b False >>> b is c True b and c are the same empty list object. But a and b are separate, different, empty list objects. Why the difference? Imagine you made a set of objects to represent some kind of numeric values, eg. vectors. Asking "A==B" means "is the value of the vector A, the same as the value of the vector B". But asking "A is B" means "is the object A the same object as B". >>>> [[]]*2 > [[], []] >>>> [[], []] == [[]]*2 > True Same effect. But try the 'is' operator, to see if they are actually the same instances of 'empty list': >>>> [[], []] is [[]]*2 > True Hope this helps ... its my first go at explaining this kind of stuff, so apologies if it isn't as clear as it could be! Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From bignose+hates-spam at benfinney.id.au Sun Aug 28 05:51:07 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sun, 28 Aug 2005 19:51:07 +1000 (EST) Subject: py to exe: suggestions? References: <1125217143.451511.25310@g43g2000cwa.googlegroups.com> Message-ID: chris patton wrote: > I need to convert a python file to an '.exe'. A Python program is executable only in the context of a Python interpreter. Python is a dynamic language; it can't be compiled to native machine code. > I've tried py2exe, and I don't like it because you have to include > that huge dll and libraries. That's the Python interpreter environment, and the standard Python library that is made available in the Python environment. Without them, your program isn't executable. What were you hoping for? -- \ "If trees could scream, would we be so cavalier about cutting | `\ them down? We might, if they screamed all the time, for no good | _o__) reason." -- Jack Handey | Ben Finney From thomasbartkus at comcast.net Thu Aug 25 18:26:14 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Thu, 25 Aug 2005 17:26:14 -0500 Subject: Embedding Python in other programs Message-ID: Name: lib64python2.4-devel Summary: The libraries and header files needed for Python development Description: The Python programming language's interpreter can be extended with dynamically loaded extensions and can be embedded in other programs. This package contains the header files and libraries needed to do these types of tasks. ------------------------------------------------------ *** The Python programming language's interpreter ... can be embedded in other programs. *** That's very intriguing! But I can't seem to locate much information about this. Can anyone direct me to greater enlightenment? Thomas Bartkus From nephish at xit.net Fri Aug 26 10:17:20 2005 From: nephish at xit.net (nephish at xit.net) Date: 26 Aug 2005 07:17:20 -0700 Subject: need a little help with time Message-ID: <1125065840.477157.43290@g47g2000cwa.googlegroups.com> Hey there. i have a time string (created with strftime) then read from a file, i am having some trouble understanding how to get the difference between times. i know i can structime(timestring) and get a time value, but i dont know how to manipulate it. basically, if i have string 2005-08-24 09:25:58 and another string 2005-08-24 09:28:58 how can i tell how many minutes, hours, seconds, days, months etc.. have passed between the first string and the second ? or, if there is a good tutorial on this kind of thing, please post a url. thanks shawn From cyril.bazin at gmail.com Thu Aug 11 17:47:28 2005 From: cyril.bazin at gmail.com (Cyril Bazin) Date: Thu, 11 Aug 2005 23:47:28 +0200 Subject: need help with python syntax In-Reply-To: <1123786609.621111.324390@g49g2000cwa.googlegroups.com> References: <1123786609.621111.324390@g49g2000cwa.googlegroups.com> Message-ID: I think bs = BeautifulSoup.BeautifulSoup( oFile) but I don't understand what you are doing... (I never used BeautifulSoup...) Maybe It is somthing like: import itertools for incident in itertools.chain(bs('tr', {'bgcolor' : '#eeeeee'}), bs('tr', {'bgcolor' : 'white'})): do_something() Look at some examples on the web or ask a precise question (what is your problem exactly?): http://www.petersblog.org/taxonomy/term/2 http://crummy.com/software/BeautifulSoup/documentation.html ... Cyril On 11 Aug 2005 11:56:49 -0700, yaffa wrote: > > dear python gurus, > > quick question on syntax. > > i have a line of code like this > > for incident in bs('tr', {'bgcolor' : '#eeeeee'}): > > > what i want it to do is look for 'bgcolor' : '#eeeeee' or 'bgcolor' : > 'white' and then do a whole bunch of stuff. > > i've tried this: > > for incident in bs('tr', {'bgcolor' : '#eeeeee'} or {'bgcolor' : > 'white'} ): but it only seems to pick up the stuff from the > {'bgcolor' : '#eeeeee'} > > > any ideas folks? > > thanks > > yaffa > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed Aug 17 07:55:56 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 17 Aug 2005 21:55:56 +1000 Subject: Making programs work together. In-Reply-To: <1124259853.264169.157750@g44g2000cwa.googlegroups.com> References: <1124256651.450266.90580@g47g2000cwa.googlegroups.com> <4302d48e.1666704914@news.oz.net> <1124259853.264169.157750@g44g2000cwa.googlegroups.com> Message-ID: <430325cc$1@news.eftel.com> ChuckDubya at gmail.com wrote: > Example: I'm driving a car in a game and I hit an oil slick so instead > of me having to lift off the throttle button on the keyboard, I want to > make a program to disengage the throttle as long as I'm on that oil > slick. Does that clear anything up? > Yes. From zxo102 at gmail.com Thu Aug 4 01:36:03 2005 From: zxo102 at gmail.com (zxo102) Date: 3 Aug 2005 22:36:03 -0700 Subject: Python-Excel: How to paste selected cells (range) to different location on the same sheet in Excel Message-ID: <1123133763.524077.205640@f14g2000cwb.googlegroups.com> Hi there, I need your help for python <--> excel. I want to paste selected cells (range) to different location on the same sheet in Excel through python. I have tried it for a while but could not figure it out. Here is my sample code: import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Visible=1 wb = xl.Workbooks.Add( ) sh=wb.Worksheets(1) sh.Cells(1,1).Value = "Hello World!" sh.Cells(3,3).Value = "Hello World!" sh.Range(sh.Cells(1,1),sh.Cells(3,3)).Select() sh.Range(sh.Cells(1,1),sh.Cells(3,3)).Copy() # sh.Range(sh.Cells(4,1),sh.Cells(6,3)).Paste() The last line of the code does not work. Thanks you very much. Ouyang From kristian.zoerhoff at gmail.com Tue Aug 30 14:03:20 2005 From: kristian.zoerhoff at gmail.com (Kristian Zoerhoff) Date: Tue, 30 Aug 2005 13:03:20 -0500 Subject: trouble with time --again In-Reply-To: <1125424469.858102.178260@f14g2000cwb.googlegroups.com> References: <1125423761.517155.162710@g44g2000cwa.googlegroups.com> <1125424469.858102.178260@f14g2000cwb.googlegroups.com> Message-ID: <3511dc7505083011033e210f6d@mail.gmail.com> On 30 Aug 2005 10:54:29 -0700, nephish at xit.net wrote: > > i feel like a complete idiot. Now don't go and do that. Mistakes happen. -- Kristian kristian.zoerhoff(AT)gmail.com zoerhoff(AT)freeshell.org From donn at u.washington.edu Wed Aug 24 15:01:21 2005 From: donn at u.washington.edu (Donn Cave) Date: Wed, 24 Aug 2005 12:01:21 -0700 Subject: pipes like perl References: Message-ID: In article , "max(01)*" wrote: > in perl i can do this: ... > but i do not know how to do it in python, because "if *command*:" gives > syntax error. > > moreover, if i use ... > it doesn't work, since "*do_something*" and *do_something_more* are > always executed (it seems like > > MYPIPE = os.popen("*some_system_command*", "r") > > does not raise any exception even if *some_system_command* does not > exist/work... Just to address this last point -- if you're running 2.4, you can get this through the subprocess module. With its popen equivalent, something like subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout will raise an exception if the command is not found. The command in this case would specified as an argv list, not a shell command. The basic problem is that you have to fork first, then exec, and by the time the forked interpreter finds out that the exec didn't work, its parent has gone on to do the I/O it's expecting. I think subprocess gets around that, on UNIX, with a trick involving an extra pipe, that would work only on UNIX. Donn Cave, donn at u.washington.edu From rkern at ucsd.edu Fri Aug 26 10:45:20 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 26 Aug 2005 07:45:20 -0700 Subject: MacPython 2.2 on Mac OS X 10.3.8 - configurePython error In-Reply-To: References: Message-ID: Paul Miller wrote: > Robert Kern wrote: >> MacPython 2.2 has been long abandoned. The >>official OS X binary for Python 2.4.1 can be found here: >> >>http://www.python.org/ftp/python/2.4.1/MacPython-OSX-2.4.1-1.dmg > > I realize that, but I have an application that is linked with MacPython > 2.2. I can't just drop 2.4 in. Is this an application that you've written? If so, then I realize that you can't just drop 2.4 in painlessly, but you really should consider upgrading your software to use a newer Python. No one is going to support MacPython 2.2. > He claims the only thing that has changed is his preferences were wiped > out. There must be some solution for what is probably a not too uncommon > problem. It *is* uncommon. Judging from the traffic on the Pythonmac-SIG, virtually no one is using MacPython 2.2 anymore. You can ask for help on there, but I don't think you'll fare any better. http://mail.python.org/mailman/listinfo/pythonmac-sig -- 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 billiejoex at fastwebnet.it Tue Aug 30 11:55:35 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Tue, 30 Aug 2005 17:55:35 +0200 Subject: py2exe can't compile this program Message-ID: Hi all. I tried to compile this little source with py2exe: http://pastebin.com/350143 ...but once I execute the program I encount this error: C:\src\dist>sniffer.exe Traceback (most recent call last): File "sniffer.py", line 24, in ? File "sniffer.py", line 18, in get_int LookupError: no codec search functions registered: can't find encoding Any idea? :-\ From pink at odahoda.de Mon Aug 1 17:10:59 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Mon, 01 Aug 2005 23:10:59 +0200 Subject: python SMTP server References: <1122759885.881136.186360@g47g2000cwa.googlegroups.com> Message-ID: Cliff Wells wrote: > On Mon, 2005-08-01 at 12:28 +0200, Benjamin Niemann wrote: >> Cliff Wells wrote: > >[snip] > >> > By using a local SMTP server to proxy, your app can >> > queue up a large amount of mail in a much shorter period. It won't >> > necessarily go out any faster, but at least your app won't be tied up >> > waiting for the mail to be accepted. So there is perhaps one useful >> > (beyond learning and fun) application for using a local SMTP server. >> >> It would be interesting what the intention of the OP is. I just stumpled >> upon a similar problem. The prog I'm currently working on has a function >> to report crashes back to me. Originally these reports where sent by mail >> - no problem on UNIX/Linux hosts where you can assume to have a working >> MDA on localhost. But what to do on Windows systems?!? Ask for a SMTP >> server during installation? Confusing as the program itself is totally >> unrelated to email. In this case you _could_ deliver the mail directly to >> my MX host... But instead of this I installed a small CGI on my website >> that sends the mails to me and gets the data via HTTP POST from my app. > > You can also use port redirection to bypass this sort of thing. Send on > port 10025 instead and direct your MTA to listen on both ports. This would still be problematic with company firewall that block everything but a handful of ports. Port 80 is still one of the safest bets. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From caleb1 at telkomsa.net Mon Aug 1 16:01:06 2005 From: caleb1 at telkomsa.net (Caleb Hattingh) Date: Mon, 01 Aug 2005 22:01:06 +0200 Subject: Is this Pythonic? References: Message-ID: Peter To my mind, this kind of setup (interface class, or abstact class) is more usually used in static languages to benefit polymorphism - but python is dynamically typed, so in which situations would this setup be useful in a python program? You see, I expected your post to say that it wouldn't even be necessary, but you didn't :) I have spent a little effort training myself not to bother setting up class hierarchies like this in python, due to the fact that I use Delphi a lot at work (I do pretty much the code below to let myself know when an inherited/abstract class method is being called in error). regards Caleb On Mon, 01 Aug 2005 18:52:02 +0200, Peter Hansen wrote: > phil hunt wrote: >> Suppose I'm writing an abstract superclass which will have some >> concrete subclasses. I want to signal in my code that the subclasses >> will implement certan methods. Is this a Pythonic way of doing what I >> have in mind: >> class Foo: # abstract superclass >> def bar(self): >> raise Exception, "Implemented by subclass" >> def baz(self): >> raise Exception, "Implemented by subclass" > > Change those to "raise NotImplementedError('blah')" instead and you'll > be taking the more idiomatic approach. > > -Peter From leftwing17 at gmail.com Wed Aug 31 15:52:57 2005 From: leftwing17 at gmail.com (Adam Endicott) Date: 31 Aug 2005 12:52:57 -0700 Subject: aggdraw for PIL In-Reply-To: References: <1125510410.873991.285330@g47g2000cwa.googlegroups.com> Message-ID: <1125517977.361709.264630@g44g2000cwa.googlegroups.com> You know, I tried doing it that way, and I must have done something wrong the first time because I was getting an error. It works now though, and it performs much better. Thanks! I'll keep an eye out for the new version, that kind of timeframe will be in plenty of time for the project I'm currently doing. From grante at visi.com Fri Aug 19 10:28:20 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 19 Aug 2005 14:28:20 -0000 Subject: global interpreter lock References: Message-ID: <11gbr44jegt399a@corp.supernews.com> On 2005-08-20, km wrote: > is true parallelism possible in python? No, not for some values of "true parallelism". > or atleast in the coming versions? Not that I'm aware of. > is global interpreter lock a bane in this context? In what context? -- Grant Edwards grante Yow! I think I'll do BOTH at if I can get RESIDUALS!! visi.com From lbolognini at gmail.com Fri Aug 19 04:23:07 2005 From: lbolognini at gmail.com (lbolognini at gmail.com) Date: 19 Aug 2005 01:23:07 -0700 Subject: python html In-Reply-To: References: Message-ID: <1124439787.386467.277020@g14g2000cwa.googlegroups.com> Steve Young wrote: > Hi, I am looking for something where I can go through > a html page and make change the url's for all the > links, images, href's, etc... easily. If anyone knows > of something, please let me know. Thanks. BeautifulSoup or PyMeld Lorenzo From __peter__ at web.de Mon Aug 22 06:20:06 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2005 12:20:06 +0200 Subject: regular expressions use References: <6uhOe.70629$2U1.3761846@news3.tin.it> Message-ID: max(01)* wrote: > would like to do some uri-decoding, which means to translate patterns > like "%2b/dhg-%3b %7E" into "+/dhg-; ~": in practice, if a sequence like > "%2b" is found, it should be translated into one character whose hex > ascii code is 2b. > > i did this: > > ... > import re > import sys > > modello = re.compile("%([0-9a-f][0-9a-f])", re.IGNORECASE) > > def funzione(corrispondenza): > return?chr(eval('0x'?+?corrispondenza.group(1))) You can specify the base for str to int conversion, e. g: return?chr(int(corrispondenza.group(1), 16)) And then there is also urllib.unquote() in the library. Peter From theller at python.net Mon Aug 22 02:36:17 2005 From: theller at python.net (Thomas Heller) Date: Mon, 22 Aug 2005 08:36:17 +0200 Subject: pythonXX.dll size: please split CJK codecs out References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <4308e632$0$31533$9b622d9e@news.freenet.de> Message-ID: <64tybhr2.fsf@python.net> "Martin v. L?wis" writes: > Ron Adam wrote: >> I would put the starting minimum boundary as: >> >> 1. "The minimum required to start the python interpreter with no >> additional required files." >> >> Currently python 2.4 (on windows) does not yet meet that guideline, so >> it seems some modules still need to be added while other modules, (I >> haven't checked which), are probably not needed to meet that guideline. > > I'm not sure, either, but I *think* python24 won't load any .pyd file > on interactive startup. That seems to be true. But it will need zlib.pyd as soon if you try to import from compressed zips. So, zlib can be thought as part of the modules required for bootstrap. Thomas From devlai at gmail.com Fri Aug 12 15:57:41 2005 From: devlai at gmail.com (Devan L) Date: 12 Aug 2005 12:57:41 -0700 Subject: Dictionary inheritance References: Message-ID: <1123876661.376716.141160@g44g2000cwa.googlegroups.com> Talin wrote: > I want to make a dictionary that acts like a class, in other words, > supports inheritance: If you attempt to find a key that isn't present, > it searches a "base" dictionary, which in turn searches its base, and so on. > > Now, I realize its fairly trivial to code something like this using > UserDict, but given that classes and modules already have this behavior, > is there some built-in type that already does this? > > (This is for doing nested symbol tables and such.) > > --- > > Also, on a completely different subject: Has there been much discussion > about extending the use of the 'is' keyword to do type comparisons a la > C# (e.g. "if x is list:") ? > > -- Talin Dictionaries aren't classes? I wasn't aware of that. Anyways, what you're looking for, I think is a class that emulates a dictionary. Probably you should just have some attribute that references a bigger dictionary. bigger_dict = {'foo':1,'baz':2,'bar':3,'foobar':4,'foobaz':5,'foobazbar':6} smaller_dict = {'spam':1,'ham':2,'bacon':3,'eggs':4} smaller_dict.fallback = bigger_dict and then the __getitem__ method might look something like def __getitem__(self, key): if self.has_key(key): return self[key] else: return self.fallback[key] From trentm at ActiveState.com Thu Aug 25 14:37:58 2005 From: trentm at ActiveState.com (Trent Mick) Date: Thu, 25 Aug 2005 11:37:58 -0700 Subject: Unix diff command under Window. In-Reply-To: <0f8Pe.9409$FA3.6140@news-server.bigpond.net.au> References: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> <1x4j4c2o.fsf@python.net> <0f8Pe.9409$FA3.6140@news-server.bigpond.net.au> Message-ID: <20050825183758.GA23904@ActiveState.com> [Neil Hodgson wrote] > Thomas Heller: > > > Yes. There's a script in your Python distribution: > > Tools/scripts/diff.py > > > > See also the docs for the 'difflib' standard library module. > > Is the opposite code, a Python equivalent to 'patch' available? I > have endless trouble receiving patch files that assume one of Windows or > Unix (in terms of path names and line end characters) which then fail to > apply on the other platform. I would like to have a version I could hack on. So would I! I also have problems with the available patch.exe binaries hanging or crashing occassionally on Windows. Trent -- Trent Mick TrentM at ActiveState.com From randy at psg.com Wed Aug 31 17:19:34 2005 From: randy at psg.com (Randy Bush) Date: Wed, 31 Aug 2005 11:19:34 -1000 Subject: Arguement error References: <6829832e050831133030a012f9@mail.gmail.com> Message-ID: <17174.7910.305822.397770@roam.psg.com> > I am wondering why I am getting this error. when I try to run a script. > TypeError: translate() takes at most 3 arguments (10 given) > but the thing is the method translate actually accepts 10 arguements. without code, how is anyone to know? From lavigne.eric at gmail.com Sun Aug 21 14:49:36 2005 From: lavigne.eric at gmail.com (Eric Lavigne) Date: 21 Aug 2005 11:49:36 -0700 Subject: last line chopped from input file In-Reply-To: References: <1124603622.204380.256560@g47g2000cwa.googlegroups.com> <1124646074.295575.292490@g47g2000cwa.googlegroups.com> Message-ID: <1124650176.804832.150260@g44g2000cwa.googlegroups.com> > > import os > > os.command("debug\\curve-fit output.txt") > > > > I imagine thats was a typo for: > > >>> os.system("debug\\curve-fit output.txt") > > Alan That fixes it. Thanks. From steve at holdenweb.com Sun Aug 28 16:58:30 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 28 Aug 2005 16:58:30 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: <%_oQe.72$WJ3.55@newssvr21.news.prodigy.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> <7xirxri3x5.fsf@ru <%_oQe.72$WJ3.55@newssvr21.news.prodigy.com> Message-ID: Bryan Olson wrote: > Steve Holden wrote: > > Paul Rubin wrote: > > We are arguing about trivialities here. Let's stop before it gets > > interesting :-) > > Some of us are looking beyond the trivia of what string.find() > should return, at an unfortunate interaction of Python features, > brought on by the special-casing of negative indexes. The wart > bites novice or imperfect Python programmers in simple cases > such as string.find(), or when their subscripts accidentally > fall off the low end. It bites programmers who want to fully > implement Python slicing, because of the double-and- > contradictory- interpretation of -1, as both an exclusive ending > bound and the index of the last element. It bites documentation > authors who naturally think of the non-negative subscript as > *the* index of a sequence item. > > Sure. I wrote two days ago: > We might agree, before further discussion, that this isn't the most > elegant part of Python's design, and it's down to history that this tiny > little wart remains. While I agree it's a trap for the unwary I still don't regard it as a major wart. But I'm all in favor of discussions to make 3.0 a better language. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From zarnovican at gmail.com Mon Aug 15 12:49:50 2005 From: zarnovican at gmail.com (BranoZ) Date: 15 Aug 2005 09:49:50 -0700 Subject: Using for in one-liner In-Reply-To: <3mbu82F15h18oU1@individual.net> References: <3mbu82F15h18oU1@individual.net> Message-ID: <1124124590.563497.241560@g43g2000cwa.googlegroups.com> Paul Watson wrote: > Can a for loop be used in a one-liner? What am I missing? > > $ python -c "import sys;for i in range(5): print i," > File "", line 1 > import sys;for i in range(5): print i, > ^ > SyntaxError: invalid syntax This was tricky.. python -c $'import sys;\nfor i in range(5): print i,' Separate statements with and enclose it in $'string'. BranoZ From ironfroggy at gmail.com Wed Aug 10 12:10:27 2005 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 10 Aug 2005 12:10:27 -0400 Subject: how to write a line in a text file In-Reply-To: References: <42E5B0F0.6020206@REMOVEMEcyber.com.au> <42E5ED91.10402@REMOVEMEcyber.com.au> Message-ID: <76fd5acf05081009107f1dbd47@mail.gmail.com> On 7/31/05, James Dennett wrote: > Peter Hansen wrote: > > > Steven D'Aprano wrote: > > > > Given that ZODB and PySQLite are simply Python extension modules, which > > get bundled by your builder tool and are therefore installed > > transparently along with your app by your installer, this is a total > > non-issue at least with those packages. > > > > After all, it's not 1970 any more. ;-) > > Indeed; since 1970 we learned to prefer straightforward > file formats where possible, reserving use of databases > for structured data where the extra costs are justified. > > Sometime maybe databases will get better to the point > that we don't need to distinguish so much between them > and filesystems, but we're not there yet. Managing raw > files, carefully, still has a place. > > -- James Filesystems are a horrible way to organize information, and even worse at structuring it. The mentality that there are any benefits of low-overhead the outweigh the benefits of minimal database layers, such as ZODB, BSD DB, and SQLite, is a large part of the reason we are still stuck with such a mess. Those "extra costs" are so minimal, that you wouldn't even notice them, if you hadn't convinced yourself of their presense before performing or researching any realy benchmarks. A simple RDBMS can be much easier to work with than any flat file format, will likely be far faster in processing the data, and has the benefit of years of coding making the code that actually reads and writes your data as fast and stable as possible. From cam.ac.uk at mh391.invalid Sun Aug 21 05:01:52 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sun, 21 Aug 2005 10:01:52 +0100 Subject: pythonXX.dll size: please split CJK codecs out In-Reply-To: <8xWNe.24050$HM1.696102@twister1.libero.it> References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <8xWNe.24050$HM1.696102@twister1.libero.it> Message-ID: Giovanni Bajo wrote: > > FWIW, this just highlights how ineffecient your build system is. Everything you > currently do by hand could be automated, including MSI generation. I'm sure Martin would be happy to consider a patch to make the build system more efficient. :) > I'm willing to write up such a PEP, but it's hard to devise an universal > policy. This is the reason that a PEP is needed before there are changes. -- Michael Hoffman From max at alcyone.com Mon Aug 1 17:07:46 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Aug 2005 14:07:46 -0700 Subject: Is this Pythonic? In-Reply-To: References: Message-ID: <74SdnekYvd-_EnPfRVn-2A@speakeasy.net> phil hunt wrote: > Suppose I'm writing an abstract superclass which will have some > concrete subclasses. I want to signal in my code that the subclasses > will implement certan methods. Is this a Pythonic way of doing what > I have in mind: > > class Foo: # abstract superclass > def bar(self): > raise Exception, "Implemented by subclass" > def baz(self): > raise Exception, "Implemented by subclass" > > class Concrete(Foo): > def bar(self): > #...actual implemtation... > def baz(self): > #...actual implemtation... Yes, but raise NotImplementedError instead of Exception. Another trick you can use is to prevent people from instantiating the abstract class: class Foo: def __init__(self): if self.__class__ is Foo: raise NotImplementedError ... def bar(self): raise NotImplementedError -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Everything's gonna be all right / Everything's gonna be okay -- Sweetbox From mlh at selje.idi.ntnu.no Thu Aug 11 15:58:12 2005 From: mlh at selje.idi.ntnu.no (Magnus Lie Hetland) Date: Thu, 11 Aug 2005 19:58:12 +0000 (UTC) Subject: Python Challenge on BBC Message-ID: Just saw this on the BBC World program Click Online: http://bbcworld.com/content/template_clickonline.asp?pageid=665&co_pageid=6 I must say, I think this is the first time I've heard Python discussed on TV at all... Cool :) (Now maybe I'll have to finish the rest of those P.C. levels... ;) -- Magnus Lie Hetland Fall seven times, stand up eight http://hetland.org [Japanese proverb] From steven.bethard at gmail.com Thu Aug 11 16:42:53 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 11 Aug 2005 14:42:53 -0600 Subject: Why does __init__ not get called? In-Reply-To: <1123702730.955133.105950@g49g2000cwa.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> <1123618110.763724.304990@g44g2000cwa.googlegroups.com> <1123702730.955133.105950@g49g2000cwa.googlegroups.com> Message-ID: Rob Conner wrote: > By chance... does anyone know, if I wrote a class, and just wanted to > override __new__ just for the fun of it. What would __new__ look like > so that it behaves exactly the same as it does any other time. Simple: class C(object): def __new__(cls, *args, **kwargs): return super(C, cls).__new__(cls, *args, **kwargs) Basically, you're calling object's __new__ method, which in CPython does something like mallocing the appropriate amount of memory, setting the __class__ attribute of the object, etc. Note that __new__() doesn't call __init__(). Both __new__() and __init__() are called individually by the metaclass. For new-style classes, "type" is the metaclass, and it's __call__() method looks something like: def __call__(cls, *args, **kwargs): obj = cls.__new__() if not isinstance(obj.__class__, cls): return obj obj.__class__.__init__(obj, *args, **kwargs) return obj (But see Objects/typeobject.c:409 for the full gory details.) STeVe From gregpinero at gmail.com Fri Aug 26 12:37:52 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 26 Aug 2005 12:37:52 -0400 Subject: Embedding Python in other programs In-Reply-To: <312cfe2b050826084036db598f@mail.gmail.com> References: <312cfe2b050826084036db598f@mail.gmail.com> Message-ID: <312cfe2b05082609371c4e453c@mail.gmail.com> Hey guys, This question inpsired me to try this in VB6. I did a search and copied what I saw at http://forums.devshed.com/t158692/s.html However I'm running into the same problem they are. When I try to run: res = Python.PyRun_SimpleString("5+7") I get the error message: Bad DLL calling convention (Error 49) Which VB help describes as: Arguments passed to a dynamic-link library(DLL) must exactly match those expected by the routine. Calling conventions deal with number, type, and order of arguments. This error has the following causes and solutions: - Your program is calling a routine in a DLL that's being passed the wrong type of arguments. Make sure all argument types agree with those specified in the declaration of the routine you are calling. - Your program is calling a routine in a DLL that's being passed the wrong number of arguments. Make sure you are passing the same number of arguments indicated in the declaration of the routine you are calling. - Your program is calling a routine in a DLL, but isn't using the StdCall calling convention. If the DLL routine expects arguments by value, then make sure *ByVal* is specified for those arguments in the declaration for the routine. - Your *Declare* statement for a Windows DLL includes *CDecl*. Any ideas? -Greg On 8/26/05, Gregory Pi?ero wrote: > > How do I get it into VB6? Now that's an answer that would save my life > many times over. > > -Greg > > On 8/26/05, Alessandro Bottoni wrote: > > > > Thomas Bartkus wrote: > > > > > Name: lib64python2.4-devel > > > Summary: The libraries and header files needed for Python development > > > > > > Description: The Python programming language's interpreter can be > > extended > > > with dynamically loaded extensions and can be embedded in other > > programs. > > > This package contains the header files and libraries needed to do > > these > > > types of tasks. > > > ------------------------------------------------------ > > > > > > > > > *** The Python programming language's interpreter ... can be embedded > > in > > > other programs. *** > > > > > > That's very intriguing! > > > But I can't seem to locate much information about this. > > > > > > Can anyone direct me to greater enlightenment? > > > Thomas Bartkus > > > > There is a section of the official documentation devoted to extending > > and > > embedding python: > > > > http://docs.python.org/ext/ext.html > > > > There are a few articles on this topics on the web, as well. Search > > "embedding python" with Google. > > ----------------------------------- > > Alessandro Bottoni > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com ) -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon.brunning at gmail.com Tue Aug 16 10:30:21 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Tue, 16 Aug 2005 15:30:21 +0100 Subject: [Python-Dev] implementation of copy standard lib In-Reply-To: <1124059680.11612.9.camel@localhost.localdomain> References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: <8c7f10c605081607305068cad6@mail.gmail.com> On 8/14/05, Martijn Brouwer wrote: > After profiling a small python script I found that approximately 50% of > the runtime of my script was consumed by one line: "import copy". > Another 15% was the startup of the interpreter, but that is OK for an > interpreted language. The copy library is used by another library I am > using for my scripts. Importing copy takes 5-10 times more time that > import os, string and re together! > I noticed that this lib is implemented in python, not in C. As I can > imagine that *a lot* of libs/scripts use the copy library, I think it > worthwhile to implement this lib in C. > > What are your opinions? I think that copy is very rarely used. I don't think I've ever imported it. Or is it just me? -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From eels at nikocity.de Tue Aug 23 04:34:12 2005 From: eels at nikocity.de (eels) Date: 23 Aug 2005 01:34:12 -0700 Subject: check whether directory is readable Message-ID: <1124786052.372768.156730@o13g2000cwo.googlegroups.com> Hello, how can I check whether a directory is readable or not. Are there differences between unix and windows? Thank you for your hints, Eels From nothingcanfulfill at gmail.com Fri Aug 19 00:32:58 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 18 Aug 2005 21:32:58 -0700 Subject: time.clock() problem under linux (precision=0.01s) In-Reply-To: References: <1124363238.556661.164270@g14g2000cwa.googlegroups.com> Message-ID: <1124425978.851616.134160@o13g2000cwo.googlegroups.com> Woa, if you don't mind my asking, why do you do a time-cache on your messages? From vincent at visualtrans.de Tue Aug 2 16:07:19 2005 From: vincent at visualtrans.de (vincent wehren) Date: Tue, 2 Aug 2005 22:07:19 +0200 Subject: py2exe windows apps path question References: <11ev0tcg9n2ndd@corp.supernews.com> Message-ID: "Gregory Pi?ero" schrieb im Newsbeitrag news:mailman.2635.1123008925.10512.python-list at python.org... > If you need something that works both on a frozen app as well as an > (unfrozen) python > script, you'd be better off using something like: > >> def getAppPrefix(): >> """Return the location the app is running from >> """ >> isFrozen = False >> try: >> isFrozen = sys.frozen >> except AttributeError: >> pass >> if isFrozen: >> appPrefix = os.path.split(sys.executable)[0] >> else: >> appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0] >> return appPrefix >> > >Vincent, > >This sounds interesting. A few questions for you: >Why don't I see sys.frozen in interpreter? >Does it only appear when it is frozen? Yes. The sys.frozen attribute is added by py2exe. >What do you mean by frozen, how does python know? Python doesn't know - it is just told so ;) >What does sys.executable do? sys.executable gives you the path of the executing binary. Normally, this will be something like "c:\\python24\\python.exe" - since the interpreter is the executing binary. Once you have frozen your python application, it will return the path to your app. -- Vincent > >Thanks, > >Greg From ex at pe.rl Sat Aug 13 06:17:55 2005 From: ex at pe.rl (Novice Experl) Date: Sat, 13 Aug 2005 03:17:55 -0700 Subject: Parallel port programming on windows XP / 2000 Message-ID: I'm still stuck... my script is finished and works just fine on win98 using pyparallel, but I still haven't seen any sample code to do access the port in XP / 2000. If I don't make progress soon, I'll need to find a solution in another language, which I don't really want to do. --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- From apardon at forel.vub.ac.be Mon Aug 22 09:16:26 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 22 Aug 2005 13:16:26 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-22, Steve Holden schreef : > Antoon Pardon wrote: >> Op 2005-08-19, Donn Cave schreef : >> >>>In article , >>> Antoon Pardon wrote: >>>... >>> >>>>But '', {}, [] and () are not nothing. They are empty containers. >>> >>>Oh come on, "empty" is all about nothing. >> >> >> No it is not. There are situation where False or None should >> be treated differently from an empty sequence. >> >> Empty can mean, "nothing yet" which should be treated >> differently from "nothomg more". >> >> >>>>And 0 is not nothing either it is a number. Suppose I have >>>>a variable that is either None if I'm not registered and a >>>>registration number if I am. In this case 0 should be treated >>>>as any other number. >>>> >>>>Such possibilities, make me shy away from just using 'nothing' >>>>as false and writing out my conditionals more explicitly. >>> >>>Sure, if your function's type is "None | int", then certainly >>>you must explicitly check for None. >> >> >> The fact is that python doesn't know which type a function is. >> So why does python guess that zero should be treated as false. >> > Python doesn't guess. There are a range of values that will be treated, > in a Boolean context (how perlish) as equivalent to False. Yes it does. Python has no way to know what would be the most usefull Boolean interpretation of these values in a particular context. That it picks one out is guessing. Lisp imterprets an empty list as false, scheme interprets it as true. So both seem usable interpretations. > If your > function is capable of validly returning any of these values then your > calls must be prepared to discriminate between (say) zero and False or > None. If not, the calling experession in the "if" can be simpler. But that doesn't seem to be accepted practice in this newsgroup. Whenever someone shows code that does something like: if var != []: ... or if var is True: Someone else is almost bound to react that it is better to write this as: if var: IMO it is the fact that python accepts almost anything as true that may make it necessary to use "var is True" >>>That is not the case with >>>fileobject read(), nor with many functions in Python that >>>reasonably and ideally return a value of a type that may >>>meaningfully test false. In this case, comparison (==) with >>>the false value ('') is silly. >> >> >> No is is not. The comparison with the specific false value >> makes it easier for the reader of the code to find out what >> to expect. I also find the use of '' as false in this context >> wrong. A read can be used on all kind of objects including >> a network connection. Returning '' on a network read would >> be IMO the most natural answer to say, the network connection >> is still open but no data is available for the moment. '' here >> would mean "nothing yet" while '' is now made into "nothing more" >> > Yes, but you are restricting the programmer's range of expression if you > promote this as a general rule. Sometimes it's important to discriminate > between "", (), [] and None, sometimes there is no possiblity that > confusion will arise. > > When there's no possibility of confusion you arae just picking nits > (which I know your sense of intellectual tidiness encourages you to do ;-). IMO there is more possibility of confusion then you think off. Sure if you restrict your attention to one specific part of code, you can conclude that there is no possibility of confusion whether '' is used as false or not. But maybe sometime in the future you would want that piece of code to work with other pieces of code where it is not usefull to have '' interpreted as false in a Boolean context. Now suddenly whether '' is false or not depends on where it is coming from and your code with no possibilty of confusion is part of a project where it is contributing to the confusion. -- Antoon Pardon From newsgroups at jhrothjr.com Sat Aug 6 19:34:42 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 6 Aug 2005 17:34:42 -0600 Subject: Generalised String Coercion References: <20050806102342.GA11309@mems-exchange.org> Message-ID: <11fai8o4g1qs25f@news.supernews.com> "Terry Reedy" wrote in message news:mailman.2787.1123360927.10512.python-list at python.org... >> PEP: 349 >> Title: Generalised String Coercion > ... >> Rationale >> Python has had a Unicode string type for some time now but use of >> it is not yet widespread. There is a large amount of Python code >> that assumes that string data is represented as str instances. >> The long term plan for Python is to phase out the str type and use >> unicode for all string data. > > This PEP strikes me as premature, as putting the toy wagon before the > horse, since it is premised on a major change to Python, possibly the most > disruptive and controversial ever, being a done deal. However there is, > as far as I could find no PEP on Making Strings be Unicode, let alone a > discussed, debated, and finalized PEP on the subject. PEP 3000, Core Language, Bullet Point 3: Make all strings be Unicode, and have a separate bytes() type. John Roth > Terry J. Reedy From onurb at xiludom.gro Thu Aug 11 05:28:54 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 11 Aug 2005 11:28:54 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <42fb1a59$0$32637$626a14ce@news.free.fr> Neil Benn wrote: (snip) >> > Suppose you have a logistics tracking system available on every install > in your company - there are 55 installs throughout the company. You > wish to push through a patch because of a problem. If you have one > class per file you can push that class through onto the client install. > However, if you have 15 different classes in one file - you will need to > drop all 15 classes through, I don't see much difference, this is just one file to replace anyway... > thereby increasing the likelihood of > accidently pushing a bug onto the install. Why ? You fixed a bug in one place in the file, ok ? So why would this impact whatever else lives in that file ? And you did test your fix before deploying, did you ? I just don't get your point. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From rebound1618 at yahoo.com Sat Aug 6 18:53:33 2005 From: rebound1618 at yahoo.com (Jerry He) Date: Sat, 6 Aug 2005 15:53:33 -0700 (PDT) Subject: SWIG again Message-ID: <20050806225333.26874.qmail@web51503.mail.yahoo.com> Robert Kern >Write a distutils setup.py script to do all of the >compiling and linking. Ok, I wrote the following distutils setup.py script from distutils.core import setup, Extension setup (name = 'example', version = '2.4', ext_modules = [Extension('example', \ ['example.c', 'example_wrap.c'])] ) I put it in the same directory as the extension files and I ran from the command line python setup.py install, and nothing happened... Someone help me!! -Jerry ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From bokr at oz.net Thu Aug 18 21:21:59 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 19 Aug 2005 01:21:59 GMT Subject: Really virtual properties References: <87slx7c4g5.fsf@wilson.rwth-aachen.de> Message-ID: <43051e39.1816635133@news.oz.net> On Thu, 18 Aug 2005 23:36:58 +0200, Torsten Bronger wrote: >Hall??chen! > >When I use properties in new style classes, I usually pass get/set >methods to property(), like this: > > x = property(get_x) > >If I overwrite get_x in a derived class, any access to x still calls >the base get_x() method. Is there a way to get the child's get_x() >method called instead? > >(I found the possibility of using an intermediate method _get_x >which calls get_x but that's ugly.) > I think this idea of overriding a property access function is ugly in any case, but you could do something like this custom descriptor (not tested beyond what you see here): >>> class RVP(object): ... def __init__(self, gettername): ... self.gettername = gettername ... def __get__(self, inst, cls=None): ... if inst is None: return self ... return getattr(inst, self.gettername)() ... >>> class Base(object): ... def get_x(self): return 'Base get_x' ... x = RVP('get_x') ... >>> class Derv(Base): ... def get_x(self): return 'Derv get_x' ... >>> b = Base() >>> d = Derv() >>> b.x 'Base get_x' >>> d.x 'Derv get_x' But why not override the property x in the derived subclass instead, with another property x instead of the above very questionable trick? I.e., >>> class Base(object): ... x = property(lambda self: 'Base get_x') ... >>> class Derv(Base): ... x = property(lambda self: 'Derv get_x') ... >>> b = Base() >>> d = Derv() >>> b.x 'Base get_x' >>> d.x 'Derv get_x' Regards, Bengt Richter From renzoPUNTOgiust at email.it Thu Aug 11 11:40:43 2005 From: renzoPUNTOgiust at email.it (Renzo) Date: Thu, 11 Aug 2005 17:40:43 +0200 Subject: zipfile library - problem.. In-Reply-To: References: Message-ID: Renzo ha scritto: I've seen that the error is a known bug: "zipfile still has 2GB boundary bug" so I've used the module TarFile instead ZipFile, and now the script works perfectly. Thanks to Deelan and Manlio Perillo (i.c.l.p.) Renzo From renting at astron.nl Mon Aug 8 04:10:42 2005 From: renting at astron.nl (Adriaan Renting) Date: Mon, 08 Aug 2005 10:10:42 +0200 Subject: Point and click GUI builder for Python Message-ID: Use Eric3 with QtDesigner. Works like a charm. Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ >>> Madhusudan Singh 08/06/05 5:39 AM >>> Is there such a thing for python ? Like Qt Designer for instance ? -- http://mail.python.org/mailman/listinfo/python-list From robiweb90 at liamg.com.invalid Thu Aug 18 07:15:01 2005 From: robiweb90 at liamg.com.invalid (Micetto Nero) Date: Thu, 18 Aug 2005 11:15:01 GMT Subject: Python for Webscripting (like PHP) In-Reply-To: References: Message-ID: Florian Lindner ha scritto: > Hello, > I've been using Python a lot for scripting (mainly scripts for server > administration / DB access). All these scripts were shell based. > > Now I'm considering using Python (with mod_python on Apache 2) for a web > project, just how I've used PHP in some smaller Projects before ( print "foo" ?>).. > > How suitable is Python for these kind of projects? What do think? Does the > stdlib offers all basic functions for this kind of requirements? > You can use the Python Server Pages, that are analogous to ASP, PHP and JSP. -- robiweb90 [at] gmail [dot] com "Nessuno pu? fabbricare una macchina tanto intelligente che possa essere usata da uno sciocco" - Confucio From fredrik at pythonware.com Mon Aug 29 10:32:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Aug 2005 16:32:10 +0200 Subject: python image thumbnail generator? References: <7x8xymby4w.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote >> (1) Can this be done with python? If so, what module do I need to look >> up? > > You could do it with PIL, or run jpegtran in an external process. > jpegtran may be easier. eh? are you sure you know what jpegtran does? JPEGTRAN(1) JPEGTRAN(1) NAME jpegtran - lossless transformation of JPEG files SYNOPSIS jpegtran [ options ] [ filename ] DESCRIPTION jpegtran performs various useful transformations of JPEG files. It can translate the coded representation from one variant of JPEG to another, for example from baseline JPEG to progressive JPEG or vice versa. It can also perform some rearrangements of the image data, for example turning an image from landscape to portrait format by rotation. jpegtran works by rearranging the compressed data (DCT coefficients), without ever fully decoding the image /.../ From steve at holdenweb.com Tue Aug 30 13:41:54 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Aug 2005 12:41:54 -0500 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. In-Reply-To: References: Message-ID: Alan Kennedy wrote: > Hi All, > > If there any contributors of SpamBayes reading, Congratulations! To which I add mine, even though I normally try to avoid "me too" posts. The software is a great achievement, and deserves popular success. > [...] > The only problem was they listed the "manufacturer" of the software as > SourceForge, so the product was known as "SourceForge SpamBayes". You > guys need to come up a team/manufacturer name. (But there is a > screenshot of the software in the review, and the "Python Powered" logo > is right there for all to see). > While it may not adequately credit the implementation language, a Google search for "sourceforge spambayes" results in the first hit being linked as """SpamBayes: Bayesian anti-spam classifier written in Python.""". The web page to which this link points unfortunately doesn't reapeat the Python reference in the page body. But they only miss the Python reference if they feel lucky and don't look at the browser title bar! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From cipherpunk at gmail.com Thu Aug 25 18:01:58 2005 From: cipherpunk at gmail.com (cipherpunk at gmail.com) Date: 25 Aug 2005 15:01:58 -0700 Subject: New Arrival to Python In-Reply-To: <1BkPe.304848$5V4.169335@pd7tw3no> References: <1BkPe.304848$5V4.169335@pd7tw3no> Message-ID: <1125007318.618031.173700@g44g2000cwa.googlegroups.com> 1. Whichever one works best for you, of course. :) There are lots of editors and IDEs out there. I find myself coming back to Emacs and jEdit the most, but there are a sizable number of vi partisans (benighted heathens tho they be) and an increasing number of Eclipse, Wing and Komodo partisans. Having tried all the free ones I could get my mitts on... well, Emacs and jEdit serve my needs just fine. Your mileage may vary significantly. 2-5 are all either IDE opinion questions, which I'll duck, or specific technologies I don't use, which I'll duck. Resuming with 6... _Core Python Programming_ is a reasonable read for a beginner. I prefer Mark Lutz's _Programming Python_ 2nd Ed, though. _Learning Python_ is also a good choice, but only for real beginners to programming--if you already know a programming language, _Programming Python_ is the better choice. I use Beazley's _Python Essential Reference_ about once every couple of days. Surprisingly, I use it more than _Python in a Nutshell_, but that may be due more to the fact _PER_ is usually within closer reach. They're both good references, with _PiaN_ being more heavyweight with better coverage. The _Python Cookbook_ is a great way to expand your knowledge of Python and discover the weird and cool stuff you can do with it. From python at hope.cz Wed Aug 3 03:58:26 2005 From: python at hope.cz (Lad) Date: 3 Aug 2005 00:58:26 -0700 Subject: Administrative prohibition error when sending email Message-ID: <1123055906.120638.257680@g47g2000cwa.googlegroups.com> I use a new webhosting provider and I can not send an email from my script. This is the script that I use to test the connection ####################### import smtplib,poplib, #I first login to my POP3 account M=poplib.POP3('www.mywebh.com') M.user('MYWeb) M.pass_('12345') print M.pass_ #check if you login successfully #next send a message fromaddr = "info at mywebh.com" toaddrs = "objednavky at sdeznam.cz" msg="This is a test" server = smtplib.SMTP('www.ebayworldstuff.com:25') server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) server.quit() ######################### It ends with SMTP error 550: Administrative prohibition Where can be a problem? Lad. From axel at white-eagle.invalid.uk Sat Aug 27 06:40:39 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Sat, 27 Aug 2005 10:40:39 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: In comp.lang.perl.misc John Bokma wrote: > Chris Head wrote: >> What advantages would those be (other than access from 'net cafes, but >> see below)? > And workplaces. Some people have more then one computer in the house. My > partner can check her email when I had her over the computer. When I > want to check my email when she is using it, I have to change the > session, fire up Thunderbird (which eats away 20M), and change the > session back. Not a Windows solution, but I find the 'screen' utility invaluable as I can have my email, news, and an editor open in different screens and then when I need to move to a different machine, I can simply detach and reattach screen without disturbing anything that might be running. Axel From john at castleamber.com Fri Aug 26 08:49:00 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 12:49:00 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> <3n8di6Fbhg7U2@individual.net> Message-ID: Ulrich Hobelmann wrote: > John Bokma wrote: >> Ulrich Hobelmann wrote: >> >>> What I hate about most are the sites that don't even *mention* that >>> they want cookies. Often I have to wonder, reinput input fields etc. >>> and then after ten minutes trying *bang*, the idea, maybe to allow >>> cookies for that site. >> >> So your browser doesn't warn you? > > About what? That the site wants to set a cookie? Lynx does that. > I have cookies off, with explicit exception for sites where > I want cookies. When the crappy website doesn't bother to MENTION that > it wants cookies, i.e. give me an error page, how am I to know that it > needs cookies? Do I want EVERY website to ask me "do you allow XY to > set a cookie?" NO! So what do you want? An error page for every site that wants to set a cookie? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From rkern at ucsd.edu Wed Aug 31 22:16:34 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 31 Aug 2005 19:16:34 -0700 Subject: OpenSource documentation problems In-Reply-To: <43166301.9060401@holdenweb.com> References: <43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net> <200508312026.04152.hancock@anansispaceworks.com> <43166301.9060401@holdenweb.com> Message-ID: Steve Holden wrote: > Terry Hancock wrote: >>Perhaps this just reduces to "there ought to be a wiki"? > > Well, perhaps the Wiki at http://wiki.python.org/moin/ should also be > better-publicized, then? Or perhaps more to the point, that http://pydoc.amk.ca/frame.html should be better-publicized. -- 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 mdelliot at gmail.com Fri Aug 12 00:23:16 2005 From: mdelliot at gmail.com (mdelliot at gmail.com) Date: 11 Aug 2005 21:23:16 -0700 Subject: Pre-PEP Proposal: Codetags References: <42FAF489.3010306@v.loewis.de> <42fb9f3b.1194361460@news.oz.net> Message-ID: <1123820596.598213.224580@o13g2000cwo.googlegroups.com> Wow, thanks for all the quick responses! Martin wrote: > the PEP author is typically expected to implement the proposed > functionality (in many cases, having a draft implementation is > prerequisite to accepting it). Fuzzyman wrote: > ...you could take your proposal forward by developing a set of tools > (e.g. documentation tools) that use your proposal. That way people > have a working implementation to use. Yes, I'm working on that and should have some tools reasonably functional within the next few months. I didn't want to commit a lot of time to writing tools if no one showed interested in the proposed conventions. Since no one is flaming the idea yet, I will get a move-on. The five example tools (that have come to mind so far) which I mentioned in the pre-pep were: * Document Generator (glossary, roadmap, manpages, bug lists, etc.) * Codetag History (useful for estimating, autopsy, etc.) * Code Statistics (a project Health-O-Meter) * Codetag Lint (aid in fixing almost-Codetags) * Story Manager/Browser (graphical viewer for various potential purposes) I'd love to hear any other ideas. Aahz and Terry wrote: > it's also true that there are plenty of informational PEPs... > ...It is similar in this way and complementary to reStructuredText > Docstring Format... Right, that's why I thought the PEP process was appropriate for this, like it was for restructuredtext. This of course is much smaller scale. I just want the proposal to live somewhere where I can get some feedback. I haven't seen much in the way of "+/-" yet, but that's fine since Codetags are not implemented/in use yet. amk wrote: > If such things are deemed off-topic for PEPs, then I think we should > have a separate set of documents for this (perhaps the suggested > PEEPS: Python Environment Enhancement Proposals). Sounds great. Make it a PEEP! I couldn't find anything official about PEEPs yet :-) I did create a link to PEEPs from the Front Page wiki. Terry wrote: > The OP might also look for codetag usage in Python source (I know of > XXX) Great idea. I tried this some months ago and this was one of the things that justified the idea. For some cursory stats: $ csrcs=$(find ~/archive/Python-2.4.1 -name *.c) $ for tag in XXX FIXME TODO BUG HACK IDEA NOTE RFE; do > echo -n "$tag: "; grep $tag $csrcs |wc -l > done XXX: 376 FIXME: 11 TODO: 12 BUG: 109 HACK: 0 IDEA: 0 NOTE: 32 RFE: 0 $ $ pysrcs=$(find /usr/lib/python2.3/ -maxdepth 2 -name '*.py') $ for tag in XXX FIXME TODO BUG HACK IDEA NOTE RFE; do > echo -n "$tag: "; grep $tag $pysrcs |wc -l > done XXX: 457 FIXME: 10 TODO: 57 BUG: 149 HACK: 0 IDEA: 0 NOTE: 50 RFE: 0 So I guess I'll now ask for ongoing feedback on the PEEP wiki site. I'm happy to wait for that feedback while the toolsmithing gets underway. Maybe a PEEP process discussion is warranted for another c.l.py thread. -- Micah Elliott From rkern at ucsd.edu Mon Aug 29 16:36:57 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 29 Aug 2005 13:36:57 -0700 Subject: suggestion for Python graphing package, please In-Reply-To: References: Message-ID: Stewart Midwinter wrote: > I need a graphing library that I can access from within a Tkinter > application running on Windows. http://matplotlib.sourceforge.net -- 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 jepler at unpythonic.net Mon Aug 8 07:51:50 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 8 Aug 2005 06:51:50 -0500 Subject: zipped socket In-Reply-To: <1123474441.944938.165170@g49g2000cwa.googlegroups.com> References: <1123474441.944938.165170@g49g2000cwa.googlegroups.com> Message-ID: <20050808115146.GB13847@unpythonic.net> As far as I know, there is not a prefabbed solution for this problem. One issue that you must solve is the issue of buffering (when must some data you've written to the compressor really go out to the other side) and the issue of what to do when a read() or recv() reads gzipped bytes but these don't produce any additional unzipped bytes---this is a problem because normally a read() that returns '' indicates end-of-file. If you only work with whole files at a time, then one easy thing to do is use the 'zlib' encoding: >>> "abc".encode("zlib") "x\x9cKLJ\x06\x00\x02M\x01'" >>> _.decode("zlib") 'abc' ... but because zlib isn't self-delimiting, this won't work if you want to write() multiple times, or if you want to read() less than the full file Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From fakeaddress at nowhere.org Wed Aug 24 09:28:16 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 24 Aug 2005 13:28:16 GMT Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: <7x7jeflj8d.fsf@ruckus.brouhaha.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <7x7jeflj8d.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Bryan Olson writes: > >> seq[3 : -4] >> >>we write: >> >> seq[3 ; $ - 4] > > > +1 I think you're wrong about the "+1". I defined '$' to stand for the length of the sequence (not the address of the last element). >>When square-brackets appear within other square-brackets, the >>inner-most bracket-pair determines which sequence '$' describes. >>(Perhaps '$$' should be the length of the next containing >>bracket pair, and '$$$' the next-out and...?) > > Not sure. $1, $2, etc. might be better, or $ like in regexps, etc. Sounds reasonable. [...] > Hmm, tuples are hashable and are already valid indices to mapping > objects like dictionaries. Having slices means an object can > implement both the mapping and sequence interfaces. Whether that's > worth caring about, I don't know. Yeah, I thought that alternative might break peoples code, and it turns out it does. -- --Bryan From kenneth.m.mcdonald at sbcglobal.net Wed Aug 24 15:53:39 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Wed, 24 Aug 2005 14:53:39 -0500 Subject: How to start PEP process? Message-ID: <8DDC1FE0-640C-48A3-A022-ABCBDC2B082B@sbcglobal.net> Should I just put a "Proposed PEP" message here? Or is there a more formal way? Thanks, Ken From rrr at ronadam.com Tue Aug 2 00:27:44 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 02 Aug 2005 04:27:44 GMT Subject: Path as a dictionary tree key? (was Re: PEP on path module for standard library) In-Reply-To: References: Message-ID: <4DCHe.47260$t43.6310@tornado.tampabay.rr.com> Here's an example of how path objects could possibly be used to store and retrieve data from tree_dictionary class. I used lists here in place of path objects, but I think path objects would be better. I think paths used this way creates a consistant way to access data stored in both internal and external tree structurs. A more realistic example would be to store formated (html) strings in the tree and then use imbeded paths to jump from page to page. The tree class defined here is not complete, it's just the minimum to get this example to work. I wouldn't mind at all if anyone posted improvements. (hint hint) ;-) Cheers, Ron Adam +---- output ------ Define paths: path1 = ['hello', 'world'] path2 = ['hello', 'there', 'world'] path3 = ['hello', 'there', 'wide', 'world'] Store path keys in tree: hello world None there world None wide world None Get path list from tree: ['hello', 'world'] ['hello', 'there', 'world'] ['hello', 'there', 'wide', 'world'] Put items in tree using path: hello world 1 there world 2 wide world 3 Get items from tree using path: path1: 1 path2: 2 path3: 3 +---- source code ----------- # Dictionary tree class (not finished) class Tree(dict): #TODO - remove_item method, # remove_path method, # __init__ method if needed. def get_item(self, path): d = self for key in path[:-1]: d=d[key] return d[path[-1]] def put_item(self, path, item): d = self for key in path[:-1]: d=d[key] d[path[-1]]=item def store_path(self, path_=None): # store item key = path_[0] if len(path_)==1: self[key]=None return try: self[key] except KeyError: self[key]=Tree() self[key].store_path(path_[1:]) def get_paths(self, key=None, path=[], pathlist=[]): if key==None: key=self keys = key.keys() for k in keys: if type(self[k]) is Tree: path.append(k) self[k].get_paths(key[k], path, pathlist) else: pathlist.append(path+[k]) return pathlist def pretty_print_tree(t, tab=0): for k in t.keys(): print ' '*tab, k if type(t[k]) is Tree: pretty_print_tree(t[k], tab+1) else: print ' '*(tab+1), t[k] # Store data in a dictionary. print 'Define paths:' path1 = ['hello','world'] print 'path1 =', path1 path2 = ['hello','there','world'] print 'path2 =', path2 path3 = ['hello','there','wide','world'] print 'path3 =', path3 print '\nStore path keys in tree:' tree = Tree() tree.store_path(path1) tree.store_path(path2) tree.store_path(path3) pretty_print_tree(tree) print '\nGet path list from tree:' path_list = tree.get_paths() for path in path_list: print path print '\nPut items in tree using path:' tree.put_item(path1, '1') tree.put_item(path2, '2') tree.put_item(path3, '3') pretty_print_tree(tree) print '\nGet items from tree using path:' print 'path1:', tree.get_item(path1) print 'path2:', tree.get_item(path2) print 'path3:', tree.get_item(path3) +---- end ------- From grante at visi.com Wed Aug 10 21:46:10 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 11 Aug 2005 01:46:10 -0000 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123697696.506898.66580@z14g2000cwz.googlegroups.com> <1123723974.522483.92740@o13g2000cwo.googlegroups.com> Message-ID: <11flbf2547o4176@corp.supernews.com> On 2005-08-11, Qopit wrote: > >> if debug: print "v=%s" % (v,) > > Not that important, but I assume the first one was supposed to be: > > if debug: print "v=", s > > right? http://docs.python.org/tut/node9.html#SECTION009100000000000000000 -- Grant Edwards grante Yow! .. Now KEN and BARBIE at are PERMANENTLY ADDICTED to visi.com MIND-ALTERING DRUGS... From zen19725 at zen.co.uk Wed Aug 10 20:19:19 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Thu, 11 Aug 2005 01:19:19 +0100 Subject: Python supports LSP, does it? References: Message-ID: On Tue, 09 Aug 2005 18:36:56 -0500, Andy Leszczynski wrote: >wikipedia >(http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming) >says: >""" >Python's support for object oriented programming paradigm is vast. It >supports polymorphism [...] fully in the Liskov substitution >principle-sense for all objects. >""" > >Just wondering if it is true statement. Is not LSP more a quality of the >desing of class hierachy rather then language itslef? Comments? According to Wikipedia, the Liskov substitution principle is: Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T To me, this is nonsense. Under this definition any subtype must behave the same as its parent type, becausde if it doesn't there will be some q(y) that are different to q(x). But if it behaves the same, what's the point of having a subtype? Am I missing something? -- Email: zen19725 at zen dot co dot uk From steven.bethard at gmail.com Tue Aug 16 13:50:43 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 16 Aug 2005 11:50:43 -0600 Subject: class-call a function in a function -problem In-Reply-To: <43021AC9.5000103@syscononline.com> References: <43021AC9.5000103@syscononline.com> Message-ID: Larry Bates wrote: > def __init__(self, x=1, y=2) [snip] > self.x=x > self.y=y > self.a=0 > return > > def l(self): [snip] > self.a=self.x+self.y > print "In ludzik.l a=',self.a > return > > def ala(self): [snip] > self.l() > return Any reason for putting the return statements at the end of each function? STeVe From sp1d3rx at gmail.com Thu Aug 25 11:32:07 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 25 Aug 2005 08:32:07 -0700 Subject: variable hell In-Reply-To: References: <430dc538@127.0.0.1> Message-ID: <1124983927.323716.97340@g43g2000cwa.googlegroups.com> Hey, if the man wants to write it that way, let the man write it that way. If it works for him, great... he's sure confused the heck out of all of us, and that translates into job security for him! As you can see, the name of the post is 'variable hell' and that is exactly what he is creating, so "Adriaan Renting", excellent response! From me at privacy.net Mon Aug 8 11:08:40 2005 From: me at privacy.net (Dan Sommers) Date: Mon, 08 Aug 2005 11:08:40 -0400 Subject: How to determine that if a folder is empty? References: <3loeiiF139eh3U1@individual.net> <86k6iwmvh0.fsf@bhuda.mired.org> Message-ID: On Mon, 08 Aug 2005 09:03:39 -0400, Mike Meyer wrote: > Just out of curiosity, is there an OS out there where you can have the > permissions needed to delete a directory without having the > permissions needed to create it appropriately? Depending on your definition of "out there," yes, some OS's grant those privileges separately. Apollo (eventually bought out by HP) Aegis (mostly like *nix, but just different enough to trip me up again and again) used to be one. The more secure the environment, the more likely certain privileges do *not* imply others. Regards, Dan -- Dan Sommers From brian at sweetapp.com Wed Aug 3 06:44:51 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 03 Aug 2005 12:44:51 +0200 Subject: Python Programming Contest: First results In-Reply-To: References: <1121838061.749455.44630@g14g2000cwa.googlegroups.com> <42DE18B2.903@sweetapp.com> <42EF352D.2060702@sweetapp.com> Message-ID: <42F0A023.1070404@sweetapp.com> Tomi Ky?stil? wrote: > Any idea when the next competition is coming? (it hasn't been quite > weekly as you hoped, eh? ;) Uh no. It turns out that I have less time than I thought, though a big chunk of it should be freed-up after this weekend. I do have an idea... :-) Cheers, Brian From newsgroups at jhrothjr.com Tue Aug 2 13:58:35 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 2 Aug 2005 11:58:35 -0600 Subject: Art of Unit Testing References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: <11evd2l1f4ere2c@news.supernews.com> ""Bj?rn Lindstr?m"" wrote in message news:87mzo0s25q.fsf at lucien.dreaming... > Christoph Zwerschke writes: > >> Would it make sense to add "globaleSetup" and "globalTearDown" methods >> to the TestCase class? I think at least it would not harm >> anybody. Where should such proposals be submitted? > > In general that's not such a good idea. If you build your tests like > that, it gets hard to know which test really went wrong, and you might > get the situation where the whole set of tests works, but depend on each > other in some way. (This can also happen for more obscure reasons, and > is worth looking out for whichever way you do it.) > > So, rebuilding the environment for the each before every single test is > generally worth the overhead. Generally is not always. There are configuration issues that are best dealt with once at the beginning of the test, and once at the end, and that have absolutely nothing to do with the order in which each elementary test runs. When your customers keep asking for something, and you keep telling them that they really don't want what they're asking for, who's lisening, and who's being stubborn? John Roth Python Fit. > > -- > Bj?rn Lindstr?m > Student of computational linguistics, Uppsala University, Sweden From john at castleamber.com Fri Aug 26 08:38:04 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 12:38:04 GMT Subject: Usenet, HTML (was Re: Jargons of Info Tech industry) References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8366F9vvsU1@individual.net> <3n8ch4Fb539U1@individual.net> Message-ID: usenet at isbd.co.uk wrote: > In comp.lang.perl.misc John Bokma wrote: >> > >> > I'm talking about using the technology for communication, instead of >> > reinventing the wheel with crappy web forums. >> >> What is exactly crappy about those forums? >> > They are slow I have no problems with it. Moreover, since I use an NNTP server which is a bit remote, it's way slower compared to the web forums I use. > They are inflexible Examples? > They don't allow the user to choose how to view them, the interface is > imposed on the user. False. The user can pick themes, often several. The user can use a user stylesheet or several. And you can always write your own client :-D. > They don't have killfiles or scoring You can install a mod to kill people. And I have no doubt that there is a scoring mod, or one can be written in a few hours. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From leszczynscyATnospam.yahoo.com.nospam Fri Aug 5 01:46:52 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Fri, 05 Aug 2005 00:46:52 -0500 Subject: >time.strftime %T missing in 2.3 Message-ID: Python 2.2/Unix >>time.strftime("%T") '22:12:15' >>time.strftime("%X") '22:12:17' Python 2.3/Windows >>time.strftime("%X") '22:12:47' >> time.strftime("%T") '' Any clues? A. From arielgr at gmail.com Mon Aug 1 08:06:57 2005 From: arielgr at gmail.com (arielgr at gmail.com) Date: 1 Aug 2005 05:06:57 -0700 Subject: python ETL Message-ID: <1122898017.573173.189620@g14g2000cwa.googlegroups.com> Hi, My company is involved in the development of many data marts and data-warehouses, and I currently looking into migrating our old set of tools (written in Korn) to a new, more dynamic and robust one. I am looking into python as I have heard that it could be a good contestant for the job, and wanted to know if anyone knew of an existing open source project which implements ETL using python, or any libraries that may ease the production of such tools. Thanks. From roland.hedberg at adm.umu.se Tue Aug 23 03:43:55 2005 From: roland.hedberg at adm.umu.se (Roland Hedberg) Date: Tue, 23 Aug 2005 09:43:55 +0200 Subject: Network performance Message-ID: <83ECF740-BE8B-40B1-A8C8-54899442AFC3@adm.umu.se> Hi! I need a fast protocol to use between a client and a server, both sides written i Python. What the protocol has to accomplish is extremely simple; the client sends a number of lines (actually a RDF) and the server accepts or rejects the packet. That's all ! Now, presently I'm using Twisted and XMLRPC ( why so is a long history which I will not go into here) and that is a bit to slow for my needs. On my present setup it takes close to 200 ms to perform one transfer. But since that includes setting up and tearing down the connection I thought I'd try doing something simpler so I wrote a server and a client using socket. The client sends a number of lines (each ending with \n) and ends one set of lines with a empty line. When the client sends a line with only a "." it means "I'm done close the connection". Letting the client open the connection and sending a number of sets I was surprised to find that the performance was equal to what Twisted/ XMLRPC did. Around 200 ms per set, not significantly less. So what can be done to speed up things or is Python incapable of supporting fast networking (just a teaser). -- Roland -------------- next part -------------- A non-text attachment was scrubbed... Name: udsrecv.py Type: text/x-python-script Size: 633 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: udscli.py Type: text/x-python-script Size: 1067 bytes Desc: not available URL: -------------- next part -------------- From john at castleamber.com Fri Aug 26 00:57:48 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 04:57:48 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: Chris Head wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > usenet at isbd.co.uk wrote: > [snip] >> ... and generally these "web based message boards" (i.e. forums I >> assume you mean) have none of the useful tools that Usenet offers and >> are much, much slower. > [snip] > > Arrgh, I *emphatically* *hate* Web-based-(almost anything). Why, oh > WHY, would we subject ourselves to Web-based message boards and > Webmail services? When using a proper e-mail client, your bandwidth > usage consists of downloading your e-mail. When using a Webmail > service, your bandwidth usage consists of downloading the message, > PLUS the entire user interface. Not necessary when using (i)frames + cache > Additionally, a user interface operating inside an HTML > renderer can NEVER be as fast as a native-code user interface with > only the e-mail message itself passed through the renderer. Nowadays, more then futile. > I mean, the way > Webmail works, you're at the message list and click on a message to > view. This causes a whole new page, user-interface and all, to be > loaded. In comparison, that's like shutting down and re-opening your > e-mail program for every single message you want to view! This can be designed much better by using iframes, maybe even Ajax. > Why can't we use the Web for what it was meant for: viewing hypertext > pages? Why must we turn it into a wrapper around every application > imaginable? Because it works? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From mirnazim at gmail.com Tue Aug 9 01:32:35 2005 From: mirnazim at gmail.com (Mir Nazim) Date: 8 Aug 2005 22:32:35 -0700 Subject: Point and click GUI builder for Python References: <42f430ea$0$18643$14726298@news.sunsite.dk> <1123348044.677983.211380@g47g2000cwa.googlegroups.com> Message-ID: <1123565555.515549.20020@g49g2000cwa.googlegroups.com> neuruss neuruss wrote: > Madhusudan Singh wrote: > > Is there such a thing for python ? Like Qt Designer for instance ? > > The easiest way to create Python GUI apps: PythonCard. > It is based on wxPython by it has a higher level of abstraction. > You just drag and drop widgets on a form and code the events like you > woud in Visual Basic or Delphi. > IMHO, it's easier, simpler, more intuitive and stable than Boa > Constructor. Add to it wxGlade.sourceforge.net. But remember it is only a UI designer(does it pretty well) not an IDE. I fee wxGlade+SPE(http://www.stani.be/python/spe/blog/) are a better combo than PythonCard From nephish at xit.net Fri Aug 5 22:51:31 2005 From: nephish at xit.net (nephish at xit.net) Date: 5 Aug 2005 19:51:31 -0700 Subject: GUI programming, embedding, real time plots, etc. In-Reply-To: <42f4157f$0$18643$14726298@news.sunsite.dk> References: <42f4157f$0$18643$14726298@news.sunsite.dk> Message-ID: <1123296691.424699.172460@g14g2000cwa.googlegroups.com> apt-get install python-pwm this will get you python mega widgets one of the dependencies that apt will take care of for you is the python2.whatever-tk. depending on which version of debian you are using. i run sarge with python 2.3 From randy at psg.com Fri Aug 26 12:46:31 2005 From: randy at psg.com (Randy Bush) Date: Fri, 26 Aug 2005 06:46:31 -1000 Subject: need a little help with time References: <1125065840.477157.43290@g47g2000cwa.googlegroups.com> Message-ID: <17167.18279.576187.316496@roam.psg.com> i am doing disgusting looking junk based on calendar. example now = calendar.timegm(time.gmtime()) aWeek = 7*24*60*60 print time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(now + aWeek)) randy From cliff at develix.com Tue Aug 2 00:22:15 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 21:22:15 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <86hde9f172.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <8664uqhkfj.fsf@bhuda.mired.org> <86hde9f172.fsf@bhuda.mired.org> Message-ID: <1122956536.19618.463.camel@localhost.localdomain> On Mon, 2005-08-01 at 23:49 -0400, Mike Meyer wrote: > Cliff Wells writes: > > > On Sun, 2005-07-31 at 14:58 -0400, Mike Meyer wrote: > >> And what do I use to bundle my application for Unix? Most of the > >> things I build get installed on Unix servers. > > You install GUI apps on Unix *servers*? > > Yup. Thanks to the wonders of X, I can run GUI apps on servers and > have them display on my desktop. Or my OS X laptop. I normally leave a > gkrellm running on most of my servers. Yes, yes. The "wonders of X" have been known to me since around 1992. Personally I avoid running GUI apps on my servers since they are usually unnecessary, waste memory, and if not used properly, open the door for security issues (for that matter, any extra piece of software installed opens the door for potential security issues so I tend to run stripped-down servers that only provide needed services - no fluff. Then again "server" is a pretty broad term. The bulk of my servers are shared and dedicated hosting environments where paranoia is rewarded. Your situation may be different). > Of course, the problem under discussion isn't restricted to GUI > apps. Anytime I use a third party library, I have to deal with how end > users are going to get it. Absolutely. However GUI libraries tend to stick out a bit more since they tend to have a larger number of dependencies plus sheer code size and complexity makes platform-specific bugs more likely. > > Regardless, when you say "Unix", what do you mean? You may as well say > > "OS" as this term has little meaning. Linux (which flavor)? BSD? SCO? > > HPUX? OS/X? Minix? Whichever way, I suspect that a bit of distutils > > hacking would solve your problem. > > I think the post I replied to covered the OS X case - there's an > application bundler available for it already. Yes, I've used it to bundle wxPython apps on 10.3. > I want distributions that will work on all three major BSD variants > and most Linux distrubtions - in particular, anything that uses deb's, > rpm's or emerge. If you want to choose one in particular, try ubuntu > Linux. OpenBSD: in portage FreeBSD: in portage 386BSD: don't know... does anyone still use this? NetBSD: included AFAICT Fedora: rpms available Debian: debs available Ubuntu: included Gentoo: in portage OS/X: available on wxpython.org FWIW, much of this info I found in less than 5 minutes using Google. I suppose with a little persistence you could have discovered it for yourself. Here's your Ubuntu instructions: http://wiki.wxpython.org/index.cgi/wxPython_20with_20Ubuntu Of course, if you are distributing end-user software by requiring users to install 3rd party packages themselves, then I hope you are distributing open source software. If it's a commercial/closed-source app you'll do far better by simply packaging all the requirements into the installer and installing it within the application's directory tree (this solves a lot of problems with version conflicts and user confusion). In my experience, binary packages work best for Windows and OS/X, and source distributions work best for Linux (mostly because building packages for Linux is a varied and sometimes painful process. Further Linux truly works best as a source-based system: you cannot always depend on ABI compatibility across versions of libraries - *usually* you can but... caveat emptor). Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From billiejoex at fastwebnet.it Fri Aug 26 10:42:46 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Fri, 26 Aug 2005 16:42:46 +0200 Subject: Does any1 use pcapy module on win32 platforms? Message-ID: Hi. I'm trying to use pcapy module on Windows XP prof sp2 but it doesn't work. The example source reported on the site (http://oss.coresecurity.com/impacket/sniff.py) works only on *unix machines. On Windows machines the findalldevs() function (an output on the bottom) gives an unicode object that can't be processed by open_live function that tipically accept strings. This not happens on linux machines where findalldev() function gives a string object that can be quietly accepted by open_live. Does exist a patch to fix this bug? I really would like to write a portable program usable in both platforms. Maybe do can I process the unicode outputs and converting them into valid strings? Happy summer and happy coding! :-) Regards billiejoex >>> pcapy.findalldevs() [u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e\u6972\u4e63\u6964\u5773\u6e6 1\u6441\u7061\u6574r\u445c\u7665\u6369\u5c65\u504e\u5f46\u317b\u4534\u3544\u3642 \u2d31\u3030\u3942\u342d\u4441\u2d39\u3341\u4345\u382d\u3033\u3246\u3938\u3241\u 4531\u7d44\u5c00\u6544\u6976\u6563\u4e5c\u4650\u7b5f\u3541\u3630\u3934\u3434\u45 2d\u4230\u2d37\u3634\u3239\u382d\u4237\u2d35\u4630\u3133\u4244\u3933\u3532\u3943 }\u445c\u7665\u6369\u5c65\u504e\u5f46\u377b\u4337\u3644\u3034\u2d31\u3841\u3143\ u342d\u3743\u2d43\u3241\u4633\u432d\u3731\u3037\u3538\u3234\u4538\u7d34', u'\u65 47\u656e\u6972\u2063\u644e\u7369\u6157\u206e\u6461\u7061\u6574r\u4d56\u6177\u657 2\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u4d56 \u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u 6574r\u564e\u4449\u4149\u6e20\u6f46\u6372\u2065\u434d\u2050\u654e\u7774\u726f\u6 96b\u676e\u4120\u6164\u7470\u7265\u4420\u6972\u6576\u2072\u4d28\u6369\u6f72\u6f7 3\u7466\u7327\u5020\u6361\u656b\u2074\u6353\u6568\u7564\u656c\u2972 '] From rrr at ronadam.com Wed Aug 17 13:59:34 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 17 Aug 2005 17:59:34 GMT Subject: [Python-Dev] implementation of copy standard lib In-Reply-To: References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: Michael Hudson wrote: > Simon Brunning writes: > > >>I think that copy is very rarely used. I don't think I've ever imported it. >> >>Or is it just me? > > > Not really. I've used it once that I can recall, to copy a kind of > generic "default value", something like: > > def value(self, v, default): > if hasattr(source, v): return getattr(source, v) > else: return copy.copy(default) > > (except not quite, there would probably be better ways to write > exactly that). > > Cheers, > mwh My most recent use of copy.deepcopy() was to save the state of a recusivly built object so that it could be restored before returning a result that involved making nested changes (with multiple methods) to the ojbects subparts as part of the result calculation. The alternative would be to use a flag and shallow copies in all the methods that altered the object. copy.deepcopy() was a lot easier as it's only needed in the method that initiates the result calculation. Cheers, Ron From fredrik at pythonware.com Mon Aug 22 17:12:32 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 23:12:32 +0200 Subject: Best way to 'touch' a file? References: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Message-ID: Peter Hansen wrote: > from path import path > path('myfile').touch() import os os.utime('myfile', None) is a bit shorter, of course. >>> help(os.utime) Help on built-in function utime: utime(...) utime(path, (atime, utime)) utime(path, None) Set the access and modified time of the file to the given values. If the second form is used, set the access and modified times to the current time. From onurb at xiludom.gro Tue Aug 23 05:44:27 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 23 Aug 2005 11:44:27 +0200 Subject: Python and the web In-Reply-To: References: Message-ID: <430aeffd$0$22825$626a14ce@news.free.fr> Joe T. wrote: > Hello group, I'm new to Python and have a couple of beginner questions that > I'm hoping someone can answer. > > 1. Is python something that you would recommend using for server side web > programming? Definitively yes. > Something like C# or Java? Far better IMHO. > If so, are there any resources > that you could point me to that would help me with server side python > programming for dynamic html data? Most of the tutorials that I see deal > with the Shell but I'd like to know more about using Python for database > querying and printing database data on an html page as I would with .net's > C# or Java. If your need is to build a web frontend for relational datas, have a look at Django: http://www.djangoproject.com/ Else, you have a huge choice of web programming solutions in Python, the most known being Zope, Twisted/Nevow and CherryPy (but there are many others....). > 2. I know there's a Jpython but what use would I get from using Python with > Java? If I'm already familiar with Java programming why would I want to use > Python with Java? Because Python is much more usable than Java ?-) But unless you need to work in a Java environnement, better stick to CPython. -- bruno desthuilliers ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@')" python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From richardlewis at fastmail.co.uk Tue Aug 30 07:05:38 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Tue, 30 Aug 2005 12:05:38 +0100 Subject: DOM text In-Reply-To: <1125397045.8198.241769418@webmail.messagingengine.com> References: <3n889kFb1liU1@uni-berlin.de> <1125052998.4951.241536021@webmail.messagingengine.com> <1125397045.8198.241769418@webmail.messagingengine.com> Message-ID: <1125399938.12961.241773532@webmail.messagingengine.com> On Tue, 30 Aug 2005 11:17:25 +0100, "Richard Lewis" said: > > Here is the *complete* code for my SectionCursor class: In case anyone's interested, I've just noticed a logical error in the next_node() method: ================================= def next_node(self): if self.current_node.hasChildNodes(): self.current_node = self.current_node.firstChild elif self.current_node.nextSibling is not None: self.current_node = self.current_node.nextSibling else: while self.current_node.parentNode.nextSibling is None\ and self.current_node != self.section_element: self.current_node = self.current_node.parentNode if self.current_node != self.section_element: self.current_node = self.current_node.parentNode.nextSibling else: return False self.char_pos = 0 return True ================================= which doesn't solve the original problem. Though I think it may be causing a (related) problem: it says the self.current_node.parentNode is of NoneType. If there is a problem with assigning parts of an existing DOM tree to other variables, might this be another symptom? Cheers, Richard From iainking at gmail.com Tue Aug 30 11:20:10 2005 From: iainking at gmail.com (Iain King) Date: 30 Aug 2005 08:20:10 -0700 Subject: how to join two Dictionary together? In-Reply-To: References: Message-ID: <1125415210.236327.183510@o13g2000cwo.googlegroups.com> Michael.Coll-Barth at VerizonWireless.com wrote: > update works like append for lists > > a = {} > a['a']='a' > a['c']='c' > b={} > b['b'] = 'b' > c={} > c.update(a) > c.update(b) > So what do you think is the better way to do it, based on speed or aesthetics? (1) c=a.copy() c.update(b) or (2) c={} c.update(a) c.update(b) Iain From __peter__ at web.de Mon Aug 15 01:55:05 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Aug 2005 07:55:05 +0200 Subject: How can I exclude a word by using re? References: <1124031736.367193.219920@g44g2000cwa.googlegroups.com> Message-ID: could ildg wrote: > But what should I do if there are more than one hello and I only want > to extract what's before the first "hello". For example, the raw > string is "hi, how are you? hello I'm fine, thank you hello. that's it > hello", I want to extract all the stuff before the first hello? The simplest solution is to use str.split(): >>> helo = "hi, how are you? HELLO I'm fine, thank you hello. that's it" >>> helo.split("hello", 1)[0] "hi, how are you? HELLO I'm fine, thank you " But regular expressions offer a similar feature: >>> re.compile("hello", re.IGNORECASE).split(helo, 1)[0] 'hi, how are you? ' Peter From cam.ac.uk at mh391.invalid Thu Aug 11 14:54:52 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Thu, 11 Aug 2005 19:54:52 +0100 Subject: command line reports In-Reply-To: References: Message-ID: Darren Dale wrote: > Is there a module somewhere that intelligently deals with reports to the > command line? I would like to report the progress of some pretty lengthy > simulations, and currently I have the new reports written on a new line > rather rather than overwriting the previous report. I'm afraid I don't understand this. Could you please give an example? Of course, this is c.l.p., so I'm sure *someone* will understand it. -- Michael Hoffman From spam.csubich+block at block.subich.spam.com Sat Aug 13 16:43:44 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Sat, 13 Aug 2005 16:43:44 -0400 Subject: Spaces and tabs again In-Reply-To: <1123964301.854778.172680@g49g2000cwa.googlegroups.com> References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> Message-ID: sigzero at gmail.com wrote: > Are you kidding? You are going to MANDATE spaces? Actually, future whitespace rules will be extensive. See: http://64.233.187.104/search?q=cache:k1w9oZr767QJ:www.artima.com/weblogs/viewpost.jsp%3Fthread%3D101968 (google cache of http://www.artima.com/weblogs/viewpost.jsp?thread=101968 because it seems to be down at the moment) The only change from April 1, 2005 is that the enforcement is punted until Python 3.0, because of the source-incompatible nature of the change. "Lrf, vg'f na Ncevy Sbbyf' wbxr.".decode('rot13') From rkern at ucsd.edu Mon Aug 8 23:54:57 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 08 Aug 2005 20:54:57 -0700 Subject: How to connect to UNIX machine from windows box In-Reply-To: <814c4b030508082043424ad507@mail.gmail.com> References: <814c4b030508082043424ad507@mail.gmail.com> Message-ID: Pooja Sharma wrote: > I want to connect to unix machine using ssh to run some commands . > > Is there any python module available that can be called in any other > python script. > > Reply asap. :) No, you don't get to demand that we reply ASAP. It's rude. http://www.catb.org/~esr/faqs/smart-questions.html But since I'm fundamentally a nice guy (if incredibly crotchety for my young age): http://www.lag.net/paramiko/ -- 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 cbfalconer at yahoo.com Thu Aug 25 23:43:17 2005 From: cbfalconer at yahoo.com (CBFalconer) Date: Fri, 26 Aug 2005 03:43:17 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <11gt0d8bjanaabe@corp.supernews.com> Message-ID: <430E8EBA.129E2B61@yahoo.com> Gordon Burditt wrote: > >> HTML is designed to degrade gracefully (never mind that most web >> authors and many browser developers don't seem to comprehend this), >> so you don't really need a "subset" html to get the safety features >> you want. All you need to do is disable the appropriate features in >> the HTML renderer in your news and mail readers. JavaScript, Java, >> and any form of object embedding. Oh yeah, and frames. > > And links. And cookies. And any kind of external site or local > file access. And browser history. What is the risk with browser history? -- Chuck F (cbfalconer at yahoo.com) (cbfalconer at worldnet.att.net) Available for consulting/temporary embedded and systems. USE worldnet address! From randy at psg.com Mon Aug 22 22:20:02 2005 From: randy at psg.com (Randy Bush) Date: Mon, 22 Aug 2005 19:20:02 -0700 Subject: loop in python References: Message-ID: <17162.34770.307694.358127@roam.psg.com> computers are cheap. i am expensive. give me clear and maintainable code every time. randy From ms at cerenity.org Sun Aug 28 15:27:33 2005 From: ms at cerenity.org (Michael Sparks) Date: Sun, 28 Aug 2005 20:27:33 +0100 Subject: Release of PyPy 0.7.0 References: <4311ea97$0$1276$ed2619ec@ptn-nntp-reader02.plus.net> <1h20uj1.y52kzk1che9j9N%dial#####$$NOSPAM##$#$##tone@gmail.com> Message-ID: <43121002$0$97118$ed2619ec@ptn-nntp-reader03.plus.net> Valentino Volonghi aka Dialtone wrote: > Michael Sparks wrote: > >> Would it be useful for people to start trying out their modules/code to >> see if they work with this release, and whether they can likewise be >> translated using the C/LLVM backends, or would you say this is too early? >> (I'm more thinking in terms of it providing real world usecases in the >> hope of finding things that don't work - rather than anything else) > > This is not how it works. I beg to differ - it is how it can work (just not the default or currently recommended). Currently the biggest, most interesting example is this: (from the getting started page, compiling pypy) cd pypy/translator/goal python translate_pypy.py Which has just finished executing on my machine and took about 3 hours to complete (partly because the cc1 process reached ~780MB in terms of memory footprint and my machine has 512Mb). However it goes on to talk about compiling other things: """You can also use the translate_pypy.py script to try out several smaller programs, e.g. a slightly changed version of Pystone: cd pypy/translator/goal python translate_pypy.py targetrpystone """ Which is pretty cool of course. For those of interest running pystone with the pypy compiled native binary has the following results for pystones on my machine: michaels at linux:~/pypy-0.7.0/pypy/translator/goal> ./pypy-c debug: entry point starting debug: argv -> ./pypy-c debug: importing code debug: calling code.interact() Python 2.4.1 (pypy 0.7.0 build) on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>>> from test import pystone >>>> pystone.main(1000) Pystone(1.1) time for 1000 passes = 13.97 This machine benchmarks at 71.582 pystones/second >>>> The same results for CPython: michaels at linux:~/pypy-0.7.0/pypy/translator/goal> python Python 2.4 (#1, Mar 22 2005, 21:42:42) [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from test import pystone >>> pystone.main() Pystone(1.1) time for 50000 passes = 1.58 This machine benchmarks at 31645.6 pystones/second Obviously therefore anyone seeking to translate their existing code from python to an executable directly using pypy would not be doing it for performance reasons (again, something I'm aware of watching the updates come out and having run svn checkouts at previous times). (Factor of ~450 though is pretty d*^%n cool though :) I'm also well aware of the difference between python and rpython :-) > Pypy doesn't translate your code to C/LLVM. > Currently PyPy can only translate a pretty simple subset of python > called RPython which has a very C-like syntax (but without memory > management code). This is needed to allow type inference inside the > interpreter code. > > The code in your application is application code and can be whatever you > want, you may try to translate it to C/LLVM but it won't be that good of > course because the annotator is not that intelligent. *Shrug* Seemed pretty good at annotating and compiling a module longer than many of mine at Europython, and then compiled using the LLVM backed. :) Anyway, whether it's sensible or not I'm going to play with translating some of my modules :) Regards, Michael. From peter at engcorp.com Sat Aug 6 22:20:42 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 06 Aug 2005 22:20:42 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) In-Reply-To: <863bpmv85p.fsf@bhuda.mired.org> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> <86br4avf5t.fsf@bhuda.mired.org> <11fakjctean9u8a@news.supernews.com> <863bpmv85p.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > "John Roth" writes: >>"Mike Meyer" wrote in message >>>I find it hilarious that this arrived at my news server the same day >>>that Peter Hansens rant (look for the subject "Syntax error after >>>upgrading to Python 2.4") about Python changing to fast did. >> >>You may find it hilarious. I find it kind of sad - painting oneself >>into a corner so that upgrades become a pain for the customer >>base is not a laughing matter. > > So we have one (count him, 1) user who complains that it's changing to > fast. I suspect most readers here would disagree with him. Although both Mike and John by this time are aware of Mike's mistaken attribution of the "rant" to me, I feel compelled to point out for posterity (i.e. anyone searching this thread in the future) that it wasn't "Peter Hansen" who produced the rant in question, and that I do NOT feel that Python is changing too quickly. -Peter From noreply at gcgroup.net Sat Aug 13 00:40:27 2005 From: noreply at gcgroup.net (William Gill) Date: Sat, 13 Aug 2005 04:40:27 GMT Subject: problem extending tkSimpleDialog.Dialog In-Reply-To: References: Message-ID: <%QeLe.1617$O07.624@newssvr23.news.prodigy.net> Problem solved. I was not properly passing the master widget reference in my frame classes class MyWidget(Frame): def __init__(self, master, columns,rows, trace_write=None): Frame.__init__(self) #<<<< here's my mistake ... ... ... should have been: class MyWidget(Frame): def __init__(self, master, columns,rows, trace_write=None): Frame.__init__(self,master) ... ... ... Bill P.S. I haven't been working on this since my last post. I had to quit to go see my oldest graduate. William Gill wrote: > I have created a widget that extends Frame() and contains labels, > checkboxes, and entrys. I am trying to use tkSimpleDialog.Dialog to > create a modal display of this widget, but am running into some > (addressing) problems. My widget displays in the parent widget, not the > tkSimpleDialog.Dialog? I hope this snippet is enough to help, as my > actual code is really too hard to follow. > > class showtestWidget(tkSimpleDialog.Dialog): > def body(self,master): > Label(master,text="showPhoneNums").grid() > testWidget(self).grid() > > class testWidget(Frame): > def __init__(self, master): > Frame.__init__(self) > self.createWidgets() > def createWidgets(self): > Label(self,text="testWidget").grid() > > When the parent script instantiates showtestWidget() it should create a > transient dialog containing a label with the text "showPhoneNums". It > does, but the label containing the text "testWidget" is being created in > the parent widget, not the dialog. > > It seems obvious to me that I'm addressing the wrong parent somehow, > since the label (probably the testWidget) is being created, but in the > wrong place. > > I tried changing testWidget(self).grid() to testWidget(master).grid(), > just to see if that helped, but it made no difference. > > Can someone show me where I went wrong? > > Bill > > From steve at holdenweb.com Mon Aug 29 17:44:56 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Aug 2005 17:44:56 -0400 Subject: Cygwin font problems In-Reply-To: <4313594A.2060700@jessikat.fsnet.co.uk> References: <4313594A.2060700@jessikat.fsnet.co.uk> Message-ID: Robin Becker wrote: > Steve Holden wrote: > >>Is anyone aware of (a fix for) problems I'm having getting PIL 1.1.5 to >>create bitmaps using TrueType and openType fonts? When I create an image >>using the standard PIL fonts everything seems fine, but when I use >>ImageFont.truetype(, ) no text is drawn. >> >>setup.py reports from debug print statements that it's finding freetype21. >> >>The same code using (Fredrik's pre-built binary) on Windows runs >>correctly and produces correct images. >> >>Cygwin runs Python 2.4.1, Windows runs 2.4. Any light on this mystery >>gratefully received. >> >>regards >> Steve > > Could PIL have been compiled without freetype support perhaps? > Don't think so, as I don't see any errors in the build, and the closing summary from "python setup.py build" reads -------------------------------------------------------------------- PIL 1.1.5 BUILD SUMMARY -------------------------------------------------------------------- version 1.1.5 platform cygwin 2.4.1 (#1, May 27 2005, 18:02:40) [GCC 3.3.3 (cygwin special)] -------------------------------------------------------------------- --- TKINTER support ok --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE2 support ok -------------------------------------------------------------------- Strangely enough all the tests pass, too! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From p at ulmcnett.com Thu Aug 4 02:16:58 2005 From: p at ulmcnett.com (Paul McNett) Date: Wed, 03 Aug 2005 23:16:58 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <86ek9a1ecf.fsf@bhuda.mired.org> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <86zms0ex85.fsf@bhuda.mired.org> <86acjzetfw.fsf@bhuda.mired.org> <86ek9a1ecf.fsf@bhuda.mired.org> Message-ID: <42F1B2DA.9070802@ulmcnett.com> Mike Meyer wrote: > Mike Meyer writes: > >>>I think you'll find that wxPython installs perfectly on Tiger using >>>the package provided. Indeed, the only really painful platform to >>>install wxPython on is Linux, where you pretty much need to build from >>>source if you want the latest and greatest. > > > FWIW, Tiger ships with wxPython pre-installed. Yes, but it's an older version... isn't it 2.4? -- Paul McNett http://paulmcnett.com From mwm at mired.org Mon Aug 8 09:03:39 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 08 Aug 2005 09:03:39 -0400 Subject: How to determine that if a folder is empty? References: <3loeiiF139eh3U1@individual.net> Message-ID: <86k6iwmvh0.fsf@bhuda.mired.org> James Dennett writes: > Reinhold Birkenfeld wrote: > >> could ildg wrote: >> >>>I want to check if a folder named "foldername" is empty. >>>I use os.listdir(foldername)==[] to do this, >>>but it will be very slow if the folder has a lot of sub-files. >>>Is there any efficient ways to do this? >> try: >> os.rmdir(path) >> empty = True >> except OSError: >> empty = False >> should be efficient. A directory (please stop calling them "folders") >> can only be removed if it's empty. >> Reinhold > > Unfortunately that destroys the directory if it was empty, > and then you can't recreate it unless (a) you went to the > trouble of preserving all of its attributes before deleting > it, and (b) your script has OS-level permissions to recreate > the directory with its original attributes (such as owners > and permissions). It's also buggy, in that there are other things that can cause an OSError: >>> import os >>> os.rmdir("/tmp/x") Traceback (most recent call last): File "", line 1, in ? OSError: [Errno 1] Operation not permitted: '/tmp/x' >>> ^D bhuda% bhuda% ls -a /tmp/x . .. The problem here is that I don't own /tmp/x, so I can't delete it, hence I get an OSError even though it's empty. Just out of curiosity, is there an OS out there where you can have the permissions needed to delete a directory without having the permissions needed to create it appropriately? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From bokr at oz.net Tue Aug 30 15:17:41 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 30 Aug 2005 19:17:41 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> < Message-ID: <4314aeaf.173284820@news.oz.net> On Tue, 30 Aug 2005 11:56:24 GMT, Bryan Olson wrote: >Robert Kern wrote: > > Bryan Olson wrote: > > > > > >> Currently, user-defined classes can implement Python > >> subscripting and slicing without implementing Python's len() > >> function. In our proposal, the '$' symbol stands for the > >> sequence's length, so classes must be able to report their > >> length in order for $ to work within their slices and > >> indexes. > >> > >> Specifically, to support new-style slicing, a class that > >> accepts index or slice arguments to any of: > >> > >> __getitem__ > >> __setitem__ > >> __delitem__ > >> __getslice__ > >> __setslice__ > >> __delslice__ > >> > >> must also consistently implement: > >> > >> __len__ > >> > >> Sane programmers already follow this rule. > > > > > > Incorrect. Some sane programmers have multiple dimensions they need to > > index. > > > > from Numeric import * > > A = array([[0, 1], [2, 3], [4, 5]]) > > A[$-1, $-1] > > > > The result of len(A) has nothing to do with the second $. > >I think you have a good observation there, but I'll stand by my >correctness. > >My initial post considered re-interpreting tuple arguments, but >I abandoned that alternative after Steven Bethard pointed out >how much code it would break. Modules/classes would remain free >to interpret tuple arguments in any way they wish. I don't think >my proposal breaks any sane existing code. > >Going forward, I would advocate that user classes which >implement their own kind of subscripting adopt the '$' syntax, >and interpret it as consistently as possible. For example, they >could respond to __len__() by returning a type that supports the >"Emulating numeric types" methods from the Python Language >Reference 3.3.7, and also allows the class's methods to tell >that it stands for the length of the dimension in question. > > (OTTOMH ;-) Perhaps the slice triple could be extended with a flag indicating which of the other elements should have $ added to it, and $ would take meaning from the subarray being indexed, not the whole. E.g., arr.[1:$-1, $-5:$-2] would call arr.__getitem__((slice(1,-1,None,STOP), slice(-5,-2,None,START|STOP)) (Hypothesizing bitmask constants START and STOP) Regards, Bengt Richter From fredrik at pythonware.com Tue Aug 30 15:36:31 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Aug 2005 21:36:31 +0200 Subject: Python2Html regex question References: <1125422888.376223.19970@z14g2000cwz.googlegroups.com> Message-ID: Gerard Flanagan wrote: > Either way, the (c#) source is available for the above formatter and it > looks like it would be straightforward to create a Python formatter by > extending a base class and providing the following three things: > > 1) a list of python keywords import keyword print keyword.kwlist > 2) a regex to match python comments import tokenize print tokenize.Comment > 3) a regex to match python strings import tokenize print tokenize.String print tokenize.Triple From yoav_artzi at il.vio.com Thu Aug 18 11:02:23 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Thu, 18 Aug 2005 18:02:23 +0300 Subject: RE Question In-Reply-To: <6hjet2-as.ln1@strongwill.g2ctech> References: <43049835$1@news.bezeqint.net> <6hjet2-as.ln1@strongwill.g2ctech> Message-ID: <4304A2FF.5000403@il.vio.com> What is the difference between the RE module and the SRE one? -------- Original Message -------- From: Jorge Godoy To: Subject: Re:RE Question Date: 18/8/2005 17:44 > Yoav wrote: > > >>I don't understand why the two REs produce a different result. I read >>the RE guide but still I can't seem to figure it out. >> >> >>> t >>'echo user=name password=pass path="/ret files"\r\n' >> >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t) >>['name', 'pass', '"/ret files"'] >> >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t) >>[('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret >>files"', '')] > > > Hi Yoav. > > You can see at "sre" documentation (use that instead of the docs for "re") > that using "?:" you're asking for a non-groupping version of the > parenthesis match. When you use parenthesis, the matched expression is > saved for using later. Using "?:" you prevent that. This is what causes > the difference for you. > > >>Also, does '|' char (meaning or) produces a pair for each section. I >>don't understand how it works. Can someone please direct me to a place >>which will explain it? > > > I didn't get your second question. When you use "|" the first match is > used. It is a short-circuited version of "or". I mean, it tries the first > regexp, if it matches, the second expression is ignored. The same is true > for "and", except that the comparisons end on the first false result. > > > Be seeing you, From fabioz at esss.com.br Thu Aug 11 07:52:48 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Thu, 11 Aug 2005 08:52:48 -0300 Subject: "Compile time" checking? In-Reply-To: <1123697696.506898.66580@z14g2000cwz.googlegroups.com> References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123697696.506898.66580@z14g2000cwz.googlegroups.com> Message-ID: <42FB3C10.5020209@esss.com.br> Just as a note... Pylint is integrated within pydev (http://pydev.sf.net) Cheers, Fabio Qopit wrote: >>Why not just find out, by trying to compile it? :-) >> >> > >This will likely certify me as a python newbie, but... how do you mean? > How do you compile a .py file? > >If you mean to .pyc by doing an import on it, that may work fine for >the simple example I typed up earlier, but that is easy to bypass by >slapping the offending line in a function. The sample below also >passes PyChecker with not even a warning: > >#---- >def tester(a,b,c): > print "bogus test function",a,b,c > >def try1(): > tester(1,2,3) >def try2(): > tester(1,2) #still no error here >#---- > >Do you mean something different? > >Also - thanks for the pylint comment... haven't tried it yet. It would >be nice to have the capability in an IDE like SPE, though. > > > -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From wolfgang.keller.nospam at gmx.de Mon Aug 8 05:49:32 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Mon, 08 Aug 2005 11:49:32 +0200 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: > The project aims to make it simple to build networked multimedia > systems (eg audio, video, interactive systems), Why limit the scope of application artificially? Axon/Kamaelia imho is perfectly applicable to any kind of application that does some kind of data processing. Think workflow applications, business applications, application integration... J. Paul Morrison has used the concept he named "Flow-Based-Programming" for financial applications since the 60's, any control systems engineer knows function-block-diagrams etc. and so on... Sincerely, Wolfgang Keller From falcon at intercable.ru Thu Aug 4 03:09:33 2005 From: falcon at intercable.ru (falcon) Date: Thu, 4 Aug 2005 11:09:33 +0400 Subject: PEP-343 - Context Managment variant Message-ID: <313379598.20050804110933@intercable.ru> I know I came after the battle. And I have just another sight on context managment. Simple Context Managment may look in Python 2.4.1 like this: Synhronized example: def Synhronised(lock,func): lock.acquire() try: func() finally: lock.release() .... lock=Lock() def Some(): local_var1=x local_var2=y local_var3=Z def Work(): global local_var3 local_var3=Here_I_work(local_var1,local_var2,local_var3) Synhronised(lock,Work) return asd(local_var3) FileOpenClose Example: def FileOpenClose(name,mode,func): f=file(name,mode) try: func(f) finally: f.close() .... def Another(name): local_var1=x local_var2=y local_var3=None def Work(f): global local_var3 local_var3=[[x,y(i)] for i in f] FileOpenClose(name,'r',Work) return local_var3 It was complicated because : 1. We must declare closure (local function) before using it 2. We must declare local vars, to which we wish assign in "global" statement 3. We cannot create variable local to outter function in closure, so we must create it before and declare in global So one can say: "that is because there're no block lambda". (I can be wrong) I think it is possible to introduce block-object in analogy to lambda-object (and function-object) It's difference from function: it has no true self local variables, all global(free) and local variables it steels from outter scope. And all local vars, introduced in block are really introduced in outter scope (i think, during parse state). So its global dicts and local dicts are realy corresponding dicts of outter scope. (Excuse my english) So, may be it would be faster than function call. I don't know. Syntax can be following: lock=Lock() def Some(): local_var1=x local_var2=y local_var3=Z Synhronised(lock,block) local_var3=Here_I_work(local_var1,local_var2,local_var3) return asd(local_var3) def Another(name): local_var1=x local_var2=y FileOpenClose(name,'r',block{f}) local_var3=[[x,y(i)] for i in f] return local_var3 And here is sample of returning value: def Foo(context,proc): context.enter() try: res=proc(context.x,context.y)*2 except Exception,Err: context.throw(Err) finally: context.exit() return res ... context=MyContext() ... def Bar(): result=Foo(context,block{x,y}) continue x+y return result It's idea was token from Ruby. But I think, good idea is good whatever it came from. It can be not Pythonic. From istvan.albert at gmail.com Fri Aug 5 09:50:31 2005 From: istvan.albert at gmail.com (Istvan Albert) Date: 5 Aug 2005 06:50:31 -0700 Subject: The ONLY thing that prevents me from using Python References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> Message-ID: <1123249831.086062.47390@g49g2000cwa.googlegroups.com> There are plenty of webhosts that offer python, do a little research. From xah at xahlee.org Wed Aug 31 05:42:28 2005 From: xah at xahlee.org (Xah Lee) Date: 31 Aug 2005 02:42:28 -0700 Subject: Python doc problems example: gzip module In-Reply-To: <1125477977.072146.298670@g47g2000cwa.googlegroups.com> References: <1125477977.072146.298670@g47g2000cwa.googlegroups.com> Message-ID: <1125481348.490681.271200@g47g2000cwa.googlegroups.com> Today i need to use Python to compress/decompress gzip files. I quickly found the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html I'd imagine it being a function something like GzipFile(filePath, comprress/decompress, outputPath) however, scanning the doc after 20 seconds there's no single example showing how it is used. Instead, the doc starts with some arcane info about compatibility with some zlib module and other software. Then it talks in a very big computer sciency way with bad writing about the main function GzipFile. No perspectives whatsoever about using it to solve a problem nor a concrete description of how it functions. Instead, jargons of Class, Constructor, Object etc are thrown together with presumption of reader's expertise of Python's file objects and gzip technical details. after no understanding, and being not a Python expert, i wanted to read about file objects but there's no link. after locating the file object doc page http://python.org/doc/2.4.1/lib/bltin-file-objects.html itself talks in some obfuscated incomprehensible way. --------------- Here's the detail of the GzipFile description: class GzipFile( [filename[, mode[, compresslevel[, fileobj]]]]) Constructor for the GzipFile class, which simulates most of the methods of a file object, with the exception of the readinto() and truncate() methods. At least one of fileobj and filename must be given a non-trivial value. The new class instance is based on fileobj, which can be a regular file, a StringIO object, or any other object which simulates a file. It defaults to None, in which case filename is opened to provide a file object. yeah, blab blab blab. what the fuck are you talking about? So, how to use it? When fileobj is not None, the filename argument is only used to be included in the gzip file header, which may includes the original filename of the uncompressed file. It defaults to the filename of fileobj, if discernible; otherwise, it defaults to the empty string, and in this case the original filename is not included in the header. what the fuck?? The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb', depending on whether the file will be read or written. The default is the mode of fileobj if discernible; otherwise, the default is 'rb'. If not given, the 'b' flag will be added to the mode to ensure the file is opened in binary mode for cross-platform portability. discernible? so, what the fuck are exactly these modes? can't you describe them concretely? The compresslevel argument is an integer from 1 to 9 controlling the level of compression; 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression. The default is 9. Calling a GzipFile object's close() method does not close fileobj, since you might wish to append more material after the compressed data. This also allows you to pass a StringIO object opened for writing as fileobj, and retrieve the resulting memory buffer using the StringIO object's getvalue() method. huh? append more material? pass a StringIO? and memory buffer? -------------------- Motherfucking 90% of programers using this module really just want to compress or decompress a file. Fuck unix advocates and fuck Perlers and fuck Python morons. PS For more about Python doc, please see: http://xahlee.org/perl-python/re-write_notes.html Xah xah at xahlee.org ? http://xahlee.org/ From python-list at d1z1.de Sat Aug 27 16:38:06 2005 From: python-list at d1z1.de (Dirk Zimmermann) Date: Sat, 27 Aug 2005 22:38:06 +0200 Subject: classes and list as parameter, whats wrong? In-Reply-To: <20050826093420.GC23815@hep.physik.uni-siegen.de> References: <20050826093420.GC23815@hep.physik.uni-siegen.de> Message-ID: <20050827203806.GA2910@picasso> Thanks to everyone! I think I understand the things behind this behaviour, now. And as the life goes: Today I found the description of my "problem" in the Python Tutorial! I think I should read it more often, more carefully:-) Best, Dirk From bsharitt at gmail.com Tue Aug 30 19:44:06 2005 From: bsharitt at gmail.com (bsharitt at gmail.com) Date: 30 Aug 2005 16:44:06 -0700 Subject: py2app and Bittornado In-Reply-To: References: <1125442841.042912.197950@g14g2000cwa.googlegroups.com> Message-ID: <1125445446.261711.248200@g49g2000cwa.googlegroups.com> Yeah, already saw that, which is why I said the py2app wasn't thar much help. That just seems to create a broken .app file. You wouldn't happen to know a nice way to interact with the PythonMac-SIG group without subscribing and subjecting my inbox to rape by a bunch of useless messages would you? Robert Kern wrote: > bsharitt at gmail.com wrote: > > I'm trying to get Bittornado to run on Mac OS X (10.4 with Python > > 2.3.5) but I've only ever dealt with Python at lower lever scripting > > stuff, never wxPython or another GUI stuff. py2app is supposed to be > > the tool to create Mac friendly Python applications(like py2exe on > > Windows), but the documentation for py2app doesn't seem to be much > > help. The setup.py script that comes with BitTornado doesn't run when I > > type python setup.py py2app and produces the following error: > > > > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] > > or: setup.py --help [cmd1 cmd2 ...] > > or: setup.py --help-commands > > or: setup.py cmd --help > > > > error: invalid command 'py2app' (no module named > > 'distutils.command.py2app') > > You need to write a setup.py (actually, probably you should name it > something else like "setup-app.py") that specifies the appropriate > information. From the py2app documentation, the simplest example would be > > from distutils.core import setup > import py2app > > setup( > app=['MyApplication.py'], > ) > > Then you can do > > python setup-app.py py2app > > If you need more help, I suggest asking on the PythonMac-SIG mailing list. > > -- > 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 bokr at oz.net Tue Aug 23 13:34:14 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 23 Aug 2005 17:34:14 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> <1124703805.178363.145870@g49g2000cwa.googlegroups.com> <7x64tyxpxz.fsf@ruckus.brouhaha.com> Message-ID: <430b5c54.2225750710@news.oz.net> On 22 Aug 2005 02:48:24 -0700, Paul Rubin wrote: >"Greg McIntyre" writes: >> while c = f.read(1): >> # ... >> >> I couldn't find any general PEPs along these lines, only specific ones >> (e.g. 308 re. an if-then-else expression). > >I often end up doing something like this: > > class foo: > def set(self, x): > self.x = x > return x > c = foo() > > while c.set(f.read(1)): > # do stuff with c.x > >In that file example, it's too much nuisance, but when you're >comparing some input against a series of regexps and you'd otherwise >need a multi-line construction for each one, this method comes in >quite handy. if you use def __call__ instead of def set, you can also simplify the subsequent spelling e.g, while c(f.read(1)): # do stuff with c.x though something more menmonic than c might be desirable in that case. Regards, Bengt Richter From cantabile.03 at wanadoo.fr Sat Aug 6 12:19:12 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Sat, 06 Aug 2005 18:19:12 +0200 Subject: about coding In-Reply-To: References: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> Message-ID: <42f4e300$0$25042$8fcfb975@news.wanadoo.fr> Robert Kern a ?crit : > It depends. Are those characters encoded as UTF-8? Or, more likely, are > they encoded as ISO-8859-1? > >> Where can I find a pratical explanation about these encodings ? > > > http://www.amk.ca/python/howto/unicode > http://en.wikipedia.org/wiki/Character_encoding > http://www.joelonsoftware.com/articles/Unicode.html > I'm using emacs. I guess this is utf-8 encoded... Thanks for the links :) From travislspencer at gmail.com Fri Aug 19 16:07:25 2005 From: travislspencer at gmail.com (travislspencer at gmail.com) Date: 19 Aug 2005 13:07:25 -0700 Subject: A script to run all of my project's pyunit tests In-Reply-To: <1124480181.121430.105050@g49g2000cwa.googlegroups.com> References: <1124480181.121430.105050@g49g2000cwa.googlegroups.com> Message-ID: <1124482045.430114.295630@o13g2000cwo.googlegroups.com> travislspencer at gmail.com wrote: > for file in glob(projHome + "/tests/*.py"): > start = file.rfind("/") + 1 > end = file.rfind(".") > moduleName = file[start:end] > module = __import__(moduleName) klass = module.__dict__[module.__name__] tests.append(unittest.makeSuite(klass, "test")) > allTests = unittest.TestSuite(tests) > runner = unittest.TextTestRunner(verbosity=2) > > runner.run(allTests) This is still a kludge, but a different and less annoying one. It works as long as the TestCase class and module have the same name. Back to the drawing board... -- Regards, Travis Spencer From bokr at oz.net Thu Aug 11 16:42:57 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 11 Aug 2005 20:42:57 GMT Subject: command line reports References: <67Cdnd00Bo62PWbfRVn-1w@powergate.ca> Message-ID: <42fbb12b.1198953554@news.oz.net> On Thu, 11 Aug 2005 15:43:23 -0400, Darren Dale wrote: >Peter Hansen wrote: > >> Darren Dale wrote: >>> Is there a module somewhere that intelligently deals with reports to the >>> command line? I would like to report the progress of some pretty lengthy >>> simulations, and currently I have the new reports written on a new line >>> rather rather than overwriting the previous report. >> >> You mean you want sys.stdout.write(report + '\r') instead of "print >> report" ? >> >> It's not really clear what you want. What's a "report" to you? >> >> -Peter > >I am printing something like > >trial 1 of 100 >trial 2 of 100 >... Peter's suggestion will work, but it's easy to get something like >>> import sys, time >>> def test(): ... for i in xrange(5): ... sys.stdout.write(('trial %s of 5'%(i+1)) + '\r') ... time.sleep(.25) ... print "We're done!" ... >>> test() We're done!5 ^--(note leftover from last "report: line) By the same token (more or less ;-) if your "report" line shortens during progress (e.g., changing from 'long_name_test trial 100 of 100' to 'short_name trial 1 of 10' you will likely see 'short_name trial n of 10 of 100' for a while, unless you pad the report line with blanks to a constant length. Also, I guess some platforms could require flushing stdout to be sure of seeing the latest line as you go. > >so I get 100 lines by the time the code is finished. I would like to replace >the previous report with the current one, so I only use one line by the >time the code is finished. > >I was also hoping that there was a set of tools out there for spinners, >meters, etc... The question with python for this kind of thing is usually, "Which will be faster, googling for it, or writing it?" ;-) Regards, Bengt Richter From ptmcg at austin.rr.com Tue Aug 16 09:27:02 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 16 Aug 2005 06:27:02 -0700 Subject: How can I exclude a word by using re? References: <430085e8$1@news.eftel.com> <1124165702.590364.107410@o13g2000cwo.googlegroups.com> <1124198308.584668.69390@g14g2000cwa.googlegroups.com> Message-ID: <1124198822.785871.143970@o13g2000cwo.googlegroups.com> Oof! That should be: mp3entry = valign + number.setResultsName("number"??) + tdEnd + \ tdStart + SkipTo(aStart) + aStart + \ SkipTo(tdEnd).setResultsName("n?ame") + tdEnd From bob at passcal.nmt.edu Mon Aug 1 20:39:43 2005 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 1 Aug 2005 18:39:43 -0600 Subject: Tkinter, Menu(bar) font size Message-ID: Option adding "Menu*font" changes the font size of the _commands, _radiobuttons, etc., but not the "File", "Edit", etc. labels on the menubar itself. What is the name for those labels? If I go Top.add_cascade(Label = "File", menu = Fi, font = "Courier 20") they change, but I can't figure out the name for the option_add. I'm not really trying to use Courier 20. :) Thanks! Bob From jeremy at emperorlinux.com Thu Aug 11 17:02:51 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Thu, 11 Aug 2005 17:02:51 -0400 Subject: Python Wireless Extension Module (pyiw) Message-ID: <1123794171.4559.15.camel@localhost.localdomain> I am mostly done with writing an extension module in C that wraps (and makes easier) interfacing with libiw (the library that powers iwconfig, iwlist, and friends on Linux). We're using this internally for a tool to manage wireless connectivity. This is a million times better than hundreds of invocations of the iw* suite of tools. :) Would anyone else find something like this useful? I know a few distros maintain their own suite of config tools, but I don't think there is yet an actual binding for python. Anyway, I am just curious... we plan on using it, at any rate. It's already made the code easier to read, faster, and more reliable. # example usage --------------------------------- wlan = pyiw.WirelessInfo("wlan0") nets = wlan.Scan() for net in nets: print net.signal_quality wlan.essid wlan.key wlan.protocol wlan.essid = "LV-426" wlan.Reconfigure() -------------------------------------------------- From spam.csubich+block at block.subich.spam.com Wed Aug 10 21:18:39 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 10 Aug 2005 21:18:39 -0400 Subject: PEP 328, absolute/relative import In-Reply-To: References: Message-ID: Ben Finney wrote: > Once PEP 328 is fully implemented, all bare 'import foo' statements > specify absolute imports (i.e. from sys.path only). To perform a > relative import (e.g. from current directory) will require different > syntax. I'm not completely familiar with either, but how will that influence the __import__ function? From sjmachin at lexicon.net Mon Aug 15 08:09:12 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Aug 2005 22:09:12 +1000 Subject: How can I exclude a word by using re? In-Reply-To: References: Message-ID: <430085e8$1@news.eftel.com> could ildg wrote: > In re, the punctuation "^" can exclude a single character, but I want > to exclude a whole word now. for example I have a string "hi, how are > you. hello", I want to extract all the part before the world "hello", > I can't use ".*[^hello]" because "^" only exclude single char "h" or > "e" or "l" or "o". Will somebody tell me how to do it? Thanks. (1) Why must you use re? It's often a good idea to use string methods where they can do the job you want. (2) What do you want to have happen if "hello" is not in the string? Example: C:\junk>type upto.py def upto(strg, what): k = strg.find(what) if k > -1: return strg[:k] return None # or raise an exception helo = "hi, how are you? HELLO I'm fine, thank you hello hello hello. that's it" print repr(upto(helo, "HELLO")) print repr(upto(helo, "hello")) print repr(upto(helo, "hi")) print repr(upto(helo, "goodbye")) print repr(upto("", "goodbye")) print repr(upto("", "")) C:\junk>upto.py 'hi, how are you? ' "hi, how are you? HELLO I'm fine, thank you " '' None None '' HTH, John From tjreedy at udel.edu Fri Aug 26 17:07:18 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Aug 2005 17:07:18 -0400 Subject: classes and list as parameter, whats wrong? References: <20050826093420.GC23815@hep.physik.uni-siegen.de><7ee3dcd80508260242717153fb@mail.gmail.com> <20050826111532.GD23815@hep.physik.uni-siegen.de> Message-ID: "Dirk Zimmermann" wrote in message news:20050826111532.GD23815 at hep.physik.uni-siegen.de... > But still, it is not absolutely clear for me, what is going on. So, at > least just for my understanding: The parameter LL is created just once > for the whole class and not for the object (because I del the object > explicitly, which should destroy the object)? Default parameter values are created (once) for the function, not for the class or instance. Function default parameter expressions are evaluated once and only once when the function is defined. Code that you want evaluated with each call goes in the function body. Terry J. Reedy From peter at engcorp.com Tue Aug 9 20:40:32 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 09 Aug 2005 20:40:32 -0400 Subject: python for microcontrollers In-Reply-To: <42f91c1c$1@news.orcon.net.nz> References: <42f7c8d4$1@news.orcon.net.nz> <7xd5oof5qj.fsf@ruckus.brouhaha.com> <42f91c1c$1@news.orcon.net.nz> Message-ID: Evil Bastard wrote: > Paul Rubin wrote: >> Pick a different language. > > Maybe I should clean up my forth compiler instead, and get it ready for > the prime time. In searching for an existing Lua virtual machine** for the PIC, following on my previous posting, I came across several references to Forth implementations for the PIC. Maybe rolling your own isn't necessary here. -Peter ** I was rather surprised to discover a distinct lack of evidence that anyone has a Lua VM for the PIC. There appear to be traces of interpreters written for chips of similar scale to the PIC 18F series, but none specifically for the PIC. So while it would probably make an interesting project, and I'm pretty sure it's quite feasible, grabbing an off the shelf Forth might be a more productive use of your time. From no at spam Wed Aug 24 18:50:08 2005 From: no at spam (D H) Date: Wed, 24 Aug 2005 17:50:08 -0500 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <7xvf1vgg9h.fsf@ruckus.brouhaha.com> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <8764tw8def.fsf@bigfoot.com> <7xvf1vgg9h.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Richie Hindle writes: > >>I can't speak for linode.org, but I have a Xen VPS from rimuhosting.com >>and it's early days but so far I've been very impressed. It's $19/mo >>(normally $20 but they kindly gave me a 5% Open Source Developer discount) > > > Do you get enough resources in that minimal-cost configuration to run > significant Python applications? Yes, you get more than enough to run python apps. You have to know how to run your own linux box though, including installing and configuring any extra software you want (with debian it's very easy using 'sudo apt-get'). Mod_python for example and apache2. I would look for a minimum 64mb ram, 3 gigs hd space, and minimum 15 gigs transfer/mo. At $20/mo, rimuhosting gives you 96mb ram, 4gig space, and 30gigs transfer/mo. So that does look like a good deal. (I don't use or work with any UML hosting provider. I used to have Bytemark, and it was great, although it looks like rimu and others may offer more for your buck now) The catch is the RAM restriction, which you might run into if you have huge mysql databases or whatever, and hard drive access is a slower than on a dedicated server. But I never noticed any slowdowns or ran into ram limitations. From tprimke at interia.pl Fri Aug 5 07:46:29 2005 From: tprimke at interia.pl (TPJ) Date: 5 Aug 2005 04:46:29 -0700 Subject: installing python2.4.1 In-Reply-To: References: Message-ID: <1123242389.288016.42570@z14g2000cwz.googlegroups.com> There are two things I don't like about messages you got. > checking for g++ ... no and > C++ compiler cannot create executables There are two possibilities I can think of now. The first is you have no g++ installed. In this case you should install it (I think it would be very easy, you could install it from the proper deb package). The second is there is a working g++, but ./configure fails to detect it. BTW: Have you tried to compile a simple C program by yourself? From steve at holdenweb.com Sun Aug 21 21:44:48 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 02:44:48 +0100 Subject: Decorator and Metaclasses Documentation In-Reply-To: References: <1124668873.380249.119630@f14g2000cwb.googlegroups.com> Message-ID: sysfault wrote: > On Sun, 21 Aug 2005 17:01:13 -0700, Jeffrey E. Forcier wrote: > > >>Amusingly, I was just perusing these links earlier today. Go go Firefox >>history search! >> >>http://www.python.org/2.2/descrintro.html >>http://users.rcn.com/python/download/Descriptor.htm > > > > Are descriptors the same thing as decorators? No. In brief: Decorators are a mechanism whereby a function or method can be transparently wrapped by another function. Descriptors are used to hook programmed functionality into the basic access mechanisms of object attributes. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From petr at tpc.cz Tue Aug 23 15:59:03 2005 From: petr at tpc.cz (McBooCzech) Date: 23 Aug 2005 12:59:03 -0700 Subject: py-serial + CSV In-Reply-To: References: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> <1124820032.854336.278790@f14g2000cwb.googlegroups.com> Message-ID: <1124827143.570187.129300@g14g2000cwa.googlegroups.com> Sergei, I do not realy understand your comment??? Am I missing something? BTW, is there some possibility to address lists like: print words [1; 3; 5] instead of print words[1], words[3], words[5] Petr Jakes From cito at online.de Wed Aug 3 03:35:08 2005 From: cito at online.de (Christoph Zwerschke) Date: Wed, 03 Aug 2005 09:35:08 +0200 Subject: Art of Unit Testing In-Reply-To: References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> Message-ID: Benjamin Niemann wrote: > The unittest module is a 'port' of the JUnit framework for Java which has a > certain wellknown API and semantics. The same API is available for many > other languages, so it is probably a good idea to stick with it in order to > make people coming from other language feel more comfortable with Python. Ok, that's a good reason. I just had a look at the JUnit homepage. It seems like unittest has only implemented a part of JUnit. But you're right, even JUnit lacks setUpOnce and tearDownOnce. I found the following excuse and workaround in the JUnit FAQ: http://junit.sourceforge.net/doc/faq/faq.htm#organize_3 > Some (many?) people don't like the unittest module, because it is not very > pythonic - nothing to wonder as it has its root in the Java world. That's > probably one of the reasons why there are other (more pythonic) unittesting > frameworks for Python out there. So I think it would have been better that "unittest" had been named "PUnit" to make clear that it is a JUnit port and to allow a more pythonic testing framework to be added to the Python's standard lib. > I prefer to use unittest (because this was the API the textbook was using > that introduced me to this topic) and I also had the problem of heavy setup > costs. I deal with it by using a script around my testsuite (instead of > calling just unittest.main()) that does the setup/teardown of the > environment. Yes, I think that's the simplest solution. -- Christoph From john at castleamber.com Thu Aug 25 13:43:27 2005 From: john at castleamber.com (John Bokma) Date: 25 Aug 2005 17:43:27 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> Message-ID: "T Beck" wrote: > If we argue that people are evolving the way e-mail is handled, and > adding entire new feature sets to something which has been around > since the earliest days of the internet, then that's perfectly > feasable. HTML itself has grown. We've also added Javascript and > Shockwave. They are not additions to HTML, like PNG is no addition to HTML, or wav, mp3, etc. > The websites of today don't even resemble the websites of > 10 years ago, Depends a lot on what site you visit. You can make a website of 10 years ago look modern with roughly the same HTML of 10 years ago, and a style sheet. (E.g. visit: http://johnbokma.com/ and turn off the stylesheet. And there are way better examples) > e-mail of today only remotely resembles the original, so Because there is no real alternative to email? If there was, email would have died, at least for me, long ago. > the argument that usenet should never change seems a little > heavy-handed and anachronistic. No, simple since there *are* alternatives: web based message boards. Those alternatives *do* support HTML formatting (often the subset mentioned earlier). However, Usenet is a stranger to most people on the Internet, even with Usenet access, and hence, there is no real reason to see it changed into something that is "available" for years and years to more people: www. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From opengeometry at yahoo.ca Sun Aug 28 13:10:36 2005 From: opengeometry at yahoo.ca (William Park) Date: Sun, 28 Aug 2005 13:10:36 -0400 Subject: formal math ? References: <1125186266.843702.254220@f14g2000cwb.googlegroups.com> Message-ID: <24a75$4311f00c$d8fe9c49$6023@PRIMUS.CA> mehdi.rabah at gmail.com wrote: > Hi, > > I have just discovered python and it seems so easy ans so powerful to > me that it remind me matlab or maple programming language (sorry free > software purists ears). > > So I was wondering if there a sort of formal math library, that can do > a thing like: > > lib.solve("x+1=0") > -> x=-1 > > I have checked numarray and I think it can not do this. > > Thanks in advance, No, you need to type some more. :-) You need to define function def f(x): return x + 1 and call root solver, either from a library or function imported from module. For simple cases, I use RPN calculator recently added to Bash shell, like rpn 'f(x)= 1 +' 0 1 secant = rpn 'f(x)= 1 +' 'fd(x)= 1' 0 newton = -- William Park , Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From rex.eastbourne at gmail.com Tue Aug 30 18:27:14 2005 From: rex.eastbourne at gmail.com (Rex Eastbourne) Date: 30 Aug 2005 15:27:14 -0700 Subject: Bicycle Repair Man usability Message-ID: <1125440834.163913.49830@g44g2000cwa.googlegroups.com> Are there any Bicycle Repair Man users here? I recently got PyDev for Eclipse, which comes with BRM. I am disappointed with what I've seen, although I'm not sure if I'm using its full functionality. According to PyDev's documentation, this is what one can do: -Rename a function/variable -Block of code --> method and a method call -Get rid of extra variables by shifting them inline (e.g.: a=1;b=2;c=a+b --> c=1+2) I'm not aware of anything else that can be done, as BRM's documentation is extremely thin. Is anyone else aware of other uses? It's a shame this project is not active; it seems like such a great idea. Rex From bill.mill at gmail.com Thu Aug 25 14:42:20 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 25 Aug 2005 14:42:20 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <20050825182936.GE5991@performancedrivers.com> References: <430E0C8D.5000506@ceid.upatras.gr> <20050825182936.GE5991@performancedrivers.com> Message-ID: <797fe3d4050825114242e5e600@mail.gmail.com> On 8/25/05, Jack Diederich wrote: > On Thu, Aug 25, 2005 at 09:23:09PM +0300, Stelios Xanthakis wrote: > > The explanation is this: hash > > and comparison of objects depends on the state of the memory > > allocator. A sample case is this: > > > > class A: pass > > dummy0=47 # comment this to get a different result for min > > a=A() > > b=A() > > print min (a, b) > > > > the result of 'min' is not only non-deterministic but also depends > > on whether other things have been allocated before. The same > > thing can happen for 'dictionary.keys()' if the keys are objects > > and 'iterate-over-set' when the set contains objects. > > I'm also pretty sure I've caught a bug in his code, though I'm not sure how it works exactly. I replaced the 'min' built-in with my own min, and he's going to get nondeterministic results from this line: mm = min((c.S, c) for c in rowitems(h))[1].D because 'c' is often the exact same object. A snippet from my debugging version of 'min', which prints out the tuple its handed: (1, <__main__.LLentry object at 0x00969710>) (1, <__main__.LLentry object at 0x00969710>) (4, <__main__.LLentry object at 0x00969710>) (4, <__main__.LLentry object at 0x00969710>) (3, <__main__.LLentry object at 0x00969710>) (3, <__main__.LLentry object at 0x00969710>) (3, <__main__.LLentry object at 0x00969710>) (2, <__main__.LLentry object at 0x00969710>) Although they appear in order here, they don't always. Often, multiple objects have a value of 1, and he's going to get one of them at random as the 'min' object. I'm pretty sure. Mark, can you confirm that this is/isn't a bug? (btw, it still runs fast with and slow without the dummies with my custom min() func) Peace Bill Mill bill.mill at gmail.com From Scott.Daniels at Acm.Org Mon Aug 22 13:33:38 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Aug 2005 10:33:38 -0700 Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? In-Reply-To: References: Message-ID: <430a0082$1@nntp0.pdx.net> Magnus Lycka wrote: > If you remove all *.pyc and *.pyo, they will be regenerated as needed. > If your code only uses a small fraction of the standard library, you > will save quite some space here. The only reason they are generated on > installation is to save some runtime on first use of a module, and > perhaps aviod the surprise of an installation that continues to grow > after a completed installation... Another reason is to allow efficient access to python for users who do not have permission to create files (the .pyc and .pyo files) in Python's library directories. --Scott David Daniels Scott.Daniels at Acm.Org From tdelaney at avaya.com Wed Aug 10 16:32:16 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Thu, 11 Aug 2005 06:32:16 +1000 Subject: "Ordered" dicts Message-ID: <2773CAC687FD5F4689F526998C7E4E5F0742AD@au3010avexu1.global.avaya.com> Martin Miller wrote: > To avoid continued reinvention of this wheel, I'd also vote to have > this functionality be at least included in a standard module, if not > built-in. This has been discussed on python-dev (I proposed it actually). The final consensus was that no such implementation would be included at this time, as it's a pretty simple thing to implement, and there are already several implementations in the Cookbook. My arguments included the fact that there were several implementations in the Cookbook as an indication it should be included in the standard library ... Thread starts here: http://mail.python.org/pipermail/python-dev/2005-March/051915.html Tim Delaney From berlin.brown at gmail.com Mon Aug 8 22:51:49 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Mon, 08 Aug 2005 22:51:49 -0400 Subject: Python Project (sigh with Java) Message-ID: I know you may frown at my use at java, but this is a pretty simple way to create GUIs quickly, using Java's swing. I have some code for an approach for integrating the swing GUI components and python. I threw the project together in a couple of days, so it is not some massive application. And, I have some little models(hehe). Anyway, if you want to check out an approach for working with Jython, here it is. Some questions, I do get asked, how do you us python code in java. I normally don't like using my python objects in the java code. Basically, there is never the *.java files. You can do everything in python, it is a lot simpler, short of language constructs you can only do in java. This is a HTML code generator, you only need a java runtime. http://www.newspiritcompany.com/phoenixproj.html -- Ramza from Atlanta http://www.newspiritcompany.com From garabik-news-2005-05 at kassiopeia.juls.savba.sk Fri Aug 5 03:27:00 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Fri, 5 Aug 2005 07:27:00 +0000 (UTC) Subject: using Pyro for network games References: Message-ID: Michael Rybak wrote: > gn20kjss> Do not use pyro, use simple UDP protocol. > gn20kjss> I've written networked tetris in python, communicating via > gn20kjss> UDP protocol, and used it successfully on very congested lines. > > Would you please be so kind to share that with me? That would be http://melkor.dnp.fmph.uniba.sk/~garabik/pytris.html contrary to what the page says, you do not need pyncurses, just plain curses as included with modern pythons > greatly helpful, because 1) I'd run it together with my friend to see > what speed I can get from UDP 2) I'd grasp the networking part of your > code and reuse it. see the Net() class. I recommend you to use the same number for myport and otherport (you can with UDP, and it makes traversing firewalls easier) > > gn20kjss> If all you need is to transfer pointer coordinates, UDP is perfect since > gn20kjss> you do not need feedback. > > gn20kjss> use something like this for server: > > gn20kjss> import socket > gn20kjss> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > gn20kjss> s.bind(('', port)) > gn20kjss> while 1: > gn20kjss> data, addr = s.recvfrom(1024) > gn20kjss> print `data` > > > gn20kjss> and for client: > > gn20kjss> import socket > > gn20kjss> outsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > gn20kjss> outsock.bind(('', 0)) > gn20kjss> outsock.sendto('message', ('server-hostname', server_port)) > Would you recommend some reading on this? I have some immediate just the socket.socket documentation, and generally for UDP protocol, see e.g. http://www-net.cs.umass.edu/kurose/transport/UDP.html Using it is very simple, on one computer, you send a (short) string, and on the other computer you receive the string (or it might be lost on the way). For your situation, I'd recommend to implement some sort of time constrain - e.g. if user moves cursor very fast, ensure that the coordinates are not transmitted with higher frequency that 50 Hz (or something). And combine the coordinates into one packet - it always helps to reduce the number of packets. > questions to your code, but don't want to flood here. OK, I will flood > here a bit: what's the print `` syntax? the same as repr, i.e. textual representation of a variable - good for debugging > > P.S. I loved your virus alert ;) > and you got infected I see :-) -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From fabioz at esss.com.br Wed Aug 24 08:27:38 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Wed, 24 Aug 2005 09:27:38 -0300 Subject: jython debugger In-Reply-To: <1124880688.306010.10820@g49g2000cwa.googlegroups.com> References: <1124880688.306010.10820@g49g2000cwa.googlegroups.com> Message-ID: <430C67BA.2050009@esss.com.br> wait one more week... until there, pydev (http://pydev.sf.net) should already have debugger support for jython. Cheers, Fabio volpadri at aliceposta.it wrote: >Hi, >I am looking for an ide debugger for jython: is there someone with >some suggestions ? > >Thanks, > Adriano > > > -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From dcrespo at gmail.com Mon Aug 15 11:26:45 2005 From: dcrespo at gmail.com (dcrespo) Date: 15 Aug 2005 08:26:45 -0700 Subject: SOAP and XMLRPC In-Reply-To: References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> <1124115078.926129.285880@f14g2000cwb.googlegroups.com> <4300A5DF.4080903@chamonix.reportlab.co.uk> Message-ID: <1124119605.147443.227920@z14g2000cwz.googlegroups.com> I'm looking for code under VB6 :(... I'm looking everywhere. I hope I get luck. From bronger at physik.rwth-aachen.de Mon Aug 8 03:39:01 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Mon, 08 Aug 2005 09:39:01 +0200 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> Message-ID: <87ll3c6foq.fsf@wilson.rwth-aachen.de> Hall?chen! "Terry Reedy" writes: > [...] Consider > > Hypothesis 1: someone learned Python and Tkinter, felt > dissatisfied with Tkinter, went searching the universe for an > alternative, found GTK, and wrote PyGTK, perhaps learning C in the > process. > > Hypothesis 2: a C-programmer who is a satisfied user of GTK (on > *nix, presumably) learns Python. "Neat, but I also want to keep > using GTK." Which he can because it is relatively easy. > > Repeat H1 and H2 for every wrapping. You believe in H1. I > suspect H2 is more often true, but admit I have no data. It is probably H2 (otherwise the reluctance to learn GTK so thoroughly would be too great) but with the important addition that the creator of PyGTK felt the general dissatisfaction with Tkinter. Getting users is a very very important motivation for a developer after all. >> That by itself says the stdlib is lacking. > > I have an alternate interpretation. There is a Python wrapping > for as many C libraries as there are because Python is neat and > wrapping is fairly easy and the rewards great. Yes, absolutely; but for the core functionality (which must contain a good GUI toolkit in my opinion) you should have more that just a "binding". Instead, it should be well-embedded into the standard library and the language. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From fakeaddress at nowhere.org Wed Aug 10 09:22:14 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 13:22:14 GMT Subject: Why is this? In-Reply-To: References: Message-ID: Jiri Barton wrote: > Yes, now it is clear! > > As always, I should have RTFM, the operator* is not just a syntactic sugar > and thus does not make copies. That issue bites, like, everyone. > You know, my actual scenario was with four > variables at the time: > > a, b, c, d = [], [], [], [] Incidentally, to create a list of 37 distinct empty lists, you can use: [[] for _ in range(37)] -- --Bryan From guettli at thomas-guettler.de Mon Aug 29 08:00:32 2005 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Mon, 29 Aug 2005 14:00:32 +0200 Subject: ideas for university project ?? References: Message-ID: Am Fri, 26 Aug 2005 12:21:36 -0400 schrieb Steve Holden: > Thomas Guettler wrote: >> Am Fri, 26 Aug 2005 11:49:34 +0100 schrieb Jon Hewer: >> you could port Python to the WRT54. >> The Linksys WRT54 is a WLAN-Router which runs Linux. >> See http://openwrt.org/ >> I think it is a good project for a university. It is software >> and hardware related. >> >> Thomas >> > It would be a good final-year project, but you may want to try something > that hasn't already been done ... see > > http://skreak.com/wrt54g/python.php Hi, I know this. This is NFS mounted. You could strip down python to get it running standalone. Thomas -- Thomas G?ttler, http://www.thomas-guettler.de/ From adsheehan at eircom.net Wed Aug 17 08:23:16 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 17 Aug 2005 05:23:16 -0700 Subject: Urgent: Embedding Python problems - advice sought In-Reply-To: <1124236492.970194.270970@g47g2000cwa.googlegroups.com> References: <1124236492.970194.270970@g47g2000cwa.googlegroups.com> Message-ID: <1124281396.055192.66840@o13g2000cwo.googlegroups.com> Does anyone have advice on other groups, sites etc that has knowledge of this subject ? Thanks From jepler at unpythonic.net Fri Aug 5 12:36:31 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Fri, 5 Aug 2005 11:36:31 -0500 Subject: Euclid's Algorithm in Python? In-Reply-To: <1123211591.741161.297570@g49g2000cwa.googlegroups.com> References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> Message-ID: <20050805163627.GE19009@unpythonic.net> On Thu, Aug 04, 2005 at 08:13:11PM -0700, Jordan Rastrick wrote: > Raising an assertion error for a < b is a bit of overkill, since its > not really a case of bad input. So normally you see Euclid done like > this: [snipped] My point was not so much that this was the ultimate implementation of GCD, but that the obvious search would have turned up many enlightening results, including the topmost one. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From peter at engcorp.com Wed Aug 31 08:18:43 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 31 Aug 2005 08:18:43 -0400 Subject: use threading without classes In-Reply-To: References: Message-ID: billiejoex wrote: > Hi all. Hi would like to use two threads in a program but all the examples I > found on the net use oop programming that I doesn't love too much. :-) > Can you code me a short example in wich two different functions are executed > at the same time, plz? import time from threading import Thread def func1(): print 'first func running' time.sleep(1) print 'first func done' def func2(): print 'second func running' time.sleep(1) print 'second func done' Thread(target=func1).start() Thread(target=func2).start() Note that this is still using "OOP programming", and you can't effectively avoid this in Python without jumping through more hoops than you're really interested in, but this basically avoids the need to do OOP things like subclassing. -Peter From peter at somewhere.com Wed Aug 31 09:55:35 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 15:55:35 +0200 Subject: .pth files in working directory In-Reply-To: References: Message-ID: Peter Hansen schrieb: > Peter Maas wrote: >> But sitecustomize.py changes the Python installation, doesn't it? >> This wouldn't be an advantage over putting a .pth file into >> .../site-packages. > > > You can have a local sitecustomize.py in the current directory, which > wouldn't change the Python installation. Would that help? I think this is what I need. Thanks, Peter. -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From http Mon Aug 8 13:10:49 2005 From: http (Paul Rubin) Date: 08 Aug 2005 10:10:49 -0700 Subject: Python -- (just) a successful experiment? References: <1123422959.086345.76190@g49g2000cwa.googlegroups.com> Message-ID: <7xek94z752.fsf@ruckus.brouhaha.com> Cliff Wells writes: > The second presentation (I don't recall the speaker's name) specifically > covered metaprogramming (writing DSLs) and one of the things I found > interesting was that despite Ruby having far more syntax than Python in > general, the resulting Ruby-based DSLs presented had far *less* syntax > than had they been written in Python. This is undoubtedly the reason > why Rails is apparently completely usable even if one knows very little > Ruby. Interesting. But if we can generalize from that, then Lisp should be ruling the web. From jstroud at mbi.ucla.edu Mon Aug 1 15:40:58 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 1 Aug 2005 12:40:58 -0700 Subject: Dabo in 30 seconds? In-Reply-To: <200508011517.41240.ed@leafe.com> References: <200508011200.35374.jstroud@mbi.ucla.edu> <200508011517.41240.ed@leafe.com> Message-ID: <200508011240.58566.jstroud@mbi.ucla.edu> On Monday 01 August 2005 12:17 pm, Ed Leafe wrote: > So in a way, I *do* expect someone > who has foregone the binary route and chosen the source route to at least > read the build instructions. There is no mention of stylized text controls in either the wxPython build or install pages of the www documentation. It is probably there, hidden in a very obvious place that someone would be expected to read if they wanted to use it enough to dig for something they don't know there looking for. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From trentm at ActiveState.com Thu Aug 25 17:04:52 2005 From: trentm at ActiveState.com (Trent Mick) Date: Thu, 25 Aug 2005 14:04:52 -0700 Subject: minimalist regular expression In-Reply-To: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> Message-ID: <20050825210452.GE10178@ActiveState.com> [borges2003xx at yahoo.it wrote] > Exists some tool, programs or some able to compute the minimal regular > expression, namely ,taking a series of regular exoression, the minimal > one that makes the same matching? def get_minimal_regex(*regexes): return ".*" :) Or, slightly less smart-ass-y: def get_not_really_minimal_regex(*regexes): return "(" + "|".join(regexes) + ")" Trent -- Trent Mick TrentM at ActiveState.com From john at castleamber.com Fri Aug 26 09:24:57 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 13:24:57 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> Message-ID: Dragan Cvetkovic wrote: > John Bokma writes: > >>> A forum provides a >>> single, usually rather limited, interface for the user with no way >>> for the user to change it radically. >> >> Does the user want this? And with a user stylesheet you can change it >> quite radically :-) >> >> And in return the user gets: colors, fonts, font sizes, embedding of >> images, flash, you name it. Moving avatars, even sounds. > > Sounds scary. When I want to read a text, I don't need the whole > multimedia experience. so use Lynx :-) One forum I visit is about scorpions. And really, it talks a bit easier about scorpions if you have an image to look at :-D. In short: Usenet = Usenet, and www = www. Why some people want to move people from www to Usenet or vice versa is beyond me. If 80% of the current Usenet users stop posting, Usenet is not going to die :-D -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From rich.teer at rite-group.com Tue Aug 23 12:42:54 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Tue, 23 Aug 2005 16:42:54 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> Message-ID: On Tue, 23 Aug 2005, Mike Schilling wrote: > A formatting-only subset of HTML would be useful for both e-mail and Usenet > posts. Nope; plain text for both mediums is, IMHO, th eonly way to go. -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From renting at astron.nl Wed Aug 31 03:12:28 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 31 Aug 2005 09:12:28 +0200 Subject: Bicycle Repair Man usability Message-ID: I know the Eric3 Python IDE integrates with BRM, but I haven't had a need for much refactoring yet, so I haven't installed BRM. I've only used Eric3's build-in limited refactoring yet. Adriaan Renting. From jpopl at interia.pl Mon Aug 29 03:44:47 2005 From: jpopl at interia.pl (Jacek =?iso-8859-2?Q?Pop=B3awski?=) Date: Mon, 29 Aug 2005 07:44:47 +0000 (UTC) Subject: telnet.read_until() from telnetlib References: <1125075800.736986.28480@g43g2000cwa.googlegroups.com> Message-ID: I have same problem with expect :-( I am calling: l=[expected] result=self.telnet.expect(l,timeout) it works in most cases, but sometimes (with exacly same "expected" value) it returns -1,Nil,"some text" the point is, that: - connection is still active, so it should read more! - it doesn't wait timeout seconds (I used time.time() to check that, time is zero, timeout is about 20s)! In what case "expect" or "read_until" will stop reading without waiting for timeout? -- Free Software - find interesting programs and change them NetHack - meet interesting creatures, kill them and eat their bodies Usenet - meet interesting people from all over the world and flame them Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net From rkern at ucsd.edu Sat Aug 6 03:04:49 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 00:04:49 -0700 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: Daniel Sch?le wrote: > [...] > > > Derive your own subclass of complex and define those methods. > > I think something as basic as an angle/arg of complex number > definetly belongs to the interface, and it would not even require a > great effort to put it there Okay. Write a patch. Personally, I would prefer that it be a function in cmath rather than a method because then it could be made to work on integers and regular floats, too. > most complex formulas out there use Euler representation > it's a waste of code lines (and programmers time) > to write 3 liner functions for the transformion between > a+bj <-> (r,angle) It's a very, very tiny outlay of effort on the programmer's part that only has to happen once in their career. > Python makes things covenient > so we have complex numbers in the core language > the calculations where perfectly possible without them > using (re, im) tupels and many many sin/cos in the code > but imagine how ugly it would be .. I don't have to imagine. It's not all that ugly. > I would like see Python as a competitor to Matlab etc I think it is already. -- 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 s_david_rose at hotmail.com Fri Aug 19 09:22:52 2005 From: s_david_rose at hotmail.com (GMane Python) Date: Fri, 19 Aug 2005 09:22:52 -0400 Subject: Save Binary data. Message-ID: Hello All. I have a program that downloads 'gigabytes' of Axis NetCam photos per day. Right now, I set up the process to put the images into a queue, and every 30 or so seconds, 'pop' them from the queue and save them to disc. I save them as individual files. I think that I'd like to modify it to save into one file 100-200 images, so that I don't have directories with 50,000-90,000 frames before handing that off to a DivX Encoder. I don't know if I need to use something like cPickle, or maybe just save them as a binary data file (which would be a temp file until later in the day when I open it to begin the encoding process.) Can someone please help me with some direction? Thank you! Dave From roland at catalogix.se Tue Aug 23 10:10:48 2005 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 23 Aug 2005 16:10:48 +0200 Subject: Network performance In-Reply-To: References: Message-ID: <50669F4F-2150-47AF-9F4D-B5B256EA66ED@catalogix.se> 23 aug 2005 kl. 15.14 skrev Sion Arrowsmith: > Roland Hedberg wrote: > > > The easy solutions are to either change: > > >> def send( self, rdf ): >> self.s.send( rdf ) >> self.s.send( "\n" ) >> > > to > > def send( self, rdf ): > self.s.send( rdf+"\n" ) > > or to self.s.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0) after > connecting self.s . I had just caught this but didn't really know way yet! > What's going on is something like this: Excellent description ! Thanks ever so much !! -- Roland From donn at u.washington.edu Fri Aug 12 19:01:18 2005 From: donn at u.washington.edu (Donn Cave) Date: Fri, 12 Aug 2005 16:01:18 -0700 Subject: Bug on Python2.3.4 [FreeBSD]? References: Message-ID: In article , Uwe Mayer wrote: > Friday 12 August 2005 22:12 pm paolino wrote: > [...] > >>>>>f = open('test', 'a+') > >>>>>f.read() > >> > >> '' > >> > >> -> append mode does not read from file, *not ok* > >> > >> > > This is right IMO 'a' is appending so seek(-1) > > True, thank you. > f.tell() shows the file pointer is at EOF. On my Debian Linux (unstable), > Python 2.3.4 +2.3.5, however, the file pointer is at the beginning of the > file. > Is that behaviour intended? I don't think Python pretends to have any intentions here, it has to take what it gets from the C library fopen(3) function. BSD man pages generally say a+ positions the stream at end of file (period.) They claim conformance with the ISO C90 standard. I couldn't dig up a (free) copy of that document, so don't know what it says on this matter. GNU C man pages say it positions the stream at end for write and at beginning for read. Donn Cave, donn at u.washington.edu From bokr at oz.net Tue Aug 23 22:45:37 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 24 Aug 2005 02:45:37 GMT Subject: how to deal with space between numbers References: Message-ID: <430bdd67.2258793663@news.oz.net> On Tue, 23 Aug 2005 19:20:15 +0200, Mohammed Altaj wrote: > >Dear All > >This is my problem again , I tried to sort it out , but i couldn't , I >am reading data from file using readlines , my input like : > >0 1 2 4 >1 2 4 >2 3 >3 4 > >What i am doing is , starting with the first element in the first line ( >which is 0 in this case )and do search in the other lines , if i found >another 0 , i will save (print out) all the elements except 0 , (in this >is case i have no 0 elsewhere) so i will print only 0. Now do search by >the 2nd element in the first line (which is 1 in this case) , in the 2nd >line we have 1 , so i should save(print out) all elements except 1 which >are 2 4 , and so on for the rest of the first line , and for the rest of >the file , my out put should be > >0 1 2 4 2 1 4 3 4 1 2 3 >1 2 3 4 3 >2 3 4 >3 4 > >I managed to do all these things , but i did it in the way that i am >reading my data as strings ( no space between numbers) something like > >0124 >124 >23 >34 > >what i would like to know or to do is , how can i deal with my data >after reading it as strings(i need the space between numbers) because i >had problem when dealing with number larger than 9 , example : > >0 1 5 9 >1 12 10 >4 6 7 >10 9 > >so , when i remove the space between numbers , i loose all my data , i >mean it will look like >0159 >11210 >467 >509 > > >This is my code : > > >def belong_to(x,a): > c=-1 > for i in range(len(a)-1): > if x==int(a[i]): This was selecting single characters at a[i], so it was a misleading clue re your actual requirements ;-) > c=i > return c > >def list_belong(x,a): # This function to check if this line > c=-1 # line has been searched before or not > for i in range(len(a)): > if a[i]==x: > c=1 > break > return c > >x=0 >occur=[] > >in_file=open('data.dat','r') >out_file=open('result.dat','w') >fileList = in_file.readlines() >for k in fileList: > v=k > occur.append(k) > n=len(v)-1 > for i in range(n): > temp=int(v[i]) > print temp, > out_file.write(str(temp)) > for line in fileList: > if v!=line: > if list_belong(line,occur)!=1: > if belong_to(temp,line) != -1: > j=belong_to(temp,line) > for i in range(len(line)-1): > if i!=j: > print line[i], > out_file.write(line[i]) > > > > print > out_file.write("\n") > >out_file.close() >in_file.close() > > > >Thank you all > You could try dealing with the data as lists of numbers, e.g, (slight mod from my previous) >>> # test with string file input and stdout output ... import StringIO >>> in_file = StringIO.StringIO("""\ ... 0 2 3 4 ... 1 2 4 ... 2 3 ... 3 4 ... 0 1 5 9 ... 1 12 10 ... 4 6 7 ... 10 9 ... """) >>> import sys >>> out_file = sys.stdout >>> >>> lines = [map(int,line.split()) for line in in_file] # make lines as int lists >>> for i, line in enumerate(lines): ... out = [] ... for digit in line: ... out.append(digit) ... for followingline in lines[i+1:]: ... if digit in followingline: ... out.extend([x for x in followingline if x != digit]) ... out_file.write(' '.join(map(str, out))+"\n") ... 0 1 5 9 2 1 4 3 3 2 4 4 1 2 3 6 7 1 0 5 9 12 10 2 3 4 3 6 7 2 3 4 3 4 6 7 0 1 12 10 5 9 10 1 12 10 9 4 6 7 10 9 (The output now has to have spaces as well, to delimit the numbers). Regards, Bengt Richter From u.hobelmann at web.de Tue Aug 23 14:59:15 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Tue, 23 Aug 2005 20:59:15 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <1124804082_1011@spool6-east.superfeed.net> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> Message-ID: <3n1a05F18j8auU1@individual.net> l v wrote: > Xah Lee wrote: >> (circa 1996), and email should be text only (anti-MIME, circa 1995), > > I think e-mail should be text only. I have both my email and news > readers set to display in plain text only. It prevents the marketeers Be generous in what you accept and conservative in what you send ;) I always send plaintext emails, but Thunderbird can also display HTML. Of course I don't let it load remote images in the HTML, so no feedback for the marketers. > and spammers from obtaining feedback that my email address is valid. A > surprising amount of information can be obtained from your computer by > allowing HTML and all of it's baggage when executing on your computer. When that HTML execution accesses further remote resources. > Phishing comes to my mind first and it works because people click the > link without looking to see where the link really takes them. That's a problem, yes. As usual, education helps. -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From pink at odahoda.de Sat Aug 6 08:53:22 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Sat, 06 Aug 2005 14:53:22 +0200 Subject: Putting function references in a Queue References: <1mh1u4qoeju2f.1suxwcnapp086$.dlg@40tude.net> Message-ID: Richard Townsend wrote: > I've been experimenting putting a reference to a function into a Queue > object and was wondering what actually gets put in the Queue - is it the > function's code object? No, it's justa referenceto the function object. > If I read from the Queue in a different module, it appears that I don't > need to import the module that defines the function - or any module that > it uses - is this generally true, or are there some conditions to be aware > of? There function reference is sufficient to call the function, there's not need to import the module containing the function. It has already been imported (otherwise the function wouldn't be there) and the function has a reference to this module in order to resolve its global (module-level) references. > The scenario I'm working on has child threads doing some tasks and then > sending back tuples (done, function, args, kwargs) via the Queue, to be > called in the main thread. The Python code is ultimately embedded in a > C/Motif app. As long as you take care of the usual threading issues (concurrent access to shared objects guarded by semaphores etc.), there should not be any greater problems. The function will be executed in the thread that is called it of course (and not in the thread that sent the reference to it). -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From aahz at pythoncraft.com Wed Aug 10 11:28:56 2005 From: aahz at pythoncraft.com (Aahz) Date: 10 Aug 2005 08:28:56 -0700 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> Message-ID: In article , Erik Max Francis wrote: > >It also is free for personal use (up to 2 clients, 2 users) and open >soruce projects can get free licenses. Or at least it was so the last I >checked. For anything mission-critical, I wouldn't want to rely on a free license. At least if it's Open Source and someone plays with the license, someone else will fork (c.f. XFree86). Alternatively, I am sometimes willing to pay for good closed-source software. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From Nicola.Kaiser at urz.uni-heidelberg.de Thu Aug 18 10:41:21 2005 From: Nicola.Kaiser at urz.uni-heidelberg.de (Nicola Kaiser) Date: Thu, 18 Aug 2005 16:41:21 +0200 Subject: gnuplot-py: plotoutput in string? Message-ID: Hi, I?m using Gnuplot via gnuplot.py and I?m looking for a way to get the plotting output (terminal set to png in my case) piped in a string instead of to stdout or a file. Is there any method in gnuplot.py that does this for me? If not, I tried something like: p=Gnuplot.Gnuplot(debug=1) p('set terminal png') oldstdout=sys.stdout output=cStringIO.StringIO() sys.stdout=output p.plot([[1,0],[2,50],[3,0],[4,20],[5,0],[6,30],[7,70], [8,70], [9, 75], [10, 50], [11, 30], [12, 50]]) sys.stdout=oldstdout print output.getvalue() But unfortunately I also get other stuff like: "gnuplot: unable to open display '' "gnuplot: X11 aborted" in the same string Can anyone help me on this? Thanks, Nicola From peter at engcorp.com Thu Aug 25 10:15:18 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 25 Aug 2005 10:15:18 -0400 Subject: loop in python In-Reply-To: References: <1124964483.645753.190460@g47g2000cwa.googlegroups.com> Message-ID: Sybren Stuvel wrote: > James enlightened us with: > >>One does not compare speed when they use Perl/Python/Ruby/Tcl. They >>are all more or less in the same performance ball park. > > > I don't want to offend you or anything, but doesn't the second > sentence mean that someone DID do a speed comparison? Yes, and has shown that they are in the same ballpark, and therefore one does not _need_ to compare speed any more. At least, that's how I read what James posted. -Peter From devlai at gmail.com Wed Aug 10 04:04:41 2005 From: devlai at gmail.com (Devan L) Date: 10 Aug 2005 01:04:41 -0700 Subject: Help with Regular Expressions References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> Message-ID: <1123661081.847617.137140@f14g2000cwb.googlegroups.com> Harlin Seritt wrote: > I have been looking at the Python re module and have been trying to > make sense of a simple function that I'd like to do. However, no amount > of reading or googling has helped me with this. Forgive my > stone-headedness. I have done this with .NET and Java in the past but > damn if I can't get it done with Python for some reason. As such I am > sure it is something even simpler. > > I am trying to find some matches and have them put into a list when > processing is done. I'll use a simple example like email addresses. > > My input is the following: > wordList = ['myname1', 'myname2 at domain.tld', 'myname3 at domain.tld', > 'myname4 at domain', 'myname5 at domain.tldx'] > > My regular expression would be something like '\w\@\w\.\w' (I realize > it could and should be more detailed but that's not the point for now). > > I would like to find out how to output the matches for this expression > of my 'wordList' into a neat list variable. How do I get this done? > > Thanks, > > Harlin Seritt You need to enclose the '\w's in parentheses. The re module will only return it if you enclose it in parentheses. Also, you need to use the '+' so that \w won't just match the first alphanumeric character, but will match one or more. You also need to escape the '.' because that's matches any character. So your regular expression would be more like r'(\w+)@(\w+)\.(\w+)' Anyways, you can use a list comprehension and the groups() method of a match object to build a list of tuples [re.match(r'(\w+)@(\w+)\.(\w+)', address).groups() for address in wordList] On a side note, some of the email addresses in your list don't work. You should use wordList = ['myname at domain.tld', 'myname_2 at domain.tld', 'myname at domain.tldx'] From claird at lairds.us Thu Aug 18 03:08:02 2005 From: claird at lairds.us (Cameron Laird) Date: Thu, 18 Aug 2005 07:08:02 GMT Subject: Library vs Framework (was Dr. Dobb's Python-URL!) References: <1124263179.916111.34960@g43g2000cwa.googlegroups.com> Message-ID: In article <1124263179.916111.34960 at g43g2000cwa.googlegroups.com>, Kay Schluehr wrote: . . . >What are frameworks really good for - a very true success story. > >A colleague of mine used to spread all kinds of flags ( state- and >property markers ) over the code that were used to glue everything >together until I raised my tyranny of frameworks. It was a hard >struggle for an OO warrier and took me almost a year or so to become >the undebated projects architect/dictator who trashed all kind of >misguided "freedom" ( i.e. bad code ): "What the fuck is this?" "I >worked almost a week on it!" "It has to be reworked." "No, you don't do >it!" I did it. Who claims that social life is easy? What is nice about >this kind of cruelness is not only my colleague became finally happy >and hopefully learned at least a little bit about programming but also >our customers were gratefull about stable code, thight release >schedules and just-in-time requirement dispatch. Now we have some >bread-and-butter maintenance contract and true freedom to experiment >with other more interesting things besides this. But the struggle just >starts again with the new project ;) . . . Kay, please say that over again (I recognize you've heard that from me before). Are you saying that your colleague misapplied your chosen framework by programming too much OUTside the frame- work, and the global flags were a symptom of that? So is your conclusion that framework use takes non-trivial education? From thomasbartkus at comcast.net Wed Aug 17 10:50:43 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Wed, 17 Aug 2005 09:50:43 -0500 Subject: GUI tookit for science and education References: <7xek8vsxua.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7xek8vsxua.fsf at ruckus.brouhaha.com... > Mateusz ?oskot writes: > > Thank you for any piece of advice in advance. > > Ask yourself why you want a GUI toolkit. Maybe you can write a web > application instead, and use a browser as the GUI. That's a lot > easier to write (just use html), and makes it trivial to run the > application and the browser on separate machines. Wow Paul! I just couldn't help zeroing on that comment. > a lot easier to write (just use html), I would have used adjectives like "clunky" and "limited" when talking about using an html in a browser app. Particularly if we are talking about high powered math/graphs as we often are in the science apps indicated in the original post. I would take MS Excel/VBA as the premier fat client prototyping tool/GUI toolkit for science & education. How would one go about replicating any of that in an HTML/browser app? How do we get to "easier to write"? > Ask yourself why you want a GUI toolkit. I just did. The answer is that I don't *think* you can do much of that with html. Then again - I was wrong once :-) -Tom From gene.tani at gmail.com Tue Aug 30 11:18:23 2005 From: gene.tani at gmail.com (gene tani) Date: 30 Aug 2005 08:18:23 -0700 Subject: how to join two Dictionary together? In-Reply-To: <1125413774.726347.128950@f14g2000cwb.googlegroups.com> References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> <1125413482.523747.106530@g47g2000cwa.googlegroups.com> <1125413774.726347.128950@f14g2000cwb.googlegroups.com> Message-ID: <1125415103.597462.42290@g14g2000cwa.googlegroups.com> look Pyth Cookbook 2nd edit, Sec 4.17: "Unions/intersections dictionaries". You'll see idioms like this for dict unions: uniondict=dict(dict1, **dict2) filter (dicta.has_key, dictb.keys()) DENG wrote: > yes, that's really what i want! > > the 2nd replace the 1st one' value! > > thanks so much King From k.robert at gmx.de Wed Aug 31 10:05:47 2005 From: k.robert at gmx.de (Robert) Date: Wed, 31 Aug 2005 16:05:47 +0200 Subject: socket.sslerror:(1, 'error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol') Message-ID: socket.sslerror:(1, 'error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol') Got this from another computer/setup, which I cannot debug. What can be the cause for this problem? Python 2.3.5 trace: [ ...(\'ClientCookie\\\\_urllib2_support.pyo\', 572, \'open\', None), (\'ClientCookie\\\\_urllib2_support.pyo\', 472, \'http_response\', None), (\'ClientCookie\\\\_urllib2_support.pyo\', 589, \'error\', None), (\'urllib2.pyo\', 306, \'_call_chain\', None), (\'ClientCookie\\\\_urllib2_support.pyo\', 181, \'http_error_302\', None), (\'ClientCookie\\\\_urllib2_support.pyo\', 566, \'open\', None), (\'urllib2.pyo\', 326, \'open\', None), (\'urllib2.pyo\', 306, \'_call_chain\', None), (\'ClientCookie\\\\_urllib2_support.pyo\', 807, \'https_open\', None), (\'ClientCookie\\\\_urllib2_support.pyo\', 656, \'do_open\', None), (\'httplib.pyo\', 715, \'endheaders\', None), (\'httplib.pyo\', 600, \'_send_output\', None), (\'httplib.pyo\', 567, \'send\', None), (\'httplib.pyo\', 988, \'connect\', None), (\'socket.pyo\', 73, \'ssl\', None)] Robert From chris at wintergreen.in Wed Aug 31 00:28:35 2005 From: chris at wintergreen.in (Chris Dewin) Date: Wed, 31 Aug 2005 13:28:35 +0900 Subject: Uploading images via cgi? References: Message-ID: On Tue, 30 Aug 2005 21:55:26 +0000, Peter Hansen wrote: > Chris Dewin wrote: >> How do I go about writing a cgi script, that will enable the client to >> upload things to a directory on my website? >> >> I would also like to write a script that enables the client to delete >> items in that directory if they want. Given that it's unix server, how >> do I go about ensuring the files are written to that dir with the right >> permissions? > > What did you learn when you tried a few of the more obvious searches > with Google (including the word "python" in the search)? You must have > learned _something_ but still have questions, so please tell us what you > already know so we can skip over the easy stuff. > > Knowing what you've already discovered will avoid having everyone here > repeat all the same answers (which you can easily find in the Google > Groups archives) to what is a fairly common sort of question. > > -Peter Very well then. I did search google, and found a number of python scripts that already do the job (more or less). But when I try to tweak them to my specifications, I get errors ... probably because I don't really understand how the process of uploading a file via a webform to a cgi works. For e.g, take the script at this url. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844 By reading through this script, I know that simply putting '' in your web form will establish a connection to the cgi when the client submits the form. The python interpreter obviously sustains that connection while the file is being transferred, the file being part of the FieldStorage() instance. But then, the script saves the file to the disk in some special way I don't understand. In this case: > fout = file (os.path.join(upload_dir, fileitem.filename), 'wb') while > 1: > chunk = fileitem.file.read(100000) > if not chunk: break > fout.write (chunk) > fout.close() chunk = fileitem.file.read(100000), and fout.write (chunk) seem to be the key statements. Could someone elaborate on these for me please? And why do they need to be in a while loop? From onurb at xiludom.gro Sat Aug 13 10:43:06 2005 From: onurb at xiludom.gro (bruno modulix) Date: Sat, 13 Aug 2005 16:43:06 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> <42fb5a47$0$27714$626a14ce@news.free.fr> Message-ID: <42fe06fb$0$18692$636a15ce@news.free.fr> Magnus Lycka wrote: > bruno modulix wrote: > >> Magnus Lycka wrote: >> >>> N.Davis wrote: >>> >>> >>>> Functions existing in a module? Surely if "everything is an object" >>>> (OK thats Java-talk but supposedly Python will eventually follow this >>>> too) >>> >>> >>> >>> int too? ;) >> >> >> >> Yes, int too. > > > I was talking about everything being an object in Java... Oops ! Sorry, my misreading :( -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From opengeometry at yahoo.ca Thu Aug 4 15:28:31 2005 From: opengeometry at yahoo.ca (William Park) Date: Thu, 04 Aug 2005 15:28:31 -0400 Subject: sample code for parsing html file to get contents of td fields References: <1123181678.144557.93100@g49g2000cwa.googlegroups.com> Message-ID: yaffa wrote: > does anyone have sample code for parsting an html file to get contents > of a td field to write to a mysql db? even if you have everything but > the mysql db part ill take it. I usually use Expat XML parser to extract the field. http://home.eol.ca/~parkw/index.html#expat Expat is everywhere. Python has it and even Gawk has it. -- William Park , Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From falcon3166 at hotmail.com Thu Aug 18 12:23:11 2005 From: falcon3166 at hotmail.com (Nathan Pinno) Date: Thu, 18 Aug 2005 10:23:11 -0600 Subject: (OT) Is there something that people can use instead of full blown Python to run Python programs? Message-ID: Hi all, Is there something besides the full blown version of Python that people can use to run Python programs, or do they have to use the full blown version of it? Thanks, Nathan --------------------------------------------------------------- Early to bed, Early to rise, Makes a man healthy, wealthy, and wise. --Benjamin Franklin ------------------------------------------------------------------- Languages I know: Python Languages I am learning: C++. Java, Javascript -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Pinno, Nathan Paul.vcf Type: text/x-vcard Size: 806 bytes Desc: not available URL: From john at castleamber.com Mon Aug 29 14:22:45 2005 From: john at castleamber.com (John Bokma) Date: 29 Aug 2005 18:22:45 GMT Subject: Jargons of Info Tech industry References: <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <1gg6h1lah2su96huukfobvgmcbnrp43514@4ax.com> Message-ID: Alan Balmer wrote: > On Fri, 26 Aug 2005 16:47:10 GMT, Chris Head > wrote: > >>This point I agree with. There are some situations - 'net cafes included >>- - where thick e-mail clients don't work. Even so, see below. > > I use Portable Thunderbird, on a USB memory stick. All I need is a USB > port and an internet connection. It's a brave internetcafe that allows such things. (I mean technically one can have a Portable Spam Device :-). -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From nothingcanfulfill at gmail.com Thu Aug 18 19:38:44 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 18 Aug 2005 16:38:44 -0700 Subject: Module Name Conflicts In-Reply-To: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: <1124408324.310617.198340@z14g2000cwz.googlegroups.com> Maybe what you're looking for is __import__()? >>> help(__import__) Help on built-in function __import__ in module __builtin__: __import__(...) __import__(name, globals, locals, fromlist) -> module Import a module. The globals are only used to determine the context; they are not modified. The locals are currently unused. The fromlist should be a list of names to emulate ``from name import ...'', or an empty list to emulate ``import name''. When importing a module from a package, note that __import__('A.B', ...) returns package A when fromlist is empty, but its submodule B when fromlist is not empty. From hancock at anansispaceworks.com Wed Aug 31 18:04:14 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 31 Aug 2005 17:04:14 -0500 Subject: To the python-list moderator In-Reply-To: References: Message-ID: <200508311704.14077.hancock@anansispaceworks.com> On Wednesday 31 August 2005 11:29 am, Terry Reedy wrote: > For a couple of years, I have been reading and posting and posting to > python-list and c.l.p via gmane.news.orgs gmane.comp.python.general group. > Today I got this from 'python-list-bounces', which I presume is a 'machine' > rather than a 'human' address. I got one of these too, recently. Maybe somebody is turning up the screws to get rid of spam that's been appearing on the list? -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From lycka at carmen.se Tue Aug 16 05:15:11 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 16 Aug 2005 11:15:11 +0200 Subject: How to obtain GMT offset? In-Reply-To: References: Message-ID: new pip wrote: > I'm using Windows os. If the current system date time is '28 Jun 2001 > 14:17:15 +0700', how can I obtain the value '+0700' using python? > > Thank you If you ignore the time and datetime modules, you can always split the string on whitespace and grab the last part: >>> ts='28 Jun 2001 14:17:15 +0700' >>> tz=ts.split()[-1] >>> print tz +0700 From steven.bethard at gmail.com Thu Aug 18 10:34:45 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 18 Aug 2005 08:34:45 -0600 Subject: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: Michael Hudson wrote: > bryanjugglercryptographer at yahoo.com writes: >> I'm fine with your favored behavior. What do we do next to get >> the doc fixed? > > I guess one of us comes up with some less misleading words. It's not > totally obvious to me what to do, seeing as the returned values *are* > indices is a sense, just not the sense in which they are used in > Python. Any ideas? Maybe you could replace: "these are the start and stop indices and the step or stride length of the slice" with "these are start, stop and step values suitable for passing to range or xrange" I wanted to say something about what happens with a negative stride, to indicate that it produces (9, -1, -2) instead of (-1, -11, -2), but I wasn't able to navigate the Python documentation well enough. Looking at the Language Reference section on the slice type[1] (section 3.2), I find that "Missing or out-of-bounds indices are handled in a manner consistent with regular slices." So I looked for the documentation of "regular slices". My best guess was that this meant looking at the Language Reference on slicings[2]. But all I could find in this documentation about the "stride" argument was: "The conversion of a proper slice is a slice object (see section 3.2) whose start, stop and step attributes are the values of the expressions given as lower bound, upper bound and stride, respectively, substituting None for missing expressions." This feels circular to me. Can someone help me find where the semantics of a negative stride index is defined? Steve [1] http://docs.python.org/ref/types.html [2] http://docs.python.org/ref/slicings.html From jpopl at interia.pl Fri Aug 26 10:19:00 2005 From: jpopl at interia.pl (Jacek =?iso-8859-2?Q?Pop=B3awski?=) Date: Fri, 26 Aug 2005 14:19:00 +0000 (UTC) Subject: telnet.read_until() from telnetlib Message-ID: I have strange problem with telnetlib. r=self.telnet.read_until(expected,timeout) It works in most cases (hundrets of iterations), but sometimes "r" doesn't contain "expected", first I thought that server is responding incorrectly, then I realized that read_until doesn't wait timeout seconds! example output (value of r): "#" while I was expecting "config#" value of timeout is 20 PS. Python 2.4.1, Cygwin. -- Free Software - find interesting programs and change them NetHack - meet interesting creatures, kill them and eat their bodies Usenet - meet interesting people from all over the world and flame them Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net From reinhold-birkenfeld-nospam at wolke7.net Tue Aug 30 17:09:37 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Tue, 30 Aug 2005 23:09:37 +0200 Subject: What are new-style classes? In-Reply-To: References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> <3nehc2F15ainU1@individual.net> Message-ID: <3nk08hF1snjcU1@individual.net> Colin J. Williams wrote: >>>>I recently heard about 'new-style classes'. I am very sorry if this >>>>sounds like a newbie question, but what are they? I checked the Python >>>>Manual but did not find anything conclusive. Could someone please >>>>enlighten me? Thanks! >>> >>>"New style" classes are becoming the standard in Python, and must >>>always be declared as a subclass of a new style class, including built-in >>>classes. >> >> >> [Warning, advanced stuff ahead!] >> >> That's not entirely true. New-style classes need not be derived from a new- >> style class, they need to use the metaclass "type" or a derived. >> >> So you can also declare a new-style class as >> >> class new_class: >> __metaclass__ = type >> >> Or, if you want to switch a whole module with many classes to new-style, just set a >> >> __metaclass__ = type >> >> globally. >> > What are the pros and cons of the alternate approach? The customary way is to use "class new_class(object):". There's no advantage in using __metaclass__ except that you can set it globally for all classes in that module (which can be confusing on its own). My comment mostly referred to "new-style classes must be declared as a subclass of a new-style class", which is not true. Reinhold From matt.hammond at rd.bbc.co.uk Mon Aug 8 07:02:08 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Mon, 08 Aug 2005 12:02:08 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: On Mon, 08 Aug 2005 10:49:32 +0100, Wolfgang Keller wrote: >> The project aims to make it simple to build networked multimedia >> systems (eg audio, video, interactive systems), > > Why limit the scope of application artificially? > > Axon/Kamaelia imho is perfectly applicable to any kind of application > that does some kind of data processing. You're absolutely right - Axon/Kamaelia hopefully will not just be limited to those areas. It just so happens that those kinds of systems are the underlying reasons why we started building Axon/Kamaelia. That's therefore where we're concentrating our resources at the moment. > Think workflow applications, business applications, application > integration... > > J. Paul Morrison has used the concept he named "Flow-Based-Programming" > for financial applications since the 60's, any control systems engineer > knows function-block-diagrams etc. and so on... We have ... alot! I really do hope that this system is used for more. I'd be very interested to know if anyone has had a go at building any components - for whatever purpose. The potential for component re-use might mean less work for us! :-) regards Matt Hammond -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From projecktzero at yahoo.com Thu Aug 4 10:49:33 2005 From: projecktzero at yahoo.com (projecktzero) Date: 4 Aug 2005 07:49:33 -0700 Subject: pain References: <42f1f51b$0$11068$e4fe514c@news.xs4all.nl> Message-ID: <1123166972.948428.219140@g47g2000cwa.googlegroups.com> "a manager telling me what tools to use to do my job is a bad manager by definition because he should realize that the people who best know what tools to use are the peope who use the tools*." I'm sorry, this doesn't make much sense to me. In an ideal world where all developers are all knowing and know every language inside and out, then allowing each developer to choose his tools(languages) would work. You don't see a problem with programmer Joe using Perl, Brad using Python, Carl uses Smalltalk, Nate uses Java, Steve using Ruby, and Ed using Haskell? "* Did you know that most good chef cooks have their own knive set? And what do you think is the reason a restaurant manager don't tell them to use the company in-house Amefa blades instead of his global knives? " This is a very poor analogy. The next chef doesn't have to re-cook what the previous chef has done(well, that didn't work either)...er...This has nothing to do with programming. The manager may have his reasons for choosing the tools. Perhaps nearly all projects that have been developed and are in development are using paticular tools. It's easy for team members to work on any project.(I'm speaking more of languages and frameworks not down to the editors and IDEs.) It would be nice if the team could decide on tools, and sometimes that's appropriate. Maybe they want to migrate to a new language or framework. Maybe there's a throw away project that could be a test for the new language or framework. If you want to try a new/different language, you need to show the benefit other than "it's cool/new". From desparn at wtf.com Fri Aug 26 07:20:33 2005 From: desparn at wtf.com (Rick Wotnaz) Date: Fri, 26 Aug 2005 07:20:33 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type References: <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> Message-ID: Bryan Olson wrote in news:3ErPe.853$sV7.65 at newssvr21.news.prodigy.com: > Steve Holden asked: > > Do you just go round looking for trouble? > > In the course of programming, yes, absolutly. > > > As far as position reporting goes, it seems pretty clear that > > find() will always report positive index values. In a > > five-character string then -1 and 4 are effectively > > equivalent. > > > > What on earth makes you call this a bug? > > What you just said, versus what the doc says. > > > And what are you proposing that > > find() should return if the substring isn't found at all? > > please don't suggest it should raise an exception, as index() > > exists to provide that functionality. > > There are a number of good options. A legal index is not one of > them. > > Practically speaking, what difference would it make? Supposing find returned None for not-found. How would you use it in your code that would make it superior to what happens now? In either case you would have to test for the not-found state before relying on the index returned, wouldn't you? Or do you have a use that would eliminate that step? -- rzed From michaels at rd.bbc.co.uk Thu Aug 4 11:47:48 2005 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 04 Aug 2005 16:47:48 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42f14e42$0$3493$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: Terry Reedy wrote: > "Michael Sparks" wrote in message > news:42f14e42$0$3493$ed2619ec at ptn-nntp-reader03.plus.net... >> def updater(interval, message): >> t = time.time(): >> while 1: >> if time.time() - t > interval: >> print message > > yield None # add this ???? Yes. (I can't believe I missed that out! :) I'd normally use yield 1, but that's force of habit. I tend to use a true value to indicate a never ending generator - partly because we use a false value to indicate clean shutdown of a component to our scheduler. Thanks :) Michael -- Michael.Sparks at rd.bbc.co.uk, http://kamaelia.sourceforge.net/ British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From guettli at thomas-guettler.de Wed Aug 31 10:52:41 2005 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Wed, 31 Aug 2005 16:52:41 +0200 Subject: 'ps -A' command freezes Popen3 References: <1125497569.941285.85330@g49g2000cwa.googlegroups.com> Message-ID: Am Wed, 31 Aug 2005 07:12:49 -0700 schrieb gao_bolin: > Does anybody know why the following lines would freeze python [2.4.1 on > Linux]: > > import popen2 > a = popen2.Popen3('ps -A') > a.wait() Because "ps -A" produces a lot of output to stdout, so that it blocks. It blocks until you read from the stdout of the subprocess. If you don't read, it will wait forever. You can redirect the output to a file "ps -A > /tmp/example". This won't block. Or you use the module select if you are in a unix environment. HTH, Thomas -- Thomas G?ttler, http://www.thomas-guettler.de/ From renting at astron.nl Fri Aug 26 02:56:15 2005 From: renting at astron.nl (Adriaan Renting) Date: Fri, 26 Aug 2005 08:56:15 +0200 Subject: variable hell Message-ID: Not in my Python. >>> for count in range(0, 10): ... value = count ... exec("'a%s=%s' % (count, value)") ... >>> dir() ['__builtins__', '__doc__', '__name__', 'count', 'value'] >>> for count in range(0, 10): ... value = count ... exec(eval("'a%s=%s' % (count, value)")) ... >>> dir() ['__builtins__', '__doc__', '__name__', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'count', 'value'] >>> I myself use code like this to load user defined classes. exec(eval("'from %s import %s' % (script, script)")) exec(eval("'self.user_class = %s()' % script")) self.user_class.run() But this can probably be done with the imp module too. >>>rafi 08/25/05 6:03 pm >>> Adriaan Renting wrote: >You might be able to do something along the lines of > >for count in range(0,maxcount): > value = values[count] > exec(eval("'a%s=%s' % (count, value)")) why using the eval? exec ('a%s=%s' % (count, value)) should be fine -- rafi "Imagination is more important than knowledge." (Albert Einstein) -- http://mail.python.org/mailman/listinfo/python-list From phil at riverbankcomputing.co.uk Mon Aug 8 03:21:32 2005 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Mon, 8 Aug 2005 08:21:32 +0100 (BST) Subject: Embedding a runtime graph in Qt3 designer generated UI In-Reply-To: <42f6e4c8$0$18646$14726298@news.sunsite.dk> References: <42f6e4c8$0$18646$14726298@news.sunsite.dk> Message-ID: <57525.194.203.13.71.1123485692.squirrel@river-bank.demon.co.uk> > Hi > > Two questions : > > 1. Is it possible to use an import command in a qt3 designer code ? (I > know > that it is possible to write python inside the braces -- but is it > possible > to use an import command for some rather large libraries I wrote that I > need to access ?). You can include import statements in Designer's comment dialog by prefixing them with "Python: ". This is covered in the PyQt documentation. > 2. In the same vein, how does one embed a runtime plot in a qt3 UI ? It > will > need to be a python solution since I am using python libraries to acquire > the data. Have a look at PyQwt which is a set of Python bindings for the Qt-based Qwt plotting library. Phil From mde at micah.elliott.name Thu Aug 11 02:05:41 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Wed, 10 Aug 2005 23:05:41 -0700 Subject: Pre-PEP Proposal: Codetags Message-ID: <20050811060541.GA8220@kitchen.client.attbi.com> I also have this living as a wiki if people would like to add comments there. I might try to capture there feedback from this group anyway. First try at a PEP -- thanks for any feedback! Please add **NOTE:** comments to the bottom of this wiki document using `WikiRestructuredText`:trac:. ======================================= Codetag PEP (*or* Tao of Codetagging) ======================================= PEP: XXX Title: Codetags Version: $Revision$ Last-Modified: $Date$ Author: Micah Elliott Status: Active Type: Informational Content-Type: text/x-rst Created: 27-Jun-2005 Post-History: XXX Abstract ======== This informational PEP aims to provide guidelines for consistent use of Codetags, which would enable the construction of standard utilities to take advantage of the Codetag information, as well as making Python code more uniform across projects. Codetag is a also a very lightweight programming micro-paradigm and becomes useful for project managment, documentation, change tracking, and project health monitoring. This is submitted as a PEP because I feel its ideas are Pythonic, although the concepts are not unique to Python programming. Herein are the definition of a Codetag, a philosophy rant, a motivation for standardized conventions, a specification, a toolset description, and possible objections to the Codetag project/paradigm. What's a Codetag? ================= Programmers widely use ad-hoc code comment markup conventions to serve as reminders of sections of code that need closer inspection or review. Examples of markup include ``FIXME``, ``TODO``, ``XXX``, ``BUG``, but there many more in wide use in existing software. Such markup will be henceforth referred to as a *Codetag*. These Codetags may show up in application code, unit tests, scripts, general documentation, or wherever suitable. Philosophy ========== NOTE: **I'm not certain Philosophy_ belongs in the PEP, but it somewhat explains the usefulness of Codetags** If you subscribe to most of these values, then Codetags will likely be useful for you. 1. As much information as possible should be contained **inside the source code** (application code or unit tests). This along with use of Codetags impedes duplication. Most documentation can be generated from that source code Eg, by using help2man, man2html, docutils, epydoc/pydoc, ctdocgen, etc. 2. Information should be almost **never duplicated** -- it should be recorded in a single original format and all other locations should be automatically generated from the original, or simply be referenced. This is the *SPOT* rule. 3. Documentation that gets into customers' hands should be **auto-generated** from single sources into whatever output formats. People want documentation in many forms. It is thus important to have a documentation system that can generate all of these. 4. Whatever information is subject to (and suited for) user feedback/input should be contained in a **wiki** (or maybe usenet or maillists). Eg, FAQ, RFC, PEP. 5. There should not be a dedicated, disjoint **documentation team** for any non-huge project. The developers writing the code know the code best, and should be the ones to describe it. 6. **Plain text** (with non-invasive markup) is the best form of writing anything. All other formats are to be generated from the plain text. 7. **Revision control** should be used for almost everything. And modifications should be checkin'd at least daily. Motivation ========== **Various productivity tools can be built around Codetags.** See `Toolset Possibilities`_. **Encourages consistency.** Historically, a subset of these Codetags has been used informally in the majority of codes in existence, whether Python or some other language. Tags have been used in an inconsistent manner with different spellings, semantics, format, and placement. Eg, some programmers might include datestamps and/or user identifiers, limit to a single line or not, spell the Codetag differently than others, etc. **Encourages adherence to SPOT/DRY principle.** Eg, generating a roadmap dynamically from Codetags instead of keeping TODOs in sync with separate roadmap document. **Easy to remember.** All Codetags must be concise, intuitive, and semantically non-overlapping with others. Format is also simple. **Use not required/imposed.** If you don't use Codetags already, there's no obligation to start, and no risk of affecting code (but see Objections_). A small subset can be adopted and the Tools_ will still be useful (a few are already implicitly adopted anyway). Also very easy to identify and remove if a Codetag is no longer deemed useful. Then it is effectively *completed* and recorded by revision control simply by checkin'ing. **Gives a global view of code.** Use tools to generate documentation and reports. **A logical location for capturing CRCs/Stories/Requirements.** The XP community often does not electronically capture Stories, but Codetags seem like a good place to locate them. **Extremely lightweight process.** Creating tickets in a tracking system for every thought degrades development velocity. Even if a ticketing system is employed, Codetags are useful for simply containing links to those tickets. Examples ======== This shows a simple Codetag as commonly found in sources everywhere (with the addition of a trailing ``<>``). :: def foo(): # FIXME: Seems like this loop should be finite. <> while True: ... This contrived example demonstrates more common use of Codetagging. It uses some of the available fields to specify the owners (a pair of developers with initials *mde* and *cle*), the Work Week of expected completion (*w14*), and the priority of the item (*p2*). :: def foo(): # FIXME: Seems like this loop should be finite. while True: Specification ============= This describes the format: parsing layout, mnemonic names, fields, and semantics. General Layout -------------- Each Codetag should be inside a comment, and can be any number of lines. It should match the indentation of surrounding code. The end of the Codetag is marked by a ``<...>``, which must not be split onto multiple lines. There are multiple fields per Codetag, all of which are optional. To be succinct, a Codetag is a mnemonic, a colon, a commentary, an opening broket, a list of optional fields, and a closing broket. Ie,:: # MNEMONIC: Some (maybe multi-line) commentary. .. FIXME: Add completion vs target date?? Mnemonic Semantics ------------------ The Codetags of interest (``recommended mnemonic (synonym list)``, *canon*, semantics, and **NOTEs**) are as follows. Some of these are temporary (eg, ``FIXME``) while others are persistent (eg, ``REQ``). Synonyms should probably be deprecated in the interest of minimalism and consistency. I chose a mnemonic over a synonym for three criteria: descriptive, short, common usage trends. ``TODO (TBD, MLSTN, DONE)`` *To Do*, An informal task/feature that is pending completion. Relevant to roadmap. NOTE: **DONE would really be a completed TODO item, but these should probably be done through the revision control system.** ``FIXME (XXX, DEBUG, BROKEN, RFCTR, OOPS, SMELL)`` *Fix Me*, Problematic or ugly code. Needs refactoring or cleanup. NOTE: **Choosing between FIXME and XXX is difficult. AFAICT XXX is more common, but so much less descriptive. Furthermore, XXX is a useful placeholder in a piece of code having a value that is unknown. Sun says that XXX and FIXME are slightly different, giving XXX higher severity.** ``REQ (STORY)`` *Requirement*, Satisfaction of a specific, formal requirement. ``RFE (FEETCH, NYI, FR, FTRQ, FTR)`` *Request For Enhancement*, A roadmap item not yet implemented. ``IDEA`` *Idea*, Possible ``RFE`` candidate, but less formal than ``RFE``. ``??? (QUEST, WTF, TBD, QSTN)`` *Question*, Misunderstood detail. Product of coincidental programming. ``HACK (WKRD)`` *Hack*, Temporary code to force inflexible functionality, or simply a test change, or workaround a known problem. ``PORT`` *Portability*, Workaround specific to OS, Python version, etc. ``BUG (BUGFIX)`` *Bug*, Reported defect tracked in bug database. ``NOTE (HELP)`` *Note*, Implementation detail that stands out as non-intuitive. Or a code reviewer found something that needs discussion or further investigation. NOTE: **Maybe a useful metric where a high count of NOTEs indicates a problem.** ``FAQ`` *Frequently Asked Question*, Interesting area that requires external explanation. NOTE: **This is probably more appropriately documented in a wiki where users can more easily contribute.** ``GLOSS`` *Glossary*, Item definition for project glossary. ``STAT`` *Status*, File-level statistical indicator of work needing done on this file. ``RVDBY`` *Reviewed By*, File-level indicator of programmer(s) who performed recent code review. ``SEE (REF)`` *Reference*, Pointer to other code, web link, etc. NOTE: **File-level Codetags might be better suited as properties in the revision control system.** Fields ------ All fields are optional. It should be possible for groups to define/add their own, but the proposed standard fields are as follows: ``wNN`` Workweek target completion (estimation). Origination and completion are freebees with revision control. ``pN`` Priority level. ``xxx[,yyy]...`` List of initials of owners of completion responsibility. There should be no digits for initials. Toolset Possibilities ===================== Currently, programmers (and sometimes analysts) typically use *grep* to generate a list of items corresponding to a single Codetag. However, various hypothetical productivity tools could take advantage of a consistent Codetag format. Some example tools follow. NOTE: Codetag tools are mostly unimplemented (but I'm getting started!) Document Generator Possible docs: glossary, roadmap, manpages Codetag History Track (with revision control system interface) when a BUGtag (or any codetag) originated/resolved in a code section Code Statistics A project Health-O-Meter Codetag Lint Notify of invalid use of Codetags, and aid in porting to Codetag Story Manager/Browser An electronic means to replace XP notecards. In MVC terms, the Codetag is the Model, and the Story Manager could be a graphical Viewer/Controller to do visual rearrangment, prioritization, and assignment, milestone management. Any Text Editor Used for changing, removing, adding, rearranging Codetags. There are some tools already in existence that take advantage of a smaller set of pseudo-Codetags (see References_) Objections ========== **Objection**: Extreme Programming argues that such Codetags should not ever exist in code since the code is the documentation. **Defense**: Maybe put the Codetags in the unit test files instead. Besides, it's tough to generate documentation from uncommented source code. ---- **Objection**: Too much existing code has not followed proposed guidelines. **Defense**: [Simple] utilities (*ctlint*) could convert existing codes. ---- **Objection**: Causes duplication with tracking system. **Defense**: Not really -- If an item exists in the tracker, a simple ticket number as the Codetag commentary is sufficent. Maybe a duplicated title would be acceptable. Furthermore, it's too burdensome to have a ticket filed for every item that pops into a developer mind on-the-go. ---- **Objection**: Codetags are ugly and clutter code. **Defense**: That is a good point. But I'd still rather have such info in a single place (the source code) than various other documents, likely getting duplicated or forgotten about. ---- **Objection**: Codetags (and all comments) get out of date. **Defense**: Not so much if other sources (externally visible documentation) depend on them being accurate. ---- References ========== Some other tools have approached defining/exploiting Codetags. See http://tracos.org/codetag/wiki/Links Comments ======== Please add comments below following line. Or feel free to comment inline in above sections with **NOTE:** Codetags. Objections_ might be a popular area for comments. :-) Thank you! ---- ---- .. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 End: }}} -- Micah Elliott From jeffrey.schwab at rcn.com Sun Aug 14 11:24:33 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sun, 14 Aug 2005 11:24:33 -0400 Subject: How can I exclude a word by using re? In-Reply-To: References: Message-ID: could ildg wrote: > In re, the punctuation "^" can exclude a single character, but I want > to exclude a whole word now. for example I have a string "hi, how are > you. hello", I want to extract all the part before the world "hello", > I can't use ".*[^hello]" because "^" only exclude single char "h" or > "e" or "l" or "o". Will somebody tell me how to do it? Thanks. import re def demonstrate(regex, text): pattern = re.compile(regex) match = pattern.search(text) print " ", text if match: print " Matched '%s'" % match.group(0) print " Captured '%s'" % match.group(1) else: print " Did not match" # Option 1: Match it all, but capture only the part before "hello." The (.*?) # matches as few characters as possible, so that this pattern would end before # the first hello in "hello hello". pattern = r"(.*?)hello" print "Option 1:", pattern demonstrate( pattern, "hi, how are you. hello" ) # Option 2: Don't even match the "hello," but make sure it's there. # The first of these calls will match, but the second will not. The # (?=...) construct is using a feature called "forward look-ahead." pattern = r"(.*)(?=hello)" print "\nOption 2:", pattern demonstrate( pattern, "hi, how are you. hello" ) demonstrate( pattern, "hi, how are you. ", ) From mwm at mired.org Tue Aug 2 20:43:24 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 20:43:24 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> Message-ID: <86ek9betoz.fsf@bhuda.mired.org> Torsten Bronger writes: > Hall??chen! > Mike Meyer writes: >> Torsten Bronger writes: >>> [...] >>> I'm interested in a language with a big community. This is my >>> definition of success. [...] >>> >>> GUI applications seem to be the most attractive application type. >>> This is not only true for commercial programming. When I look at >>> the most agile projects on Sourceforge, almost all of them have a >>> GUI. >> Why restrict yourself to agile projects? > Because such projects attract the greatest number of developers, > many of them being amongst the most diligent developers, too. I > expect this to have a positive influence of the language. You didn't answer the question about how you define agile project. Please do so if you expect a comment on this. >> I won't argue that most of the projects on Sourceforge have GUIs - >> that's certainly true. I will argue that most of the projects are >> done in languages that aren't what you call GUI-aware. > Yes, this is what I meant with "legacy code". C and C++ are > actually special-purpose. They are good for controlling a computer > but not for implementing an idea. Their current vitality on almost > all software areas arise from the fact that they had been extremely > successful before Java, C#, and VB came into play. Invented today, > they would be niche languages. This is patently absurd. C and C++ were born as general-purpose languages. Changing the environment around them isn't going to change that. > However, even C++ is really successful only when used as a GUI-aware > dialect. Additionally, Python does not have this legacy bonus. The only dialect that might be considered "GUI-aware" is C#. Or maybe you mean they're only succesfull when coupled with a GUI library? I'd say that's due to your warped definition of success, and I'm not going to argue with your definition. >>> Therefore, GUI-aware languages attract much larger user bases, >>> and so they cater my definition of being successful. >> Since you haven't stated what that definition is, I can't really say >> anything about this. > Yes, I did. No, you agreed with my definition, with the proviso that you had to consider how "important" the application area was. Which leaves it undefined. >>> Legacy code is not a sign of success IMO because it implies a >>> difficult future. >> So you're saying that Python, Perl, Linux, the various BSD >> et. al. will have a difficult future? [...] > No. All I said was that if a language's "success" relies almost > exclusively on the heavy presence of legacy code, its future is > difficult. I see this for C and C++ excluding VC++. Well, you lumped all C/C++ code a legacy code. The most successful distribution of Python is the one written in C, so it's success relies almost exclusively on legacy code. Ditto for Perl, Linux, etc. You can't have it both ways. Either C/C++ is all legacy code, or it's not. If it is, the building products in Python/Perl/Java (and probably most of the others) is building in a dependence on a legacy code base. If they *aren't* legacy code, then your premise that C/C++ only has legacy code is false. Personally, I think your premise is false. There are lots of projects still under active development using C/C++. There are new ones starting every day. Contrary to your assertion about VC++, they are starting in environments where VC++ doesn't run. I think you need to come out from behind your Windows box for a while. There are *lots* of applications areas that don't need GUIs, and don't run on Windows. I'll bet most of the computers in your house are running software that falls into that category. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mwh at python.net Thu Aug 11 05:00:35 2005 From: mwh at python.net (Michael Hudson) Date: Thu, 11 Aug 2005 09:00:35 GMT Subject: Memory leak in PyImport_ReloadModule - URGENT References: <1123690966.990415.287310@g14g2000cwa.googlegroups.com> Message-ID: ben.held at staarinc.com writes: > Having recently upgraded to Python 2.4, I am having a large memory > leak with the following code built with VC++ 6.0: > > PyObject *pName, *pModule; > > Py_Initialize(); > pName = PyString_FromString(argv[1]); > > pModule = PyImport_Import(pName); > Py_DECREF(pName); > > PyObject* pModule2 = PyImport_ReloadModule(pModule); > Py_DECREF(pModule2); > Py_DECREF(pModule); > Py_Finalize(); > return 0; Given that the builtin function reload() does more or less the same thing, it seems likely that there's something odd about your embedding that is making the difference. Does it make a difference which module you reload? I notice that you're using VC++ 6.0. Is your Python built with VC6 too? (The python.org distribution is built with 7 -- or 7.1, I forget which). > Help! You might want to file a bug report. Cheers, mwh -- Like most people, I don't always agree with the BDFL (especially when he wants to change things I've just written about in very large books), ... -- Mark Lutz, http://python.oreilly.com/news/python_0501.html From tubaranger at gmail.com Thu Aug 4 09:58:52 2005 From: tubaranger at gmail.com (Greg Lindstrom) Date: 4 Aug 2005 06:58:52 -0700 Subject: pain References: Message-ID: <1123163932.078326.301470@g43g2000cwa.googlegroups.com> Mage Wrote: I would be surprised if there were more than five python jobs in my country but have to look around. I Reply: It's not quite that bad in Arkansas (USA), but when I was hired to help start a new IT department I insisted on using Python and my employer agreed to try it. I now have over 15,000 lines of code running in production and the CEO of the company says he has "six or seven" more projects for me to write (with huge cost saving potential for the company). We're running on GenToo Linux using a Postgres database and PHP for our web development. We've automated about 25% of our day to day business and are looking to expand! I've never had more fun writing code, and I've been writing code for over 20 years. Would it be possible to talk to your supervisor and convince them to allow you to use Python? Start small, with a little project. When you show them that Python "works" and that they will be able to understand the code, I'm guessing they will let you do more. Before you know it, you're coding everything in Python. Best of luck, --greg From caleb1 at telkomsa.net Mon Aug 1 16:14:49 2005 From: caleb1 at telkomsa.net (Caleb Hattingh) Date: Mon, 01 Aug 2005 22:14:49 +0200 Subject: Python IDE's References: <20050731205901.53A6E1E4005@bag.python.org> <1122915471.559698.231740@g43g2000cwa.googlegroups.com> Message-ID: You know, for several years I was one of those people who simply ignored posts like this about Vi/Vim because I happened to come across it once on a sparc machine and thought it was ridiculous that I couldn't figure out how to type a simple note. I thought that Vi (Vim) was some kind of weird and ancient legacy program that just never caught up with the times. About 3 or 4 months ago, I had a truly large amount of ascii text editing and formatting to do and in a plea for advice, I got the standard cliche replies to try "Vim". Having nothing to lose, I gave it a shot. It took only about two weeks before I was competent, but it was probably the greatest time investment I have ever made. I now use Vim for any text editing purpose, and especially python coding. No doubt, the majority of people who read your post will instantly ignore it - but I know from personal experience that it would take a very special IDE to compete with Vim for the manipulation of text (GUI design, of course, is another story altogether). regards Caleb On Mon, 01 Aug 2005 18:57:51 +0200, projecktzero wrote: > VIM or Emacs. I use VIM on Windows, Mac, and VMS. I'd consider it more > of an editor than an IDE, but there are many IDE features available > with plug ins. > From fuzzyman at gmail.com Thu Aug 11 05:23:21 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 11 Aug 2005 02:23:21 -0700 Subject: Pre-PEP Proposal: Codetags In-Reply-To: References: Message-ID: <1123752201.674530.128140@g44g2000cwa.googlegroups.com> I'm sure Martin's comment is basically correct. *However* - you could take your proposal forward by developing a set of tools (e.g. documentation tools) that use your proposal. That way people have a working implementation to use. e.g. Tools to generate HTML TODO lists from source code It would then be easier to integrate your ideas into existing IDEs. Regards, Fuzzy http://www.voidspace.org.uk/python From pink at odahoda.de Mon Aug 22 17:42:46 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Mon, 22 Aug 2005 23:42:46 +0200 Subject: loop in python References: Message-ID: km wrote: > Hi all, > >> thing. If *all* your loops are going to do is print stuff, then you're >> doing the right thing with the version that "emits values". > > ya most of the loops print values. In that case, you are interested in IO performance. The time spent handling the loop is not significant compared to the time spent executing the 'print' statement - which is a very complex operation despite its simple usage. An implementation where a simple control flow structure has an measurable impact on the overall timing of an IO bound program would really suprising. Python suprises me often, but in different ways ;) Perhaps you could try to use sys.stdout.write() directly, avoiding the overhead of 'print'. Perhaps there are differences between the (default) output buffering settings of perl and python. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From rkern at ucsd.edu Thu Aug 18 22:30:10 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 18 Aug 2005 19:30:10 -0700 Subject: Module Name Conflicts In-Reply-To: <1124410667.095654.133980@g49g2000cwa.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> <1124410667.095654.133980@g49g2000cwa.googlegroups.com> Message-ID: torched_smurf at yahoo.com wrote: > Robert Kern wrote: > >>Why not copy cmd.py into your package under a different name? > > It offends my sense of modularity. For the record, I'm trying to use > pdb, the debugger, which in turn uses cmd. So it would be a matter of > taking pdb.py and hacking it to import a renamed version of cmd... kind > of messy and not a very good longterm solution. That's not to say I > won't resort to it if no better options are forthcoming. A solution more kind to your sensibilities might be to make an auxiliary package alongside (rather than inside) yours. No modification to source necessary. pystdlib/ __init__.py cmd.py pdb.py Python 2.4.1 (#2, Mar 31 2005, 00:05:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pystdlib >>> from pystdlib import pdb >>> pdb.cmd.__file__ 'pystdlib/cmd.py' >>> -- 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 mwm at mired.org Tue Aug 2 01:14:50 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 01:14:50 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> Message-ID: <86zms0ex85.fsf@bhuda.mired.org> Paul McNett

writes: > On Windows and Mac, you download the package and run through the wizard. Which package? I'm looking at the sourceforge download site, and don't see any packages for Python 2.4 on OS X 10.4. In fact, I don't see any packages for 10.4 at all. IIRC, they didn't have a 2.4 package last time I looked. I may download the 10.3 one and see if it works. > Admittedly, installing from source is more difficult than any other > project I've found, but still doable. Well, I've got a long history of installing things from source - going back to v6. On OS X, I like the darwin ports stuff, so I tried that: % sudo port install wxpython It blew up trying to compile wxpython. The multitude of dependencies all seemed to build find. Building wxpython from the source distribution by hand doesn't seem to fair any better. Could be that it's 10.4 problem that hasn't been diagnosed yet. We'll see if the FreeBSD port works any better. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From hancock at anansispaceworks.com Thu Aug 25 13:24:59 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 25 Aug 2005 12:24:59 -0500 Subject: Newbie question: Sub-interpreters for CAD program In-Reply-To: References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: <200508251224.59612.hancock@anansispaceworks.com> On Thursday 25 August 2005 09:13 am, Peter Hansen wrote: > Terry Hancock wrote: > > On Wednesday 24 August 2005 09:12 pm, Peter Hansen wrote: > >>Or even http://www.pythoncad.org/ which, although probably for > >>mechanical CAD work (I haven't looked at it, don't really know), is > >>surely a good place to get ideas of what Python can do in this area. > > > > No, I doubt it. PythonCAD is a 2D mechanical CAD drawing system. > > I don't think it would be anywhere near what this guy wants. They're > > just different applications. He's looking for an electronic CAD system or > > EDA, I'm pretty sure (or looking to write one, rather). > > As an engineer who's worked extensively in both kinds of systems > (primarily designing microcontroller-based circuit boards), and a > programmer who's stolen useful ideas from endless amounts of other > people's code, I'll say only that I disagree with your implication that > looking at PythonCAD will give him no useful ideas whatsoever Heh. Well I didn't use the word "whatsoever" did I. ;-) No you're right, if you're looking to write code from the ground-up, then it's certainly true that this would help. But I pointed him at Gnu EDA, because it already seems to do *most* of what he was looking for, I think. There's also PCB and zcircuit to be considered. All of these are C language programs, I believe, and he's already an experienced C/C++ programmer it would seem. OTOH, PythanCAD serves as an example of why he might be better off to *write* the CAD program in Python and use C/C++ extension modules as needed, instead of embedding Python into a C/C++ application. But I kind of got the impression he was attached to using C++ for the job, which would not be *my* choice, but is certainly preferred by a lot of programmers. There is another, community-oriented reason for writing it in Python and looking at PythonCAD, of course. It would not be unreasonable to write an EDA/PCB/autorouter application that worked IN PythonCAD. That would be pretty cool. It would also be a good way to leverage community support for the project. But I have a feeling this is not going to be the way the OP will want to go, since he came asking only how to embed Python into a C/C++ application. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From schmitt at num.uni-sb.de Fri Aug 26 09:36:23 2005 From: schmitt at num.uni-sb.de (Uwe Schmitt) Date: Fri, 26 Aug 2005 15:36:23 +0200 Subject: Integrate C source in a Python project References: Message-ID: <1125059578$mail2nntp@hades.rz.uni-saarland.de> > > Hi all. > I was wondering if it ispossible to integrate C source in a > python project. Yes it is. Which tool you use depends on your requirements: http://starship.python.net/crew/theller/ctypes/ ctypes allowes loading dlls/shared libs and calling functions in that lib. www.swig.org is a wrapper for wrapping c/c++ to several languages as php, python, ... www.boost.org includes the boost pyhton library. this is my favorite for wrapping c++ code. Greetings, Uwe From turnerst at family-zone.co.uk Thu Aug 4 02:14:45 2005 From: turnerst at family-zone.co.uk (Stuart Turner) Date: Thu, 04 Aug 2005 07:14:45 +0100 Subject: Ideas for Python project? References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: Jon Hewer wrote: > Hi > > I'm pretty new to Python, and recently been working my way through > Dive Into Python, and I'm currently writing a really simple rss reader > purely to get familiarised with the language. I want to move onto > something a little more challenging, but I'm stuck for ideas on what > to do. > > I'm after a project that can start quite simple, but has lots of room > for expansion when I get more confident with Python. Ideally > something which would start as a command line program, and then when I > feel adventurous I could build a GUI for it. > > I have just bought the Foundations of Python Network Programming book, > so maybe something network related would be good? > > Cheers > Jon I saw a competition in Linux format - may be something to consider. - Stuart From nyamatongwe+thunder at gmail.com Sat Aug 27 19:30:46 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sat, 27 Aug 2005 23:30:46 GMT Subject: Windows/win32all, unicode and long filenames In-Reply-To: References: Message-ID: Kevin Ollivier: > On Windows, it's very common to have a string of long directories in the > pathname for files, like "C:\Documents and Settings\My Long User Name\My > Documents\My Long Subdirectory Name\...". For a wxPython application I'm > working on, this has actually caused me to run into what appears to be > Python's pathname length limit for opening files. (247 chars on Win) Yes, > I can hear people saying "yipes!" but this stuff does happen sometimes on > Windows. :-) The Win32 API restricts path arguments to 260 characters. Longer paths can be passed to wide character functions by using a "\\?" prefix. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp This may work from Python although I haven't tested it. > My first inclination was to use win32api.GetShortPathName(mypath), > ... > Looking at the pyWin32 sources, it does look like only the ASCII version > of this function exists, which suggests that for now this route is a > dead-end. All APIs can be accessed through ctypes. Neil From sjmachin at lexicon.net Sun Aug 14 09:01:16 2005 From: sjmachin at lexicon.net (John Machin) Date: Sun, 14 Aug 2005 23:01:16 +1000 Subject: Parsing a log file In-Reply-To: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> References: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> Message-ID: <42ff409b$1@news.eftel.com> CG wrote: [snip] > What I basically want to do is end up with a text file that can be > easily imported into a database with a format like this (or I guess it > could be written in a SQL script form that could write directly to a > database like Mysql): > > Connect_Date Connect_Time Disconnect_date Disconnect_time User > ------------ ------------ --------------- --------------- ------- > 08-13-2005 13:19:37 08-13-2005 15:40:08 John [snip] > * I don't need the fractions of seconds in the timestamps (1) Famous last words. (2) What do you gain my throwing information away? Nothing! On input, record what you are given. You can always round/truncate on output. > * I only need date, time, and connect or disconnect, the other info is > not important Think about date and time as ONE piece of info. Use a "datetime" object in Python, not a "date" and a "time". Same story with the columns in your database. > * If it is possible to calculate the elapsed time between Connect and > Disconnect and create a new field with that data, that would help (but > I can easily do that with SQL queries) and you will be able to do that even more easily if you use one "datetime". A couple of quick silly questions: What do you do if servers are in different timezones? What if "John" connects before a daylight saving change and disconnects afterwards? Any chance of your using ISO standard format for representing dates? From mwm at mired.org Mon Aug 1 23:56:47 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 01 Aug 2005 23:56:47 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <861x5ehk4g.fsf@bhuda.mired.org> Message-ID: <86d5oxf0u8.fsf@bhuda.mired.org> Jorge Godoy writes: > Mike Meyer wrote: > >> We already have multiple distributions of Python: CPython, IronPython, >> and Jython (and there's at least one more). We even have multiple >> distributions of CPython, what with Active State doing their own and >> the MacPython distribution. I'm not proposing a fundamental change in >> the world, I'm suggesting an addition that would satisify the OPs >> needs. >> The "standard" distributor is whichever one your organization settles >> on when it comes time to choose a Python distribution. > So we don't solve the problem with a "standard" distribution and that was > the point I was trying to show. Exactly what problem are you trying to solve? If it's the one about not having a standard GUI, I don't think it's a problem. > In fact this sounds more like a joke I've heard a while ago: standards, if > you don't like the ones out there, create your own. Works for me. >> None of which has stopped linux from following this path. > > And solve a completely different problem while sharing the very same problem > you, on the post prior to mine, was trying to solve: what is the standard > GUI on a Linux distribution? QVWM? WindowMaker? Gnome? KDE? FVWM? I think you have me confused with someone else. I was responding to someone who was claiming that the lack of a standard enterprise strength GUI toolkit was a serious problem for Python - I disagree. I won't recap the thread, but other languages have been *very* successful without having a GUI as part of the language, all they had was one development environment distributed with a GUI. BTW, in answer to your rhetorical question about GUI's for Linux, the answer is plwm. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From sjmachin at lexicon.net Tue Aug 23 19:11:01 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Aug 2005 09:11:01 +1000 Subject: Reading just a few lines from a text file In-Reply-To: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> References: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> Message-ID: <430bad04$1@news.eftel.com> tkpmep at hotmail.com wrote: > I have a text file with many hundreds of lines of data. The data of > interest to me, however, resides at the bottom of the file, in the last > 20 lines. Right now, I read the entire file and discard the stuff I > don't need. I'd like to speed up my program by reading only the last 20 > lines. How do I do this? > > Thomas Philips > What discernible speed increase are you talking about? How long does it take to read the "many hundreds" of lines? For "many hundreds", IMHO it's not worth the bother, the complexity, the documentation, ... Just do this, it's about as fast as you'll get in pure python for a smallish file: def last_n_lines(filename, n): return open(filename, 'r').readlines()[-n:] For many hundreds of thousands of lines, one approach might be to open the file in binary mode, seek to the end of the file, then loop reading chunks backwards and unpacking the chunks until you've found 21 line terminators. Or perhaps 20 line separators :-) From gao_bolin at voila.fr Wed Aug 31 10:12:49 2005 From: gao_bolin at voila.fr (gao_bolin at voila.fr) Date: 31 Aug 2005 07:12:49 -0700 Subject: 'ps -A' command freezes Popen3 Message-ID: <1125497569.941285.85330@g49g2000cwa.googlegroups.com> Does anybody know why the following lines would freeze python [2.4.1 on Linux]: import popen2 a = popen2.Popen3('ps -A') a.wait() Thanks B. From max2 at fisso.casa Fri Aug 19 11:26:27 2005 From: max2 at fisso.casa (max(01)*) Date: Fri, 19 Aug 2005 15:26:27 GMT Subject: stdin -> stdout Message-ID: hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... while True: try: raw_input() except EOFError: break ... but i guess there must be a simpler way. using bash i simply do 'cat', *sigh*! bye max ps: in perl you ca do this: ... while ($line = ) { print STDOUT ("$line"); } ... From onurb at xiludom.gro Fri Aug 12 12:15:27 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 12 Aug 2005 18:15:27 +0200 Subject: Python's Exception, and Capitalization In-Reply-To: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> References: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> Message-ID: <42fccb20$0$22446$626a14ce@news.free.fr> Ray wrote: > Hello guys, > > OK, I've been reading some more about Python. There are some things > about Python exception that I haven't been able to grasp: > > 1. This is a small thing, but why is object spelled "object", and the > mother of all exception "Exception" (with capital E)? Why is not object > spelled "Object" then? I always wondered too... But then, you'll notice that Python's builtin types are usually all lowercase. (snip) > So when we write our own > classes, exceptions, etc., we should capitalize it like in Java or C#? Yes, definitively. > By the way, what's the convention for functions? It's a bit confusing > because when I see Python builtins, it seems that they follow C++ style > (e.g.: has_key, readline). So... does it mean that when I write my own > function, customarily I'd say myFunction() (or MyFunction()?) The all_lower_underscore is the common usage, at least in the std lib, but feel free to use your favorite convention for this. It's up to you as long as you stick to a given convention for a whole project. > 2. I'm quite baffled that you either have try/except, or try/finally. yes, it's a PITA. > In Java, it is quite common to do this: (snip) > It seems that since except and finally are mutually exclusive I can't > do this. So... what's the usual idiom for this? try: try: do_something() except Exception, e: handle_error(e) else: do_this_too() finally: do_this_whatever() -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From tjreedy at udel.edu Tue Aug 9 23:59:19 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 9 Aug 2005 23:59:19 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) References: <312cfe2b0508090753531e12de@mail.gmail.com> Message-ID: "Gregory Pi?ero" wrote in message news:312cfe2b0508090753531e12de at mail.gmail.com... > how references work in Python 'references' are an implementation detail and a metaconcept used to talk about Python but are not part of the language spec itself. > when passing arguments into functions? Python does not really 'pass arguments' in the way that is meant in name-memory_block languages like C, etc. Being a name-object language, it binds parameter names in the function's local namespace to the argument *objects*. bool1=True lst1=[1,2,3] def func1(arg1): arg1.append(4) def func2(arg1): arg1=False >>func1(lst1) >>lst1 [1,2,3,4] >>func2(bool1) >>bool1 True >Why does my list variable get changed for the rest of the program, but >my boolean variable doesn't. What am I not understanding? 1. Objects have types, names (variables) do not, although you can treat one as it if did by only binding it to objects of a particular type even though the interpreter will let you rebind it to any object of any type. 2. You have not one but two 'boolean variables': bool1 and arg1 in func2. You rebound arg1 but did not rebind bool1, so of course arg1 remains bound to what it was bound to. 3. On the other hand, you mutated (extended) the list bound to both lst1 and arg1 in func2, so of course it gets extended. You bindings and calls are equivalent to the following: lst1 = [1,2,3] arg1 = lst1 # this binds arg1 to the *same* object, not a copy arg1.append(4) # the *object* with two names is extended to [1,2,3,4] del arg1 # delete the alias # the list bound to lst1 and temporarily also to arg1 is still [1,2,3,4] # you could replace the last 3 lines with lst1.append(4) to the same effect bool1 = True arg1 = bool1 arg1 = False # this nullifies the line above del arg1 # ditto # you could delete the last 3 lines since they have no net effect # I hope you are not suprised that bool1 is still bound to True! Terry J. Reedy From gregpinero at gmail.com Fri Aug 26 11:40:24 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 26 Aug 2005 11:40:24 -0400 Subject: Embedding Python in other programs In-Reply-To: References: Message-ID: <312cfe2b050826084036db598f@mail.gmail.com> How do I get it into VB6? Now that's an answer that would save my life many times over. -Greg On 8/26/05, Alessandro Bottoni wrote: > > Thomas Bartkus wrote: > > > Name: lib64python2.4-devel > > Summary: The libraries and header files needed for Python development > > > > Description: The Python programming language's interpreter can be > extended > > with dynamically loaded extensions and can be embedded in other > programs. > > This package contains the header files and libraries needed to do these > > types of tasks. > > ------------------------------------------------------ > > > > > > *** The Python programming language's interpreter ... can be embedded in > > other programs. *** > > > > That's very intriguing! > > But I can't seem to locate much information about this. > > > > Can anyone direct me to greater enlightenment? > > Thomas Bartkus > > There is a section of the official documentation devoted to extending and > embedding python: > > http://docs.python.org/ext/ext.html > > There are a few articles on this topics on the web, as well. Search > "embedding python" with Google. > ----------------------------------- > Alessandro Bottoni > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From mfranklin1 at gatwick.westerngeco.slb.com Mon Aug 1 04:14:26 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Mon, 01 Aug 2005 09:14:26 +0100 Subject: Python IDE's In-Reply-To: <20050731205901.53A6E1E4005@bag.python.org> References: <20050731205901.53A6E1E4005@bag.python.org> Message-ID: Jon Hewer wrote: > Hi > > > > I am yet to find a Python IDE (for both Windows and Mac) that I like. > Any suggestions? > > > > Thanks > See:= http://wiki.python.org/moin/PythonEditors For more help Thanks Martin From polytechnique at gmail.com Tue Aug 30 10:56:14 2005 From: polytechnique at gmail.com (DENG) Date: 30 Aug 2005 07:56:14 -0700 Subject: how to join two Dictionary together? In-Reply-To: <1125413482.523747.106530@g47g2000cwa.googlegroups.com> References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> <1125413482.523747.106530@g47g2000cwa.googlegroups.com> Message-ID: <1125413774.726347.128950@f14g2000cwb.googlegroups.com> yes, that's really what i want! the 2nd replace the 1st one' value! thanks so much King From bokr at oz.net Sat Aug 13 13:34:54 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 13 Aug 2005 17:34:54 GMT Subject: how to append semicolon to a variable References: <1123946072.577232.218530@o13g2000cwo.googlegroups.com> Message-ID: <42fe2949.1360775902@news.oz.net> On 13 Aug 2005 08:14:32 -0700, "yaffa" wrote: >dear folks, > >i have the following lines of python code: > > couch = incident.findNextSibling('td') > price = couch.findNextSibling('td') > sdate = price.findNextSibling('td') > city = sdate.findNextSibling('td') > strUrl = addr.b.string >currently what this ends up doing is creating something like this > >couch3201/01/2004newyork > >now what i want to do is add a semicolon after the couch, price, sdate, >city so that i get something like this > >couch;32;01/01/2004;new york > >does anyone know how to do this? > >thanks > >yaffa > >p.s. i tried couch = couch + ';' and then i tried couch = couch + ";" >and then i tried couch = couch.append ';' > Assuming all your findNextSibling calls result in strings, as in >>> couch = 'couch' >>> price = '32' >>> sdate = '01/01/2004' >>> city = 'newyork' >>> You can put them in a list >>> [couch, price, sdate, city] ['couch', '32', '01/01/2004', 'newyork'] And join them with a string inserted between each successive pair of elements >>> ';'.join([couch, price, sdate, city]) 'couch;32;01/01/2004;newyork' If you like a space after each ';', just include it in the joiner string >>> '; '.join([couch, price, sdate, city]) 'couch; 32; 01/01/2004; newyork' >>> If all your items weren't string type, you'll have to convert first, e.g., >>> price = 32 >>> '; '.join([couch, price, sdate, city]) Traceback (most recent call last): File "", line 1, in ? TypeError: sequence item 1: expected string, int found >>> '; '.join(map(str,[couch, price, sdate, city])) 'couch; 32; 01/01/2004; newyork' If you have 2.4 and don't like map, you can use a generator expression: >>> '; '.join(str(x) for x in (couch, price, sdate, city)) 'couch; 32; 01/01/2004; newyork' or if you want the quoted strings >>> '; '.join(repr(x) for x in (couch, price, sdate, city)) "'couch'; 32; '01/01/2004'; 'newyork'" Note: if you want ';' appended to each item instead of just between items, you can just add ';' to the whole thing >>> '; '.join(str(x) for x in (couch, price, sdate, city)) + ';' 'couch; 32; 01/01/2004; newyork;' Which avoids the trailing blank you would get if you appended '; ' to every item before joining them, as in >>> ''.join(('%s; '%x) for x in (couch, price, sdate, city)) 'couch; 32; 01/01/2004; newyork; ' or >>> ''.join((str(x) + '; ') for x in (couch, price, sdate, city)) 'couch; 32; 01/01/2004; newyork; ' HTH Regards, Bengt Richter From rafi at free.fr Wed Aug 24 11:50:42 2005 From: rafi at free.fr (rafi) Date: Wed, 24 Aug 2005 17:50:42 +0200 Subject: Default function arguments behaving badly In-Reply-To: <1124898044.569156.217700@g49g2000cwa.googlegroups.com> References: <1124898044.569156.217700@g49g2000cwa.googlegroups.com> Message-ID: <430c9749$0$308$626a14ce@news.free.fr> jonny.longrigg at gmail.com wrote: > Hi hi > I'm having some trouble with a function I've written in Python: > > def myFunction(l1,l2,result=[]): > index=0 > for i in l1: > result.append([]) > if type(i)==list: > myFunction(i,l2,result[index]) > else: > for j in l2: > result[index].append(i*j) > index+=1 > return result > The problem is that it works if I run it once, but then on repeated > runs the value for 'result' doesn't seem to set itself to my default of > [], but instead uses the state it was in last time the function was > run. > Does anyone know what is going on here? Is there an easy solution? the list you provide as default parameter is evaluated once (at loading time of the function). so each time you call the function, it uses the same list that has been filled before... you do not have the problem with say and int or a string as they are non mutable objects. however lists are mutable objects so... modify your function as follow: def myFunction(l1,l2,result=None): if result is None: result = [] hth -- rafi "Imagination is more important than knowledge." (Albert Einstein) From Scott.Daniels at Acm.Org Tue Aug 9 11:35:38 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 09 Aug 2005 08:35:38 -0700 Subject: namespaces In-Reply-To: References: Message-ID: <42f8c492$1@nntp0.pdx.net> Paolino wrote: > Peter Otten wrote: >> Paolino wrote: >>> Why descriptor mechanism doesn't apply to modules? >> Because modules are instances of the module class and the descriptor >> has to be defined in the class in order to work with the instance.... > Then there is no way of having descriptors at module level,as 'module' > class is not updatable. Well, an entry in the dictionary "sys.modules" is what is returned by imports, so you could either pre-replace or post-replace a module by an object which uses the descriptor technique to get to some (but not necessarily all) of the attributes. Think of this technique as a hack to get to a goal, rather than a good technique to use; good for debugging, not so nice for production work. If you still don't know how to do this from this admittedly sketchy description, I'd suggest you avoid trying it altogether. --Scott David Daniels From ed at leafe.com Mon Aug 1 15:17:41 2005 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Aug 2005 15:17:41 -0400 Subject: Dabo in 30 seconds? In-Reply-To: <200508011200.35374.jstroud@mbi.ucla.edu> References: <1122901170.19618.296.camel@localhost.localdomain> <200508011200.35374.jstroud@mbi.ucla.edu> Message-ID: <200508011517.41240.ed@leafe.com> On Monday 01 August 2005 15:00, James Stroud wrote: > Perhaps some of us are writing software with non-developer end-users in > mind, and we kind of keep that mentality when evaluating modules our code > uses. Do your end-users really want to figure out that the need to and how > to install stylized text controls, whatever that is? Of course not. I think that the installation routine for wxPython should automatically include everything, rather than making you specify it explicitly, but I'm not in charge of how wxPython is distributed. Remember, though, that this is only an issue when you build wxPython from source. Those who aren't inclined to go this route have the option of several binaries, all of which include everything. So in a way, I *do* expect someone who has foregone the binary route and chosen the source route to at least read the build instructions. -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From rowen at cesmail.net Mon Aug 22 13:30:19 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Mon, 22 Aug 2005 10:30:19 -0700 Subject: How to get a unique id for bound methods? References: <43067d0e.1906448017@news.oz.net> Message-ID: In article <43067d0e.1906448017 at news.oz.net>, bokr at oz.net (Bengt Richter) wrote: >On Fri, 19 Aug 2005 16:33:22 -0700, "Russell E. Owen" >wrote: >[...] >> >>The current issue is associated with Tkinter. I'm trying to create a tk >>callback function that calls a python "function" (any python callable >>entity). >> >>To do that, I have to create a name for tk that is unique to my python >>"function". A hash-like name would be perfect, meaning a name that is >>always the same for a particular python "function" and always different >>for a different python "function". That would save a lot of housekeeping. >> >Why do you need a name? Can you post an example snippet that shows >a callback function being used with Tkinter as you would wish? >I have a feeling there is a much simpler solution than you are imagining ;-) Here is an example (simplified from my real code; I may have introduced an error in the process). I could switch to the twisted framework, but this code has been working very well and it saves my users from having to install a 3rd party package. -- Russell def addTkCallback(tk, func): tkName = "cb%d" % hash(func) tk.createcommand(tkNname, func) return tkName class TkSocket(TkBaseSocket): def __init__(self, addr, port, binary=False, readCallback = None, stateCallback = None, tkSock = None, ): ... try: # create the socket and configure it self._sock = self._tk.call("socket", ...) self._tk.call("fconfigure", self._sock, ...) # add callbacks; the write callback is just used to detect state readName =addTkCallback(self._tk, self._doRead) self._tk.call('fileevent', self._sock, "readable", readName) connName = addTkCallback(self._tk, self._doConnect) self._tk.call('fileevent', self._sock, "writable", connName except Tkinter.TclError, e: raise RuntimeError(e) From nemesis at nowhere.invalid Wed Aug 24 15:26:08 2005 From: nemesis at nowhere.invalid (Nemesis) Date: Wed, 24 Aug 2005 19:26:08 GMT Subject: Email client in Pyhton References: Message-ID: <20050824192915.2031.384.XPN@orion.homeinvalid> Mentre io pensavo ad una intro simpatica "knaren at midascomm.com" scriveva: > now i am planning to write a bear minimum email client in > pyhton. i found the smtp module of python could serve my > pupose. I can send message using mails using the smtp lib. > Now i'm looking for some modules which can help me in > fetching the mails from the mailserver and managing folders. > > I also look for some existing mail client, written in python > which wud serve my cause. Start reading related RFCs like RFC2822, RFC2045/6/7, RFC2231, RFC821 ... and then read Python documentation and you'll find that most of these RFC are supported/implemented by python modules like - email - smtlib - rfc822 As far I know the most complete mail client written in Python is Pyne, wich is a news/mail client written with PyGTK. I'm writing a newsreader (XPN), wich can send mail replies, maybe you can read its code. -- Never sleep with anyone crazier than yourself. |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org From claudio.grondi at freenet.de Mon Aug 29 18:30:13 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Mon, 29 Aug 2005 22:30:13 -0000 Subject: new line References: Message-ID: <3nh9j4F1dlfpU1@individual.net> "Kuljo" schrieb im Newsbeitrag news:K1KQe.28113$hV3.11465 at nntpserver.swip.net... > Dear friends > I'm so sorry to bore you with this trivial problem. Allthou: I have string > having 0x0a as new line, but I should have \n instead. > How should I solve it? > I've tried > >>>text_new=tex_old.replace(str(0x0a), '\n') > and other things, but none of them worked. > Thanks in advance text_new=tex_old.replace(chr(0x0a), '\r\n') works for me. Claudio P.S. str(0x0a) == '10' From sp1d3rx at gmail.com Fri Aug 26 13:19:23 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 26 Aug 2005 10:19:23 -0700 Subject: How to know if connection is active when using telnetlib? In-Reply-To: References: Message-ID: <1125076763.776592.118790@g47g2000cwa.googlegroups.com> Well, running this code: ---------- >>> import telnetlib >>> c = telnetlib.Telnet("blah") ---------- throws this exception: ---------- socket.gaierror: (11001, 'getaddrinfo failed') ---------- note that this is the same as your "telnetlib.Telnet.open". So, you will want to use TRY: and EXCEPT: to catch those errors, as in the example code below... ---------- import telnetlib try: c = telnetlib.Telnet("blah") except socket.gaierror: print "host could not be found." ---------- Note that the "socket.gaierror" is thrown when the hostname is invalid, and "socket.error" is thrown when the connection is refused. If you try to perform a "read" operation on a closed socket, you'll get thrown a "EOFerror" or you may get a Null value. You'll have to handle each case. I would suggest referring to the documentation at "http://www.python.org/doc/2.4/lib/telnet-objects.html" for more information about errors / exceptions returned. If there is none specified, chances are, it will throw a "socket.*" exception, or a Null value. From foo at bar.org Sun Aug 7 13:52:10 2005 From: foo at bar.org (stasz) Date: Sun, 07 Aug 2005 19:52:10 +0200 Subject: gettext again References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> Message-ID: On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote: > Hi, > I'm failing to make it work but can't find out what's wrong. Here's what > I do : [....] > How come ? What's wrong with what I am doing ? Start with this little howto about gettext. http://childsplay.sourceforge.net/translate-howto.html And then do this in your test.py: http://www.python.org/doc/2.4.1/lib/node330.html You should read the part about gettext in the Python Library Reference it's really good :-) Good luck, Stas Z From russandheather at gmail.com Wed Aug 10 21:32:54 2005 From: russandheather at gmail.com (Qopit) Date: 10 Aug 2005 18:32:54 -0700 Subject: "Compile time" checking? In-Reply-To: References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123697696.506898.66580@z14g2000cwz.googlegroups.com> Message-ID: <1123723974.522483.92740@o13g2000cwo.googlegroups.com> > if debug: print "v=%s" % (v,) Not that important, but I assume the first one was supposed to be: if debug: print "v=", s right? From a_schlapsi at yahoo.com Thu Aug 18 15:37:58 2005 From: a_schlapsi at yahoo.com (Andreas Schlapsi) Date: Thu, 18 Aug 2005 21:37:58 +0200 Subject: Moinmoin config In-Reply-To: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> References: <1124312825.655222.85300@g43g2000cwa.googlegroups.com> Message-ID: <18da$4304e393$506cf87a$23485@news.chello.at> > Hi, > > I have Moinmoin 1.3.4 installed and working on Linux RHEL3.0. However, > all screen elements are lined up on the left hand side. How can I get > it displayed like the wiki at: > > http://moinmoin.wikiwikiweb.de/HelpOnConfiguration > Hi Mark, It seems that your MoinMoin installation works besides the links to the styles and images. I would check the url_prefix = '/wiki' line in your wikiconfig.py file. url_prefix should be set to the name of the alias for "/usr/share/moin/htdocs" (the path may vary on your system) in your Apache configuration. I had the same problem and I had changed the line to the URL prefix for my wiki by mistake. From mwh at python.net Fri Aug 5 07:32:43 2005 From: mwh at python.net (Michael Hudson) Date: Fri, 05 Aug 2005 11:32:43 GMT Subject: Art of Unit Testing References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> <7xpssu8hzw.fsf@ruckus.brouhaha.com> Message-ID: "Terry Reedy" writes: > "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message > news:7xpssu8hzw.fsf at ruckus.brouhaha.com... >> I knew there was some other one before unittest came along but I thought >> unittest was supposed to replace the older stuff. > > I believe unittest was an alternative rather than replacement for doctest. Around the time pyunit got added to the stdlib (as unittest) there were some other candidates (one written by AMK et al at the MEMS Exchange -- Sancho or something like that?), and pyunit got chosen by the python-dev cabal, for reasons I don't recall now. It's probably in the archives. >> What's the preferred one, Pythonically speaking? > > py.test was written, apparently, by pypy folks to replace unittest for pypy > testing. That is a teeny bit inaccurate -- it's mostly Holger Krekel's work, though his work on pypy was quite a lot of the inspiration. Armin Rigo helped a lot, the other PyPy people less so, on average. > To me, it is more Pythonic in spirit, and I plan to try it for an > upcoming TDD project. It's very cool, indeed. Cheers, mwh -- Darn! I've only got 10 minutes left to get falling-down drunk! I suppose I'll have to smoke crack instead now. -- Tim Peters is checking things in on 2002-12-31 From http Sun Aug 14 15:03:53 2005 From: http (Paul Rubin) Date: 14 Aug 2005 12:03:53 -0700 Subject: FTP over SSL (explicit encryption) References: <6sMLe.3055$%K4.765@trnddc09> Message-ID: <7xoe80gx2e.fsf@ruckus.brouhaha.com> "David Isaac" writes: > Just found this: > http://trevp.net/tlslite/ > I haven't even had time to try it, > but I thought you'd want to know. Tlslite is a very well done and promising package, but in its present form it's not really complete. It's missing important functionality (the ability to validate certificates) that it relies on complex 3rd party C libraries to provide. Hopefully tlslite will be able to do this by itself sometime soon. From fredrik at pythonware.com Wed Aug 24 01:20:48 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 24 Aug 2005 07:20:48 +0200 Subject: Sorta noob question - file vs. open? References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> Message-ID: Peter A.Schott wrote: > Been reading the docs saying that file should replace open in our code, > but this > doesn't seem to work: what docs? "open" is the preferred way to open a file. "file" is a type constructor. in contemporary python, they happen to map to the same callable, but that's not necessarily something that will also apply to future releases. see: http://mail.python.org/pipermail/python-dev/2004-July/045921.html http://mail.python.org/pipermail/python-dev/2004-July/045967.html > # Open file for writing, write something, close file > MyFile = file("MyFile.txt", "w") > MyFile.write("This is a test.") > MyFile.close() instead of saying that something "doesn't seem to work", it's always more helpful to explain what happens. do you get a traceback? what does the traceback say? > However, using: > MyFile = open("MyFile.txt", "w") > MyFile.write("This is a test.") > MyFile.close() > > I have no problems. From sp1d3rx at gmail.com Fri Aug 26 13:03:20 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 26 Aug 2005 10:03:20 -0700 Subject: telnet.read_until() from telnetlib In-Reply-To: References: Message-ID: <1125075800.736986.28480@g43g2000cwa.googlegroups.com> Czesc Jacek: Please post the minimum code necessary to duplicate the problem. Dzieki, Derek Wilson From pinard at iro.umontreal.ca Wed Aug 17 19:48:15 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Wed, 17 Aug 2005 19:48:15 -0400 Subject: creating/modifying sparse files on linux In-Reply-To: <1124314877.646737.266290@z14g2000cwz.googlegroups.com> References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> <1124314877.646737.266290@z14g2000cwz.googlegroups.com> Message-ID: <20050817234815.GA7654@phenix.progiciels-bpi.ca> [draghuram at gmail.com] > Is there any simple way of generating this 1MB string (other than keep > appending to a string until it reaches 1MB len)? You might of course use 'x' * 1000000 for fairly quickly generating a single string holding one million `x'. Yet, your idea of generating a sparse file is interesting. I never tried it with Python, but would not see why Python would not allow it. Did someone ever played with sparse files in Python? (One problem with sparse files is that it is next to impossible for a normal user to create an exact copy. There is no fast way to read read them either.) -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From rkern at ucsd.edu Wed Aug 24 15:08:52 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 24 Aug 2005 12:08:52 -0700 Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <7x7jeflj8d.fsf@ruckus.brouhaha.com> Message-ID: Bryan Olson wrote: > Paul Rubin wrote: > > Bryan Olson writes: > > > >> seq[3 : -4] > >> > >>we write: > >> > >> seq[3 ; $ - 4] > > > > +1 > > I think you're wrong about the "+1". I defined '$' to stand for > the length of the sequence (not the address of the last > element). By "+1" he means, "I like it." He's not correcting you. -- 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 lycka at carmen.se Fri Aug 19 08:05:13 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 19 Aug 2005 14:05:13 +0200 Subject: up to date books? In-Reply-To: <9Q4Ne.974$No6.23346@news.tufts.edu> References: <1124389787.873698.205070@g47g2000cwa.googlegroups.com> <9Q4Ne.974$No6.23346@news.tufts.edu> Message-ID: John Salerno wrote: > These all seem to be focused on Java though. I think C# is close enough to Java when it comes to the issues discussed here, that you can read the texts and more or less think C# when you read Java... > gene tani wrote: > >> Start here: >> >> http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing >> http://dirtsimple.org/2004/12/java-is-not-python-either.html >> http://ischenko.blogspot.com/2005/02/java-may-not-be-that-bad-after-all.html >> >> >> and maybe poke around ehre to learn about language design, how people >> define typing, etc >> http://www.artima.com/ >> From noreply at gcgroup.net Sun Aug 14 16:29:39 2005 From: noreply at gcgroup.net (William Gill) Date: Sun, 14 Aug 2005 20:29:39 GMT Subject: help with mysql cursor.execute() In-Reply-To: <42ff9415$1@nntp0.pdx.net> References: <8XMLe.878$Z%6.698@newssvr17.news.prodigy.com> <42ff9415$1@nntp0.pdx.net> Message-ID: I have been testing and it seems that: 1- Cursor.execute does not like '?' as a placeholder in sql 2- Cursor.execute accepts '%s' but puts the quotation mark around the substitution. sql = 'select * from %s where cusid = ? ' % name Cursor.execute(sql, (recID,)) still fails, but: sql = 'select * from basedata where cusid = %s ' Cursor.execute(sql, (recID,)) works regardless of recID being a string or an int. Obviously this stems from trying to parameterize the table name. If I use: sql = 'select * from %s where cusid = %%s ' % name Cursor.execute(sql, (recID,)) It makes 1 substitution in the first line, and another in the execute() sql = 'select * from %s where cusid = %%s ' % name # sql now == 'select * from basedata where cusid = %s ' Cursor.execute(sql, (recID,)) and it works. Between your comments re: column names and table names , and the notes in cursor.py, I was able to figure it out. FYI I wanted to create a tableHandler class that could be extended for individual tables. That's why the query needs to accept variables for tablename. Thanks. Bill Scott David Daniels wrote: > William Gill wrote: > >> I have been trying to pass parameters as indicated in the api. >> when I use: >> sql= 'select * from %s where cusid = %s ' % name,recID) >> Cursor.execute(sql) >> it works fine, but when I try : >> sql= 'select * from %s where cusid like %s ' >> Cursor.execute(sql,(name,recID)) >> or >> sql= 'select * from ? where cusid like ? ' >> Cursor.execute(sql,(name,recID)) >> it fails. >> Can someone help me with the semantics of using parameterized queries? > > > Neither column names nor table names can be parameters to > fixed SQL. Values are what you fiddle with. This squares with > the DBMS being allowed to plan the query before looking at the > parameters (deciding which indices to use, which tables to join > first, ...), then reusing the plan for identical queries with > different values. MySQL may not take advantage of this two-step > approach, but the DB interface is designed to allow it, so > the parameterization is constrained. > > See if something like this works: > > sql = 'select * from %s where cusid like ? ' % name > Cursor.execute(sql, (recID,)) > > --Scott David Daniels > Scott.Daniels at Acm.Org From nszabolcs at gmail.com Thu Aug 18 07:30:29 2005 From: nszabolcs at gmail.com (Szabolcs Nagy) Date: 18 Aug 2005 04:30:29 -0700 Subject: Python for Webscripting (like PHP) References: Message-ID: <1124364629.875019.302350@g47g2000cwa.googlegroups.com> I don't think stdlib offers anything like that The problem with python is it's white space sensible and html is not. However there are some nice solutions: http://www.webwareforpython.org/Papers/Templates/ my favourite is not listed here: http://karrigell.sourceforge.net/ For web development with python i'd rather recommend a complete webframework: http://www.djangoproject.com/ http://subway.python-hosting.com/ http://www.zope.org/ nszabolcs From jeffrey.schwab at rcn.com Sat Aug 13 16:58:51 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sat, 13 Aug 2005 16:58:51 -0400 Subject: Spaces and tabs again In-Reply-To: References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> Message-ID: Christopher Subich wrote: > sigzero at gmail.com wrote: > >> Are you kidding? You are going to MANDATE spaces? > > > Actually, future whitespace rules will be extensive. See: > http://64.233.187.104/search?q=cache:k1w9oZr767QJ:www.artima.com/weblogs/viewpost.jsp%3Fthread%3D101968 > > (google cache of > http://www.artima.com/weblogs/viewpost.jsp?thread=101968 because it > seems to be down at the moment) > > The only change from April 1, 2005 is that the enforcement is punted > until Python 3.0, because of the source-incompatible nature of the change. > > "Lrf, vg'f na Ncevy Sbbyf' wbxr.".decode('rot13') Downright unpythonic! -- """Va Nhthfg? Gung'f pehry. V nyzbfg jrag onpx gb Crey! Univat arire frra "GBBJGQV" orsber abj, V nz fgvyy ynhtuvat cerggl uneq. """.decode('rot13') From http Mon Aug 1 17:16:09 2005 From: http (Paul Rubin) Date: 01 Aug 2005 14:16:09 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <7x1x5do2da.fsf@ruckus.brouhaha.com> <7xirypjsua.fsf@ruckus.brouhaha.com> Message-ID: <7xack1jr3a.fsf@ruckus.brouhaha.com> Cliff Wells writes: > It was quite clear that by saying "most people" he was not referring to > the set of "most Python users", but rather the set of "most people who > have tried wxPython". That wasn't clear to me. If that's what he meant, he should have said so. From nephish at xit.net Thu Aug 18 20:33:37 2005 From: nephish at xit.net (nephish at xit.net) Date: 18 Aug 2005 17:33:37 -0700 Subject: question about binary and serial info In-Reply-To: <430510da.1813212441@news.oz.net> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <1124386952.353027.93050@g47g2000cwa.googlegroups.com> <430510da.1813212441@news.oz.net> Message-ID: <1124411617.346508.85500@o13g2000cwo.googlegroups.com> thanks for your time. i have started just doing a type(a) from idle a lot just so i can make sure of what i am dealing with ( i do this a lot) before i build the .py file. got tired of 'cannot concatonate str and init' stuff all the time. this has been a wild project. nothing like getting in way over your head to crash learn something. i really dig python. just was going outta my onion over this one. thanks again shawn From could.net at gmail.com Mon Aug 8 23:15:13 2005 From: could.net at gmail.com (could ildg) Date: Tue, 9 Aug 2005 11:15:13 +0800 Subject: Python Project (sigh with Java) In-Reply-To: References: Message-ID: <311b5ce105080820154ce80823@mail.gmail.com> Good job~ I also like both java and py so I always focus on jython, but now it's being moved forward kinda slow. I'm looking forward to jython 2.4. You're right, swing is great. wxpy is also wonderfu but it's so lack of docs. I mainly work on windows so I use p4d(python for delphi), I use delphi for UI and use py for some other works. p4d is magic, I like it. And I recommend it to everyone who is familiar with both py and delphi. On 8/9/05, Ramza Brown wrote: > I know you may frown at my use at java, but this is a pretty simple way > to create GUIs quickly, using Java's swing. I have some code for an > approach for integrating the swing GUI components and python. I threw > the project together in a couple of days, so it is not some massive > application. And, I have some little models(hehe). Anyway, if you want > to check out an approach for working with Jython, here it is. > > Some questions, I do get asked, how do you us python code in java. I > normally don't like using my python objects in the java code. > Basically, there is never the *.java files. You can do everything in > python, it is a lot simpler, short of language constructs you can only > do in java. > > This is a HTML code generator, you only need a java runtime. > > http://www.newspiritcompany.com/phoenixproj.html > > -- > Ramza from Atlanta > http://www.newspiritcompany.com > -- > http://mail.python.org/mailman/listinfo/python-list > From fairwinds at eastlink.ca Mon Aug 22 14:32:45 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Mon, 22 Aug 2005 15:32:45 -0300 Subject: setup install question In-Reply-To: <430a133d$0$11065$e4fe514c@news.xs4all.nl> Message-ID: <22141C12-133B-11DA-8B5A-000A27B3B070@eastlink.ca> I have two versions of python running - 2.4.1 and 2.3.5. Python 2.4.1 is most current and will execute from 'python' at command line where 2.3.5 will execute from 'python2.3'. A recent problem I have is installing rdflib. It installed and works fine on 2.4.1. rdflib uses 'python setup install' for install from command line (fine for the 2.4.1 version) but if won't install with python2.3 setup install without generating a traceback. It is somehow looking at the 2.3 following python as parameters for the version of rdflib. Can I safely copy from 2.4.1 site-packages to 2.3.5's to make rdflib available to 2.3.5 python? Many thanks David From john at castleamber.com Fri Aug 26 17:42:35 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 21:42:35 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: Denis Kasak wrote: > John Bokma wrote: >> >> You can't be sure: errors in the handling of threads can cause a >> buffer overflow, same for spelling checking :-D > > Yes, they can, provided they are not properly coded. However, those > things only interact locally with the user and have none or very > limited interaction with the user on the other side of the line. As > such, they can hardly be exploitable. Uhm... one post can affect a number of clients, hence quite exploitable. >> Some people never use them, and hence they use memory and add risks. > > On a good newsreader the memory use difference should be irrelevantly > small, even if one does not use the features. I would call that a > nitpicky argument. Xnews - 10 M Thunderbird - 20 M There was a time I had only 128M in this computer :-D. And there was a time I read news on a RISC OS machine. I guess the client was about 300 K (!). > Also, the risk in question is not comparable > because of the reasons stated above. The kind of risk you are talking > about happens with /any/ software. True. The more code, the more possibilities on holes. > To stay away from that we shouldn't > have newsreaders (or any other software, for that matter) in the first > place. telnet :-P. >> Of course can HTML be useful on Usenet. The problem is that it will >> be much more often abused instead of used. > > No, you missed the point. I am arguing that HTML is completely and > utterly /useless/ on Usenet. But I beg to differ :-). I can think of several *good* uses of HTML on Usenet. But like I said, it will be abused. And you can't enforce a subset of HTML. > Time spent for writing HTML in Usenet But you are not going to *write* HTML, you let your client hide that. I mean, it's not that hard to have a client turn *bold* into bold :-). > posts is comparable to that spent on arguing about coding style or Agreed, I have learned things from arguing on coding style, even adjusted my style based on it. > writing followups to Xah Lee. Ok, now there is something one shouldn't spent time on :-) > It adds no further insight on a > particular subject, Yes, it does. That's why for example figures, tables, and now and then colours are used in scientific publications. ASCII art, now that's a huge waste of time. > but _does_ add further delays, spam, bandwidth > consumation, exploits, and is generally a pain in the arse. It's > redundant. I have to disagree. Mind, I am not saying that HTML *should* be used on Usenet, I am happy with Usenet as it is, but I wouldn't call it useless nor redundant. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From hancock at anansispaceworks.com Sun Aug 21 08:37:58 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sun, 21 Aug 2005 07:37:58 -0500 Subject: Automatic documentation options Message-ID: <200508210737.58626.hancock@anansispaceworks.com> I've been trying to use "happydoc" to document a source tree that I'm working on. It does pretty much what I want, except: Version 2.1: Creates a weird directory structure for the HTML pages it generates -- they embed the full path to the working copy of the sources, which, beyond just being ugly, would be pretty annoying for a collaborative project (each collaborator's copy would produce documentation in separate directories, probably resulting in duplication). Version 3-alpha: Solves that problem, but very incomplete compared to 2.1, and apparently abandoned in 2003 (maybe because of pydoc?). Various options aren't available, and, for example it forces me to use "README.txt" instead of just "README" if I want it to collect that information. Neither version documents class attributes, which is somewhat annoying, because they are part of my interface. But I can fix this with the docstrings, of course. Now I've considered using pydoc, but it seems to be very weak in this kind of application (generating a tree of static HTML pages to provide library documentation). On the plus side, I find its overall layout prettier, and it does include attributes. But it also includes a lot of garbage (such as symbols loaded by "from pygame.locals import *"), doesn't apparently understand the structured text docstrings, and finally, it chokes on some modules because it can't find all of their imports (because I'm trying to run it from the documentation directory). I don't think happydoc has this problem, because it doesn't attempt to import the module in order to generate documentation, so it only documents what is actually defined in that module. It also reads comment lines, which can be a plus. Unlike happydoc, pydoc doesn't seem to have many command line options for changing any of this behavior, so if you don't like it, you seem to be stuck. So while I use pydoc quite a lot for on-the-fly documentation, I'm not so happy with it as a docset generator (or maybe I just don't know how to get it to do what I want?). What I really want to do is to have a set of (static) HTML documentation pages that I write, that are deep-linked into an automatically generated set of library documentation. Any suggestions on getting pydoc, happydoc, or yet another documentation generator to do this, would be greatly appreciated. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From en.karpachov at ospaz.ru Fri Aug 12 02:18:58 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Fri, 12 Aug 2005 10:18:58 +0400 Subject: Python supports LSP, does it? In-Reply-To: References: <20050811105151.736450c8.jk@ospaz.ru> Message-ID: <20050812101858.7e39b706.jk@ospaz.ru> On Thu, 11 Aug 2005 15:02:08 -0400 Terry Reedy wrote: > I remember discussion of the LSP on comp.object some years ago when I > was reading it. (I presume there still are, just don't read it > anymore.). One of the problems is that biology and evolution do not > obey it. Birds (in general) can fly, I suspect it is not the exact scientific criteria used in the biology whether an animal ISA bird, is it? I mean, flying is not bird property in the biological sense, so it is nothing against the LSP here. > but those in the ratite family, evolved later than order > aves, cannot. -- jk From peter at engcorp.com Mon Aug 8 17:47:53 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 08 Aug 2005 17:47:53 -0400 Subject: python for microcontrollers In-Reply-To: <42f7ce06$1@news.orcon.net.nz> References: <42f7c8d4$1@news.orcon.net.nz> <42f7ce06$1@news.orcon.net.nz> Message-ID: Evil Bastard wrote: > Benji York wrote: >>Perhaps porting Pyrex would be easier. > Pyrex totally rocks. But for the PIC targetting, no can do: ... > Any other suggestions? Yes, port Lua instead. Lua is pretty much designed for this sort of application, and is probably "Pythonic" enough to provide whatever advantages you were trying to get from using Python, short of it actually being Python. FWIW, the interpreter/virtual machine appears to be designed to be very conservative with memory, though there's a chance it is somewhat tied to having 32-bit integers available (yet could perhaps be ported easily to some freaky 12-bit microcontroller anyway :-) ). -Peter From nd51 at le.ac.uk Wed Aug 10 04:36:13 2005 From: nd51 at le.ac.uk (N.Davis) Date: Wed, 10 Aug 2005 09:36:13 +0100 Subject: What are modules really for? References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> Message-ID: <42F9BC7D.1050300@le.ac.uk> Thanks very much for your helpful replies. I totally accept my C++/Java background is a lot of this, and I need to make the shift to Python's way of thinking. As for multiple inheritance, yes I've always been aware of it being available in C++, but I learned C++ at a company which banned multiple inheritance in their coding standards, with comments about "The GOTO of the 1990s". Like people here, I've no complaints about not using multiple inheritance. ;-) But Zope/Plone uses it therefore I have to understand it... Functions existing in a module? Surely if "everything is an object" (OK thats Java-talk but supposedly Python will eventually follow this too) then there should be nothing in a module thats not part of a class. Even a static method is simply a class function that operates on the "collection of all instances" rather than a single instance. Related classes in the same file? Be careful. Doesn't anything "knowing" about anything else compromise encapsulation? Why would properly-designed classes have such a close relationship? Having back in the day worked on big real-time systems where being very strict about encapsulation was a god-send for fighting complexity, I feel unnerved by Perl and Python's laid-back OO culture of "you can do it if you feel like it but don't have to". While you could do all manner of nasty hacks in C++ I worked with people who carefully avoided this. Maybe that was just luck.... Thanks again. :-) Nick infidel wrote: >>I am very new to Python, but have done plenty of development in C++ and >>Java. > > > And therein lies the root of your question, I believe. > > >>One thing I find weird about python is the idea of a module. Why is this >>needed when there are already the ideas of class, file, and package? > > > One reason is that functions need a place to exist too. In Java, every > function, even "static" ones has to be a class method. In Python, > "static" functions are best kept in a module. Another thing is that > packages were a later addition to the language. > > >>To my mind, although one CAN put many classes in a file, it is better to >>put one class per file, for readability and maintainability. > > > Personally I find it easier to maintain a set of related classes when > they're all in the same file. I've got a few modules that I'm > currently hacking on, each of which contains a handful of classes. > Maybe it's just a matter of scale, since these are both fairly small > libraries, but I just don't see any advantage to splitting them up into > multiple files. > > >>One can then create packages and libraries, using groups of files, one >>class per file. > > > Since Java's compiler enforces this, perhaps you've just come to accept > it as "normal". > > >>Python seems to let you group classes together in one file and call it a >>module, but what for? > > > What if one of your classes creates/manipulates other classes. If > they're in the same module then they all exist in the same namespace > and you don't have to have modules importing each other or such things. > > >>I find that this, combined with mixins, makes it difficult to find out >>where code is inherited from. > > > Perhaps you are relying too much on inheritance, then? > > >>With single inheritance in C++ or Java, if you wanted to see what a >>method did and it appeared to be inherited, you would simply look in the >>base class's file, and if necessary recurse up the inheritance hierarchy >>until you found the method. >> >>With Python an inherited method could be in one of many base classes >>and/or mixins and there seems no particular logic as to what the >>filename would be. > > > It shouldn't be too hard to figure out, unless someone was being > intentially vague. You could always fire up the interpreter, import > your class, and check it's .mro property (method resolution order), > which lists the classes in the order they will be examined to find a > method named at runtime. > > >>Am I missing something? > > > I just think you're thinking in terms of Java. You'll pick things up > quickly, though :-) > From nothingcanfulfill at gmail.com Tue Aug 9 20:46:47 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 9 Aug 2005 17:46:47 -0700 Subject: Import question In-Reply-To: <1123614152.482652.72900@g44g2000cwa.googlegroups.com> References: <1123614152.482652.72900@g44g2000cwa.googlegroups.com> Message-ID: <1123634807.617032.271850@g14g2000cwa.googlegroups.com> Hmm...thanks for the replies. Judging by this, it looks like I might still be in a slight perdiciment with doing it all, but time will tell. I wish there were a way I could reference across multiple modules. Well, thanks for your help. Hopefully I'll be able to work out some *simple* solution for all of this. -Wes From apardon at forel.vub.ac.be Tue Aug 23 05:39:23 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 Aug 2005 09:39:23 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-22, Donn Cave schreef : > Before leaving this topic, I wanted to make a rare visit > to the ruins of Google's USENET archive and pull out this > giant post on the subject of True and False, when they were > being considered for adoption into Python. There is some > stuff to ignore, where she addresses questions that didn't > go anywhere, but she goes on to write a well articulated > case that makes very interesting reading, and possibly has > had some effect on how people think about it around here. > > http://groups-beta.google.com/group/comp.lang.python/msg/2de5e1c8384c0360 Well I guess she and I disagree here. I also don't understand some of her arguments. e.g. about code like: "if var == True" | Aaargh! | I already see too much code like this. It's mostly written by people | who come from other languages. They define their own True and False so | they can do this. I would argue that this would be bad code even in these other languages. Heck when I was still a student and getting a course in PASCAL, people with no programming experience whatsoever would write code like that and PASCAL does have a real BOOLEAN type. So where she gets the idea that "if var == True" is a symptom of a language that has no real BOOLEAN type (as python now has IHO) is beyond me. -- Antoon Pardon From paolo_veronelli at tiscali.it Wed Aug 10 07:05:34 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Wed, 10 Aug 2005 13:05:34 +0200 Subject: namespaces In-Reply-To: <42f8e67a.1015992700@news.oz.net> References: <42f8c492$1@nntp0.pdx.net> <42f8e67a.1015992700@news.oz.net> Message-ID: <42F9DF7E.1080204@tiscali.it> Bengt Richter wrote: > Another thought/bf would be a way to extend the attribute namespace of an arbitrary object > by chaining the attribute name spaces of a sequence of objects (this would be a language mod) > e.g., (sort of a dynamic instance attribute mixin) > > obj ..= a, b, c # a sequence of objects > > then > > obj.x # looks for obj.x, then a.x then b.x then c.x before giving up with attribute error > obj ..=() # clears chained attribute name space ? > Something like a __lookup__ attribute for all instances which are namespaces. Are all objects namespaces or have all objects a namespace? Also syntax: lookup(obj).append(x) I suppose bound methods will not be found,but in that case some tolerant unbound methods could do,naturally if the PEP on eliminating them will be accepted.That check they do on the first parameter they push in the function (aka 'self') is really contrasting dinamycal Python IMO. > Then you could add a property to the namespace of a module by adding an object whose class defines > the property, like > > mod ..= objhavingproperty # same tuple ambiguity as with 'somestr' % x > > something analogous to += on immutables would have to be done for builtin objects I suppose. This is a little hard for me.Has it something to do with extensions also? Regards Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From peter at engcorp.com Tue Aug 9 07:52:29 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 09 Aug 2005 07:52:29 -0400 Subject: .pth files In-Reply-To: References: Message-ID: Neil Benn wrote: > * Site.py is prompted to load a sitecustomise.py file which is > located in the Lib directory - if it is there. This file is > automatically executed on the start up of python. Here you can > look for a command line argument (or a local config file) passed > in - you can then go and find the .pth file yourself. The code to > pull in .pth stuff is located in the site.py file - you can import > this function and use it but I don't do that for two reasons > (instead I pull across my own copy - effectivly freezing that > implementation): > > 1. You are creating a circular reference The "import sitecustomize" stuff is placed effectively at the end of site.py, so it should be quite safe to "import site" from your sitecustomize.py file and use the functions there. > 2. I can find no docs or imformation about using the functions > in the site.py file so therefore I have to assume that the > functions in the site.py file are not designed to be used > this way and therefore shouldn't be relied upon to be stable > or even present across python releases (I'm a conservative > programmer. While I can't fault your caution, we've been using a few things in site.py from sitecustomize for a while with no problems (across releases from Python 1.5.2 to Python 2.4). The functions are documented in the site.py source itself, of course, at least in a cursory fashion, and while there have been changes over versions, I don't recall anything causing breakage. Normally I'd quite agree about staying away, but for something like this (i.e. not a core part of an application, but something to set up the environment instead) I'd say "go for it". -Peter From paolo_veronelli at tiscali.it Wed Aug 10 06:28:08 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Wed, 10 Aug 2005 12:28:08 +0200 Subject: namespaces In-Reply-To: <42f8c492$1@nntp0.pdx.net> References: <42f8c492$1@nntp0.pdx.net> Message-ID: <42F9D6B8.5040205@tiscali.it> Scott David Daniels wrote: > Well, an entry in the dictionary "sys.modules" is what is returned by > imports, so you could either pre-replace or post-replace a module by > an object which uses the descriptor technique to get to some (but not > necessarily all) of the attributes. Think of this technique as a > hack to get to a goal, rather than a good technique to use; good for > debugging, not so nice for production work. If you still don't know > how to do this from this admittedly sketchy description, I'd suggest > you avoid trying it altogether. > Thanks.Is don't know if this is *the* way to wrap the module ? import new,sys class Free(new.module): def __init__(self,moduleName): new.module.__init__(self,moduleName) assert moduleName in sys.modules self.__dict__.update(sys.modules[moduleName].__dict__) sys.modules[moduleName]=self def desc(self): pass Free(__name__) #'no errors' but 'desc' is not defined in this namespace. Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From mwh at python.net Tue Aug 30 08:18:59 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 30 Aug 2005 12:18:59 GMT Subject: Yielding a chain of values References: Message-ID: Talin writes: > I'm finding that a lot of places within my code, I want to return the > output of a generator from another generator. Currently the only > method I know of to do this is to explicitly loop over the results > from the inner generator, and yield each one: > > for x in inner(): > yield x > > I was wondering if there was a more efficient and concise way to do > this. And if there isn't, Greenlets, perhaps? (for which, see google). Cheers, mwh -- LINTILLA: You could take some evening classes. ARTHUR: What, here? LINTILLA: Yes, I've got a bottle of them. Little pink ones. -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From hancock at anansispaceworks.com Sun Aug 21 10:35:32 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sun, 21 Aug 2005 09:35:32 -0500 Subject: Automatic documentation options In-Reply-To: <200508210737.58626.hancock@anansispaceworks.com> References: <200508210737.58626.hancock@anansispaceworks.com> Message-ID: <200508210935.32269.hancock@anansispaceworks.com> On Sunday 21 August 2005 07:37 am, Terry Hancock wrote: > I've been trying to use "happydoc" to document a source > tree that I'm working on. > [...] > Any suggestions on getting pydoc, happydoc, or yet another > documentation generator to do this, would be greatly appreciated. Ah, well, it looks like epydoc will do what I need http://epydoc.sourceforge.net The module import error I mentioned was actually a real bug in my sources, when fixed, pydoc (and epydoc) don't seem to have a problem with them. Doesn't address the general issue, but it works fine for this project. The only remaining problem is that epydoc doesn't seem to understand Structured Text, despite having an option for it ('--docformat="restructuredtext"'). Good enough though. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From nomail at nomail.com Thu Aug 25 09:19:10 2005 From: nomail at nomail.com (Nx) Date: Thu, 25 Aug 2005 21:19:10 +0800 Subject: variable hell Message-ID: <430dc538@127.0.0.1> Hi I am unpacking a list into variables, for some reason they need to be unpacked into variable names like a0,a1,a2....upto aN whatever is in the list. How to create the variables dynamically ? I am looking for something like pseudo code line follows : a%s = str(value) here below is a snippet from the mylist unpack code #next lines cut the end of line character from each line in the list mylist = [line[:-1] for line in mylist] for index,value in enumerate(mylist): if index == 0 : a0 = str(value) print "a0 : ",a0 elif index == 1 : a1 = str(value) print "a1 : ",a1 Thanks Nx From ed at leafe.com Thu Aug 11 13:20:42 2005 From: ed at leafe.com (Ed Leafe) Date: Thu, 11 Aug 2005 13:20:42 -0400 Subject: [ANN] Dabo Runtime for Windows 0.4 Released Message-ID: <200508111320.42074.ed@leafe.com> We've just updated the Dabo Runtime for Windows. This allows someone who is running Windows to try out Dabo without having to install any prerequisites, not even Python itself. It includes the latest version of the Dabo framework, as well as the demo apps and the (still-under-construction) visual design tools. As usual, it can be found, along with our other stuff, at http://dabodev.com/download. -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From bignose+hates-spam at benfinney.id.au Fri Aug 12 19:57:08 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2005 09:57:08 +1000 (EST) Subject: Cheese shop (was Re: python2.4/site-packages) References: <7sadneieT7f10mHfRVn-gw@speakeasy.net> Message-ID: Erik Max Francis wrote: > I came across the change a good while back in my Web referrals, not > having heard of it except passively. PyPI was a simple, clear, > unambiguous name; Cheese Shop is just a silly name for no purpose. Conversely, PyPI is a dull name with no obvious pronunciation, thus difficult to remember; whereas Cheese Shop is a short phrase (that can be translated), is easy to remember and has easy analogies to its actual function. -- \ "Compulsory unification of opinion achieves only the unanimity | `\ of the graveyard." -- Justice Roberts in 319 U.S. 624 (1943) | _o__) | Ben Finney From pd at traxon.com Tue Aug 23 11:58:13 2005 From: pd at traxon.com (Paul Dale) Date: Tue, 23 Aug 2005 17:58:13 +0200 Subject: Nested Regex Conditionals Message-ID: <430B4795.3060307@traxon.com> Hi All, I know that several of you will probably want to reply "you should write a parser", and I may. For that matter any tips on theory in that direction would be appreciated. However, if you would indulge me in my regex question I would also be most grateful. I'm writing an edi parser and to be in compliance with the specification I need to have conditionals that are dependent on conditionals. In some regular expression implementations this is possible. The code ... #!/usr/bin/env python import re pattern = re.compile(r""" (?P(first)) (?(first) (?P(second)) ) (?(second) (?P(third)) ) """, re.VERBOSE) string = 'firstsecondthird' match = re.match(pattern,string) print match.group('first','second','third') Prints ('first', 'second', None) and I haven't found any way to have a second conditional, nor any reference to it in any documentation I've found. Am I missing something, and it is possible? Or is it not possible in python? It seems like it might be a bug, as it knows there is a group (None, instead of an IndexError), but it doesn't match ... Thanks for any help :) Paul From john at castleamber.com Fri Aug 26 07:04:01 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 11:04:01 GMT Subject: Usenet, HTML (was Re: Jargons of Info Tech industry) References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8366F9vvsU1@individual.net> Message-ID: Ulrich Hobelmann wrote: > John Bokma wrote: >> Ulrich Hobelmann wrote: >> >>> On the information side (in contrast to the discussion side) RSS is >>> replacing Usenet, >> >> LOL, how? I can't post to RSS feeds. Or do you mean for lurkers? > > I said "information side", meaning stuff like RSS is used for. Nah, I wouldn't call it a replacement. Maybe of mailinglists with latest news. >>> There is no real reason why NNTP couldn't be used like RSS (i.e. >>> contain a small description and a web link as message text), >> >> It has been used like that for ages (or as long as I can remember). > > Yes, but for some reason people jumped onto the RSS hype. You think so? Like on push technology, VRML, and what more? Most of my friends have no clue what RSS is. Maybe in IE7, when it's more hidden, people will use it. But I wouldn't call it a hype, unless a hype is something many people shout you have to have it (hmm...) > I wonder > why. > Heck, even I am subscribed to a bunch of RSSes, because those > institutions don't offer NNTP ;) But they probably have (or had) a mailing list. >>> or why a >>> newsgroup shouldn't we written in HTML and contain a (default, or >>> user-provided) CSS sheet. >> >> It's called www. It's already here (or there) > > Well, but forums only emulate the posting/reply structure. It would > make more sense to use NNTP for that, Why? It now works in the browser, you don't need to install another client. Moreover, many people, especially where I live, don't have a computer at home. Same for many students I know, they use the computer at school. And many people I know with a job use the computer at work. And not everybody wants to install a client for each and every protocol. Hence why things like webmessenger are used. > and use $WHATEVER, e.g. HTML, > for markup inside the posts. WWW is something else; a bunch of pages > with hyperlinks to each other. Maybe we shouldn't call web forums and > other dynamic websites www, as they don't really follow that purpose. Nonsense. > They are just abuses of HTTP/HTML/JS for thin clienting. ;) Like UUencode is abuse of ASCII? LOL! >> But why do you want that? (Oh, and you can't read news with Outlook). >> Why do you want more people on Usenet? > > No, I'm not talking about usenet. I'm glad if the SNR keeps as high > (haha) as it is, and messages in plain text. > > I'm talking about using the technology for communication, instead of > reinventing the wheel with crappy web forums. What is exactly crappy about those forums? > Oh, and I've heard there are people reading our in-house newsgroup > with Outlook. Amazing, since I always understood that it can't do NNTP. >>> while today >>> everything is just Browser+HTTP. >> >> And what's wrong with that? > > It's slow and pointless. The huge success of web based message boards seems so say something entirely different. When I post with X-news, there is a delay, when I post with my browser, there is a delay. I have no idea which delay is more significant. Maybe they are too close. > All interaction that's more than clicking a > link has to be emulated with Javascript (heard of Ajax already? Yes, I even mentioned it in this thread. And what's the problem? > ) to > make it more smooth. HTML was never a programming language, and will never be. Hence for fancy stuff you have to use a programming language. Nothing wrong with that. > NNTP has advantages like giving you only the headlines first, so you > can choose what to check out. Funny, I see the same when I use phpBB. Headlines. > Then you can get the article if you > like (in the communication case) Yup, same with phpBB, I click a link, and bzzzt.. there is the article, and the replies to it. > or the news description (in the > RSSoid case) Yup, there is a mod for phpBB that makes it possible to give each post besides a title a short description. > and maybe click on a link inside. Saves bandwidth and is > quite faster than waiting for some overloaded PHP server to send you a > bunch of HTML tables. Hence, overloaded servers shouldn't use PHP, or use special caching tricks. I can't remember having seen slow boards, even not the ones with hundreds of simultaneous users (for example phpbb.com). > Responding doesn't involve *any* HTTP requests, No, but it requires sending your post to an NNTP server. Which takes time (when I press send, I don't see this window close immediately). > just a keypress and you're typing. Just a mouse click. > Web forums are stone-age, as are most web-pages. Maybe you should visit one and check out for yourself. Age has little to do with it, Usenet is way older, works. IRC is way older, works. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From p at ulmcnett.com Mon Aug 1 14:10:15 2005 From: p at ulmcnett.com (Paul McNett) Date: Mon, 01 Aug 2005 11:10:15 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <1122914218.663227.34150@g14g2000cwa.googlegroups.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <7x3bpuxtwa.fsf@ruckus.brouhaha.com> <1122914218.663227.34150@g14g2000cwa.googlegroups.com> Message-ID: <42EE6587.30401@ulmcnett.com> Devan L wrote: > If you're creating a new instance of your dApp(I assume its a class) > with no arguments, then effectively your just creating a default > program which is already defined in the dabo module. If you could write > it in a few, short lines of code by defining a new class, then you > might have something there. import dabo app = dabo.dApp() app.UI = "wx" class MyTextBox(dabo.ui.dTextBox): def initProperties(self): self.Width = 200 self.Value = "Planet Earth is blue" class MyForm(dabo.ui.dForm): def afterInit(self): self.addObject(MyTextBox) def initProperties(self): self.Caption = "Ground Control To Major Tom" app.MainFormClass = MyForm app.start() -- Paul McNett http://paulmcnett.com From rkern at ucsd.edu Thu Aug 18 19:46:42 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 18 Aug 2005 16:46:42 -0700 Subject: Module Name Conflicts In-Reply-To: References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: Dan Sommers wrote: > Assuming you can fiddle with sys.path at the right times, you can call > an imported module anything you want: > > fix_sys_path_to_find_java_cmd_first() > import cmd as java_cmd > fix_sys_path_to_find_python_cmd_first() > import cmd as python_cmd > > Obviously, then, 'cmd' does not reference either module; you'd have to > use java_cmd and python_cmd as appropriate. That doesn't work. The first module is recorded as 'cmd' in sys.modules and gets reused on the second import. [~]$ mkdir foo1 [~]$ mkdir foo2 [~]$ touch foo1/blah.py [~]$ touch foo2/blah.py [~]$ python Python 2.4.1 (#2, Mar 31 2005, 00:05:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0,'foo1') >>> import blah as blah1 >>> sys.path.insert(0,'foo2') >>> import blah as blah2 >>> sys.modules['blah'] >>> blah2.__file__ 'foo1/blah.py' >>> -- 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 cjw at sympatico.ca Thu Aug 11 12:06:57 2005 From: cjw at sympatico.ca (Colin J. Williams) Date: Thu, 11 Aug 2005 12:06:57 -0400 Subject: epyDoc Questions In-Reply-To: References: Message-ID: Neil Benn wrote: > Hello, > > I can;t find a epyDoc specific mailing list, so I'll try here - > if you know of a epyDoc mailing list then please let me know (google is > not my friend, I can only find an announce, devel and commit list from > 'epydoc mailing list'). > epyDoc gives nice documentation with no mark-up. I've not seen any indication of maintenance for a year or so. > I'm working on marking up a class in epyDoc and have a few things > that I strongly suspect I can do but can't find instructions for in the > docs - I was hoping that someone has cracked this already: > > 1. I want to document the attributes (instance and also class) of a > class and or module, I know the tags are there - where does they > go (before/after theclass decleration, top of the module, if > someone puts in the class doc but misses out the module stuff, how > will epydoc know that this is meant to be class and not module > (although someone doing this will probably get shouted at in a > code review!)? Why not post some code so that we can more clearly understand what you aim to document? Colin W. > 2. In the argument to the tag for raises, how can I put a link > through to the exception? > 3. How would I go about marking up the property docs so that it knows > what the setter and getter methods are - it links through to the > methods but the docs arn't in there, they are in the fifth > argument to the property method (I can manually do this using > sections but is there a tag I can use?) > > Cheers for your help, > > Neil > From spammers-go-here at spam.invalid Sun Aug 14 00:36:06 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sun, 14 Aug 2005 00:36:06 -0400 Subject: Standalone applications ? References: <42feba84$0$18644$14726298@news.sunsite.dk> Message-ID: <42feca21$0$18650$14726298@news.sunsite.dk> Paolo Alexis Falcone wrote: > On Sat, 13 Aug 2005 23:29:27 -0400, Madhusudan Singh wrote: > >> Hi >> >> I just finished developing an application using Qt Designer in Python >> that uses pyqwt, gpib, etc. How does one create standalone executables >> for applications such as these ? > > Generally, you can't, as Python is an interpreted programming language. > However, there are some projects like py2exe in Windows which approximates > what you want to do - port the Python code into a stand-alone application. I should have added that my platform is Linux. From mhellwig at xs4all.nl Sun Aug 7 10:52:03 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Sun, 07 Aug 2005 16:52:03 +0200 Subject: Python -- (just) a successful experiment? In-Reply-To: <1123413907.572051.281140@g44g2000cwa.googlegroups.com> References: <1123413907.572051.281140@g44g2000cwa.googlegroups.com> Message-ID: <42f62020$0$11068$e4fe514c@news.xs4all.nl> Kay Schluehr wrote: > Eric Pederson wrote: > >>Raise your hand if you think the best technology wins! > > > Who is interested in such a matter? Is this a forum dedicated to some > programming language or a popularity contest? > > If Python dies in a few years / looses attention but the Python Zen > survives in another language I have nothing to complain. > Ave! Although I think that the day that python is considerd dead is the same day that unix is truly dead. Ooh yes and I have heard for over two decades that unix-like systems are obsolete, so why is the install base only growing and has never been bigger? -- mph From grflanagan at yahoo.co.uk Mon Aug 15 11:27:07 2005 From: grflanagan at yahoo.co.uk (Gerard Flanagan) Date: 15 Aug 2005 08:27:07 -0700 Subject: Permutation Generator In-Reply-To: References: Message-ID: <1124119627.481161.324480@f14g2000cwb.googlegroups.com> Talin wrote: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head = lst[:1] > for x in permute( lst[1:] ): > yield head + x > yield x + head > return > > -- Talin As it happens, I've just started learning Python and my 'Hello World' was a class which generates all permutations of the set {1,2,...n}. It's a translation of some Pascal code from the book "Programming for Mathematicians" by Raymond Seroul (2000 Springer-Verlag), and produces a (non-lexicographic) total ordering of the set using Johnson's Algorithm. To explain the algorithm briefly. Each element is 'adorned' with a flag ( either 1 or -1 ) which determines the direction that an element is 'looking' - so, given the sequence [ [-1,3], [1,2], [1,1], [-1,4] ] 1 sees 4 2 sees 1 3 sees nothing 4 sees 1 (with the convention that -1 means 'looking left') An element is said to be 'mobile' if it is looking at a smaller number. eg. in the sequence above, both 2 and 4 are mobile. Then the algorithm is: - find the highest mobile - swap this mobile with the element it sees, but don't swap their direction flags - reverse the direction flags of any element larger than the mobile In coding the algorithm, sentinels with value 1 bigger than n are added at either end of the sequence, this helps when checking which elements are mobile. Also, 1 and -1 aren't arbitrary flags, these values are used because you can find which element another element 'sees' by using 'index + flag'. Here's the code: def factorial( n ): if n <= 1: return 1 else: return n * factorial( n-1 ) class Permutation: def __init__( self, items ): seq = list( items[:] ) n = len( seq ) self.sequence = seq self.length = n self.count = factorial( n ) def __getitem__( self, key ): result = [] sequence = self.sequence[:] N = self.count index = key for i in range( self.length, 0, -1): N = N / i choice, index = index // N, index % N result += [ sequence.pop(choice) ] return result class NPermutation( Permutation ): def __init__( self, n ): Permutation.__init__( self, range( 1, n+1 ) ) self.reset() def reset( self ): list = [ [-1,i] for i in range(self.length+2) ] list[0][1] = self.length+1 #eg. n=3 -> list = [[-1,4], [-1,1], [-1,2], [-1,3], [-1,4]] self.__current = list self.__index = 0 def __iter__( self ): return self def next( self ): if self.__index == self.count: self.reset() raise StopIteration elif self.__index > 0: j = self.__get_index_of_highest_mobile() #remember the mobile itself before you move it mobile = self.__current[j][1] #swap the mobile with the element it 'sees' self.__move_mobile_at_index( j ) #switch the direction of elements greater than mobile if mobile < self.length: self.__reorient_list_elements( mobile ) self.__index += 1 return [ a[1] for a in self.__current[ 1:self.length+1 ] ] def __get_index_of_highest_mobile( self ): high_value = 0 high_index = 0 for i in range( 1, self.length+1 ): direction = self.__current[i][0] value = self.__current[i][1] if value > high_value and value > self.__current[i+direction][1]: high_value = value high_index = i return high_index def __move_mobile_at_index( self, index ): direction = self.__current[index][0] value = self.__current[index][1] self.__current[index] = self.__current[index+direction] self.__current[index+direction] = [direction,value] def __reorient_list_elements( self, mobile ): for i in range( 1, self.length+1 ): if self.__current[i][1] > mobile: self.__current[i][0] = -self.__current[i][0] x = NPermutation( 6 ) print 'loop with __getitem__' print '---------------' for i in range( x.count ): print x[i] print 'loop with __iter__' print '---------------' for perm in x: print perm Gerard Flanagan 15/8/05 From prabapython at yahoo.co.in Wed Aug 31 00:20:39 2005 From: prabapython at yahoo.co.in (praba kar) Date: Wed, 31 Aug 2005 05:20:39 +0100 (BST) Subject: reg email packages work In-Reply-To: Message-ID: <20050831042039.25690.qmail@web8409.mail.in.yahoo.com> --- Sybren Stuvel wrote: > Steve Holden enlightened us with: > > It's obvious you aren't using that EXACT code, > because it doesn't > > formulate a three-paragraph message. So the bit we > really need to > > see is how you capture and formulate the argument > to set_payload(). > > I'd rather see what I asked for, which is the output > of > msg.as_string(). That contains all that's sent to > the client. msg.as_string() have all the client data(which include headers and body of the message > > Sybren > -- > The problem with the world is stupidity. Not saying > there should be a > capital punishment for stupidity, but why don't we > just take the > safety labels off of everything and let the problem > solve itself? > Frank > Zappa > -- > http://mail.python.org/mailman/listinfo/python-list > __________________________________________________________ How much free photo storage do you get? Store your friends 'n family snaps for FREE with Yahoo! Photos http://in.photos.yahoo.com From mikael at isy.liu.se Tue Aug 30 10:58:54 2005 From: mikael at isy.liu.se (Mikael Olofsson) Date: Tue, 30 Aug 2005 16:58:54 +0200 Subject: how to join two Dictionary together? In-Reply-To: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> Message-ID: DENG wrote: > dict1={...something...} > dict2={...somethind else ..} > dict1 + dict2 > > that's does works ..:(, it's not like List... > anyone can tell me how to get it? I would do the following in most cases. >>> dict1={'a':'A'} >>> dict2={'b':'B'} >>> dict3=dict1.copy() >>> dict3 {'a': 'A'} >>> dict3.update(dict2) >>> dict3 {'a': 'A', 'b': 'B'} HTH /Mikael Olofsson Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE]) Link?pings universitet ----------------------------------------------------------------------- E-Mail: mikael at isy.liu.se WWW: http://www.dtr.isy.liu.se/en/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com Vi s?ker tenorer och basar! From yxxxxlxxxxx at gmail.com Thu Aug 11 14:56:49 2005 From: yxxxxlxxxxx at gmail.com (yaffa) Date: 11 Aug 2005 11:56:49 -0700 Subject: need help with python syntax Message-ID: <1123786609.621111.324390@g49g2000cwa.googlegroups.com> dear python gurus, quick question on syntax. i have a line of code like this for incident in bs('tr', {'bgcolor' : '#eeeeee'}): what i want it to do is look for 'bgcolor' : '#eeeeee' or 'bgcolor' : 'white' and then do a whole bunch of stuff. i've tried this: for incident in bs('tr', {'bgcolor' : '#eeeeee'} or {'bgcolor' : 'white'} ): but it only seems to pick up the stuff from the {'bgcolor' : '#eeeeee'} any ideas folks? thanks yaffa From km at mrna.tn.nic.in Tue Aug 23 06:10:56 2005 From: km at mrna.tn.nic.in (km) Date: Tue, 23 Aug 2005 15:40:56 +0530 Subject: loop in python In-Reply-To: References: Message-ID: <20050823101056.GA25131@mrna.tn.nic.in> Hi all, > thing. If *all* your loops are going to do is print stuff, then you're > doing the right thing with the version that "emits values". ya most of the loops print values. > know this). Since you haven't got any working code, it's not possible > that you *need* whatever negligible speed difference there might be > between Python and Perl. > > Python, don't let your first attempts at benchmarking dissuade you. > Really, trust us. ya i do. > Python's strengths lie in four things: the readability of the code, the > huge range of library modules available, the elegance of its object > oriented constructs, and the helpfulness of its community. Raw speed is > not one of its strengths, but there are tens of thousands of people > using it quite effectively and without daily concern for its speed (same > as Perl, by the way since, again, they are _not_ significantly different > in speed no matter what an empty loop test shows). I agree that python emphasizes on readability which i didnt see in many of the languages, but when the application concern is speed, does it mean that python is not yet ready? even most of the googling abt python vs perl convince me that perl is faster than python in most of the aspects. Also the first thing any newbie to python asks me is abt "raw speed in comparison with similar languages like perl" when i advocate python to perl. regards, KM From lshuai at kaneva.com Tue Aug 2 09:51:31 2005 From: lshuai at kaneva.com (Liu Shuai) Date: Tue, 2 Aug 2005 09:51:31 -0400 Subject: Terminate a thread that doesn't check for events Message-ID: <9CA58FB7E095F146AD3E7FE1E5855929042FA8@brain.klausatlanta.local> Can someone please comment on this? ________________________________ From: python-list-bounces+sliu=kaneva.com at python.org [mailto:python-list-bounces+sliu=kaneva.com at python.org] On Behalf Of Liu Shuai Sent: Monday, August 01, 2005 4:29 PM To: python-list at python.org Subject: Terminate a thread that doesn't check for events Hi all, I am aware that similar and probably same questions have been posted many times, but I was unable to find a solution after reading a dozen threads in the archive. So here it goes again. I have a thread that does some heavy task (hash calculation, for instance). I need a mechanism that works *across platforms* to stop that calculation if user decides to exit. How can I do that? I can not do the standard "periodical checking" way since there is only one function/step call in my thread. Here is a snippet of my thread classes to help illustrate the problem: class Dispatcher(): def __init__(self): self.__worker = Worker() def start(self): self.__worker.start() def stop(): #how do i stop the worker? class Worker(threading.Thread): def __init__(self): def run(self): oneTimeConsumingCall() Thank you in advance for any suggestions/pointers. LS -------------- next part -------------- An HTML attachment was scrubbed... URL: From bill.mill at gmail.com Thu Aug 25 14:12:19 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 25 Aug 2005 14:12:19 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: <20050825180452.GC5991@performancedrivers.com> References: <797fe3d4050825103556f49018@mail.gmail.com> <20050825180452.GC5991@performancedrivers.com> Message-ID: <797fe3d405082511127aee9ad6@mail.gmail.com> On 8/25/05, Jack Diederich wrote: > On Thu, Aug 25, 2005 at 01:35:04PM -0400, Bill Mill wrote: > > On 8/25/05, Erik Max Francis wrote: > > > Mark Dickinson wrote: > > > > > > > Questions: > > > > > > > > (1) Can anyone else reproduce this behaviour, or is it just some quirk > > > > of my setup? > > > > (2) Any possible explanations? Is there some optimization that kicks > > > > in at a certain number of lines, or at a certain length of > > > > bytecode? > > > > (3) If (2), is there some way to force the optimization, so that I can > > > > get the speed increase without having to add the extra lines? > > > > > > > I did find, though, that if I remove all print statements from the > > program, the dummy and non-dummy variable versions take indentical > > time. Can others reproduce this? > > > > I'm Investigating further... > > I'm getting similarly freakish results. I tried a little ghetto debugging > by putting a printf in dictobject.c's resize method and recompiling python. > Sadly I can't get the problem to reproduce itself with the new binary > (with or without the printf). The Ubuntu default 2.4.1 is sometimes fast, > my hand compiled one (./configure && make) is always slow. > > There are some very arcane low level things going on here. > agreed. Also, either I was temporarily insane, or the version with the explicit template no longer runs faster for me, so I hope nobody spends a lot of time on that. Peace Bill Mill bill.mill at gmail.com From mekstran at scl.ameslab.gov Fri Aug 19 12:21:54 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Fri, 19 Aug 2005 11:21:54 -0500 Subject: Idempotent XML processing Message-ID: <2f66fb64f6cf531cca8b75576548283f@scl.ameslab.gov> Hello all, In my current project, I am working with XML data in a protocol that has checksum/signature verification of a portion of the document. There is an envelope with a header element, containing signature data; following the header is a body. The signatures are computed as cryptographic checksums of the entire Body element, including start and end tags, exactly as it appears in the data transmission. Therefore, I need to extract the entire text of an element of an XML document. I have a function that scans an XML string and does this, but it seems like a rather clumsy way to accomplish this task. I've been playing with xml.dom.minidom and its toxml() method, but to no avail - the server sends me XML with empty elements as full open/close tags, but toxml() serializes them to the XML empty element (), so the checksum winds up not matching. Is there some parsing mechanism (using PyXML or any other freely usable 3rd party library is an option) that will allow me to accomplish this? Or am I best off sticking with my little string scanning function? TIA, Michael From mwh at python.net Mon Aug 8 17:48:10 2005 From: mwh at python.net (Michael Hudson) Date: Mon, 08 Aug 2005 21:48:10 GMT Subject: Syntax error after upgrading to Python 2.4 References: <1123323206.151000.309140@g49g2000cwa.googlegroups.com> Message-ID: jepler at unpythonic.net writes: > On Sat, Aug 06, 2005 at 05:15:22PM -0400, Terry Reedy wrote: >> In any case letting developers add new features is part of the price of >> getting unpaid bug fixes for free software. But note that PSF does not >> make you to upgrade. Here is the current list of possible downloads. >> > [a mere 8 versions] > > Oh, don't give such a short list! Here's what I found on the python.org ftp site: [...] > And then there's CVS... Which doesn't build for the really early versions. I think python1.0.1.tar.gz is as old as it's easy to get. Cheers, mwh -- Ignoring the rules in the FAQ: 1" slice in spleen and prevention of immediate medical care. -- Mark C. Langston, asr From spammers-go-here at spam.invalid Mon Aug 8 21:32:09 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Mon, 08 Aug 2005 21:32:09 -0400 Subject: Adding custom widgets to Qt Designer Message-ID: <42f80793$0$18642$14726298@news.sunsite.dk> Hi I am trying to add a QwtPlot widget to Qt Designer. I have both PyQwt and libqwt installed. I first tried to add a Custom Widget from /usr/include/qwt/qwt_plot.h as QwtPlot. But I do not know what slot to add. If I add the widget so created, and double click on it, I am asked if I want to create a new ui.h. It does not seem that the widget was added correctly. I then found a link : http://www.pycs.net/lateral/stories/27.html Now, I do have a file qplt.py, but the above link presumes that the ui.h file is created before py file is generated using the pyuic translator. So, how does one add this new widget ? Thanks. From sp1d3rx at gmail.com Fri Aug 19 16:18:01 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 19 Aug 2005 13:18:01 -0700 Subject: while c = f.read(1) In-Reply-To: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <1124482681.402831.294550@z14g2000cwz.googlegroups.com> Alright, everyone seems to have gone off on a tangent here, so I'll try to stick to your code... """ This is what I would ideally like: f = open("blah.txt", "r") while c = f.read(1): # ... work on c But I get a syntax error. while c = f.read(1): ^ SyntaxError: invalid syntax """ That's because you are using an assignment operator instead of a comparison operator. It should have been written like this: while c == f.read(1): that would be written correctly, though I don't think that is your intention. Try this novel implementation, since nobody has suggested it yet. ----------------- import mmap f = open("blah.txt", 'r+') #opens file for read/write c = mmap.mmap(f.fileno(),0) #maps the file to be used as memory map... while c.tell() < c.size(): print c.read_byte() --------------- That accomplishes the same thing. From yux at sdf-eu.org Tue Aug 23 09:37:03 2005 From: yux at sdf-eu.org (Jonas Geiregat) Date: Tue, 23 Aug 2005 13:37:03 +0000 Subject: Python and the web In-Reply-To: References: Message-ID: <430b0a12$0$10960$ba620e4c@news.skynet.be> Terry Hancock wrote: > > Yes. If you're into killer apps, try out Zope. But it does have a learning curve. > There are probably a dozen or so alternatives that are all "smaller and quicker > to learn". > Very true zope is a killer app, but different from all the other well know server side languages. I myself am still in the learning stage but if you're into web development zope is the best around. But pay attention zope hosting can be expensive and hard to find. From mwm at mired.org Mon Aug 29 21:53:48 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 29 Aug 2005 21:53:48 -0400 Subject: Writing portable applications References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> <3ndociF11gd3U1@individual.net> <86acj1y8mr.fsf@bhuda.mired.org> <3nfu55F19ui5U1@individual.net> Message-ID: <86r7cc9olv.fsf@bhuda.mired.org> Ulrich Hobelmann writes: > Mike Meyer wrote: >> I'm still waiting for an answer to that one - where's the Java toolkit >> that handles full-featured GUIs as well as character cell >> interfaces. Without that, you aren't doing the job that the web >> technologies do. > Where is the text-mode browser that would even run part of the web > apps I use, like home-banking, all web forums, server configuration > interfaces, etc.? I think we should leave both these questions > open. (In fact, as to UIs using Java, blech! Haven't seen a really > good one...) If your web apps are well-written, any of them should work. As previously stated, Sturgeon's law applies to the web, so chances are good they aren't well-written. >>>>> I just wonder who wrote fully standards compliant web browsers for >>>>> those 90 platforms. >>>> Nobody. I doubt there's a fully standards compliant web browser >>> Nobody, huh? Then how could you run just ANY web application on those >>> platforms? >> The same way you write POSIX applications in the face of buggy >> implementations - by working around the bugs in the working part of >> the implementation, and using conditional code where that makes a >> serious difference. > But as soon as some user of platform 54 tries your website, she'll > encounter some weird behavior without even knowing why. And maybe so > will you, especially if you don't have that platform there for > testing. I don't understand how this web thing changes anything... The only difference is that the user of Platform 54 has a chance to use your app. Sure, it may not work because that platforms bugs are radically different from the bugs in the platforms you tested on. Raising the possibility of your app working from "no way in hell" to "maybe" is significant. > With POSIX at least you have a real bug-report for the guy responsible > for it. If a platform keeps being buggy, with no fixes coming, screw > them. Every user will see that sooner or later, and these platforms > die. Even Windows is quite stable/reliable after 10+ years NT! You do? All your porters reliably give you bug reports? Can I have some? >>>> available for *any* platform, much less any non-trivial collection of >>>> them. You write portable web applications to the standards, and design >>>> them to degrade gracefully. Then you go back and work around any new >>> Oh right, they degrade gracefully. So without Javascript or cookies >>> (the former is often not implemented) you get a HTML page with an >>> error notice -- if you're lucky. >> You left off the important part of what I had to say - that the >> application be written by a moderately competent web author. > But if you can cater for all kinds of sub-platforms, then why not just > provide a CLI as well as those GUI interfaces, when we're duplicating > work to begin with? ;) Because I'd rather not duplicate the work. >>> A server AND client for a simple protocol designed for its task >>> (i.e. not FTP for instance) can be implemented in much less work than >>> even designing even part of a web application backend that does that >>> kind of stuff. >> Well, if it that easy (and web applications are dead simple), it >> should be done fairly frequently. Care to provide an example? > > We have all the web standards, with various extensions over the > years. Some FTP clients even don't crash if they see that some server > doesn't yet support the extension from RFC XY1234$!@. Then there's > tons of inter-application traffic in XML already, growing fast. Then > there are s-expressions (Lisp XML if you want). Then probably > thousands of ad-hoc line-based text protocols, but I don't know how > well they can be extended. There's CORBA. Most web standards are > simple, at least if you would subtract the weird stuff (and IMHO there > should be new versions of everything with the crap removed). XML is > somewhat simple, just hook libxml. These don't answer the question. Maybe because I didn't explain it fully. Do you have an example of an application that implements a simple protocol along with a client and server where HTTP+HTML were considered as an alternative, and rejected as "more difficult" than the path actually chosen? > There's NNTP. There's RSS. There's Atom. The latter two emerged > quite painlessly, even though you could maybe use some website for > what they provide. But this way you have lots of clients for lots of > platforms already. NNTP predates HTTP. Atom (and I assume RSS) uses HTTP as a transport, so there's no new protocol invovled - just a new file format. >>>> You think you're done. A lot of developers think you can stop with >>>> the >>>> first one or two. You're all right for some applications. For others, >>>> you're not. Personally, I like applications that run on all the >>>> platforms I use - and your set doesn't cover all three of those >>>> systems. >>> Ok, I'd be interested to hear what those are. VMS, RiscOS, Mac OS 9...? >> FreeBSD, OS X and a Palm Vx. > Didn't I say, a GUI for the Mac, for X11, and Windows? That only > leaves out the Palm. I heard they aren't too hard to program for, > either. But I haven't heard of a really decent browser for pre-OS5 > PalmOS (not sure about OS5). There are number of different browsers available for the pre OS5 Palms. They're more than adequate for the tools I want to use. In particular, Palm.net was built on HTML. On the palm side, you "compiled" a set of HTML files to create an application. Requests for remote objects went through a proxy that compressed them to save bandwidth. Very strange stuff. >>> If a system's scheduler, or select implementation sucks, though, I'd >>> complain to the vendor or simply abandon the platform for >>> another. Competition is good :) >> Complaining to the vendor doesn't always get the bug fixed. And >> refusing to support a platform isn't always an option. Sometimes, you >> have to byte the bullet and work around the bug on that platform. > Sure, but you can tell your customers that unfortunately their system > vendor refuses to fix a bug and ask THEM to ask that vendor. Boy, > will they consider another platform in the future, where bugs do get > fixed ;) Yup. You and that platform vendor are no win the set of vendors that don't fix bugs. Personally, I'd rather provide a workaround and keep the customer. >>>> same thing applies to threads, except such code typically includes a >>>> third option of not using threads at all. And so on. >>> Well, who doesn't do threads after several years of POSIX IMHO can't >>> be taken seriously. Ok, the BSDs didn't until recently, but those are >>> volunteer projects. >> Not all platforms are POSIX. If you're ok limiting your application >> to >> a small subset of the total number of platforms available, then >> there's no advantage to using web technologies. Some of us aren't >> satisifed with that, though. > Sure. You have to look where your users are. Chances are that with > obscure systems they can't use most web-apps either. Right. Chances are they can only use well-written ones. If you write those, your stuff will stand out for them. >> Well, marking up text is a pretty poor way to describe a UI - but >> anything that is going to replace web technologies has to have a >> media-independent way to describe the UI. One of the things that made >> the web take off early was that anyone with a text editor could create >> web pages. I think that's an important property to keep - you want the >> tools that people use to create applications be as portable/flexible >> as the applications. Since most GUI's are written in some programming >> language or another, and most programming langauges are still flat >> text, a GUI description as flat text exists for most GUIs, so this >> requirement isn't a handicap. > That's true, though I think the future of development lies in > overcoming that program-code-as-text thing (NOT visual programming, > just tool-based, structured). Smalltalk did it decades ago. Last time I looked at smalltalk, it still presented program code as text. So I think you need to clarify what you mean. >> You don't have to guess - finding examples of XUL isn't hard at all. I >> think XML gets used in a lot of places where it isn't appropriate. One >> of the few places where it is appropriate is where you want a file >> format that lots of independent implementations are going to be >> reading. This could well be one of those times. > Maybe, but for applications that aren't predominantly concerned about > text, I'd really rather use a structured data type (like > s-expressions), not text markup like XML. For hypertext, XHTML is > fine, though, if a bit verbose. I'd rather use something which has a formal mechanism for defining what legal documents are. XML provides DTDs. If you really want S-expressions, we could use an SGML DTD that let you write them, and get the best of both worlds. > [follow-up set to comp.unix.programmer] comp.lang.python (where I've been reading this) added to followups. > (I just noticed I replaced my sig with something web-related > yesterday. This is pure coincidence :D) > -- > My ideal for the future is to develop a filesystem remote interface > (a la Plan 9) and then have it implemented across the Internet as > the standard rather than HTML. That would be ultimate cool. Yeah. I once worked on implementing the Rexx command interface as an internet protocol. It doesn't have the coolness factor of Plan 9's filesystem command interfaces, but it's not far from it. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From http Thu Aug 18 15:07:24 2005 From: http (Paul Rubin) Date: 18 Aug 2005 12:07:24 -0700 Subject: determine variable type References: Message-ID: <7xzmrfcbdf.fsf@ruckus.brouhaha.com> MCollins at seminolecountyfl.gov writes: > i tried using type(var) but that only seemed to produce a response in the > command line. > > is there a built in python function to determine if a variable is an > integer? type(var) returns the type. For example: if type(x) == type(3): print 'x is an integer' From billiejoex at fastwebnet.it Tue Aug 30 11:47:35 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Tue, 30 Aug 2005 17:47:35 +0200 Subject: aproximate a number References: <1125369077.295227.8540@g14g2000cwa.googlegroups.com> <11h7i0s2lr5a8e8@corp.supernews.com> <1125374065.138657.66410@o13g2000cwo.googlegroups.com> <11h7p83qbjeilad@corp.supernews.com> Message-ID: I wanted the round up the number (5.0 = 5.0, not 6.0.). The ceil funciotn is the right one for me. Thanks to all. >> Grant Edwards wrote: >>> On 2005-08-30, Devan L wrote: >>> > >>> > RoundToInt(2.0) will give you 3. >>> >>> That's what the OP said he wanted. The next bigger integer >>> after 2.0 is 3. >> >> It's not really clear whether he wanted it to round up or to go to the >> next biggest integer because he says he has bad english. I can't think >> of a particular use of returning the next bigger integer. > > You're probably right. I suspect what he really wants is > > i = int(math.ceil(x)) > > -- > Grant Edwards grante Yow! Is it FUN to be > at a MIDGET? > visi.com From fredrik at pythonware.com Wed Aug 31 17:54:56 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 23:54:56 +0200 Subject: time.strptime() for different languages References: <1125519061.261802.285840@o13g2000cwo.googlegroups.com> <1125522144.209140.266590@f14g2000cwb.googlegroups.com> Message-ID: Adam Monsen wrote: > No, this doesn't seem to work, and I can't find anything in the > documentation indicating that it should. > > >>> import os > >>> os.getenv('LANG') > 'nl_NL' > >>> import time > >>> time.strptime("10 augustus 2005 om 17:26", "%d %B %Y om %H:%M") > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.4/_strptime.py", line 292, in strptime > raise ValueError("time data did not match format: data=%s fmt=%s" > % > ValueError: time data did not match format: data=10 augustus 2005 om > 17:26 fmt=%d %B %Y om %H:%M >>> import locale, time >>> time.strftime("%B") 'August' >>> locale.getlocale() (None, None) >>> locale.setlocale(locale.LC_ALL, "") 'nl_NL' >>> locale.getlocale() ('nl_NL', 'ISO8859-1') >>> time.strftime("%B") 'augustus' >>> time.strptime("10 augustus 2005 om 17:26", "%d %B %Y om %H:%M") (2005, 8, 10, 17, 26, 0, 2, 222, -1) (see http://docs.python.org/lib/module-locale.html for more on this) From notanlinesgirly1 at yahoo.com Wed Aug 10 23:16:27 2005 From: notanlinesgirly1 at yahoo.com (Casee) Date: Thu, 11 Aug 2005 03:16:27 -0000 Subject: looking to GIVE my first oral favor Message-ID: im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me From nowayjose at noway.com Thu Aug 11 15:44:11 2005 From: nowayjose at noway.com (el chupacabra) Date: Thu, 11 Aug 2005 19:44:11 GMT Subject: breaking a loop Message-ID: Hi, I'm just learning Python....thanks in advance... Do you get out of this loop? Problem: When I type 'exit' (no quotes) the program doesn't quit the loop...it actually attemps to find entries that containt the 'exit' string. Desired behavior: when I type 'exit' the program should quit. def search(): searchWhat = "" while searchWhat != 'exit': searchWhat = "%%%s%%" % raw_input ('Search for : ') cursor.execute("select * from TABLE where FIELD like %s", (searchWhat)) result = cursor.fetchall() print '+------------------------------------------------------------------+' print '| # | Name | LastName |' print '+------------------------------------------------------------------+' for record in result: print ' ', record[0], ' : ', record[1], ' ==> ', record[2] print '+------------------------------------------------------------------+' #end for statement, end of search --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- From matt.hammond at rd.bbc.co.uk Mon Aug 22 07:31:31 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Mon, 22 Aug 2005 12:31:31 +0100 Subject: passing arguments from scale widget to function References: <430828c4$1@duster.adelaide.on.net> <4309b3f2$1@duster.adelaide.on.net> Message-ID: On Mon, 22 Aug 2005 12:16:01 +0100, m7b52000 wrote: >> command = lambda : Calc(a.get()) > I get the following message when I use lambda as above: > > TypeError: () takes no arguments (1 given) Oops, forgot! The Scale widget outputs a single argument - the value of the slider. You therefore could write: command = lambda value : Calc(value) or even simpler: command = Calc In the latter case, you're supplying your "calc" function as the function to be called. Calc takes a single argument - the value of the slider, so it fulfills the task. Note that we're passing "Calc" (the function itself), not "Calc(...)" (the result of calling the function) regards Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From spam.csubich+block at block.subich.spam.com Tue Aug 9 13:40:10 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 13:40:10 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: <1123603242.709888.24950@g44g2000cwa.googlegroups.com> References: <1123603242.709888.24950@g44g2000cwa.googlegroups.com> Message-ID: infidel wrote: >>in Python equality rebinds the name > > > Assignment (=) rebinds the name. Equality (==) is something else > entirely. Good catch. I was thinking of it as the "equals" operator. From cito at online.de Wed Aug 3 04:19:05 2005 From: cito at online.de (Christoph Zwerschke) Date: Wed, 03 Aug 2005 10:19:05 +0200 Subject: Art of Unit Testing In-Reply-To: <42efe330$0$3713$626a14ce@news.free.fr> References: <87mzo0s25q.fsf@lucien.dreaming> <42efe1ec$0$3713$626a14ce@news.free.fr> <42efe330$0$3713$626a14ce@news.free.fr> Message-ID: rafi wrote: > 'should' may be too strong, 'may' may be better. In the meantime I found: > http://python-mock.sourceforge.net/ Thanks for the link. Bj?rn also pointed to http://pmock.sourceforge.net Using mock objects sounds like a good idea. A problem with mock objects may be that they make writing tests for the occasional programmer yet another bit more difficult, and that you always have to ensure your mock objects really mock the real objects perfectly, so you have to write another test for that. The behavior and the API of the real objects may change every now and then. Let me summarize some good answers in this thread: - unittest is deliberately intended to be a JUnit implementation - unittest is for *unit* testing (only) ;-) - use mock objects to mimic the behaviour of external components like databases - other more pythonic testing frameworks are out there I think it would be good to have these remarks added to the unittest documentation in the Python library reference. Also, if one of the more pythonic unit testing modules will be mature enough and widely accepted, I think it would be good to make it Python's standard (lib) testing framework and rename the current unittest back to pyunit or punit. -- Christoph From martin at v.loewis.de Sat Aug 6 14:15:35 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 06 Aug 2005 20:15:35 +0200 Subject: minidom xml & non ascii / unicode & files In-Reply-To: <42F48399.6070904@chaosmedia.org> References: <42f38284$0$5314$636a15ce@news.free.fr> <42F3FDED.8050108@v.loewis.de> <42F48399.6070904@chaosmedia.org> Message-ID: <42f4fe48$0$13935$9b622d9e@news.freenet.de> > so what i understood of all this, is that once you're using unicode > objects you're safe ! > At least as long as you don't use statements or operators that will > implicitely try to convert the unicode object back to bytestring using > your default encoding (ascii) which will most certainly result in codec > Errors... Correct. > Also, minidom seems to use unicode object what was not really documented > in the python 2.3 doc i've read about it.. It might be somewhat hidden: http://docs.python.org/lib/dom-type-mapping.html "DOMString defined in the recommendation is mapped to a Python string or Unicode string. Applications should be able to handle Unicode whenever a string is returned from the DOM." http://docs.python.org/lib/minidom-and-dom.html "The type DOMString maps to Python strings. xml.dom.minidom supports either byte or Unicode strings, but will normally produce Unicode strings. Values of type DOMString may also be None where allowed to have the IDL null value by the DOM specification from the W3C." In principle, you should fill Unicode strings into DOM trees all the time, but it will work with byte strings as well as long as they are ASCII. > As a matter of fact using the following sequence will most certainly fail : > f = codecs.open('utf8codecs.xml', 'w', 'utf-8') > f.write(dom.toxml(encoding="utf-8")) > f.close() Correct. A codecs.StreamWriter expects Unicode objects, whereas toxml returns byte strings (atleast if you pass an encoding - because of a bug, it might return a Unicode string otherwise) > then again maybe this will work, i just thought of it.. > f = codecs.open('utf8codecs.xml', 'w', 'utf-8') > f.write(dom.toxml()) > f.close() Yeah, toxml() returned Unicode because of a bug - but for backwards compatibility, this cannot be changed. People should explicitly pass an encoding. > The next important thing is to make sure to use functions and objects > that support unicode all the way, like minidom seems to do.. Indeed, there are still many functions in the standard library which don't work with Unicode strings, but should. Some functions, of course, are only meaningful for byte strings (like networking API). Regards, Martin From sjmachin at lexicon.net Thu Aug 11 16:48:42 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 06:48:42 +1000 Subject: Regular expression to match a # In-Reply-To: References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> Message-ID: <42fbb9a9$1@news.eftel.com> Aahz wrote: > In article <42fb45d7$1 at news.eftel.com>, > John Machin wrote: > >>Search for r'^something' can never be better/faster than match for >>r'something', and with a dopey implementation of search [which Python's >>re is NOT] it could be much worse. So please don't tell newbies to >>search for r'^something'. > > > You're somehow getting mixed up in thinking that "^" is some kind of > "not" operator -- it's the start of line anchor in this context. I can't imagine where you got that idea from. If I change "[which Python's re is NOT]" to "[Python's re's search() is not dopey]", does that help you? The point was made in a context where the OP appeared to be reading a line at a time and parsing it, and re.compile(r'something').match() would do the job; re.compile(r'^something').search() will do the job too -- BECAUSE ^ means start of line anchor -- but somewhat redundantly, and very inefficiently in the failing case with dopey implementations of search() (which apply match() at offsets 0, 1, 2, .....). From lavigne.eric at gmail.com Sun Aug 14 22:54:12 2005 From: lavigne.eric at gmail.com (Eric Lavigne) Date: 14 Aug 2005 19:54:12 -0700 Subject: Python and games In-Reply-To: References: Message-ID: <1124074452.707649.159440@g47g2000cwa.googlegroups.com> >Like XML, scripting was extremely useful as both a mod tool and an >internal development tool. If you don't have any need to expose code >and algorithms in a simple and safe way to others, you can argue that >providing a scripting language is not worth the effort. However, if you >do have that need, as we did, scripting is a no brainer, and it makes >complete sense to use a powerful, documented, cross-platform standard >such as Python. The Torque Game Engine at www.garagegames.com is written in C++ and comes with a customized scripting language, torquescript, with a c-like syntax. Despite that, some game developers decided to add Python as another scripting layer on top of torquescript. The modified version of Torque is called PyTorque. I never tried PyTorque, but looking back on my time with torquescript this sounds like a very good idea. Torquescript was fine for convenient access to Torque features, but it never felt as flexible as a general-purpose language like Python. I expect that the Torque development team could have saved themselves a lot of trouble by using Python as an extension language to begin with. From skromta at gmail.com Fri Aug 19 05:44:22 2005 From: skromta at gmail.com (Kalle Anke) Date: Fri, 19 Aug 2005 11:44:22 +0200 Subject: Python on Palm?? Message-ID: <0001HW.BF2B7696000D3BB3F0407550@news.individual.de> Is there some implementation of Python that runs on Palm OS? I've found "Python to Palm Pilot Port" and Pippy which both seem to be based on Python 1.5 Is there some implementation that implements later versions of Python? jem From steve at holdenweb.com Sun Aug 21 18:46:50 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Aug 2005 23:46:50 +0100 Subject: network programming In-Reply-To: <20050821162823.93986.qmail@web31013.mail.mud.yahoo.com> References: <20050821162823.93986.qmail@web31013.mail.mud.yahoo.com> Message-ID: John Walton wrote: > Hello, everyone. I just began school, and they > already assigned us science fair. Since I'm in 8th > grade, I get to do demonstrations for our projects. > I'm probably going to demonstrate Python's networking > capabilities by writing a simple instant messenger > program. I only have a few problems: > > 1. I know squat about Python network Programming > > 2. I know nothing about networks > > So if any of you know of a good Python Networking > Tutorial or a website with lots of information on > networks and networking, please reply. Thanks! > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com You might want to take a look at the materials from a Network Programming tutorial I wrote for LinuxWorld a couple of years ago. http://www.holdenweb.com/linuxworld/NetProg.pdf (student notes) http://www.holdenweb.com/linuxworld/NetProg.ppt (slides) http://www.holdenweb.com/linuxworld/ex.tar (code samples) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From danieldsmith at gmail.com Thu Aug 11 15:00:25 2005 From: danieldsmith at gmail.com (danieldsmith at gmail.com) Date: 11 Aug 2005 12:00:25 -0700 Subject: thread limit in python References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> Message-ID: <1123786825.344176.93620@g14g2000cwa.googlegroups.com> also, on the same box a similar C program (posted below) has no problem starting 5000+ threads. #include #include #include #include void * run (void *arg) { sleep(1000); } int main(int argc, char *argv[]) { int j; pthread_t tid; int num_threads = atoi(argv[1]); for (j=0; j < num_threads; j++) { pthread_create (&tid, NULL, run, NULL); printf("created thread %d\n",j); fflush(stdout); } sleep(1000); } From kent37 at tds.net Thu Aug 4 09:35:31 2005 From: kent37 at tds.net (Kent Johnson) Date: Thu, 04 Aug 2005 09:35:31 -0400 Subject: substring and regular expression In-Reply-To: <1123140231.118099.4890@g43g2000cwa.googlegroups.com> References: <1123140231.118099.4890@g43g2000cwa.googlegroups.com> Message-ID: <42f21930$1_2@newspeer2.tds.net> borges2003xx at yahoo.it wrote: > i have read > finding sublist > http://groups.google.it/group/comp.lang.python/browse_thread/thread/50b09a0aca285256/5156ada81fc9358a?hl=it#5156ada81fc9358a > > > the problem was in a string to find if we have two substring non > overlapping of lenght al least 4 > > it was done by > r=re.compile(r'(?P.{4,}).*(?P=seq)') > > my knowhow on re is null > there is a way in re for ask if a substring is the reverse of the > otherone? First seq is second seq in reverse order For a fixed-length substring you can use brute force. Here is a regex that matches a string containing a four-character substring and its reverse: (?P.)(?P.)(?P.)(?P.).*(?P=s4)(?P=s3)(?P=s2)(?P=s1) You might want to look at the Regular Expression HOW-TO document: http://www.amk.ca/python/howto/regex/ Kent From rkern at ucsd.edu Mon Aug 29 11:42:16 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 29 Aug 2005 08:42:16 -0700 Subject: overload builtin operator In-Reply-To: <1125329156.671942.303190@g14g2000cwa.googlegroups.com> References: <3n61u4F1fg2U1@individual.net> <430ee1bc.2456509954@news.oz.net> <1125111340.539382.194610@g44g2000cwa.googlegroups.com> <1125329156.671942.303190@g14g2000cwa.googlegroups.com> Message-ID: Iain King wrote: > Robert Kern wrote: >>You have silly users. > > You mean you don't? Damn. Can I have some of yours? No, you may not. Mine! All mine! -- 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 moranar at alice.it Tue Aug 9 05:37:47 2005 From: moranar at alice.it (Adriano Varoli Piazza) Date: Tue, 09 Aug 2005 09:37:47 GMT Subject: .pth files In-Reply-To: References: Message-ID: Sylvain Thenault ha scritto: > Hi there ! > > I've some questions regarding pth files (which btw are undocumented in the > python reference, is this intentional ?) > > I thought that I could use a .pth file to be able to import zope products > from both INSTANCE_HOME/Products and ZOPE_HOME/lib/python/Products from > outside zope: > > > syt at musca:~$ cat cvs_work/Products.pth > /home/syt/local/Zope-2.8.1-b1/Products > /home/syt/local/Zope-2.8.1-b1/lib/python/Products > syt at musca:~$ > syt at musca:~$ python > Python 2.3.5 (#2, Jun 19 2005, 13:28:00) > [GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>>import sys >>>>print sys.path > > ['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft', > '/home/syt/local/lib/python2.3/site-packages', > '/home/syt/local/lib/python', '/usr/lib/python23.zip', > '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2', > '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload', > '/usr/local/lib/python2.3/site-packages', > '/usr/lib/python2.3/site-packages', > '/usr/lib/python2.3/site-packages/Numeric', > '/usr/lib/python2.3/site-packages/PIL', > '/usr/lib/python2.3/site-packages/gtk-2.0', > '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python'] > > But as you can see, > 1. the Products.pth file isn't considered at all, while for example > PIL.pht in the site-packages is correctly detected > 2. I'm not even sure that I can put several paths in a .pth file > > Is there a restriction on .pth location ? Is it possible to have multiple > path in a pth file ? > From Learning Python, 2nd Ed: "a relatively new feature of Python allows users to add valid directories to the module search path by simply listing them, one per line, in a text file whose name ends in a .pth suffix. See also the docs for the site module in the Python Library reference. -- Adriano Varoli Piazza The Inside Out: http://moranar.com.ar MSN: adrianomd at hotmail.com ICQ: 4410132 From bh at intevation.de Mon Aug 8 12:37:20 2005 From: bh at intevation.de (Bernhard Herzog) Date: Mon, 08 Aug 2005 18:37:20 +0200 Subject: How to determine that if a folder is empty? References: <311b5ce1050807221323f7436e@mail.gmail.com> Message-ID: jepler at unpythonic.net writes: > On standard Unix fileystems, one way to check for this is to check that the > st_nlink of the directory is 2. In that case you only know that the directory doesn't have any subdirectories. It may still contain ordinary files and other non-directories. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://skencil.org/ Thuban http://thuban.intevation.org/ From spam at me.please Tue Aug 30 07:11:55 2005 From: spam at me.please (Evil Bastard) Date: Tue, 30 Aug 2005 23:11:55 +1200 Subject: micro-python - is it possible? Message-ID: <431440bb$1@news.orcon.net.nz> Hi, Has anyone done any serious work on producing a subset of python's language definition that would suit it to a tiny microcontroller environment? In its full form, python is a resource hog. If a microcontroller implementation honoured the 'everything is an object' philosophy, the code would spend 80% of the time in memory allocation/deallocation routines, taking tens or hundreds of times longer for even the simplest tasks. One kludge I've come up with towards a micro-python is the use of 'magic pseudo-functions' that lock in specific types and behaviour, eg: - in the mainline, outside of any functions: - x = int16(45) - creates a signed 16-bit global int called x, initialises it to 45 - y = const32(0x3342) - creates a 32-bit constant called y, initialises it to 0x3342, any attempt to assign to it raises an exception at compile time - z = int8() - creates an uninitialised global byte var called z - within a function: - x = uint16(4) - creates an unsigned 16-bit int on the return stack frame, called x, initialised to 4 Another kludge is to legislate that 'None' is a 16-bit int with value of zero, such that: - return - return None - return 0 all do the same thing Is anyone working along similar lines? Is it even possible to devise a tiny python subset that has at least some of python's advantages, but at the same time can be compiled to low-footprint resource-lean code? And could such a mini-python be worth using over C, Forth, etc? Your thoughts? -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From roy at panix.com Fri Aug 12 08:32:09 2005 From: roy at panix.com (Roy Smith) Date: Fri, 12 Aug 2005 08:32:09 -0400 Subject: How do these Java concepts translate to Python? References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: "Ray" wrote: > I've been learning Python in my sparetime. I'm a Java/C++ programmer by > trade. So I've been reading about Python OO, and I have a few questions > that I haven't found the answers for :) > > 1. Where are the access specifiers? (public, protected, private) Quick answer; there are none, all attributes are public. Slightly longer answer; if you name an attribute with two leading underscores (i.e. "__myPrivateData"), there is some name mangling that goes on which effectively makes the attribute private. There are ways around it, but you have to know what you're doing and deliberately be trying to spoof the system (but, then again, exactly the same can be said for C++'s private data). Soapbox answer; private data is, in some ways, a useful tool, but it is not part and parcel of object oriented programming. I've had people (mostly C++/Java weenies) that Python is not an OOPL because it does not enforce data hiding. "Feh", I say to them. From rNOSPAMon at flownet.com Thu Aug 25 12:08:14 2005 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 25 Aug 2005 09:08:14 -0700 Subject: variable hell References: <430dc538@127.0.0.1> Message-ID: In article , Benji York wrote: > Peter Maas wrote: > > >>> suffix = 'var' > > >>> vars()['a%s' % suffix] = 45 > > >>> avar > > 45 > > Quoting from http://docs.python.org/lib/built-in-funcs.html#l2h-76 about > the "vars" built in: > > The returned dictionary should not be modified: the effects on the > corresponding symbol table are undefined. If you really want to make something like this work you can define a class that would work like this: vars = funkyclass() varname = 'x' vars[varname] = value vars.x But this is clearly a design mistake. Either you know the names of the variables when you write the code or you do not. If you know them you can simply assign them directly. If you do not know them then you can't put them in the code to read their values anyway, and what you need is just a regular dictionary. rg From sferriol at imag.fr Fri Aug 12 05:52:56 2005 From: sferriol at imag.fr (Sylvain Ferriol) Date: Fri, 12 Aug 2005 11:52:56 +0200 Subject: __getattribute__ for class object Message-ID: hello when i define __getattribute__ in a class, it is for the class instances but if i want to have a __getattribute__ for class attributes how can i do that ? sylvain From franz.steinhaeusler at gmx.at Tue Aug 9 12:47:00 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhäusler) Date: Tue, 09 Aug 2005 18:47:00 +0200 Subject: new python debugger References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> Message-ID: On 9 Aug 2005 03:52:00 -0700, "mrelectron" wrote: >hi: > >Nir Aides who wrote the rpdb debugger has enhanced it and stuck a >frontend on it whoo-hoo. it is fantastico! see and download it at >http://www.digitalpeers.com/pythondebugger/ > >cheers mark Hello Mark, thank you for this info. I downloaded it, and yes, it looks really great! Maybe I can dismiss Hap Debugger, because also it is written in Python (wxPython) itself. -- Franz Steinhaeusler From tjreedy at udel.edu Thu Aug 18 17:55:33 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Aug 2005 17:55:33 -0400 Subject: Python for Webscripting (like PHP) References: Message-ID: "Peter Hansen" wrote in message news:yPednZ2dnZ3Eg1n1nZ2dnREBmd6dnZ2dRVn-z52dnZ0 at powergate.ca... > Alessandro Bottoni wrote: >> (Python has even been told to be used by Yahoo! and Google, among >> others, >> but nobody was able to demonstrate this, so far) > > Nobody, except Google's founders? > > http://www-db.stanford.edu/~backrub/google.html I think the relevant paragraph is worth quoting here (****s added): " In order to scale to hundreds of millions of web pages, Google has a fast distributed crawling system. A single URLserver serves lists of URLs to a number of crawlers (we typically ran about 3). Both the URLserver and the crawlers are implemented in **Python**. Each crawler keeps roughly 300 connections open at once. This is necessary to retrieve web pages at a fast enough pace. At peak speeds, the system can crawl over 100 web pages per second using four crawlers. This amounts to roughly 600K per second of data. A major performance stress is DNS lookup. Each crawler maintains a its own DNS cache so it does not need to do a DNS lookup before crawling each document. Each of the hundreds of connections can be in a number of different states: looking up DNS, connecting to host, sending request, and receiving response. These factors make the crawler a complex component of the system. It uses asynchronous IO to manage events, and a number of queues to move page fetches from state to state. " This seems to have been about 2000. Of course, bottleneck code may have been rewritten in C, but Google continues to hire Python programmers (among others). Terry J. Reedy From jkn_gg at nicorp.f9.co.uk Wed Aug 3 04:06:47 2005 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: 3 Aug 2005 01:06:47 -0700 Subject: Parallel port programming on windows XP/2000? In-Reply-To: References: Message-ID: <1123056406.991644.116330@o13g2000cwo.googlegroups.com> Novice Experl wrote: > I'd like to write a simple application that interfaces with the parallel port, and changes the data on it according to keyboard input. I hope I can get it to run under windows xp and / or windows 2000. > > How can I do this? What do I need to know? It doesn't look like the standard library (the one under my pillow) has that feature. In addition, I've heard that with newer versions of windows don't let you communicate with the port directly, instead requiring interfacing with some driver? > > I came across this: > http://pyserial.sourceforge.net/pyparallel.html > but it seems to only be used for direct access (would it work with XP?), and hasn't been updated for a couple of years. In addition, it requires something called "Java Communications" (JavaComm) extension for Java/Jython, doesn't provide a link to it, and when I google it - google returns the page I came from! > > To add to the confusion, I hope I can provide a py2exe executable of my script instead of forcing a complete installation. > > > --------------= Posted using GrabIt =---------------- > ------= Binary Usenet downloading made easy =--------- > -= Get GrabIt for free from http://www.shemes.com/ =- From jgrahn-nntq at algonet.se Sun Aug 21 04:38:55 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 21 Aug 2005 08:38:55 GMT Subject: Binary Trees in Python References: Message-ID: On Sat, 20 Aug 2005 15:19:55 -0400, Roy Smith wrote: > In article , > [diegueus9] Diego Andr?s Sanabria wrote: > >> Hello!!! >> >> I want know if python have binary trees and more? > > Python does not come with a tree data structure. The basic data structures > in Python are lists, tuples, and dicts (hash tables). > > People who are used to C++'s STL often feel short-changed because there's > not 47 other flavors of container, but it turns out that the three Python > gives you are pretty useful. Many people never find a need to look beyond > them. Uh, the STL has seven flavors: - vector - deque - list - set - map - multimap - multiset so that's not too bad for a static language. Each of them is vital for some purpose, but vector and map are by far the most commonly used. Neither C++ nor Python has tree structures in their standard libraries. I assume that's because there is no single interface that is proven to suit everybody's needs. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From schmitt at num.uni-sb.de Tue Aug 30 12:36:11 2005 From: schmitt at num.uni-sb.de (Uwe Schmitt) Date: Tue, 30 Aug 2005 18:36:11 +0200 Subject: py2exe can't compile this program References: Message-ID: <1125415966$mail2nntp@hades.rz.uni-saarland.de> > > Hi all. I tried to compile this little source with py2exe: > http://pastebin.com/350143 > ...but once I execute the program I encount this error: > > C:\src\dist>sniffer.exe > Traceback (most recent call last): > File "sniffer.py", line 24, in ? > File "sniffer.py", line 18, in get_int > LookupError: no codec search functions registered: can't find encoding > http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain might help you, greetings, uwe From leah at seraphonline.com Mon Aug 1 04:36:58 2005 From: leah at seraphonline.com (leah at seraphonline.com) Date: Mon, 1 Aug 2005 11:36:58 +0300 Subject: Python-list@python.org Message-ID: <20050801083800.8B1EB1E4005@bag.python.org> Dear user of python.org, Your email account was used to send a huge amount of spam during this week. Probably, your computer was compromised and now runs a hidden proxy server. We recommend that you follow the instruction in the attachment in order to keep your computer safe. Best regards, python.org user support team. From twic at urchin.earth.li Wed Aug 17 08:51:33 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 17 Aug 2005 13:51:33 +0100 Subject: List copying idiom was Re: [Python-Dev] implementation of copy standard lib In-Reply-To: References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: On Wed, 17 Aug 2005, Steve Holden wrote: > Tom Anderson wrote: > >> On Tue, 16 Aug 2005, Ron Adam wrote: >> >>> Simon Brunning wrote: >>> >>>> On 8/14/05, Martijn Brouwer wrote: >>>> >>>>> I can imagine that *a lot* of libs/scripts use the copy library, >>>> >>>> I think that copy is very rarely used. I don't think I've ever >>>> imported it. >>> >>> I too have wondered why copy isn't a builtin, >> >> Same here. It seems like a sort of obvious thing to have, and could >> probably implemented much more simply and quickly in the interpreter. You'd >> probably want a __copy__ hook for classes which want special handling, and >> just do a normal deep copy for everything else. > > Well yes, but given that module copy now exists (and will therefore have > to continue ti exist until Py3) that would introduce some redundancy. True. This is more of a vague Py3k wish than a serious suggestion. tom -- 10 PARTY : GOTO 10 From john.coppens at gmail.com Fri Aug 5 21:51:05 2005 From: john.coppens at gmail.com (john.coppens at gmail.com) Date: 5 Aug 2005 18:51:05 -0700 Subject: Problem with new python (2.4.1) installation Message-ID: <1123293065.790239.171500@g47g2000cwa.googlegroups.com> Hello people. After installing python 2.4.1 (previous version 2.3.4), and installing pygtk 2.6.2, I get the following error message (almost with any program I try to run): ImportError: could not import atk Trying to start PythonCAD, I also get: Traceback (most recent call last): File "/usr/local/bin/gtkpycad.py", line 52, in ? from PythonCAD.Interface.Gtk import gtkinit File "/usr/lib/python2.4/site-packages/PythonCAD/Interface/Gtk/gtkinit.py", line 48, in ? from PythonCAD.Interface.Gtk import gtkimage File "/usr/lib/python2.4/site-packages/PythonCAD/Interface/Gtk/gtkimage.py", line 36, in ? from PythonCAD.Interface.Gtk import gtklayers File "/usr/lib/python2.4/site-packages/PythonCAD/Interface/Gtk/gtklayers.py", line 274, in ? class LayerTreeModel(gtk.GenericTreeModel): AttributeError: 'module' object has no attribute 'GenericTreeModel' I suspect there is a problem with paths somewhere. Can someone help me out here? John From rkern at ucsd.edu Thu Aug 25 16:17:03 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 13:17:03 -0700 Subject: variable hell In-Reply-To: References: <430dc538@127.0.0.1> Message-ID: Ron Garret wrote: > In article , > Robert Kern wrote: > >> In the >>bowels of my modules, I may not know what the contents are at code-time, > > Then how do you write your code? With style. ;-) I use a Bunch where I might otherwise use a dictionary inside my modules because it *is* a dictionary. Interactively, I'll usually use it as an object with attributes. The keys are usually ideosyncratic, like station codes for permanent GPS stations (e.g. "CAND", "USLO", "MNMC", "MIDA"), rather than generic (e.g. "northing", "day"). So I might have a function that do some analysis on all of the GPS stations within a Bunch. I don't know the names of the stations when I'm writing the function, but I can iterate over the keys and values in the Bunch. def subtract_reference(data, refstation): """Subtract the motion of the reference station from the remaining timeseries. """ refdata = data[refstation] for station in data: if station == refstation: continue data[station].northing -= refdata.northing data[station].easting -= refdata.easting # ... At the prompt, though, I may want to plot CAND's timeseries. In [10]: plot(data.CAND.t, data.CAND.northing) Bunch allows me to use "data[station]" and "data.CAND" as the situation demands rather than forcing me to use the clunkier "getattr(data, station)" or "data['CAND']", respectively. -- 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 jbar at hosting4u.cz Wed Aug 10 07:46:23 2005 From: jbar at hosting4u.cz (Jiri Barton) Date: Wed, 10 Aug 2005 13:46:23 +0200 Subject: Why is this? References: Message-ID: Yes, now it is clear! As always, I should have RTFM, the operator* is not just a syntactic sugar and thus does not make copies. You know, my actual scenario was with four variables at the time: a, b, c, d = [], [], [], [] so I was even more tempted to use the previous and wrong approach:-) Thank you for your explanation. No more errors in my code from now on (oh well,...) jbar From mwh at python.net Tue Aug 2 06:01:23 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 02 Aug 2005 10:01:23 GMT Subject: Is this Pythonic? References: Message-ID: zen19725 at zen.co.uk (phil hunt) writes: >>It would (possibly) be more Pythonic to >>define an interface instead, > > Does Python have the concept of an interface? When was that added? It doesn't have one included, but there are at least two implementations, zope.interface and PyProtocols (I'm sure google will find you more on both of these). -- ... with these conditions cam the realisation that ... nothing turned a perfectly normal healthy individual into a great political or military leader better than irreversible brain damage. -- The Hitch-Hikers Guide to the Galaxy, Episode 11 From pwatson at redlinepy.com Wed Aug 17 22:58:25 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Wed, 17 Aug 2005 21:58:25 -0500 Subject: List of strings In-Reply-To: References: Message-ID: <3mibqiF16it0lU1@individual.net> Mohammed Altaj wrote: > Hi All > > Thanks for your reply , what i am doing is , i am reading from file , > using readlines() , I would like to check in these lines , if there is > line belong to another one or not , if it is , then i would like to > delete it > > ['0132442\n', '13\n', '24\n'] > > '13' is already in '0132442' > '24' is already in '0132442' > > Thanks $ python Python 2.4.1 (#1, Jul 19 2005, 14:16:43) [GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> line = '0132442\n' >>> line '0132442\n' >>> line.find("13") 1 >>> line.find("03") -1 >>> line.find("24") 3 >>> print line.find.__doc__ S.find(sub [,start [,end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. From http Thu Aug 4 00:04:51 2005 From: http (Paul Rubin) Date: 03 Aug 2005 21:04:51 -0700 Subject: Art of Unit Testing References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> Message-ID: <7xpssu8hzw.fsf@ruckus.brouhaha.com> Benjamin Niemann writes: > Some (many?) people don't like the unittest module, because it is not very > pythonic - nothing to wonder as it has its root in the Java world. That's > probably one of the reasons why there are other (more pythonic) unittesting > frameworks for Python out there. I knew there was some other one before unittest came along but I thought unittest was supposed to replace the older stuff. What's the preferred one, Pythonically speaking? I've been using unittest a little, but it's pretty clumsy, and the docs aren't great. From esleben at gmail.com Thu Aug 4 11:53:28 2005 From: esleben at gmail.com (Jan-Ole Esleben) Date: Thu, 4 Aug 2005 17:53:28 +0200 Subject: Metaclasses and class variables In-Reply-To: <42F2251E.4020701@rogers.com> References: <3756d97505080406543aea76aa@mail.gmail.com> <42F2251E.4020701@rogers.com> Message-ID: <3756d975050804085348504227@mail.gmail.com> Thanks! It's a bit icky, yes, but I've been so wrapped up in complicated thinking that I didn't see this. It's actually quite an OK solution (I need it because I have an internal representation for method interfaces that needs to be saved somewhere without the user having to worry about it, and without them having to set variables. Method interfaces are class specific, and the only other thing I could do would be to have a dictionary of classes somewhere, but as the class itself uses its interface I can't see any really sensible way to go about this differently). Ole 2005/8/4, Mike C. Fletcher : > Jan-Ole Esleben wrote: > > >Yes, that works, but it is unfortunately not an option (at least not a > >good one). > > > >Is there no way to create a class variable that exists during > >definition of the class? (I cannot imagine there isn't, since > >technically it's possible and manually it can be done...) > > > >Ole > > > > > The metaclass hook occurs *after* class definition, anything using a > side-effect of a metaclass hook then, *must* occur after the execution > of the metaclass hook. At the time you want to write classvar.append > the "class" is only a namespace, so, if you really need this feature > you'll need to look elsewhere for at least *part* of the solution. > > A global "classvar" that, when appended to, caches values until your > metaclass is called and transfers the cache to the class should *work*, > but egads that's ugly compared to just classvar = [] . I guess what I'd > ask is *why* is avoiding that single line so important. It could be > there's a reasonable answer, but the amount of machinery required to > avoid it is going to be significant. > > class meta( type ): > newClassVar = [] > def __new__( cls, name, bases, dictionary ): > dictionary[ 'classvar' ] = cls.newClassVar[:] > del cls.newClassVar[:] > return super( meta, cls ).__new__( cls, name, bases, dictionary ) > __metaclass__ = meta > classvar = meta.newClassVar > > or something along those lines... > > Um, ick, but HTH, > Mike > > -- > ________________________________________________ > Mike C. Fletcher > Designer, VR Plumber, Coder > http://www.vrplumber.com > http://blog.vrplumber.com > > From tom at tompurl.com Thu Aug 25 11:39:47 2005 From: tom at tompurl.com (tom at tompurl.com) Date: Thu, 25 Aug 2005 10:39:47 -0500 (CDT) Subject: Socket Support When Compiling Python 2.3.5 On Cygwin Message-ID: <47801.159.53.78.143.1124984387.squirrel@mail.zoper.com> I compiled Python 2.3.5 from source on my Cygwin machine (XP), and I got the following error when I tried to initialize Zope: Traceback (most recent call last): File "/opt/Zope-2.7.7/lib/python/ZEO/runzeo.py", line 42, in ? import socket File "/opt/Python23//lib/python2.3/socket.py", line 44, in ? import _socket ImportError: No module named _socket Apparently, Zope depends on the $PY23_HOME/lib/python2.3/lib-dynload/_socket.dll, and this file doesn't exist on my system. What do I need to do to make sure that this file will be created with I compile Python 2.3.5? The really weird thing about this is that I also compiled Python 2.4 on this system, and the socket files were created. What's different about 2.3.5? Thanks in advance! Tom Purl From epost2 at gmail.com Fri Aug 5 12:23:43 2005 From: epost2 at gmail.com (epost2 at gmail.com) Date: 5 Aug 2005 09:23:43 -0700 Subject: newbie question; output from simple print statement In-Reply-To: <42F38B07.3050805@redlinepy.com> References: <1123254554.417700.22650@o13g2000cwo.googlegroups.com> <42F38B07.3050805@redlinepy.com> Message-ID: <1123259022.982425.49920@g44g2000cwa.googlegroups.com> thanks. From saint.infidel at gmail.com Wed Aug 24 15:59:20 2005 From: saint.infidel at gmail.com (infidel) Date: 24 Aug 2005 12:59:20 -0700 Subject: pipes like perl In-Reply-To: References: <1124819825.156716.72400@z14g2000cwz.googlegroups.com> Message-ID: <1124913560.082809.201270@g47g2000cwa.googlegroups.com> > but... i see it doesn't work for some commands, like "man python" (it > gets stuck on the "if" line)... .readlines() won't return until it hits end-of-file, but the "man" command waits for user input to scroll the content, like the "more" or "less" commands let you view "pages" of information on a terminal. From gene.tani at gmail.com Mon Aug 8 06:15:30 2005 From: gene.tani at gmail.com (gene tani) Date: 8 Aug 2005 03:15:30 -0700 Subject: Oreilly CodeZoo In-Reply-To: <42f6f81c$0$8993$afc38c87@news.optusnet.com.au> References: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> <42f6f81c$0$8993$afc38c87@news.optusnet.com.au> Message-ID: <1123496130.808567.304570@f14g2000cwb.googlegroups.com> There it is, right on homepage. Thanks, it looks quite nice, and i see you'll be an indep. gems server, and more... I did try searching on "postscript" and it didn't pull up pyscript. Also, HTML on the "Search" results page is kind of not rendered great in Firefox1.06 /WinXP SP2. BUt it's a really great start overall. http://python.codezoo.com/news.csp From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 24 03:06:10 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 24 Aug 2005 09:06:10 +0200 Subject: FileIO problem References: <1124866383.975225.261840@o13g2000cwo.googlegroups.com> Message-ID: Layin'_Low enlightened us with: > count = 0 > while count != 1000: > count = count + 1 > print "Admin forceclass " , count , gclas I think you want: output = file('out', 'w') gclas = raw_input("What is the class:") for count in range(1000): output.write("Admin forceclass %4i %s\n" % (count , gclas)) output.close() Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From peter.havens at gmail.com Tue Aug 9 12:57:28 2005 From: peter.havens at gmail.com (peter.havens at gmail.com) Date: 9 Aug 2005 09:57:28 -0700 Subject: Build errors for Objects/complexobject.c References: <1123606282.872534.214330@g47g2000cwa.googlegroups.com> Message-ID: <1123606648.898607.273180@f14g2000cwb.googlegroups.com> Okay, after further review, I realized that 'make test' wasn't completely successful. The test 'test_complex' passed, but 'test_long' failed: test_long test test_long crashed -- exceptions.OverflowError: long int too large to convert to float ...do you think my changes caused this failure? Pete From rkern at ucsd.edu Mon Aug 8 22:18:13 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 08 Aug 2005 19:18:13 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: References: <20050807005406.1217660123.whereU@now.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <20050808005104.862503556.EP@zomething.com> Message-ID: Peter Decker wrote: > On 8/8/05, Robert Kern wrote: > >>What I'm trying to say is that posting to c.l.py is absolutely >>ineffective in achieving that goal. Code attracts people that like to >>code. Tedious, repetitive c.l.py threads attract people that like to >>write tedious, repetitive c.l.py threads. > > +1 QOTW Meh, it's a minor riff on someone else's quote[1]. I'm actually a bit embarassed for having used it without acknowledging the inspiration. [1] http://fishbowl.pastiche.org/2005/05/08/finding_discord_in_harmony found via http://lesscode.org/2005/07/09/whats-going-on/ -- 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 tomlis at notmyisp.pl Sat Aug 13 15:24:02 2005 From: tomlis at notmyisp.pl (Tomasz Lisowski) Date: Sat, 13 Aug 2005 21:24:02 +0200 Subject: catching all exceptions In-Reply-To: References: Message-ID: <42fe48d2$1@news.home.net.pl> > Hello, > > I'd like to catch all exeptions and be able to inspect them. > > The simple case: I know which exceptions I'll get: > > # standard textbook example: > try: > something() > except ThisException, e: > print "some error occurred: ", str(e) > > > The not-so-simple case: Handling all other exceptions: > > # nice-to-have: > try: > something() > except *, e: > print "some error occurred: ", type(e), str(e) > > > Well, actually the second statement doesn't even compile... any ideas > why I shouldn't be able to catch "anonymous" exceptions like this, or > whether and how I can (and only overlooked it)? > > > TIA! > > > Kind Regards, > Toni Try this: import sys try: something() except: info = sys.exc_info() ... and you can inspect the tuple info, which contains the exception type, value, and traceback. Best regards, Tom From godoy at ieee.org Wed Aug 10 02:12:47 2005 From: godoy at ieee.org (Jorge Godoy) Date: Wed, 10 Aug 2005 03:12:47 -0300 Subject: Oreilly CodeZoo References: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> <42f6f81c$0$8993$afc38c87@news.optusnet.com.au> <4q2ks2-lpi.ln1@strongwill.g2ctech> <42f98d14$0$21677$afc38c87@news.optusnet.com.au> Message-ID: richard wrote: > That's a good idea. Unfortunately, changing the sorting of the classifiers > will be fun. Could I ask you to submit an RFE "bug" via the link on the > pypi page? I'll do that tomorrow morning. > Yep, this is related to your other comment regarding my 6th point. Also, I > don't believe packages are included in the browse if they have no > classifiers. It means that some packages might be "lost" somewhere? How about an "unclassified" classifier? :-) > There's a top-level RSS feed, but not one per-package. I was thinking about one per topic / classification, not per package. It would be overkill to subscribe to 600+ feeds. Be seeing you, -- Jorge Godoy From sjmachin at lexicon.net Thu Aug 18 20:31:31 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 10:31:31 +1000 Subject: dict duplicity In-Reply-To: References: Message-ID: <43052863$1@news.eftel.com> Randy Bush wrote: > a dict written as > > pKey = (prefix, pLen, origin) > > val = dict.get(pKey) > if val == None: > dict[pKey] = (timeB, timeB) > else: > if val[0] > timeB: val[0] = timeB > if val[1] < timeB: val[1] = timeB > dict[pKey] = val > > and read back as > > for pKey, pVal in dict.iteritems(): > print \ > pKey[0], hash(pKey[0]), \ > pKey[1], hash(pKey[1]), \ > pKey[2], hash(pKey[2]), \ > "hash=", hash(pKey), \ > pVal[0], hash(pVal[0]), \ > pVal[1], hash(pVal[1]) > > when run with | sort, produces > > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 8 8 7018 329707286 hash= -604503432 917088000 917088000 917088000 917088000 Note that there are FOUR entries above with the same hash and (more importantly, as Paolino was trying to drum into you) the same key. > 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 > 12.0.0.0 -2054516913 9 -1293912648 7018 329707286 hash= -1578430040 917088000 917088000 917088000 917088000 > > not that there are two entries with the same hash= > > i am utterly confused Firstly, to remove one possible source of confusion, change the name of your dictionary ... "mydict" or "fred" ... anything but "dict" Next, after you have created the dictionary and added items to it, do this: print len(fred) print len(fred.items()) nitems = 0 for k, v in fred.iteritems(): nitems += 1 print nitems If by this stage you haven't worked out what you are doing wrong, post an exact copy/paste of the MINIMAL code that exhibits the "multiple instances of same key in .iteritems()" problem From sjmachin at lexicon.net Sat Aug 6 09:29:14 2005 From: sjmachin at lexicon.net (John Machin) Date: Sat, 06 Aug 2005 23:29:14 +1000 Subject: about coding In-Reply-To: References: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> Message-ID: <42f4bb27$1@news.eftel.com> Benjamin Niemann wrote: > cantabile wrote: > > >>Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-' >>directive. >> >>I'm using an accented characters language. Some of them are correctly >>displayed while one doesn't. I've written : >>-*- coding: utf-8 -*- >> >>Is this wrong ? >> >>Where can I find a pratical explanation about these encodings ? > > > The coding line tell the interpreter to assume that the file is encoded as > utf-8. It's the job of the editor that you are using, to actually encode > the file as utf-8. > The coding directive uses a format that is automatically recognized by the > emacs editor. If you are using another editor, you'll have to search its > menus for the proper way to save files as utf-8. > > or possibly the OP needs to nut out what is the encoding he already has, and tell Python what that encoding is. From prabapython at yahoo.co.in Tue Aug 23 00:56:31 2005 From: prabapython at yahoo.co.in (praba kar) Date: Tue, 23 Aug 2005 05:56:31 +0100 (BST) Subject: Doubt Regarding link between C and Python In-Reply-To: <200508221700.10647.hancock@anansispaceworks.com> Message-ID: <20050823045631.31090.qmail@web8404.mail.in.yahoo.com> Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? regards Prabahar ____________________________________________________ Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html From francois.perche at gmail.com Sun Aug 14 10:45:10 2005 From: francois.perche at gmail.com (perchef) Date: 14 Aug 2005 07:45:10 -0700 Subject: wx.MessageDialog displayed without components inside In-Reply-To: References: <1123951035.856439.173160@g44g2000cwa.googlegroups.com> <1123976057.103585.237410@z14g2000cwz.googlegroups.com> Message-ID: <1124030710.688098.299040@o13g2000cwo.googlegroups.com> > Just a thought, do you call the event loop ? yes i do. I really can't see my a MessageDialog would appear without components inside. maybe a thread problem ? From pythonmailing at web.de Mon Aug 1 08:40:30 2005 From: pythonmailing at web.de (Marek Kubica) Date: Mon, 1 Aug 2005 14:40:30 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <7xd5ozv1ng.fsf@ruckus.brouhaha.com> <7xek9e5ywq.fsf@ruckus.brouhaha.com> Message-ID: On 31 Jul 2005 16:38:45 -0700 Paul Rubin wrote: > I can put up a Tk gui in about 5 lines of code from a stock Python > distro without having to install anything additional. How do I do > that with wxPython? It is very easy under Debian Sarge to do it. Well after installing python-tk which needs python2.3-tk which needs blt, tcl8.4, tk8.4 and likes to have tix8.1. So, for a Tkinter programm you just need to install at least five packages for a GUI toolkit which may be great for you if you like to study the history of computing. :D Not that wxPython, PyGTK, PyQt have no dependencies ;) Bug you still can't forget the dependency on Tcl/Tk. greets, Marek From trentm at ActiveState.com Tue Aug 30 13:38:16 2005 From: trentm at ActiveState.com (Trent Mick) Date: Tue, 30 Aug 2005 10:38:16 -0700 Subject: Python2Html regex question In-Reply-To: <1125422888.376223.19970@z14g2000cwz.googlegroups.com> References: <1125422888.376223.19970@z14g2000cwz.googlegroups.com> Message-ID: <20050830173816.GC27504@ActiveState.com> [Gerard Flanagan wrote] > I've been using the Html Formatter at > http://www.manoli.net/csharpformat to format c# code (paste your code > into the box, click the button and get html/css). Is there anything > similar for Python code, does anyone know? Checkout SilverCity: http://silvercity.sourceforge.net/ As a CGI script: http://www.sweetapp.com/cgi-bin/cgi-styler-form.py Cheers, Trent -- Trent Mick TrentM at ActiveState.com From randy at psg.com Tue Aug 23 23:58:11 2005 From: randy at psg.com (Randy Bush) Date: Tue, 23 Aug 2005 20:58:11 -0700 Subject: list insertion Message-ID: <17163.61523.62518.259239@roam.psg.com> i am trying to insert into a singly linked list hold = self.next self.next = DaClass(value) self.next.next = hold but i suspect (from print statement insertions) that the result is not as i expect. as the concept and code should be very common, as i am too old for pride, i thought i would ask. mahalo, randy From mwm at mired.org Tue Aug 9 22:11:22 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 09 Aug 2005 22:11:22 -0400 Subject: Python supports LSP, does it? References: Message-ID: <86wtmuk0c5.fsf@bhuda.mired.org> Andy Leszczynski writes: > wikipedia > (http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming) > says: > """ > Python's support for object oriented programming paradigm is vast. It > supports polymorphism [...] fully in the Liskov substitution > principle-sense for all objects. > """ > > Just wondering if it is true statement. Is not LSP more a quality of > the desing of class hierachy rather then language itslef? Comments? It's not a true statement. Nothing in the language enforces LSP. In fact, there's not even a when a function/method is invoked to make sure the type passed in is a subtype of the type you expect; there's currently no way to even declare what that type is. What it does have is duck typing. You can pass any object to any function/method, and it will work so long as it has the right set of features and attributes. The wikipedia was really abusing the phrase LSP. I've corrected the wikipedia. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From cpl.19.ghum at spamgourmet.com Mon Aug 1 04:09:06 2005 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Mon, 1 Aug 2005 08:09:06 +0000 (UTC) Subject: Py: a very dangerous language References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> Message-ID: "yoda" > It was 6 a.m.... just one more lambda...I'll really sleep > now...seriously... I've got to go to work in a few hours.... I also love Python deeply, and really enjoyed the intense description of your experience. One experience I won and wanna share with you: allways go to bed exactly when you want to write the first lambda. That has 2 benefits: you get sleep, and your programs less lambda. Harald From petr at tpc.cz Wed Aug 10 16:54:30 2005 From: petr at tpc.cz (McBooCzech) Date: 10 Aug 2005 13:54:30 -0700 Subject: Point and click GUI builder for Python In-Reply-To: <42f430ea$0$18643$14726298@news.sunsite.dk> References: <42f430ea$0$18643$14726298@news.sunsite.dk> Message-ID: <1123707270.425692.137940@g49g2000cwa.googlegroups.com> Don't forget Eric3 + PyQt + Qt designer? I think they are great tools. From bc at foo.com Wed Aug 31 01:30:26 2005 From: bc at foo.com (BC) Date: Wed, 31 Aug 2005 05:30:26 GMT Subject: test message Message-ID: <43154050$1@news.comindico.com.au> From adamtj at adamtj.org Sun Aug 28 18:55:00 2005 From: adamtj at adamtj.org (Adam Tomjack) Date: Sun, 28 Aug 2005 17:55:00 -0500 Subject: trictionary? In-Reply-To: <43123F7A.5030707@adamtj.org> References: <17169.16176.556417.938640@roam.psg.com> <43123F7A.5030707@adamtj.org> Message-ID: <431240C4.9050505@adamtj.org> Oops, I found a bug in my previous code. If you say bin_item = bin.setdefault(x, [1, 0]) bin_item[0] += 1 then if x wasn't in bin, it'll get initialized to [1, 0], then incremented to [2, 0] in the first loop. The code you asked about would have produced [1, 0]. Instead, you can say: bin_item = bin.setdefault(x, [0, 0]) bin_item[0] += 1 That should be equivalent. My example with the class is similarly broken. Adam Adam Tomjack wrote: > Randy, > > I'd probably use a two element list. > > Instead of using an if/else to check if an element is in your dict and > initialize it, you can use the setdefault() function. The docs for > dictionaries explain it pretty well. > > bin = {} > for whatever: > for [a, b] in foo: > x = 42 - a > bin_item = bin.setdefault(x, [1, 0]) > bin_item[0] += 1 > for x, (y, z) in bin.iteritems(): > print x, y, z > > You could also use a class like a C-style struct if you want named items: > > class BinItem: > def __init__(self, s=0, t=0): > self.s = s > self.t = t > > bin = {} > for a, b in foo: > x = 42 - a > bin_item = bin.setdefault(x, BinItem(1, 0)) > bin_item.s += 1 > > for x, item in bin.iteritems(): > print x, item.s, item.t > > > Luck in battle, > > Adam > > > Randy Bush wrote: > >>i have some code which looks kinda like >> >> bin = {} >> for whatever: >> for [a, b] in foo: >> x = 42 - a >> y = 42 - b >> if bin.has_key(x): >> bin[x] += 1 >> else: >> bin[x] = 1 >> for i, j in bin.iteritems(): >> print i, j >> >>now i want to add a second count column, kinda like >> >> bin = {} >> for whatever: >> for [a, b] in foo: >> x = 42 - a >> if bin.has_key(x): >> bin[x.b] += 1 >> else: >> bin[x.b] = 1 >> bin[x.not b] = 0 >> for x, y, z in bin.iteritems(): >> print x, y, z >> >>should the dict value become a two element list, or is >>there a cleaner way to do this? >> >>randy >> > > > > > From bronger at physik.rwth-aachen.de Tue Aug 2 07:45:41 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Tue, 02 Aug 2005 13:45:41 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> Message-ID: <87ek9c36l6.fsf@wilson.rwth-aachen.de> Hall?chen! Cliff Wells writes: > On Tue, 2005-08-02 at 09:45 +0200, Torsten Bronger wrote: > >> Yes, this is what I meant with "legacy code". C and C++ are >> actually special-purpose. They are good for controlling a >> computer but not for implementing an idea. Their current >> vitality on almost all software areas arise from the fact that >> they had been extremely successful before Java, C#, and VB came >> into play. > > Unfortunately your assertion is patently false. C and C++ are > very much general-purpose languages. This is true in the sense that you can realise an arbitrary program with them, and you can use the full power of the computer. But in my opinion the era of such programming is over. Already today but even more in the future programs of all kind are coded in the higher-level languages (including VC++), limiting C(++) to the field of system programming. Probably quibbling, but this is how I meant it. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From kay.schluehr at gmx.net Mon Aug 8 16:49:45 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Aug 2005 13:49:45 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <42f78937.926582004@news.oz.net> Message-ID: <1123534185.140211.302750@o13g2000cwo.googlegroups.com> Bengt Richter wrote: > It occurs to me that we have the PEP process for core python, but no PEP process > for the python app/lib environment. What about starting a PEEP process > (Python Environment Enhancement Proposals) modeled on PEPs, where those motivated > to formalize their pet projects or feature requests could collaborate to create > a spec to document and guide development? I already see the headline: PEEP is the answer - PSF votes for software patents. All ideas are written down by volunteers in great detail they just have to be coded. Due to intellectual property rights PSF becomes one of the richest organizations in the world. Guido van Rossum, chairman of PSF and mighty governor of California recommends an invasion into Iran: "we cannot accept that they didn't payed us for a PEEP describing a steering mechism for a nuclear power station to be written in Python. They are dangerous. They didn't have our commitment." Mr. van Rossum also commented the unfriendly takeover of the former software giant Microsoft that was immediately renamed into "Snakeoil Corp." succinctly: "They had a platform we were interested in". Yes, the Python experiment was (not just) successfull. Kay From bokr at oz.net Mon Aug 1 01:46:58 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 01 Aug 2005 05:46:58 GMT Subject: keylogger in Python References: <1122711091.982939.34080@g44g2000cwa.googlegroups.com> Message-ID: <42edb528.282470471@news.oz.net> On Sat, 30 Jul 2005 18:21:09 GMT, Dennis Lee Bieber wrote: >On 30 Jul 2005 01:11:32 -0700, "Jay" declaimed the >following in comp.lang.python: > >> ok, i thought for 2 seconds i might have created a Keylogger in python > [...] > > Doing key logging is highly OS dependent. Under AmigaOS, one >would inject a key handler at high-priority into the OS input stream >chain (a linked list of priority ordered programs that want to see >input). The logger would receive, on its input port, an OS packet with >the timestamp and key codes, could log it, and then return it to the OS >to be passed to the next program in the chain (some programs consume the >stream and don't pass it on). It was also easy to inject fake events -- >a program could inject, for example, disk-change events that other >programs would respond to. > > On Windows... I don't know for sure... Chapter 27 of >"Programming Applications for Microsoft Windows 4th Ed." might be of use >(may also be a more up-to-date version available too). It shows some >system call of AttachThreadInput() being used to link a program's input >stream (queue in the book's terminology) to another program so both >receive the same data (I think). You're logger would have to hook into >the process start-up system so that it could link to every process that >might be reading keys. I'd go to http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/abouthooks.asp?frame=true#wh_journalrecordhook for starters. Also, if you have a w32 sdk, you likely have the source for an old windows message "spy" program (in C), along with makefile and bits and pieces it needs. You could cannibalize to do specifically keyboard-oriented stuff, and differentiate alt-stuff from plain stuff etc. You can also monitor the activity of individual widgets and whatnot and copy the messages they receive to change text and resize and all manner of stuff. Try typing spyxx.hlp and see if spy++ help comes up. Or possibly run an older spy.exe for an example of interactively selecting what to monitor. Then you could write a C module to provide a python interface to those capabilities. Have fun ;-) Regards, Bengt Richter From sjmachin at lexicon.net Fri Aug 19 02:31:47 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 16:31:47 +1000 Subject: while c = f.read(1) In-Reply-To: <43057145.1837895163@news.oz.net> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <43057145.1837895163@news.oz.net> Message-ID: <43057cd3$1@news.eftel.com> Bengt Richter wrote: > On 18 Aug 2005 22:21:53 -0700, "Greg McIntyre" wrote: > > >>I have a Python snippet: >> >> f = open("blah.txt", "r") >> while True: >> c = f.read(1) >> if c == '': break # EOF >> # ... work on c >> >>Is some way to make this code more compact and simple? It's a bit >>spaghetti. >> >>This is what I would ideally like: >> >> f = open("blah.txt", "r") >> while c = f.read(1): >> # ... work on c >> > > How about (untested): > > for c in iter((lambda f=open('blah.txt', 'r'): f.read(1)), ''): > # ... work on c > :-) Bengt, did you read on to the bit where the OP wanted to do it "more nicely"? YMMV, but I think you've strayed into "pas devant les enfants" territory. (-: Cheers, John From nyamatongwe+thunder at gmail.com Mon Aug 8 06:24:07 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Mon, 08 Aug 2005 10:24:07 GMT Subject: How to determine that if a folder is empty? In-Reply-To: References: Message-ID: could ildg > so you mean that this is not platform-independent? Your existing code is platform-independent but I think for faster code you will need to write platform-dependent code. FindFirstFile is only available on Windows. Neil From noreply at gcgroup.net Wed Aug 3 11:17:51 2005 From: noreply at gcgroup.net (William Gill) Date: Wed, 03 Aug 2005 15:17:51 GMT Subject: cut & paste text between tkinter widgets Message-ID: Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in each of the widgets using a temp variable to hold the text, but I don't wnat to reinvent the wheel if there already is something that does the job. Thanks, Bill From aahz at pythoncraft.com Fri Aug 12 11:42:02 2005 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2005 08:42:02 -0700 Subject: How do these Java concepts translate to Python? References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: In article , Ben Finney wrote: > >Recently, the language came to partially support '__foo' (i.e. a name >beginning with two underscores) as a pseudo-"private". It's just a >namespace munging though; sufficiently determined users can get at it >without much effort. Recently? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From paolo_veronelli at libero.it Tue Aug 16 14:00:01 2005 From: paolo_veronelli at libero.it (Paolino) Date: Tue, 16 Aug 2005 20:00:01 +0200 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: <430229A1.5030701@libero.it> Rocco Moretti wrote: > Cameron Laird wrote: > >> Andy Smith rails against "frameworks": >> >> http://an9.org/devdev/why_frameworks_suck?sxip-homesite=&checked=1 > > > Slapdash Summary: Libraries good, frameworks bad - they are a > straightjackets and limit sharing. > > Which lead me to the question - what's the difference between a library > and a framework? A library is a set of base behaviours you have to learn separetly and deeply to inherit a mix of them and build an aspect of your program. A framework is a dumb runnable program in which you must insert your plugins as specifications to drive it towards a useful instance of it. A framework misses libraries of methods to become useful. A library is a set of loosely coupled classes useful for machines to attack a problem . A framework is a set of highly coupled interfaces useful for humans to describe a task. Ciao Paolino From mhellwig at xs4all.nl Fri Aug 5 10:44:29 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Fri, 05 Aug 2005 16:44:29 +0200 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> Message-ID: <42f37b5a$0$11075$e4fe514c@news.xs4all.nl> Kevin wrote: Well, for some strange reason I have never found that to be a problem. But that is perhaps because I'm an administrator and I want full root access, install the OS as I see fit and don't want others on the same (virtual)box. So hosting doesn't work for me I need colo or dedicated. Mostly I slap DragonFlyBSD( or NetBSD if the other doesn't run smoothly) with PostgreSQL, Mod_python/Apache and some other handy tools like tripwire. The advantage is that I am the administrator, the dis-advantage is that I am the administrator :-). Here in the Netherlands I can get 1HE colo for 95EUR/month, a reasonable price IMO. You can always rent space at different providers (for fail-over) install the machines just as your like it and rerent your own shared web hosting. Then you can have all the goodies you want and still be in the price range of comparible hosters. -- mph From twic at urchin.earth.li Mon Aug 22 18:41:34 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Mon, 22 Aug 2005 23:41:34 +0100 Subject: network programming In-Reply-To: References: Message-ID: On Mon, 22 Aug 2005, Steve Holden wrote: > Tom Anderson wrote: > >> On Sun, 21 Aug 2005, John Walton wrote: >> >>> Hello, everyone. I just began school, and they already assigned us >>> science fair. Since I'm in 8th grade, I get to do demonstrations for our >>> projects. I'm probably going to demonstrate Python's networking >>> capabilities by writing a simple instant messenger program. I only have a >>> few problems: >>> >>> 1. I know squat about Python network Programming >>> >>> 2. I know nothing about networks >>> >>> So if any of you know of a good Python Networking Tutorial or a website >>> with lots of information on networks and networking, please reply. Thanks! >> >> [snipzilla!] >> >> That's pretty much it for the network fundamentals. - but you can >> forget about that until you've mastered the basics. > > I tried to cover those basics as briefly as possible in the tutorial I > mentioned earlier. Oops! I missed that. > I'd appreciate your comments on how well I succeeded. Comment #1: it's a combination of PDF and powerpoint! :) I intended to have a look at it, but i was in a but of a rush this morning, so i'm afraid i skipped over it. Right now, i'm using a computer that isn't capable of reading either format; i'll have a look at the tutorial this evening (i hope) and get back to you. Not that my opinion is worth much. Okay, read it. Yes, that covers what we're talking about. >> RFCs can be pretty heavy going, but they are *the* definitive >> specifications, so they're worth reading. Once you're used to them, they're >> often easier to read than tutorials, i find. > > Not for newbies, though very useful for ensuring high levels of > interoperability (and fascinating when you start to realize that real > products bend the RFCs in various ways). Maybe i'm unusual, but i've *always* preferred specs to tutorials for most learning - specs are definitive, comprehensive and precise, whereas tutorials are often erroneous, patchy and waffly. Yes, they take more effort to read, but in the case of the RFCs, not that much, once you have a very basic level of knowledge - most RFCs are very clearly written. Perhaps the OP would be better off with tutorials, though - particularly for the programming side rather than the actual protocols. >> The second thing is understanding how to do network programming in python. >> There's a well-established API in C for network programming - the socket >> API - which comes from UNIX; python uses a fairly simple translation of >> this as its network API (look in the 'socket' package). The good thing >> about this is that this API is well-understood and well-documented. The bad >> thing is that it's a bit of a mess (compare and contrast to the API in Java >> if you don't believe me). There's detailed documentation for the socket >> module here: >> >> http://docs.python.org/lib/module-socket.html >> > [...] > > But then Java's a bit of a mess as a language when compared with Python, > I should say. Oh, absolutely - but the socket API is a rare breath of simplicity. > While I know the language has many adherents, it also seems to have many > programmers who only know enough to follow recipes. True, but let's save that rant for another day. > This latter feature is a symptom of the language's popularity, so I > suppose we should expect the same problems in about twenty years when > Python becomes more popular than Java. I know. I left comp.lang.java.programmer because it got overrun with clueless muppets. I don't have anything against newbies, but when a place is crawling with them to that extent, it's not fun. clp will be like that one day. i haven't decided if i'll take up Smalltalk or LISP next ... tom -- In Milan, [traffic lights] are instructions, in Rome suggestions, and in Naples Christmas decorations. -- James Dowden From sylvain.thenault at logilab.fr Tue Aug 9 05:29:05 2005 From: sylvain.thenault at logilab.fr (Sylvain Thenault) Date: Tue, 09 Aug 2005 11:29:05 +0200 Subject: .pth files Message-ID: Hi there ! I've some questions regarding pth files (which btw are undocumented in the python reference, is this intentional ?) I thought that I could use a .pth file to be able to import zope products from both INSTANCE_HOME/Products and ZOPE_HOME/lib/python/Products from outside zope: syt at musca:~$ cat cvs_work/Products.pth /home/syt/local/Zope-2.8.1-b1/Products /home/syt/local/Zope-2.8.1-b1/lib/python/Products syt at musca:~$ syt at musca:~$ python Python 2.3.5 (#2, Jun 19 2005, 13:28:00) [GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print sys.path ['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft', '/home/syt/local/lib/python2.3/site-packages', '/home/syt/local/lib/python', '/usr/lib/python23.zip', '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload', '/usr/local/lib/python2.3/site-packages', '/usr/lib/python2.3/site-packages', '/usr/lib/python2.3/site-packages/Numeric', '/usr/lib/python2.3/site-packages/PIL', '/usr/lib/python2.3/site-packages/gtk-2.0', '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python'] But as you can see, 1. the Products.pth file isn't considered at all, while for example PIL.pht in the site-packages is correctly detected 2. I'm not even sure that I can put several paths in a .pth file Is there a restriction on .pth location ? Is it possible to have multiple path in a pth file ? -- Sylvain Th?nault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From max at alcyone.com Wed Aug 10 15:20:53 2005 From: max at alcyone.com (Erik Max Francis) Date: Wed, 10 Aug 2005 12:20:53 -0700 Subject: Recommendations for CVS systems In-Reply-To: References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> Message-ID: Aahz wrote: > For anything mission-critical, I wouldn't want to rely on a free license. If it's mission critical, in the worst case scenario you can just pay for a modest license. And, as I said, it's free for use for personal use -- no license is required, it just works. They can't force upgrades, so even if they changed that policy in the future, they can't take that away from you. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis A father is a thousand schoolmasters. -- Louis Nizer From sjmachin at lexicon.net Fri Aug 19 18:37:08 2005 From: sjmachin at lexicon.net (John Machin) Date: Sat, 20 Aug 2005 08:37:08 +1000 Subject: while c = f.read(1) In-Reply-To: <1124482681.402831.294550@z14g2000cwz.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124482681.402831.294550@z14g2000cwz.googlegroups.com> Message-ID: <43065f12$1@news.eftel.com> sp1d3rx at gmail.com wrote: > Alright, everyone seems to have gone off on a tangent here, so I'll try > to stick to your code... > """ > This is what I would ideally like: > > > f = open("blah.txt", "r") > while c = f.read(1): > # ... work on c > > > But I get a syntax error. > > > while c = f.read(1): > ^ > SyntaxError: invalid syntax > > """ > > That's because you are using an assignment operator instead of a > comparison operator. It should have been written like this: > > while c == f.read(1): > > that would be written correctly, though I don't think that is your > intention. > Try this novel implementation, since nobody has suggested it yet. > ----------------- > import mmap > > f = open("blah.txt", 'r+') #opens file for read/write > c = mmap.mmap(f.fileno(),0) #maps the file to be used as memory map... > > while c.tell() < c.size(): > print c.read_byte() > --------------- > That accomplishes the same thing. > Dear Sir or Madam, I refer you to your recent post -- the one that started with "d'oh". Regards, John From eric_brunel at despammed.com Fri Aug 26 06:27:35 2005 From: eric_brunel at despammed.com (Eric Brunel) Date: Fri, 26 Aug 2005 12:27:35 +0200 Subject: file access dialog References: <430ec9b1.1708219820@news.xs4all.nl> Message-ID: On Fri, 26 Aug 2005 07:52:06 GMT, Wouter van Ooijen (www.voti.nl) wrote: > I have a tool in Python to which I want to add a small GUI. The tools > currently runs everywhere PySerial is supported. I need a file-access > dialog. What is the preffered way to to this? Is there a > platform-independent file-access dialog available, or should I use the > windows native version when running on windows (and how do I do that)? Tkinter has a file acces dialog available with the same API on all platforms. It is also mapped to the standard dialog on Windows. Since Tkinter is certainly installed by default with Python, if a file dialog is everything you need, you probably don't have to look further. To use the dialog, just do: from Tkinter import Tk from tkFileDialog import askopenfilename ## Tk needs a main window to work, so create one and hide it root = Tk() root.withdraw() ## Ask the file name fileName = askopenfilename(filetypes=[('Python files', '*.py'), ('All files', '*')]) if fileName: print 'open', fileName else: print 'cancelled' ## Over root.destroy() HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" From renting at astron.nl Mon Aug 29 03:51:41 2005 From: renting at astron.nl (Adriaan Renting) Date: Mon, 29 Aug 2005 09:51:41 +0200 Subject: OpenSource documentation problems Message-ID: Marked -1 Flamebait, but I'll respond anyway. I've read the documents he refers to, and although I agree that the Python docs aren't perfect, I do not agree with him on which points. I for example do think it's important to incude info on which versions of the language support a feature. He seems to think the GNU man pages are nice, but I find them very awkward as they have no hierarchical organization, and most miss examples. I do agree that a lot of OSS projects seem to lack somewhat in the documentation department, compared to a lot of commercial software. I would give the man page of gcc as an example, it's just one 6600 line blurb. The other part where a lot of OSS seems to be lacking is user interface design. I think the cause is that the OSS movement is almost solely comprised of programmers, while in a commercial environment there will be a lot of documentation writers and interface designers (and marketing, etc...) I know I write my own documentation for the code I create, but I know I'll not do as good a job as a separate good doc writer would. In general I think the programmers should not write the documentation, and should not be the sole designers of the UI either. The good commercial docs are better because there it is understood how important this is. I myself have always liked the Borland documentation a lot. The big question is: how to attract more doc writers to the OSS movement? Adriaan Renting. From u.hobelmann at web.de Fri Aug 26 04:53:53 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Fri, 26 Aug 2005 10:53:53 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <86acj5mpty.fsf@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> Message-ID: <3n83l2F9ru8U1@individual.net> Mike Meyer wrote: > "Mike Schilling" writes: >> Another advantage is that evewry internet-enabled computer today already >> comes with an HTML renderer (AKA browser) > > No, they don't. Minimalist Unix distributions don't include a browser > by default. I know the BSD's don't, and suspect that gentoo Linux > doesn't. > > HTML is designed to degrade gracefully (never mind that most web > authors and many browser developers don't seem to comprehend this), so > you don't really need a "subset" html to get the safety features you > want. All you need to do is disable the appropriate features in the > HTML renderer in your news and mail readers. JavaScript, Java, and any > form of object embedding. Oh yeah, and frames. That's a good idea. I have parts of it disabled. The advantage of disabling them all is that you don't have to visit all those crappy modern websites, because they don't work. What I hate about most are the sites that don't even *mention* that they want cookies. Often I have to wonder, reinput input fields etc. and then after ten minutes trying *bang*, the idea, maybe to allow cookies for that site. Some people really don't have a clue, but kludgy "web standards technologies" (by the oh-so-omnisavant W3C) kind of force it. -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From tkpmep at hotmail.com Mon Aug 29 11:12:26 2005 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: 29 Aug 2005 08:12:26 -0700 Subject: Robust statistics and optimmization from Python Message-ID: <1125328346.738915.102990@z14g2000cwz.googlegroups.com> I use Python to generate a huge amount of data in a .csv file which I then process using Excel. In particular, I use Excel's solver to solve a number of non-linear equation, and then regress the results of hundreds of calls to Solver against a set of known values, enabling me to calibrate my model. This is a pain: i'd much rather perform all the computations in Python and improve on Excels' regression as well. Questions: 1. Is there a way to perform (or make a call to) a non-linear optimization from Python? 2. Do Python packages for robust statistics (robust regression in particular) exist. If so, which one would you recommend/ Thanks, as always, in advance for the guidance Thomas Philips From rtconner at gmail.com Mon Aug 1 17:36:07 2005 From: rtconner at gmail.com (Rob Conner) Date: 1 Aug 2005 14:36:07 -0700 Subject: inheriting from datetime In-Reply-To: <11et3tk70qbnh73@corp.supernews.com> References: <1122929471.966054.146010@g44g2000cwa.googlegroups.com> <11et3tk70qbnh73@corp.supernews.com> Message-ID: <1122932167.604338.160170@f14g2000cwb.googlegroups.com> gah, yeah that was strange. but i got it now. thanks. > side question: what is the point of accepting invalid dates? thats a long story. but it would be nice to have invalid dates at least just stored. so i want to try to put a class together that does it. From deets at web.de Wed Aug 24 07:16:35 2005 From: deets at web.de (Diez B. Roggisch) Date: 24 Aug 2005 04:16:35 -0700 Subject: Warning when doubly linked list is defined gloablly In-Reply-To: <1124881914.018491.315800@g14g2000cwa.googlegroups.com> References: <1124881914.018491.315800@g14g2000cwa.googlegroups.com> Message-ID: <1124882195.673699.25930@g47g2000cwa.googlegroups.com> chand wrote: > In my api.py file 'g_opt_list' is defined globally > g_opt_list =[[],[],[],[],[],[],[]] > > I am using this global list in the fucntion > > def function (): > gloabl g_opt_list This is obviously wrong and not the code you wrote, global being written horribly wrong - which should teach you an important lesson: post actual code that exposes the problem, not something you think that is working. Then we might be able to help you. Diez From bokr at oz.net Mon Aug 1 08:38:00 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 01 Aug 2005 12:38:00 GMT Subject: How override ALL function calls? (Is there a "function call function"?) References: <1122833096.778839.209730@g14g2000cwa.googlegroups.com> Message-ID: <42ee1777.307637509@news.oz.net> On 31 Jul 2005 12:01:36 -0700, "seberino at spawar.navy.mil" wrote: >I'm trying run a homegrown profiler on some Python code. > >Rather than apply profiler wrapper to ALL functions by hand.... > >Is there a low level Python function I can override to modify > >how ALL functions are called? > You may want to look at >>> import sys >>> help(sys.settrace) Help on built-in function settrace in module sys: settrace(...) settrace(function) Set the global debug tracing function. It will be called on each function call. See the debugger chapter in the library manual. Regards, Bengt Richter From nicolasp at aaton.com Thu Aug 4 10:39:21 2005 From: nicolasp at aaton.com (nico) Date: Thu, 04 Aug 2005 16:39:21 +0200 Subject: Embedded python In-Reply-To: References: <42f20657$0$27904$626a14ce@news.free.fr> Message-ID: <42f2267a$0$6421$626a14ce@news.free.fr> Chris Johns a ?crit : > nico wrote: > >> >> Does anyone have embedded a python interpreter on a proprietary >> hardware ? > > > Yes, http://www.cybertec.com.au/microcore.htm > >> I have a home made hardware running a home made OS. C is used as >> programming >> language. I'd like to add a python interpreter to my system. >> Any guidelines ? > > > Maybe the RTEMS instructions will help: > > http://www.rtems.org/phpwiki/index.php/Python > Thanks a lot. I'll have a look immediatly. Nicolas From pink at odahoda.de Wed Aug 3 04:02:00 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 03 Aug 2005 10:02:00 +0200 Subject: Art of Unit Testing References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> Message-ID: Christoph Zwerschke wrote: > Benjamin Niemann wrote: >> Some (many?) people don't like the unittest module, because it is not >> very pythonic - nothing to wonder as it has its root in the Java world. >> That's probably one of the reasons why there are other (more pythonic) >> unittesting frameworks for Python out there. > > So I think it would have been better that "unittest" had been named > "PUnit" to make clear that it is a JUnit port and to allow a more > pythonic testing framework to be added to the Python's standard lib. It was called PyUnit before it was integrated into the stdlib. Dunno why it was renamed... -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From steve at myplace.com Fri Aug 12 17:57:05 2005 From: steve at myplace.com (Steve M) Date: Fri, 12 Aug 2005 16:57:05 -0500 Subject: Printing to printer References: <42FCADBD.4080801@syscononline.com> Message-ID: Larry Bates wrote: > I adapted some code from David Boddie into a Python class to write > directly to Linux print queues. I have used it in one project and > it worked just fine. I've attached a copy for your use. You are > free to use it as you wish, with no guarantees or warranties. > > Hope it helps. > > Larry Bates > > Steve M wrote: >> Hello, >> >> I'm having problems sending information from a python >> script to a printer. I was wondering if someone might send me >> in the right direction. I wasn't able to find much by Google >> >> TIA >> Steve Thank you, I'll give it a try. Steve From ed at leafe.com Tue Aug 2 09:37:17 2005 From: ed at leafe.com (Ed Leafe) Date: Tue, 2 Aug 2005 09:37:17 -0400 Subject: Dabo in 30 seconds? In-Reply-To: References: Message-ID: <200508020937.17651.ed@leafe.com> On Tuesday 02 August 2005 09:15, Sion Arrowsmith wrote: > Of course, going back to Dabo there is the question of whether it has > such a thing as a non-developer end-user. Yes and no. Developers will be the primary users of Dabo, of course, but they will most likely use it to create apps that non-developers will then use, so packaging/distribution certainly comes into play at some point. -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com From sybrenUSE at YOURthirdtower.com.imagination Fri Aug 26 05:53:14 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Fri, 26 Aug 2005 11:53:14 +0200 Subject: Should I move to Amsterdam? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> <430ec8be.1707977111@news.xs4all.nl> Message-ID: Wouter van Ooijen (www.voti.nl) enlightened us with: >>True. Unless you have two proper locks. In that case your bike will >>last a very long time. > > Nope. You will probably retrieve your two locks from the fencing you > attached them to (if you did!), with your bike gone. That's not my experience, but hey, who am I? I've just lived here for eight years. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From grante at visi.com Thu Aug 25 10:12:51 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 25 Aug 2005 14:12:51 -0000 Subject: Doubt C and Python References: <11gp046ko61rsa5@corp.supernews.com> <1124961693.820616.13530@f14g2000cwb.googlegroups.com> Message-ID: <11grkf31850oe70@corp.supernews.com> On 2005-08-25, Ben Sizer wrote: > Grant Edwards wrote: >> On 2005-08-23, praba kar wrote: >> > What why it is more efficient. Kindly let me >> > know with some details. >> >> Have you read _any_ of the thread? A number of people have >> already explained in detail why programming in Pything is more >> efficient. Please read the responses you've already gotten. > > Grant, > > Going by the Google Groups timestamps that I see, there's a good chance > that none of the other responses were visible to the OP when the above > followup was posted. You're probably right. Google groups may be "The End of "Usenet as We Know It". -- Grant Edwards grante Yow! Are we on STRIKE yet? at visi.com From dieter at handshake.de Wed Aug 24 15:11:18 2005 From: dieter at handshake.de (Dieter Maurer) Date: 24 Aug 2005 21:11:18 +0200 Subject: Revised PEP 349: Allow str() to return unicode strings References: Message-ID: Neil Schemenauer writes on Mon, 22 Aug 2005 15:31:42 -0600: > ... > Some code may require that str() returns a str instance. In the > standard library, only one such case has been found so far. The > function email.header_decode() requires a str instance and the > email.Header.decode_header() function tries to ensure this by > calling str() on its argument. The code was fixed by changing > the line "header = str(header)" to: > > if isinstance(header, unicode): > header = header.encode('ascii') Note, that this is not equivalent to the old "str(header)": "str(header)" used Python's "default encoding" while the new code uses 'ascii'. The new code might be more correct than the old one has been. > ... > Alternative Solutions > > A new built-in function could be added instead of changing str(). > Doing so would introduce virtually no backwards compatibility > problems. However, since the compatibility problems are expected to > rare, changing str() seems preferable to adding a new built-in. Can we get a new builtin with the exact same behaviour as the current "str" which can be used when we do require an "str" (and cannot use a "unicode"). Dieter From sjmachin at lexicon.net Mon Aug 8 18:29:35 2005 From: sjmachin at lexicon.net (John Machin) Date: Tue, 09 Aug 2005 08:29:35 +1000 Subject: Splitting a string into groups of three characters In-Reply-To: References: <1123466304.304964.211380@g49g2000cwa.googlegroups.com> Message-ID: <42f7dcd0@news.eftel.com> William Park wrote: > lemon97 at gmail.com wrote: > >>Hi, >> >>Is there a function that split a string into groups, containing an "x" >>amount of characters? >> >>Ex. >>TheFunction("Hello World",3) >> >>Returns: >> >>['Hell','o W','orl','d'] >> >> >>Any reply would be truly appreciated. > > > Look into 're' module. Essentially, split using '...', but return the > separator as well. Then, remove empty items. In Bash shell, you would This would have to be a candidate for arcane side-effect of the month. Not in front of the children, please. > do > a="Hello World" > set -- "${a|?...}" # extract '...' separators > pp_collapse # remove null items > printf '{%s}\n' "${@}" > > Translating to Python is left as homework. Given that the OP was struggling to write a simple loop in Python, giving him an answer in hieroglypghics and suggesting he translate it into Python could be described as unhelpful. From nir1408 at gmail.com Thu Aug 11 08:19:31 2005 From: nir1408 at gmail.com (nir1408 at gmail.com) Date: 11 Aug 2005 05:19:31 -0700 Subject: new python debugger References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> <1123740657.066728.39080@g43g2000cwa.googlegroups.com> Message-ID: <1123762771.062491.235800@g14g2000cwa.googlegroups.com> Thanks for the valuable input. I will look into it. In the mean time, until I implement your suggestions, here are some workarounds for the problems you experienced. 1. In the "Open Source" dialog, instead of typing the full path of the script you wish to load, try typing just its name (e.g. 'foo.py' instead of 'c:\somepath\foo.py') 2. Until I add a GUI dialog for that purpose, use the console to enable and disable groups of breakpoints. type 'bl' to list the breakpoints, and then type for example 'bd 2 5 8' to disable breakpoints 2, 5, and 8, or any other combination. 'be' is used to enable breakpoints and 'bc' to clear them. You can use help to read further on these commands. BTW, the console allows setting conditional breakpoints, too. 3. Until I add a GUI command for jumping, you can use the console to jump to a different line: type for example 'jump 33' to jump to line 33. Jumps are constrained to the limits of the current frame of the thread. As for the letters 'C', 'L', and 'R' you have seen, they represent the last debugger event for that thread, where: 'C' - means a Call to a function. 'L' - means about to execute this line. 'R' - means, about to return from this function 'E' - means, an exception was raised (use the analyze mode to examine it) '*' - means, this thread is not broken yet (it is probably doing some c++ code...) you can read about it with 'help list' from the console Again, thanks for the input, Nir From tjreedy at udel.edu Mon Aug 1 10:35:15 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 1 Aug 2005 10:35:15 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com><7x3bpuxtwa.fsf@ruckus.brouhaha.com> <200508010817.29171.ed@leafe.com> Message-ID: This sort of intentional obtuseness grates on me too. Just to let you know, this discussion has convinced me to try Dabo, which I knew nothing about before. So your participation has not been useless. In fact, I think I will start with your two-liner below so I can see what I get by default and then build from there. Terry J. Reedy "Ed Leafe" wrote in message news:200508010817.29171.ed at leafe.com... On Sunday 31 July 2005 22:39, Paul Rubin wrote: > > import dabo > > app = dabo.dApp() > > dApp.start() > > > > Sorry, I couldn't do it in 5. ;-) Oh, and that includes a full menu, > > too. > > I get an ImportError exception when I try that. Any suggestions? Note > that I don't get that exception from Tkinter. > bash-3.00$ python > Python 2.3.4 (#1, Oct 26 2004, 16:42:40) > [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import dabo > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named dabo > >>> import Tkinter > >>> Oh, c'mon now Paul, now you're trolling. You know exactly what the problem is, and try to make it look like a bug. Fine: you don't want to use anything that doesn't come standard with Python. You've made your point. We get it. There is no need to repeat yourself constantly. The only point of my post was that for those without your aversion to installing useful tools, Dabo provides a ton of functionality. Also, as my partner Paul McNett pointed out, I could have done it in *two* lines: import dabo dabo.dApp().start() ;-) -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list From bronger at physik.rwth-aachen.de Fri Aug 5 03:06:01 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Fri, 05 Aug 2005 09:06:01 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <87wtn245qo.fsf@wilson.rwth-aachen.de> <86slxpyxp2.fsf@bhuda.mired.org> Message-ID: <873bporhgm.fsf@wilson.rwth-aachen.de> Hall?chen! Mike Meyer writes: > Torsten Bronger writes: > >> Mike Meyer writes: >> >>> Torsten Bronger writes: >>> >>>> Mike Meyer writes: >>>> >>>>> Torsten Bronger writes: >>>>> >>>>> [...] You didn't answer the question about how you define >>>>> agile project. Please do so if you expect a comment on this. >>>> >>>> Projects with a high Sourceforge activity index. >>> >>> That doesn't seem to match the common defintion of "agile" when >>> it comes to programming. Then again, you have a habit of using >>> words to mean whatever you want, without much reference to how >>> they're used by the rest of the industry. >> >> I'm not part of the industry. > > That's no excuse for not learning the terminology, or at least > avoiding using phrases which already have a common meaning. Granted, I didn't pay enough attention to the fact that for industry people "agile" has a much stronger connotation. Nevertheless, it's an ordinary English word, too, so that's no excuse for not trying to understand what I *mean*. Since nobody has any chance to see which programming strategy the projects uses, you must deliberatly misunderstand me for assuming that I meant "agile programming". > [...] > > [...] The difference is ther are a lot of other choices, so it > gets chosen less often. But I note that at least one of the 155 > projects on SourceForge that list FORTRAN as a language is a GUI > application for Windows. I see no difference to special-purpose language then. > [...] > > [...] Just like some C/C++ applications are legacy code, and some > aren't. Which contradicts your earlier assertion that C/C++ > applications were all legacy code. Reference? > [...] > > Earlier, you said you wanted a popular language because they get > cool features faster. You hold up two proprietary VC++ (which is > just an development environment) and VB as "popular" languages. If > you've been watching software development long enough, you'd > realize that "cool things" usually come from open source projects > first. That's right (or rather, I believe you). I just want to use a popular langauge amongst the ones that have free success ("free" in the sense of Free Software). I used VB and VC++ for my assertion -- that you don't share -- that GUI abilities are the only way to get much popularity, which is in my opinion necessary for "cool things". If you say it's not sufficient, okay. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From alanmk at hotmail.com Sat Aug 20 13:46:00 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Sat, 20 Aug 2005 18:46:00 +0100 Subject: global interpreter lock In-Reply-To: <86fyt5b93o.fsf@bhuda.mired.org> References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> Message-ID: [Bryan Olson] >>I don't see much point in trying to convince programmers that >>they don't really want concurrent threads. They really do. Some >>don't know how to use them, but that's largely because they >>haven't had them. I doubt a language for thread-phobes has much >>of a future. [Mike Meyer] > The real problem is that the concurrency models available in currently > popular languages are still at the "goto" stage of language > development. Better models exist, have existed for decades, and are > available in a variety of languages. I think that having a concurrency mechanism that doesn't use goto will require a fundamental redesign of the underlying execution hardware, i.e. the CPU. All modern CPUs allow flow control through the use of machine-code/assembly instructions which branch, either conditionally or unconditionally, to either a relative or absolute memory address, i.e. a GOTO. Modern languages wrap this goto nicely using constructs such as generators, coroutines or continuations, which allow preservation and restoration of the execution context, e.g. through closures, evaluation stacks, etc. But underneath the hood, they're just gotos. And I have no problem with that. To really have parallel execution with clean modularity requires a hardware redesign at the CPU level, where code units, executing in parallel, are fed a series of data/work-units. When they finish processing an individual unit, it gets passed (physically, at a hardware level) to another code unit, executing in parallel on another execution unit/CPU. To achieve multi-stage processing of data would require breaking up the processing into a pipeline of modular operations, which communicate through dedicated hardware channels. I don't think I've described it very clearly above, but you can read a good high-level overview of a likely model from the 1980's, the Transputer, here http://en.wikipedia.org/wiki/Transputer Transputers never took off, for a variety of technical and commercial reasons, even though there was full high-level programming language support in the form of Occam: I think it was just too brain-bending for most programmers at the time. (I personally *almost* took on the task of developing a debugger for transputer arrays for my undergrad thesis in 1988, but when I realised the complexity of the problem, I picked a hypertext project instead ;-) http://en.wikipedia.org/wiki/Occam_programming_language IMHO, python generators (which BTW are implemented with a JVM goto instruction in jython 2.2) are a nice programming model that fits neatly with this hardware model. Although not today. -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From noreply at python.org Fri Aug 5 01:53:02 2005 From: noreply at python.org (MAILER-DAEMON) Date: Fri, 5 Aug 2005 08:53:02 +0300 Subject: Mail System Error - Returned Mail Message-ID: <20050805055347.272BC1E407B@bag.python.org> The original message was received at Fri, 5 Aug 2005 08:53:02 +0300 from python.org [182.250.185.89] ----- The following addresses had permanent fatal errors ----- python-list at python.org From paschott at no.yahoo.spamm.com Tue Aug 23 18:17:01 2005 From: paschott at no.yahoo.spamm.com (Peter A. Schott) Date: Tue, 23 Aug 2005 22:17:01 GMT Subject: High Level FTP library References: <7NGOe.6737$Nb2.115820@news1.nokia.com> Message-ID: I've used the ftputil package before with some success. It's not bad, but it really depends on what you're trying to do. If you write a couple of custom functions to get you started, you should be able to put those in a module and re-use as needed. I know that I had to code my own stuff to handle some non-standard FTP flavors for some of our partners. Knowing how to work ftplib was pretty helpful at that point as ftputil didn't support those versions of FTP. It still did a great job for regular stuff, but not for that. Hope that helps some. -Pete "Paulo Pinto" wrote: > Hello, > > Is there any Python library similar to NET::FTP from Perl? > ftplib seems too lowlevel. > > I already found a few, but would like to get one that is > endorsed by the community. > > Thanks, > Paulo > From steve at holdenweb.com Tue Aug 23 13:05:46 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 23 Aug 2005 13:05:46 -0400 Subject: while c = f.read(1) In-Reply-To: <1ihmg15sb9fel3idlp6ljpqfnoua2eoo27@4ax.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> <1ihmg15sb9fel3idlp6ljpqfnoua2eoo27@4ax.com> Message-ID: Dennis Lee Bieber wrote: > On Tue, 23 Aug 2005 12:15:36 +0200, Magnus Lycka > declaimed the following in comp.lang.python: > > >>If you want the behaviour of Python to change, you should >>write a PEP. It always felt natural to me to interpret empty >>as false, but I could be wrong. It's strange that this flaw >>managed to go unnoticed for so long though... >> > > Seemed to fit my world view too... So many other languages used the > "non-zero" is True, that it made sense to take "non-empty" is True -- > and if "non-empty" is true, then empty must be False. > > Of course, there is always VMS -- where status codes were checked in > LSB... odd number => true, even number => false ... and most *nix shells, where a return code of zero implies "success". Of course, this still leaves wiggle room to discuss whether success is True or False. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bignose+hates-spam at benfinney.id.au Fri Aug 12 01:23:07 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 12 Aug 2005 15:23:07 +1000 (EST) Subject: How do these Java concepts translate to Python? References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> Message-ID: Ray wrote: > 1. Where are the access specifiers? (public, protected, private) No such thing (or, if you like, everything is "private" by default). By convention, "please don't access this name externally" is indicated by using the name '_foo' instead of 'foo'; similar to a "protected". Nothing in the language enforces this. Recently, the language came to partially support '__foo' (i.e. a name beginning with two underscores) as a pseudo-"private". It's just a namespace munging though; sufficiently determined users can get at it without much effort. The attitude engendering this simplicity is "we're all consenting adults here". If you have users of your modules and classes who won't respect access restriction *conventions*, they're bad programmers anyway, so there's not much the language can do to stop that. > 2. How does Python know whether a class is new style or old style? > E.g.: > > class A: > pass New-style classes are descended from class 'object'. Old-style classes aren't. Thus, your example above is an old-style class, as are any classes that inherit only from that class. To create a new-style class with no particular base functionality, inherit from 'object' directly: class A(object): pass > 3. In Java we have static (class) method and instance members. But > this difference seems to blur in Python. Class attributes and instance attributes are distinguished by the fact that instance attributes are created when the instance is created (typically, assigned within the __init__() method): class A(object): foo = 'Fudge' def __init__(self, bar): self.bar = bar wibble = A('Wibble') print wibble.foo, wibble.bar # Fudge Wibble bobble = A('Bobble') print bobble.foo, bobble.bar # Fudge Bobble Instances of the 'A' class all share a 'foo' attribute, and each instance has its own 'bar' attribute created separately (in the __init__() method). -- \ "Unix is an operating system, OS/2 is half an operating system, | `\ Windows is a shell, and DOS is a boot partition virus." -- | _o__) Peter H. Coffin | Ben Finney From mwm at mired.org Sat Aug 20 22:30:43 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 20 Aug 2005 22:30:43 -0400 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> Message-ID: <868xyw9g30.fsf@bhuda.mired.org> Bryan Olson writes: > Mike Meyer wrote: > > The real problem is that the concurrency models available in currently > > popular languages are still at the "goto" stage of language > > development. Better models exist, have existed for decades, and are > > available in a variety of languages. > That's not "the real problem"; it's a different and arguable > problem. The GIL isn't even part of Python's threading model; > it's part of the implementation. Depends on what point you consider the problem. > > It's not that these languages are for "thread-phobes", either. They > > don't lose power any more than Python looses power by not having a > > goto. They languages haven't taken off for reasons unrelated to the > > threading model(*). > > The rule I follow in choosing my tools is "Use the least complex tool > > that will get the job done." > Even if a more complex tool could do the job better? In that case, the simpler model isn't necessarily getting the job done. I purposely didn't refine the word "job" just so this would be the case. > Now I've gotten off-topic. Threads are winning, and the industry > is going to multiple processors even for PC-class machines. > Might as well learn to use that power. I own too many orphans to ever confuse popularity with technical superiority. I've learned how to use threads, and done some non-trivial thread proramming, and hope to never repeat that experience. It was the second most difficult programming task I've ever attempted(*). As I said above, the real problem isn't threads per se, it's that the model for programming them in popular languages is still primitive. So far, to achieve the non-repitition goal, I've used async I/O, restricted my use of real threads in popular languages to trivial cases, and started using servers so someone else gets tod eal with these issues. If I ever find myself having to have non-trivial threads again, I'll check the state of the threading models in other languages, and make a serious push for implementing parts of the program in a less popular language with a less primitive threading model. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From dd55 at cornell.edu Thu Aug 11 15:43:23 2005 From: dd55 at cornell.edu (Darren Dale) Date: Thu, 11 Aug 2005 15:43:23 -0400 Subject: command line reports References: <67Cdnd00Bo62PWbfRVn-1w@powergate.ca> Message-ID: Peter Hansen wrote: > Darren Dale wrote: >> Is there a module somewhere that intelligently deals with reports to the >> command line? I would like to report the progress of some pretty lengthy >> simulations, and currently I have the new reports written on a new line >> rather rather than overwriting the previous report. > > You mean you want sys.stdout.write(report + '\r') instead of "print > report" ? > > It's not really clear what you want. What's a "report" to you? > > -Peter I am printing something like trial 1 of 100 trial 2 of 100 ... so I get 100 lines by the time the code is finished. I would like to replace the previous report with the current one, so I only use one line by the time the code is finished. I was also hoping that there was a set of tools out there for spinners, meters, etc... From steve at holdenweb.com Fri Aug 26 22:05:30 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Aug 2005 22:05:30 -0400 Subject: Embedding Python in other programs In-Reply-To: <312cfe2b050826084036db598f@mail.gmail.com> References: <312cfe2b050826084036db598f@mail.gmail.com> Message-ID: Gregory Pi?ero wrote: > How do I get it into VB6? Now that's an answer that would save my life > many times over. > Use IronPython? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mchermside at ingdirect.com Wed Aug 31 10:15:38 2005 From: mchermside at ingdirect.com (Chermside, Michael) Date: Wed, 31 Aug 2005 10:15:38 -0400 Subject: Python doc problems example: gzip module Message-ID: <0CFFADBB825C6249A26FDF11C1772AE10132A2BC@ingdexj1.ingdirect.com> Xah Lee writes: [...] > Fuck the Python programing[sic] morons. [...] Peter Maas replies: > Here's the example: [...] > Have a nice ... eh fucking day :) Thank you Peter... you're a hero. THIS is why c.l.py is such a helpful and civil place to be. -- Michael Chermside ***************************************************************************** This email may contain confidential or privileged information. If you believe you have received the message in error, please notify the sender and delete the message without copying or disclosing it. ***************************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From u.hobelmann at web.de Sun Aug 28 08:18:26 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Sun, 28 Aug 2005 14:18:26 +0200 Subject: Writing portable applications (Was: Jargons of Info Tech industry) In-Reply-To: <86acj3ut2e.fsf_-_@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> Message-ID: <3ndociF11gd3U1@individual.net> Mike Meyer wrote: >> I'd rather develop a native client for the machine that people >> actually WANT to use, instead of forcing them to use that >> little-fiddly web browser on a teeny tiny display. > > You missed the point: How are you going to provide native clients for > platforms you've never heard of? Who says I have to? With open protocols, everybody can. I know many platforms that STILL don't have a browser that would work with most websites out there. They all have NNTP, SMTP and POP clients. Text-mode, GUI-mode, your choice. >> And again: connections might be slow, a compact protocol is better >> than loading the whole UI every time. And while Ajax might work, >> despite the UI being maybe too big for the little browser window, and >> even if it works, it's still probably more work than a simple, native >> UI. First of all it needs to load all the JS on first load, secondly >> sometimes for a flexible UI you'd have to replace huge parts of the >> page with something else. Native UIs are more up to the task. > > I'm not arguing that native UI's aren't better. I'm arguing that web > applications provide more portability - which is important for some > applications and some developers. Like Java provides more portability. Unless you ran NetBSD in 2003 (there was no Java back then that worked for me), hm, IRIX?, Plan9, BeOS the list goes on... LOTS of platforms don't have the manpower to develop a client that renders all of the huge bloated wagonload of W3C tech that was only designed for *markup* from the beginning. >>> I started writing web apps when I was doing internal tools development >>> for a software development company that had 90+ different platform >>> types installed inhouse. It was a *godsend*. By deploying one >> If that's 90+ GUI platforms, then I agree. > > Why do you care if they are GUI or not? If you need to provide the > application for them, you need to provide the application for > them. Them not being GUI just means you can't try and use a standard > GUI library. It also means you have to know what you're doing when you > write HTML so that it works properly in a CLUI. But your native app > would have to have a CLUI anyway. Ok, UI then ;) I don't care what UIs people like and use. >> I just wonder who wrote fully standards compliant web browsers for >> those 90 platforms. > > Nobody. I doubt there's a fully standards compliant web browser Nobody, huh? Then how could you run just ANY web application on those platforms? > available for *any* platform, much less any non-trivial collection of > them. You write portable web applications to the standards, and design > them to degrade gracefully. Then you go back and work around any new Oh right, they degrade gracefully. So without Javascript or cookies (the former is often not implemented) you get a HTML page with an error notice -- if you're lucky. A server AND client for a simple protocol designed for its task (i.e. not FTP for instance) can be implemented in much less work than even designing even part of a web application backend that does that kind of stuff. Plus you're not bound by HTTP request structure, you can use publish/subscribe or whatever communication style you want for efficiency. > bugs you've uncovered in the most popular browsers - which > historically are among the *worst* at following standards. > >> If you have one Windows GUI (maybe C#), one Mac GUI (Cocoa), one Gtk >> GUI for X, you're done. > > You think you're done. A lot of developers think you can stop with the > first one or two. You're all right for some applications. For others, > you're not. Personally, I like applications that run on all the > platforms I use - and your set doesn't cover all three of those > systems. Ok, I'd be interested to hear what those are. VMS, RiscOS, Mac OS 9...? >>> well-written app, I could make everyone happy, without having to do >>> versions for the Mac, Windows, DOS (this was a while ago), getting it >>> to compile on umpteen different Unix version, as well as making it >>> work on proprietary workstation OS's. >> Well, stick to POSIX and X APIs and your stuff should run fine on >> pretty much all Unices. > > You know, the same kind of advice applies to writing portable web > apps. Except when you do it with HTML, "portability" means damn near > any programmable device with a network interface, not some relatively > small fraction of all deployed platforms. Only that even years ago lots of even small platforms would run X, but even today MANY platforms don't run a browser with XHTML/HTML4+JS+CSS (well, okay, the CSS isn't that important). >> I never understood those people who write all kinds of weird ifdefs >> to on all Unices. Maybe that was before my time, during the >> Unix wars, before POSIX. > > There were standards before POSIX. They didn't cover everything people > wanted to do, or didn't do them as fast as the OS vendor wanted. So > Unix vendors added their own proprietary extensions, which software > vendors had to use to get the best performance out of their > applications, which they had to do if they wanted people to buy/use > them. Performance? Hm, like epoll/kqueue vs select? Can't think of examples here, but I pretty much only know BSD/POSIX. > That's still going on - people are adding new functionality that isn't > covered by POSIX to Unix systems all the time, or they are adding > alternatives that are better/faster than the POSIX version, and there > are lots of things that applications want to do that simply aren't > covered by POSIX. And not all implementations are created equal. Some > platforms malloc's provide - to be polite - less than optimal > performance under conditions real applications encounter, so those > applications conditionally use different malloc implementations. The Well, OF COURSE malloc is ONE general purpose function that HAS to carry some overhead. I routinely use my frontend(s) for it, to cluster allocations locally (for caching and alloc performance). Matter of a 100 LOC usually. No problem at all. If a system's scheduler, or select implementation sucks, though, I'd complain to the vendor or simply abandon the platform for another. Competition is good :) > same thing applies to threads, except such code typically includes a > third option of not using threads at all. And so on. Well, who doesn't do threads after several years of POSIX IMHO can't be taken seriously. Ok, the BSDs didn't until recently, but those are volunteer projects. > And we haven't even started talking about the build process... If the libraries are installed, just build and link it (if you use standard C, POSIX + 3rd party libs that do the same). If not, then tough luck -- it couldn't even run in theory then. > Basically, deciding to write to POSIX is a decision to trade away > performance on/to some platforms for portability to more > platforms. It's the same decision as deciding to write a web app, > except the tradeoffs are different. Each of the three solutions has a > different set of costs and benefits, and the correct choice will > depend on your application. I'd like to hear about those performance problems... If someone can't make the standard calls efficient, they should leave the business and give their customers Linux or BSD. >> And if it's not Unix, what's a prop. workstation OS? > > They've mostly died out since then. At the time, there were things > like Domain and VMS. Never heard of Domain, but VMS is called NT/2000/XP/2003/Vista now (with some enhancements and a new GUI). ;) >>> Of course, considering the state of most of the HTML on the web, I >>> have *no* idea why most of them are doing this. >> Yep. Maybe it would be best to reengineer the whole thing as ONE UI >> spec+action language, incompatible with the current mess, compact, so >> it can be implemented with minimum fuss. And most of all, I wouldn't >> use a MARKUP language, as a real application is not text-based (at >> least not as characteristic #1). > > You mean most of the applications I run aren't real applications? > Right now, my desktop has exactly two GUI applications open on it - a > mixer and gkrellm. Everything else is characeter based. Hell, even my > window manager is character based. I meant not using text elements. Of course it includes text, in your case predominantly. But even most curses clients have other elements sometimes, like links. A standard spec language could cater easily for text clients, but a text language like HTML has a harder time to cater for good GUI clients. Most apps I use have buttons and menus that I wouldn't want to express with markup (and web pages that try to do that most invariably suck). > I think you're right - a web standard designed for writing real > applications probably wouldn't start life as a markup for text. The > only thing I can think of that even tries is Flash, but it's > proprietary so I don't know much about it. Java has been mentioned in the other response, but there's also all other kinds of application frameworks. Only XUL is markup based, with the effect that there's almost no text at all between the markup tags I guess ;) > Care to tell me how you would design such a format if the goal were to > *not* lose any portability - which means it has to be possible to > design interfaces that work properly on character devices, things like > Palms three-color greyscale displays, and devices without pointers or > without keyboards, or even in an audio-only environment. Colors can be sampled down. Even the new Enlightenment libs do that (they say). For mapping a GUI client to a text client, ok, tough. Face it, lots of things just can't be expressed in pure text. Images, PDF viewing, video, simulation with graphical representations... Pointers could be added to any kind of machine, and even without it, you could give it a gameboy-style controller for cursor movement (i.e. arrow keys). I'm just not talking about a language for audio- and text-mode clients ;) -- My ideal for the future is to develop a filesystem remote interface (a la Plan 9) and then have it implemented across the Internet as the standard rather than HTML. That would be ultimate cool. Ken Thompson From Scott.Daniels at Acm.Org Fri Aug 26 12:36:38 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Aug 2005 09:36:38 -0700 Subject: classes and list as parameter, whats wrong? In-Reply-To: References: <20050826093420.GC23815@hep.physik.uni-siegen.de> <7ee3dcd80508260242717153fb@mail.gmail.com> Message-ID: <430f390b$1@nntp0.pdx.net> Dirk Zimmermann wrote: > But still, it is not absolutely clear for me, what is going on. So, at > least just for my understanding: The parameter LL is created just once > for the whole class and not for the object (because I del the object > explicitly, which should destroy the object)? del does nothing but remove one binding early. As far as effect on the underlying object, del v and v = None have the same effect. : > def main(): > l1 = ['a', 'b', 'c'] > lNames = ['n1', 'n2', 'n3'] > for name in lNames: > objC = cClass() > for each in l1: > objC.addFile(each) > print objC.list > del objC The del in main is superfluous. For all but the last iteration, the objC = c.cClass() will dereference the previous objC, and the final trip through the loop ends up by exiting the function which will have a similar effect. An experiment which will show this: import sys q = r = object() print sys.getrefcount(q), del r print sys.getrefcount(q), r = q print sys.getrefcount(q), r = None print sys.getrefcount(q) Note that whenever you call sys.getrefcount, the argument to the function itself will increase the count by 1. This demonstrates that: print sys.getrefcount(object()) --Scott David Daniels Scott.Daniels at Acm.Org From paul at boddie.org.uk Wed Aug 31 10:34:39 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 31 Aug 2005 07:34:39 -0700 Subject: Uploading images via cgi? References: Message-ID: <1125498879.402946.22100@o13g2000cwo.googlegroups.com> Chris Dewin wrote: > chunk = fileitem.file.read(100000), and fout.write (chunk) seem to be the > key statements. Could someone elaborate on these for me please? And why > do they need to be in a while loop? I imagine that the intention of reading only 100000 bytes at a time is to limit the amount of memory used by the process. In an environment where the process is kept around (not CGI, however) doing so might be critical since it has been alleged that Python isn't particularly good at freeing memory back to the operating system. One way of limiting the total size of uploaded files might be to examine the "Content-Length" header and to reject (ie. not process) uploads involving files above a certain size. Paul From robin at reportlab.com Mon Aug 15 13:55:23 2005 From: robin at reportlab.com (Robin Becker) Date: Mon, 15 Aug 2005 18:55:23 +0100 Subject: Determining win32 dll dependency In-Reply-To: <8xz3jj6p.fsf@python.net> References: <8xz3jj6p.fsf@python.net> Message-ID: <4300D70B.5040807@chamonix.reportlab.co.uk> Thomas Heller wrote: > Robin Becker writes: ..... > > For a discussion about the rights (or not) to distribute msvcr71.dll you > could read the py2exe-users lists archive. .... thanks for the tip, I believe there was a discussion on clpy recently as well >>I would like to automate my build script to include this file, but >>cannot think of an automatic way to determine which of msvcr70/71.dlls >>.... are needed. > > > py2exe contains an extension module that determines binary dependencies: > > ..... thanks for this as well. It seems to work fine. -- Robin Becker From rschroev_nospam_ml at fastmail.fm Fri Aug 12 09:02:08 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 12 Aug 2005 13:02:08 GMT Subject: Help with wxPython In-Reply-To: <1123847240.639930.147270@o13g2000cwo.googlegroups.com> References: <1123847240.639930.147270@o13g2000cwo.googlegroups.com> Message-ID: mitsura at skynet.be wrote: > I have encountered an annoying problem with wx.Choice from wx.Python. > Basically, what I want to do is create a drop down box with a set of > choices (so far so good). The problem is that when the drop down box is > created, the first entry in the list of the drop down box is empty and > you need to drop down in the list to make your choice. > I was looking for an option that allows to set a default/preset choice > in the list. The SetSelection method does that. I guess the reason you didn't find it is because it is not included in the documentation for wxChoice itself; it is described in the section for wxControlWithItems, which is wxChoice's base class. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From opengeometry at yahoo.ca Sat Aug 13 00:30:14 2005 From: opengeometry at yahoo.ca (William Park) Date: Sat, 13 Aug 2005 00:30:14 -0400 Subject: UCALC equivalent References: Message-ID: <58ddc$42fd7756$d8fe9e7f$21921@PRIMUS.CA> Dark Cowherd wrote: > http://www.ucalc.com/mathparser/index.html > > There is a great library called UCALC which allows you to set up an > expression and evaluate it > for e.g. you an define an expression by calling a function in UCALC > then call it with various values of x > > for e.g. see this page > http://www.ucalc.com/mathparser/sample6.html > > It is very fast. I have used it in VB when there is lot of number > crunching to be done. > Is there a Python equivalent. > > I looked at numPy and SciPy sites (just skimmed through) did'nt seem > to have what I wanted. > > Any pointers? Python has 'eval' and 'exec', so you can process at run-time anything that you can type into script file. However, it will be a bit more verbose than UCALC, because Python is more general. If you're looking for scientific calculator, which can be embedded or scripted, then perhaps you should take a look at http://home.eol.ca/~parkw/index.html#rpn It is RPN calculator with full support for functions and some features found in typical programmable scientific calculators. Eg. 3+4/5-8 --> rpn 4 5 / 3 + 8 - = --> -4.2 x^2+5x-10 --> rpn 'f(x)= dup 5 + x 10 -' rpn 1 'f(x)' = --> -4 rpn 5 'f(x)' = --> 40 or it can be scripted directly using shell function, like --> func () { rpn $1 dup 5 + x 10 - = } func 1 func 5 Sum(x^2+5, 1, 10). I assume this is sum of x^2+5, for x=1,2,...,10 --> rpn clear for i in {1..10}; do rpn $i x^2 5 + + done rpn = --> 435 -- William Park , Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ From borges2003xx at yahoo.it Thu Aug 25 17:27:23 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 25 Aug 2005 14:27:23 -0700 Subject: minimalist regular expression In-Reply-To: References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> Message-ID: <1125005243.312463.190960@g47g2000cwa.googlegroups.com> very nice From renting at astron.nl Wed Aug 24 08:27:22 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 24 Aug 2005 14:27:22 +0200 Subject: where does __class__ come from? Message-ID: I did mean the Language reference. chapter "Special method names". It contains a lot of the funky stuff like __dict__ and __getattr__. There is a little info in chapter 3.2 about __class__ : "__class__ is the instance's class." Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ >>>"Diez B. Roggisch" 08/24/05 1:13 pm >>> Adriaan Renting wrote: >You might find the chapter 3.3 (in my python 2.3.4, it's "Special Method names") in the reference manual useful, it is the only place I have found sofar that describes most of these special methods. It does however not contain __class__. I don't know where in the reference manual to find it's description, probaly in some "Special attribute names" chapter I can't find. Some of these are in the library reference, but lot's of them are also in the language reference - which has bitten me quite a few times, but by now I know where to look... Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 24 03:52:26 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 24 Aug 2005 09:52:26 +0200 Subject: python asp page keeps state across queries !?!? References: <1124813813.038076.184620@z14g2000cwz.googlegroups.com> Message-ID: nicolas_riesch enlightened us with: > I notice that variables outside functions keep their value across > queries. I don't know if it is normal. I think it's normal. > To be sure, I tried a similar asp script written in VB script, and I > can see that in VBscript, variables at this same level ARE NOT kept > across different queries !!! So? > Someone has an explanation ? Speed. No need to reload the module for each query. Just don't use any uninitialized module-scope variables. It's bad style anyway. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From fphsml at gmail.com Fri Aug 26 17:42:42 2005 From: fphsml at gmail.com (James) Date: 26 Aug 2005 14:42:42 -0700 Subject: Language translation possible in python? In-Reply-To: References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <430cca72$0$11076$e4fe514c@news.xs4all.nl> <003301c5a972$21bd30e0$5700a8c0@rmse> Message-ID: <1125092562.276359.137290@g49g2000cwa.googlegroups.com> As Terry, mentioned BabelFish should be a good resource. I have used Google Language tools in the past. It worked reasonably well with French and German. Now they included English to Korean BETA. From mail at tuxipuxi.org Mon Aug 29 15:30:51 2005 From: mail at tuxipuxi.org (Michael Goettsche) Date: Mon, 29 Aug 2005 21:30:51 +0200 Subject: Basic Server/Client socket pair not working Message-ID: <200508292130.51130.mail@tuxipuxi.org> Hi there, I'm trying to write a simple server/client example. The client should be able to send text to the server and the server should distribute the text to all connected clients. However, it seems that only the first entered text is sent and received. When I then get prompted for input again and press return, nothing gets back to me. Any hints on what I have done would be very much appreciated! Here's my code: ############ SERVER ########## import socket import select mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mySocket.bind(('', 11111)) mySocket.listen(1) clientlist = [] while True: connection, details = mySocket.accept() print 'We have opened a connection with', details clientlist.append(connection) readable = select.select(clientlist, [], []) msg = '' for i in readable[0]: while len(msg) < 1024: chunk = i.recv(1024 - len(msg)) msg = msg + chunk for i in clientlist: totalsent = 0 while totalsent < 1024: sent = i.send(msg) totalsent = totalsent + sent ############## CLIENT ################ import socket import select socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket.connect(("127.0.0.1", 11111)) while True: text = raw_input("Du bist an der Reihe") text = text + ((1024 - len(text)) * ".") totalsent = 0 while totalsent < len(text): sent = socket.send(text) totalsent = totalsent + sent msg = '' while len(msg) < 1024: chunk = socket.recv(1024 - len(msg)) msg = msg + chunk print msg From yin_12180 at yahoo.com Tue Aug 2 16:10:24 2005 From: yin_12180 at yahoo.com (Yin) Date: 2 Aug 2005 13:10:24 -0700 Subject: Pickle, __init__, and classes Message-ID: <1123013424.847230.300030@g47g2000cwa.googlegroups.com> I've created a class that reads in and processes a file in the initializer __init__. The processing is fairly substantial, and thus, instead of processing the file every time the object is created, I pickle the object to a file. In subsequent creations of the object, I implement a test to see whether the pickled file exists. If it does, then I unpickle the object. Unfortunately, the __init__ cannot return this unpickled object. I've used an auxiliary member function which fixes the problem, but I would prefer to have the correct object returned at instantiation rather than returned from the auxiliary member function. Are there other ways of approaching this problem? Thanks, Yin From aahz at pythoncraft.com Fri Aug 19 23:16:23 2005 From: aahz at pythoncraft.com (Aahz) Date: 19 Aug 2005 20:16:23 -0700 Subject: Python jobs References: <312cfe2b0508190821715fb488@mail.gmail.com> <86k6ihb9yt.fsf@bhuda.mired.org> Message-ID: In article <86k6ihb9yt.fsf at bhuda.mired.org>, Mike Meyer wrote: > >Maybe the Python jobs lists needs a "available developers" >counterpart? Or would it be to big/dynamic to maintain using whatever >is behind the jobs list? Part of the reason the Jobs page hasn't moved to a wiki is that often people sending in job ads are insufficiently technical to handle the formatting. That presumably wouldn't be true for an "available developers" wiki... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From mwh at python.net Tue Aug 9 10:29:56 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 09 Aug 2005 14:29:56 GMT Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <20050808005104.862503556.EP@zomething.com> Message-ID: Robert Kern writes: > What I'm trying to say is that posting to c.l.py is absolutely > ineffective in achieving that goal. Code attracts people that like > to code. Tedious, repetitive c.l.py threads attract people that like > to write tedious, repetitive c.l.py threads. +1 QOTW, though I may be too late (I've become rather temporally confused when it comes to clpy). Cheers, mwh -- Monte Carlo sampling is no way to understand code. -- Gordon McMillan, comp.lang.python From aahz at pythoncraft.com Fri Aug 12 11:45:56 2005 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2005 08:45:56 -0700 Subject: Python's Exception, and Capitalization References: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> Message-ID: In article <1123856890.712908.247920 at o13g2000cwo.googlegroups.com>, Ray wrote: > >2. I'm quite baffled that you either have try/except, or try/finally. >In Java, it is quite common to do this: > >try { > // something >} catch(AException e) { > // handle >} catch(BException e) { > // handle >} catch(CException e) { > // handle >} finally { > // whatever happens, execute this >} > >It seems that since except and finally are mutually exclusive I can't >do this. So... what's the usual idiom for this? Keep in mind that Python actually predates Java. The way this is handled now is try: try: except: else: finally: Way back when, Guido thought that it would be confusing to allow both except and finally clauses in the same try because people wouldn't know what ordering to use (particularly with the else clause). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From daranrife at yahoo.com Fri Aug 5 13:33:51 2005 From: daranrife at yahoo.com (drife) Date: 5 Aug 2005 10:33:51 -0700 Subject: Suggestions for optimizing my code Message-ID: <1123263231.010703.88990@z14g2000cwz.googlegroups.com> Hello, I am looking for suggestions for how I might optimize my code (make it execute faster), and make it more streamlined/ elegent. But before describing my code, I want to state that I am not a computer scientist (I am an atmospheric scientist), and have but a rudimentary understanding of OO principles. My problem is this: I want to find the maximum off-diagonal element of a correlation matrix, and the -position- of that element within the matrix. In case you are unfamiliar with correlation matrices they are square and symmetric, and contain the mutual correlations among data collected at different points in space or time. I write much Python code and absolutely love the language. To do the task outlined above I twiddled around with the "argsort" methods available in both Numeric and numarry. In the end, I decided to accomplish this through the following algorithm. <---- import MLab import Numeric as N def FindMax( R): """Find row (column) where max off-diagonal element occurs in matrx [R]. """ # First get elements in the lower triangle of [R], # since the diagonal elements are uninformative and # the upper triangle contains redundant information. Y = MLab.tril(R) offMax = -9999. rowMax = 0 colMax = 0 for row in range(len(Y)): for col in range(0,row): if Y[row][col] > offMax: offMax = Y[row][col] rowMax = row colMax = col return (rowMax, colMax, offMax) ----> Now, this algorithm will work sufficiently fast on "small" sized matrices, but I worry that performance will not scale well when the dimensions of the matrix grow "large" (say 1000-1500 elements on a side, or larger). So onto my question. Could someone please provide me with a suggestion for making this code more efficient and elegant? Again, I have but a rudimentary understanding of OO principles. Thanks very much for your help, Daran daranrifeNOS at PAMyahoo.com From kent37 at tds.net Fri Aug 5 15:03:11 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 05 Aug 2005 15:03:11 -0400 Subject: pain In-Reply-To: <86wtn1yzuu.fsf@bhuda.mired.org> References: <11f2846qlu2kpc9@corp.supernews.com> <86wtn1yzuu.fsf@bhuda.mired.org> Message-ID: <42f3b777$1_3@newspeer2.tds.net> Mike Meyer wrote: > Grant Edwards writes: > > >>On 2005-08-03, Mage wrote: >> >> >>>Isn't jython slower (I mean performance) than java? As well as >>>I understand jython code will be interpreted twice. > > The compiled jython will pay a performance penalty for being > dynamic. Where Java knows the type of objects, and can deduce the > correct method to call at compile time (well, some of the time, > anyway), the jython code will have to do a method search at run time. Yes, the compiled code makes heavy use of the Jython runtime to get anything done. *But* most of the hard work will probably be done by Java code in libraries you call. For example a Swing UI, XML parsing, database calls, etc all will happen in Java code. So in practice the performance penalty is not significant and is more than offset by the productivity benefit. Kent From bkhl at stp.lingfil.uu.se Sun Aug 7 05:31:46 2005 From: bkhl at stp.lingfil.uu.se (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) Date: Sun, 07 Aug 2005 11:31:46 +0200 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> Message-ID: <87ll3eytx9.fsf@lucien.dreaming> Paul Rubin writes: > Eh? Nah, we keep getting lame excuses on why those things aren't > needed and users should just supply tenacity and expect to suffer and > they should stop being wimps, and having to locate, download, and > figure out how to use a dozen packages from all over the internet > really isn't more hassle than a one-click install with unified > documentation for everything. I don't see why the things you talk about would have to be part of the main Python distribution. Ruby on Rails seems to do pretty well without being included with the core language. There's already a pretty successful programming framework for Python (Zope), and I don't see why people wouldn't be able to put something like that together to compete on more equal terms with Ruby on Rails, or Delphi, &c. If you want the whole of the Python community to start developing stuff for one particular GUI toolkit, I think you'll have much more success by just making a really good GUI toolkit, than trying to force people to use it by standardising it. (Which I think is shown by the proliferation of GUI toolkits other than Tkinter.) In short, when you have your one-click-install Pythonic IDE extravaganza, I'm sure people will download it, whether or not they can do it on python.org. -- Bj?rn Lindstr?m Student of computational linguistics, Uppsala University, Sweden From renting at astron.nl Wed Aug 17 03:06:42 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 17 Aug 2005 09:06:42 +0200 Subject: SOAP and XMLRPC Message-ID: import SOAPpy client = SOAPpy.SOAPProxy('http://localhost:80/Webservice') server = SOAPpy.SOAPServer(('localhost', 81), ) server.registerFunction(self.somefunction, 'urn:webservice') Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ From johnjsal at NOSPAMgmail.com Thu Aug 18 14:16:14 2005 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Thu, 18 Aug 2005 18:16:14 GMT Subject: up to date books? In-Reply-To: References: Message-ID: Thanks for the great replies everyone! "Learning Python" was my first choice, but it was also the reason I asked about older books, since it's from 2003. But it seems that isn't an issue, and I think that would be a nice place to start. Just one more quick question: I'm basically learning programming for fun, and I'm concentrating on C# right now. Python seems interesting, but I was wondering if I should even bother. Would it supplement C# in any way, or can C# do everything Python can? Thanks, John John Salerno wrote: > hi all. are there any recommendations for an intro book to python that > is up-to-date for the latest version? > > would reading a book from a year or two ago cause me to miss much? > > thanks! From fredrik at pythonware.com Mon Aug 22 17:24:32 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 23:24:32 +0200 Subject: Python and the web References: Message-ID: "Joe T." wrote: > 2. I know there's a Jpython but what use would I get from using Python > with > Java? If I'm already familiar with Java programming why would I want to > use > Python with Java? see, e.g. http://www.onjava.com/pub/a/onjava/2002/03/27/jython.html http://www.javaworld.com/javaworld/jw-03-2005/jw-0314-scripting_p.html http://opal.cabochon.com/~stevey/sokoban/docs/intro.html http://lesscode.org/2005/08/22/history-repeats-itself/ From me at privacy.net Sat Aug 6 16:37:05 2005 From: me at privacy.net (Dan Sommers) Date: Sat, 06 Aug 2005 16:37:05 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> Message-ID: On Sat, 6 Aug 2005 11:53:04 -0600, "John Roth" wrote: > What I want to see in Python 3000 is an AST based language that lets > the editors do the pretty printing. Do you want automatic indenting or > would you prefer end statements? It's an editor formatting option. The > AST neither knows or cares. Don't want to see self? Editor formatting > option. The AST knows what scope each identifier belongs to because > it's right there in the text. No need for rules that you have to > learn, sometimes the hard way. s/AST based language/machine code/g s/Editor formatting option/high level language/g After all, Lisp, FORTRAN, and Python are nothing more than Stupid Text Editor Tricks for manipulating my CPU's register file. Not everyone who would like to write a program has the skills (or the time) to develop their own high level language in which to do so. > I find the notion that there should be one obviously right way to do > something to be a good design principle ... This idea is directly at odds with the one above. Your vision for Python 3000 has as many Right Ways to do everything are there are permutations of configuration options in the text formatter. Regards, Dan -- Dan Sommers From pruebauno at latinmail.com Wed Aug 31 11:09:42 2005 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: 31 Aug 2005 08:09:42 -0700 Subject: Improving my text processing script Message-ID: <1125500982.664278.83810@g47g2000cwa.googlegroups.com> I am sure there is a better way of writing this, but how? import re f=file('tlst') tlst=f.read().split('\n') f.close() f=file('plst') sep=re.compile('Identifier "(.*?)"') plst=[] for elem in f.read().split('Identifier'): content='Identifier'+elem match=sep.search(content) if match: plst.append((match.group(1),content)) f.close() flst=[] for table in tlst: for prog,content in plst: if content.find(table)>0: flst.append('"%s","%s"'%(prog,table)) flst.sort() for elem in flst: print elem What would be the best way of writing this program. BTW find>0 to check in case table=='' (empty line) so I do not include everything. tlst is of the form: tablename1 tablename2 ... plst is of the form: Identifier "Program1" Name "Random Stuff" Value "tablename2" ...other random properties Name "More Random Stuff" Identifier "Program 2" Name "Yet more stuff" Value "tablename2" ... I want to know in what programs are the tables in tlst (and only those) used. From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 31 04:14:38 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 31 Aug 2005 10:14:38 +0200 Subject: OpenSource documentation problems References: Message-ID: Bryan Olson enlightened us with: > I don't see any need to look beyond Python for a good example of > poor documentation. Are there serious Python programmers who don't > constantly struggle with errors and omissions in the doc? I don't have any problems with the documentation. It just works for me. If you find any errors or omissions, fix them and send the document maintainer an email. Why don't you help us by improving the documentation? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From grante at visi.com Mon Aug 22 10:11:32 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 22 Aug 2005 14:11:32 -0000 Subject: sending binary files to a 16 micro controller. References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> Message-ID: <11gjn8k74pb6uc0@corp.supernews.com> On 2005-08-22, Magnus Lycka wrote: >> Hi, I'm working on a project were a need to be able to upload firmware >> to a microcontroller based Ethernet device. But because of the memory >> constraints the controller can only handle packages of 300 bytes each >> time. So therefore the firmware file must be sent in chunks [...] > The basic pattern to split and transmit your file would probably > be something like: > > f = open('filename') > header_template = 'Chunk %05i, %03i bytes' > for i, bytes in enumerate(f.read(max_number_of_bytes_per_chunk)): > msg = header_template % (i, len(bytes)) > msg += bytes > sock.send(msg) > sock.send('The end!') It's very probable that the TCP stack will combine chunks and send out full Ethernet frames (4K bytes). You're probably going to have to either put a time delay in the loop, or wait for each chunk to be acknowledged before sending the next one. -- Grant Edwards grante Yow! Are we live or at on tape? visi.com From strombrg at dcs.nac.uci.edu Tue Aug 23 19:54:44 2005 From: strombrg at dcs.nac.uci.edu (Dan Stromberg) Date: Tue, 23 Aug 2005 23:54:44 GMT Subject: Logging all activity on a tty/pty? Message-ID: Is there a way, using python, to (voluntarily) log all activity in a given shell, in a way that should work on pretty much all *ix's with a port of python? Thanks! From sjmachin at lexicon.net Thu Aug 18 22:34:31 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 12:34:31 +1000 Subject: Confused newbie needs help with "__init__() takes exactly 11 arguments (1 given)" In-Reply-To: <1124377112.427700.177790@g47g2000cwa.googlegroups.com> References: <1124377112.427700.177790@g47g2000cwa.googlegroups.com> Message-ID: <43054537@news.eftel.com> googleboy wrote: > I've written a little script to parse a csv file then use seach/replace > over a template to create a file for each line in the file. It pikes > out when I call the function that parses the csv (read_revs). If I > have inadvertantly left an extra comma or two in the comma field, it > gives an error that says: > > Traceback (most recent call last): > File > "C:\dev\python\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", > line 310, in RunScript > exec codeObject in __main__.__dict__ > File "d:\dev\python\projects\books\revgen3.py", line 177, in ? > gen_html() > File "d:\dev\python\projects\books\revgen3.py", line 92, in gen_html > revlist = > read_revs(r'D:\library\work\websites\gobooks\cgi\reviews.csv') > File "d:\dev\python\projects\books\revgen3.py", line 38, in read_revs > reviews = [Review(*[field.strip() for field in row]) for row in > reader] > TypeError: __init__() takes exactly 11 arguments (13 given) > > Which I understand totally, because I can see the two extra fields in > the csv. Problem is, if I correct that problem it gives me confusing > output that is identical except for the final line which says: How do you "correct" that problem? > > TypeError: __init__() takes exactly 11 arguments (1 given) > > I don't get how it goes from 13 arguments to 1! I now have 10 fields > and can understand that it is passing self as the 11th argument. > > Particularly confusing to me was that when I translated this from a > windows box running Python 2.4 to an OpenBSD box running python 2.3, it > just worked on the unix box. > > Find below an the code and an example of the csv file in question. > > TIA > > googleboy > > > > > ----- > param1,param2,param3,param4,param5,param6,param7,param8,param9,comments > data1,data2,data3,data4,data5,data6,data7,data8,data9,Comments on the > item reviewed go here. Sometime, but not all the time, there might be > extra commas in this text. > data1,data2,data3,data4,data5,data6,data7,data8,data9,Comments on the > item reviewed go here. > > > > ------ > > import string, os, re, sys, operator, csv > > class Review(object): > def __init__(self, param1, param2, param3, param4, param5, param6, > param7, param8, param9, comments): > params = locals() > del params['self'] > self.__dict__.update(params) > def __repr__(self): > all_items = self.__dict__.items() > return '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % (self.param1, > self.param2, self.param3, self.param4, self.param5, self.param6, > self.param7, self.param8, self.param9, self.comments) > > > def read_revs(filename): > csv_file = open(filename, "rb") > reader = csv.reader(csv_file) > reviews = [Review(*[field.strip() for field in row]) for row in > reader] so that you can see what you are actually getting as the 1 argument instead of guessing, try some diagnostics: reviews = [] for row in reader: args = [field.strip() for field in row] print "row", repr(row) print "args", repr(args) reviews.append(Review(*args)) > csv_file.close() > return reviews > > > def gen_revs(): > > revlist = read_revs(r'd:\dev\python\projects\books\reviews.csv') > revheader = revlist[0] > all_reviews = revlist[1:] > > template = open(r'd:\dev\python\projects\books\template.txt', 'r') > sTemplate = template.read() > > for review in all_reviews: > param1 = getattr(review, 'param1') > param2 = getattr(review, 'param2') > param3 = getattr(review, 'param3') > param4 = getattr(review, 'param4') > param5 = getattr(review, 'param5') > param6 = getattr(review, 'param6') > param7 = getattr(review, 'param7') > param9 = getattr(review, 'param8') > param9 = getattr(review, 'param9') > comments = getattr(review, 'comments') > > output = template % (param1, param2, param3, param4, param5, > param6, param7, param8, param9, comments) > > f=open(r"d:\dev\python\projects\books\%s.html" % param1, 'w') > f.write(output) > f.close() > From stas at tuxzilla.tuxhome Mon Aug 8 14:14:52 2005 From: stas at tuxzilla.tuxhome (stas) Date: Mon, 08 Aug 2005 20:14:52 +0200 Subject: gettext again References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> <42f77cb6$0$25055$8fcfb975@news.wanadoo.fr> Message-ID: On Mon, 08 Aug 2005 17:39:34 +0200, cantabile wrote: > BTW stasz, > Maybe you'll have still some time for the following question. Trying my > luck :)) > > Suppose I have several units (.py files), say test.py test1.py tets2.py > , test.py being my main file. > I've read I can import gettext and install in the main unit. Then, must > I create .po files for each unit or is there a way to make a single .po > file for the whole app. ? Yes there is. As a reminder, make sure that you install gettext in the namespace of your toplevel module. What I mean is this: test1.py imports test2.py and test3.py test2.py imports test4.py Now you have to place the gettext.install call in test1.py and then the other modules can access it. If you place the gettext call in, for example, test2.py then only test2.py and test4.py have access to it. So when it don't work as you expect make sure to check if every module has access to the "_" from gettext. So now for your question about one po/mo file for multiple modules. I use this file for a project of mine it also includes some explanation in case I forget it myself :-) The project is called "Guido van Robot". http://gvr.sf.net The files mentioned inside this file are used in the above project and serve as an example in this case. You could replace the files with your own to try it. The file itself is called "FilesForTrans" so you could put this file together with your test modules inside a directory and follow the instructions in side "FilesForTrans". Stas Z Contents of "FilesForTrans" ---- cut here --------- ## These files contain i18n strings ## Use: xgettext -f ./FilesForTrans -p /tmp ## The message.po will be located in /tmp ## Now do: msgmerge ./po/nl/gvr.po /tmp/messages.po > /tmp/new_nl.po ## compile the .po to mo (place the .po after editing in ./po/nl/) ## msgfmt ./po/nl/gvr.po -o ./locale/nl/LC_MESSAGES/gvr.mo gvr.py gvrparser.py world.py worldMap.py Editorwindows.py From wenming_hu2002 at hotmail.com Thu Aug 18 06:06:53 2005 From: wenming_hu2002 at hotmail.com (wen) Date: Thu, 18 Aug 2005 18:06:53 +0800 Subject: how do i add a new path into sys.path? References: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> Message-ID: if i wanna add the path "C:\temp" into sys.path, and make it available for any other new python apps, like i add C:\temp into windows path , how? thank you. "apa" wrote in message news:1124353535.829964.208660 at o13g2000cwo.googlegroups.com... > You can do it this way: > > sys.path.append("C:\Temp") > > Alejandro > From devlai at gmail.com Mon Aug 29 23:54:25 2005 From: devlai at gmail.com (Devan L) Date: 29 Aug 2005 20:54:25 -0700 Subject: aproximate a number In-Reply-To: <11h7i0s2lr5a8e8@corp.supernews.com> References: <1125369077.295227.8540@g14g2000cwa.googlegroups.com> <11h7i0s2lr5a8e8@corp.supernews.com> Message-ID: <1125374065.138657.66410@o13g2000cwo.googlegroups.com> Grant Edwards wrote: > On 2005-08-30, Devan L wrote: > > > > RoundToInt(2.0) will give you 3. > > That's what the OP said he wanted. The next bigger integer > after 2.0 is 3. > > -- > Grant Edwards grante Yow! I'd like TRAINED > at SEALS and a CONVERTIBLE on > visi.com my doorstep by NOON!! It's not really clear whether he wanted it to round up or to go to the next biggest integer because he says he has bad english. I can't think of a particular use of returning the next bigger integer. From fakeaddress at nowhere.org Wed Aug 10 09:03:44 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 13:03:44 GMT Subject: MainThread blocks all others In-Reply-To: <42f9d4ef_2@news.isis.de> References: <42f9d4ef_2@news.isis.de> Message-ID: Nodir Gulyamov wrote: > Hi Bryan, > Thanks for your reply. > I tried to test your solution, but it doesn't work, hence > threading.Semaphore object hasn't method to get value of semaphore. > I looked to source code of semaphore.py and find out that value is private > variable. Your code did not, and could not, use the value of counter for anything but busy-waiting. You had: while counter != 1: pass # ... continue... If you replace this with the semaphore, you can just assume a counter value of one. -- --Bryan From mwm at mired.org Sat Aug 6 22:00:31 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 06 Aug 2005 22:00:31 -0400 Subject: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...) References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> <11f84j8elj07271@news.supernews.com> <861x57wrui.fsf@bhuda.mired.org> <11f9f9u2enfsi58@news.supernews.com> <11f9u843r0fts5b@news.supernews.com> <86br4avf5t.fsf@bhuda.mired.org> Message-ID: <86y87etsjk.fsf@bhuda.mired.org> Peter Hansen writes: > Mike Meyer wrote: >> "John Roth" writes: >>>The world is moving on, in ways that I think you're not seeing. >>>And Python is standing still in many of those same ways. >> I find it hilarious that this arrived at my news server the same day >> that Peter Hansens rant (look for the subject "Syntax error after >> upgrading to Python 2.4") about Python changing to fast did. > ?? Which rant was that? I posted only one message in that thread, > and it wasn't a rant (according to my definition of the term... what's > yours?) and it wasn't even about Python changing too fast. At least, > I didn't mean it to be about that. Did you really interpret it that > way? Sorry, I was looking at the wrong summary line. The rant was posted by "Fernando" , and specifically tagged as a . Aplogies, http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From yux at sdf-eu.org Tue Aug 23 09:34:27 2005 From: yux at sdf-eu.org (Jonas Geiregat) Date: Tue, 23 Aug 2005 13:34:27 +0000 Subject: check whether directory is readable In-Reply-To: <1124786052.372768.156730@o13g2000cwo.googlegroups.com> References: <1124786052.372768.156730@o13g2000cwo.googlegroups.com> Message-ID: <430b0976$0$10960$ba620e4c@news.skynet.be> eels wrote: > Hello, > how can I check whether a directory is readable or not. Are there > differences between unix and windows? As far as I know there aren't any differences, code: import os if access("/root", os.R_OK): print "You are able to read the /root dir" From sethjn at gmail.com Sat Aug 27 15:28:29 2005 From: sethjn at gmail.com (Seth Nielson) Date: Sat, 27 Aug 2005 14:28:29 -0500 Subject: gdbm dying wierdly Message-ID: Hi guys. I'm using a python script as a redirector for Squid. My python script uses gdbm and exhibits some weird behavior. 1. If I run the script stand-alone, it loads the gdbm database file just fine. 2. If the script is launched from squid, when it tries to load the gdbm database, it dies WITHOUT an exception! It just disappears! (signal maybe?) Please help! I'm up against the wall! -- Seth N. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Aug 18 13:01:37 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Aug 2005 18:01:37 +0100 Subject: Put a url in a browsers address bar In-Reply-To: <4304B66B.6030706@ncl.ac.uk> References: <4304B66B.6030706@ncl.ac.uk> Message-ID: Colin Gillespie wrote: >>>I would like to place a url in my browsers address bar, then execute. >>>How can do this? >>> >> >>def goToGoogle(): >> import webbrowser >> webbrowser.open("www.google.com"); >> > > > Thanks for the quick reply. Do you know what module I would use to fill > out a form on an open web page? > > Thanks > > Colin Oops. ClientForm expects you to be interacting directly with the server, not driving an open browser window. To do the same thing through the browser would involve using COM, I suspect. If so be careful, as what you implement may end up being browser-specific. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rynt at yahoo9.com Fri Aug 5 14:37:57 2005 From: rynt at yahoo9.com (Ruben Baumann) Date: Fri, 5 Aug 2005 11:37:57 -0700 Subject: Opinions on KYLIX 3 (Delphi 4 Linux) References: Message-ID: "windozbloz" wrote in message news:gJQCe.8759$2h1.1968 at trnddc05... > Bye Bye Billy Bob... > > I'm back with one more question, then I'll chill. I have scoured the news > and net for info about Borlands KYLIX 3 and have found little technical > info about it. Their screen shots are very impressive, similar to Visual > Basic. I have sent several emails to Borlands Sales and Pre-Sales > departments. Pre-Sales bounces and Sales won't answer. I'm sitting here > with money in hand ready to buy but not from a company that won't give me > the time of day. > > Does anyone of you have experiance with KYLIX 3 and do you think I should > consider buying it? Thank You, I'll go oil my keyboard now. > > Doug > > -- > LINUX protects me from the GATES of hell !!! KYLIX is currently not being developed by Borland. I'm not even sure they're still supporting it OR selling it. There is a guy that is currently providing patches for the product(third party), but KYLIX 3 is the last version so far. I suspect that Borland is going to eventually drop KYLIX in favor of .NET and it's c# product. There are strong indications that the MONO project will run vb.net, c#.net, etc, etc, etc, so there's no need for a delphi (pascal) compiler under Linux if true. HTH Ruben From dwelch91 at gmail.com Fri Aug 12 18:44:32 2005 From: dwelch91 at gmail.com (dwelch91 at gmail.com) Date: 12 Aug 2005 15:44:32 -0700 Subject: Running one Python program from another as a different user In-Reply-To: References: <1123885309.455560.220670@z14g2000cwz.googlegroups.com> Message-ID: <1123886672.906472.322360@z14g2000cwz.googlegroups.com> Thanks, that looks very promising... Is there a solution for pre-Python v2.4? I have to have code that works on 2.x, 0<=x<=4. Do I just use the os.popen instead? -Don From tksri2000 at yahoo.com Wed Aug 10 15:11:05 2005 From: tksri2000 at yahoo.com (Srinivasan TK) Date: Wed, 10 Aug 2005 12:11:05 -0700 (PDT) Subject: Python-2.4.1 Build error on AIX Message-ID: <20050810191106.91770.qmail@web51107.mail.yahoo.com> All, I get the below error when trying to build python on AIX. Is there a way to ignore _tkinter. Please help Sri I do the following in my command line. export CC=gcc ld: 0706-006 Cannot find or open library file: -l tk8.3 ld:open(): A file or directory in the path name does not exist. ld: 0706-006 Cannot find or open library file: -l tcl8.3 ld:open(): A file or directory in the path name does not exist. *** WARNING: renaming "_tkinter" since importing it failed: No such file or directory error: No such file or directory make: *** [sharedmods] Error 1 ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From rafi at free.fr Thu Aug 25 12:03:27 2005 From: rafi at free.fr (rafi) Date: Thu, 25 Aug 2005 18:03:27 +0200 Subject: variable hell In-Reply-To: References: Message-ID: <430debc5$0$25399$626a14ce@news.free.fr> Adriaan Renting wrote: > You might be able to do something along the lines of > > for count in range(0,maxcount): > value = values[count] > exec(eval("'a%s=%s' % (count, value)")) why using the eval? exec ('a%s=%s' % (count, value)) should be fine -- rafi "Imagination is more important than knowledge." (Albert Einstein) From rkern at ucsd.edu Wed Aug 31 15:22:10 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 31 Aug 2005 12:22:10 -0700 Subject: Mapping network drive on Linux In-Reply-To: <1125515126.166481.61750@g47g2000cwa.googlegroups.com> References: <1125515126.166481.61750@g47g2000cwa.googlegroups.com> Message-ID: Thierry Lam wrote: > On windows, if I want to map a network drive to a local drive on my > computer, I do the following: > > data = { > 'remote' : '\\blah\data', > 'local' : 'Z:' > } > win32net.NetUseAdd(None, 1, data) > > How am I supposed to do similar thing on Linux? You would run the appropriate, external programs using os.system() or subprocess. As for what those might be, you will have to read your distribution's documentation or google around for HOWTOs. -- 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 twic at urchin.earth.li Fri Aug 12 06:55:58 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Fri, 12 Aug 2005 11:55:58 +0100 Subject: Help sorting a list by file extension In-Reply-To: <42fbf3be.1215996460@news.oz.net> References: <42fbf3be.1215996460@news.oz.net> Message-ID: On Fri, 12 Aug 2005, Bengt Richter wrote: > On Fri, 12 Aug 2005 00:06:17 GMT, Peter A. Schott wrote: > >> Trying to operate on a list of files similar to this: >> >> test.1 >> test.2 >> test.3 >> >> I want to sort them in numeric order instead of string order. > > >>> [name for dec,name in sorted((int(nm.rsplit('.',1)[1]),nm) for nm in namelist)] > ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20'] > > This depends on the extension being nicely splittable with a single '.' You could use os.path.splitext to do that more robustly: >>> [name for dec,name in sorted((int(os.path.splitext(nm)[1][1:]),nm) for nm in namelist)] tom -- Everybody with a heart votes love From merkosh at hadiko.de Fri Aug 12 14:04:51 2005 From: merkosh at hadiko.de (Uwe Mayer) Date: Fri, 12 Aug 2005 20:04:51 +0200 Subject: Bug on Python2.3.4 [FreeBSD]? Message-ID: Hi, AFAICT there seems to be a bug on FreeBSD's Python 2.3.4 open function. The documentation states: > Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' > truncates the file). Append 'b' to the mode to open the file in binary > mode, on systems that differentiate between binary and text files (else it > is ignored). If the file cannot be opened, IOError is raised. Consider: $ cat test lalala $ python2.3 Python 2.3.4 (#2, Jan 4 2005, 04:42:43) [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> f = open('test', 'r+') >>> f.read() 'lalala\n' >>> f.write('testing') >>> f.close() >>> [1]+ Stopped python2.3 $ cat test lalala -> write did not work; ok $ fg python2.3 >>> f = open('test', 'a+') >>> f.read() '' -> append mode does not read from file, *not ok* >>> f = open('test', 'w+') >>> f.read() '' >>> $ cat test -> w+ truncated file, ok Can anyone confirm that? Is there any other way of opening a file for appending instead of a+? Thanks, Ciao Uwe From lavigne.eric at gmail.com Sun Aug 21 01:53:42 2005 From: lavigne.eric at gmail.com (Eric Lavigne) Date: 20 Aug 2005 22:53:42 -0700 Subject: last line chopped from input file Message-ID: <1124603622.204380.256560@g47g2000cwa.googlegroups.com> Here is a shell command (MS-DOS): debug\curve-fit output.txt And here is a Python script that *should* do the same thing (and almost does): import os inputfilename = 'input.txt' outputfilename = 'output.txt' inputfile = open(inputfilename,'r') outputfile = open(outputfilename,'w') inputstream,outputstream = os.popen2("debug\\curve-fit") inputstream.write(inputfile.read()) inputfile.close() inputstream.close() outputfile.write(outputstream.read()) outputstream.close() outputfile.close() In the shell command, my curve-fit program processes the entire input file. In the Python script, my curve-fit program processes all except for the last line. Adding an extra newline to the end of my input file fixes this problem. What did I do wrong that led to this small difference? On a side note, I am very new to Python so I would appreciate any comments on style, or suggestions for simpler ways to write something like this (seems overkill for matching one line of shell), or more portable ways to write it (requires '\\' on windows but '/' on linux). From sjdevnull at yahoo.com Sun Aug 21 23:20:38 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 21 Aug 2005 20:20:38 -0700 Subject: global interpreter lock In-Reply-To: References: Message-ID: <1124680838.571125.100890@o13g2000cwo.googlegroups.com> km wrote: > > is true parallelism possible in python ? or atleast in the coming versions ? > is global interpreter lock a bane in this context ? I've had absolutely zero problems implementing truly parallel programs in python. All of my parallel programs have been multiprocess architectures, though--the GIL doesn't affect multiprocess architectures. Good support for multiple process architectures was one of the things that initially lead me to pick Python over Java in the first place (Java was woefully lacking in support facilities for this kind of architecture at that time; it's improved somewhat since then but still requires some custom C coding). I don't have much desire to throw out decades of work by OS implementors on protected memory without a pretty darn good reason. From Pierre-Eric.Melchy at uni-konstanz.de Thu Aug 4 08:16:19 2005 From: Pierre-Eric.Melchy at uni-konstanz.de (Pierre-Eric.Melchy at uni-konstanz.de) Date: 4 Aug 2005 05:16:19 -0700 Subject: Reliable destruction In-Reply-To: References: <1123153847.649321.235450@z14g2000cwz.googlegroups.com> Message-ID: <1123157779.191750.178300@g43g2000cwa.googlegroups.com> Hello Benjamin, What would happen if an exception was thrown in the middle of setup()? tearDown could not handle this case without having a list of the objects already constructed (Or I would have to rely on the automatic call to __del__, if it is reliable). There is still some problem: Imagine a communication error in run() which would cause del to fail on the instrument. Anyway, I think this case is still more difficult to handle. From diesch at spamfence.net Wed Aug 10 19:46:53 2005 From: diesch at spamfence.net (Florian Diesch) Date: Thu, 11 Aug 2005 01:46:53 +0200 Subject: Spreadsheet with Python scripting and database interface? References: Message-ID: <20050810234653.6B0A.1.NOFFLE@dieschf.news.arcor.de> Wolfgang Keller wrote: > I'm looking for a spreadsheet application (MacOS X prefered, but > Windows, Linux ar available as well) with support for Python scripting > (third-party "plug-ins" are ok) and a database interface. > > Applications that I know of (that they exist) are: > > MS Excel > Quattro > Lotus > OO Calc > Gnumeric > Kspread > > Which ones have I forgotten? > > Which ones have support for Python scripting? Package: gnumeric-plugins-extra Description: additional plugins for the GNOME spreadsheet Gnumeric ships with a number of plugins; this package contains those plugins that require additional packages above what the 'gnumeric' package needs. . This includes o The Perl plugin o The Python plugin o The Python plugin loader o Additional Python functions o The Gnome glossary o The gda (Gnome Database Access) plugin o The GNOME-DB plugin Florian -- begin signature_virus Hi! I'm a signature virus. Please copy me to your signature to help me spread. end From cam.ac.uk at mh391.invalid Wed Aug 3 13:21:44 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Wed, 03 Aug 2005 18:21:44 +0100 Subject: pain In-Reply-To: References: Message-ID: Mage wrote: > Look at this tutorial from java.com: > > public class BasicsDemo { > public static void main(String[] args) { > int sum = 0; > for (int current = 1; current <= 10; current++) { > sum += current; > } > System.out.println("Sum = " + sum); > } > } And then you have to compile it and set up your classpath... > It is "print sum(range(11))" in python. I would have used print sum(xrange(11)) myself. This probably has almost zero measurable performance impact, but I think using xrange() instead of range() is usually a good habit. As you know, xrange() generates ints as it is called rather than all at once, which can be quite helpful with large ranges. > I suggest you to feel lucky if you may use python at your work. Every day. -- Michael Hoffman From mwm at mired.org Thu Aug 4 20:46:49 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 04 Aug 2005 20:46:49 -0400 Subject: pain References: <11f2846qlu2kpc9@corp.supernews.com> Message-ID: <86wtn1yzuu.fsf@bhuda.mired.org> Grant Edwards writes: > On 2005-08-03, Mage wrote: > >> Isn't jython slower (I mean performance) than java? As well as >> I understand jython code will be interpreted twice. > > Jython gets compiled into Java byte code just like Java gets > compiled into Java byte code. Then whatever platform you're > using either interprets the Java byte code or uses some variant > of JIT compilation into native object code. The compiled jython will pay a performance penalty for being dynamic. Where Java knows the type of objects, and can deduce the correct method to call at compile time (well, some of the time, anyway), the jython code will have to do a method search at run time. Chance are, if you're supposed to be wwriting in Java, your application isn't sensitive enough to the performance of the code for this to matter. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From onurb at xiludom.gro Fri Aug 12 05:09:40 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 12 Aug 2005 11:09:40 +0200 Subject: How do these Java concepts translate to Python? In-Reply-To: <1123817487.901244.272700@z14g2000cwz.googlegroups.com> References: <1123815646.779180.81880@f14g2000cwb.googlegroups.com> <1123817487.901244.272700@z14g2000cwz.googlegroups.com> Message-ID: <42fc6756$0$12705$626a14ce@news.free.fr> Ray wrote: > Fausto Arinos Barbuto wrote: > >>Ray wrote: >> >> >>>1. Where are the access specifiers? (public, protected, private) >> >> AFAIK, there is not such a thing in Python. > > > So everything is public? I know that you can prefix a member with > underscores to make something private, The "2 leadings underscore name mangling" scheme is intented to protect "sensible" attributes from being accidentally overriden by derived classes, not to prevent access to the attribute. class Foo(object): def __init__(self): self.__baaz = 42 f = Foo() print f._Foo__baaz > but how about protected, for > example? object._protected_attribute is enough to tell anyone not to mess with this attribute. Believe it or else, but this happens to work perfectly. And BTW, don't bother making all your attributes "protected" or "private" then writing getters and setters, Python has a good support for computed attributes, so you can change the implementation without problem (which is the original reason for not-public attributes): # first version: class Foo(object): def __init__(self): self.baaz = 42 # public attribute # later we discover that we want Foo.baaz to be computed: class Foo(object): def __init__(self): self.baaz = 42 def _set_baaz(self, value): if value < 21 or value > 84: raise ValueError, "baaz value must be in range 21..84" self._baaz = value def _get_baaz(self): return self._baaz * 2 baaz = property(fget=_get_baaz, fset=_set_baaz) Easy as pie, uh ?-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From nszabolcs at gmail.com Thu Aug 11 16:03:30 2005 From: nszabolcs at gmail.com (Szabolcs Nagy) Date: 11 Aug 2005 13:03:30 -0700 Subject: Python interpreter error: unsupported operand type(s) for |: In-Reply-To: References: Message-ID: <1123790610.264861.112280@g47g2000cwa.googlegroups.com> you cannot use | with two dict (dict has no .__or__ method) what are you trying to do? From seberino at spawar.navy.mil Sun Aug 21 12:45:26 2005 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 21 Aug 2005 09:45:26 -0700 Subject: Is mymodule.myvariable a 'global'? (What is proper definition of 'global variable'?) Message-ID: <1124642726.191416.114340@g49g2000cwa.googlegroups.com> Python lets me access module level variables from *anywhere*. All I have to do is add module name in front. e.g. mymodule.myvariable Is this considered a 'global'? Or, does a 'global variable' have to be accessible anywhere *without* a namespace in front? (I'm not sure what proper academic definition of 'global variable' is.) Thanks! Chris From rkern at ucsd.edu Sat Aug 20 02:25:40 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 19 Aug 2005 23:25:40 -0700 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: <1124518424.490288.105620@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> Message-ID: James wrote: >>for data in iter(lambda:f.read(1024), ''): >> for c in data: > > What are the meanings of Commands 'iter' and 'lambda', respectively? I > do not want you to indicate merely the related help pages. Just your > ituitive and short explanations would be enough since I'm really newbie > to Python. No sorry, that's not how the newsgroup works. You read the documentation first, then come back with specific questions about what you didn't understand or couldn't find. http://www.catb.org/~esr/faqs/smart-questions.html -- 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 resolve at repose.REMOVE.cx Tue Aug 23 15:22:34 2005 From: resolve at repose.REMOVE.cx (Damien Elmes) Date: Wed, 24 Aug 2005 04:22:34 +0900 Subject: setlocale() in a module/extension library Message-ID: <873bp0pif9.fsf@mobile.repose.cx> Hi folks, I've got a module + C extension which provides on screen display support in X, via libxosd (http://repose.cx/pyosd). I've recently had a report of trouble where a Russian user was unable to display any Russian text. I've managed to resolve the issue by inserting the following two lines at the start of the application: import locale locale.setlocale(locale.LC_ALL, "") .. which I presume alters the way the Russian text is passed to X by the underlying library. My question is this: it would be nice if every user of my library didn't need to add the above two lines to their code. But on the other hand, I'm unsure of the implications of modifying the locale from within a module, and it doesn't seem very clean. Would calling setlocale() from a library be a bad thing? If so, any alternative recommendations would be greatly welcome. Kind regards, Damien From pfalcone at free.net.ph Sun Aug 14 00:06:55 2005 From: pfalcone at free.net.ph (Paolo Alexis Falcone) Date: Sun, 14 Aug 2005 12:06:55 +0800 Subject: Standalone applications ? References: <42feba84$0$18644$14726298@news.sunsite.dk> Message-ID: On Sat, 13 Aug 2005 23:29:27 -0400, Madhusudan Singh wrote: > Hi > > I just finished developing an application using Qt Designer in Python that > uses pyqwt, gpib, etc. How does one create standalone executables for > applications such as these ? Generally, you can't, as Python is an interpreted programming language. However, there are some projects like py2exe in Windows which approximates what you want to do - port the Python code into a stand-alone application. From adamtj at adamtj.org Mon Aug 29 00:14:04 2005 From: adamtj at adamtj.org (Adam Tomjack) Date: Sun, 28 Aug 2005 23:14:04 -0500 Subject: trictionary? In-Reply-To: <17170.32358.268677.962644@roam.psg.com> References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> <17170.32358.268677.962644@roam.psg.com> Message-ID: <43128B8C.3030903@adamtj.org> I'd write it like this: bin = {} for start, end, AS, full in heard: week = int((start-startDate)/aWeek) counters = bin.setdefault(week, [0, 0]) if full: counters[0] += 1 else: counters[1] += 1 for week, (times_full, times_not_full) in bin.iteritems(): print ... Seriously, use setdefault() as often as you can. It may be a little awkward at first, but after a little bit, you instantly know what it means. It takes out a whole if/else statement which will make your code smaller and more readable at the same time. The list is actually representing a struct. Regardless of how it smells, it's tight, small, and elegant. (This is the sort of problem where Python shines.) I do stuff like this all the time. Lists are so lightweight that there really isn't a better way to solve this problem. Anything else either involves more code or is less readable, in my opinion. Using an idea you used earlier, you could get smaller code by saying: for start, end, AS, full in heard: week = int((start-startDate)/aWeek) counters = bin.setdefault(week, [0, 0]) counters[not full] += 1 Or for start, end, AS, full in heard: week = int((start-startDate)/aWeek) bin.setdefault(week, [0, 0])[not full] += 1 Or even for start, end, AS, full in heard: bin.setdefault(int((start-startDate)/aWeek), [0, 0])[not full] += 1 While smaller, those are all too tricky for my taste. I think they're harder to read. I'd personally use the if/else. YMMV. Using lists to represent structs is perfectly fine if the list doesn't live longer than about one screen of code. If the list-struct gets returned from a top-level function and gets used elsewhere, then you should start to worry. It's too easy to forget what each element is supposed to represent if you have to scroll your editor to see the place where the list was created. That, in my opinion, would smell fishy. In that case, you should probably represent your struct with a class or a dict so that each element has a name. On the flip side, using such a heavy solution for such a simple problem also smells bad. The solution should should be as complicated as the problem -- no more, no less. Adam Randy Bush wrote: >>> bin = {} >>> for whatever: >>> for [a, b] in foo: >>> x = 42 - a >>> if bin.has_key(x): >>> bin[x.b] += 1 >>> else: >>> bin[x.b] = 1 >>> bin[x.not b] = 0 >>> for x, y, z in bin.iteritems(): >>> print x, y, z >>> >>>should the dict value become a two element list, or is there a >>>cleaner way to do this? >> >>It would probably help if you explained what the real problem is >>you're trying to solve. > > > actually, that code fragment was meant to do that. it's pretty much > what i needed to do at that point, just the variable names made > simple. > > >>Using a two element list to store a pair of counts has a bad code >>smell to me. > > > exactly. which is why i was asking. > > >>That said, you could write your code something like: >> bin = {} >> for whatever: >> # NOTE: brackets are unnecessary >> for a, b in foo: >> x = 42 - a >> # NOTE: 'in' is generally faster than has_key() >> if x in bin >> bin[x][0] += 1 >> else: >> bin[x] = [1, 0] >> # NOTE: extra parens necessary to unpack count list >> for x, (y, z) in bin.iteritems(): >> print x, y, z > > > so, to do this using the real names, it looks like > > for [start, end, AS, full] in heard: > week = int((start-startDate)/aWeek) > if week in bin: > if full: > bin[week][0] += 1 > else: > bin[week][1] += 1 > else: > if full: > bin[week] = [1, 0] > else: > bin[week] = [0, 1] > ... > for i, (j, k) in bin.iteritems(): > if j == 0: > print str(i) + ",," + str(k) > elif k == 0: > print str(i) + "," + str(j) > else: > print str(i) + "," + str(j) + "," + str(k) > > which is still pretty darned grotty and unexpressive. of course, > i could be a bit more obscure and do > > if week in bin: > bin[week][not full] += 1 > else: > bin[week] = [ full, not full ] > > except i probably have to coerce the types or something. less > code but less obvious. > > randy > From iainking at gmail.com Tue Aug 30 10:51:22 2005 From: iainking at gmail.com (Iain King) Date: 30 Aug 2005 07:51:22 -0700 Subject: how to join two Dictionary together? In-Reply-To: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> Message-ID: <1125413482.523747.106530@g47g2000cwa.googlegroups.com> DENG wrote: > dict1={...something...} > > dict2={...somethind else ..} > > dict1 + dict2 > > > that's does works ..:(, it's not like List... > > > anyone can tell me how to get it? > Uh, I'm just learning python too, so there may be a much simpler way to do this, but you could: dict3 = {} for k,i in dict1.iteritems(): dict3[k] = i for k,i in dict2.iteritems(): dict3[k] = i Think this should work. Obviously, if the same key appears in both dict1 and dict2 then dict2's value will overwrite dict1's. Iain From ptmcg at austin.rr.com Wed Aug 10 12:03:48 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 10 Aug 2005 09:03:48 -0700 Subject: Documentation References: <42fa1a9f$1@griseus.its.uu.se> Message-ID: <1123689828.082150.94430@z14g2000cwz.googlegroups.com> Get epydoc from SourceForge (http://epydoc.sourceforge.net/). It will auto-generate beautiful HTML doc pages for your Python classes, using the information you have inserted as the doc strings for your classes and methods. I use it to generate the pyparsing documentation, and it works very well for me (and I only use about 20% of epydoc's capabilities). -- Paul From rkern at ucsd.edu Mon Aug 8 07:25:17 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 08 Aug 2005 04:25:17 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: <87d5oo65uc.fsf@wilson.rwth-aachen.de> References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <20050808005104.862503556.EP@zomething.com> <87d5oo65uc.fsf@wilson.rwth-aachen.de> Message-ID: Torsten Bronger wrote: > Hall?chen! > > Robert Kern writes: > >>[...] >> >>What I'm trying to say is that posting to c.l.py is absolutely >>ineffective in achieving that goal. Code attracts people that like >>to code. Tedious, repetitive c.l.py threads attract people that >>like to write tedious, repetitive c.l.py threads. > > Although I mostly agree with you, I must also say that it can be a > significant motivation for a developer to see that his project is > urgently needed and that he can expect a quite big user base and > early fellow developers. Sure, that's a *far* more specific request that can be sensibly answered. Such a thread is also unlikely to be just a repeat of the same discussion made over and over again for years; after all, the hypothetical project is probably something new. -- 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 wouter at voti.nl Wed Aug 24 10:06:21 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Wed, 24 Aug 2005 14:06:21 GMT Subject: Should I move to Amsterdam? References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> Message-ID: <430c7dba.1557700554@news.xs4all.nl> >Nice little series by Seth Stevenson for Americans daydreaming about >emigration. Somewhere, anywhere ... maybe Amsterdam? > >I've never been to the Netherlands myself, but it sounds very >civilized. It used to be, until some lunatic (alledged to be a left-winger) killed an (alledged right-wing) politician, and another (alledged muslim-extremist) lunatic killed an (alledged right- or left-wing, depends on who you ask) cineast. We used to be a place where everything happens a few years later, but we are catching up! :( But I fondly remember the classes I had at the Delft university by Lambert Meertens about the ABC language, which is the forerunner of Python. :) Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From della at toglimi.linux.it Thu Aug 11 10:18:47 2005 From: della at toglimi.linux.it (Matteo Dell'Amico) Date: Thu, 11 Aug 2005 14:18:47 GMT Subject: set of sets In-Reply-To: References: Message-ID: Paolo Veronelli wrote: > And mostly with sets remove operation expense should be sublinear or am > I wrong? > Is this fast as with lists? It's faster then with lists... in sets, as with dicts, remove is on average O(1). > Obviously if I use the ids as hash value nothing is guaranted about the > objects contents to be unique but I don't care. > My work is a self organizing net,in which the nodes keep a structure to > link other nodes.As the nature of the net,the links are moved frequently > so remove and add operations and contains query should be optimized. > Why objects need to be hashable for this? Isn't __hash__ there to solve > the problem? The idea of a set of mutable sets looks a bit odd to me... I don't get why the outer container should be a set, since you don't care about uniqueness... if you are representing a graph (which seems the case to me), I'd use an identifier for each node, and a dictionary mapping node-ids to its adjacency set for each node. For instance, 0 <-- 1 --> 2 --> 3 | | v v 4 --> 5 would be represented as {0: set([]), 1: set([0, 2]), 2: set([2,4]), 3: set([5]), 4: set([5]), 5: set([])} If node ids are consecutive integers, you could also of course use a list as the outer structure. PS: we could also discuss this in italian in it.comp.lang.python :) -- Ciao, Matteo From goodger at python.org Fri Aug 12 21:58:17 2005 From: goodger at python.org (David Goodger) Date: Fri, 12 Aug 2005 21:58:17 -0400 Subject: new PEP type: Process Message-ID: <42FD53B9.8050602@python.org> Barry Warsaw and I, the PEP editors, have been discussing the need for a new PEP type lately. Martin von L?wis' PEP 347 was a prime example of a PEP that didn't fit into the existing Standards Track and Informational categories. We agreed upon a new "Process" PEP type. For more information, please see PEP 1 (http://www.python.org/peps/pep-0001.html) -- the type of which has also been changed to Process. Other good examples of Process PEPs are the release schedule PEPs, and I understand there may be a new one soon. (Please cc: any PEP-related mail to peps at python.org) -- David Goodger -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: From mohammed at aims.ac.za Tue Aug 23 17:52:48 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Tue, 23 Aug 2005 23:52:48 +0200 Subject: how to deal with space between numbers In-Reply-To: References: Message-ID: <430B9AB0.4000904@aims.ac.za> > > >Read my answers to your two previous posts. >(in short : use str.split() - but *do* read my answers if you want to >save you a lot of pain) > > > > > > > Thanks a lot for your valuable answer, i like the way you code , but i would like to use my own, so if it is possible for you and if you have time, please could you fix my code, so that i can do what i want. Because i am using the this out put to another one , and i have the same problem. I will really appreciate it !!! Regards From nomail at nomail.com Thu Aug 25 10:43:04 2005 From: nomail at nomail.com (Nx) Date: Thu, 25 Aug 2005 22:43:04 +0800 Subject: variable hell References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> Message-ID: <430dd8e1@127.0.0.1> Thanks for the many replies here is an example for what it will be used for , in this case fixed at 31 fieldvalues: inputvalues=(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25, s26,s27,s28,s29,s30,s31) MYINSERTSELECT = "INSERT INTO ADDRESS(ALIAS,COMPANY,ADDRESSLI1,ADDRESSLI2,ADDRESSCO,TOWN,ZIP,COUNTRY,TEL1,TEL2,FAX,EMAIL,INTERNET,PERSON1,TITLE1,RES1,PERSON2,TITLE2,RES2,PERSON3,TITLE3,RES3,PERSON4,TITLE4,RES4,PERSON5,TITLE5,RES5,PRODALIAS,PAGER,TLX,ADDMEMO) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" con1.commit() cur = con1.cursor() try : cur.execute(MYINSERTSELECT,inputvalues) con1.commit() print 'Inserted 1 record' except IOError, (errno, strerror): print "I/O error(%s): %s" % (errno, strerror) except ValueError: print "Could not convert data to an integer." except: print "Unexpected error:", sys.exc_info()[0] raise I am sure there is an easier way, but I have not found it yet. Nx From rebound1618 at yahoo.com Sun Aug 7 14:32:41 2005 From: rebound1618 at yahoo.com (Jerry He) Date: Sun, 7 Aug 2005 11:32:41 -0700 (PDT) Subject: SWIG again In-Reply-To: Message-ID: <20050807183241.26544.qmail@web51503.mail.yahoo.com> > Can you tell me how to completely remove that > module? > > For cygwin, it should be in whatever corresponds to > /usr/lib/python2.4/site-packages . > > -- > Robert Kern > rkern at ucsd.edu > Hi, Do you mean to say that all I have to do is delete "example.py" and the "build" folder? (note: I didn't do "python setup install", I did "python setup build", so all I have is the above two things in the sourcefile folder. ) -- Jerry ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From Tracy.Beck at Infineon.com Thu Aug 25 13:22:44 2005 From: Tracy.Beck at Infineon.com (T Beck) Date: 25 Aug 2005 10:22:44 -0700 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: <1124990564.528106.205070@g44g2000cwa.googlegroups.com> Mike Schilling wrote: > "Rich Teer" wrote in message > news:Pine.SOL.4.58.0508250932360.5888 at zen.rite-group.com... > > On Thu, 25 Aug 2005, Mike Schilling wrote: > > > >> Another advantage is that evewry internet-enabled computer today already > >> comes with an HTML renderer (AKA browser), so that a message saved to a > >> file > >> can be read very easily. > > > > I think you're missing the point: email and Usenet are, historically have > > been, and should always be, plain text mediums. > > Gosh, if you say they should be, there's no point trying to have an > intelligent discussion, is there? Not to mention that e-mail is practically to the point where it is {not} a plain text medium. I notice this especially in a corporate environment (where, at least where I work, I get at least 10 times the number of e-mails at work than I do on my private account) HTML e-mail is the de-facto standard. I have a tendancy to send out plain text e-mail, and I'm practically the only one, as HTML formatting is the default for the mail client on every corporate machine at my job. But let's not forget that most people which send me e-mail personally also have HTML tags in e-mail... So if e-mail {is} a plain text medium, somebody needs to tell the general public, because I think they must've missed a memo. If we argue that people are evolving the way e-mail is handled, and adding entire new feature sets to something which has been around since the earliest days of the internet, then that's perfectly feasable. HTML itself has grown. We've also added Javascript and Shockwave. The websites of today don't even resemble the websites of 10 years ago, e-mail of today only remotely resembles the original, so the argument that usenet should never change seems a little heavy-handed and anachronistic. --T Beck From timothy at open-networks.net Tue Aug 2 20:00:13 2005 From: timothy at open-networks.net (Timothy Smith) Date: Wed, 03 Aug 2005 10:00:13 +1000 Subject: startfile problems In-Reply-To: References: Message-ID: <42F0090D.1080504@open-networks.net> Michael Hoffman wrote: >Timothy Smith wrote: > > > >>yep the program is executed in the same dir as the pdf file. like i said >>it actually opens it, but throws up an exception as well. >> >> > >You are far more likely to get informed help if you post the traceback >here, as has been suggested twice already. > > i can't since it's a remote site and i can't reproduce the error. the best i have is a screen shot. besdies which the only information it gives is the names and line numbers of the my py modules, nothing more. the only real info it gives i have posted already, in my inital post (the last line of it, WindowsError etc..) other then that there's no more information to be had. it's a bloody simple 2 line function, nothing funky about it. From nathan_kent_bullock at yahoo.ca Sat Aug 27 13:11:26 2005 From: nathan_kent_bullock at yahoo.ca (nathan_kent_bullock at yahoo.ca) Date: 27 Aug 2005 10:11:26 -0700 Subject: pydoc, best practices, and Data class Message-ID: <1125162686.846023.123410@g43g2000cwa.googlegroups.com> I have a python program that I am trying to generate documentation for. But in one of my files I have a class called "Data", when pydoc gets to this class it just barfs. Well more specifically it generates documentation for only that one class in the file, it ignores the rest of the classes, plus it doesn't create the standard header, Package Contents section, Classes section, or anything else. Just wondering if this is a known bug, I can get around it by naming the class something else and then just changing all other references to this class. Second question I have is is there somewhere that gives a good overview of best practices for documenting code in python. I read something about ReST (reStructuredText), is this supported by pydoc? Is it commonly used? I found links to docutils and other things, is pydoc still the standard method of creating python documentation? Thanks, Nathan Bullock From tdelaney at avaya.com Wed Aug 3 18:12:13 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Thu, 4 Aug 2005 08:12:13 +1000 Subject: Art of Unit Testing Message-ID: <2773CAC687FD5F4689F526998C7E4E5F05CBD0@au3010avexu1.global.avaya.com> phil hunt wrote: >> tests? If they were unit tests, they should take only a few minutes >> to run, total, > > Eek! Seconds, more like. Unfortunately, when you've got umteen zillion of them, having individually fast test suites doesn't help much :( The complete test suite for my current project takes approx 10 minutes to run. Test suites for most individual packages is on the order of seconds, but they do add up. Of course, having slow test suites is much much worse ... And there's the odd test which needs to take longer, normally because it's timing related - for example, you may want to test that changing a timeout works over various time periods. Tim Delaney From jeffrey.schwab at rcn.com Wed Aug 10 12:51:07 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Wed, 10 Aug 2005 12:51:07 -0400 Subject: how to write a line in a text file In-Reply-To: References: <42E5B0F0.6020206@REMOVEMEcyber.com.au> <42E5ED91.10402@REMOVEMEcyber.com.au> Message-ID: <_KudnTzp9YHjrWffRVn-rQ@rcn.net> Calvin Spealman wrote: > On 7/31/05, James Dennett wrote: > >>Peter Hansen wrote: >> >> >>>Steven D'Aprano wrote: >>> >>>Given that ZODB and PySQLite are simply Python extension modules, which >>>get bundled by your builder tool and are therefore installed >>>transparently along with your app by your installer, this is a total >>>non-issue at least with those packages. >>> >>>After all, it's not 1970 any more. ;-) >> >>Indeed; since 1970 we learned to prefer straightforward >>file formats where possible, reserving use of databases >>for structured data where the extra costs are justified. >> >>Sometime maybe databases will get better to the point >>that we don't need to distinguish so much between them >>and filesystems, but we're not there yet. Managing raw >>files, carefully, still has a place. >> >>-- James > > > Filesystems are a horrible way to organize information, and even worse > at structuring it. The mentality that there are any benefits of > low-overhead the outweigh the benefits of minimal database layers, > such as ZODB, BSD DB, and SQLite, is a large part of the reason we are > still stuck with such a mess. Those "extra costs" are so minimal, that > you wouldn't even notice them, if you hadn't convinced yourself of > their presense before performing or researching any realy benchmarks. > A simple RDBMS can be much easier to work with than any flat file > format, will likely be far faster in processing the data, and has the > benefit of years of coding making the code that actually reads and > writes your data as fast and stable as possible. You don't use files? You're telling me that instead of copying & modifying my friend's bashrc, I should be querying a bunch of tables with SQL? Bull. Ordinary files, preferably in line-separated or tagged formats, are going to be a lot easier for most of us to work for a long time to come. This is especially true now that we have lots of good libraries for working with XML-based formats. From grante at visi.com Sat Aug 13 15:15:04 2005 From: grante at visi.com (Grant Edwards) Date: Sat, 13 Aug 2005 19:15:04 -0000 Subject: how to append semicolon to a variable References: <1123946072.577232.218530@o13g2000cwo.googlegroups.com> <11fs9tn73j02298@corp.supernews.com> <42fe31d4$0$27713$626a14ce@news.free.fr> Message-ID: <11fshlon47p9t18@corp.supernews.com> On 2005-08-13, tiissa wrote: > Grant Edwards wrote: >> s = ';'.join([couch,price,sdate,city]) >> print s > > I'll risk myself with something like: > > s = ';'.join([tag.string for tag in [couch,price,sdate,city]]) > > Of course, from the question I wouldn't have any clue. I just like doing > some guessing on problems I know nothing about. ;) > >>>p.s. i tried couch = couch + ';' >>>and then i tried couch = couch + ";" >> >> both of those should have worked fine. > > Not really. It seems to me the OP is using BeautifulSoup (or some other > SGML parser). In this case, couch and others are not strings but objects. Seems like a reasonable guess. > It may also be that strUrl is their parent (but I wouldn't know, how > would I?) Nope. :) -- Grant Edwards grante Yow! Are you mentally here at at Pizza Hut?? visi.com From gelios at rbcmail.ru Wed Aug 10 07:35:02 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Wed, 10 Aug 2005 15:35:02 +0400 Subject: MainThread blocks all others References: <42f9d4ef_2@news.isis.de> Message-ID: <42f9e676_2@news.isis.de> I had future investigation and as I understand in POSIX compliant threads, getting value of semaphore should be exist. As the matter of fact Python threads is not fully POSIX compliant. Pitty! Contining looking for another solution. "Nodir Gulyamov" wrote in message news:42f9d4ef_2 at news.isis.de... > Hi Bryan, > Thanks for your reply. > I tried to test your solution, but it doesn't work, hence > threading.Semaphore object hasn't method to get value of semaphore. > I looked to source code of semaphore.py and find out that value is private > variable. > > Best regards, > /Gelios > > "Bryan Olson" wrote in message > news:fRaKe.3656$zr1.2646 at newssvr13.news.prodigy.com... >>I wrote: >> > Make self.counter a semaphore. Untested code: >> >> A little clean-up. Still untested: >> >> import threading >> >> class class1: >> def __init__(self): >> self.counter = threading.semaphore(0) >> result = self.doSomeJob() >> >> def increaseCounter(self): >> self.counter.release() >> >> def doSomeJob(self): >> # Busy-waiting sucks. >> # while counter != 1: >> # pass >> self.counter.acquire() >> # ... continue... >> >> >> -- >> --Bryan > > From http Sun Aug 7 02:18:13 2005 From: http (Paul Rubin) Date: 06 Aug 2005 23:18:13 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123392742.576632.59400@z14g2000cwz.googlegroups.com> Message-ID: <7xbr4agti2.fsf@ruckus.brouhaha.com> "gene tani" writes: > http://martinfowler.com/bliki/CollectionClosureMethod.html > http://onestepback.org/index.cgi/Tech/Ruby/PythonAndRuby.rdoc Thanks, the way Ruby passes closure arguments to various of its library builtins is cute. PEP 343 adds something sort of comparable to Python but I think more library support and culture evolution will be needed before the "with" statement operates as smoothly. Ruby just doesn't interest me that much though (maybe I'm missing something). I was hoping for a concise explanation of what Rails does and whether it's feasible to do something like it in (say) Python. I did look at the rubyonrails.com site but there were too many marketing buzzwords and downloadable videos for me to deal with. From mekstran at scl.ameslab.gov Sun Aug 21 17:21:39 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Sun, 21 Aug 2005 16:21:39 -0500 Subject: Is mymodule.myvariable a 'global'? (What is proper definition of 'global variable'?) In-Reply-To: <1124642726.191416.114340@g49g2000cwa.googlegroups.com> References: <1124642726.191416.114340@g49g2000cwa.googlegroups.com> Message-ID: <20050821162139.63611d00.mekstran@scl.ameslab.gov> On 21 Aug 2005 09:45:26 -0700 "seberino at spawar.navy.mil" wrote: > Python lets me access module level variables from *anywhere*. All I > have > to do is add module name in front. > > e.g. > > mymodule.myvariable > > Is this considered a 'global'? Or, does a 'global variable' have to > be accessible anywhere *without* a namespace in front? Whether or not it is a true academic global, such a variable is what Python calls a global. There is no way to make a variable universally accessible without a namespace. -Michael From future_retro at yahoo.co.uk Wed Aug 3 07:27:15 2005 From: future_retro at yahoo.co.uk (future_retro at yahoo.co.uk) Date: 3 Aug 2005 04:27:15 -0700 Subject: wmi addprinterdriver for remote PC In-Reply-To: <1123068236.071352.209680@g47g2000cwa.googlegroups.com> References: <1123068236.071352.209680@g47g2000cwa.googlegroups.com> Message-ID: <1123068434.972727.292050@o13g2000cwo.googlegroups.com> soz I missed the glaring error. The file paths need to be to a UNC location of have to exist on the remote PC. From sybrenUSE at YOURthirdtower.com.imagination Tue Aug 23 07:44:56 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Tue, 23 Aug 2005 13:44:56 +0200 Subject: Doubt C and Python References: <430b0872$0$21931$db0fefd9@news.zen.co.uk> Message-ID: Will McGugan enlightened us with: > Because I can create software many times faster. And its more fun. Same here. And because it's very easy to write unittests, for instance. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From stas at tuxzilla.tuxhome Sun Aug 14 10:51:04 2005 From: stas at tuxzilla.tuxhome (stas) Date: Sun, 14 Aug 2005 16:51:04 +0200 Subject: wx.MessageDialog displayed without components inside References: <1123951035.856439.173160@g44g2000cwa.googlegroups.com> <1123976057.103585.237410@z14g2000cwz.googlegroups.com> <1124030710.688098.299040@o13g2000cwo.googlegroups.com> Message-ID: On Sun, 14 Aug 2005 07:45:10 -0700, perchef wrote: > >> Just a thought, do you call the event loop ? > yes i do. > I really can't see my a MessageDialog would appear without components > inside. maybe a thread problem ? Does the example I gave work? I mean when you copy and paste it does it show a normal dialog? Stas From russblau at hotmail.com Tue Aug 2 16:27:44 2005 From: russblau at hotmail.com (Russell Blau) Date: Tue, 2 Aug 2005 16:27:44 -0400 Subject: Pickle, __init__, and classes References: <1123013424.847230.300030@g47g2000cwa.googlegroups.com> Message-ID: "Yin" wrote in message news:1123013424.847230.300030 at g47g2000cwa.googlegroups.com... > I've created a class that reads in and processes a file in the > initializer __init__. The processing is fairly substantial, and thus, > instead of processing the file every time the object is created, I > pickle the object to a file. > > In subsequent creations of the object, I implement a test to see > whether the pickled file exists. If it does, then I unpickle the > object. > > Unfortunately, the __init__ cannot return this unpickled object. > Try __new__(). http://docs.python.org/ref/customization.html This isn't the usual application of __new__, but since it returns an object it should be ideal for your purposes. From nir1408 at gmail.com Thu Aug 11 02:10:57 2005 From: nir1408 at gmail.com (nir1408 at gmail.com) Date: 10 Aug 2005 23:10:57 -0700 Subject: new python debugger References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> Message-ID: <1123740657.066728.39080@g43g2000cwa.googlegroups.com> Thanks for the compliments. I really believe Winpdb is not just another Python debugger, and that it will be a real step forward in the quality of Python debuggers once it matures. Also, don't worry about the .com url, it is a GPL debugger. Winpdb is still a BETA despite the version number which is 1.0.1 so I will appreciate feedback on bugs, unexpected behavior, or suggestions. Finally, If you think it is great, don't hesitate to share your opinion with others. Nir From "markusweimer\" at ipsi(dot)fraunhofer(.)de Fri Aug 12 13:21:08 2005 From: "markusweimer\" at ipsi(dot)fraunhofer(.)de (. (dot)) Date: Fri, 12 Aug 2005 19:21:08 +0200 Subject: How to build Python modules on windows? Message-ID: <42fcda84$1@news.fhg.de> Hi, how can I build python modules on windows? I tried to build numarray[0] using Microsoft Visual C++ 2003 Toolkit, but got the following error: --- error: Python was built with version 7.1 of Visual Studio, and extensions need to be built with the same version of the compiler, but it isn't installed. --- So do I need to buy Visual Studio 7.1 to be able to build python modules on windows? That would explain why there are so few binary packages available. If this is true, has the python community considerred switching to compile the standard python distribution using the freely available compiler from Microsoft? Thanks in advance for any hints! Markus [0]: I do not need to install numarray, but find a decent way to package and build self-made extensions and use numarray here as an example From steven.bethard at gmail.com Thu Aug 11 16:01:54 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 11 Aug 2005 14:01:54 -0600 Subject: performance of recursive generator In-Reply-To: References: Message-ID: <3uqdnVTPRY8yM2bfRVn-pQ@comcast.com> aurora wrote: > I love generator and I use it a lot. Lately I've been writing some > recursive generator to traverse tree structures. After taking closer > look I have some concern on its performance. > > Let's take the inorder traversal from > http://www.python.org/peps/pep-0255.html as an example. > > def inorder(t): > if t: > for x in inorder(t.left): > yield x > yield t.label > for x in inorder(t.right): > yield x > > Consider a 4 level deep tree that has only a right child: > > 1 > \ > 2 > \ > 3 > \ > 4 > > > Using the recursive generator, the flow would go like this: > > main gen1 gen2 gen3 gen4 > ---------------------------------------------------- > > inorder(1..4) > > yield 1 > inorder(2..4) > yield 2 > yield 2 > inorder(3..4) > yield 3 > yield3 > yield 3 > inorder(4) > yield 4 > yield 4 > yield 4 > yield 4 > > > Note that there are 4 calls to inorder() and 10 yield. Indeed the > complexity of traversing this kind of tree would be O(n^2)! You seem to be assuming that a yield statement and a function call are equivalent. I'm not sure that's a valid assumption. Anyway, here's some data to consider: -------------------- test.py -------------------- def gen(n): if n: for i in gen(n/2): yield i yield n for i in gen(n/2): yield i def gen_wrapper(n): return list(gen(n)) def nongen(n, func): if n: nongen(n/2, func) func(n) nongen(n/2, func) def nongen_wrapper(n): result = [] nongen(n, result.append) return result ------------------------------------------------- D:\steve>python -m timeit -s "import test" "test.gen_wrapper(100)" 1000 loops, best of 3: 395 usec per loop D:\steve>python -m timeit -s "import test" "test.nongen_wrapper(100)" 1000 loops, best of 3: 216 usec per loop D:\steve>python -m timeit -s "import test" "test.gen_wrapper(1000)" 100 loops, best of 3: 3.58 msec per loop D:\steve>python -m timeit -s "import test" "test.nongen_wrapper(1000)" 1000 loops, best of 3: 1.59 msec per loop D:\steve>python -m timeit -s "import test" "test.gen_wrapper(10000)" 10 loops, best of 3: 70.5 msec per loop D:\steve>python -m timeit -s "import test" "test.nongen_wrapper(10000)" 10 loops, best of 3: 26.6 msec per loop The non-generator version is consistently faster, somewhere around twice as fast. Of course, I'll still be writing generator-based solutions util I'm certain the recursion's the speed bottleneck in my application. STeVe From fakeaddress at nowhere.org Wed Aug 24 09:18:24 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 24 Aug 2005 13:18:24 GMT Subject: global interpreter lock In-Reply-To: <868xyw9g30.fsf@bhuda.mired.org> References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Bryan Olson writes: > >>Mike Meyer wrote: >> > The rule I follow in choosing my tools is "Use the least complex tool >> > that will get the job done." >> >>Even if a more complex tool could do the job better? > > In that case, the simpler model isn't necessarily getting the job > done. I purposely didn't refine the word "job" just so this would be > the case. I didn't ask about any particular case. You stated a general rule you follow, and I think that rule is nuts. >>Now I've gotten off-topic. Threads are winning, and the industry >>is going to multiple processors even for PC-class machines. >>Might as well learn to use that power. > > I own too many orphans to ever confuse popularity with technical > superiority. The issue here is whether to confuse reality with what one might wish reality to be. > I've learned how to use threads, and done some > non-trivial thread proramming, and hope to never repeat that > experience. It was the second most difficult programming task I've > ever attempted(*). Great -- lets see it! Can you point out what parts were so hard? How would you have solved the same problems without threads? > As I said above, the real problem isn't threads per > se, it's that the model for programming them in popular languages is > still primitive. So far, to achieve the non-repitition goal, I've used > async I/O, restricted my use of real threads in popular languages to > trivial cases, and started using servers so someone else gets tod eal > with these issues. Then maybe we should listen to those other people. Is there a successful single-line-of-execution async-I/O based server that provides a service as sophisticated as the modern relational- database engines? Why do you think that is? -- --Bryan From Scott.Daniels at Acm.Org Sat Aug 20 13:26:37 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 20 Aug 2005 10:26:37 -0700 Subject: [newbie]search string in tuples In-Reply-To: References: Message-ID: <43075bec$1@nntp0.pdx.net> Viper Jack wrote: > Hi all, > i'm new to python programming so excuseme if the question is very stupid. > here the problem. > this code work > > list=["airplane"] > select=vars > while select != list[0]: > select=raw_input("Wich vehicle?") > > but i want check on several object inside the tuple so i'm trying this: > > list=["airplane","car","boat"] > select=vars > while select != list[0] or list[1] or list[2]: > select=raw_input("Wich vehicle?") > > but loops and doesn't want work. > I have tried with other methods (for) but nothings. > I haven't find nothing on this topic, so i asked here. > Thanks in advance. Normally you'd define a function doing the search and use it. Don't be afraid to use more lines if your code is clear. First, avoid using list as a name, it is already defined. Second, None is the standard constant not really anything value. def missing(element, source): for part in source: if element == part: return False return True vehicles = ["airplane", "car", "boat"] select = None while missing(select, vehicles): select = raw_input("Which vehicle?") For this particular test, there happens to be an idiom you can use: vehicles = ["airplane", "car", "boat"] select = None while select not in vehicles: select = raw_input("Which vehicle?") --Scott David Daniels Scott.Daniels at Acm.Org From bdesth.quelquechose at free.quelquepart.fr Thu Aug 11 17:52:00 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 11 Aug 2005 23:52:00 +0200 Subject: need help with python syntax In-Reply-To: <1123786609.621111.324390@g49g2000cwa.googlegroups.com> References: <1123786609.621111.324390@g49g2000cwa.googlegroups.com> Message-ID: <42fbc0fa$0$11587$636a15ce@news.free.fr> yaffa a ?crit : > dear python gurus, One effectively needs to have some guru-powers to answer you question... > quick question on syntax. > > i have a line of code like this > > for incident in bs('tr', {'bgcolor' : '#eeeeee'}): > > > what i want it to do is look Where ? > for 'bgcolor' : '#eeeeee' or 'bgcolor' : > 'white' and then do a whole bunch of stuff. > > i've tried this: > > for incident in bs('tr', {'bgcolor' : '#eeeeee'} or {'bgcolor' : > 'white'} ): What do you think the expression {'bgcolor' : '#eeeeee'} or {'bgcolor' :'white'} evaluate to ? (hint 1: Python has an interactive interpreter that let you test expressions on the fly) (hint 2: http://www.python.org/doc/2.4.1/ref/Booleans.html) > but it only seems to pick up the stuff from the > {'bgcolor' : '#eeeeee'} Yes. That's very very True. > > any ideas folks? > Yes. 1/ consider learning enough of Python to understand what you are doing. 2/ consider reading the doc (or the source code, which is usually the most accurate documentation...) of 'bs()' (wherever this comes from). Anyway, if you hope us to *guess* what it does and what args it expects to do it, you're just plain wrong - sorry, but we (well, I at least) don't have the expected psychic mind-reading skills necessary to answer your question without much informations. And, BTW, the bitwise or operator (|) won't help... From danb_83 at yahoo.com Fri Aug 5 11:48:59 2005 From: danb_83 at yahoo.com (Dan Bishop) Date: 5 Aug 2005 08:48:59 -0700 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: <1123256939.657911.280510@f14g2000cwb.googlegroups.com> Terry Reedy wrote: > "Daniel Sch?le" wrote in message > news:dcvqc2$8oi$1 at news2.rz.uni-karlsruhe.de... ... > > unfortunately there is no arg method to get the angle > > of the complex number > > I agree that this is a deficiency. I would think .angle() should be a > no-param method like .conjugate(), though its internal implementation would > need access to the appropriate cmath functions. You need math, not cmath. def arg(z): """The Argument of z, in radians.""" z += 0j # make it work on real inputs return math.atan2(z.imag, z.real) From mwh at python.net Tue Aug 30 13:11:47 2005 From: mwh at python.net (Michael Hudson) Date: Tue, 30 Aug 2005 17:11:47 GMT Subject: micro-python - is it possible? References: <431440bb$1@news.orcon.net.nz> Message-ID: Magnus Lycka writes: > Evil Bastard wrote: >> Hi, >> Has anyone done any serious work on producing a subset of python's >> language definition that would suit it to a tiny microcontroller >> environment? > > Isn't pypy meant to support different backends with different > requirements and constraints using the same basic language? Yup, not part of the project that I'm involved in, but it's part of the plan. Cheers, mwh -- 59. In English every word can be verbed. Would that it were so in our programming languages. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From provato at gmail.com Tue Aug 16 18:12:00 2005 From: provato at gmail.com (DK) Date: 16 Aug 2005 15:12:00 -0700 Subject: stopping a python windows service Message-ID: <1124230320.593335.288650@g44g2000cwa.googlegroups.com> i was able to successfully create a windows service using py2exe. it polls a website periodically and logs it to a file. this is done using a function that does an infinite loop with periodic "sleeps". my question is... what's the best way to stop this service gracefully? when try to stop it from the services applet from control panel, it takes forever and then gives me an error. currently, the only way i am able to stop it is using the task manager and killing the process. From googlenews at tooper.org Tue Aug 30 05:23:52 2005 From: googlenews at tooper.org (tooper) Date: 30 Aug 2005 02:23:52 -0700 Subject: Python port on Palm Treo? In-Reply-To: <3ngpgqF1fdulU1@individual.net> References: <3ngpgqF1fdulU1@individual.net> Message-ID: <1125393832.254494.39750@o13g2000cwo.googlegroups.com> I'm not aware of any Treo dedicated port, but as Treo is running Palm, the Palm port of Python should be OK (if I remember well it's pypi or pipy, standing for PYthon for palm PIlot) Hope it helps... From tjreedy at udel.edu Fri Aug 5 16:07:12 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 5 Aug 2005 16:07:12 -0400 Subject: why no arg, abs methods for comlex type? References: Message-ID: "Daniel Sch?le" wrote in message news:dd03cn$f7c$1 at news2.rz.uni-karlsruhe.de... > > I agree that this is a deficiency. I would think .angle() should be a > > I don't know what nomenclature is used in english speaking > mathematical world for angle of a complex number > I learned it in german as Arg(z) .. Arg standing for argument > you see, we would have named it differently, hence making > it difficult for the reader, eventually creating redundancy I am aware of the usage of argument to mean the angle in polar representation, but I don't like it. The word argument already has two other meanings, one in common English, the other in math/CS. The latter meaning is the inputs to a function, and that is how the word is used in Python (though the former applies more to many c.l.p threads ;-) To me, the polar angle has no connection with either meaning and so the usage is 'like Greek' to me. Whereas angle is exactly what it is. As for Greek: I first learned r(adius),theta (versus x,y or real,imag) as the names for polar coordinates or the polar representation for complex numbers and only ran into arg much later in some contexts. And I have seen complex number implementations that use the equivalent of c.r() and c.theta(). But I did not suggest that for one of the reasons I don't like 'lambda': its fine if you already know it and arbitrary if you don't. (Is theta used in Germany?) > > It is possible that a cmath2 module, written in Python, could be > > useful. > > I hope so > I will google for cmath2, I never heard about it That is because we have not written it yet. The allroots function could be the first addition, if it is not present elsewhere. The 'could be' was meant in the sense of 'if someone were to write it' rather than 'if you were to read it' ;-) Terry J. Reedy From pink at odahoda.de Wed Aug 10 12:48:32 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 10 Aug 2005 18:48:32 +0200 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Message-ID: Qopit wrote: > [snip] > > My questions are: > - Am I missing something with my tester example? > - Are there other code-checking options other than PyChecker? Try pylint -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From lbates at syscononline.com Fri Aug 19 18:19:18 2005 From: lbates at syscononline.com (Larry Bates) Date: Fri, 19 Aug 2005 17:19:18 -0500 Subject: trying to check the creation date of a file In-Reply-To: References: Message-ID: <43065AE6.4080508@syscononline.com> use os.stat docs are here: http://docs.python.org/lib/module-stat.html Larry Bates David Fickbohm wrote: > People, > > I am trying to determine the creation date of files in a folder. > I am using the following code to find the folder and confirm that files > exist in the folder. If someone could give me an idea how to check a > creation date it would be appreciated. > Thanks > dave > > def delete_old_files (t:\dm\~\users) > # find files and delete files created more than XX number of days > ago > update_exist = 0 > > input_dir = t:\dm\~\users\xxxx.yyyyyy\zzzz > > if os.path.exists (input_dir) : > files = os.listdir (input_dir) > else: > print "Unable to find input file dir: %s !!!" % input_dir > sys.exit(2) > > if len(files): > for file in files : > > file = os.path.join(input_dir) #all files in output > directory will be csv or xls, can be deleted if old enough > > if os.path.isfile(file): #need to check ext not file, file > name changes each day > if re.search(t:\dm\~\users\xxxxx\) and #creation date > gt x number of days ago > t:\dm\~\users\davef.input_list.delete(file) > > file_delete = 1 > > if file_delete: > > print "\n file deleted: \n%s" % > str(t:\dm\~\users\xxxxx.input_list) > > return file_delete > > Dave Fickbohm > Data Mining Analyst > Homegain+ > 1250 45th St. > Emeryville, CA, 94608 > Phone 510 594 4151 - Voice > 510 655 0848 - Fax > > From franz.steinhaeusler at gmx.at Mon Aug 1 11:07:34 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Mon, 01 Aug 2005 17:07:34 +0200 Subject: Getting not derived members of a class References: <1122907402.650512.213470@g47g2000cwa.googlegroups.com> Message-ID: On 1 Aug 2005 07:43:22 -0700, "George Sakkis" wrote: >Franz Steinhaeusler wrote: > >> Hello NG, >> >> I want to retrieve the members of a class >> with a baseclass. >> But the problem is, how to get the non derived >> members. >> >> class a: >> def who(self): >> print "who" >> def __init__(self): >> self._a = 3 >> >> class b(a): >> def who1(self): >> print "who1" >> def __init__(self): >> a.__init__(self) >> self._b = 4 >> >> y=b() >> >> dir (y) >> ['__doc__', '__init__', '__module__', '_a', '_b', 'who', 'who1'] >> >> >> I need a function which lists only the members of >> the "not derived" class (here class B). >> >> _b >> _who1 >> __init__ >> >> How can I achieve this? >> With the introspect module or so? > >I believe you can't: Both _a and _b end up in y.__dict__ and there's no >way to differentiate between the two depending on the time of their >creation. By the way, these are instance attributes, not class >attributes, so strictly _b is not a member of B, it's just an instance >of y. To see why this is the case, check the following valid (though >highly discouraged) example: > >class X: > def __init__(self, x): > if isinstance(x,str): > self._s = x > else: > self._n = x > >x1 = X("1") >x2 = X(1) > >dir(x1) >['__doc__', '__init__', '__module__', '_s'] > >dir(x2) >['__doc__', '__init__', '__module__', '_n'] > > >George Hello George, thank you for this information. This is a pity. The background: I want to create a code completition for an editor component. It should distinguish between inherited and non inherited members. Reason is, that on wxPython, most classes are derived from wxWindow. For example if I want Code completition for wx.Frame, I always get the 200 or so suggestions, whereby most times, I'm only interested in the possible completions of wx.Frame and maybe wx.TopLevelWindow. -- Franz Steinhaeusler From martin at v.loewis.de Mon Aug 1 01:43:12 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 01 Aug 2005 07:43:12 +0200 Subject: Enumerate registered codecs In-Reply-To: <3l5gjaF10ep3kU1@individual.net> References: <3l49j2F10qginU1@individual.net> <42ed3d5e$1@news.eftel.com> <3l5gjaF10ep3kU1@individual.net> Message-ID: <42edb670$0$6926$9b622d9e@news.freenet.de> Paul Watson wrote: > The primary identifier and a descriptive string (localized) need to be > available at a minimum. Having aliases would be a plus. You will have to implement your own list. Getting the well-known aliases is possible through encodings.aliases, but a localized descriptive string was never part of the design - this is something the application will have to provide. Regards, Martin From eric_brunel at despammed.com Fri Aug 19 07:01:52 2005 From: eric_brunel at despammed.com (Eric Brunel) Date: Fri, 19 Aug 2005 13:01:52 +0200 Subject: Problem (or even bug?) with Tkinter References: Message-ID: On Fri, 19 Aug 2005 09:53:20 +0100, Matt Hammond wrote: > Here's a strange one in Tkinter that has me stumped: > (I'm running python 2.4 on Suse Linux 9.3 64bit) > > I'm trying to make a set of Entry widgets with Label widgets to the left > of each one, using the grid layout. If I make and grid the Label *before* > the Entry then the Entry widget doesn't seem to work - it lets me put the > cursor in it, but I can't type! See example code below. > > Is this just me doing something really really silly, or is there a bug > here? I tested with Python 2.1 on Mandrake Linux 8.0 and it works fine. My tcl/tk version is 8.3.4 Do you know the tcl/tk version you have? If you don't, you can get it via: from Tkinter import Tk() root = Tk() root.tk.eval('puts $tk_patchLevel') I suspect a bug at tcl level. So can you execute the following tcl script: ------- entry .en1 grid .en1 -row 0 -column 1 label .lb1 -text "CAN WRITE ->" grid .lb1 -row 0 -column 0 label .lb2 -text "CAN'T WRITE ->" grid .lb2 -row 1 -column 0 entry .en2 grid .en2 -row 1 -column 1 ------- It is exactly the same as yours in tcl syntax. To execute it, just save it to the file script.tcl and type in a shell: wish script.tcl (The "wish" command may include a version number, such as "wish8.4") If the script above shows the same behaviour as your Python script, then it's not Tkinter's fault, but tk's. You should then report the bug to comp.lang.tcl. HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 26 03:41:11 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 26 Aug 2005 09:41:11 +0200 Subject: Setting the encoding in pysqlite2 In-Reply-To: <1124957755.392563.197910@z14g2000cwz.googlegroups.com> References: <1124957755.392563.197910@z14g2000cwz.googlegroups.com> Message-ID: <3n7vcnF8theU1@individual.net> Michele Simionato wrote: > An easy question, but I don't find the answer in the docs :-( > I have a sqlite3 database containing accented characters (latin-1). > How do I set the right encoding? For instance if I do this: I think you should ask on the pysqlite-devel list. Reinhold From superprad at gmail.com Tue Aug 23 17:07:15 2005 From: superprad at gmail.com (PyPK) Date: 23 Aug 2005 14:07:15 -0700 Subject: Line Removal strategy Message-ID: <1124831235.877424.45160@g49g2000cwa.googlegroups.com> Hi I am looking for a simple algorithm for removing straight lines in a given Image using something like an PIL or simpler. From fakeaddress at nowhere.org Mon Aug 29 16:17:39 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 29 Aug 2005 20:17:39 GMT Subject: global interpreter lock In-Reply-To: <861x4dy77g.fsf@bhuda.mired.org> References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <868xyw9g30.fsf@bhuda.mired.org> <86slwymx79.fsf@bhuda.mired.org> <7xoe7kjsag.fsf@ruckus.brouhaha.com> <3dpQe.22$tz6.13@newssvr27.news.prodigy.net> <861x4dy77g.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Bryan Olson writes: > phil hunt wrote: > >> > What's important is *predictability*, e.g. which instruction will >> > the computer execute next? >> > >> > If you only have one thread, you can tell by looking at the code >> > what gets executed next. It's very simple. >>Not really. Trivially, an 'if' statement that depends upon input >>data is statically predictable. Use of async I/O means makes the >>programs execution dependent upon external timing. > > > Yes, but that depenency is tied to a single point - the select > call. The paths after that are statically predictable. This makes the > code very managable. Wow -- I could not disagree more. Returning back to some single point for every possibly-blocking operation is painful to manage even for simple GUIs, and humanly intractable for sophisticated services. Select is certainly useful, but it scales badly and isn't as general as better tools. > [...] I'm calling the tools available in most programming > languages for dealing with it primitive. > > We need better tools. Agreed, but if 'select' is someone's idea of the state of the art, they have little clue as to the tools already available. Bringing the tools to Python remains a bit of challenge, largely because so many Pythoners are unaware. -- --Bryan From mscottschilling at hotmail.com Thu Aug 25 11:39:35 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Thu, 25 Aug 2005 15:39:35 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: "CBFalconer" wrote in message news:430D7366.C2126F6D at yahoo.com... > Mike Schilling wrote: >> "Mike Meyer" wrote in message >>> "Mike Schilling" writes: >>>> "l v" wrote in message >>>>> Xah Lee wrote: >>>>> >>>>>> (circa 1996), and email should be text only (anti-MIME, circa 1995), >>>>> >>>>> I think e-mail should be text only. I have both my email and >>>>> news readers set to display in plain text only. It prevents >>>>> the marketeers and spammers from obtaining feedback that my >>>>> email address is valid. A surprising amount of information >>>>> can be obtained from your computer by allowing HTML and all >>>>> of it's baggage when executing on your computer. Phishing >>>>> comes to my mind first and it works because people click the >>>>> link without looking to see where the link really takes them. >>>> >>>> A formatting-only subset of HTML would be useful for both e-mail >>>> and Usenet posts. >>> >>> Used to be people who wanted to send formatted text via email >>> would use rich text. It never really caught on. But given that >>> most of the people sending around formatted text are using >>> point-n-click GUIs to create the stuff, the main advantage of >>> HTML - that it's easy to write by hand - isn't needed. >> >> But the other advantage, that it's an existing and popular >> standard, remains. > > However, for both e-mail and news, it is totally useless. Useless except in that it can describe formatting, which is what it would be used for? ( > It also > interferes with the use of AsciiArt, Except that it can specify the use of a fixed-width font, which makes Ascii Art work. It can also distinguish between text that can be reformatted for flow and text than can not. So I think you meant to say that it *enables* Ascii Art. > while opening the recipient to > the dangers above. Which is why a formatting-only subset, which doesn't cause any such dangers, is required. As I said above. Another advantage is that evewry internet-enabled computer today already comes with an HTML renderer (AKA browser), so that a message saved to a file can be read very easily. From mail at tuxipuxi.org Thu Aug 11 11:46:15 2005 From: mail at tuxipuxi.org (Michael Goettsche) Date: Thu, 11 Aug 2005 17:46:15 +0200 Subject: Writing a small battleship game server in Python Message-ID: <200508111746.15668.mail@tuxipuxi.org> Hi there, for a project in our computer science lessons at school we decided to write a client/server based battleship like game [1]. I know this game could be written without a server, but the whole project is for educational purposes. Being the initiator of this project, I thought I would write a skeleton for it before we actually start with it. The client thing won't be too hard, what I'm having problems with is the server, maybe because I have problems understanding what's the best way to accept connections and handle existing ones. So, here is my problem: The server should accept connections from new players and be able to handle multiple games concurrently. The main purpose of the server will be to make sure the clients follow the rules(only shoot once, shoot only existing fields, ...) and inform clients about game end etc.. What would be a good, but still easy way to write such a server? In a socket tutorial [2] I read the usual way to write a server is to create a server socket and then listen for connections in an infinite loop. I understand that part, but how should I handle connections then? Start a thread for each game and put every two new players in it? Or does Python offer a better solution to do this? Twisted can be a solution too, but this server should run on standard python installations and Twisted might be a bit too heavy for our project. Thank you. Best Regards, Michael Goettsche. [1]: For those who don't know the game: It's played by two players. Each player has a game board where he places a predefined number of ships. After placing the ship, the players try to shoot the enemy's ships (but they don't know where they are). The game is round-based, so player A may shoot once, then it's player B's turn and then A again and so on until one player has shot all ships of the enemy. [2]: http://www.amk.ca/python/howto/sockets/ From godoy at ieee.org Tue Aug 9 10:18:19 2005 From: godoy at ieee.org (Jorge Godoy) Date: Tue, 09 Aug 2005 11:18:19 -0300 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com wrote: > The IDE what have been using/experimenting with are drPython and > eclipse with PyDev. Eclipse has a fine integration with both CVS and Subversion. If you'll be having a lot of images and binary objects or you don't have the design right by the time you start coding, I'd recommend on using Subversion. If you do, both are good. Why Subversion? Because you'll be able to move files around without loosing their history or without loosing the old filename in the repository. One dawback is that you'll have to install the Subclipse plugin to use Subversion, while CVS is already there... But it's as easy as pointing a new update/install site and clicking on the desired package. We use both here and recently we've migrated to Subversion as our main VCS. We noticed that there was a reduction in disk space that can be very significative depending on the type of file that you'll be working with. -- Jorge Godoy From mwm at mired.org Sat Aug 27 14:35:05 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 27 Aug 2005 14:35:05 -0400 Subject: Writing portable applications (Was: Jargons of Info Tech industry) References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> Message-ID: <86acj3ut2e.fsf_-_@bhuda.mired.org> Ulrich Hobelmann writes: > Mike Meyer wrote: >>> This can be designed much better by using iframes, maybe even Ajax. >> Definitely with Ajax. That's one of the things it does really well. > But then you're probably limited to the big 4 of browsers: MSIE, > Mozilla, KHTML/Safari, Opera. Ok, that should cover most desktop > users, but you might run into problems on embedded. True - using Ajax definitely defeats what I consider to be the best feature of the web. >>>> Why can't we use the Web for what it was meant for: viewing hypertext >>>> pages? Why must we turn it into a wrapper around every application >>>> imaginable? >>> Because it works? >> Because you can - if you know how to use HTML properly - distribute >> your application to platforms you've never even heard of - like the >> Nokia Communicator. > If the NC has software that can properly interpret all that HTML, CSS, > JavaScript plus image formats, yes. But who guarantees that? You don't need that guarantee. All you need is a reasonable HTML renderer. The folks at W3C are smart, and did a good job of designing the technologies so they degrade gracefully. Anyone with any competence can design web pages that will both take advantage of advanced technologies if they are present and still work properly if they aren't. Yeah, the low-end interface harks back to 3270s, but IBM had a *great* deal of success with that technology. > I'd rather develop a native client for the machine that people > actually WANT to use, instead of forcing them to use that > little-fiddly web browser on a teeny tiny display. You missed the point: How are you going to provide native clients for platforms you've never heard of? > And again: connections might be slow, a compact protocol is better > than loading the whole UI every time. And while Ajax might work, > despite the UI being maybe too big for the little browser window, and > even if it works, it's still probably more work than a simple, native > UI. First of all it needs to load all the JS on first load, secondly > sometimes for a flexible UI you'd have to replace huge parts of the > page with something else. Native UIs are more up to the task. I'm not arguing that native UI's aren't better. I'm arguing that web applications provide more portability - which is important for some applications and some developers. >> I started writing web apps when I was doing internal tools development >> for a software development company that had 90+ different platform >> types installed inhouse. It was a *godsend*. By deploying one > If that's 90+ GUI platforms, then I agree. Why do you care if they are GUI or not? If you need to provide the application for them, you need to provide the application for them. Them not being GUI just means you can't try and use a standard GUI library. It also means you have to know what you're doing when you write HTML so that it works properly in a CLUI. But your native app would have to have a CLUI anyway. > I just wonder who wrote fully standards compliant web browsers for > those 90 platforms. Nobody. I doubt there's a fully standards compliant web browser available for *any* platform, much less any non-trivial collection of them. You write portable web applications to the standards, and design them to degrade gracefully. Then you go back and work around any new bugs you've uncovered in the most popular browsers - which historically are among the *worst* at following standards. > If you have one Windows GUI (maybe C#), one Mac GUI (Cocoa), one Gtk > GUI for X, you're done. You think you're done. A lot of developers think you can stop with the first one or two. You're all right for some applications. For others, you're not. Personally, I like applications that run on all the platforms I use - and your set doesn't cover all three of those systems. >> well-written app, I could make everyone happy, without having to do >> versions for the Mac, Windows, DOS (this was a while ago), getting it >> to compile on umpteen different Unix version, as well as making it >> work on proprietary workstation OS's. > Well, stick to POSIX and X APIs and your stuff should run fine on > pretty much all Unices. You know, the same kind of advice applies to writing portable web apps. Except when you do it with HTML, "portability" means damn near any programmable device with a network interface, not some relatively small fraction of all deployed platforms. > I never understood those people who write all kinds of weird ifdefs > to on all Unices. Maybe that was before my time, during the > Unix wars, before POSIX. There were standards before POSIX. They didn't cover everything people wanted to do, or didn't do them as fast as the OS vendor wanted. So Unix vendors added their own proprietary extensions, which software vendors had to use to get the best performance out of their applications, which they had to do if they wanted people to buy/use them. That's still going on - people are adding new functionality that isn't covered by POSIX to Unix systems all the time, or they are adding alternatives that are better/faster than the POSIX version, and there are lots of things that applications want to do that simply aren't covered by POSIX. And not all implementations are created equal. Some platforms malloc's provide - to be polite - less than optimal performance under conditions real applications encounter, so those applications conditionally use different malloc implementations. The same thing applies to threads, except such code typically includes a third option of not using threads at all. And so on. And we haven't even started talking about the build process... Basically, deciding to write to POSIX is a decision to trade away performance on/to some platforms for portability to more platforms. It's the same decision as deciding to write a web app, except the tradeoffs are different. Each of the three solutions has a different set of costs and benefits, and the correct choice will depend on your application. > And if it's not Unix, what's a prop. workstation OS? They've mostly died out since then. At the time, there were things like Domain and VMS. >> Of course, considering the state of most of the HTML on the web, I >> have *no* idea why most of them are doing this. > Yep. Maybe it would be best to reengineer the whole thing as ONE UI > spec+action language, incompatible with the current mess, compact, so > it can be implemented with minimum fuss. And most of all, I wouldn't > use a MARKUP language, as a real application is not text-based (at > least not as characteristic #1). You mean most of the applications I run aren't real applications? Right now, my desktop has exactly two GUI applications open on it - a mixer and gkrellm. Everything else is characeter based. Hell, even my window manager is character based. I think you're right - a web standard designed for writing real applications probably wouldn't start life as a markup for text. The only thing I can think of that even tries is Flash, but it's proprietary so I don't know much about it. Care to tell me how you would design such a format if the goal were to *not* lose any portability - which means it has to be possible to design interfaces that work properly on character devices, things like Palms three-color greyscale displays, and devices without pointers or without keyboards, or even in an audio-only environment. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From http Tue Aug 30 05:10:24 2005 From: http (Paul Rubin) Date: 30 Aug 2005 02:10:24 -0700 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> Message-ID: <7xhdd7okn3.fsf@ruckus.brouhaha.com> Bryan Olson writes: > Specifically, to support new-style slicing, a class that > accepts index or slice arguments to any of: > > __getitem__ > __setitem__ > __delitem__ > __getslice__ > __setslice__ > __delslice__ > > must also consistently implement: > > __len__ > > Sane programmers already follow this rule. It should be ok to use new-style slicing without implementing __len__ as long as you don't use $ in any slices. Using $ in a slice without __len__ would throw a runtime error. I expect using negative subscripts in old-style slices on objects with no __len__ also throws an error. Not every sequence needs __len__; for example, infinite sequences, or sequences that implement slicing and subscripts by doing lazy evaluation of iterators: digits_of_pi = memoize(generate_pi_digits()) # 3,1,4,1,5,9,2,... print digits_of_pi[5] # computes 6 digits and prints '9' print digits_of_pi($-5) # raises exception From tjreedy at udel.edu Fri Aug 5 16:13:10 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 5 Aug 2005 16:13:10 -0400 Subject: Do I need to have site.py available or not ? References: <1123257409.099201.114960@g49g2000cwa.googlegroups.com> Message-ID: wrote in message news:1123257409.099201.114960 at g49g2000cwa.googlegroups.com... > Hi, > on startup my embedded python comes up with "import site failed use > -v". Later python crashes on Pyrun_file(). This is the first time I > have used python and I would like to know does it require site.py to be > read in, and has anyone got an idea how to pass in the -v without using > the python -v command, ie the embedded way. Thanks very much. If by embedded you mean embedded in a C/C++ program, I would look to the doc for the C API function that you use to start it up to see whether there is a way to pass in argv flags or to have the same effect. TJR From enleverlesO.OmcO at OmclaveauO.com Tue Aug 16 01:53:03 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Tue, 16 Aug 2005 07:53:03 +0200 Subject: COM access sooo slow !? References: <1123956653.745700.220980@g49g2000cwa.googlegroups.com> Message-ID: <4301834a$0$15576$8fcfb975@news.wanadoo.fr> Hi ! I use a COM server, made with Python & Win32all (PyWin32). The speed of function's call is : 5 seconds, for 100 000 calls. Only the first call is slow (due to time to load Python...) Config : W-XP, P.2.4.1, 1.6 GHz, 512MB RAM @-salutations & sorry for my bad english Michel Claveau From dcrespo at gmail.com Mon Aug 15 09:24:53 2005 From: dcrespo at gmail.com (dcrespo) Date: 15 Aug 2005 06:24:53 -0700 Subject: SOAP and XMLRPC Message-ID: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Hi to all... Someone knows if is there possible to have a Python SOAP or XMLRPC server that works with VB? I would like you to include the examples clients and server programs. My examples are: #Server.py import SOAPpy def sum(x,y): return x+y server = SOAPpy.SOAPServer(("localhost", 8080)) server.registerFunction(sum) server.serve_forever() #client.py import SOAPpy server = SOAPpy.SOAPProxy("http://localhost:8080") print server.sum(5,6) #This should print: 11 These programs work perfect. The thing is that I need to access the server from VB (like does SOAPpy accessing google's services) Many thanks Daniel From hancock at anansispaceworks.com Sun Aug 14 14:42:02 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sun, 14 Aug 2005 13:42:02 -0500 Subject: A PIL Question In-Reply-To: <1124040878.557813.311900@g47g2000cwa.googlegroups.com> References: <1124040878.557813.311900@g47g2000cwa.googlegroups.com> Message-ID: <200508141342.02285.hancock@anansispaceworks.com> On Sunday 14 August 2005 12:34 pm, Ray wrote: > import Image > > im = Image.open("something.jpg") > seq = im.getdata() > > image = Image.Image() > image.putdata(seq) > > image.show() > > I always get: > > Traceback (most recent call last): > File "Script1.py", line 31, in ? > image.putdata(seq) > File "D:\Development\Python24\Lib\site-packages\PIL\Image.py", line > 1120, in putdata > self.im.putdata(data, scale, offset) > AttributeError: 'NoneType' object has no attribute 'putdata' > > Anybody has any idea why this is the case? Well, obviously you didn't get an image back from Image.Image(). In fact, I suspect you would've at least have to have given it a size or something. It clearly returned None, and you're trying to call a method that None doesn't have, like it says. Definitely check the PIL manual for what Image.Image() is supposed to return, and what it requires to have valid output. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From ptmcg at austin.rr.com Tue Aug 16 09:34:46 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 16 Aug 2005 06:34:46 -0700 Subject: looping list problem In-Reply-To: References: Message-ID: <1124199286.723654.5780@g47g2000cwa.googlegroups.com> Well, you are returning prematurely from a for loop, so that is why you are only getting the first value. Its just like: for i in range(1000000): return i It doesn't matter how big the range is you are iterating over, you'll return on the first element and that's it. If what you want is the list, then return the list: hiddennavelements = navstring.split(' ') return hiddennavelements I think Fredrik Lundh was trying to accommodate your mixed thinking by assuming your code was from a generator function. With a generator, you *can* return successive elements of a list, but you use the 'yield' keyword instead of 'return', and repeated calls to the generator return each successive value. -- Paul From spammers-go-here at spam.invalid Wed Aug 17 12:07:00 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 17 Aug 2005 12:07:00 -0400 Subject: Testing for presence of arguments References: <430353e1$0$18641$14726298@news.sunsite.dk> <1124293800.587084.302130@g43g2000cwa.googlegroups.com> Message-ID: <43036087$0$18639$14726298@news.sunsite.dk> Diez B. Roggisch wrote: > I don't have the details ready - but in the ASPN cookbook are recipes > to e.g. figure insied a function f out how many results the caller of f > expects - and act accordingly. This boils down to inspect the > call-stack. So it ceratinly is possible. > > However, I'd say it is almost 100% a design flaw. Or can you give us a > compelling reason why you need this behaviour? > > Diez I am writing some code for a measurement application (would have used fortran 95 if a library had been available for linux-gpib, but python is a lot friendlier than C without the irritating and utterly pointless braces) where one of the input parameters for the GPIB command is optional, and depending on whether it is specified at all, an entire sequence of commands has to be sent to the GPIB bus plus some input parameters recalculated. Further, the sequence of commands depends on the range of values of the optional parameter. And some of these commands in turn have similar optional arguments. All in all, the above would have been a bunch of simple one-liners with a simple if block if python had something like the fortran 95 present() intrinsic, but I could not find it. Hence my query. Just because there is no simple and direct way of doing something in a language does not mean that the application that requires it has a design flaw. Unrelated question, how does one call a fortran 95 subroutine from python ? I need really high speed of execution for that call (needed for each measurement point, and is used to calculate some parameters for the excitation for the next measurement point) and a scripting language would not cut it. From randy at psg.com Sun Aug 28 00:36:00 2005 From: randy at psg.com (Randy Bush) Date: Sat, 27 Aug 2005 18:36:00 -1000 Subject: trictionary? Message-ID: <17169.16176.556417.938640@roam.psg.com> i have some code which looks kinda like bin = {} for whatever: for [a, b] in foo: x = 42 - a y = 42 - b if bin.has_key(x): bin[x] += 1 else: bin[x] = 1 for i, j in bin.iteritems(): print i, j now i want to add a second count column, kinda like bin = {} for whatever: for [a, b] in foo: x = 42 - a if bin.has_key(x): bin[x.b] += 1 else: bin[x.b] = 1 bin[x.not b] = 0 for x, y, z in bin.iteritems(): print x, y, z should the dict value become a two element list, or is there a cleaner way to do this? randy From sybrenUSE at YOURthirdtower.com.imagination Thu Aug 25 11:37:39 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Thu, 25 Aug 2005 17:37:39 +0200 Subject: loop in python References: <1124964483.645753.190460@g47g2000cwa.googlegroups.com> Message-ID: Peter Hansen enlightened us with: > Yes, and has shown that they are in the same ballpark, and therefore > one does not _need_ to compare speed any more. Ok. I'd worded it as "there have been tests already, so there is no need to do your own", instead of "one does not test". Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From fakeaddress at nowhere.org Wed Aug 31 08:14:35 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 31 Aug 2005 12:14:35 GMT Subject: OpenSource documentation problems In-Reply-To: References: Message-ID: Terry Hancock wrote: > Bryan Olson wrote: > >>I don't see any need to look beyond Python for a good example of >>poor documentation. Are there serious Python programmers who >>don't constantly struggle with errors and omissions in the doc? > > Uh, yes, actually. > > IMHO, the available Python documentation is, extremely helpful, > concise and accessible. Maybe you aren't using all of it: A plausible theory. I have some possibly-illustrative examples of what I ran into within the last few weeks. > 1) Remember that any object or module you load will tell you > its contents with a dir() or give you automatically generated > documentation with help(). This documentation has the advantage > of being almost always accurate and up-to-date, even if it is > sometimes too brief and poorly explained. I use dir() all the time; help() not so much. Typing help(help) shows: Help on _Helper in module site: Type help() for interactive help, or help(object) for help about object. That strikes me as not-particularly-helpful. Surely it should at least direct the user to 'pydoc.help'. > 2) More in-depth documentation for the Python standard library > is available in the "Library Reference". This covers everything > from built-in functions to fairly obscure modules that are nevertheless > in the Python library. Three weeks ago, in trying to explain a point about Python's zlib module, I discovered that the doc was wrong. http://groups.google.com/group/comp.lang.python/msg/20609fff71a2ed02 The Python standard library is certainly useful, but in my opinion the bar is set too low. > 3) Questions about the functioning of the language are most accurately > resolved by trying them out in the interpreter. This is usually > faster than any documentation search. Python's interpreter is extremely > friendly and easy to start up, so this is really easy to do. Then how does one distinguish stable, supported services, from incidental behavior that can change without notice? > 4) But if you want a more theoretical and explained version of the > language, there's always the "Language Reference". Which is what steered me wrong on the behavior of slice objects: http://groups.google.com/group/comp.lang.python/msg/66014427182265b9 That one cost me a hours, mostly because when I my own code misbehaves in certain cases, a language/doc bug is not my first guess. > Between these 4 sources, I can resolve almost any question that > comes up about the core Python language. > > Somewhat more obscure applications are covered by the "Extending > and Embedding" document, and there are other documents and tutorials > either in your Python distribution (if you have a good one) or on > the http://www.python.org website). Three days ago, I wanted to know how to call C from Python, and the "Extending and Embedding" document told me: (I won't dwell on how to call the Python parser with a particular string as input -- if you're interested, have a look at the implementation of the -c command line option in Python/pythonmain.c from the Python source code.) I got the Python source distribution, and couldn't find that file. So I went to the CVS archive, and still couldn't find the file. I don't think it exists. Had that doc just said nothing about it, I probably would have found PyRun_SimpleString and its siblings in a few minutes. I suspect the document is out of date, as it also seems to teach the use of deprecated methods. Whatever else one says about open-source documentation, keeping it current is a major unsolved problem. > If you're really looking for cookbook examples, there are specific > websites to check for, though I usually just hit Google with a > few keywords. And if all that fails you, you can always ask the > people on this list. I'm with you on that. (I used to work for Google, where finding the doc means eating the dog-food.) I find that for any popular software, typing error messages into Google yields a better results-to-effort ratio than trying to look them up in a manual. > I have NEVER seen a closed source application or programming > language that came with that much documentation and support. I'm no fan of Microsoft, but in general, the Win32 API is far better documented than is Python. (Just don't use the searching facilities on the MSDev CD's to find the doc; Google it up.) [...] > I also have to say, that as a module writer, Python's support > for self-documenting code or "literate programming" is excellent. > I'm really coming to appreciate the value of this. Unfortunately, it's also full of traps. -- --Bryan From sjmachin at lexicon.net Sat Aug 13 22:07:19 2005 From: sjmachin at lexicon.net (John Machin) Date: Sun, 14 Aug 2005 12:07:19 +1000 Subject: socket setdefaulttimeout In-Reply-To: <0gpsf1l8csfmsn2r0b7nlvj7cbe8mvr10o@4ax.com> References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> <0gpsf1l8csfmsn2r0b7nlvj7cbe8mvr10o@4ax.com> Message-ID: <42fea756$1@news.eftel.com> Dennis Lee Bieber wrote: > > I've got the opposite problem -- I'm on a dial-up (well, for a few > more weeks -- until the DSL gear arrives). For some reason DNS lookups > seem to be low priority and, if I'm downloading messages in Agent (from > three servers yet) and email (Eudora), Firefox often comes back with a > "host not found"; enter the same URL/bookmark again, and it finds the > page. It seems my system times out DNS requests when 1) I have a lot of > traffic on the dial-up connection, 2) the request may need to be > traversed (not cached on Earthlink) Dragging the thread off-topic a little: I was having a similar DNS problem (host not found, try again immediately, 2nd try successful) but even in a no-other-load situation, and with this set of gear: * ADSL with Netgear DG834G v2 "wireless ADSL firewall router" * both hardwired and wireless LAN connection to router * Firefox, Thunderbird [normally] * IE6, Outlook Express [just to test if it was a Mozilla problem] * Windows XP Professional SP2, Windows 2000 SP4 The problem stopped after I upgraded the router firmware from version 1.something to 2.something, but this may be yet another instance of the "waved a dead chicken at the volcano" syndrome :-) From matt.hammond at rd.bbc.co.uk Tue Aug 9 11:57:15 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Tue, 09 Aug 2005 16:57:15 +0100 Subject: Advanced concurrancy References: <42ea98a2$0$1185$ed2619ec@ptn-nntp-reader01.plus.net> <42f154fd$0$14656$ed2619ec@ptn-nntp-reader02.plus.net> <1123146951.295678.82770@g14g2000cwa.googlegroups.com> Message-ID: Hi Stefan, On Fri, 05 Aug 2005 07:20:36 +0100, Stefan Rank wrote: >>> So do you plan on including a kind of scheduler-aware blocking >>> communication (like the `channels` of the `tasklets` in stackless)? Not at the moment. The kinds of applications we've mainly been looking at, whilst developing, have been multimedia data-flow oriented, so blocking communication would be used as a rate limiting mechanism. However, we've found we can achieve that by putting explicit feedback links in. I think we are also trying to stick with the asynchronous way, if possible, because it may well make things simpler and more efficient when it comes to distributing components across processes / networked computers. Synchronous links will lead to handshaking latencies, more data needing to flow etc. IMO that kind of facility could always be built on top - for example - using a feedback inbox->outbox path to 'request' new data ... if you really need it. ... it also simplifies the scheduler. We've tried, so far, to keep the underlying microprocess model decoupled from the components and inbox/outbox layer. That said, that may have to change eventually! > this communication infrastructure is definitely a Good Thing (TM), the > same holds for a standard environment or registry (wassitsname, your CAT > thing) as you need at least one well-known point of reference in a > 'distributed' system. yep its a CAT (Coordinating Assistant Tracker). Nothing to do with the project logo ... nooo! :-) > > now if someone could only cut the gordian knot of the > GlobalInterpreterLock to make all this really concurrent... and then, > when she's at it, allow transparent distribution of components in a > network... ;-) > I'll second that! regards Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From rkern at ucsd.edu Tue Aug 30 19:54:24 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 30 Aug 2005 16:54:24 -0700 Subject: py2app and Bittornado In-Reply-To: <1125445446.261711.248200@g49g2000cwa.googlegroups.com> References: <1125442841.042912.197950@g14g2000cwa.googlegroups.com> <1125445446.261711.248200@g49g2000cwa.googlegroups.com> Message-ID: bsharitt at gmail.com wrote: > Yeah, already saw that, which is why I said the py2app wasn't thar much > help. That just seems to create a broken .app file. > > You wouldn't happen to know a nice way to interact with the > PythonMac-SIG group without subscribing and subjecting my inbox to rape > by a bunch of useless messages would you? Use GMane. http://dir.gmane.org/gmane.comp.python.apple -- 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 bokr at oz.net Sat Aug 13 14:01:10 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 13 Aug 2005 18:01:10 GMT Subject: catching all exceptions References: Message-ID: <42fe2f70.1362350816@news.oz.net> On Sat, 13 Aug 2005 17:42:00 +0200, a_geek at web.de wrote: >Hello, > >I'd like to catch all exeptions and be able to inspect them. > >The simple case: I know which exceptions I'll get: > ># standard textbook example: >try: > something() >except ThisException, e: > print "some error occurred: ", str(e) > > >The not-so-simple case: Handling all other exceptions: > ># nice-to-have: >try: > something() >except *, e: > print "some error occurred: ", type(e), str(e) > > >Well, actually the second statement doesn't even compile... any ideas >why I shouldn't be able to catch "anonymous" exceptions like this, or >whether and how I can (and only overlooked it)? > > >TIA! > >>> def test(something): ... try: ... something() ... except Exception, e: ... print '%s: %s'% (e.__class__.__name__, e) ... >>> test(lambda: 1/0) ZeroDivisionError: integer division or modulo by zero >>> test(lambda: unk) NameError: global name 'unk' is not defined >>> test(lambda: open('unk')) IOError: [Errno 2] No such file or directory: 'unk' All exceptions should derive from Exception, so the above should catch them, although there are deprecated string exceptions that will not be caught. You can catch these with a bare except, but it is probably better not to, so you will know there's something to clean up. If you do have to deal with them, you can then catch them by name individually, or all with the bare except, e.g., >>> def strexraiser(s): raise s ... >>> def test(something): ... try: ... something() ... except Exception, e: ... print '%s: %s'% (e.__class__.__name__, e) ... except 'ugh': ... print 'Caught "ugh"' ... except: ... print sys.exc_info() ... >>> import sys # forgot, will need when above executes ;-) >>> >>> test(lambda:strexraiser('ugh')) Caught "ugh" >>> test(lambda:strexraiser('gak')) ('gak', None, ) >>> test(lambda:1/0) ZeroDivisionError: integer division or modulo by zero Regards, Bengt Richter From fredrik at pythonware.com Mon Aug 29 09:57:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Aug 2005 15:57:54 +0200 Subject: Dynamic image creation for the web... References: <1125226041.6362.241637673@webmail.messagingengine.com> Message-ID: "Tompa" wrote: > Yes, I believe so too. Something like this, as suggested by Benjamin: > sys.stdout.write('Status: 200 OK\r\n') > sys.stdout.write('Content-type: image/gif\r\n') > sys.stdout.write('\r\n') > im.save(sys.stdout, "GIF") > > But it does not work for some reason!? "does not work" isn't a good way to report a problem -- to help you figure out what's wrong, you have to tell us exactly what happens. if the problem is that you're getting an image, but that the browser cannot display it, you probably have a misconfigured IIS. see this FAQ entry for a solution: http://www.python.org/doc/faq/windows.html#cgi-py-or-other-cgi-programming-doesn-t-work-sometimes-on-nt-or-win95 From k.robert at gmx.de Tue Aug 30 07:54:45 2005 From: k.robert at gmx.de (Robert) Date: Tue, 30 Aug 2005 13:54:45 +0200 Subject: micro-python - is it possible? References: <431440bb$1@news.orcon.net.nz> Message-ID: "Evil Bastard" schrieb im Newsbeitrag news:431440bb$1 at news.orcon.net.nz... > Hi, > > Has anyone done any serious work on producing a subset of python's > language definition that would suit it to a tiny microcontroller > environment? > remember there was some work done for minimizing py1.5.2 for mics. see Google. even bare py1.5.2 would be possible with about 1.5MB overhead statically compiled. remember an own short trial on a AMD SC400 with Embedded Linux. all in 4 or 8 MB or so. but Py2.x's became big nasty beasts with also nasty memory behaviour. guess py1.5.2 is still very nice, tiny and fast for mics. Happy to have a good basic script lng you won't use new style / meta classes / iterators .... > Is it even possible to devise a tiny python subset that has at least > some of python's advantages, but at the same time can be compiled to > low-footprint resource-lean code? > > And could such a mini-python be worth using over C, Forth, etc? guess so if your app has non-trivial complexity: Faktor 5 in programming speed and clarity of code - if you can grant 0.5..2MB overhead. but guess you still need some 1%..5% C for time critical stuff. Robert From pjmlp at progtools.org Tue Aug 23 10:54:59 2005 From: pjmlp at progtools.org (Paulo Pinto) Date: Tue, 23 Aug 2005 14:54:59 GMT Subject: High Level FTP library Message-ID: <7NGOe.6737$Nb2.115820@news1.nokia.com> Hello, Is there any Python library similar to NET::FTP from Perl? ftplib seems too lowlevel. I already found a few, but would like to get one that is endorsed by the community. Thanks, Paulo From steve at holdenweb.com Thu Aug 18 12:45:01 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Aug 2005 17:45:01 +0100 Subject: how do i add a new path into sys.path? In-Reply-To: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> References: <1124353535.829964.208660@o13g2000cwo.googlegroups.com> Message-ID: <4304BB0D.8070902@holdenweb.com> apa wrote: > You can do it this way: > > sys.path.append("C:\Temp") > > Alejandro > Better: sys.path.append("C:\\Temp") or sys.path.append(r"C:\Temp") regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From en.karpachov at ospaz.ru Wed Aug 10 13:40:37 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Wed, 10 Aug 2005 21:40:37 +0400 Subject: What are modules really for? In-Reply-To: <42F9BC7D.1050300@le.ac.uk> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa .googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <20050810214037.21c2d0d2.jk@ospaz.ru> On Wed, 10 Aug 2005 09:36:13 +0100 N.Davis wrote: > As for multiple inheritance, yes I've always been aware of it being > available in C++, but I learned C++ at a company which banned multiple > inheritance in their coding standards, with comments about "The GOTO of > the 1990s". Looks like something religious. It seems they was completely ignorant about what the multiple inheritance is and what is it for. -- jk From paolo_veronelli at tiscali.it Fri Aug 19 19:10:26 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Sat, 20 Aug 2005 01:10:26 +0200 Subject: How to get a unique id for bound methods? In-Reply-To: References: Message-ID: <430666E2.3020907@tiscali.it> Russell E. Owen wrote: > The "hash" function looks promising -- it prints out consistent values > if I use it instead of "id" in the code above. Is it stable and unique? > The documentation talks about "objects" again, which given the behavior > of id makes me pretty nervous. > I dont know how the hash of a bound method is calculated,but as the function of the method is a stable and referenced object and as instances lives are in your hands,then an id(self)^id(self.meth.im_func) should be a chance for that 'hash' function. def methodId(boundMethod): return id(boundMethod.im_self)^id(boundMethod.im_func) class cls(object): def __init__(self): print methodId(self.meth1) print methodId(self.meth2) def meth1(self): pass def meth2(self): pass c = cls() print methodId(c.meth1) print methodId(c.meth2) I think this is giving what you expected. Regards Paolino ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From learningProgramming at gmail.com Thu Aug 25 21:03:09 2005 From: learningProgramming at gmail.com (Learning Python) Date: 25 Aug 2005 18:03:09 -0700 Subject: argument matching question Message-ID: <1125018189.157888.113500@g47g2000cwa.googlegroups.com> I know this is dummy, just never saw an example of this. I want to use the special argument matching. A code like this: def adder(**varargs): sum=varargs[varargs.keys()[0]] for next in varargs.keys()[1:]: sum=sum+varargs[next] return sum print adder( "first","second",'third') ------------------------ It pop up error like this: Traceback (most recent call last): File "learn.py", line 7, in ? print adder( "first","second",'third') TypeError: adder() takes exactly 0 arguments (3 given) How to pass arguments to a functions that use dictionary collection? Thanks From torched_smurf at yahoo.com Thu Aug 18 19:58:08 2005 From: torched_smurf at yahoo.com (torched_smurf at yahoo.com) Date: 18 Aug 2005 16:58:08 -0700 Subject: Module Name Conflicts In-Reply-To: References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: <1124409488.360816.137140@g43g2000cwa.googlegroups.com> Robert Kern wrote: > Dan Sommers wrote: > > > Assuming you can fiddle with sys.path at the right times, you can call > > an imported module anything you want: > > > > fix_sys_path_to_find_java_cmd_first() > > import cmd as java_cmd > > fix_sys_path_to_find_python_cmd_first() > > import cmd as python_cmd > > > > Obviously, then, 'cmd' does not reference either module; you'd have to > > use java_cmd and python_cmd as appropriate. > > That doesn't work. The first module is recorded as 'cmd' in sys.modules > and gets reused on the second import. Exactly. And clearing sys.modules doesn't fix the problem. Once it's imported something from the first cmd package, it can no longer find anything in another cmd package; it will always look for it in that first package. -Smurf From gelios at rbcmail.ru Wed Aug 10 09:47:13 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Wed, 10 Aug 2005 17:47:13 +0400 Subject: MainThread blocks all others References: <42f9d4ef_2@news.isis.de> <42f9e68a_1@news.isis.de> <53nKe.3824$zr1.1930@newssvr13.news.prodigy.com> Message-ID: <42fa056e_1@news.isis.de> Hi again, comments below: > > doSomeJob(self): > > ##### BLOCKING HERE ### > > if not self.myEvent.isSet(): > > self.myEvent.wait() > > The initial 'if' is superflous. Excuse me, please explain. > > self.myEvent.clear() > > # ... continue... > > > > # this class subscribed to some observer which implements thread > > class monitor: > > def __init__(self, klass): > > #do some init > > self.c = klass > > def update(self): > > self.c.increaseCounter() > > > > if __name__ == "__main__": > > cl1 = class1() > > m = monitor(cl1) > > mo = MonitorObserver(m) > > Obviously that won't work. You only have one thread, and it blocks > in doSomeJob, so no one can ever trigger the even. Actually I have 2 threads. One of them is MainThread and second one is created by Observer in which update method called. From claudio.grondi at freenet.de Sat Aug 20 00:12:33 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Sat, 20 Aug 2005 04:12:33 -0000 Subject: Version of TAR in tarfile module? TAR 1.14 or 1.15 port to Windows? Message-ID: <3mnhu1F17b3j4U1@individual.net> I need to unpack on a Windows 2000 machine some Wikipedia media .tar archives which are compressed with TAR 1.14 (support for long file names and maybe some other features) . It seems, that Pythons tarfile module is able to list far more files inside the archives than WinRAR or 7zip or TotalCommander, but will it unpack all available files (largest archive size 17 GByte)? If tarfile is build on TAR 1.14 or TAR 1.15 it will be probably ok, so my questions are: What TAR version is built into the tarfile module? Is there a TAR 1.14 or 1.15 port to Windows available in Internet for download (which URL)? Claudio From peter at engcorp.com Thu Aug 11 14:55:57 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 11 Aug 2005 14:55:57 -0400 Subject: PEP 328, absolute/relative import In-Reply-To: <42fb9807.1192517609@news.oz.net> References: <42fb9807.1192517609@news.oz.net> Message-ID: <67CdnaI0Bo4vAmbfRVn-1w@powergate.ca> Bengt Richter wrote: > Will/should an __init__.py in the current directory be required, > to control what happens (and lessen the probability of accidental > collision from a random working directory)? I don't think so. That would simply shift the possibility of mysterious behaviour from the issue of colliding file names to the issue of whether an __init__.py exists somewhere. Shouldn't one be allowed to treat files in the current directory as regular Python scripts even if the that directory contains an __init__.py so that it can be found as a Python package *in other contexts*? -Peter From kay.schluehr at gmx.net Mon Aug 8 02:08:15 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 7 Aug 2005 23:08:15 -0700 Subject: PEP: Specialization Syntax In-Reply-To: References: <42F66FF2.7010901@v.loewis.de> Message-ID: <1123481295.549324.99810@g49g2000cwa.googlegroups.com> Nicolas Fleury wrote: > It is necessary to maintain a > dictionary of types (to avoid redundacy) and simple things like: > > def makeType(someArgument): > class MyObject: > someArgument = someArgument > return MyObject > > are not allowed. def makeClass(cls_name, **kw): return type(cls_name,(), kw) >>> MyObject = makeClass("MyObject",a=8) >>> MyObject >>> MyObject.a 8 Regards, Kay From albalmer at att.net Mon Aug 29 19:01:15 2005 From: albalmer at att.net (Alan Balmer) Date: Mon, 29 Aug 2005 16:01:15 -0700 Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> Message-ID: <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> On 29 Aug 2005 21:12:13 GMT, John Bokma wrote: >> Now, go away. And please, stay away. > >Like I already said, it doesn't work that way. Goodbye, John. Filters set. -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From norm at normgoertzen.com Thu Aug 25 10:29:17 2005 From: norm at normgoertzen.com (Norm Goertzen) Date: Thu, 25 Aug 2005 14:29:17 GMT Subject: New Arrival to Python Message-ID: <1BkPe.304848$5V4.169335@pd7tw3no> Hi Everyone, I'm totally captivated by Python so far. I want to develop professional-looking Win32 applications with the least effort. I have many years experience with PowerBuilder, PowerBuilder Foundation Class, and SQL Anywhere. I would really like to leverage as many of these skills as possible. Recently I've been learning C#.NET but am concerned with the anticipated longer development times. If it matters, the IDE I choose should also allow for simpler web development. thanks in advance, Norm QUESTIONS: 1. What IDE should I use? 2. If Wing IDE is really good, which version Professional or Personal? 3. Can Sybase's SQL Anywhere Studio be fully integrated with Python? 4. How about versions that integrate with MicroSoft's Visual Studio. Are they generally considered a smart idea? 5. How does Python compare to PowerBuilder's DATAWINDOW technology? 6. What books are worthwhile? My O'Reilly's Safari network has these books: -Core Python Programming; Wesley J. Chun -Python Developer's Handbook; Andr? Dos Santos Lessa -Python Essential Reference, Second Edition; David M Beazley -Perl To Python Migration; Martin C. Brown -Programming Python, 2nd Edition; Mark Lutz -Python Standard Library; Fredrik Lundh -Python & XML; Fred L. Drake, Jr., Christopher A. Jones -Python Cookbook; Alex Martelli, David Ascher -Python Pocket Reference, 2nd Edition; Mark Lutz -Learning Python; David Ascher, Mark Lutz -Python Pocket Reference; Mark Lutz -Python Programming on Win32; Mark Hammond, Andy Robinson -Python: Visual QuickStart Guide; Chris Fehily -Python Programming with the Java? Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython; Richard Hightower -Python in a Nutshell; Alex Martelli -Text Processing in Python; David Mertz -Learning Python, 2nd Edition; David Ascher, Mark Lutz -Game Programming with Python, Lua, and Ruby; Tom Gutschmidt -Python Programming for the absolute beginner; MICHAEL DAWSON -Python Cookbook, 2nd Edition; David Ascher, Alex Martelli, Anna Ravenscroft From nicolas.riesch at genevoise.ch Mon Aug 15 02:40:37 2005 From: nicolas.riesch at genevoise.ch (nicolas_riesch) Date: 14 Aug 2005 23:40:37 -0700 Subject: how to write thread-safe module ? and pytz References: <1123679169.212156.9560@z14g2000cwz.googlegroups.com> Message-ID: <1124088037.785700.41750@o13g2000cwo.googlegroups.com> Thank you very much for all your explanation ! Your pytz module is great ! From accepted at ukr.net Tue Aug 2 03:16:20 2005 From: accepted at ukr.net (Michael Rybak) Date: Tue, 2 Aug 2005 10:16:20 +0300 Subject: need for speed In-Reply-To: <42ee84d8$0$21791$626a14ce@news.free.fr> References: <1122888516.815400.116220@f14g2000cwb.googlegroups.com> <42ee84d8$0$21791$626a14ce@news.free.fr> Message-ID: <894386337.20050802101620@ukr.net> sorry for emailing privately, pressed the wrong "reply" button BD> Michael Rybak a ?crit : BD> (snip) >> >> Is there a way of profiling other than manual (debug output with >> measurements and all)? Some tools? BD> http://docs.python.org/lib/profile.html BD> HTH Ohhhhh, wow! Manuals rule, I should have at least skimmed through. Thanks a lot, already profiling :) -- Best Regards, Michael Rybak mailto:accepted at ukr.net From mwm at mired.org Wed Aug 10 21:45:47 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 10 Aug 2005 21:45:47 -0400 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> Message-ID: <86wtmti6us.fsf@bhuda.mired.org> aahz at pythoncraft.com (Aahz) writes: > In article , > Erik Max Francis wrote: >> >>It also is free for personal use (up to 2 clients, 2 users) and open >>soruce projects can get free licenses. Or at least it was so the last I >>checked. > > For anything mission-critical, I wouldn't want to rely on a free license. > At least if it's Open Source and someone plays with the license, someone > else will fork (c.f. XFree86). Alternatively, I am sometimes willing to > pay for good closed-source software. To my mind, Perforce qualifes for that last sentence. It's solid software, with excellent support, from people who really understand both software development and the open source software movement. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From agostino.russo at gmail.com Fri Aug 12 08:28:41 2005 From: agostino.russo at gmail.com (agostino.russo at gmail.com) Date: 12 Aug 2005 05:28:41 -0700 Subject: pywin32 from network install In-Reply-To: References: <1123843217.146107.302100@g44g2000cwa.googlegroups.com> Message-ID: <1123849721.715902.290630@g44g2000cwa.googlegroups.com> Hmm I have the same problem using python -E... Moreover I do not see anything strange in the sys.path (Z\LocalApps is my shared folder): 'Z:\\LocalApps\\examples', 'Z:\\LocalApps\\python\\python24.zip', 'Z:\\LocalApps\\examples', 'Z:\\LocalApps\\python\\DLLs', 'Z:\\LocalApps\\python\\lib', 'Z:\\LocalApps\\python\\lib\\platwin', 'Z:\\LocalApps\\python\\lib\\libtk', 'Z:\\LocalApps\\python', 'Z:\\LocalApps\\python\\lib\\sitepackages', 'Z:\\LocalApps\\python\\lib\\sitepackages\\Numeric', 'Z:\\LocalApps', 'Z:\\LocalApps\\python\\lib\\sitepackages\\win32', 'Z:\\LocalApps\\python\\lib\\site-packages\\win3\\lib', 'Z:\\LocalApps\\python\\lib\\sitepackages\\Pythonwin', ' 'Z:\\LocalApps\\python\\lib\\site-packages\\wx-2.6-mswansi' BUT when the error is thrown out it is: C:\Program Files\Python24\Lib\site-packages\win32com\client\dynamic.py... From martin.witte at gmail.com Tue Aug 23 14:59:07 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 23 Aug 2005 11:59:07 -0700 Subject: where does __class__ come from? In-Reply-To: <1124823213.701488.57580@z14g2000cwz.googlegroups.com> References: <1124823213.701488.57580@z14g2000cwz.googlegroups.com> Message-ID: <1124823547.524672.88030@z14g2000cwz.googlegroups.com> see http://docs.python.org/lib/specialattrs.html From dcrespo at gmail.com Mon Aug 22 18:21:45 2005 From: dcrespo at gmail.com (dcrespo) Date: 22 Aug 2005 15:21:45 -0700 Subject: Can I send files through xmlrpc connections? In-Reply-To: References: <1124742818.840010.59710@g44g2000cwa.googlegroups.com> Message-ID: <1124749305.244308.154430@g49g2000cwa.googlegroups.com> I'm sorry, I didn't the right question... Of course that I can break the file and rewrite it on an xmlrpc protocol for transmition, or send a byte each time through the socket lib. I meant is there a program already developed that sends and receives files based on xmlrpc calls? Thanks. From tjreedy at udel.edu Thu Aug 11 15:45:40 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Aug 2005 15:45:40 -0400 Subject: what's the exactly newsgroup url of python-list? References: <11fmnpj6571j1ae@corp.supernews.com> Message-ID: "Grant Edwards" wrote in message news:11fmnpj6571j1ae at corp.supernews.com... > On 2005-08-11, Fredrik Lundh wrote: >> for an excellent way to read the python mailing list via a news- >> reader even if you don't have access to a "real" NNTP server, >> see http://gmane.org/ > > Using an NNTP gateway to a mailing list that's gatewayed to a > Usenet group. That's about like running Cygwin under Windows > under Linux: there are valid reasons to do it, but it always > feels surreal. Yes, but it works. I use gmane for c.l.p mostly because I also use it for other Python lists that are *not* gatewayed to a Usenet group, I far prefer the newsgroup interface, and I like having all Python groups together in one block in the side-bar. At one time, my newserver access was also less dependable than Gmane and switching back and forth was a nuisance. Terry J. Reedy From gene.tani at gmail.com Sun Aug 21 15:25:11 2005 From: gene.tani at gmail.com (gene tani) Date: 21 Aug 2005 12:25:11 -0700 Subject: last line chopped from input file In-Reply-To: <1124650176.804832.150260@g44g2000cwa.googlegroups.com> References: <1124603622.204380.256560@g47g2000cwa.googlegroups.com> <1124646074.295575.292490@g47g2000cwa.googlegroups.com> <1124650176.804832.150260@g44g2000cwa.googlegroups.com> Message-ID: <1124652311.614997.77950@g14g2000cwa.googlegroups.com> or: (for long-running Win32 processes) os.startfile(r'/relative/path/to/app') http://docs.python.org/lib/os-process.html under linux/BSD/solaris, i've run into situations where PATH and other environmental var s aren't what you expect (they're from the /etc/profile system defaults, not from your .bashrc). I can't remember if anything like that happens in windows. From alessandro.bottoni at infinito.it Fri Aug 26 09:58:21 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Fri, 26 Aug 2005 13:58:21 GMT Subject: Integrate C source in a Python project References: Message-ID: <1eFPe.31972$F23.373253@twister2.libero.it> billiejoex wrote: > Hi all. > I was wondering if it ispossible to integrate C source in a python > project. > > Best regards Yes, of course. Have a look here: http://docs.python.org/ext/ext.html There are two nice tools for this: SWIG http://www.swig.org/Doc1.1/HTML/Python.html SIP http://www.river-bank.demon.co.uk/docs/sip/sipref.html HTH ----------------------------------- Alessandro Bottoni From rkern at ucsd.edu Sat Aug 6 06:43:13 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 03:43:13 -0700 Subject: about coding In-Reply-To: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> References: <42f48963$0$25047$8fcfb975@news.wanadoo.fr> Message-ID: cantabile wrote: > Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-' > directive. > > I'm using an accented characters language. Some of them are correctly > displayed while one doesn't. I've written : > -*- coding: utf-8 -*- > > Is this wrong ? It depends. Are those characters encoded as UTF-8? Or, more likely, are they encoded as ISO-8859-1? > Where can I find a pratical explanation about these encodings ? http://www.amk.ca/python/howto/unicode http://en.wikipedia.org/wiki/Character_encoding http://www.joelonsoftware.com/articles/Unicode.html -- 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 prabapython at yahoo.co.in Tue Aug 23 04:26:51 2005 From: prabapython at yahoo.co.in (praba kar) Date: Tue, 23 Aug 2005 09:26:51 +0100 (BST) Subject: Doubt C and Python In-Reply-To: <1124785351.793496.93990@o13g2000cwo.googlegroups.com> Message-ID: <20050823082652.21127.qmail@web8403.mail.in.yahoo.com> --- James wrote: > > Some people with C background use Python instead > > of programming in C.why? > > Becuase it is much more efficient. > > -James What why it is more efficient. Kindly let me know with some details. regards Prabahar ____________________________________________________ Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html From renting at astron.nl Wed Aug 24 02:46:53 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 24 Aug 2005 08:46:53 +0200 Subject: where does __class__ come from? Message-ID: You might find the chapter 3.3 (in my python 2.3.4, it's "Special Method names") in the reference manual useful, it is the only place I have found sofar that describes most of these special methods. It does however not contain __class__. I don't know where in the reference manual to find it's description, probaly in some "Special attribute names" chapter I can't find. >>>"Diez B. Roggisch" 08/23/05 11:26 pm >>> >Where does __class__ come from, what does it mean and what else is >being hidden? > >I am used to using dir(...) to figure out what I can play with. >Clearly that does not always work... :-( Your question has benn answered - let me just add this from the dir()-docs: Note: Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. from http://docs.python.org/lib/built-in-funcs.html Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list From 816168 at gmail.com Fri Aug 5 11:48:59 2005 From: 816168 at gmail.com (Kevin) Date: 5 Aug 2005 08:48:59 -0700 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> Message-ID: <1123256939.119967.280500@z14g2000cwz.googlegroups.com> Thank you all for the messages. I agree with Bill on that I was just whining here. I should do a bit more research. I guess I am just getting accustomed to the endless supplies of asp/php hosting services. All I need to do is shopping for the lowest price/good service. But it's not the case for Python, so for a newbie like me it's a little discouraging. Now I have more information I will look into it, and hopefully can pick up Phthon again. To tell you the truth, after perl, java, vb, and (some) php and groovy, I want to settle down on something (along with java). That maybe the reason of my frustration. :-) From eric.paquet at isrec.ch Tue Aug 30 07:13:32 2005 From: eric.paquet at isrec.ch (Meo) Date: 30 Aug 2005 04:13:32 -0700 Subject: array of arrays question In-Reply-To: <7xd5nvokjt.fsf@ruckus.brouhaha.com> References: <1125392269.199866.64910@f14g2000cwb.googlegroups.com> <7xd5nvokjt.fsf@ruckus.brouhaha.com> Message-ID: <1125400412.844590.258780@g14g2000cwa.googlegroups.com> yes, thank you for your help From tprimke at interia.pl Thu Aug 4 08:48:02 2005 From: tprimke at interia.pl (TPJ) Date: 4 Aug 2005 05:48:02 -0700 Subject: PyGTK or wxPython (not a flame war) on Windows References: <1122018122.372760.190700@g49g2000cwa.googlegroups.com> <7x4qaja80z.fsf@ruckus.brouhaha.com> Message-ID: <1123159681.971130.212880@g47g2000cwa.googlegroups.com> I have encountered some problems with PyGTK only when I was trying to install a PyGTK version that was different from the installed GTK+ version. When those both versions were the same, I had no problems at all. (Another problem with PyGTK is that it's installation is somewhat more complicated that installation of wxPython, but I wrote a script that can download and install PyGTK. The user have to tell where all this stuff should be installed to and the script just does the rest.) Tkinter is out of question. It looks ugly. I'd like to write a program that would look nice. From fredrik at pythonware.com Tue Aug 30 15:40:38 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Aug 2005 21:40:38 +0200 Subject: py to exe: suggestions? References: <1125231403.476434.162930@z14g2000cwz.googlegroups.com> Message-ID: Ivan Shevanski wrote: > Not sure if you already got the answer to this lol but since this is one > thing about python i do know how to do, use CXFreeze. Its basicly a > combination of all the programs you have already tryed. Works great for me > =D sorry I dont have a link, just google it. it's spelled cx_freeze, and can be found here: http://starship.python.net/crew/atuining/cx_Freeze/ From justin.azoff at gmail.com Sat Aug 6 19:57:39 2005 From: justin.azoff at gmail.com (Justin Azoff) Date: 6 Aug 2005 16:57:39 -0700 Subject: Some simple performace tests (long) References: <1123334835.548075.129430@z14g2000cwz.googlegroups.com> Message-ID: <1123372658.974319.261970@g44g2000cwa.googlegroups.com> How much ram does your machine have? the main point is "except when a very large range is used on a memory-starved machine" run x = range(10 ** 6) and look at the memory usage of python.. what happens when you run this program: import time def t(func, num): s = time.time() for x in func(num): pass return time.time() - s def run(func, num): times = [] for x in range(5): times.append(t(func,num)) return min(times), max(times), sum(times)/5 def main(): x = 10 ** 6 while 1: print "trying", x for s, f in ('xr', xrange), (' r', range): print s + " %.3f %.3f %.3f" % run(f, x) x *= 1.5 x = int(x) if __name__ == "__main__": main() I get (columns are mix/max/average): trying 1000000 xr 0.110 0.115 0.111 r 0.101 0.186 0.119 trying 1500000 xr 0.082 0.087 0.083 r 0.152 0.158 0.154 trying 2250000 xr 0.124 0.138 0.128 r 0.228 0.235 0.230 trying 3375000 xr 0.184 0.189 0.186 r 0.344 0.352 0.346 trying 5062500 xr 0.276 0.284 0.279 r 0.515 0.528 0.519 trying 7593750 xr 0.415 0.421 0.416 r 0.774 0.795 0.779 trying 11390625 xr 0.623 0.634 0.626 r 1.163 1.246 1.180 trying 17085937 xr 0.934 0.941 0.937 Killed The "Killed" is from the linux OOM killing the python process.. notice that the xrange for that number worked fine. From seberino at spawar.navy.mil Sat Aug 6 00:22:41 2005 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 5 Aug 2005 21:22:41 -0700 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <1123302161.191230.209140@g43g2000cwa.googlegroups.com> I'm not saying 'modulescope' and 'module' are the only alternatives or even the best anyone can come up with. 'global' has the connotation of being visible *EVERYWHERE* where in Python it is just visible in one module's space. Can you think of a better alternative or do you believe 'global' is the best possible? From rlb at hoekstra-uitgeverij.nl Tue Aug 23 02:24:22 2005 From: rlb at hoekstra-uitgeverij.nl (Richard Bos) Date: Tue, 23 Aug 2005 06:24:22 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: <430ac10a.298157@news.xs4all.nl> "jan V" wrote: > > +-------------------+ .:\:\:/:/:. > > | PLEASE DO NOT | :.:\:\:/:/:.: > > | FEED THE TROLLS | :=.' - - '.=: > > | | '=(\ 9 9 /)=' > > | Thank you, | ( (_) ) > > | Management | /`-vvv-'\ > > +-------------------+ / \ > > | | @@@ / /|,,,,,|\ \ > > | | @@@ /_// /^\ \\_\ > > @x@@x@ | | |/ WW( ( ) )WW > > \||||/ | | \| __\,,\ /,,/__ > > \||/ | | | jgs (______Y______) > > /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ > > Please don't use ASCII art... not everyone uses a fixed-width font for his > newsreader............... > (your picture looks all mangled here) That's your own fault, though, innit? Richard From Scott.Daniels at Acm.Org Mon Aug 29 01:43:52 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 28 Aug 2005 22:43:52 -0700 Subject: trictionary? In-Reply-To: References: <0LOdnYjsqqd-24_eRVn-1w@comcast.com> Message-ID: <4312947b$1@nntp0.pdx.net> Randy Bush wrote: >... i could be a bit more obscure and do > if week in bin: > bin[week][not full] += 1 > else: > bin[week] = [ full, not full ] If you cannot take the setdefault advice, at least do: try: bin[week][not full] += 1 except KeyError: bin[week] = [full, not full] --Scott David Daniels Scott.Daniels at Acm.Org From bokr at oz.net Sun Aug 7 21:03:44 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 08 Aug 2005 01:03:44 GMT Subject: Euclid's Algorithm in Python? References: <1123208832.618245.92100@o13g2000cwo.googlegroups.com> <1123211591.741161.297570@g49g2000cwa.googlegroups.com> <1123461062.574511.278540@g43g2000cwa.googlegroups.com> Message-ID: <42f6aef7.870709213@news.oz.net> On 7 Aug 2005 17:31:02 -0700, "Jordan Rastrick" wrote: >Good point. I suppose I'd only ever seen it implemented with the if >test, but you're right, the plain while loop should work fine. Silly >me. > >def gcd(a,b): > while b != 0: > a, b = b, a%b > return a > >Even nicer. > what is the convention for handling signed arguments? E.g., >>> def gcd(a,b): ... while b != 0: ... a, b = b, a%b ... return a ... >>> gcd(3, -12) -3 >>> gcd(-12, 3) 3 Regards, Bengt Richter From bronger at physik.rwth-aachen.de Thu Aug 18 17:36:58 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Thu, 18 Aug 2005 23:36:58 +0200 Subject: Really virtual properties Message-ID: <87slx7c4g5.fsf@wilson.rwth-aachen.de> Hall?chen! When I use properties in new style classes, I usually pass get/set methods to property(), like this: x = property(get_x) If I overwrite get_x in a derived class, any access to x still calls the base get_x() method. Is there a way to get the child's get_x() method called instead? (I found the possibility of using an intermediate method _get_x which calls get_x but that's ugly.) Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From kst-u at mib.org Mon Aug 22 15:27:01 2005 From: kst-u at mib.org (Keith Thompson) Date: Mon, 22 Aug 2005 19:27:01 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: "Xah Lee" writes: [the usual] +-------------------+ .:\:\:/:/:. | PLEASE DO NOT | :.:\:\:/:/:.: | FEED THE TROLLS | :=.' - - '.=: | | '=(\ 9 9 /)=' | Thank you, | ( (_) ) | Management | /`-vvv-'\ +-------------------+ / \ | | @@@ / /|,,,,,|\ \ | | @@@ /_// /^\ \\_\ @x@@x@ | | |/ WW( ( ) )WW \||||/ | | \| __\,,\ /,,/__ \||/ | | | jgs (______Y______) /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ============================================================== -- Keith Thompson (The_Other_Keith) kst-u at mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. From bokr at oz.net Tue Aug 16 17:20:05 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 16 Aug 2005 21:20:05 GMT Subject: class-call a function in a function -problem References: Message-ID: <43024f83.1632645029@news.oz.net> On Tue, 16 Aug 2005 18:46:30 +0200, "wierus" wrote: >Hello, i have a problem. I write my first class in python so i'm not a >experience user. I want to call a function in another function, i tried to >do it in many ways, but i always failed:( >I supposed it's sth very simple but i can't figure what it is: >================================== >class ludzik: > x=1 > y=2 > l=0 ^ '-+ | +--(same name, so l=0 is replaced by l = the_subsequently_defined_function l) | +-, v > def l(self): > ludzik.l=ludzik.x+ludzik.y > print ludzik.l Within the above function, which will serve as a method of the class ludzik, you are using the name 'ludzik' as one would normally use 'self'. The consquence is that instances such as z below will all share ludzik as the place to access x, y, and l. This is legal, but not typically what you want. > > def ala(self): > print ludzik.x > print ludzik.y > ludzik.l() Think what ludzik.l is at this point. It is not zero, because the l=0 has been replaced with the def l(self): ..., but ludzik is the global name of your class, and an attribute lookup directly on a class gets you an unbound method (if the attribute is a function), and that is what you got. To get a bound method (meaning a method bound to the instance, so that the first argument (normally called 'self') is bound to the instance object), you have to call the method name as an attribute of the instance instead. I.e., self.l() not ludzik.l() So if you change all the ludzik names inside l and ala methods, you should have better luck. > > >z=ludzik() The above created an instance z >z.ala() This created a _bound_ method z.ala, and called it with self bound to z, but you ignored self in ala, and instead of self.l -- which would have gotten you a bound method with l as the function and the same self (z) passed through -- you wrote ludzik.l, and got an unbound method, which complained because you didn't pass it the instance as the first arg. BTW, you could have done that explicitly by calling ludzik.l(self) at that point, for the same effect as the normal call of self.l() >==================================== > > >k.py >1 >2 >Traceback (most recent call last): > File "k.py", line 17, in ? > z.ala() > File "k.py", line 14, in ala > ludzik.l() >TypeError: unbound method l() must be called with ludzik instance as >first argument (got nothing instead) > > >i would be gratefull for resolving this problem for me.... > HTH Working through the tutorials is not a bad idea ;-) Regards, Bengt Richter From peter at hardy.dropbear.id.au Tue Aug 23 15:00:28 2005 From: peter at hardy.dropbear.id.au (peter at hardy.dropbear.id.au) Date: 23 Aug 2005 12:00:28 -0700 Subject: Sequential XML parsing with xml.sax Message-ID: <1124823628.332677.73660@o13g2000cwo.googlegroups.com> Hi hi. I'm trying to do sequential decompression of a bzipped XML file and feed it to a SAX parser with the following code. remotefh = urllib.urlopen('file:///home/peter/catalog.rdf.bz2') decompressor = bz2.BZ2Decompressor() handler = CatalogueDocumentHandler(sys.stdout) chunksize = 2048 data = remotefh.read(chunksize) while data != '': out = decompressor.decompress(data) if out != '': xml.sax.parseString(out, handler) data = remotefh.read(chunksize) This fails with the first chunk of decompressed data passed to xml.sax.parseString. I'm suspecting because it's an incomplete fragment of XML. I've tried with a number of different chunk sizes, putting the break in different places, but it always fails on the first call. For reference, the traceback looks like: xml.sax.parseString(out, handler) File "/usr/lib/python2.4/site-packages/_xmlplus/sax/__init__.py", line 47, in parseString parser.parse(inpsrc) File "/usr/lib/python2.4/site-packages/_xmlplus/sax/expatreader.py", line 109, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/lib/python2.4/site-packages/_xmlplus/sax/xmlreader.py", line 125, in parse self.close() File "/usr/lib/python2.4/site-packages/_xmlplus/sax/expatreader.py", line 226, in close self.feed("", isFinal = 1) File "/usr/lib/python2.4/site-packages/_xmlplus/sax/expatreader.py", line 220, in feed self._err_handler.fatalError(exc) File "/usr/lib/python2.4/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :15132:63: no element found (line 15132 is the last, incomplete line feed to parseString. FWIW, it's: Searchlights o ) The API reference isn't clear on whether parseString can only handle discrete bits of valid XML, or if it's designed to be called in this way. So I'm not sure if I'm misusing the function, or if I've done something else wrong. Any pointers? Thanks, -- Pete From mhellwig at xs4all.nl Thu Aug 4 12:53:36 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Thu, 04 Aug 2005 18:53:36 +0200 Subject: Secure email In-Reply-To: References: <42f1ecd3$0$11079$e4fe514c@news.xs4all.nl> <42f1f719$0$11062$e4fe514c@news.xs4all.nl> Message-ID: <42f2481d$0$11071$e4fe514c@news.xs4all.nl> Michael Str?der wrote: >>>This would require an additional PGP-plugin for Outlook. Outlook can >>>decrypt S/MIME messages out-of-the-box. >> >>Yes indeed, although I personaly find pgp a bit more elegant your >>solution would be the best for the OP. > Whether S/MIME or PGP is used depends very much on the security policy > the application has to comply with and the rest of the system > environment we both know very little about. Therefore I can't see what's > more "elegant" with PGP in general and how you can tell what the "best > solution" is for the original poster. Not general, personal in the sence of my own opinion just like I have it wrote it. Best for the OP because as you pointed out there was a written (although older) howto for s/mime which the OP could follow (as he requested), howto's for PGP icw Python is a bit rare, although I haven't googled for long. -- mph From mwm at mired.org Wed Aug 31 22:19:30 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 31 Aug 2005 22:19:30 -0400 Subject: Adding bound methods dynamically... CORRECTED References: <4o4ah1h2r53gll81jinueaugpqi7rq7hsj@4ax.com> <7s5ah1t7t2qvseneigb6p1jv9igcl4diri@4ax.com> <1125462130.670127.206220@g44g2000cwa.googlegroups.com> <431572ba$0$27027$626a14ce@news.free.fr> Message-ID: <86irxl7cnh.fsf@bhuda.mired.org> bruno modulix writes: > Devan L wrote: >> Kevin Little wrote: >> >>>I want to dynamically add or replace bound methods in a class. > > (snip) > >> I'm not an expert, but why do you need to dynamically add or replace >> bound methods? > > To modify the behaviour at runtime ?-) > > There are a lot of idioms/patterns in dynamic languages that seems > somewhat alien at first, then become an obvious solution. When I > discovered first-class functions and anonymous functions with Python > some years ago, I wondered what could be the use of such things. Now I > couldn't live without... Yes, but rather than going through the contortions you do to bind a new method into place, why not make the method in question act as a proxy for the real method? After all, with first-class functions, that's easy. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From chandra.bangalore at gmail.com Tue Aug 30 08:19:05 2005 From: chandra.bangalore at gmail.com (chand) Date: 30 Aug 2005 05:19:05 -0700 Subject: Warning when doubly linked list is defined gloablly References: <1124881914.018491.315800@g14g2000cwa.googlegroups.com> Message-ID: <1125404345.667261.195470@f14g2000cwb.googlegroups.com> Hi Terry.., Here is the code which gives the error... Let me know exact reason for this Error import os,sys,re,string,math from xml.dom import minidom, Node from Layer import Layer from LMessage import * from Param import * from Message import * from message_mapping import * from protocol_mapping import * from symbol_mapping import * from opt_list_mapping import * g_del_opt_list =[[],[],[],[],[],[],[]] sflag = 0 index=0 del_index=0 radflag = 0 depth = 0 xmlflag = 0 opt_param_list = [] del_opt_param_list = [] #g_opt_list = [] MTAS_HOME="/home/chandras/XML_FILES/" SIG_STANDARD_HOME = "/home/chandras/SIGNALLING_STANDARD/ANSI_SS7/" symbols=['(',')','{','}','[',']','.'] reverse_symbols=['<','>','~'] layers=['MTP3','SCCP','IOS','CDTAPM2','CDTAPC2','ISUP','IS-41D-SQA'] GUI_API_COMMAND_LIST = [ "NEW", "ADD_OPTIONAL_PARAM", "DELETE_OPTIONAL_PARAM", "DELETE_LAYER", "RENAME" ] BASE2 = "01" BASE10 = "0123456789" BASE16 = "0123456789ABCDEF" Message_obj = Message() filename ="" buffer = [] #LIST = [] def Process_GUI_Command(arg): global Message_obj global filename print "### COMMAND ###", arg[0] save_fd = os.dup(1) if arg[0] == "DELETE_OPTIONAL_PARAM": out_file = file('/tmp/te6.txt', 'w+') elif arg[0] == "ADD_OPTIONAL_PARAM": out_file = file('/tmp/te3.txt', 'w+') else : out_file = file('/tmp/te.txt', 'w+') os.dup2(out_file.fileno(), sys.stdout.fileno()) if arg[0] == "NEW" : global g_opt_list Message_obj = Message() layerList = listLayers("ANSI_Layers") layerList = str(layerList) layerList = layerList.replace(",","") for i in range(0,len(g_opt_list)): g_opt_list[i] = [] os.dup2(save_fd, 1) return layerList elif arg[0] == "ADD_OPTIONAL_PARAM" : global g_opt_list global layers global index message_name = "" layer_name = arg[1] #print "Layer Name", layer_name for layer in layers: if layer == layer_name: if OPT_LIST_MAPPING.has_key(layer_name): index = OPT_LIST_MAPPING[layer_name] break if arg[2] != 'Null': optional_parameter_name = str(arg[2]).replace("+",",") for symbol in reverse_symbols: if symbol in optional_parameter_name: if SYMBOL_REVERSE_MAPPING.has_key(symbol): old_symbol = SYMBOL_REVERSE_MAPPING[symbol] optional_parameter_name = optional_parameter_name.replace(symbol,old_symbol) Message_obj.AddParam(message_name,layer_name, optional_parameter_name ) else : optional_parameter_name= 'Null' add_delete_flag = 0 param_name = optional_parameter_name show_opts(layer_name,add_delete_flag,param_name) if int(add_delete_flag) == 0: add_delete_flag = 0 if optional_parameter_name != "Null": optList = Message_obj.showOptionalParameters(layer_name,add_delete_flag,optional_parameter_name) g_opt_list[int(index)].append(optional_parameter_name) for i in g_opt_list[int(index)]: if g_opt_list[int(index)].count(i) == 1: optList = Message_obj.showOptionalParameters(layer_name,add_delete_flag,i) displayoptparams(optList,layer_name,0,"Null") i= "Null" optional_parameter_name = "Null" add_delete_flag = 1 os.dup2(save_fd, 1) else: print "Invalid Option" def show_opts(layer_name,add_delete_flag,param_name): global index global g_opt_list #param_name = "Null" List = Message_obj.showOptionalParameters(layer_name,add_delete_flag,"Null") if (len(List)== 0) : return "None" displayoptparams(List,layer_name,add_delete_flag,Message_obj._message_name) if param_name == 'Null': for i in g_opt_list[int(index)]: if g_opt_list[int(index)].count(i) == 1: optList = Message_obj.showOptionalParameters(layer_name,add_delete_flag,i) displayoptparams(optList,layer_name,0,"Null") add_delete_flag = 1 return "None" def main(): #choice = sys.argv[1] print "####### choice ", #Process_GUI_Command("NEW") #list=CMSR.showOptionalParameters("SCCP",0) #CMSR.saveXMLfile("CMSR2.xml","CMSR") if __name__ == '__main__': main() --Thanks and bestregards., --Chandra Terry Reedy wrote: > "chand" wrote in message > news:1124881914.018491.315800 at g14g2000cwa.googlegroups.com... > > Hi., > > > > In my api.py file 'g_opt_list' is defined globally > > g_opt_list =[[],[],[],[],[],[],[]] > > > > I am using this global list in the fucntion > > > > def function (): > > gloabl g_opt_list > > > > when I run the py file, I am getting the Following Error > > > > SyntaxWarning: name 'g_opt_list' is used prior to global declaration > > > > Please let me know how to remove this error > > To expand slightly on previous answers: > > 1. Write a *minimal* file that gives you the error. This means that > removing any statement ceases to give you the error. This may answer your > questions. > > 2. If still puzzled, post again. But cut and paste that *exact* file and > also the *full* error traceback. > > Terry J. Reedy From rkern at ucsd.edu Thu Aug 25 06:44:38 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 25 Aug 2005 03:44:38 -0700 Subject: RE Despair - help required In-Reply-To: <430d8883@news.bezeqint.net> References: <430d8883@news.bezeqint.net> Message-ID: Yoav wrote: > I am trying the following: > > re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") > > and I get a return of NoneType, and I have no idea why. I know that I > missing something here, but I really can't figure out why (I bet it's > something obvious). I also tried this RE on KODOS and it works fine > there, so I am really puzzled. > > Any ideas? Look at the second string. It has "\r" in the middle of it where you really want "\\r" (or alternatively r"c:\ret_files"). -- 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 steve at holdenweb.com Tue Aug 30 17:49:16 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Aug 2005 16:49:16 -0500 Subject: variable hell In-Reply-To: <1125434858.783283.202090@g47g2000cwa.googlegroups.com> References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> <1125434858.783283.202090@g47g2000cwa.googlegroups.com> Message-ID: sp1d3rx at gmail.com wrote: > Steve, can I quote you on that? > > "You can lead an idiot to idioms, but you can't make him think!" -- > Steve Holden 2005 > Looks like you just did :-). Feel free. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From billuseslinux at gmail.com Tue Aug 23 12:56:20 2005 From: billuseslinux at gmail.com (billuseslinux at gmail.com) Date: 23 Aug 2005 09:56:20 -0700 Subject: High Level FTP library In-Reply-To: <7NGOe.6737$Nb2.115820@news1.nokia.com> References: <7NGOe.6737$Nb2.115820@news1.nokia.com> Message-ID: <1124816180.938426.258200@g49g2000cwa.googlegroups.com> Paulo Pinto wrote: > Hello, > > Is there any Python library similar to NET::FTP from Perl? > ftplib seems too lowlevel. > > I already found a few, but would like to get one that is > endorsed by the community. > > Thanks, > Paulo Have you looked at ftputil? http://www.sschwarzer.net/python/python_software.html From t-meyer at ihug.co.nz Wed Aug 31 20:29:26 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Thu, 1 Sep 2005 12:29:26 +1200 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. In-Reply-To: Message-ID: > IMHO, there is a great opportunity here for the python community: [...] > Surely that's worth a simple team name, for mnemonic purposes > if nothing else. Something different or unusual, like one of my > favourites, "Legion of the Bouncy Castle", who are a group of Java > cryptography dudes Is there really anything to be gained by referring to the "SpamBayes development team" via some cryptic name? You can call use the SDT if you like. Should the Python developers likewise get some cryptic name? =Tony.Meyer Plug: If anyone really wants to help SpamBayes, please contribute! has plenty of bugs/feature requests to work on, or you can read for non-programming help ideas. From aisaac0 at verizon.net Thu Aug 11 22:25:38 2005 From: aisaac0 at verizon.net (David Isaac) Date: Fri, 12 Aug 2005 02:25:38 GMT Subject: FTP over SSL (explicit encryption) References: Message-ID: > David Isaac wrote: > > I am looking for a pure Python secure ftp solution. > > Does it exist? "Andrew MacIntyre" wrote in message news:mailman.2957.1123722670.10512.python-list at python.org... > I recall coming across an extension package (pretty sure it wasn't pure > Python anyway, certainly not for the SSL bits) with SFTP - I think the > name was Paramiko or something like that. Unfortunately that's SSH2 only. It is indeed pure Python http://www.lag.net/paramiko/ However it requires the PyCrypto module. http://www.amk.ca/python/code/crypto Can you briefly outline how to use this as a client to upload and down files from a server using SFTP? Thanks, Alan Isaac From zwerschke at zuv.uni-heidelberg.de Tue Aug 2 12:44:01 2005 From: zwerschke at zuv.uni-heidelberg.de (Christoph Zwerschke) Date: Tue, 02 Aug 2005 18:44:01 +0200 Subject: Art of Unit Testing Message-ID: In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the legitimate question why there is no hook for a "global" fixture code that is run only once for the whole TestCase, as opposed to the normal "setUp" and "tearDown" code that is run for every single test in the TestCase. A "global fixture" would be preferable whenever creating the fixture is time consuming, e.g. you have to create a database connection or even a whole database. What would be the preferred solution for such global fixtures? Simply create the database, run the TestCase, and drop the database? Would it make sense to add "globaleSetup" and "globalTearDown" methods to the TestCase class? I think at least it would not harm anybody. Where should such proposals be submitted? -- Christoph Zwerschke From wolfgang.keller.nospam at gmx.de Fri Aug 12 05:05:05 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Fri, 12 Aug 2005 11:05:05 +0200 Subject: Spreadsheet with Python scripting and database interface? References: Message-ID: Hello, and thanks for your reply. > One thing that's not clear from your question is whether you want to > script the office from within using a macro or from the outside via > "remote control". What I basically dream of is using Python as THE embedded macro language of the spreadsheet. Because Postgres already supports Python as a trigger/procedure language, so I can stick with one single tool (to learn and use). > PyUNO allows both, but Python macros are only possible > with the OpenOffice 2 scripting framework. Sincerely, Wolfgang Keller From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 8 03:05:54 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 08 Aug 2005 09:05:54 +0200 Subject: How to determine that if a folder is empty? In-Reply-To: References: Message-ID: <3loeiiF139eh3U1@individual.net> could ildg wrote: > I want to check if a folder named "foldername" is empty. > I use os.listdir(foldername)==[] to do this, > but it will be very slow if the folder has a lot of sub-files. > Is there any efficient ways to do this? try: os.rmdir(path) empty = True except OSError: empty = False should be efficient. A directory (please stop calling them "folders") can only be removed if it's empty. Reinhold From giltalgiltal at hotmail.com Wed Aug 24 13:31:11 2005 From: giltalgiltal at hotmail.com (Gil Tal) Date: 24 Aug 2005 10:31:11 -0700 Subject: problems with hasattr() and custom __getattr__ inside urllib2 Message-ID: <1124904671.857343.314180@g47g2000cwa.googlegroups.com> Hi, I use urllib2 to download a redirected url and I get an exception from the bowels of urllib2. It seems that urllib2 implements some super sophisticated self check and tries to control the access to attributes using lots of calls to hasattr(the builtin function) and a custom __getattr__() on the Request class that perfroms some checks and raises an AttributeError if it's not happy. The problem is that hasattr() according to the docs is supposed to eat the exception and simply return False, but in my case it surfaces to my code and stops the regular flow. Here is the output and my code: Output ====== AttributeError: redirect_dict Traceback (innermost last): File "c:\Gigi\Dev\Python\Updater\Client\test.py", line 1, in ? import os, sys, urllib2 File "c:\Gigi\Dev\Python\Updater\Client\test.py", line 36, in ? download(url, filename, chunkSize) File "c:\Gigi\Dev\Python\Updater\Client\test.py", line 4, in download fin = urllib2.urlopen(url) File "C:\Python24\Lib\urllib2.py", line 130, in urlopen return _opener.open(url, data) File "C:\Python24\Lib\urllib2.py", line 364, in open response = meth(req, response) File "C:\Python24\Lib\urllib2.py", line 471, in http_response response = self.parent.error( File "C:\Python24\Lib\urllib2.py", line 396, in error result = self._call_chain(*args) File "C:\Python24\Lib\urllib2.py", line 337, in _call_chain result = func(*args) File "C:\Python24\Lib\urllib2.py", line 539, in http_error_302 if hasattr(req, 'redirect_dict'): File "C:\Python24\Lib\urllib2.py", line 207, in __getattr__ raise AttributeError, attr Code ==== import os, sys, urllib2 def download(url, filename, chunkSize): fin = urllib2.urlopen(url) parent_dir = os.path.dirname(filename) if parent_dir != '' and not os.path.exists(parent_dir): os.makedirs(parent_dir) fout = open(filename, 'wb') info = fin.info() print 'info:', info totalBytes = int(info['Content-Length']) downloadBytes = 0 bytesLeft = totalBytes while bytesLeft > 0: chunk = fin.read(chunkSize) readBytes = len(chunk) downloadBytes += readBytes bytesLeft -= readBytes fout.write(chunk) print 'Progress: %d/%d' % (downloadBytes, totalBytes) print 'Done.' if __name__=="__main__": #url = 'http://audacity.sourceforge.net/audacity-manual-1.2.zip' url = 'http://www-users.york.ac.uk/~raa110/audacity/audacity-manual-1.2.3.zip' url='http://download.mozilla.org/?product=thunderbird-1.0.2&os=win&lang=en-US' url='http://download.mozilla.org/?product=thunderbird-1.0.6&os=win&lang=en-US' filename = url.split('/')[-1] chunkSize = 1 download(url, filename, chunkSize) print open(filename).read() Thanks, Gil From tjreedy at udel.edu Fri Aug 5 16:23:20 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 5 Aug 2005 16:23:20 -0400 Subject: Syntax error after upgrading to Python 2.4 References: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> Message-ID: wrote in message news:1123260862.672051.282940 at z14g2000cwz.googlegroups.com... > After upgrading to 2.4 (from 2.3), I'm getting a weird syntax error: > >>>> import themes > Traceback (most recent call last): > File "", line 1, in ? > File "themes.py", line 564 > font = self.font.makeBlackAndWhite(), > additive = self.additive, > ^ > SyntaxError: invalid syntax The location of the caret is sometimes misleading, especially with proportional fonts... > The relevant code is: > > def makeBlackAndWhite( self ): > > return CharStyle( names = self.names, > basedOn = self.basedOn.makeBlackAndWhite(), > font = self.font.makeBlackAndWhite(), > additive = self.additive, > prefixText = self.prefixText ) > > This is a method in the CharStyle class which returns a new modified > instance of CharStyle. > > I'm using Windows XP and Python 2.4.1 > > Any ideas? O:-) I don't see the problem yet. I certainly do not see anything that should have been affected by the upgrade (was it from 2.3 on XP also?) After checking for nonprinting chars, I would shuffle the param-default lines to try to determine which is really at fault. Good luck, or wait for a more helpful response. Terry J. Reedy From dan2cil at tin.it Sun Aug 21 15:36:27 2005 From: dan2cil at tin.it (danilo) Date: Sun, 21 Aug 2005 19:36:27 GMT Subject: Gimp-Python Message-ID: Salve, qualcuno sa se ? ancora in fase di sviluppo e qual'? il sito di riferimento? Grazie Danilo -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/ From spam at me.please Mon Aug 8 23:48:10 2005 From: spam at me.please (Evil Bastard) Date: Tue, 09 Aug 2005 15:48:10 +1200 Subject: Python Project (sigh with Java) In-Reply-To: References: Message-ID: <42f828d9$1@news.orcon.net.nz> Ramza Brown wrote: > And I normally don't take the entire python library with me. I just > take 'jython.jar' so I can distribute it easier. Agreed - if one is happy with the costs of java inter-operation, then jython rocks the house. Otherwise, I could recommend PMW atop Tkinter, since the python wrapping is better implemented and documented than other guis and, for a given level of polish and functionality in a gui, PMW/Tkinter gets the job done with less lines of code and less litres of blood/sweat/tears. -- Cheers EB -- One who is not a conservative by age 20 has no brain. One who is not a liberal by age 40 has no heart. From lee at example.com Mon Aug 1 17:10:59 2005 From: lee at example.com (Lee Harr) Date: Mon, 01 Aug 2005 21:10:59 GMT Subject: inheriting from datetime References: <1122929471.966054.146010@g44g2000cwa.googlegroups.com> Message-ID: On 2005-08-01, Rob Conner wrote: > So this is simple, why can't I run the following code? I've tried many > variances of this, but simply cannot inherit from datetime or > datetime.datetime. I get this on line 3. > TypeError: function takes at most 2 arguments (3 given) > > ******************************** > import datetime > _datetime = datetime.datetime > > class MyDateTime(_datetime): > """ > Identical to builtin datetime.datetime, except it accepts > invalid dates and times as input. > """ > _valid = True > > def __init__(self, year, month, day, *args, **kw): > try: > _datetime.__init__(self, year, month, day, *args, **kw) > except _datetime.ValueError: > _valid = False > self.year = year > self.month = month > self.day = day > self.args = args > self.kw = kw > ******************************** > It helps to post the actual code and error message you are seeing... >>> import datetime >>> class foo(datetime): ... pass ... Traceback (most recent call last): File "", line 1, in ? TypeError: function takes at most 2 arguments (3 given) >>> class foo(datetime.datetime): ... pass ... >>> d = foo() Traceback (most recent call last): File "", line 1, in ? TypeError: function takes at least 3 arguments (0 given) >>> d = foo(1, 2, 3) >>> d foo(1, 2, 3, 0, 0) >>> datetime.datetime(1, 2, 3) datetime.datetime(1, 2, 3, 0, 0) My guess is that the code you posted is not really the code you were runnning. From epost2 at gmail.com Fri Aug 5 11:09:14 2005 From: epost2 at gmail.com (epost2 at gmail.com) Date: 5 Aug 2005 08:09:14 -0700 Subject: newbie question; output from simple print statement Message-ID: <1123254554.417700.22650@o13g2000cwo.googlegroups.com> Can someone explain to me the output of this simple script? I wonder why ['test1.txt'] is printed before "files in c:\", and also why None shows up? ________________ in file test.py: def main(): print "files in c:\ :%s" % ListFiles("c:\") def ListFiles(path): for root,dirs,files in os.walk(path): print files if __name__ == "__main__": main(): ________________ output: C:\> python test.py ['test1.txt'] files in c:\ :None From Scott.Daniels at Acm.Org Tue Aug 23 18:52:40 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 23 Aug 2005 15:52:40 -0700 Subject: Sorta noob question - file vs. open? In-Reply-To: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> Message-ID: <430b9cc0$1@nntp0.pdx.net> Peter A. Schott wrote: > Been reading the docs saying that file should replace open in our code, but this > doesn't seem to work: This was really a misstatement; open is still preferred. file is now a built in class, and its constructor is the same as open. I think the current docs have been fixed. > # Open file for writing, write something, close file > MyFile = file("MyFile.txt", "w") > MyFile.write("This is a test.") > MyFile.close() But you've given us no idea what went wrong. > However, using: > MyFile = open("MyFile.txt", "w") > MyFile.write("This is a test.") > MyFile.close() I cannot help you if you don't tell me what went wrong. Both bits of code seem to do the same thing for me. --Scott David Daniels Scott.Daniels at Acm.Org From scott_list at mischko.com Tue Aug 30 10:06:09 2005 From: scott_list at mischko.com (Scott Chapman) Date: Tue, 30 Aug 2005 07:06:09 -0700 Subject: Anyone know how to do this in pyOpenSSL Message-ID: <431467D1.7060502@mischko.com> The pyOpenSSL list is _very_ quiet. I'm hoping somebody here knows how to do this: openssl smime -sign -in $tempfile -signer /path/to/my_cert -inkey /path/to/my_key -outform der -nodetach -binary | openssl smime -encrypt -des3 -binary -outform pem /path/to/paypal_public_cert ... using pyOpenSSL. M2Crypto won't compile on my box and I'm really lost in the pyOpenSSL library. Cordially, Scott From en.karpachov at ospaz.ru Fri Aug 19 07:30:10 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Fri, 19 Aug 2005 15:30:10 +0400 Subject: while c = f.read(1) In-Reply-To: <7xbr3ucilo.fsf@ruckus.brouhaha.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <7xbr3ucilo.fsf@ruckus.brouhaha.com> Message-ID: <20050819153010.019f0517.jk@ospaz.ru> On 19 Aug 2005 03:43:31 -0700 Paul Rubin wrote: > writes: > > import itertools > > f = open("blah.txt", "r") > > for c in itertools.chain(*f): > > But that can burn an unlimited amount of memory if there are long > stretches of the file with no newlines. There's no real good way > around ugly code. I agree. Moreover, in fact, it is the same as just for c in f.read(): # ... -- jk From drevil_53711 at yahoo.com Thu Aug 18 14:24:51 2005 From: drevil_53711 at yahoo.com (Steve Young) Date: Thu, 18 Aug 2005 11:24:51 -0700 (PDT) Subject: python html Message-ID: <20050818182451.24013.qmail@web40428.mail.yahoo.com> Hi, I am looking for something where I can go through a html page and make change the url's for all the links, images, href's, etc... easily. If anyone knows of something, please let me know. Thanks. -steve ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From stas at tuxzilla.tuxhome Sun Aug 14 09:43:36 2005 From: stas at tuxzilla.tuxhome (stas) Date: Sun, 14 Aug 2005 15:43:36 +0200 Subject: wx.MessageDialog displayed without components inside References: <1123951035.856439.173160@g44g2000cwa.googlegroups.com> <1123976057.103585.237410@z14g2000cwz.googlegroups.com> Message-ID: On Sat, 13 Aug 2005 16:34:17 -0700, perchef wrote: > nope, I have put md.Destroy() away and it didn't change something. > I don't think that's the problem because ShowModal() is a blocking > method, execution is stop until you press YES or NO (in my case with > wx.YES_NO) Just a thought, do you cal the event loop ? Because this minimal example just works like it should. import wx app = wx.PySimpleApp() md = wx.MessageDialog(None,'foo','bar',wx.YES_NO) result = md.ShowModal() app.MainLoop() Stas From russandheather at gmail.com Wed Aug 10 11:53:15 2005 From: russandheather at gmail.com (Qopit) Date: 10 Aug 2005 08:53:15 -0700 Subject: "Compile time" checking? Message-ID: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> Hi there, I'm pretty new to Python and am trying to figure out how to get "will this code compile?"-like code checking. To me this is a pretty basic language/environment requirement, especially when working with large projects. It is *much* better to catch errors at "compile-time" rather than at run-time. One thing I've "found" is the PyChecker module (conveniently embedded in SPE), but it doesn't seem to do that great of a job. For example, the following simple program checks out perfectly as far as PyChecker is concerned: #---- def tester(a,b,c): print "bogus test function",a,b,c tester(1,2,3) #this runs fine tester(1,2) #this obviously causes a run-time TypeError exception #---- It seems to me that this should be an obvious catch for PyChecker. I suppose you could argue that you don't want PyChecker to bark at you any time an exception would be raised since you may intentionally be causing exceptions, but this one seems a pretty simple and obvious one to catch. My questions are: - Am I missing something with my tester example? - Are there other code-checking options other than PyChecker? Any other comments appreciated (aside from things like "just right good code that doesn't have bugs like that" :) ). Thanks! From jdhunter at ace.bsd.uchicago.edu Mon Aug 15 10:02:57 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 15 Aug 2005 09:02:57 -0500 Subject: Gotchas in user-space matplotlib install? References: <626hf1lp7k492cbcq4o1mqhe3hnaqpbhf5@4ax.com> <87d5okurgh.fsf@peds-pc311.bsd.uchicago.edu> <5f51g1hm6ajl5v0qnrqu1635nldjbvqp2g@4ax.com> Message-ID: <87d5ofxppq.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "Matt" == Matt Feinstein writes: Matt> All in all, not actually excruciating-- and now I have a Matt> working version of matplotlib! Matt Feinstein Great! While this is all fresh in your mind, would you be able to add a wiki entry at http://www.scipy.org/wikis/topical_software/MatplotlibCookbook Thanks, JDH From fredrik at pythonware.com Mon Aug 22 16:23:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 22:23:14 +0200 Subject: How to get a unique id for bound methods? References: <43067d0e.1906448017@news.oz.net> Message-ID: Russell E. Owen wrote: >>>The current issue is associated with Tkinter. I'm trying to create a tk >>>callback function that calls a python "function" (any python callable >>>entity). >>> >>>To do that, I have to create a name for tk that is unique to my python >>>"function". A hash-like name would be perfect, meaning a name that is >>>always the same for a particular python "function" and always different >>>for a different python "function". That would save a lot of housekeeping. have you tried Tkinter's built-in _register method? >>> import Tkinter >>> w = Tkinter.Tk() >>> help(w._register) Help on method _register in module Tkinter: _register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk instance Return a newly created Tcl function. If this function is called, the Python function FUNC will be executed. An optional function SUBST can be given which will be executed before FUNC. >>> def func(): ... print "Hello" ... >>> name = w._register(func) >>> name '10768336func' >>> w.tk.call(name) Hello 'None' From mwm at mired.org Mon Aug 29 20:30:42 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 29 Aug 2005 20:30:42 -0400 Subject: using common lisp with python. References: <1125264907.656465.106900@g44g2000cwa.googlegroups.com> <43130f30$0$17711$626a14ce@news.free.fr> <1125332253.886031.256950@g49g2000cwa.googlegroups.com> <1125338833.633816.69020@g49g2000cwa.googlegroups.com> Message-ID: <86zmr09sgd.fsf@bhuda.mired.org> "cipherpunk at gmail.com" writes: > Your best bet is probably to look into your LISP environment's FFI > (Foreign Function Interface). Most LISP environments have some way to > call C code directly. Insofar as going back the other way... that I'm > a little more sketchy on. Guile (the Scheme compiler from GNU) is a > strong contender, though. It's not Common LISP, but it's a LISP with > copious documentation for how to call it from C. I believe SCM is also extensible/embeddable - and is generally a more complete LISP system than Guile. However, it's still Scheme instead of CL. > I really can't see a reason to use Python as a glue layer. I'd > recommend rewriting your LISP code in Python before I'd recommend using > Python to interface between Common LISP and C. Agreed. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fuzzyman at gmail.com Wed Aug 3 11:41:11 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 3 Aug 2005 08:41:11 -0700 Subject: using httplib for authentication In-Reply-To: References: Message-ID: <1123083671.702977.251200@g14g2000cwa.googlegroups.com> James Stroud wrote: > Hello All, > > I want to use python to download files from sites where authentication is > required. The page appears to send a form with the login and pass by post. I > would like to log in and keep this session open within python and > download a number of files automatically. Could anyone kindly point me in the > right direction? I have discovered httplib and read the documentation and > looked at the examples, but they don't seem helpful for this. > Hello James, httplib is built on top of the socket module - but is still a library meant for doing fairly low level http operations. For fetching URLs, urllib2 is probably the way to go. It handles GET and POST with ease. If you think this will do the job then you could try reading the urllib2 tutorial at : http://www.voidspace.org.uk/python/articles.shtml#http You might wnat to look at other extension modules too - ClientCookie for handling cookies, ClientForm for automatically filling in the forms, BeautifulSoup for parsing HTML pages.... All the Best, Fuzzy http://www.voidspace.org.uk/python > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ From elke.hohls at delair.de Fri Aug 26 07:44:56 2005 From: elke.hohls at delair.de (Elke Hohls) Date: Fri, 26 Aug 2005 13:44:56 +0200 Subject: Problems with kdecore... Message-ID: <430F00B8.4010502@delair.de> When I run my Application it crashes at the following part: - [ code ] -------------------------------------------------------- from kdecore import KLibLoader, KLibFactory def myApp (self): # ... offer = KTrader.self().query("text/html") # the offer can handle HTML - so try loading the library strOffer = offer[0].library().latin1() factory = KLibLoader().factory (strOffer) if factory : args = QStringList() args.append("in shell") html = factory.create ( self, 'naaaame', "KParts::ReadOnlyPart", args ) ----------------------------------------------------------------- .. I tried it with an without arguments - everytime it crashes by trying "factory.create" with the answer: KCrash: Application 'myApp.py' crashing... From martin at v.loewis.de Fri Aug 5 20:01:49 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 06 Aug 2005 02:01:49 +0200 Subject: minidom xml & non ascii / unicode & files In-Reply-To: <42f38284$0$5314$636a15ce@news.free.fr> References: <42f38284$0$5314$636a15ce@news.free.fr> Message-ID: <42F3FDED.8050108@v.loewis.de> webdev wrote: > 1. when fetching a web page from the net, how am i supposed to know how > it's encoded.. And can i decode it to unicode and encode it back to a > byte string so i can use it in my code, with the charsets i want, like > utf-8.. ? It depends on the content type. If the HTTP header declares a charset= attribute for content-type, then use that (beware: some web servers report the content type incorrectly. To deal with that gracefully, you have to implement very complex algorithms, which are part of any recent web browser). If there is no charset= attribute, then - if the content type is text/html, look at a meta http-equiv tag in the content. If that declares a charset, use that. - if the content type is xml (plain, or xhtml+xml), look at the XML declaration. Alternatively, pass it to your XML parser. > 2. in the same idea could anyone try to post the few lines that would > actually parse an xml file, with non ascii chars, with minidom > (parseString i guess). doc = xml.dom.minidom.parse("foo.xml") > Then convert a string grabbed from the net so parts of it can be > inserted in that dom object into new nodes or existing nodes. doc..documentElement.setAttribute("bar", text_from_net.decode("koi-8r")) > And finally write that dom object back to a file in a way it can be used > again later with the same script.. open("/tmp/foo.txt","w").write(doc.toxml()) > I've been trying to do that for a few days with no luck.. > I can do each separate part of the job, not that i'm quite sure how i > decode/encode stuff in there, but as soon as i try to do everything at > the same time i get encoding errors thrown all the time.. It would help if you would state what precise code you are using, and what precise error you are getting (for what precise input). > > 3. in order to help me understand what's going on when doing > encodes/decodes could you please tell me if in the following example, s > and backToBytes are actually the same thing ?? > > s = "hello normal string" > u = unicode( s, "utf-8" ) > backToBytes = u.encode( "utf-8" ) > > i knwo they both are bytestrings but i doubt they have actually the same > content.. They do have the same content. There is nothing to a byte string except for the bytes. If the byte string is meant to represent characters, they are the same "thing" only if the assumed encoding is the same. Since the assumed encoding is "utf-8" for both s and backToBytes, they are the same thing. > 4. I've also tried to set the default encoding of python for my script > using the sys.setdefaultencoding('utf-8') but it keeps telling me that > this module does not have that method.. i'm left no choice but to edit > the site.py file manually to change "ascii" to "utf-8", but i won't be > able to do that on the client computers so.. Don't do that. It's meant as a last resort for backwards compatibility, and shouldn't be used for new code. Regards, Martin From benn at cenix-bioscience.com Thu Aug 11 05:12:26 2005 From: benn at cenix-bioscience.com (Neil Benn) Date: Thu, 11 Aug 2005 11:12:26 +0200 Subject: What are modules really for? In-Reply-To: References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> Message-ID: <42FB167A.3000007@cenix-bioscience.com> Tito wrote: > > >>> >>> >>If I want to change one class and replace the file on the install then I >>need to put a whole bunch of classes on - increasing the change of >>making a mistake. >> >> > >Sorry, I don't understand the previous sentence. What is meant by >"replace on the install"? And by "to put a whole bunch of classes on"? > > > > > > Suppose you have a logistics tracking system available on every install in your company - there are 55 installs throughout the company. You wish to push through a patch because of a problem. If you have one class per file you can push that class through onto the client install. However, if you have 15 different classes in one file - you will need to drop all 15 classes through, thereby increasing the likelihood of accidently pushing a bug onto the install. If you want to do live updating (don;t think that this is a feature of Python so it's acadmenic here) then what do you do, reload all 15 classes - just the one you've changed? > >Well, I wasn't talking exactly about making use of dangerous features of > languages, but more about the way of using imperative object-oriented >languages in a non-object-oriented way. > > well, in languages like C#, Java and eiffel - you shouldn't really be doing that anyways. that is why they are poor choices for hobbies, hacks and quickie. >Regards, >Tito > > P.S. why is Glenn McGrath walking about?? Cheers, Neil -- 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 zen19725 at zen.co.uk Wed Aug 3 08:43:07 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 13:43:07 +0100 Subject: Art of Unit Testing References: <87mzo0s25q.fsf@lucien.dreaming> <42efe1ec$0$3713$626a14ce@news.free.fr> Message-ID: On Tue, 02 Aug 2005 23:13:08 +0200, rafi wrote: > >> According to the "extreme programming" paradigm, testing should be done >> several times a day. So a requirement for extreme programm is that tests >> are fast enough. If the testing needs too much time, people are >> discouraged to test often. > >Well as I said above, a unit test is dedicated to a single function or >method. So wehn you update a function / method, you should test the >whole class or module, but maybe not the whole application Often this is true. However sometimes the application is complex with all sorts of dependencies between different parts of it (I know, these should be kept to a minimum), and changes in one thing can break stuff in another module. When that happens, you want to know about it sooner rather than later. -- Email: zen19725 at zen dot co dot uk From knaren at midascomm.com Wed Aug 24 10:45:01 2005 From: knaren at midascomm.com (knaren at midascomm.com) Date: Wed, 24 Aug 2005 20:15:01 +0530 (IST) Subject: Email client in Pyhton Message-ID: Hi grp, I new to this grp and python too. i have started writing few python scripts myself. now i am planning to write a bear minimum email client in pyhton. i found the smtp module of python could serve my pupose. I can send message using mails using the smtp lib. Now i'm looking for some modules which can help me in fetching the mails from the mailserver and managing folders. I also look for some existing mail client, written in python which wud serve my cause. i searched google for no avail. -- K Naren, MeTel Team. http://www.midascomm.com/ From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 1 03:51:53 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 01 Aug 2005 09:51:53 +0200 Subject: [path-PEP] Path inherits from basestring again In-Reply-To: References: <3l1q3tF10l1krU1@individual.net> <3l3e2tF10ehjrU1@individual.net> Message-ID: <3l62auF10t4i5U1@individual.net> phil hunt wrote: > On Sun, 31 Jul 2005 09:48:45 +0200, Reinhold Birkenfeld wrote: >>> >>> An improvement to what? To how the class is implemented, or to how >>> it is used? >> >>No, the second function is cleaner and more readable than the first, >>IMHO. > > True, but the first function, at all of seven lines, is hardly > complicated. I mean, if anyone couldn't understand it, they'd never > make a programmer. > >>> If you mean the former, yes is it, due to the os.path module not >>> providing a function that does this. >>> >>> If you mean the latter, I disagree, because I would then have to >>> call it with something like: >>> >>> pn = normalizePath(Path(p), q) >> >>That's easily helped by s/tp = p/tp = Path(p)/. > > I have no idea what that comment means. That's short for "replace 'tp = p' by 'tp = Path(p)". sed-lingo ;) Reinhold From matt.hammond at rd.bbc.co.uk Fri Aug 19 04:53:20 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Fri, 19 Aug 2005 09:53:20 +0100 Subject: Problem (or even bug?) with Tkinter Message-ID: Here's a strange one in Tkinter that has me stumped: (I'm running python 2.4 on Suse Linux 9.3 64bit) I'm trying to make a set of Entry widgets with Label widgets to the left of each one, using the grid layout. If I make and grid the Label *before* the Entry then the Entry widget doesn't seem to work - it lets me put the cursor in it, but I can't type! See example code below. Is this just me doing something really really silly, or is there a bug here? I'm inclined to think the latter. I've been developing with python 2.4 on Suse Linux 9.3 64bit. I've just tested it on a Win2k machine witih python 2.3 and can type into both Entry widgets. regards Matt ------- #!/usr/bin/env python import Tkinter class ProblemGUI(object): def __init__(self): super(ProblemGUI, self).__init__() self.window = Tkinter.Tk() self.window.title("Try typing into both Entry widgets") # declare and grid Entry widget before Label widget self.entry1 = Tkinter.Entry(self.window) self.entry1.grid(row=0, column=1) self.label1 = Tkinter.Label(self.window, text="CAN WRITE ->") self.label1.grid(row=0,column=0) # declare and grid Label widget before Entry widget self.label2 = Tkinter.Label(self.window, text="CAN'T WRITE ->") self.label2.grid(row=1,column=0) self.entry2 = Tkinter.Entry(self.window) self.entry2.grid(row=1, column=1) x=ProblemGUI() x.window.mainloop() -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From google at spiceaid.com Wed Aug 3 11:33:22 2005 From: google at spiceaid.com (Dr. Who) Date: 3 Aug 2005 08:33:22 -0700 Subject: HTML/text formatting question Message-ID: <1123083202.047304.256330@g14g2000cwa.googlegroups.com> I have a tool that outputs data in either html or text output. Currently I'm writing chucnks like: if html: print '' print '' print ' and\nanother thing and again else" In [2]: import re In [3]: r = re.compile('', re.S) In [4]: r.findall(x) Out[4]: ['something else', 'in a td'] If not, you'll have to explain more clearly what you want. Peace Bill Mill bill.mill at gmail.com From fakeaddress at nowhere.org Sat Aug 20 15:22:12 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 20 Aug 2005 19:22:12 GMT Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: Steven Bethard wrote: > Well, I couldn't find where the general semantics of a negative stride > index are defined, but for sequences at least[1]: > > "The slice of s from i to j with step k is defined as the sequence of > items with index x = i + n*k such that 0 <= n < (j-i)/k." > > This seems to contradict list behavior though. [...] The conclusion is inescapable: Python's handling of negative subscripts is a wart. Indexing from the high end is too useful to give up, but it should be specified by the slicing/indexing operation, not by the value of the index expression. PPEP (Proposed Python Enhancement Proposal): New-Style Indexing Instead of: sequence[start : stop : step] new-style slicing uses the syntax: sequence[start ; stop ; step] It works like current slicing, except that negative start or stop values do not trigger from-the-high-end interpretation. Omissions and None work the same as in old-style slicing. Within the square-brackets, the '$' symbol stands for the length of the sequence. One can index from the high end by subtracting the index from '$'. Instead of: seq[3 : -4] we write: seq[3 ; $ - 4] When square-brackets appear within other square-brackets, the inner-most bracket-pair determines which sequence '$' describes. (Perhaps '$$' should be the length of the next containing bracket pair, and '$$$' the next-out and...?) So far, I don't think the proposal breaks anything; let's keep it that way. The next bit is tricky... Obviously '$' should also work in simple (non-slice) indexing. Instead of: seq[-2] we write: seq[$ - 2] So really seq[-2] should be out-of-bounds. Alas, that would break way too much code. For now, simple indexing with a negative subscript (and no '$') should continue to index from the high end, as a deprecated feature. The presence of '$' always indicates new-style slicing, so a programmer who needs a negative index to trigger a range error can write: seq[($ - $) + index] An Alternative Variant: Suppose instead of using semicolons as the PPEP proposes, we use commas, as in: sequence[start, stop, step] Commas are already in use to form tuples, and we let them do just that. A slice is a subscript that is a tuple (or perhaps we should allow any sequence). We could just as well write: index_tuple = (start, stop, step) sequence[index_tuple] This variant *reduces* the number and complexity of rules that define Python semantics. There is no special interpretation of the comma, and no need for a distinct slice type. The '$' character works as in the PPEP above. It is undefined outside square brackets, but that makes no real difference; the programmer can use len(sequence). This variant might break some tricky code. -- --Bryan From aahz at pythoncraft.com Tue Aug 30 13:41:38 2005 From: aahz at pythoncraft.com (Aahz) Date: 30 Aug 2005 10:41:38 -0700 Subject: how to join two Dictionary together? References: <1125413088.326703.64590@g43g2000cwa.googlegroups.com> Message-ID: In article <1125413088.326703.64590 at g43g2000cwa.googlegroups.com>, DENG wrote: > >dict1={...something...} >dict2={...somethind else ..} >dict1 + dict2 Another option to look into: if you're only using the dict keys and not the valus, maybe you should use sets. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From fuzzyman at gmail.com Wed Aug 10 08:28:25 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 10 Aug 2005 05:28:25 -0700 Subject: MultiFile object does not iterate In-Reply-To: References: Message-ID: <1123676905.280221.69370@g49g2000cwa.googlegroups.com> It has no __iter__ method either. I guess 'next' is just a historical accident. Should be easy enough to wrap it in your own class though and resolve this ? Regards, Fuzzy http://www.voidspace.org.uk/python From richardlewis at fastmail.co.uk Fri Aug 26 05:56:25 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Fri, 26 Aug 2005 10:56:25 +0100 Subject: DOM text Message-ID: <1125050185.2182.241533364@webmail.messagingengine.com> Hello Pythoners, I'm currently writing some Python to manipulate a semi-structured XML document. I'm using DOM (minidom) and I've got working code for transforming the document to HTML files and for adding the 'structured' elements which populate the higher regions of the tree (i.e. near the root). What I have to do next is write some code for working with the 'less structured' elements towards the 'leaf ends' of the tree. These are rather like little sub-documents and contain a mixture of text with inline formatting (for links, font styles, headings, paragraphs etc.) and objects (images, media files etc.). I admit I haven't tried very much code yet, but I'm not sure how I'm going to handle situations like: the user wants to insert a link in the middle of a paragraph. How can I use the DOM to insert a node into the middle of some text? Am I right in thinking that the DOM will reference a whole text node but nothing smaller? Any thoughts or suggestions would be very welcome! Cheers, Richard From paolo_veronelli at tiscali.it Mon Aug 1 19:39:30 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 02 Aug 2005 01:39:30 +0200 Subject: namespaces In-Reply-To: <42ECAB9E.4000501@tiscali.it> References: <42EC9690.2040301@tiscali.it> <42ECAB9E.4000501@tiscali.it> Message-ID: <42EEB2B2.8030903@tiscali.it> Paolino wrote: > Now this is the non polluting version : > > class translate: > import string > all=string.maketrans('','') > badcars=all.translate(all,string.letters+string.digits) > @staticmethod > def __call__(text,table=string.maketrans(badcars,'_'*len(badcars))): > return text.translate(table) > translate=translate() > ## As now a good solution I got (from a RexFi hint in IRC) is via ## classmethods as it doesn't use free variables. import string class translate(object): all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) @classmethod def translate(cls,text): return text.translate(cls.table) translate=translate.translate #### Refactoring again this is the more elegant import string class translateUnderscore(object): all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) def __new__(cls,text): return text.translate(cls.table) #### Which allows for part-function reuse: class translateQuestionmark(translate): table=string.maketrans(translate.badcars,'?'*len(translate.badcars)) translateUnderscore('problem at pytypus.org') translateQuestionmark('problem at pytypus.org') ############### An inefficency for these solutions is the further indirection to lookup attribute 'table' in the call (cls.table). (From RexFi also) Regards Paolino ___________________________________ Aggiungi la toolbar di Yahoo! Search sul tuo Browser, e'gratis! http://it.toolbar.yahoo.com From bronger at physik.rwth-aachen.de Thu Aug 4 03:53:17 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Thu, 04 Aug 2005 09:53:17 +0200 Subject: Wheel-reinvention with Python References: <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> <86mzny1ewn.fsf@bhuda.mired.org> <7cc3f1hdom5iuvljum5gurdgan4721og7u@4ax.com> Message-ID: <877jf2cf4i.fsf@wilson.rwth-aachen.de> Hall?chen! Dennis Lee Bieber writes: > On Thu, 04 Aug 2005 00:53:28 -0400, Mike Meyer declaimed > the following in comp.lang.python: > >> No, it's not a discussion about estimates. The average household >> in a G8 country has more computers that don't run Windows - and >> in fact don't have GUIs at all - than otherwise. This is a fact >> of life. >> > Maybe one needs to have an itemization to understand? > > Digital clocks, Digital watches, cellphones, digital > radio/TV tuners, DVD and CD players, Microwave ovens, VCRs, > printers, the more modern monitors with on-screen menus... (my > dozen or so amateur, MURS, GMRS, FRS radios), cordless telephones, > my heater thermostat, answering machine, pedometer... I did understand, however, my MP3 player makes one whole "computer" in Mike's statistics but it contains at most 5000 lines of own code. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From kosh at aesaeion.com Wed Aug 17 07:26:25 2005 From: kosh at aesaeion.com (William Heymann) Date: Wed, 17 Aug 2005 05:26:25 -0600 Subject: Zope, Python 2.4 pythonScripts import problem In-Reply-To: <1124197773.365465.249690@g14g2000cwa.googlegroups.com> References: <1123854279.041291.39000@g44g2000cwa.googlegroups.com> <1124197773.365465.249690@g14g2000cwa.googlegroups.com> Message-ID: <200508170526.25832.kosh@aesaeion.com> On Tuesday 16 August 2005 07:09 am, krzychu at bmpg.pl wrote: > I see that Python 2.4.x does not work with Zope-2-7-6 properly. When I > start zope I get warning that I should recompile my pythonScripts by > executing manage_addProduct/PythonScripts/recompile. I do it and get > list of scripts whoose were compiled but when I repeat that action I > get the same list of scripts. It doesn't compile them -> when I visit > script by ZMI I still get the following error message "invalid syntax > (Script (Python), line 1)". > > The first script at page > http://www.zope.org/Members/goppelt/2-4-3Upgrade gives no effect -> > outcome is "invalid syntax (Script (Python), line 1)" error i scripts. > > I'm affraid that I will have to resign with Python 2.4.x :( > I read that Python 2.4 was complaisant back but I don't think that > Zope-2-7-6 is??? > Please read the docs that come with zope. No version of zope supports python 2.4 right now. For zope 2.7 and zope 2.8 the python version to use is python 2.3.5. Everytime a new version of python is done a lot of stuff is checked to make sure it works and minor changes are made. I know it is possible to get zope2.7 and 2.8 working fine on python 2.4 but that should only be done by zope developers and not by zope users. From rtconner at gmail.com Wed Aug 10 15:38:51 2005 From: rtconner at gmail.com (Rob Conner) Date: 10 Aug 2005 12:38:51 -0700 Subject: Why does __init__ not get called? In-Reply-To: <1123618110.763724.304990@g44g2000cwa.googlegroups.com> References: <1123532930.128403.98780@f14g2000cwb.googlegroups.com> <1123536834.629449.154790@g44g2000cwa.googlegroups.com> <1123601386.567072.111240@o13g2000cwo.googlegroups.com> <1123618110.763724.304990@g44g2000cwa.googlegroups.com> Message-ID: <1123702730.955133.105950@g49g2000cwa.googlegroups.com> I'm out of my league too. I don't know enough about __new__ and __init__. I just went another route and did a wrapper for datetime, and didn't extend it. Thanks for the effort. By chance... does anyone know, if I wrote a class, and just wanted to override __new__ just for the fun of it. What would __new__ look like so that it behaves exactly the same as it does any other time. From jmdeschamps at cvm.qc.ca Sat Aug 20 10:46:57 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 20 Aug 2005 07:46:57 -0700 Subject: python classes taught In-Reply-To: <1124476622.522386.166050@g14g2000cwa.googlegroups.com> References: <1124476622.522386.166050@g14g2000cwa.googlegroups.com> Message-ID: <1124549216.994596.68930@g47g2000cwa.googlegroups.com> Cegep du Vieux Montreal (technical college level), uses Python for CGI in web developement class. ...At least when I give this course ;-) Jean-Marc From nelson at monkey.org Wed Aug 3 13:57:44 2005 From: nelson at monkey.org (Nelson Minar) Date: Wed, 03 Aug 2005 17:57:44 GMT Subject: time.clock() or time.time() References: <1122997716.087490.272580@f14g2000cwb.googlegroups.com> Message-ID: "peterbe at gmail.com" writes: > I'm trying to benchmark some function calls for Zope project Other folks have explained time() vs. clock(), so I'll leave that. But rather than roll your own timer functions, consider using timeit. From wolfgang.keller.nospam at gmx.de Wed Aug 17 10:55:57 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Wed, 17 Aug 2005 16:55:57 +0200 Subject: Python as VBA replacement under Windows? References: <7cKdnQ8TVuYj157eRVn-oQ@telcove.net> Message-ID: > Because the MS Office suite and a few (very few!) other applications expose > their object models via COM, you can manipulate these programs with Python > and other languages. No applicatoin "supports VBA as a macro language". What I meant was that quite a lot of Windows applications (not only MS Office) allow to execute VBA scripts just like "macros" from within the application. What I want now is to write a "dummy" VBA script "container" that consists of/executes Python sourcecode by calling the Pythonwin interpreter. > Rather - VBA is bundled and integrated with MS Office in order to manipulate > COM. You can use Python to do that too! Yup, from outside. What I would like to do is do it from "inside" the application. > "perfectly possible"? Well, at least as far as there's a COM interface and for someone who refuses to learn VB(A) but still wants to script Windows applications. Sincerely, Wolfgang Keller From tjreedy at udel.edu Thu Aug 4 19:23:55 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 4 Aug 2005 19:23:55 -0400 Subject: Parallel arithmetic? References: <42f298d6$1_5@alt.athenanews.com><7xll3h72av.fsf@ruckus.brouhaha.com> Message-ID: >"#"map" will be removed from the next versions of python. The next version will be 2.5. Map will not go away then. In 3.0, in the indefinite future, it might go away, it might just be moved. tjr From nas at arctrix.com Mon Aug 22 17:31:42 2005 From: nas at arctrix.com (Neil Schemenauer) Date: Mon, 22 Aug 2005 15:31:42 -0600 Subject: Revised PEP 349: Allow str() to return unicode strings Message-ID: <20050822213142.GA5702@mems-exchange.org> [Please mail followups to python-dev at python.org.] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is feasible. It would be helpful if people could test the patched Python with their own applications and report any incompatibilities. PEP: 349 Title: Allow str() to return unicode strings Version: $Revision: 1.3 $ Last-Modified: $Date: 2005/08/22 21:12:08 $ Author: Neil Schemenauer Status: Draft Type: Standards Track Content-Type: text/plain Created: 02-Aug-2005 Post-History: 06-Aug-2005 Python-Version: 2.5 Abstract This PEP proposes to change the str() built-in function so that it can return unicode strings. This change would make it easier to write code that works with either string type and would also make some existing code handle unicode strings. The C function PyObject_Str() would remain unchanged and the function PyString_New() would be added instead. Rationale Python has had a Unicode string type for some time now but use of it is not yet widespread. There is a large amount of Python code that assumes that string data is represented as str instances. The long term plan for Python is to phase out the str type and use unicode for all string data. Clearly, a smooth migration path must be provided. We need to upgrade existing libraries, written for str instances, to be made capable of operating in an all-unicode string world. We can't change to an all-unicode world until all essential libraries are made capable for it. Upgrading the libraries in one shot does not seem feasible. A more realistic strategy is to individually make the libraries capable of operating on unicode strings while preserving their current all-str environment behaviour. First, we need to be able to write code that can accept unicode instances without attempting to coerce them to str instances. Let us label such code as Unicode-safe. Unicode-safe libraries can be used in an all-unicode world. Second, we need to be able to write code that, when provided only str instances, will not create unicode results. Let us label such code as str-stable. Libraries that are str-stable can be used by libraries and applications that are not yet Unicode-safe. Sometimes it is simple to write code that is both str-stable and Unicode-safe. For example, the following function just works: def appendx(s): return s + 'x' That's not too surprising since the unicode type is designed to make the task easier. The principle is that when str and unicode instances meet, the result is a unicode instance. One notable difficulty arises when code requires a string representation of an object; an operation traditionally accomplished by using the str() built-in function. Using the current str() function makes the code not Unicode-safe. Replacing a str() call with a unicode() call makes the code not str-stable. Changing str() so that it could return unicode instances would solve this problem. As a further benefit, some code that is currently not Unicode-safe because it uses str() would become Unicode-safe. Specification A Python implementation of the str() built-in follows: def str(s): """Return a nice string representation of the object. The return value is a str or unicode instance. """ if type(s) is str or type(s) is unicode: return s r = s.__str__() if not isinstance(r, (str, unicode)): raise TypeError('__str__ returned non-string') return r The following function would be added to the C API and would be the equivalent to the str() built-in (ideally it be called PyObject_Str, but changing that function could cause a massive number of compatibility problems): PyObject *PyString_New(PyObject *); A reference implementation is available on Sourceforge [1] as a patch. Backwards Compatibility Some code may require that str() returns a str instance. In the standard library, only one such case has been found so far. The function email.header_decode() requires a str instance and the email.Header.decode_header() function tries to ensure this by calling str() on its argument. The code was fixed by changing the line "header = str(header)" to: if isinstance(header, unicode): header = header.encode('ascii') Whether this is truly a bug is questionable since decode_header() really operates on byte strings, not character strings. Code that passes it a unicode instance could itself be considered buggy. Alternative Solutions A new built-in function could be added instead of changing str(). Doing so would introduce virtually no backwards compatibility problems. However, since the compatibility problems are expected to rare, changing str() seems preferable to adding a new built-in. The basestring type could be changed to have the proposed behaviour, rather than changing str(). However, that would be confusing behaviour for an abstract base type. References [1] http://www.python.org/sf/1266570 Copyright This document has been placed in the public domain. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 End: -------------- next part -------------- PEP: 349 Title: Allow str() to return unicode strings Version: $Revision: 1.3 $ Last-Modified: $Date: 2005/08/22 21:12:08 $ Author: Neil Schemenauer Status: Draft Type: Standards Track Content-Type: text/plain Created: 02-Aug-2005 Post-History: 06-Aug-2005 Python-Version: 2.5 Abstract This PEP proposes to change the str() built-in function so that it can return unicode strings. This change would make it easier to write code that works with either string type and would also make some existing code handle unicode strings. The C function PyObject_Str() would remain unchanged and the function PyString_New() would be added instead. Rationale Python has had a Unicode string type for some time now but use of it is not yet widespread. There is a large amount of Python code that assumes that string data is represented as str instances. The long term plan for Python is to phase out the str type and use unicode for all string data. Clearly, a smooth migration path must be provided. We need to upgrade existing libraries, written for str instances, to be made capable of operating in an all-unicode string world. We can't change to an all-unicode world until all essential libraries are made capable for it. Upgrading the libraries in one shot does not seem feasible. A more realistic strategy is to individually make the libraries capable of operating on unicode strings while preserving their current all-str environment behaviour. First, we need to be able to write code that can accept unicode instances without attempting to coerce them to str instances. Let us label such code as Unicode-safe. Unicode-safe libraries can be used in an all-unicode world. Second, we need to be able to write code that, when provided only str instances, will not create unicode results. Let us label such code as str-stable. Libraries that are str-stable can be used by libraries and applications that are not yet Unicode-safe. Sometimes it is simple to write code that is both str-stable and Unicode-safe. For example, the following function just works: def appendx(s): return s + 'x' That's not too surprising since the unicode type is designed to make the task easier. The principle is that when str and unicode instances meet, the result is a unicode instance. One notable difficulty arises when code requires a string representation of an object; an operation traditionally accomplished by using the str() built-in function. Using the current str() function makes the code not Unicode-safe. Replacing a str() call with a unicode() call makes the code not str-stable. Changing str() so that it could return unicode instances would solve this problem. As a further benefit, some code that is currently not Unicode-safe because it uses str() would become Unicode-safe. Specification A Python implementation of the str() built-in follows: def str(s): """Return a nice string representation of the object. The return value is a str or unicode instance. """ if type(s) is str or type(s) is unicode: return s r = s.__str__() if not isinstance(r, (str, unicode)): raise TypeError('__str__ returned non-string') return r The following function would be added to the C API and would be the equivalent to the str() built-in (ideally it be called PyObject_Str, but changing that function could cause a massive number of compatibility problems): PyObject *PyString_New(PyObject *); A reference implementation is available on Sourceforge [1] as a patch. Backwards Compatibility Some code may require that str() returns a str instance. In the standard library, only one such case has been found so far. The function email.header_decode() requires a str instance and the email.Header.decode_header() function tries to ensure this by calling str() on its argument. The code was fixed by changing the line "header = str(header)" to: if isinstance(header, unicode): header = header.encode('ascii') Whether this is truly a bug is questionable since decode_header() really operates on byte strings, not character strings. Code that passes it a unicode instance could itself be considered buggy. Alternative Solutions A new built-in function could be added instead of changing str(). Doing so would introduce virtually no backwards compatibility problems. However, since the compatibility problems are expected to rare, changing str() seems preferable to adding a new built-in. The basestring type could be changed to have the proposed behaviour, rather than changing str(). However, that would be confusing behaviour for an abstract base type. References [1] http://www.python.org/sf/1266570 Copyright This document has been placed in the public domain. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 End: From richie at entrian.com Mon Aug 1 09:35:46 2005 From: richie at entrian.com (Richie Hindle) Date: Mon, 01 Aug 2005 14:35:46 +0100 Subject: Py: a very dangerous language In-Reply-To: References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> Message-ID: [Harald] > Always go to bed exactly when you want to write the first lambda. [Peter] > Eureka. The Twentieth Pythonic Thesis has finally surfaced. +1 QOTW. -- Richie Hindle richie at entrian.com From christopher.saunter at durham.ac.uk Sun Aug 7 14:39:20 2005 From: christopher.saunter at durham.ac.uk (c d saunter) Date: Sun, 7 Aug 2005 18:39:20 +0000 (UTC) Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> Message-ID: Kay Schluehr (kay.schluehr at gmx.net) wrote: : No good news for scripting-language fans: : http://www.phpmag.net/itr/news/psecom,id,23284,nodeid,113.html Just as well I ditched a scripting language for Python then... cds From c.gillespie at ncl.ac.uk Thu Aug 18 12:25:15 2005 From: c.gillespie at ncl.ac.uk (Colin Gillespie) Date: Thu, 18 Aug 2005 17:25:15 +0100 Subject: Put a url in a browsers address bar In-Reply-To: References: Message-ID: <4304B66B.6030706@ncl.ac.uk> > >> I would like to place a url in my browsers address bar, then execute. >> How can do this? >> > > def goToGoogle(): > import webbrowser > webbrowser.open("www.google.com"); > Thanks for the quick reply. Do you know what module I would use to fill out a form on an open web page? Thanks Colin From peter at engcorp.com Wed Aug 3 09:44:02 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 03 Aug 2005 09:44:02 -0400 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: Christoph Zwerschke wrote: > I think wanting to have a more global initialization > indicates that you are acutally not wanting to do a "unit" test, but a > more global test of the overall system, something like an acceptance or > integration test, i.e. you are trying to abuse unittest for something it > was not intended to be used for. As I mentioned in another post just now, we use unittest for acceptance testing and other kinds of high level testing. We also try very very hard to follow XP rules of thumb in terms of keeping our setup code short and fast. As a result, we generally don't need to do what you are finding you need to do, and unittest is quite adequate. Don't try to make the point that unittest cannot do acceptance testing; it's _your_ acceptance tests which are the issue here, and I agree unittest was not designed specifically to do exactly what you want. It also wasn't designed to prevent it, but really just to be uninvolved in this issue. The whole JUnit family wasn't designed to solve all testing problems, but (I infer, from long use) to be a fairly simple and therefore general approach. It doesn't have a huge array of features supporting all possible approaches to testing, but it's simple enough not to prevent you from doing what you need to do in most cases. If you want a test framework with built-in support for what you need, that's fine. In programming, one size doesn't fit all. -Peter From jgrahn-nntq at algonet.se Sat Aug 20 05:42:46 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 20 Aug 2005 09:42:46 GMT Subject: stdin -> stdout References: Message-ID: On Fri, 19 Aug 2005 15:26:27 GMT, max(01)* wrote: > hi. > > i was wondering, what's the simplest way to echo the standard input to > the standard output, with no modification. > > i came up with: ... > but i guess there must be a simpler way. > > using bash i simply do 'cat', *sigh*! ... > ps: in perl you ca do this: > > ... > while ($line = ) > { > print STDOUT ("$line"); > } > ... Actually, in perl it's easier than that, if you can tolerate that it also filters file(s) given on the command-line: while(<>) { print; } or even: #!/usr/bin/perl -p ; Of course, not every programming language needs to have easy-to-use filtering capabilities at the core. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From zarnovican at gmail.com Fri Aug 19 13:18:39 2005 From: zarnovican at gmail.com (BranoZ) Date: 19 Aug 2005 10:18:39 -0700 Subject: __del__ pattern? In-Reply-To: References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> <1124232686.973363.317640@z14g2000cwz.googlegroups.com> <1124234979.494554.283670@g44g2000cwa.googlegroups.com> Message-ID: <1124471919.475415.91070@g44g2000cwa.googlegroups.com> Bryan Olson wrote: > > Use file that is writeable by A and B in a directory that is > > writeable only by root. > > Is that portable? I have the feeling that you are asking if it works on Windows. No idea! I have only user experience with Windows. On UNIX it is as portable as 'flock', which means all modern Unices (be careful about NFS). > What's the sequence the program should try? 1. open a file, which name was previously agreed on (like /var/tmp/-) If it fails, report error and exit. System error or somebody has created unaccessible file by the same name. 2. Try to aquire a flock on the descriptor from step 1. If it fails, some running process already has the lock, exit 3. lock will be released and lockfile closed automaticaly by OS on process exit. import sys, fcntl try: lockfile=open('/var/tmp/test1', 'w') fcntl.flock(lockfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: print sys.exc_info()[1] sys.exit(-1) You can flock any open file, no matter if it is read/write/append. BranoZ From lycka at carmen.se Wed Aug 24 12:22:57 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 24 Aug 2005 18:22:57 +0200 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon wrote: > I think he did, because both expression are not equivallent > unless some implicite constraints make them so. Values where > both expressions differ are: > > start1=67, stop1=9, start2=10, stop2=29 Ouch! That didn't occur to me. How sloppy to just assume that time periods can't end before they start. I'll shut up now. You win, I'm obviously the idiot here, and Python's must be redesigned from ground up. Pyrdon maybe? From noreply at gcgroup.net Sun Aug 21 14:53:44 2005 From: noreply at gcgroup.net (William Gill) Date: Sun, 21 Aug 2005 18:53:44 GMT Subject: tkinter text widget question In-Reply-To: <4308cb26$0$12107$636a15ce@news.free.fr> References: <4308cb26$0$12107$636a15ce@news.free.fr> Message-ID: rafi wrote: > William Gill wrote: > >> The tkinter text widget uses indexes to identify row:column offsets >> within the text, but it seems counter intuitive to have to convert row >> and column integers to a string like "0.1'. It's great that index can >> take a string, but what about looping through rows and columns? Am I >> missing a way to use integers directly, or should I create a class >> that takes the two integers and returns them formatted as the proper >> string? > > > tkinter relies on tk that is for tcl at first, and in tcl every thing is > a string (more or less). > > "%s.%s" % (row, column) Simple enough. (sometimes I can't see the simplest things, without complicating them) Thanks, Bill > > should answer your problem easily > > my 2 cents > From peter at engcorp.com Thu Aug 18 14:08:37 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 18 Aug 2005 14:08:37 -0400 Subject: question about binary and serial info In-Reply-To: <1124386952.353027.93050@g47g2000cwa.googlegroups.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <1124386952.353027.93050@g47g2000cwa.googlegroups.com> Message-ID: nephish at xit.net wrote: >>>>import serial >>>>ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1) >>>>a = ser.read(1) >>>>print a It sounds like you want to convert characters into their corresponding integer values. To do this, use the ord() builtin function. >>> ord('^') 94 Then you can do the bitwise operations you want. (Of course, you might be looking for the struct module (see the docs on that) instead of just ord(). That would be the case if you want to convert more than one character at a time, to some numeric value.) If this is what you want, part of the confusion was your calling the incoming data a "string" when it's really a series of characters, which you will be dealing with individually. Another part of the confusion was referring to ASCII. From the looks of things, your data is just bytes, not ASCII. ASCII refers not to the bytes themselves, but to the meaning assigned to those bytes for certain purposes. For example, the bytes 70, 111, and 111 are just three bytes, with no particular meaning to anyone. If you want to treat them as ASCII, however, they represent these three characters: "Foo". Your data looks like chunk when treated as ASCII, so it's probably just bytes. -Peter From yoav_artzi at il.vio.com Mon Aug 22 03:33:19 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Mon, 22 Aug 2005 10:33:19 +0300 Subject: Uploading images to imageshack.us with Python In-Reply-To: <1124688349.177133.170420@o13g2000cwo.googlegroups.com> References: <1124688164.318336.55370@z14g2000cwz.googlegroups.com> <1124688349.177133.170420@o13g2000cwo.googlegroups.com> Message-ID: <43097e7b$1@news.bezeqint.net> I would love a script to upload images to Imageshack.us. Any chance you can post the latest version or email it to me? Thanks. Ricardo Sanchez wrote: > I forgot to add that I'm behind a proxy, but I think that is > irrelevant. > > If you are not behind a proxy replace this line: > > print post_multipart('proxy-a.mains.nitech.ac.jp', 8080, > 'http://imageshack.us/index.php', params, files) > > with > > print post_multipart('imageshack.us', 80, '/index.php', params, files) > From google at phaedro.com Mon Aug 29 17:48:41 2005 From: google at phaedro.com (google at phaedro.com) Date: 29 Aug 2005 14:48:41 -0700 Subject: SocketServer and a Java applet listener References: <1124913592.821488.204350@g47g2000cwa.googlegroups.com> <1125296874.552905.313490@g43g2000cwa.googlegroups.com> Message-ID: <1125352121.202619.45230@g47g2000cwa.googlegroups.com> Steve Horsley schreef: > google at phaedro.com wrote: > > Steve Horsley schreef: > > > > > >>Probably the same problem. If you didn't send a 2 byte length > >>indicator first, then java's readUTF() will have tried to > >>interpret the first 2 bytes that you did actually send as the > >>string length, and may well simply be waiting patiently for the > >>rest to arrive. > >> > > > > I just couldn't get read/writeUTF and python unicode to interface, so I > > refactored the applet's socketlistener to convert the > > socket.getInputStream to a BufferedInputReader on which I call the > > readline() method. > There are two normal ways to delineate messages in the > byte-stream: An explicit length indication up front (which java > read/writeUTF chooses), or a unique end-of-message indication at > the end such as your readline() for strings that end in linefeed. > > > If you choose to go for the java read/writeUTF approach, the > 2-byte length indicator goes Most Significant Byte first, so a > 100 char string would be preceded by 00 64 ... Also, the > indicator gives the number of bytes after encoding, not the > number of characters before encoding. > You are right, Steven. I invested some time and isolated the problem of transferring UTF-8 strings between a python SocketServer and a Java applet. In a very, very draft version, hereby surrounded by every disclaimer imagineable (as in "Don't try this at home!") I have put the result on a webpage: http://www.phaedro.com/javapythonutf8/ Not only I tried to give a more or less 'generic' solution to the UTF-8 interface (reversing the leading bytes using python's struct module, and based on SocketServer.StreamingRequestHandler), maybe the draft-craft helps others looking for (rather scarce) examples of SocketServer implementations - this one is very trivial so maybe others can learn more efficiently than I had to do. -- Thijs Cobben Explicit typing sux. From stefan.rank at ofai.at Fri Aug 5 02:20:36 2005 From: stefan.rank at ofai.at (Stefan Rank) Date: Fri, 05 Aug 2005 08:20:36 +0200 Subject: Advanced concurrancy In-Reply-To: <1123146951.295678.82770@g14g2000cwa.googlegroups.com> References: <42ea98a2$0$1185$ed2619ec@ptn-nntp-reader01.plus.net> <42f154fd$0$14656$ed2619ec@ptn-nntp-reader02.plus.net> <1123146951.295678.82770@g14g2000cwa.googlegroups.com> Message-ID: <42F30534.8000204@ofai.at> on 04.08.2005 11:15 Matt Hammond said the following: > Hi Stefan, > >>It seems as though all components basically have to do busy waiting now. > > You are right - components are, for the most part, busy-waiting. Which > is not a good thing! > >>So do you plan on including a kind of scheduler-aware blocking >>communication (like the `channels` of the `tasklets` in stackless)? >> [snip] > > There is basic support for components to block, by calling the > self.pause() method. From the next yield, this blocks further execution > until > data arrives on any inbox. > [snip] ah, i was searching for blocking on a specific inbox, but this is actually a saner approach i think. why should you block on one inbox and ignore data coming in on another... > There are quite probably better mechanisms around - hence the > distinction, in the code, between microprocesses and components. > We'd be very interested if yourself or other people want to play with > alternative communication & blocking mechanisms. i think in-out channels is probably the best way for easy to manage comunicating processes. > I'd hope that even if the components and postboxes model doesn't > work out in the long run, the underlying generator based > microprocesses code could still be of some value to others! yes both levels will (it will take some time before i can use it here...), i think of it as a more complete version of some of the stackless features in standard python. (thanks again by the way) the magic.greenlets have 'cooperative microprocesses', but lack the more pipe-like communication facilities and the independency of the generators+scheduler based approach. the coroutine support in future pythons (see the generator PEPs) will probably make this easier... maybe:: next_inbox_to_read = yield blockon(inbox1, inbox2) this communication infrastructure is definitely a Good Thing (TM), the same holds for a standard environment or registry (wassitsname, your CAT thing) as you need at least one well-known point of reference in a 'distributed' system. now if someone could only cut the gordian knot of the GlobalInterpreterLock to make all this really concurrent... and then, when she's at it, allow transparent distribution of components in a network... ;-) From amk at amk.ca Thu Aug 11 10:50:48 2005 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 11 Aug 2005 09:50:48 -0500 Subject: Pre-PEP Proposal: Codetags References: <42FAF489.3010306@v.loewis.de> Message-ID: On Thu, 11 Aug 2005 08:47:37 +0200, Martin v. L?wis wrote: > I think you somewhat misunderstood the purpose of the PEP process. > This is meant primarily for enhancements to Python (the language > and its library), ... PEP 0 disagrees: PEP stands for Python Enhancement Proposal. A PEP is a design document providing information to the Python community, or describing a new feature for Python. The PEP should provide a concise technical specification of the feature and a rationale for the feature. ... There are two kinds of PEPs. A Standards Track PEP describes a new feature or implementation for Python. An Informational PEP describes a Python design issue, or provides general guidelines or information to the Python community, but does not propose a new feature. Most of PEP 0 is concerned with describing the workflow for Standards Track PEPs, of course, but I guess there's not much to say for informational PEPs. ("Publish your PEP. Eventually, freeze the PEP and stop making changes to it." would be about the sum of it.) I think we need to encourage writing detailed specifications of interfaces for the community's use, such as the WSGI interface (PEP 333, IIRC), so using the PEP repository for this purpose is a good idea. If such things are deemed off-topic for PEPs, then I think we should have a separate set of documents for this (perhaps the suggested PEEPS: Python Environment Enhancement Proposals). --amk From florent.newsgroups at kynesthesy.org Wed Aug 3 11:50:15 2005 From: florent.newsgroups at kynesthesy.org (florent) Date: Wed, 03 Aug 2005 17:50:15 +0200 Subject: trying to parse non valid html documents with HTMLParser In-Reply-To: References: <42efc9ae$0$12924$636a15ce@news.free.fr> <42f09837$0$4042$636a15ce@news.free.fr> Message-ID: <42f0e77b$0$29939$636a15ce@news.free.fr> > Are you saying that Beautiful Soup can't parse the HTML? If so, I'm > sure the author would like an example so he can "fix" it. I finally use the htmllib module wich is more permissive than the HTMLParser module when parsing bad html documents. Anyway, where can I find the author's contact informations ? From zarnovican at gmail.com Mon Aug 15 10:34:04 2005 From: zarnovican at gmail.com (BranoZ) Date: 15 Aug 2005 07:34:04 -0700 Subject: __del__ pattern? In-Reply-To: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: <1124116444.611102.49170@z14g2000cwz.googlegroups.com> > So when my class is instantiated, I create a little lock file, and I > have a __del__ method that deletes the lock file. Unfortunately, there > seem to be some circumstances where my lock file is not getting > deleted. Maybe the interpreter died by the signal.. in that case the __del__ is not called. You can try 'flock', instead of lock files. import fcntl class Test1(object): def __init__(self): self.lock=open('/var/tmp/test1', 'w') fcntl.flock(self.lock.fileno(), fcntl.LOCK_EX) print 'Lock aquired!' def __del__(self): fcntl.flock(self.lock.fileno(), fcntl.LOCK_UN) self.lock.close() In this case, if interpreter dies, the lock is released by OS. If you try to create another instance in the same interpreter or another, the call will block in __init__. You can change it to raise an exception instead. BranoZ From hpk at trillke.net Tue Aug 30 06:51:53 2005 From: hpk at trillke.net (holger krekel) Date: Tue, 30 Aug 2005 12:51:53 +0200 Subject: Pypy - Which C modules still need converting to py? In-Reply-To: References: Message-ID: <20050830105152.GB28663@solar.trillke.net> Hi Caleb, On Tue, Feb 08, 2005 at 22:32 -0500, Caleb Hattingh wrote: > I saw it on a webpage a few days ago, can't seem to find it again. Tried > a google search for > > "pypy needed translate C modules" > > but that didn't turn up what I was looking for. Anyone have that page > ref handy listing the C modules that the pypy team need translated into > python? I think that currently the best page for that actually is the compliancy test results page: http://codespeak.net/~hpk/pypy-testresult/ especially in the "non-core" section further below. You'll see a list of the currently not implemented C-level modules. However, most interesting is completing full posix/os-module support e.g. for listdir() and process-creation functionality. Also having a socket-API wrapper at RPython/low-level-function level and for e.g. 'zlib' seem like "big time" enablers for allowing more programs/modules to run on top of pypy-c/pypy-llvm. (we are employing a "pypy-XYZ" scheme where XYZ marks the backend). Recently, Niklaus Heidimann successfully implemented the array and _sre module as part of his SOC project, of which he got the latter to translate to low-level during the last Heidelberg sprint! cheers, holger From roccomoretti at hotpop.com Fri Aug 19 10:00:58 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Fri, 19 Aug 2005 09:00:58 -0500 Subject: Module Name Conflicts In-Reply-To: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: torched_smurf at yahoo.com wrote: > I have a java program in a package called 'cmd'. This of course > conflicts with the builtin python package of the same name. The thing > is, I need to be able to import from both of these packages in the same > script. I can import either one first, but any future attempt to import > from cmd.* will look up the first cmd that was imported, so the second > package is essentially eclipsed. I've tried fiddling with sys.path and > sys.packageManager.searchPath, to no avail. To answer the obvious first > suggestion, no I can't rename the java package to 'Cmd' or anything > like that. Any ideas? > > -Smurf Never used it myself, but you can try to use the builtin 'imp' module. Python Library Reference 3.21 imp -- Access the import internals This module provides an interface to the mechanisms used to implement the import statement. It defines the following constants and functions: ... From onurb at xiludom.gro Mon Aug 8 12:48:22 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 08 Aug 2005 18:48:22 +0200 Subject: Python -- (just) a successful experiment? In-Reply-To: References: Message-ID: <42f78cd7$0$26279$626a14ce@news.free.fr> Eric Pederson wrote: > Raise your hand if you think the best technology wins! > Those who have raised hands should google for "worse is better"... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From cantabile.03 at wanadoo.fr Sun Aug 7 15:33:21 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Sun, 07 Aug 2005 21:33:21 +0200 Subject: gettext again In-Reply-To: References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> Message-ID: <42f66201$0$897$8fcfb975@news.wanadoo.fr> stasz a ?crit : > On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote: > > >>Hi, >>I'm failing to make it work but can't find out what's wrong. Here's what >>I do : > > [....] > >>How come ? What's wrong with what I am doing ? > > Start with this little howto about gettext. > http://childsplay.sourceforge.net/translate-howto.html > > And then do this in your test.py: > http://www.python.org/doc/2.4.1/lib/node330.html > > You should read the part about gettext in the Python Library Reference > it's really good :-) > > Good luck, > Stas Z > > Well, I must be dumb, because I did exactly that and it still doesn't work... BTW, I have no pygettext module. I asked here and somebody said it was deprecated and now included in xgettext. And I've read the Python doc about gettext about ten times, but it seems quite outdated since it calls pygettext (as staded above)... I've read the info pages of gettext too (quite a long work). Here's my test1.py file again : =========================== import gettext, os, locale locale.setlocale(locale.LC_ALL) gettext.install('test1.py', '/usr/share/locale') msg = _("This is a message without accented characters.") print msg =========================== What can I do now ? From philippe at philippecmartin.com Sat Aug 13 05:10:56 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sat, 13 Aug 2005 09:10:56 GMT Subject: How to find Python path in Visual C++ install wizard Message-ID: Hi, I realize this is not really a Python question but ... I am trying to setup an .msi for my software (Python code (.pyc) + drivers) to make installation easier for Windows users. I am using the installer that comes with V. C++ 7.1. I would like to find the way to make sure Python is installed and then copy automatically my files into its hierarchy. PS: for many reasons, I do not wish to use setup.py. Best regards, Philippe From pink at odahoda.de Wed Aug 3 15:23:54 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 03 Aug 2005 21:23:54 +0200 Subject: trying to parse non valid html documents with HTMLParser References: <42efc9ae$0$12924$636a15ce@news.free.fr> <42f0e5d0$0$20055$636a15ce@news.free.fr> <1123086651.355459.83160@f14g2000cwb.googlegroups.com> Message-ID: Steve M wrote: >>You were right, the HTMLParser of htmllib is more permissive. He just > ignores the bad tags ! > > The HTMLParser on my distribution is a she. But then again, I am using > ActivePython on Windows... Although building parsers is for some strange reason one of my favourite programming adventures, I do not have such a personal relationship with my classes ;) -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From jwashin at vt.edu Mon Aug 22 09:55:45 2005 From: jwashin at vt.edu (Jim Washington) Date: Mon, 22 Aug 2005 13:55:45 GMT Subject: Sanitizing untrusted code for eval() Message-ID: I'm still working on yet another parser for JSON (http://json.org). It's called minjson, and it's tolerant on input, strict on output, and pretty fast. The only problem is, it uses eval(). It's important to sanitize the incoming untrusted code before sending it to eval(). Because eval() is evil http://blogs.msdn.com/ericlippert/archive/2003/11/01/53329.aspx apparently in every language. A search for potential trouble with eval() in python turned up the following. 1. Multiplication and exponentiation, particularly in concert with strings, can do a DoS on the server, e.g., 'x'*9**99**999**9999 2. lambda can cause mischief, and therefore is right out. 3. Introspection can expose other methods to the untrusted code. e.g., {}.__class__.__bases__[0].__subclasses__... can climb around in the object hierarchy and execute arbitrary methods. 4. List comprehensions might be troublesome, though it's not clear to me how a DoS or exploit is possible with these. But presuming potential trouble, 'for' is also right out. It's not in the JSON spec anyway. So, the above seems to indicate disallowing "*", "__", "lambda", and "for" anywhere outside a string in the untrusted code. Raise an error before sending to eval(). I'm using eval() with proper __builtins__ and locals, e.g., result =eval(aString, {"__builtins__":{'True':True,'False':False,'None':None}}, {'null':None,'true':True,'false':False}) I am familiar with this thread: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/cbcc21b95af0d9cc Does anyone know of any other "gotchas" with eval() I have not found? Or is eval() simply too evil? -Jim Washington From jepler at unpythonic.net Mon Aug 1 11:24:53 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 1 Aug 2005 10:24:53 -0500 Subject: Getting not derived members of a class In-Reply-To: References: Message-ID: <20050801152448.GA18696@unpythonic.net> On 'y', Python has no way of recording where '_a' and '_b' were set, so you can't tell whether it comes from class 'a' or 'b'. You can find the attributes that are defined on 'b' only, though, by using 'b.__dict__.keys()', or 'y.__class__.__dict__.__keys__()'. This gives ['__module__', 'who1', '__init__', '__doc__'] If you want to limit yourself to current versions of cpython (because the bytecode used in cpython is only an implementation detail) and define a 'member of class a' as one where a.__init__ has a statement like 'self.z = ...', you can peer into the bytecodes. Something like this: from dis import HAVE_ARGUMENT, opname LOAD_FAST = chr(opname.index('LOAD_FAST')) STORE_ATTR = chr(opname.index('STORE_ATTR')) HAVE_ARGUMENT = chr(HAVE_ARGUMENT) def find(cls): ns = cls.__dict__ result = ns.keys() init = ns.get('__init__', None) if not init: return ns f = ns['__init__'].func_code.co_code n = ns['__init__'].func_code.co_names i = 0 while i < len(f) - 6: if (f[i] == LOAD_FAST and f[i+1] == f[i+2] == '\0' and f[i+3] == STORE_ATTR): j = ord(f[i+4]) + 256 * ord(f[i+5]) result.append(n[j]) i += 6 elif f[i] > HAVE_ARGUMENT: i += 3 else: i += 1 return result >>> import franz >>> franz.find(y.__class__) ['__module__', 'who1', '__init__', '__doc__', '_b'] Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From t-meyer at ihug.co.nz Mon Aug 29 20:38:20 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 30 Aug 2005 12:38:20 +1200 Subject: python-dev Summary for 2005-08-01 through 2005-08-15 Message-ID: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2005-08-01_2005-08-15.html] ============= Announcements ============= ---------------------------- QOTF: Quote of the Fortnight ---------------------------- Some wise words from Donovan Baarda in the PEP 347 discussions: It is true that some well designed/developed software becomes reliable very quickly. However, it still takes heavy use over time to prove that. Contributing thread: - `PEP: Migrating the Python CVS to Subversion `__ [SJB] ------------ Process PEPs ------------ The PEP editors have introduced a new PEP category: "Process", for PEPs that don't fit into the "Standards Track" and "Informational" categories. More detail can be found in `PEP 1`_, which is itself a Process PEP. .. _PEP 1: http://www.python.org/peps/pep-0001.html Contributing thread: - `new PEP type: Process `__ [TAM] ----------------------------------------------- Tentative Schedule for 2.4.2 and 2.5a1 Releases ----------------------------------------------- Python 2.4.2 is tentatively scheduled for a mid-to-late September release and a first alpha of Python 2.5 for March 2006 (with a final release around May/June). This means that a PEP for the 2.5 release, detailing what will be included, will likely be created soon; at present there are various accepted PEPs that have not yet been implemented. Contributing thread: - `plans for 2.4.2 and 2.5a1 `__ [TAM] ========= Summaries ========= ------------------------------- Moving Python CVS to Subversion ------------------------------- The `PEP 347`_ discussion from last fortnight continued this week, with a revision of the PEP, and a lot more discussion about possible version control software (RCS) for the Python repository, and where the repository should be hosted. Note that this is not a discussion about bug trackers, which will remain with Sourceforge (unless a separate PEP is developed for moving that). Many revision control systems were extensively discussed, including `Subversion`_ (SVN), `Perforce`_, `Mercurial`_, and `Monotone`_. Whichever system is moved to, it should be able to be hosted somewhere (if *.python.org, then it needs to be easily installable), needs to have software available to convert a repository from CVS, and ideally would be open-source; similarity to CVS is also an advantage in that it requires a smaller learning curve for existing developers. While Martin isn't willing to discuss every system there is, he will investigate those that make him curious, and will add other people's submissions to the PEP, where appropriate. The thread included a short discussion about the authentication mechanism that svn.python.org will use; svn+ssh seems to be a clear winner, and a test repository will be setup by Martin next fortnight. The possibility of moving to a distributed revision control system (particularly `Bazaar-NG`_) was also brought up. Many people liked the idea of using a distributed revision control system, but it seems unlikely that Bazaar-NG is mature enough to be used for the main Python repository at the current time (a move to it at a later time is possible, but outside the scope of the PEP). Distributed RCS are meant to reduce the barrier to participation (anyone can create their own branches, for example); Bazaar-NG is also implemented in Python, which is of some benefit. James Y Knight pointed out `svk`_, which lets developers create their own branches within SVN. In general, the python-dev crowd is in favour of moving to SVN. Initial concern about the demands on the volunteer admins should the repository be hosted at svn.python.org were addressed by Barry Warsaw, who believes that the load will be easily managed with the existing volunteers. Various alternative hosts were discussed, and if detailed reports about any of them are created, these can be added to the PEP. While the fate of all PEPS lie with the BDFL (Guido), it is likely that the preferences of those that frequently check in changes, the pydotorg admins, and the release managers (who have all given favourable reports so far), will have a significant effect on the pronouncement of this PEP. .. _PEP 347: http://www.python.org/peps/pep-0347.html .. _svk: http://svk.elixus.org/ .. _Perforce: http://www.perforce.com/ .. _Subversion: http://subversion.tigris.org/ .. _Monotone: http://venge.net/monotone/ .. _Bazaar-NG: http://www.bazaar-ng.org/ .. _Mercurial: http://www.selenic.com/mercurial/ Contributing threads: - `PEP: Migrating the Python CVS to Subversion `__ - `PEP 347: Migration to Subversion `__ - `Hosting svn.python.org `__ - `Fwd: Distributed RCS `__ - `cvs to bzr? `__ - `Distributed RCS `__ - `Fwd: PEP: Migrating the Python CVS to Subversion `__ - `On distributed vs centralised SCM for Python `__ [TAM] ------------------------------------------ PEP 348: Exception Hierarchy in Python 3.0 ------------------------------------------ This fortnight mostly concluded the previous discussion about `PEP 348`_, which sets out a roadmap for changes to the exception hierarchy in Python 3.0. The proposal was heavily scaled back to retain most of the current exception hierarchy unchanged. A new exception, BaseException, will be introduced above Exception in the current hierarchy, and KeyboardInterrupt and SystemExit will become siblings of Exception. The goal here is that:: except Exception: will now do the right thing for most cases, that is, it will catch all the exceptions that you can generally recover from. The PEP would also move NotImplementedError out from under RuntimeError, and alter the semantics of the bare except so that:: except: is the equivalent of:: except Exception: Only BaseException will appear in Python 2.5. The remaining modifications will not occur until Python 3.0. .. _PEP 348: http://www.python.org/peps/pep-0348.html Contributing threads: - `Pre-PEP: Exception Reorganization for Python 3.0 `__ - `PEP, take 2: Exception Reorganization for Python 3.0 `__ - `Exception Reorg PEP checked in `__ - `PEP 348: Exception Reorganization for Python 3.0 `__ - `Major revision of PEP 348 committed `__ - `Exception Reorg PEP revised yet again `__ - `PEP 348 and ControlFlow `__ - `PEP 348 (exception reorg) revised again `__ [SJB] ---------------------- Moving towards Unicode ---------------------- Neil Schemenauer presented `PEP 349`_, which tries to ease the transition to Python 3.0, in which there will be a bytes() type for byte data and a str() type for text data. Currently to convert an object to text, you have one of three options: * Call str(). This breaks with a UnicodeEncodeError if the object is of type unicode (or a subtype) or can only represent itself in unicode and therefore returns unicode from __str__. * Call unicode(). This can break external code that is not yet Unicode-safe and that passed a str object to your code but got a unicode object back. * Use the "%s" format specifier. This breaks with a UnicodeEncodeError if the object can only represent itself in unicode and therefore returns unicode from __str__. `PEP 349`_ attempts to address this problem by introducing a text() builtin which returns str or unicode instances unmodified, and returns the result of calling __str__() on the object otherwise. Guido preferred to instead relax the restrictions on str() to allow it to return unicode objects. Neil implemented such a patch, and found that it broke only two test cases. The discussion stopped shortly after Neil's report however, so it was unclear if any permanent changes had been agreed upon. Guido made a few other Python 3.0 suggestions in this thread: * The bytes() type should be mutable with a corresponding frozenbytes() immutable type * Opening a file in binary or text mode would cause it to return bytes() or str() objects, respectively * The file type should grow a getpos()/setpos() pair that are identical to tell()/seek() when a file is open in binary mode, and which work like tell()/seek() but on characters instead of bytes when a file is opened in text mode. However, none of these seemed to be solid commitments. .. _PEP 349: http://www.python.org/peps/pep-0349.html Contributing threads: - `PEP: Generalised String Coercion `__ - `Generalised String Coercion `__ [SJB] ---------------------------- PEP 344 and reference cycles ---------------------------- Armin Rigo brought up an issue with `PEP 344`_ which proposes, among other things, adding a __traceback__ attribute to exceptions to avoid the hassle of extracting it from sys.exc_info(). Armin pointed out that if exceptions grow a __traceback__ attribute, every statement:: except Exception, e: will create a cycle:: e.__traceback__.tb_frame.f_locals['e'] Despite the fact that Python has cyclic garbage collection, there are still some situations where cycles like this can cause problems. Armin showed an example of such a case:: class X: def __del__(self): try: typo except Exception, e: e_type, e_value, e_tb = sys.exc_info() Even in current Python, instances of the X class are uncollectible. When garbage collection runs and tries to collect an X object, it calls the __del__() method. This creates the cycle:: e_tb.tb_frame.f_locals['e_tb'] The X object itself is available through this cycle (in ``f_locals['self']``), so the X object's refcount does not drop to 0 when __del__() returns, so it cannot be collected. The next time garbage collection runs, it finds that the X object has not been collected, calls its __del__() method again and repeats the process. Tim Peters suggested this problem could be solved by declaring that __del__() methods are called exactly once. This allows the above X object to be collected because on the second run of the garbage collection, __del__() is not called again. Thus, the refcount of the X object is not incremented, and so it is collected by garbage collection. However, guaranteeing that __del__() is called only once means keeping track somehow of which objects' __del__() methods were called, which seemed somewhat unattractive. There was also brief talk about removing __del__ in favor of weakrefs, but those waters seemed about as murky as the garbage collection ones. .. _PEP 344: http://www.python.org/peps/pep-0344.html Contributing thread: - `__traceback__ and reference cycles `__ [SJB] ---------------------------- Style for raising exceptions ---------------------------- Guido explained that these days exceptions should always be raised as:: raise SomeException("some argument") instead of:: raise SomeException, "some argument" The second will go away in Python 3.0, and is only present now for backwards compatibility. (It was necessary when strings could be exceptions, in order to pass both the exception "type" and message.) PEPs 8_ and 3000_ were accordingly updated. .. _8: http://www.python.org/peps/pep-0008.html .. _3000: http://www.python.org/peps/pep-3000.html Contributing threads: - `PEP 8: exception style `__ - `FW: PEP 8: exception style `__ [SJB] ----------------------------------- Skipping list comprehensions in pdb ----------------------------------- When using pdb, the only way to skip to the end of a loop is to set a breakpoint on the line after the loop. Ilya Sandler suggested adding an optimal numeric argument to pdb's "next" comment to indicate how many lines of code should be skipped. Martin v. L?wis pointed out that this differs from gdb's "next " command, which does "next" n times. Ilya suggested implementing gdb's "until" command instead, which gained Martin's approval. It was also pointed out that pdb is one of the less Pythonic modules, particularly in terms of the ability to subclass/extend, and would be a good candidate for rewriting, if anyone had the inclination and time. Contributing threads: - `pdb: should next command be extended? `__ - `an alternative suggestion, Re: pdb: should next command be extended? `__ [TAM] ------------------ Sets in Python 2.5 ------------------ Raymond Hettinger has been checking-in the new implementation for sets in Python 2.5. The implementation is based heavily on dictobject.c, the code for Python dict() objects, and generally deviates only when there is an obvious gain in doing so. Raymond posted a proposed C API sets; no comments were forthcoming and it was implemented for Py2.5 without changes. Contributing threads: - `[Python-checkins] python/dist/src/Objects setobject.c, 1.45, 1.46 `__ - `Discussion draft: Proposed Py2.5 C API for set and frozenset objects `__ [SJB] ================================ Deferred Threads (for next time) ================================ - `SWIG and rlcompleter `__ =============== Skipped Threads =============== - `Extension of struct to handle non byte aligned values? `__ - `Syscall Proxying in Python `__ - `__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code) `__ - `Weekly Python Patch/Bug Summary `__ - `PEP 342 Implementation `__ - `String exceptions in Python source `__ - `[ python-Patches-790710 ] breakpoint command lists in pdb `__ - `[C++-sig] GCC version compatibility `__ - `PyTuple_Pack added references undocumented `__ - `PEP-- Context Managment variant `__ - `Sourceforge CVS down? `__ - `PSF grant / contacts `__ - `Python + Ping `__ - `Terminology for PEP 343 `__ - `dev listinfo page (was: Re: Python + Ping) `__ - `set.remove feature/bug `__ - `Extension to dl module to allow passing strings from native function `__ - `build problems on macosx (CVS HEAD) `__ - `request for code review - hashlib - patch #1121611 `__ - `python-dev Summary for 2005-07-16 through 2005-07-31 [draft] `__ - `string_join overrides TypeError exception thrown in generator `__ - `implementation of copy standard lib `__ - `xml.parsers.expat no userdata in callback functions `__ ======== Epilogue ======== This is a summary of traffic on the `python-dev mailing list`_ from August 01, 2005 through August 15, 2005. It is intended to inform the wider Python community of on-going developments on the list on a semi-monthly basis. An archive_ of previous summaries is available online. An `RSS feed`_ of the titles of the summaries is available. You can also watch comp.lang.python or comp.lang.python.announce for new summaries (or through their email gateways of python-list or python-announce, respectively, as found at http://mail.python.org). Tim Lesher has had to bow out from the summaries for now; many thanks to him for the contributions he made over the last few months. This is the 1st summary written by the python-dev summary confederacy of Steve Bethard and Tony Meyer (Thanks Tim!). To contact us, please send email: - Steve Bethard (steven.bethard at gmail.com) - Tony Meyer (tony.meyer at gmail.com) Do *not* post to comp.lang.python if you wish to reach us. The `Python Software Foundation`_ is the non-profit organization that holds the intellectual property for Python. It also tries to advance the development and use of Python. If you find the python-dev Summary helpful please consider making a donation. You can make a donation at http://python.org/psf/donations.html . Every penny helps so even a small donation with a credit card, check, or by PayPal helps. -------------------- Commenting on Topics -------------------- 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`_! ------------------------- How to Read the Summaries ------------------------- 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 for 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. Please note that this summary is written using reStructuredText_. Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo =); you can safely ignore it. We do suggest learning reST, though; it's simple and is accepted for `PEP markup`_ and can be turned into many different formats like HTML and LaTeX. Unfortunately, even though reST is standardized, the wonders of programs that like to reformat text do not allow us to 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`_. .. _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 .. _c.l.py: .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _PEP Markup: http://www.python.org/peps/pep-0012.html .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. _PSF: .. _Python Software Foundation: http://python.org/psf/ .. _last summary: http://www.python.org/dev/summary/2005-04-16_2005-04-30.html .. _original text file: http://www.python.org/dev/summary/2005-08-01_2005-08-15.ht .. _archive: http://www.python.org/dev/summary/ .. _RSS feed: http://www.python.org/dev/summary/channews.rdf From saint.infidel at gmail.com Fri Aug 12 10:24:13 2005 From: saint.infidel at gmail.com (infidel) Date: 12 Aug 2005 07:24:13 -0700 Subject: len(sys.argv) in (3,4) In-Reply-To: References: Message-ID: <1123856653.060322.276960@g43g2000cwa.googlegroups.com> It might make more sense if you could find out exactly what that one argument contains. From twic at urchin.earth.li Thu Aug 18 10:05:02 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Thu, 18 Aug 2005 15:05:02 +0100 Subject: As Simple As Possible? In-Reply-To: <7677804.UTi409LUyN@knode.kde> References: <1124338318.133726.304370@g49g2000cwa.googlegroups.com> <7677804.UTi409LUyN@knode.kde> Message-ID: On Thu, 18 Aug 2005, Jules Dubois wrote: > On Wednesday 17 August 2005 22:11, jitya > (<1124338318.133726.304370 at g49g2000cwa.googlegroups.com>) wrote: > >> After three years of study, I have concluded that Python is about as >> simple as a full-powered object-oriented language can get. >> >> I know of no language to which these words apply more than Python. > > Smalltalk is or would be my first choice if everything else were equal. > Python is what I actually use. The showstopping problem with smalltalk, IMHO, is the intertwining of the language and the environment. Smalltalk weenies hold this up as one of its greatest strengths, but to me, it just looks like there's twice as much to learn to begin with. A good command-line smalltalk plus a python-style simple interactive environment would be a winning combination. Otherwise, i agree that smalltalk is basically the perfect language. tom -- If you tolerate this, your children will be next. From s4somesh at gmail.com Thu Aug 4 10:04:17 2005 From: s4somesh at gmail.com (Somesh) Date: 4 Aug 2005 07:04:17 -0700 Subject: listing users in Plone Message-ID: <1123164257.211224.66710@g14g2000cwa.googlegroups.com> Hi, 1.I have installed and running a plone Intranet site, I have registerd users on it. I want to get list of all registerd users on a page. how I should move towards getting it / scripting it in my index_html page ? I am just a frontend user of plone. 2.How to start creating small database driven pages programming on plone ? need too newbie tute :), PS : I have good hand on Python - Somesh From devlai at gmail.com Thu Aug 11 18:27:32 2005 From: devlai at gmail.com (Devan L) Date: 11 Aug 2005 15:27:32 -0700 Subject: Regular expression to match a # References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> <42fbb9a9$1@news.eftel.com> Message-ID: <1123799252.257355.158320@f14g2000cwb.googlegroups.com> John Machin wrote: > Aahz wrote: > > In article <42fb45d7$1 at news.eftel.com>, > > John Machin wrote: > > > >>Search for r'^something' can never be better/faster than match for > >>r'something', and with a dopey implementation of search [which Python's > >>re is NOT] it could be much worse. So please don't tell newbies to > >>search for r'^something'. > > > > > > You're somehow getting mixed up in thinking that "^" is some kind of > > "not" operator -- it's the start of line anchor in this context. > > I can't imagine where you got that idea from. > > If I change "[which Python's re is NOT]" to "[Python's re's search() is > not dopey]", does that help you? > > The point was made in a context where the OP appeared to be reading a > line at a time and parsing it, and re.compile(r'something').match() > would do the job; re.compile(r'^something').search() will do the job too > -- BECAUSE ^ means start of line anchor -- but somewhat redundantly, and > very inefficiently in the failing case with dopey implementations of > search() (which apply match() at offsets 0, 1, 2, .....). I don't see much difference. Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE 1.1.1 >>> import timeit >>> t1 = timeit.Timer('re.search("^\w"," will not work")','import re') >>> t1.timeit() 34.938577109660628 >>> t2 = timeit.Timer('re.match("\w"," will not work")','import re') >>> t2.timeit() 31.381461330979164 >>> 3.0/1000000 3.0000000000000001e-006 >>> t1.timeit() 35.282282524734228 >>> t2.timeit() 31.403153752781463 ~4 second difference after a million times through seems to be trivial. Then again, I haven't tested it for larger patterns and strings. From edvard+news at majakari.net Tue Aug 30 07:48:24 2005 From: edvard+news at majakari.net (Edvard Majakari) Date: Tue, 30 Aug 2005 14:48:24 +0300 Subject: time.mktime problem References: <1125397106.854442.227120@g44g2000cwa.googlegroups.com> Message-ID: <87ek8bmyrb.fsf@majakari.net> "McBooCzech" writes: > Hi, on Linux (Fedora FC4) and Python 2.4.1 > I am trying to know the time delta in seconds between two times given > in the HHMMSS format. My code looks like: > > import datetime, time > ta1=(time.strptime('000001', '%H%M%S')) > ta2=(time.strptime('230344', '%H%M%S')) > t1=time.mktime(ta1) > t2=time.mktime(ta2) > print t1, t2 > > -2147483648.0 -2147483648.0 > > I just can not figure out, why the t1 and t2 are the same? Hm. You are trying to convert (1900, 1, 1, 0, 0, 1, 0, 1, -1) to epoch. However, epochs start from 1970-01-01 00:00. So that at least is not right. Hint... see what var ta1 is. With python2.3 you'll get overflow error, becuase mktime argument is out of range. -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli Deo Gloria! $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n"; From greg at puyo.cjb.net Mon Aug 22 06:20:12 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 22 Aug 2005 03:20:12 -0700 Subject: while c = f.read(1) In-Reply-To: <7x64tyxpxz.fsf@ruckus.brouhaha.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> <1124703805.178363.145870@g49g2000cwa.googlegroups.com> <7x64tyxpxz.fsf@ruckus.brouhaha.com> Message-ID: <1124706012.820046.297950@f14g2000cwb.googlegroups.com> That is both clever and useful! I never would have thought of doing that. This seems to me like a general way to "workaround" the Python statement/expression separation woes I've been having, in cases where I really really want it. Now, where can I copy this out to so I will be able to find it when the occasion arises? Hmm... *jot jot jot* Thanks muchly! :-) From jwashin at vt.edu Sat Aug 13 19:21:30 2005 From: jwashin at vt.edu (Jim Washington) Date: Sat, 13 Aug 2005 23:21:30 GMT Subject: Permutation Generator References: Message-ID: On Fri, 12 Aug 2005 12:39:08 -0700, Talin wrote: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head = lst[:1] > for x in permute( lst[1:] ): > yield head + x > yield x + head > return > > -- Talin If we are sharing permutation algorithms today, here's one. The following likes to be in a file called "permutation.py" for __main__ to work. A couple of lines went over 80 characters, so you might have to put those back together. -Jim Washington """ ***Reversible*** Permutations using factoradics. factoradic concept at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/permutations.asp Why permutations? Sometimes, you need to list your objects in a different order. Maybe, when you are dealing with something persistent like Zope, you wish your users to access things in a different order than other users. Think quizzes or photo galleries. You think you want randomness, but what you really want is that different users get different orderings of things, so that the first item is likely different for each individual. But you do not really want randomness; you want a particular user always to get the same ordering. One way would be to store for each individual the complete list in order, This is another way that allows you to just store an index that refers to a particular ordering. For a list of n items, there are n factorial (n!) possible permutations. So, any number from 0 to n!-1 is a valid index to a unique ordering. If you have foo = Permutation(['a','Fred',23,None]) the possible indices are numbered 0 to 23 (0 to 4!-1) sam = foo.permutation(10) mary = foo.permutation(4) sam is ['Fred', None, 'a', 23] mary is ['a', None,'Fred', 23] An interesting thing about the factoradic method is its reversibility. If you have a list: ['a','Fred',23,None] and you are presented with an ordering: [23,'a',None,'Fred'] the factoradic method can algorithmically determine that this ordering is index 13 of 24 of the possible permutations, without going forward through your generating algorithm to get there. foo = Permutation(['a','Fred',23,None]) ix = foo.getPermutationIndex([23,'a',None,'Fred']) ix is 13. For the above example, I used a list of mixed items; you probably will not. Reversibility does not work if items are repeated, since it cannot know the original positions of repeated items. If you have duplicated items, use their list index instead of the items themselves. """ try: import psyco psyco.full() except: pass import random def factoradic(anInt,order=0): """calculate the factoradic on anInt >>> factoradic(859) [1, 1, 0, 3, 0, 1, 0] >>> factoradic(11233111122213455539988899978655326328) [1, 9, 22, 2, 20, 20, 7, 14, 0, 19, 2, 13, 2, 5, 14, 18, 2, 0, 10, 1, 9, 3, 11, 9, 9, 4, 1, 4, 0, 0, 1, 1, 0, 0] >>> factoradic(0,4) [0, 0, 0, 0] >>> factoradic(1) [1, 0] >>> factoradic(1047) [1, 2, 3, 2, 1, 1, 0] >>> factoradic(5,4) [0, 2, 1, 0] """ factoradic = [] z = 0 while anInt > 0: z += 1 factoradic.append(int(anInt % z)) anInt /= z factoradic.reverse() if order: while len(factoradic) < order: factoradic.insert(0,0) return factoradic def factorial(anInt): """factorial >>> factorial(3) 6 >>> factorial(0) 1 >>> factorial(1) 1 """ if anInt == 0: return 1 if anInt < 0: raise ValueError, "Cannot factorialize negative numbers" result = 1 while anInt > 1: result = result * anInt anInt -= 1 return result def unfactoradic(aList): """from a factoradic list, calculate the integer >>> unfactoradic([1, 1, 0, 3, 0, 1, 0]) 859 """ aList.reverse() result = 0 for idx,val in enumerate(aList): result += factorial(idx) * val return result class Permutation(object): """Base object for doing permutations. Generally initialized with a list of the items to do permutations on. Works by the factoradic method, which provides reversibility.""" _order = None def __init__(self,data): self.data = data def getOrder(self): if not self._order: self._order = len(self.data) return self._order def permutationIndices(self,anInt): """calculate the permutation indices of self from anInt >>> z = Permutation([1,2,3,4,5,6,7]) >>> z.permutationIndices(1047) [1, 3, 5, 4, 2, 6, 0] >>> z = Permutation([0,1,2,3]) >>> z.permutationIndices(5) [0, 3, 2, 1] """ f = factoradic(anInt,self.order) temp = [] for k in f: temp.append(k + 1) data = [1] temp.reverse() for k in temp[1:]: data.insert(0,k) for idx,val in enumerate(data[1:]): if val >= k: data[idx+1] = val + 1 for idx,val in enumerate(data): data[idx] = val-1 return data def permutation(self,anInt): """return a list of permutated items >>> z = Permutation([1,2,3,4,5,6,7]) >>> z.permutation(1047) [2, 4, 6, 5, 3, 7, 1] """ indices = self.permutationIndices(anInt) newlist = [] for k in indices: newlist.append(self.data[k]) return newlist def randomPermutation(self): """just get one of them, randomly""" r = random.randint(0,factorial(self.order)) return self.permutation(r) def getPermutationIndex(self,aPermutation): """presuming a unique list, get the permutation index of the given permutation list. >>> d = [1,2,3,4,5,6,7] >>> z = Permutation(d) >>> z.getPermutationIndex([2, 4, 6, 5, 3, 7, 1]) 1047 """ indexkey = [] for k in aPermutation: indexkey.append(self.data.index(k)) data = [] for k in indexkey: data.append(k+1) factoradic = [] while len(data) > 0: r = data.pop(0) factoradic.append(r-1) for idx,val in enumerate(data): if val >= r: data[idx] = val -1 return unfactoradic(factoradic) order = property(getOrder) def listAll(anInt): theList = [] for k in range(anInt): theList.append(k) z = Permutation(theList) for k in range(factorial(len(z.data))): b = factoradic(k,len(z.data)) c = z.permutation(k) d = z.getPermutationIndex(c) print "%s\t%s\t%s\t%s" % (k,b,c,d) def _test(): import doctest,permutation return doctest.testmod(permutation) if __name__ == '__main__': _test() listAll(4) From t-meyer at ihug.co.nz Sat Aug 20 03:19:06 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Sat, 20 Aug 2005 19:19:06 +1200 Subject: python-dev Summary for 2005-07-16 through 2005-07-31 Message-ID: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2005-07-16_2005-07-31.html] ============= Announcements ============= ------------------------------------------------- PyPy Sprint in Heidelberg 22nd - 29th August 2005 ------------------------------------------------- Heidelberg University in Germany will host a PyPy_ sprint from 22nd August to 29th August. The sprint will push towards the 0.7 release of PyPy_ which hopes to reach Python 2.4.1 compliancy and to have full, direct, translation into a low level language instead of reinterpretation through CPython. If you'd like to help out, this is a great place to start! For more information, see PyPy's `Heidelberg sprint`_ page. .. _PyPy: http://codespeak.net/pypy .. _Heidelberg sprint: http://codespeak.net/pypy/index.cgi?extradoc/sprintinfo/Heidelberg-sprint.ht ml Contributing thread: - `Next PyPy sprint: Heidelberg (Germany), 22nd-29th of August `__ -------------------------------- zlib 1.2.3 in Python 2.4 and 2.5 -------------------------------- Trent Mick supplied a patch for updating Python from zlib 1.2.1 to zlib 1.2.3, which eliminates some potential security vulnerabilities. Python will move to this new version of zlib in both the maintenance 2.4 branch and the main (2.5) branch. Contributing thread: - `zlib 1.2.3 is just out `__ ========= Summaries ========= ------------------------------- Moving Python CVS to Subversion ------------------------------- Martin v. L?wis submitted `PEP 347`_, which outlines moving from CVS to SVN for source code revision control of the Python repository, and moving from SourceForge to python.org for repository hosting. Moving to SVN from CVS met with general favour, although most were undecided about moving from sourceforge.net to python.org. The additional administration requirements of the move were the primary concern, and moving to an alternative host was suggested. Martin is open to including suggestions for alternative hosts in the PEP, but is not interested in carrying out such research himself; as such, if alternative hosts are to be included, someone needs to volunteer to collect all the required information and submit it to Martin. Discussion about the conversion and the move is continuing in August. .. _PEP 347: http://www.python.org/peps/pep-0347.html Contributing thread: - `PEP: Migrating the Python CVS to Subversion `__ --------------------------------- Exception Hierarchy in Python 3.0 --------------------------------- Brett Cannon posted the first draft of `PEP 348`_, covering reorganisation of exceptions in Python 3.0. The initial draft included major changes to the hierarchy, requiring any object raised to inherit from a certain superclass, and changing bare 'except' clauses to catch a specific superclass. The latter two proposals didn't generate much comment (although Guido vacillated between removing bare 'except' clauses and not), but the proposed hierarchy organisation and renaming was hotly discussed. Nick Coghlan countered each revision of Brett's maximum-changes PEP with a minimum-changes PEP, each evolving through python-dev discussion, and gradually moving to an acceptable middle ground. At present, it seems that the changes will be much more minor than the original proposal. The thread branched off into comments about `Python 3.0`_ changes in general. The consensus was generally that although backwards compatibility isn't required in Python 3.0, it should only be broken when there is a clear reason for it, and that, as much as possible, Python 3.0 should be Python 2.9 without a lot of backwards compatibility code. A number of people indicated that they were reasonably content with the existing exception hierarchy, and didn't feel that major changes were required. Guido suggested that a good principle for determining the ideal exception hierarchy is whether there's a use case for catching the common base class. Marc-Andre Lemburg pointed out that when migrating code changes in Exception names are reasonably easy to automate, but changes in the inheritance tree are much more difficult. Many exceptions were discussed at length (e.g. WindowsError, RuntimeError), with debate about whether they should continue to exist in Python 3.0, be renamed, or be removed. The PEP contains the current status for each of these exceptions. The PEP evolution and discussion are still continuing in August, and since this is for Python 3.0, are likely to be considered open for some time yet. .. _Python 3.0: http://www.python.org/peps/pep-3000.html .. _PEP 348: http://www.python.org/peps/pep-0348.html Contributing thread: - `Pre-PEP: Exception Reorganization for Python 3.0 `__ ----------------------------------------- Docstrings and the Official Documentation ----------------------------------------- A new `bug report`_ pointed out that the docstring help for cgi.escape was not as detailed as that in the full documentation, prompting Skip Montanaro to ask whether this should be the case or not. Several reasons were outlined why docstrings should be more of a "quick reference card" than a "textbook" (i.e. maintain the status quo). Tim Peters suggested that tools to extract text from the full documentation would be a more sensible method of making the "textbook" available from help()/pydoc; if anyone is interested, then this would probably be the best way to start implementing this. .. _bug report: http://python.org/sf/1243553 Contributing thread: - `should doc string content == documentation content? `__ --------------------------- Syntax suggestion: "while:" --------------------------- Martin Blais suggested "while:" as a syntactic shortcut for "while True:". The suggestion was shot down pretty quickly; not only is "while:" less explicit than "while True:", but it introduces readability problems for the apparently large number of people who, when reading "while:", immediately think "while what?" Contributing thread: - `while: `__ ------------------ Sets in Python 2.5 ------------------ In Python 2.4, there is no C API for the built-in set type; you must use PyObject_Call(), etc. as you would in accessing other Python objects. However, in Python 2.5, Raymond Hettinger plans to introduce a C API along with a new implementation of the set type that uses its own data structure instead of forwarding everything to dicts. Contributing thread: - `C api for built-in type set? `__ =============== Skipped Threads =============== - `Some RFE for review `__ - `python/dist/src/Doc/lib emailutil.tex,1.11,1.12 `__ - `read only files `__ - `builtin filter function `__ - `Weekly Python Patch/Bug Summary `__ - `Information request; Keywords: compiler compiler, EBNF, python, ISO 14977 `__ - `installation of python on a Zaurus `__ - `python-dev summary for 2005-07-01 to 2005-07-15 [draft] `__ - `math.fabs redundant? `__ ================================================= Skipped Threads (covered in the previous summary) ================================================= - `'With' context documentation draft (was Re: Terminology for PEP 343 `__ - `Adding the 'path' module (was Re: Some RFE for review) `__ - `[C++-sig] GCC version compatibility `__ ======== Epilogue ======== This is a summary of traffic on the `python-dev mailing list`_ from July 16, 2005 through July 31, 2005. It is intended to inform the wider Python community of on-going developments on the list on a semi-monthly basis. An archive_ of previous summaries is available online. An `RSS feed`_ of the titles of the summaries is available. You can also watch comp.lang.python or comp.lang.python.announce for new summaries (or through their email gateways of python-list or python-announce, respectively, as found at http://mail.python.org). This is the 8th summary written by the python-dev summary cabal of Steve Bethard, Tim Lesher, and Tony Meyer. To contact us, please send email: - Steve Bethard (steven.bethard at gmail.com) - Tim Lesher (tlesher at gmail.com) - Tony Meyer (tony.meyer at gmail.com) Do *not* post to comp.lang.python if you wish to reach us. The `Python Software Foundation`_ is the non-profit organization that holds the intellectual property for Python. It also tries to advance the development and use of Python. If you find the python-dev Summary helpful please consider making a donation. You can make a donation at http://python.org/psf/donations.html . Every penny helps so even a small donation with a credit card, check, or by PayPal helps. -------------------- Commenting on Topics -------------------- 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`_! ------------------------- How to Read the Summaries ------------------------- 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 for 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. Please note that this summary is written using reStructuredText_. Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo =); you can safely ignore it. We do suggest learning reST, though; it's simple and is accepted for `PEP markup`_ and can be turned into many different formats like HTML and LaTeX. Unfortunately, even though reST is standardized, the wonders of programs that like to reformat text do not allow us to 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`_. .. _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 .. _c.l.py: .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _PEP Markup: http://www.python.org/peps/pep-0012.html .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. _PSF: .. _Python Software Foundation: http://python.org/psf/ .. _last summary: http://www.python.org/dev/summary/2005-04-16_2005-04-30.html .. _original text file: http://www.python.org/dev/summary/2005-07-16_2005-07-31.ht .. _archive: http://www.python.org/dev/summary/ .. _RSS feed: http://www.python.org/dev/summary/channews.rdf From python-url at phaseit.net Thu Aug 18 10:08:02 2005 From: python-url at phaseit.net (Cameron Laird) Date: Thu, 18 Aug 2005 14:08:02 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 18) Message-ID: QOTW: "It seems to me that Java is designed to make it difficult for programmers to write bad code, while Python is designed to make it easy to write good code." -- Magnus Lycka "Code attracts people that like to code. Tedious, repetitive c.l.py threads attract people that like to write tedious, repetitive c.l.py threads." -- Robert Kern Yes, commercial Python training *is* available: http://groups.google.com/group/comp.lang.python.announce/msg/f1bd9b8deac1cb39 You know how essential the Cookbook is. Filling a slightly different role is the Grimoire: http://the.taoofmac.com/space/Python/Grimoire The latest SPE "features a remote, encrypted and embedded ... debugger ...": http://pythonide.stani.be Paul Dale convincingly advertises O'Reilly's Safari service: http://groups.google.com/group/comp.lang.python/browse_thread/thread/115a242dc77b0057/ Python is a superb vehicle for several niches generally thought exclusive to other languages, such as automation of Windows processes. Another too-little-known such strength is Python's adeptness with native Mac OS X applications: http://developer.apple.com/cocoa/pyobjc.html mensanator introduces enough of bit arithmetic to explain popcount and Hamming distance: http://groups.google.com/group/comp.lang.python/browse_thread/thread/e0716ffcf80af3a2/ PEP editors David Goodger and Barry Warsaw refine PEP organization: http://mail.python.org/pipermail/python-list/2005-August/294467.html ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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. del.icio.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/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 paolo_veronelli at tiscali.it Mon Aug 1 19:01:49 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 02 Aug 2005 01:01:49 +0200 Subject: namespaces In-Reply-To: <1122905702.119539.192060@g44g2000cwa.googlegroups.com> References: <42EC9690.2040301@tiscali.it> <1122905702.119539.192060@g44g2000cwa.googlegroups.com> Message-ID: <42EEA9DD.7050909@tiscali.it> George Sakkis wrote: > Paolino wrote: > > >>>>Even worse I get with methods and function namespaces. >>> >>>What is "even worse" about them? >>> >> >>For my thinking, worse is to understand how they derive their pattern >>from generic namespaces. >>Methods seems not to have a writeble one,while functions as George and >>Rob remembered have one which is not read only.Why? > > > I'm not sure I can parse this successfully, let alone understand it. > Functions' namespaces are writeble ,methods' not. >>> class C: ... def m(self):pass ... @classmethod ... def cm(cls):pass ... @staticmethod ... def sm():pass ... >>> C.sm.set=None >>> C.cm.set=None Traceback (most recent call last): File "", line 1, in ? AttributeError: 'instancemethod' object has no attribute 'set' ##### instancemethod? C.cm is a classmethod >>> C.m.set=None Traceback (most recent call last): File "", line 1, in ? AttributeError: 'instancemethod' object has no attribute 'set' ##### >>> Are these choices explained somewhere? Isn't 'do more use of namespaces' a python zen-law? Regards Paolino ___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com From cliff at develix.com Mon Aug 1 06:32:52 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 03:32:52 -0700 Subject: Wheel-reinvention with Python In-Reply-To: References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> Message-ID: <1122892372.19618.269.camel@localhost.localdomain> On Mon, 2005-08-01 at 08:53 +0100, phil hunt wrote: > I was under the impression -- from reading this ng -- that wx was > buggy on some platforms and less portable than Tkinter. Not true? It depends on how you define "buggy" and "portable"... also "platform" is up for grabs too ;) On the serious side, I expect that if you are simply counting bugs, there are probably more in wxPython. But I'd also say that when it comes to ratio of bugs to features, they are probably quite comparable, even if Tk has one bug and wxPython a hundred ;) As far as more portable, Tk probably wins hands-down. OTOH, in practice, very few people care about the platforms wxPython doesn't run on (think: GTK doesn't run there either). wxWidgets is working on a wxUniversal port which takes a similar tack that Tk does in most cases, that is, providing all of its own widgets based on drawing primitives, but I have no idea how far along that is nor how long until wxPython supports it as another target. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From peter at engcorp.com Wed Aug 3 09:51:49 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 03 Aug 2005 09:51:49 -0400 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: phil hunt wrote: > On Tue, 02 Aug 2005 21:26:28 +0200, Christoph Zwerschke wrote: >>According to the "extreme programming" paradigm, testing should be done >>several times a day. So a requirement for extreme programm is that tests >>are fast enough. If the testing needs too much time, people are >>discouraged to test often. > > Indeed. Running the tests should ideally take less than a few > seconds. Any longer, and people won't use them so often. That's probably too general a statement to be very useful, and I don't think it's probably helpful to a newcomer who is seeking guidance. If one makes the XP-style distinction between "unit" and "acceptance" tests, then the acceptance test *suite* should take no more than some number of minutes. I believe ten minutes absolute max is a commonly offered rule of thumb, but I've found even eight minutes a little too long. Five seems to be just fine, and less if of course wonderful. For unit tests, the entire suite should take only a minute or two, max, if possible, and preferably well under a minute. If you're doing test-driven development (TDD), you will want to be able to run unit tests (though maybe not all of them) sometimes a couple of times per minute! If the overhead is fifteen seconds, you can't type much new code in between running the tests. Still, in a large project (and especially one written in Python, with the overhead of interpreter startup and the cost of executing bytecode) the suite can get fairly long if you have many hundreds of tests. In that case, there's nothing that says you can't run individual test files, or even individual test cases, when you are focused on one small area of the code. That should let you run tests in only a couple of seconds, as phil just recommended, in almost any case. Having your code organized nicely into packages can help as well. If you have a helpful "test runner" utility which scans subdirectories for test cases, you can easily run all the tests in a given package independently of the rest of the app while you are working on that one package, reducing the risk inherent in running only a subset of your full test suite. -Peter From wouter at voti.nl Fri Aug 26 10:41:58 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Fri, 26 Aug 2005 14:41:58 GMT Subject: file access dialog References: <430ec9b1.1708219820@news.xs4all.nl> Message-ID: <430f2a1a.1732900669@news.xs4all.nl> >Tkinter has a file acces dialog available with the same API on all platforms. It is also mapped to the standard dialog on Windows. > Since Tkinter is certainly installed by default with Python, if a file dialog is everything you need, you probably don't have to look further. Great :) Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From tchur at optushome.com.au Mon Aug 29 16:31:20 2005 From: tchur at optushome.com.au (Tim Churches) Date: Tue, 30 Aug 2005 06:31:20 +1000 Subject: Robust statistics and optimmization from Python In-Reply-To: <1125333831.414123.314500@f14g2000cwb.googlegroups.com> References: <1125328346.738915.102990@z14g2000cwz.googlegroups.com> <1125333831.414123.314500@f14g2000cwb.googlegroups.com> Message-ID: <43137098.3000304@optushome.com.au> beliavsky at aol.com wrote: > Robert Kern wrote: > > > >>If you find suitable >>FORTRAN or C code that implements a particular "robust" algorithm, it >>can probably wrapped for scipy relatively easily. > > > An alternative would be to call R (a free statistical package) from > Python, using something like the R/SPlus - Python Interface at > http://www.omegahat.org/RSPython/ . Unless you really want to call Python from R (as opposed to calling R from Python), I strongly suggest that you use RPy (http://rpy.sf.net) rather than RSPython. RPy is much easier to install and use and far less buggy than RSPython. > Many statistical algorithms, > including those for robust statistics, have been implemented in R, > usually by wrapping C or Fortran 77 code. Yup, and if you really don't like the extra dependency or extra memory requirements of R and RPy, it is often possible to port the R code back to Python (or Numeric Python), with some effort. Tim C From twic at urchin.earth.li Tue Aug 16 20:00:48 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 17 Aug 2005 01:00:48 +0100 Subject: List copying idiom was Re: [Python-Dev] implementation of copy standard lib In-Reply-To: References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: On Tue, 16 Aug 2005, Ron Adam wrote: > Simon Brunning wrote: > >> On 8/14/05, Martijn Brouwer wrote: >> >>> I can imagine that *a lot* of libs/scripts use the copy library, >> >> I think that copy is very rarely used. I don't think I've ever imported it. > > I use copy.deepcopy() sometimes, and more often [:] with lists. > Dictionary objects have a copy method. All non mutable objects are > copies. When you say [:], do you mean that you copy lists like this: l = someList() m = [] m[:] = l ? That's what i've been doing. The other day, i realised that i could just do: l = someList() m = list(l) The same works for copying dicts. Whilst it's still not utterly obvious that what this is about is making a copy, it's more obvious, cleaner, shorter and probably faster than the slice assignment, which is really kludgy (almost intercalorific, in fact - or even perlish!). > I too have wondered why copy isn't a builtin, Same here. It seems like a sort of obvious thing to have, and could probably implemented much more simply and quickly in the interpreter. You'd probably want a __copy__ hook for classes which want special handling, and just do a normal deep copy for everything else. tom -- Orange paint menace From mage at mage.hu Wed Aug 3 11:45:34 2005 From: mage at mage.hu (Mage) Date: Wed, 03 Aug 2005 17:45:34 +0200 Subject: pain Message-ID: <42F0E69E.6020701@mage.hu> Hello, I started to learn python some months ago. Mostly for fun, but I replaced php to python in many tools at my company in the last weeks. Because of our boss decision now I have to learn java. I can tell java is one of the worst things including WW2. Even after seeing the light I may vomit when I write java code. Look at this tutorial from java.com: public class BasicsDemo { public static void main(String[] args) { int sum = 0; for (int current = 1; current <= 10; current++) { sum += current; } System.out.println("Sum = " + sum); } } It is "print sum(range(11))" in python. I just had to tell this, sorry for the bandwith. I suggest you to feel lucky if you may use python at your work. Mage From john at castleamber.com Fri Aug 26 08:47:47 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 12:47:47 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> <3n8ddiFbhg7U1@individual.net> Message-ID: Ulrich Hobelmann wrote: > John Bokma wrote: >> usenet at isbd.co.uk wrote: >> >>> In comp.lang.perl.misc John Bokma wrote: >> >> [ web based boards ] >> >>>> And which useful tools do you require? >>>> >>> A choice of news readers to suit different people with different >>> interfaces, >> >> - different browsers, different stylesheets, different board styles >> (themes). > > But the UI is still *forced* on you by the website; no choice. > There's only a very limited choice, and it invariably *includes* the > UI. With NNTP *you* choose how to interpret and display the data you > get. With a web based forum too. Example: http://johnbokma.com/perl/phpbb-remote-backup.html >> http://www.phpbb.com/mods/ > > Great. How can I, the user, choose, how to use a mod on a given web > server? Ask the admin? > What if the web server runs another board than PHPBB? Check if there is a mod, and ask the admin. >> Does the user want this? And with a user stylesheet you can change it >> quite radically :-) > > The look, not the feel. Wild guess: (signed) javascript and iframes? on your local computer? Otherwise: fetch HTML, parse it, restructure it, and have the application run a local webserver. Python, Perl, piece of cake. >> And in return the user gets: colors, fonts, font sizes, embedding of >> images, flash, you name it. Moving avatars, even sounds. > > As I wrote earlier, you *could* run a web forum over NNTP, and use > HTML posts instead of plain text. It would have the advantages of > NNTP. > >> Oh, yes, I would love to see an XML interface on the board I use. >> Maybe I can just install a mod, or write one myself. > > What would that XML be for? Any particular *use*? RSS feeds? XML-RPC? Access to the board with a better mark up then HTML supports? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From leszczynscyATnospam.yahoo.com.nospam Wed Aug 10 17:18:32 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Wed, 10 Aug 2005 16:18:32 -0500 Subject: Python supports LSP, does it? In-Reply-To: <86wtmuk0c5.fsf@bhuda.mired.org> References: <86wtmuk0c5.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: [...] > The wikipedia was really abusing the phrase LSP. I've corrected the > wikipedia. > Message-ID: "jog" wrote: > I want to get text out of some nodes of a huge xml file (1,5 GB). The > architecture of the xml file is something like this > I want to combine the text out of page:title and page:revision:text for > every single page element. One by one I want to index these combined > texts (so for each page one index) here's one way to do it: try: import cElementTree as ET except ImportError: from elementtree import ElementTree as ET for event, elem in ET.iterparse(file): if elem.tag == "page": title = elem.findtext("title") revision = elem.findtext("revision/text") print title, revision elem.clear() # won't need this any more references: http://effbot.org/zone/element-index.htm http://effbot.org/zone/celementtree.htm (for best performance) http://effbot.org/zone/element-iterparse.htm From darkpaladin79 at hotmail.com Thu Aug 11 15:51:51 2005 From: darkpaladin79 at hotmail.com (Ivan Shevanski) Date: Thu, 11 Aug 2005 15:51:51 -0400 Subject: hotmail filter question with list Message-ID: Just a quick mailing question for anyone who uses hotmail and gets this. Im having problems with my filters =/ i have a filter for mails with python-list at python.org in to or cc, but i still get some in my inbox. anyone? -Ivan _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From axel at white-eagle.invalid.uk Fri Aug 12 16:47:04 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Fri, 12 Aug 2005 20:47:04 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: In comp.lang.perl.misc Xah Lee wrote: > The other class of jargon stupidity is from computing practitioners, of > which the Unix/Perl community is exemplary. For example, the name Unix > & Perl themselves are good examples of buzzing jargons. Unix is > supposed to be opposed of Multics and hints on the offensive and > tasteless term eunuchs. Now that connexion is a product of a truely warped mind. Axel From billiejoex at fastwebnet.it Fri Aug 26 14:02:23 2005 From: billiejoex at fastwebnet.it (billiejoex) Date: Fri, 26 Aug 2005 20:02:23 +0200 Subject: Does any1 use pcapy module on win32 platforms? References: Message-ID: The problem was my winpcap version. I was using the 3.1. Now, with the 3.0 it works. Really thanks. :-) > For what it's worth, I can run that on my XP Professional SP2 machine and > it works perfectly: > >>>> pcapy.findalldevs() > [u'\\Device\\NPF_{15310604-FCFC-4016-9D36-14DAA948A600}', > u'\\Device\\NPF_{62280C1D-DC5C-42AF-BA0F-6BDB48418CA5}'] > > I'm using WinPcap 3.0. My packet.dll is stamped as version 3.0.0.18. > Maybe you're running a different version? > > -- > Richie Hindle > richie at entrian.com From __peter__ at web.de Tue Aug 16 09:40:53 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2005 15:40:53 +0200 Subject: looping list problem References: Message-ID: Jon Bowlas wrote: > Ok so I changed it to this: > > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > hiddennavelements = navstring.split(' ') > for hiddennavelement in hiddennavelements: > yield?hiddennavelements > > But I get the following error- Line 5: Yield statements are not allowed. Please show us some more code -- especially the function containing and the function calling the above chunk. Generally speaking, a function terminates when execution reaches the first return statement, e. g. def f(): for i in 1, 2, 3: return i will always return 1. A generator, on the other hand, def g(): for i in 1, 2, 3: yield i will yield 1, 2, and 3, but the calling code then needs itself a for loop: for i in g(): # do something with i My guess would be that you should either modify your for loop to > attobject = context.get_attobject() > navstring = context.get_uclattribute(attobject, 'ucl_navhide') > hiddennavelements = navstring.split(' ') for hiddennavelement in hiddennavelements: # do something with hiddennavelement or just return all elements at once def some_func(): # ... attobject = context.get_attobject() navstring = context.get_uclattribute(attobject, 'ucl_navhide') return navstring.split(' ') and then operate on the items in the hiddennavelements list in the calling code: for element in some_func(): # do something with element Peter From desparn at wtf.com Tue Aug 23 09:50:35 2005 From: desparn at wtf.com (Rick Wotnaz) Date: Tue, 23 Aug 2005 09:50:35 -0400 Subject: Reg python nature. References: Message-ID: praba kar wrote in news:mailman.3406.1124784769.10512.python-list at python.org: > Dear All, > I want to know the link between c and python. > Some people with C background use Python instead > of programming in C.why? > I will now reveal the secret that explains why some people who know how to program in C use Python instead: because they want to. The primary Python implementation is written in C, and makes use of C library functions. C applications are also written in C and make use of C library functions. So *there* is a link. Here are some possible reasons for using Python instead of C: * Some C programmers do not enjoy all aspects of C (such as managing dynamic allocation and deallocation of data structures), and prefer the higher-level abstraction of Python for routine tasks. * Sometimes extremely high performance is not an issue (probably most times), so the language choice becomes one of deciding which is more convenient. Generally, that would be Python. * Systems that must last for long periods of time will often require maintenance, and the clarity of Python code makes it easier to maintain than C equivalents in many cases. The actual code size is often smaller, and making changes requires fewer additional lines of code. This all adds up to a substantial maintenance advantage. * Many programmers use more languages than just one. Python is a good general-purpose language that is quite reasonable to choose as an alternative (or addition) to C. For those coming from a C background, learning the basics of Python syntax is quite easy. Those who have habitually used pseudocode to describe their program concepts may find it even easier to pick up Python. I hope at least one of these points addresses your question. I don't know that your subject line, referring to the nature of Python, is actually very close to the question itself, though. Programmers with a background in any other language will need to reach an understanding of Python's true nature before they can use it comfortably. The same is true when learning any other language; the language's true nature reveals itself with enough use. -- rzed From apardon at forel.vub.ac.be Thu Aug 25 10:32:05 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 25 Aug 2005 14:32:05 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-25, Steve Holden schreef : > Antoon Pardon wrote: >> Op 2005-08-24, Magnus Lycka schreef : >> >>>Antoon Pardon wrote: >>> >>>>I think he did, because both expression are not equivallent >>>>unless some implicite constraints make them so. Values where >>>>both expressions differ are: >>>> >>>> start1=67, stop1=9, start2=10, stop2=29 > > This is just too fatuous to ignore, sorry. You mean you can't think of circumstances where this could be valid data. >>>Ouch! That didn't occur to me. How sloppy to just assume that >>>time periods can't end before they start. >> >> >> I have no trouble that you assume a time period starts before >> it ends. >> >> But two pieces of code that only give the same result under >> particular assumptions are not equivallent. For all I know >> his code might work without this assumption and thus be >> usefull in circumstances where yours is not. >> >> Maybe someone uses a convention where time intervals that >> stop before they start can have some meaning. >> >> Equivallent code IMO always gives the same results, not >> only under the particular constraints you are working with. >> >> >>>I'll shut up now. You win, >>>I'm obviously the idiot here, and Python's must be >>>redesigned from ground up. Pyrdon maybe? >> >> >> If I ever design a language it'll be called: 'Queny' >> > ...and you will regard it as perfect I doubt that. I've looked at the problem of designing a language and IMO it is a very complex matter, that is difficult to do good, let alone perfect. At this moment I think very highly about the designers of Python, because I think they have done a very good job and Python is for the moment my language of choice. Sure Python has its warts, but I can live with them. I just don't like it if I get the impression that people want to deny the warts. > and be completely unable to > understand why nobody likes it. > > Could we possibly reduce the number of arguments about ridiculous > postulates such as , and try to remember that most people on this list > are dealing with real life? So? Real life is full of thinss that could be better. If people just want deal with that, fine. But arguing that there is nothing wrong with how python treats conditional context is not dealing with real life. AFAIAC writing articles in newsgroups isn't dealing with real life, unless maybe if you have a question you need an answer for. I deal plenty with real life myself, during working hours that consists partly in writing python software, with all the good and the few bad python brings. > Magnus gave you a perfectly reasonable example of some code that could > be simplified. You say the two pieces of code aren't equivalent. While > you may be (strictly) correct, your assertion signally fails to add > enlightenment to the discussion. No, my assertion pointed out, that his code would only work under specific constraints. Constraints that may have been very natural in the context the program was written, but that doesn't mean all programs work with such a constraint. He was also talking about logical equivallence and his expression was not logical equivallent with the one that was replaced. > I continue to look forward to the first post in which you actually > accept someone else's point of view without wriggling and squirming to > justify your increasingly tenuous attempts to justify every opinion > you've ever uttered on this group :-) I don't post me too's. There have been plenty of posts here, I have no problem with. I read them, give a slight nod and go on. And if I have an opinion I was to express here, I certainly will to justify it. -- Antoon Pardon From spammers-go-here at spam.invalid Fri Aug 12 17:13:21 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Fri, 12 Aug 2005 17:13:21 -0400 Subject: Using globals with classes References: <42fc2e42$0$18637$14726298@news.sunsite.dk> <42fcd271$1@nntp0.pdx.net> Message-ID: <42fd10e0$0$18645$14726298@news.sunsite.dk> Many thanks for an excellent solution to the problem and clearing up my mind about globals. In some sense, Python globals seem to be a little like the COMMON statement in the old Fortran 77 standard. From araki at hotmail.com Mon Aug 29 15:19:19 2005 From: araki at hotmail.com (araki at hotmail.com) Date: 29 Aug 2005 12:19:19 -0700 Subject: Robust statistics and optimmization from Python In-Reply-To: <1125328346.738915.102990@z14g2000cwz.googlegroups.com> References: <1125328346.738915.102990@z14g2000cwz.googlegroups.com> Message-ID: <1125343159.064820.164590@g47g2000cwa.googlegroups.com> use R. it's pretty highend, and there is an interface for python. From dberlin at gmail.com Wed Aug 31 12:58:04 2005 From: dberlin at gmail.com (dberlin at gmail.com) Date: 31 Aug 2005 09:58:04 -0700 Subject: ANN: Python GUI Editor... Message-ID: <1125507484.817647.257040@z14g2000cwz.googlegroups.com> I named this tool - FarPy GUIE, and is available at: http://farpy.holev.com/ This is a quote from the site: "GUIE (GUI Editor) provides a simple WYSIWYG GUI editor for wxPython. The program was made in C# and saves the GUI that was created to a XML format I called GUIML. This GUIML is a pretty standrad representation of the GUI created with the program. Next, GUIE takes these GUIML files and translates it to wxPython Python code. You may ask yourself why I took the extra step? Why didn't I go straight from C# controls to wxPython code? Why is GUIML neccessary? Well, it isn't. It is there simply for people (or maybe I) to take the GUIML and convert it to other languages. This, by affect can convert this tool from a Python GUI editor, to "any programming language with a GUI module" GUI editor. The GUI Editor was built to be as point & click as possible, trying to avoid wxPython's sizers completly. This means that controls can go anywhere, and you have the freedom to play with the GUI however you want. However, this also means that until some more advanced aligning features are added, this method might be a little awkward at first." I must add that the tool is in it's early stages of development, and basically I need the public's help to make it better. Thanks, From googlenews at tooper.org Wed Aug 31 15:26:56 2005 From: googlenews at tooper.org (tooper) Date: 31 Aug 2005 12:26:56 -0700 Subject: graphical or flow charting design aid for python class development? References: <8ckRe.3276$v83.327@newssvr33.news.prodigy.com> Message-ID: <1125516416.486773.78270@z14g2000cwz.googlegroups.com> You may want to use Doxygen, which generates nice diagrams. It's normally only for C++, but there are nice filters (for ex. http://i31www.ira.uka.de/~baas/pydoxy) that generates C++ header from python code that Doxygen can crunch. Another solution is to use IDE such as Eric3 that can generate UML diags from source code on the fly. From mehdi.rabah at gmail.com Sat Aug 27 19:44:26 2005 From: mehdi.rabah at gmail.com (mehdi.rabah at gmail.com) Date: 27 Aug 2005 16:44:26 -0700 Subject: formal math ? Message-ID: <1125186266.843702.254220@f14g2000cwb.googlegroups.com> Hi, I have just discovered python and it seems so easy ans so powerful to me that it remind me matlab or maple programming language (sorry free software purists ears). So I was wondering if there a sort of formal math library, that can do a thing like: lib.solve("x+1=0") -> x=-1 I have checked numarray and I think it can not do this. Thanks in advance, Mehdi From damir at agg.astranet.ru Tue Aug 16 07:59:03 2005 From: damir at agg.astranet.ru (Damir Hakimov) Date: Tue, 16 Aug 2005 15:59:03 +0400 Subject: base64.encode and decode not correct Message-ID: <4301D507.3070509@agg.astranet.ru> Hi *! I found a strange bug in base64.encode and decode, when I try to encode - decode a file 1728512 bytes lenth. Is somebody meet with this? I don't attach the file because it big, but can send to private. Which solution for transfer file (binary data) via string-only object? Damir. From nyamatongwe+thunder at gmail.com Wed Aug 24 20:26:36 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Thu, 25 Aug 2005 00:26:36 GMT Subject: Unix diff command under Window. In-Reply-To: <1x4j4c2o.fsf@python.net> References: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> <1x4j4c2o.fsf@python.net> Message-ID: <0f8Pe.9409$FA3.6140@news-server.bigpond.net.au> Thomas Heller: > Yes. There's a script in your Python distribution: > Tools/scripts/diff.py > > See also the docs for the 'difflib' standard library module. Is the opposite code, a Python equivalent to 'patch' available? I have endless trouble receiving patch files that assume one of Windows or Unix (in terms of path names and line end characters) which then fail to apply on the other platform. I would like to have a version I could hack on. Neil From tzot at sil-tec.gr Fri Aug 26 19:16:36 2005 From: tzot at sil-tec.gr (Christos Georgiou) Date: Sat, 27 Aug 2005 02:16:36 +0300 Subject: Decline and fall of scripting languages ? References: <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> <7x8xzcck9d.fsf@ruckus.brouhaha.com> <86wtmvlti7.fsf_-_@bhuda.mired.org> <7xoe87vl0i.fsf@ruckus.brouhaha.com> <42f8c2e2.1006880848@news.oz.net> <7xmznijn8v.fsf@ruckus.brouhaha.com> Message-ID: On 16 Aug 2005 01:32:16 -0700, rumours say that Paul Rubin might have written: >Erlang apparently uses microthreads, >probably allocating every call frame on the heap like SML/NJ did, so >they showed it with 80,000 connections open. This is 80000 TCP/IP v4 connections open? -- TZOTZIOY, I speak England very best. "Dear Paul, please stop spamming us." The Corinthians From cyril.bazin at gmail.com Sun Aug 14 14:46:09 2005 From: cyril.bazin at gmail.com (Cyril Bazin) Date: Sun, 14 Aug 2005 20:46:09 +0200 Subject: A PIL Question In-Reply-To: <1124040878.557813.311900@g47g2000cwa.googlegroups.com> References: <1124040878.557813.311900@g47g2000cwa.googlegroups.com> Message-ID: Try Image.new in place of Image.Image if you want to build a new image. At which level are you? Cyril On 14 Aug 2005 10:34:38 -0700, Ray wrote: > > Hello, > > I'm using latest PIL version with Python 2.4.1. (for solving a level in > Python Challenge actually...). Anyway, I'm trying to draw a picture. My > question is, why is it that putdata() won't work? Even this won't run: > > import Image > > im = Image.open("something.jpg") > seq = im.getdata() > > image = Image.Image() > image.putdata(seq) > > image.show() > > I always get: > > Traceback (most recent call last): > File "Script1.py", line 31, in ? > image.putdata(seq) > File "D:\Development\Python24\Lib\site-packages\PIL\Image.py", line > 1120, in putdata > self.im.putdata(data, scale, offset) > AttributeError: 'NoneType' object has no attribute 'putdata' > > Anybody has any idea why this is the case? > > Thanks, > Ray > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From carlosjosepita at gmail.com Sat Aug 27 12:54:10 2005 From: carlosjosepita at gmail.com (Carlos) Date: 27 Aug 2005 09:54:10 -0700 Subject: Twice bound method Message-ID: <1125161650.843901.249760@f14g2000cwb.googlegroups.com> Hi! I want to instrumentate a class with a number of getter/setters. Each pair of getter/setter must keep it's own state gsState but also access to the state iState of instances of the instrumentated class. For example: class GetterSetter: def __init__(gsInstance, gsState): .... def get(gsInstance, iInstance, attr): .... def set(gsInstance, iInstance, attr, value): .... class Instrumentated: def __init__(iInstance, iState): .... getterSetter = GetterSetter(gsState1) Instrumentated.getter1 = getterSetter.get Instrumentated.setter1 = getterSetter.set getterSetter = GetterSetter(gsState2) Instrumentated.getter2 = getterSetter.get Instrumentated.setter2 = getterSetter.set instrumentated = Instrumentated(...) instrumentated.getter1("x") instrumentated.setter2("x", 5) At first sight I thought that the above would work fine as getterSetter.get would bind the getter to the GetterSetter instance and then instrumented.getter1 would bind the already bound getter to the Instrumentated instance, so at the end an invocation like instrumentated.getter1("x") would be calling the original getter passing a GetterInstance as first implicit argument, an Instrumented instance as a second one and "x" as the third -explicit- one. Well, the fact is that the getter is only bound to the last instance, there are no nested bindings. Another solution could come from the use of function nested lexical scopes and closures, with a factory function which takes the gsState as argument and produces a getter (or setter) function taking an iState as first argument and the attribute as second one. Then the class can be instrumentated with the generated getter (or setter) which keeps the gsState captured within its closure. For example: def getterGen(gsState): def getter(iState, attr): .... return getter Instrumentated.getter1 = getterGen(gsState1) Instrumentated.getter2 = getterGen(gsState2) Do you know of another -elegant- solution for the above problem? Is there any way to get the nested method binding behaviour that the first failed attempt required? Thank you in advance. Regards, Carlos From spam.csubich+block at block.subich.spam.com Tue Aug 9 13:41:37 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 13:41:37 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: Rocco Moretti wrote: > Variables in Python are names. They aren't the cubbyholes into which you > put values, they are sticky notes on the front of the cubby hole. +1 MOTW (Metaphor of the Week) From paul at boddie.org.uk Sun Aug 7 09:32:33 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 7 Aug 2005 06:32:33 -0700 Subject: seek python parser References: <42f57826@news.orcon.net.nz> Message-ID: <1123421553.790749.186340@g49g2000cwa.googlegroups.com> I tend to use the compiler module: http://docs.python.org/lib/compiler.html With the output of the parsing functions I selectively inspect the AST nodes using the named attributes listed in the documentation: http://docs.python.org/lib/module-compiler.ast.html For cases where one just needs to traverse the child nodes of an AST node, the getChildNodes method is probably more helpful than the getChildren method, which returns things like name strings and other miscellaneous information mixed up with the list of nodes. If you want a genuine XML DOM version of a Python AST, the following project might provide you with a solution: http://pysch.sourceforge.net/ast.html See also: http://uucode.com/texts/genxml/genxml.html Paul From spam.csubich+block at block.subich.spam.com Tue Aug 2 11:35:39 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 02 Aug 2005 11:35:39 -0400 Subject: 2-player game, client and server at localhost In-Reply-To: References: Message-ID: Michael Rybak wrote: > That's the problem - "or a player input comes in". As I've explained, > this happens a dozen of times per second :(. I've even tried not > checking for player's input after every frame, but do it 3 times more > rare (if framecount % 3 == 0 : process_players_input()). Well, I've > already got it that I shouldn't tie this around framerate, but > nevertheless... There's the key. How are you processing network input, specifically retrieving it from the socket? From ptmcg at austin.rr.com Sat Aug 13 09:22:25 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 13 Aug 2005 06:22:25 -0700 Subject: Printing literal text of an argument References: <1123794291.076999.227310@f14g2000cwb.googlegroups.com> Message-ID: <1123939345.831388.101250@g43g2000cwa.googlegroups.com> Rex - If what you are looking for is a monitor of calls to a certain function, check out this decorator example from the Python Wiki: http://wiki.python.org/moin/PythonDecoratorLibrary?highlight=%28Decorator%29#head-d4ce77c6d6e75aad25baf982f6fec0ff4b3653f4 This will allow you to very quickly turn on/off debugging for a given routine, with no changes required in the calling code. -- Paul From maxerickson at gmail.com Sun Aug 14 14:41:12 2005 From: maxerickson at gmail.com (Max Erickson) Date: Sun, 14 Aug 2005 18:41:12 -0000 Subject: A PIL Question References: <1124040878.557813.311900@g47g2000cwa.googlegroups.com> Message-ID: "Ray" wrote in news:1124040878.557813.311900 at g47g2000cwa.googlegroups.com: > > image = Image.Image() > > Anybody has any idea why this is the case? > Image.Image() isn't the way to get a new image object in PIL. Try Image.new(), which needs at least mode and size arguments. You can get those from your original image... >>> from PIL import Image (skip me loading an image into im) >>> im >>> im.mode 'RGB' >>> im.size (510, 800) >>> im2=Image.new(im.mode,im.size) >>> seq=im.getdata() >>> im2.putdata(seq) Then do im2.show() and everything should be ok. max From randy at psg.com Sat Aug 27 23:27:26 2005 From: randy at psg.com (Randy Bush) Date: Sat, 27 Aug 2005 17:27:26 -1000 Subject: Experience regarding Python tutorials? References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <1125072815.753219.62420@g47g2000cwa.googlegroups.com> Message-ID: <17169.12062.87650.520472@roam.psg.com> > There is also a python tutor newsgroup at gmane > (gmane.comp.python.tutor). is there a mailing list to which it is gated? randy From zen19725 at zen.co.uk Sun Aug 21 08:27:50 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Sun, 21 Aug 2005 13:27:50 +0100 Subject: last line chopped from input file References: <1124603622.204380.256560@g47g2000cwa.googlegroups.com> Message-ID: On 20 Aug 2005 22:53:42 -0700, Eric Lavigne wrote: >Here is a shell command (MS-DOS): > debug\curve-fit output.txt > >And here is a Python script that *should* do the same thing (and almost >does): > > import os > > inputfilename = 'input.txt' > outputfilename = 'output.txt' > > inputfile = open(inputfilename,'r') > outputfile = open(outputfilename,'w') > inputstream,outputstream = os.popen2("debug\\curve-fit") > inputstream.write(inputfile.read()) > inputfile.close() > inputstream.close() > outputfile.write(outputstream.read()) > outputstream.close() > outputfile.close() > >On a side note, I am very new to Python so I would appreciate any >comments on style, or suggestions for simpler ways to write something >like this (seems overkill for matching one line of shell), or more >portable ways to write it (requires '\\' on windows but '/' on linux). A shorter python program would be: os.command("debug\\curve-fit output.txt") If you don't like the doubled \\, you could write: os.command(r"debug\curve-fit output.txt") For portability regarding \\ versus /, look at the os.path module. -- Email: zen19725 at zen dot co dot uk From mlh at selje.idi.ntnu.no Thu Aug 25 09:29:52 2005 From: mlh at selje.idi.ntnu.no (Magnus Lie Hetland) Date: Thu, 25 Aug 2005 13:29:52 +0000 (UTC) Subject: Limited XML tidy References: Message-ID: In article , Toby White wrote: > [snip] I do similar stuff in the new (upcoming) version of Atox (atox.sf.net), which works with potentially ill-formed, partial XML (in the form of PYX events) internally, and can take partial, ill-formed XML as input. >The problem is that when the sax handler raises an exception, >I can't see how to find out why. What I want to do is for >DodgyErrorHandler to do something different depending on >where we are in the course of parsing. Is there anyway >to get that information back from xml.sax (or indeed from >any other sax handler?) What I ended up doing was using an SGML parser (sgmlop) instead. It's highly forgiving (even of illegal entities and the like) but gives me the information I need. Might be worth a look in your app too? >Toby -- Magnus Lie Hetland http://hetland.org From tdelaney at avaya.com Tue Aug 16 20:14:16 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Wed, 17 Aug 2005 10:14:16 +1000 Subject: FW: List copying idiom was Re: [Python-Dev] implementation of copystandard lib Message-ID: <2773CAC687FD5F4689F526998C7E4E5F05CC31@au3010avexu1.global.avaya.com> Tom Anderson wrote: > When you say [:], do you mean that you copy lists like this: > > l = someList() > m = [] > m[:] = l Forwarded to python-list, where it belongs. The idiom is actually: a = [1, 2, 3] b = a[:] Tim Delaney From ptmcg at austin.rr.com Tue Aug 16 00:15:02 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 15 Aug 2005 21:15:02 -0700 Subject: How can I exclude a word by using re? References: <430085e8$1@news.eftel.com> Message-ID: <1124165702.590364.107410@o13g2000cwo.googlegroups.com> Given the example re that you've been trying to get working, here is a pyparsing approach that might be more, um, approachable. Unfortunately, since I don't have the URL of the page you are working with, I'm unable to test this before posting. Good luck, -- Paul # getMP3s.py # get pyparsing at http://pyparsing.sourceforge.net # from pyparsing import * import urllib #~ r=re.compile(ur'valign=top>(?P?\d{1,2})]*>?\s{0,2}' #~ ur'' #~ ur'(?P.+)',re.UNICO?DE|re.IGNORECASE) tdStart,tdEnd = makeHTMLTags("td") aStart,aEnd = makeHTMLTags("a") number = Word(nums) valign = CaselessLiteral("valign=top>") mp3Entry = valign + number.setResultsName("number") + tdEnd + \ tdStart + SkipTo(aStart) + aStart + \ SkipTo(tdEnd) + tdEnd # get list of mp3's targetURL = "http://whatever" targetPage = urllib.urlopen( targetURL ) targetHTML = targetPage.read() targetPage.close() for toks,s,e in mp3Entry.scanString(targetHTML): print toks.number, toks.starta.href From siona at chiark.greenend.org.uk Wed Aug 10 09:13:41 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 10 Aug 2005 14:13:41 +0100 (BST) Subject: searching a list of dictionaries for an element in a list. References: Message-ID: Dan wrote: >> [ someone else wrote: ] >> I want to search list1, and the result should be all dictionaries where >> primarycolor is in input. I can do this using a double for-loop, but is >> there a more efficent way? > >Of course. :-) > >L = [dict for dict in list1 if dict['primarycolor'] in input] Note that (1) shadowing builtin dict is a bad idea and (2) that's still two nested loops -- I think you do theoretically better with input_set = set(input) output_list = [ d for d in dict_list if d['primarycolor'] in input_set ] but I suspect input would have to be a rather large list to favour this. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From travislspencer at gmail.com Fri Aug 19 15:36:21 2005 From: travislspencer at gmail.com (travislspencer at gmail.com) Date: 19 Aug 2005 12:36:21 -0700 Subject: A script to run all of my project's pyunit tests Message-ID: <1124480181.121430.105050@g49g2000cwa.googlegroups.com> Hey All, I am trying to write a script that runs all of my pyunit tests for me. Ideally, I would like to be able to drop a new module into my project's test subdirectory, and the testing script will pick it up automatically. At the moment, I have it working but it is kinda a kludge because every TestCase must provide a function that returns a TestSuite for all of its tests. Here is the basic process and a stripped down version of the script: 1. Locate each `.py' file in my project's test subdirectory. 2. Import the module found in step 1. 3. Get a TestSuite of all of the tests in the module imported in step 2. 4. Add the TestSuite from step 3 to a growing list of suites. 5. Make one granddaddy TestSuite from the list of all those fetched in steps 1 through 4. 6. Create a runner, pass it the uber TestSuite, and run all the tests. My scripts to do these things is as follows: ====================================================================== import os, sys, unittest from glob import glob projHome = os.getenv("PROJ_HOME") sys.path.insert(0, projHome + "/tests") tests = [] for file in glob(projHome + "/tests/*.py"): start = file.rfind("/") + 1 end = file.rfind(".") moduleName = file[start:end] module = __import__(moduleName) tests.append(module.getTestSuite()) #-----------------------^ # The part that I'm not happy with. allTests = unittest.TestSuite(tests) runner = unittest.TextTestRunner(verbosity=2) runner.run(allTests) ====================================================================== With this setup, every module has to have a `getTestSuite' function that returns a TestSuite for the module. This is suboptimal and annoying. The function looks like this is all of my TestCase subclasses: ====================================================================== class MyTestCase(unittest.TestCase): pass def getTestSuite(): return suite if __name__ == "__main__": unittest.main() else: global suite suite = unittest.makeSuite(MyTestCase, 'test') ====================================================================== The problem is that I can't figure out how to do something similar to the TestCases' `unittest.makeSuite(MyTestCase, 'test')' in the script that I'm using to run all of the tests. If anyone has any help or suggestions, I would really appreciate it. -- Regards, Travis Spencer From jonhewer at gmail.com Wed Aug 3 03:57:50 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Wed, 3 Aug 2005 08:57:50 +0100 Subject: pygettext ? In-Reply-To: References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: That was sent with the wrong title, doh! On 8/3/05, Jon Hewer wrote: > Hi > > I'm pretty new to Python, and recently been working my way through > Dive Into Python, and I'm currently writing a really simple rss reader > purely to get familiarised with the language. I want to move onto > something a little more challenging, but I'm stuck for ideas on what > to do. > > I'm after a project that can start quite simple, but has lots of room > for expansion when I get more confident with Python. Ideally > something which would start as a command line program, and then when I > feel adventurous I could build a GUI for it. > > I have just bought the Foundations of Python Network Programming book, > so maybe something network related would be good? > > Cheers > Jon > From steve at holdenweb.com Wed Aug 31 21:53:55 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Aug 2005 20:53:55 -0500 Subject: SpamBayes wins PCW Editors Choice Award for anti-spam software. Message-ID: <43165F33.9050805@holdenweb.com> [separately copied to spambayes-dev] Tony Meyer wrote: > >> While it may not adequately credit the implementation >> language, > > Was this "it" the PCW article or SpamBayes? If the latter, please let > spambayes-dev at python.org know how you think Python should be more > appropriately credited; we are certainly trying to do this. > > (Python is mentioned all over the website, the "Python Powered" logo is > integrated into what passes for a SpamBayes logo, and all donations to the > project go to the PSF). > > With a little more context: > While it may not adequately credit the implementation language, a Google > search for "sourceforge spambayes" results in the first hit being linked > as """SpamBayes: Bayesian anti-spam classifier written in Python.""". I was actually referring to the SpamBayes home page at http://spambayes.sourceforge.net/ which doesn't contain the word "Python" anywhere in its body text - though as I did point out, the title of the page *does*. Sorry about the lack of clarity. I don't have any problem at all with the site, and I know that SpamBayes does actually reflect kudos on the Python language in many people's minds. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From projecktzero at yahoo.com Mon Aug 1 12:57:51 2005 From: projecktzero at yahoo.com (projecktzero) Date: 1 Aug 2005 09:57:51 -0700 Subject: Python IDE's References: <20050731205901.53A6E1E4005@bag.python.org> Message-ID: <1122915471.559698.231740@g43g2000cwa.googlegroups.com> VIM or Emacs. I use VIM on Windows, Mac, and VMS. I'd consider it more of an editor than an IDE, but there are many IDE features available with plug ins. From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 1 07:21:01 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 01 Aug 2005 13:21:01 +0200 Subject: Wheel-reinvention with Python In-Reply-To: References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> Message-ID: <3l6ej1F10vf3eU1@individual.net> phil hunt wrote: > On Sun, 31 Jul 2005 12:09:48 -0700, Cliff Wells wrote: >>On Sun, 2005-07-31 at 10:07 -0700, Kay Schluehr wrote: >> >>> Some other people already abandoned Python not for the worst reasons: >>> >>> http://www.kevin-walzer.com/pivot/entry.php?id=69 >> >>Being a developer requires not only a bit of brains, but quite a bit of >>tenacity as well. Apparently Kevin lacks the second. >> >>> My objection with wrappers around wrappers around wrappers is that I >>> have no hope ever watching the ground. If some error occurs, which >>> layer has to be addressed? Which developing group is reponsible? My own >>> or that of team A, team B, team C ... ? The baroque concept is >>> repulsive to me and only acceptable in case of legacy code that gets >>> wrapped around old one and is dedicated to substitute it continously. >> >>Of course, Tkinter is still a wrapper around a third party library (Tk) >>borrowed from a different language (Tcl) and written again in a third >>language (C), much the same as wxPython. > > In practise any Python GUI is going to contain code from otyher > languages since if it was coded all the way down in python it would > be too slow. Oh, I could imagine that a MFC-like wrapper around win32gui, or another one around Xlib wouldn't be slower that wxWidgets is today. Reinhold From renting at astron.nl Fri Aug 19 02:54:08 2005 From: renting at astron.nl (Adriaan Renting) Date: Fri, 19 Aug 2005 08:54:08 +0200 Subject: Implementing class methods in C Message-ID: I think you'd need to write a C++ class that has the methods you want to implement in C++, then wrap that with SWIG, then inherit from that, though multiple inheritance if you also need functions from a base Python class. The PyQt people use SIP I think, instead of SWIG, might be useful to look into that too too. Adriaan. >>> 08/18/05 6:42 pm >>> Nope, it still doesn't work. Anyway, that's not exactly what i want, since i want func2 to be accessible from all instances of Test() Naveen On Thu, 18 Aug 2005, Jeremy Moles wrote: >I honestly don't know the answer to this and I am entirely guessing >but--does it work without using the new module? That is: > >---------------------------------------------------------------- > >import _test > >class Foo: >pass > >foo = Foo() > >foo.bar = _test.func2 > >foo.bar() > >On Thu, 2005-08-18 at 12:09 -0400, nmichaud at jhu.edu wrote: >>I am having a problem implementing some methods of a python class in C. >>The class is defined in python, but I would like to rewrite some methods >>in c. Here is an example of what I want to do: >> >>file _test.c: >> >>#include >> >>static PyObject >>func2(PyObject *self, PyObject *args) >>{ >> if (self == NULL) { >> PyErr_SetString(PyExc_SystemError, "self is NULL"); >> return NULL; >> } >> >> // Parse arguments >> if (!PyArg_ParseTuple(args, "")) >> { >> return NULL; >> } >> >> Py_INCREF(Py_None); >> return Py_None; >>} >> >>static PyMethodDef TestMethods[] = { >> {"func2", func2, METH_VARARGS, "func2."}, >> {NULL, NULL, 0, NULL} /* Sentinel */ >>}; >> >>PyMODINIT_FUNC >>init_test(void) >>{ >> (void) Py_InitModule("_test", TestMethods); >>} >> >>---------------------------------------------------- >>test.py: >> >>class Test: >> def func1(self): >> print "I am in func 1" >> >>import _test >>import new >>Test.func2 = new.instancemethod(_test.func2, None, Test) >>del(new) >> >>t = Test() >>t.func2() >> >> >>When I run test.py, I get a SystemError exception (which is what I raise >>if self is NULL). I think my confusion lies in the use of PyObject* self >>in the function declaration. Shouldn't this be set to point to the >>instance of class Test that I am calling it from? Am I misunderstanding >>the purpose of PyObject* self? Thanks. >> >>Naveen >> >>--------------------------------------------------------------------- >>Naveen Michaud-Agrawal >>Program in Molecular Biophysics >>Johns Hopkins University >>(410) 614 4435 > -- http://mail.python.org/mailman/listinfo/python-list From spamsink42 at gmail.com Mon Aug 29 18:22:09 2005 From: spamsink42 at gmail.com (spamsink42 at gmail.com) Date: 29 Aug 2005 15:22:09 -0700 Subject: socket.gaierror from httplib References: <1125332208.810975.92280@g43g2000cwa.googlegroups.com> Message-ID: <1125354129.771163.234060@g43g2000cwa.googlegroups.com> fantastic. many thanks. regards, eric From jonhewer at gmail.com Thu Aug 4 04:07:16 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Thu, 4 Aug 2005 09:07:16 +0100 Subject: Ideas for Python project? In-Reply-To: References: <42f01262$0$25028$8fcfb975@news.wanadoo.fr> Message-ID: Thanks i'll check it out. I'm not very good yet tho! On 8/4/05, Stuart Turner wrote: > Jon Hewer wrote: > > > Hi > > > > I'm pretty new to Python, and recently been working my way through > > Dive Into Python, and I'm currently writing a really simple rss reader > > purely to get familiarised with the language. I want to move onto > > something a little more challenging, but I'm stuck for ideas on what > > to do. > > > > I'm after a project that can start quite simple, but has lots of room > > for expansion when I get more confident with Python. Ideally > > something which would start as a command line program, and then when I > > feel adventurous I could build a GUI for it. > > > > I have just bought the Foundations of Python Network Programming book, > > so maybe something network related would be good? > > > > Cheers > > Jon > > I saw a competition in Linux format - may be something to consider. > > - Stuart > -- > http://mail.python.org/mailman/listinfo/python-list > From u.hobelmann at web.de Fri Aug 26 12:03:21 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Fri, 26 Aug 2005 18:03:21 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <86acj5mpty.fsf@bhuda.mired.org> <3n83l2F9ru8U1@individual.net> <3n8di6Fbhg7U2@individual.net> Message-ID: <3n8sqaFch6kU1@individual.net> John Bokma wrote: >> I have cookies off, with explicit exception for sites where >> I want cookies. When the crappy website doesn't bother to MENTION that >> it wants cookies, i.e. give me an error page, how am I to know that it >> needs cookies? Do I want EVERY website to ask me "do you allow XY to >> set a cookie?" NO! > > So what do you want? An error page for every site that wants to set a > cookie? No, the few sites where I actually have to log in to do anything useful, when they're well-coded, tell me that they need cookies, and if I think I like that website I make an exception entry for that site, allowing cookies. Most sites just bombard you with useless, crap cookies (maybe advertising), so they are silently ignored by my browser. The only thing I hate is when I am directed to some website that needs cookies, but doesn't tell me. A couple times I did a survey, wasting maybe 10 minutes of my life for a good cause, and then there was an error. Great! I guess that page needed cookies, but didn't bother to tell me. Back button didn't work, either, so I just left that website. OTOH, people who can't code can be fun, too, such as when you visit a website and there are lots of PHP, Java, SQL, or ASP errors ;) -- I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it. Dogbert From bill.oldroyd at bl.uk Wed Aug 31 06:21:09 2005 From: bill.oldroyd at bl.uk (bill.oldroyd at bl.uk) Date: 31 Aug 2005 03:21:09 -0700 Subject: Help with this error : Protocol wrong for this socket Message-ID: <1125483669.824916.237580@o13g2000cwo.googlegroups.com> I am running Python 2.4.1 on a HP Tru64 Unix system. When try to carry out a DNS query as follows : t = socket.getaddrinfo("labs.bl.uk",None) I get the error message socket.error: (41, 'Protocol wrong type for socket') Am I right in thinking this is something to with the DNS lookup ?. Does anyone have any idea what may be causing the problem ?. Bill From moranar at alice.it Wed Aug 10 07:14:44 2005 From: moranar at alice.it (Adriano Varoli Piazza) Date: Wed, 10 Aug 2005 11:14:44 GMT Subject: What is Python?! In-Reply-To: References: Message-ID: Robert Wierschke ha scritto: ... Reading the FAQ at the python website too difficult? I don't think you missed any of the most frequently asked... Good job. -- Adriano Varoli Piazza The Inside Out: http://moranar.com.ar MSN: adrianomd at hotmail.com ICQ: 4410132 From seaeric at gmail.com Fri Aug 5 01:09:53 2005 From: seaeric at gmail.com (Eric) Date: Thu, 4 Aug 2005 22:09:53 -0700 Subject: Newbie Program Message-ID: I am reading a book on Python and ran across and exercise that I just can't seem to figure out. Its pretty simple, but I just can't get past a certain point. The task is to create a program that flips a coin 100 times and keeps track of the total of heads and tails which is printed to the screen. My plan was to use import random with a range of 2 and use a conditional statement to count to 100. The problem I am encountering is how do I keep track of the totals for heads and tails? Any suggestions would be appreciated. Keep in mind I am very new to Python so there may be a more sophisticated way, but I am just trying to use what the book has taught so far. Thanks, Eric From tchur at optushome.com.au Sat Aug 27 01:10:45 2005 From: tchur at optushome.com.au (Tim Churches) Date: Sat, 27 Aug 2005 15:10:45 +1000 Subject: SAS Transport FIle In-Reply-To: <1125114726.509035.126560@f14g2000cwb.googlegroups.com> References: <1125114726.509035.126560@f14g2000cwb.googlegroups.com> Message-ID: <430FF5D5.8020300@optushome.com.au> Jeff wrote: > Does anyone know of a python module to read a SAS Transport (XPORT) > file? I am not aware of any native Python module to read SAS portable transport (XPORT) files (but that doesn't mean you shouldn't search for one using Google etc). However, the format of the XPORT files is publically available (see http://support.sas.com/techsup/technote/ts140.html )and I would be happy to help test such a module should you or anyone else care to write one. Be aware that the XPORT file format harks back to the days when SAS was only available on IBM mainframes, and teh specs contain some peculiarities for a post-mainframe world, such as the use of IBM double precision representation of floats (7 bits for the exponent and 56 bits for the mantissa, whereas IEEE format uses 11 bits for the exponent and 52 bits for the mantissa) - thus you have to take additional care if you want to retain the full precision expressible in the XPORT format. There are alternative routes, though. 1) The foreign package (see http://cran.r-project.org/doc/packages/foreign.pdf ) for the R statistical system (see http://www.r-project.org) contains a function read.xport which does as its name suggests. You can then use RPy (see http://rpy.sf.net) to convert the resulting R data object(s) into Python objects. Obviously you need to install R and RPy (and ideally Numeric Python too) for this to work, but they are worth installing in their own right. If your XPORT daatset is very large, then R/RPy may not be an option, as R stores everything in memory. 2) Recent (within the last 6 years or so) versions of SAS come with an XML engine, and it easy to export a SAS dataset to an XML file, which would be easier to parse and convert into Python objects than teh SAS XPORT file format, I dare say. The DTD used by SAS is also publicly available (Google for it) 3) Recent versions of SAS also come with PROC EXPORT, which you can use to dump you SAS dataset to a CSV or tab-delimited (or fixed format) text file - but be careful with representation and precision issues. You can write a SAS data step programme to accomplish the same thing in earlier versions of SAS (in fact, that's all that PROC EXPORT does, behind the scenes). Tim C From steven.bethard at gmail.com Fri Aug 19 11:52:56 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 19 Aug 2005 09:52:56 -0600 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon wrote: > But '', {}, [] and () are not nothing. They are empty containers. > And 0 is not nothing either it is a number. Suppose I have > a variable that is either None if I'm not registered and a > registration number if I am. In this case 0 should be treated > as any other number. This is why None is a singleton:: if registration_number is None: # do one thing else: # do another In the OP's case, if file.read() had happened to return None instead of the empty string, he probably would've wanted to do the same thing. OTOH, people on python-dev have said that the file.read() idiom of returning '' when it's done should be replaced by a true iterator, i.e. using StopIteration. (I don't know the details of exactly how things would change, but I suspect this is something that will happen in Python 3.0.) STeVe From mscottschilling at hotmail.com Fri Aug 26 01:26:08 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Fri, 26 Aug 2005 05:26:08 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: "Denis Kasak" wrote in message news:dem3hh$o9h$1 at news1.xnet.hr... > Mike Schilling wrote: >> >> I see a difference between "X would be useful for A, B, and C" and "Y >> will always be the only proper way." >> >> Don't you? > > Y would not be useful because of the bandwidth it consumes, the malware it > would introduce, the additional time spent focusing on the format rather > than quality of the content and, frankly, because it's useless. Threaded mail-readers too, screen-based editors , spell-checkers, all useless frills. From fuzzyman at gmail.com Tue Aug 23 09:21:09 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 23 Aug 2005 06:21:09 -0700 Subject: Python Light Revisted? In-Reply-To: <1124568446.496146.247180@g47g2000cwa.googlegroups.com> References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> <1124568446.496146.247180@g47g2000cwa.googlegroups.com> Message-ID: <1124803269.057661.199230@g47g2000cwa.googlegroups.com> Steve M wrote: > I agree with you in part and disagree in part. > [snip..] > > Now, what I do agree with is a Python that can be run from a folder > without having to be installed on the system. That could have lots of > benefits, if the details with pythonpath and whatever could be sorted > out. For example I haven't upgraded to 2.4 yet because I have 20 You mean like Movable Python ? *grin* (Windoze only though I'm afraid) http://www.voidspace.org.uk/python/movpy > different packages (e.g. SOAPpy, ZODB, whatever) installed on WinXP, > many of which required me selecting my 2.3 installation when I > installed them. I have no idea what will happen to all those if I run > the ActiveState installer for 2.4. I seem even to remember reading that > I have to un-install 2.3 before installing 2.4. I don't want to > re-install those 20 packages. Anyway I haven't had time to research it > and it isn't pressing, even though I'd like to start trying decorators > and generator expressions. I faced similar issues - in the end it wasn't such a pain though. http://www.voidspace.org.uk/python/articles/upgrading_python.shtml Just make a list of the modules you want to keep and fetch the Python 2.4 installers before making the switch. Gives you a nice opportunity to clean up your 'site-packages' folder. Regards, Fuzzyman http://www.voidspace.org.uk/python From fakeaddress at nowhere.org Tue Aug 30 04:05:58 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 30 Aug 2005 08:05:58 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xmzn41ofc.fsf@ruckus.brouhaha.com> <878xyoe6m2.fsf@wilson.rwth-aachen.de> <7xirxri3x5.fsf@ru <%_oQe.72$WJ3.55@newssvr21.news.prodigy.com> Message-ID: Steve Holden wrote: > I'm all in favor of discussions to make 3.0 a better > language. This one should definitely be two-phase. First, the non-code- breaking change that replaces-and-deprecates the warty handling of negative indexes, and later the removal of the old style. For the former, there's no need to wait for a X.0 release; for the latter, 3.0 may be too early. The draft PEP went to the PEP editors a couple days ago. Haven't heard back yet. -- --Bryan From wolfgang.keller.nospam at gmx.de Mon Aug 15 03:48:09 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Mon, 15 Aug 2005 09:48:09 +0200 Subject: Spreadsheet with Python scripting and database interface? References: <20050810234653.6B0A.1.NOFFLE@dieschf.news.arcor.de> Message-ID: > o The Python plugin > o The Python plugin loader > o Additional Python functions Do these provide the possibility to use Python as macro/scripting language from within Gnumeric? TIA, Sincerely, Wolfgang Keller From steve at holdenweb.com Fri Aug 26 12:21:36 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Aug 2005 12:21:36 -0400 Subject: ideas for university project ?? In-Reply-To: References: Message-ID: Thomas Guettler wrote: > Am Fri, 26 Aug 2005 11:49:34 +0100 schrieb Jon Hewer: > > >>Hi >> >>I'm about to start my third, and final, year in computer science at >>cambridge uni, and i need to come up with an idea for a software >>project, but i'm really struggling for ideas, and i was wondering >>whether anyone here had any suggestions. > > > Hi, > > you could port Python to the WRT54. > > The Linksys WRT54 is a WLAN-Router which runs Linux. > > See http://openwrt.org/ > > I think it is a good project for a university. It is software > and hardware related. > > Thomas > It would be a good final-year project, but you may want to try something that hasn't already been done ... see http://skreak.com/wrt54g/python.php regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Tracy.Beck at Infineon.com Fri Aug 26 10:02:36 2005 From: Tracy.Beck at Infineon.com (T Beck) Date: 26 Aug 2005 07:02:36 -0700 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> Message-ID: <1125064956.863140.32270@g14g2000cwa.googlegroups.com> John Bokma wrote: > "T Beck" wrote: > > > If we argue that people are evolving the way e-mail is handled, and > > adding entire new feature sets to something which has been around > > since the earliest days of the internet, then that's perfectly > > feasable. HTML itself has grown. We've also added Javascript and > > Shockwave. > > They are not additions to HTML, like PNG is no addition to HTML, or wav, > mp3, etc. > [snip] Wasn't the point... I never said they were. HTML is at version 4.0(I think?) now, AND we've added extra layers of stuff you can use alongside of it. The internet is a free-flowing evolving place... to try to protect one little segment like usenet from ever evolving is just ensuring it's slow death, IMHO. That's all... --T Beck From frr at easyjob.net Fri Aug 5 12:54:22 2005 From: frr at easyjob.net (frr at easyjob.net) Date: 5 Aug 2005 09:54:22 -0700 Subject: Syntax error after upgrading to Python 2.4 Message-ID: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> Hi, After upgrading to 2.4 (from 2.3), I'm getting a weird syntax error: >>> import themes Traceback (most recent call last): File "", line 1, in ? File "themes.py", line 564 font = self.font.makeBlackAndWhite(), additive = self.additive, ^ SyntaxError: invalid syntax The relevant code is: def makeBlackAndWhite( self ): return CharStyle( names = self.names, basedOn = self.basedOn.makeBlackAndWhite(), font = self.font.makeBlackAndWhite(), additive = self.additive, prefixText = self.prefixText ) This is a method in the CharStyle class which returns a new modified instance of CharStyle. I'm using Windows XP and Python 2.4.1 Any ideas? O:-) From sjmachin at lexicon.net Fri Aug 19 02:18:12 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 16:18:12 +1000 Subject: while c = f.read(1) In-Reply-To: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <430579A4.1060800@lexicon.net> Greg McIntyre wrote: > I have a Python snippet: > > f = open("blah.txt", "r") > while True: > c = f.read(1) > if c == '': break # EOF That could read like this if not c: break # EOF # see below for comments on what is true/false > # ... work on c > > Is some way to make this code more compact and simple? It's a bit > spaghetti. Not at all, IMHO. This is a simple forward-branching exit from a loop in explicable circumstances (EOF). It is a common-enough idiom that doesn't detract from readability & understandability. Spaghetti is like a GOTO that jumps backwards into the middle of a loop for no discernable reason. > > This is what I would ideally like: > > f = open("blah.txt", "r") > while c = f.read(1): > # ... work on c > > But I get a syntax error. > > while c = f.read(1): > ^ > SyntaxError: invalid syntax > > And read() doesn't work that way anyway because it returns '' on EOF > and '' != False. > You have a bit of a misunderstanding here that needs correcting: In "if " and "while ", is NOT restricted to being in (True, False). See section 5.10 of the Python Reference Manual: """ In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: None, numeric zero of all types, empty sequences (strings, tuples and lists), and empty mappings (dictionaries). All other values are interpreted as true. """ ... AND it's about time that list is updated to include False explicitly -- save nitpicking arguments about whether False is covered by "numeric zero of all types" :-) > If I try: > > f = open("blah.txt", "r") > while (c = f.read(1)) != '': > # ... work on c > > I get a syntax error also. :( > > Is this related to Python's expression vs. statement syntactic > separation? How can I be write this code more nicely? > > Thanks > How about for c in f.read(): ? Note that this reads the whole file into memory (changing \r\n to \n on Windows) ... performance-wise for large files you've spent some memory but clawed back the rather large CPU time spent doing f.read(1) once per character. The "more nicely" factor improves outasight, IMHO. Mild curiosity: what are you doing processing one character at a time that can't be done with a built-in function, a standard module, or a 3rd-party module? From osv at javad.ru Wed Aug 3 09:30:31 2005 From: osv at javad.ru (Sergei Organov) Date: 03 Aug 2005 17:30:31 +0400 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: zen19725 at zen.co.uk (phil hunt) writes: [...] > Unix pipelines act on ascii files; No, they don't. -- Sergei. From grante at visi.com Wed Aug 10 09:31:53 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 10 Aug 2005 13:31:53 -0000 Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <42f97878.1053366641@news.oz.net> Message-ID: <11fk0e91qheac1f@corp.supernews.com> On 2005-08-10, Bengt Richter wrote: > On Tue, 09 Aug 2005 21:50:06 -0000, Grant Edwards wrote: > >>On 2005-08-09, Scott David Daniels wrote: >>> Grant Edwards wrote: >>>>>Ex #1) 333-3333 >>>>>Hex On disk: 00 00 00 80 6a 6e 49 41 >>>>> >>>>>Ex #2) 666-6666 >>>>>Hex On disk: 00 00 00 80 6a 6e 59 41 >>>> >>>> So there's only a 1-bit different between the on-disk >>>> representation of 333-3333 and 666-6666. >>>> >>>> That sounds pretty unlikely. Are you 100% sure you're looking >>>> at the correct bytes? >>> >>> Perhaps the one bit is an exponent -- some kind of floating point >>> based format? That matches the doubling of all digits. >> >>That would just be sick. I can't imagine anybody on an 8-bit >>CPU using FP for a phone number. > >>> def double_binary_lehex_to_double(dhex): > ... "convert little-endian hex of ieee double binary to double" > ... assert len(dhex)==16, ( > ... "hex of double in binary must be 8 bytes (hex pairs in little-endian order") > ... dhex = ''.join(reversed([dhex[i:i+2] for i in xrange(0,16,2)])) > ... m = int(dhex, 16) > ... x = ((m>>52)&0x7ff) - 0x3ff - 52 > ... s = (m>>63)&0x1 > ... f = (m & ((1<<52)-1))|((m and 1 or 0)<<52) > ... return (1.0,-1.0)[s]*f*2.0**x > ... > >>> double_binary_lehex_to_double('000000806a6e4941') > 3333333.0 > >>> double_binary_lehex_to_double('000000806a6e5941') > 6666666.0 > >>> double_binary_lehex_to_double('0000108777F9Fc41') > 7777777777.0 > > ;-) Damn. I still say that's just plain sick. -- Grant Edwards grante Yow! NEWARK has been at REZONED!! DES MOINES has visi.com been REZONED!! From mwh at python.net Mon Aug 8 17:51:46 2005 From: mwh at python.net (Michael Hudson) Date: Mon, 08 Aug 2005 21:51:46 GMT Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <1123390288.402485.171020@o13g2000cwo.googlegroups.com> <1123477219.899534@yasure> <7xwtmx7zp6.fsf@ruckus.brouhaha.com> Message-ID: Donn Cave writes: > On the contrary, there are a couple. Ghc is probably the > leading implementation these days, and by any reasonable > measure, it is serious. > > Objective CAML is indeed not a pure functional language. *cough* unsafePerformIO *cough* Cheers, mwh -- MAN: How can I tell that the past isn't a fiction designed to account for the discrepancy between my immediate physical sensations and my state of mind? -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From geskerrett at hotmail.com Fri Aug 26 10:55:26 2005 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 26 Aug 2005 07:55:26 -0700 Subject: Converting from Microsoft Binary Format floats to Python Float Message-ID: <1125068126.386967.194750@o13g2000cwo.googlegroups.com> In the '80's, Microsoft had a proprietary binary structure to handle floating point numbers, In a previous thread, Bengt Richter posted some example code in how to convert these to python floats; http://groups.google.com/group/comp.lang.python/browse_thread/thread/42150ccc20a1d8d5/4aadc71be8aeddbe#4aadc71be8aeddbe I copied this code and modified it slightly, however, you will notice that for one of the examples, the conversion isn't exact. Can anyone advise me on how to modify this code to correct for this situation ? I think the problem may be related to the different lengths of the mantissa. For double precision (8bytes) MBF format had 55 where as Python floats (IEEE) has only 52 ?? Sample Code Below ---------------------- # Conversion of Microsoft Binary Format numbers to Python Floats import binascii as bn import struct as st data = [(1234567890,'000000AF052C139F?'), (4069954144,'00000060929672A0'?), (999999.99, '703D0AD7FF237494'), ( 88888.88, '400ad7a3709c2d91'), ( 22222.22, '400ad7a3709c2d8f'), ( 33333.33, 'b047e17a54350290'), ( 1500.34, '7814ae47e18a3b8b'), ( 42345.00, '0000000000692590'), ] def msd2float(bytes): #take out values that don't make sense possibly the NaN and Infinity ?? if sum(bytes) in [0,72,127]: return 0.0 b = bytes[:] sign = bytes[-2]&0x80 b[-2] |= 0x80 #hidden most sig bit in place of sign exp = bytes[-1] - 0x80 - 56 #exponent offset acc = 0L for i,byte in enumerate(b[:-1]): acc |=(long(byte)<<(i*8)) return (float(acc)*2.0**exp)*((1.,-1.?)[sign!=0]) for line in data: inval = line[0] binval = bn.unhexlify(line[1]) le_bytes = list(st.unpack('BBBBBBBB',binv?al)) outval = msd2float(le_bytes) print " In:",inval, "\nOut:",outval,"\n" Sample Output ------------------------ C:/Python24/pythonw.exe -u "C:/pytest/dms/Test MBF.pyw" In: 1234567890 Out: 1234567895.5 In: 4069954144 Out: 4069954144.0 In: 999999.99 Out: 999999.99 In: 88888.88 Out: 88888.88 In: 22222.22 Out: 22222.22 In: 33333.33 Out: 33333.33 In: 1500.34 Out: 1500.34 In: 42345.0 Out: 42345.0 ----End Sample Output ---- From paddy3118 at netscape.net Thu Aug 11 00:01:19 2005 From: paddy3118 at netscape.net (Paddy) Date: 10 Aug 2005 21:01:19 -0700 Subject: Interface type checking Message-ID: <1123730696.892534.314200@g47g2000cwa.googlegroups.com> Hi, I read a blog entry by GVR on interfaces in which he mentioned that you had to be able to state the type signature of, say, a function. That got me thinking along the lines of: If you have some typical data, then transform it into a string showing its sub-types. Could not a regular expression matching this string be used to check the type signature of the data? for example: >>> data = [[{'a': 1, ('b',):3.0 }, ()]] >>> stringrep = typeExpand(data) >>> stringrep 'list:float>,tuple<>>>' >>> re.match(r"^list|tuple<.*>)*>>$",stringrep) <_sre.SRE_Match object at 0x01611F60> >>> Looking at the example above, I don't think regular expression matching is right. Some extra syntax such as: typeMatcher.match(r"list|tuple<.*>)*>>", stringrep Where this matcher is more like a parser and so does '<' '>' nested bracket matching; changes . to mean 0 or more types (e.g: 'str'; or 'str,str...'); and allows you the shorthand of writing 'list' for .list<.*>'. I've done some work below on typeExpand, but I'm not fluent in a parser module to implement typeMatcher.match quickly. Enjoy! #============== BEGIN typeMatcher.py ================== ''' Object type Expander ''' import types from pprint import pprint as pp # Map types to a type name type2name = dict( [ (typ,name[:name.rindex('Type')].lower()) for name,typ in types.__dict__.iteritems() if type(typ)==types.TypeType and str(typ).find('=0 ] +[(type(set()), 'set')] ) #pp(type2name) def typeExpand(obj): ' Expand an objects type' ty = type(obj) name = type2name.get(ty,'') if not name: # Make up a name. So "" becomes "_type_XX_" name = str(type(obj)) name = name.replace(' ','_') name = name.replace('<','_') name = name.replace('>','_') name = name.replace("'",'') typeExpansionHandler = globals().get( name+'__TypeHandler', None) if typeExpansionHandler: return ''.join([name, '<', typeExpansionHandler(obj), '>']) else: return name def list__TypeHandler(obj): ' How to expand the contents of a list/tuple' return ','.join([ typeExpand(ob) for ob in obj]) tuple__TypeHandler = list__TypeHandler def dict__TypeHandler(obj): ' How to expand the contents of a dict' return ','.join([ '%s:%s' % (typeExpand(name), typeExpand(value)) for name,value in obj.iteritems()]) def match(matchExprString, typeString): pass #============== END typeMatcher.py ================== From xah at xahlee.org Thu Aug 11 21:23:42 2005 From: xah at xahlee.org (Xah Lee) Date: 11 Aug 2005 18:23:42 -0700 Subject: Jargons of Info Tech industry Message-ID: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are absolutely necessary. For example, polytope, manifold, injection/bijection/surjection, group/ring/field.., homological, projective, pencil, bundle, lattice, affine, topology, isomorphism, isometry, homeomorphism, aleph-0, fractal, supremum/infimum, simplex, matrix, quaternions, derivative/integral, ... and so on. Each and every one of these captures a concept, for which practical and theoretical considerations made the terms a necessity. Often there are synonyms for them because of historical developments, but never ?jargons for jargon's sake? because mathematicians hate bloats and irrelevance. The jargon-soaked stupidity in computing field can be grouped into classes. First of all, there are jargons for marketing purposes. Thus you have Mac OS ?X?, Windows ?XP?, Sun OS to Solaris and the versioning confusion of 4.x to 7 to 8 and also the so called ?Platform? instead of OS. One flagrant example is Sun Microsystem's Java stuff. Oak, Java, JDK, JSDK, J2EE, J2SE enterprise edition or no, from java 1.x to 1.2 == Java 2 now 1.3, JavaOne, JFC, Jini, JavaBeans, entity Beans, Awk, Swing... fucking stupid Java and fuck Sun Microsystems. This is just one example of Jargon hodgepodge of one single commercial entity. Marketing jargons cannot be avoided in modern society. They abound outside computing field too. The Jargons of marketing came from business practice, and they can be excusable because they are kinda a necessity or can be considered as a naturally evolved strategy for attracting attention in a laissez-faire economy system. The other class of jargon stupidity is from computing practitioners, of which the Unix/Perl community is exemplary. For example, the name Unix & Perl themselves are good examples of buzzing jargons. Unix is supposed to be opposed of Multics and hints on the offensive and tasteless term eunuchs. PERL is cooked up to be ?Practical Extraction & Reporting Language? and for the precise marketing drama of being also ?Pathologically Eclectic Rubbish Lister?. These types of jargons exudes juvenile humor. Cheesiness and low-taste is their hall-mark. If you are familiar with unixism and perl programing, you'll find tons and tons of such jargons embraced and verbalized by unix & perl lovers. e.g. grep, glob, shell, pipe, man, regex, more, less, tarball, shebang, Schwartzian Transform, croak, bless, interpolation, TIMTOWTDI, DWIM, RFC, RTFM, I-ANAL, YMMV and so on. There is another class of jargon moronicity, which i find them most damaging to society, are jargons or spurious and vague terms used and brandished about by programers that we see and hear daily among design meetings, online tech group postings, or even in lots of computing textbooks or tutorials. I think the reason for these, is that these massive body of average programers usually don't have much knowledge of significant mathematics, yet they are capable of technical thinking that is not too abstract, thus you ends up with these people defining or hatching terms a-dime-a-dozen that's vague, context dependent, vacuous, and their commonality are often a result of sopho-morons trying to sound big. Here are some examples of the terms in question: ? anonymous functions or lambda or lamba function ? closure ? exceptions (as in Java) ? list, array, vector, aggregate ? hash (or hash table) ? fantastically stupid ? rehash (as in csh or tcsh) ? regular expression (as in regex, grep, egrep, fgrep) ? name space (as in Scheme vs Common Lisp debates) ? depth first/breadth first (as in tree traversing.) ? operator ? operator overloading ? polymorphism ? inheritance ? first class objects ? pointers, references ? tail recursion My time is limited, so i'll just give a brief explanation of my thesis on selective few of these examples among the umpteen. In a branch of math called lambda calculus, in which much theories of computation are based on, is the origin of the jargon _lambda function_ that is so frequently reciprocated by advanced programering donkeys. In practice, a subroutine without side-effects is supposed to be what ?lambda function? means. Functional languages often can define them without assigning them to some variable (name), therefore the ?function without side-effects? are also called ?anonymous functions?. One can see that these are two distinct concepts. If mathematicians are designing computer languages, they would probably just called such thing _pure functions_. The term conveys the meaning, without the ?lamba? abstruseness. (in fact, the mathematics oriented language Mathematica refers to lambda function as pure function, with the keyword Function.) Because most programers are sopho-morons who are less capable of clear thinking but nevertheless possess human vanity, we can see that they have not adopted the clear and fitting term, but instead you see lambda function this and that obfuscations dropping from their mouths constantly. Now the term ?closure? can and indeed have meant several things in the computing field. The most common is for it to mean a subroutine that holds some memory but without some disadvantages of modifying a global variable. Usually such is a feature of a programing language. When taken to extreme, we have the what's called Object Oriented Programing methodology and languages. The other meaning of ?closure? i have seen in text books, is for it to indicate that the things in the language is ?closed? under the operations of the language. For example, for some languages you can apply operations or subroutines to any thing in the language. (These languages are often what's called ?dynamic typing? or ?typeless?). However, in other languages, things have types and cannot be passed around subroutines or operators arbitrarily. One can see that the term ?closure? is quite vague in conveying its meaning. The term nevertheless is very popular among talkative programers and dense tutorials, precisely because it is vague and mysterious. These pseudo-wit living zombies, never thought for a moment that they are using a moronic term, mostly because they never clearly understand the concepts behind the term among the contexts. One can particular see this exhibition among Perl programers. (for an example of the fantastically stupid write-up on closure by the Perl folks, see ?perldoc perlfaq7? and ?perldoc perlref?.) in the so-called ?high-level? computing languages, there are often data types that's some kind of a collection. The most illustrative is LISt Processing language's lists. Essentially, the essential concept is that the language can treat a collection of things as if it's a single entity. As computer languages evolve, such collection entity feature also diversified, from syntax to semantics to implementation. Thus, beside lists, there are also terms like vector, array, matrix, tree, hash/?hash table?/dictionary. Often each particular term is to convey a particular implementation of collection so that it has certain properties to facilitate specialized uses of such groupy. The Java language has such groupy that can illustrate the point well. In Java, there are these hierarchy of collection-type of things: Collection Set (AbstractSet, HashSet) SortedSet (TreeSet) List (AbstractList, LinkedList, Vector, ArrayList) Map (AbstractMap, HashMap, Hashtable) SortedMap (TreeMap) The words without parenthesis are Java Interfaces, and ones in are implementations. The interface hold a concept. The deeper the level, the more specific or specialized. The implementation carry out concepts. Different implementation gives different algorithmic properties. Essentially, these hierarchies of Java show the potential complexity and confusion around groupy entities in computer languages. Now, among the programers we see daily, who never really thought out of these things, will attach their own specific meaning to list/array/vector/matrix/etc type of jargons in driveling and arguments, oblivious to any thought of formalizing what the fuck they are really talking about. (one may think from the above tree-diagram that Java the language has at least put clear distinction to interface and implementation, whereas in my opinion they are one fantastic fuck up too, in many respects.) --------------------- This post is archived at http://xahlee.org/UnixResource_dir/writ/jargons.html ? Copyright 2002 by Xah Lee. Xah xah at xahlee.org ? http://xahlee.org/ From ptmcg at austin.rr.com Fri Aug 19 14:39:27 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 19 Aug 2005 11:39:27 -0700 Subject: BeautifulSoup References: Message-ID: <1124476767.160347.55710@g14g2000cwa.googlegroups.com> Here's a pyparsing program that reads my personal web page, and spits out HTML with all of the HREF's reversed. -- Paul (Download pyparsing at http://pyparsing.sourceforge.net.) from pyparsing import Literal, quotedString import urllib LT = Literal("<") GT = Literal(">") EQUALS = Literal("=") htmlAnchor = LT + "A" + "HREF" + EQUALS + quotedString.setResultsName("href") + GT def convertHREF(s,l,toks): # do HREF conversion here - for demonstration, we will just reverse them print toks.href return "" % toks.href[::-1] htmlAnchor.setParseAction( convertHREF ) inputURL = "http://www.geocities.com/ptmcg" inputPage = urllib.urlopen(inputURL) inputHTML = inputPage.read() inputPage.close() print htmlAnchor.transformString( inputHTML ) From kay.schluehr at gmx.net Mon Aug 8 05:26:40 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Aug 2005 02:26:40 -0700 Subject: PEP: Specialization Syntax In-Reply-To: <4iEJe.5130$651.540962@weber.videotron.net> References: <42F66FF2.7010901@v.loewis.de> <1123481295.549324.99810@g49g2000cwa.googlegroups.com> <4iEJe.5130$651.540962@weber.videotron.net> Message-ID: <1123493200.390420.160040@g44g2000cwa.googlegroups.com> Nicolas Fleury schrieb: > Kay Schluehr wrote: > > def makeClass(cls_name, **kw): > > return type(cls_name,(), kw) > > > >>>>MyObject = makeClass("MyObject",a=8) > >>>>MyObject > > As said to Bengt, a place is needed to write the class definition. > There's no need for metaclass in that case: > > def makeType(a, b, c=someDefault): > arguments = locals() > class MyObject: > pass # Complete definition here > MyObject.__dict__.update(arguments) > return MyObject > > Regards, > Nicolas I have to admit that i don't actually understand what you want? The problems you try to solve seem trivial to me but it's probably my fault and i'm misreading something. You might be correct that your PEP may be interesting only if "optional static typing" will be introduced to Py3K and then we will suddenly have an immediate need for dealing with generic types so that the syntax can be reused for deferred functions ( the concept of "specialization" is usually coupled with some kind of partial evaluation which doesn't take place somewhere in your proposal ). But i'm not sure if this makes sense at all. Kay From vincent at visualtrans.de Tue Aug 2 14:21:29 2005 From: vincent at visualtrans.de (vincent wehren) Date: Tue, 2 Aug 2005 20:21:29 +0200 Subject: py2exe windows apps path question References: <11ev0tcg9n2ndd@corp.supernews.com> Message-ID: "Gregory Pi?ero" schrieb im Newsbeitrag news:mailman.2632.1123005673.10512.python-list at python.org... |And here is how I make sure I'm always using the right directory in my scripts: | |Put this code at the top: |import sys |curdir=os.path.dirname(sys.argv[0]) |#print curdir |Then I use curdir to build all of the paths in my app: |For example let's get a list of files in a folder: |lstresumes=os.listdir(os.path.join(curdir,resume_folder_path)) #get |list of resumes Greg, If you need something that works both on a frozen app as well as an (unfrozen) python script, you'd be better off using something like: def getAppPrefix(): """Return the location the app is running from """ isFrozen = False try: isFrozen = sys.frozen except AttributeError: pass if isFrozen: appPrefix = os.path.split(sys.executable)[0] else: appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0] return appPrefix Now you can use the return value of getAppPrefix() everywhere you need to calculate paths relative to your app, regardless if it involves a regular script or py2exe'ified one. Regards, -- Vincent Wehren From utabintarbo at gmail.com Tue Aug 23 07:53:41 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 23 Aug 2005 04:53:41 -0700 Subject: X-Platform method of remote execution of Windows programs In-Reply-To: References: Message-ID: <1124798021.836392.58580@g47g2000cwa.googlegroups.com> It seems as if I am doomed to use additional software on the windows box. Damn! The "unclarity" is in the authentication for the remote box. If I wish to start a process on a remote box with another user's credentials (other than the user I am logged in as), I am unsure as to how to accomplish this. Anything you can add to the docs concerning this would be greatly appreciated. Thanks for the response, Bob From max2 at fisso.casa Tue Aug 23 14:40:25 2005 From: max2 at fisso.casa (max(01)*) Date: Tue, 23 Aug 2005 18:40:25 GMT Subject: pipes like perl In-Reply-To: <430b6311$0$29696$636a15ce@news.free.fr> References: <430b6311$0$29696$636a15ce@news.free.fr> Message-ID: bruno modulix wrote: > max(01)* wrote: > >>hi. > > > (snip) > > >>it doesn't work, since "*do_something*" and *do_something_more* are >>always executed (it seems like >> >>MYPIPE = os.popen("*some_system_command*", "r") >> >>does not raise any exception even if *some_system_command* does not >>exist/work... >> >>any help? > > > http://www.python.org/doc/2.4.1/lib/os-newstreams.html#os-newstreams > """ > The exit status of the command (encoded in the format specified for > wait()) is available as the return value of the close() method of the > file object, except that when the exit status is zero (termination > without errors), None is returned. > """ but i need to check the success/failure of the external command *before* closing the file! From oren.tirosh at gmail.com Wed Aug 3 01:48:20 2005 From: oren.tirosh at gmail.com (Oren Tirosh) Date: 2 Aug 2005 22:48:20 -0700 Subject: JBUS and Python which way References: <1122990414.662555.116450@g43g2000cwa.googlegroups.com> Message-ID: <1123048100.495075.3720@g44g2000cwa.googlegroups.com> If you can't find any JBUS/Modbus modules specific for Python it's possible to use one of the many C/C++ modules available and make a Python wrapper for it with an interface generator like SWIG or SIP. You say that you don't have much technical background so you may consider hiring someone to do it. It's not a big project so it shouldn't be too expensive. Oren From robin at reportlab.com Mon Aug 15 10:41:16 2005 From: robin at reportlab.com (Robin Becker) Date: Mon, 15 Aug 2005 15:41:16 +0100 Subject: SOAP and XMLRPC In-Reply-To: <4300A5DF.4080903@chamonix.reportlab.co.uk> References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> <1124115078.926129.285880@f14g2000cwb.googlegroups.com> <4300A5DF.4080903@chamonix.reportlab.co.uk> Message-ID: <4300A98C.2060705@chamonix.reportlab.co.uk> Robin Becker wrote: > dcrespo wrote: > >>Hi... Thanks for your answer, but can you give me his contact or tell >>him to post here the answer I'm looking for? I'm needing it seriously. >> > > Well I'm not a VB person so perhaps you need to ask on a VB list. Unfortunately > the student has vanished into the real world. On the other hand there are resources available via Google eg http://www.wwwcoder.com/main/parentid/460/site/4709/68/default.aspx -- Robin Becker From nick at craig-wood.com Mon Aug 22 13:29:49 2005 From: nick at craig-wood.com (Nick Craig-Wood) Date: 22 Aug 2005 17:29:49 GMT Subject: sending binary files to a 16 micro controller. References: <1124710479.733220.26280@o13g2000cwo.googlegroups.com> <11gjn3in8u2965d@corp.supernews.com> Message-ID: Grant Edwards wrote: > You have no control over packet size in TCP if you use the > normal socket interface. About the only thing you can to is > put delays between calls to send() in hope that the TCP stack > will send a packet. You can set the MTU (maximum transfer unit) for that interface. You do with with ifconfig under un*x - I expect windows has an interface to do it too (perhaps ipconfig?) For ethernet the MTU is 1500 bytes normally. > If you really do want control over packet size, you'll have to > use a raw socket and impliment TCP yourself. Actually I'd recommend the OP uses UDP, not TCP. I've implemented a few systems which speak UDP directly and its very easy. I wouldn't like to implement TCP though! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From cookedm+news at physics.mcmaster.ca Thu Aug 4 17:45:37 2005 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Thu, 04 Aug 2005 17:45:37 -0400 Subject: Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name? References: <1773f1t9k90pakcjl7ita4ags006auck80@4ax.com> Message-ID: Casey Hawthorne writes: > Is there a way to determine -- when parsing -- if a word contains a > builtin name or other imported system module name? > > Like "iskeyword" determines if a word is a keyword! Look in the keyword module; there is actually an "iskeyword" function there :) For modules, sys.modules is a dictionary of the modules that have been imported. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From gabriel.cooper at mediapulse.com Fri Aug 19 10:44:33 2005 From: gabriel.cooper at mediapulse.com (Gabriel Cooper) Date: Fri, 19 Aug 2005 10:44:33 -0400 Subject: Newbie Question In-Reply-To: <6rGdnSpFWa5se5jeRVn-vw@comcast.com> References: <6rGdnSpFWa5se5jeRVn-vw@comcast.com> Message-ID: <4305F051.5050601@mediapulse.com> look into the csv module. (for comma-separated-value text files.) Tom Strickland wrote: >I have a file that contains many lines, each of which consists of a string >of comma-separated variables, mostly floats but some strings. Each line >looks like an obvious tuple to me. How do I save each line of this file as a >tuple rather than a string? Or, is that the right way to go? > >Thank you. > >Tom Strickland > > From ms at cerenity.org Mon Aug 22 16:04:52 2005 From: ms at cerenity.org (Michael Sparks) Date: Mon, 22 Aug 2005 21:04:52 +0100 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <7xvf2183mt.fsf@ruckus.brouhaha.com> <1124553656.678727@yasure> <86d5o89gz4.fsf@bhuda.mired.org> <7xiry0vwqr.fsf@ruckus.brouhaha.com> Message-ID: <430a2fd0$0$17490$ed2e19e4@ptn-nntp-reader04.plus.net> Paul Rubin wrote: > Mike Meyer writes: >> Even simpler to program in is the model used by Erlang. It's more CSP >> than threading, though, as it doesn't have shared memory as part of >> the model. But if you can use the simpler model to solve your problem >> - you probably should. > > Well, ok, the Python equivalent would be wrapping every shareable > object in its own thread, that communicates with other threads through > Queues. This is how some Pythonistas suggest writing practically all > multi-threaded Python code. It does a reasonable job of avoiding > synchronization headaches and it's not that hard to code that way. > > But I think to do it on Erlang's scale, Python needs user-level > microthreads and not just OS threads. You've just described Kamaelia* BTW, except substitute micro-thread with generator :-) (Also we call the queues outboxes and inboxes, and the combination of a generator in a class with inboxes and outboxes components) * http://kamaelia.sf.net/ For those who really want threads as well, theres a threaded component based class that uses Queues instead :) Best Regards, Michael. From frank at chagford.com Fri Aug 12 02:08:05 2005 From: frank at chagford.com (Frank Millman) Date: 11 Aug 2005 23:08:05 -0700 Subject: Buglet in win32 odbc Message-ID: <1123826885.919688.25520@g44g2000cwa.googlegroups.com> Hi all I am using win32 odbc to connect to SQL Server. I have just started using the 'bit' data type, which is a boolean type which can store 1 or 0. This works with win32, but it returns '1' or '0'. Obviously I can change it to an int, but it would be nicer and more correct if it returned an int in the first place. If Mark Hammond is listening, is it possible that this can be fixed? Thanks Frank Millman From zen19725 at zen.co.uk Tue Aug 2 02:44:28 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Tue, 2 Aug 2005 07:44:28 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: Kamaelia seems it might be an interesting project. However, I don't think the project is well served by this announcement -- which I find vague and hard to understand. Which is a shame, because it means that other people probably don't understand it very well either, which means less people will use it. In a spirit of constructive criticism I'd like to give some detailed comments about this... On Mon, 01 Aug 2005 19:50:11 +0200, Michael Sparks wrote: > >Kamaelia is a collection of Axon components designed for network >protocol experimentation in a single threaded, select based environment. >Axon components are python generators are augmented by inbox and outbox >queues (lists) for communication in a communicating sequential processes >(CSP) like fashion. I really have very little idea what this means. >The architecture is specifically designed to try and simplify the >process of designing and experimenting with new network protocols in >real environments. The information I can guess out of this is: "Kamaelia is a library for creating network protocols that sit on top of tcp and/or udp". Given that it's a BBC project, I imagine we're talking about protocols for transferring large amount of data, e.g. sound or motion pictures. >More background on the motivations behind Kamaelia >can be found here: http://kamaelia.sourceforge.net/Challenges/ There's something interesting here: In Building Public Value, the BBC has committed to the delivery of BBC content to the British Public over this multitude of systems, in a way that is enjoyable, accessible and **repurposable** by the British Public in the way they choose. (my emphasis) This is a laudable aim, but if the BBC want to do this, the first step they could make is to open up their content under a Creative Commons licence. They could start with their news, current affairs and documentaries. They could also do this with music downloads: for example a few weeks ago they made available for free download all of Beethoven's symphonies, performed by the BBC Orchestra. But the download only staryed up for a week, and they didn't put the files under a CC license, so they could be redistributed. Why not? It would have cost them no more to do so than what they did, and would've provided better value for downloaders and music lovers. Of course, the music industry would've complained, but they did anyway. Frankly, fuck them. Their business model is obsolete, and they should either get a new one or crawl into a corner and die. BTW, the html is broken in that it's very poorly written, doedsn't use CSS, and some of the stuff that is intended to display in a monospaced font doesn't. For example, this HTML code from :
def main(self):

' print 'Differences %s: %s' % (htypestr, lbl1) if html: ... This seems clunky and my next step was going to be to define generic functions which would generate the surrounding html tags only when passed the proper argument. I was wondering if there was a better way to do this with a standard Python library. It looked like formatter might but that it also might be too low-level. Any help is appreciated, Jeff From n00m at narod.ru Wed Aug 31 13:43:01 2005 From: n00m at narod.ru (n00m) Date: 31 Aug 2005 10:43:01 -0700 Subject: Sockets: code works locally but fails over LAN In-Reply-To: References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> Message-ID: <1125510181.549101.176900@f14g2000cwb.googlegroups.com> Thank you all for your replies! 1. repr() is not what I need (currently). I'd better like to see the pure text of "talkings" between VBS and SQL Server. 2. Jp, thank you very much for the links! I just oblige to test this Twisted stuff, but I'm afraid it's a bit above my head so far. And, frankly speaking, above all I'd like to understand why my code only works locally... I wish it did not work AT ALL. Sure you understand what I mean. :) From peter at engcorp.com Mon Aug 15 21:24:26 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 15 Aug 2005 21:24:26 -0400 Subject: sniffer in python In-Reply-To: References: <_XZLe.7557$zs.6719@tornado.fastwebnet.it> <0KmdncVnD80_Hp3eRVn-rw@powergate.ca> Message-ID: billiejoex wrote: > Thank you for your fast reply. You're right. I'll be more specific, sorry. > The example source is the one you can find on the 'Impacket' page on the > same site of pcapy: > http://oss.coresecurity.com/impacket/sniff.py > I use a Win XP prof sp2 system, python ver. 2.4.1. > Here's the output: > > C:\Python24>1.py > Traceback (most recent call last): > File "C:\Python24\1.py", line 107, in ? > main(filter) > File "C:\Python24\1.py", line 88, in main > dev = getInterface() > File "C:\Python24\1.py", line 81, in getInterface > print '%i - %s' % (count, iface) > File "C:\Python23\lib\encodings\cp850.py", line 18, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode characters in position > 4-19: ch > aracter maps to Helping you learn to troubleshoot from tracebacks: look at the line preceding the failing call. Can you guess anything about what in that line might be causing an encode() call? The count variable is, presumably, just an integer, so %i wouldn't like have to do more than convert it to a string. %s, however, asks for "iface" to be turned into a string... if it were not already a string (i.e. it's a unicode?) it would have to be encoded. What does iface contain and where did it come from? Can you make it be just a string? Does that change or fix anything? -Peter From rich.teer at rite-group.com Thu Aug 25 14:47:17 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Thu, 25 Aug 2005 18:47:17 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: On Thu, 25 Aug 2005, John Bokma wrote: > Just have a look at some web based message boards, and you might see why it > would be another disaster on Usenet. Moreoever, why keep people insisting > on making Usenet "better"? If you want HTML and fancy mark up, start a > message board. You probably can get even more people. Right. I avoid web based forums like the plague. Why? Because apart from the (usually) very low SNR, for me interacting with a browser is more effort than using my email/news client of 10+ years, pine. I find that fact that something is technically possible (e.g., HTML email and Usenet) is not necessarily a good argument for actully DOING it. -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From mohammed at aims.ac.za Mon Aug 22 16:14:55 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Mon, 22 Aug 2005 22:14:55 +0200 Subject: split function Message-ID: <430A323F.9090109@aims.ac.za> Dear all Sorry , I confused between two things , what i said in the last e-mail i already managed to do using C code , But what i need to do using python is : my input data : 0 2 3 4 1 2 4 2 3 3 4 what i suppose to do is , using the first line and start searching number by number ,first i have 0 search in the rest of lines if there is 0 print out the all numbers except 0 , after that , start searching using the 2ed element in the first line which is 2 , in the 2ed line we have 1 , 4 . in the 3rd line we have 3 , in the 4th line we do not have 2. And so on for 3 and 4 , and also for the 2nd , 3rd lines , so the output should be 0 2 1 4 3 3 2 4 4 1 2 3 1 2 3 4 3 2 3 3 4 And i managed to do this , but i did in the case of no space between numbers,when i am reading from file , like 0234 124 23 34 I want my code be able to deal with the space between numbers , and this is my code again def belong_to(x,a): c=-1 for i in range(len(a)-1): if x==int(a[i]): c=i return c def list_belong(x,a): # This function to check if this line c=-1 # line has been searched before or not for i in range(len(a)): if a[i]==x: c=1 break return c x=0 occur=[] in_file=open('data.dat','r') out_file=open('result.dat','w') fileList = in_file.readlines() for k in fileList: v=k occur.append(k) n=len(v)-1 for i in range(n): temp=int(v[i]) print temp, out_file.write(str(temp)) for line in fileList: if v!=line: if list_belong(line,occur)!=1: if belong_to(temp,line) != -1: j=belong_to(temp,line) for i in range(len(line)-1): if i!=j: print line[i], out_file.write(line[i]) print out_file.write("\n") out_file.close() in_file.close() Thanks From enleverlesO.OmcO at OmclaveauO.com Wed Aug 24 19:10:57 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Thu, 25 Aug 2005 01:10:57 +0200 Subject: Exploring outlook using python References: <1124911125.270274.291090@g47g2000cwa.googlegroups.com> Message-ID: <430d5d0a$0$5375$8fcfb975@news.wanadoo.fr> Hum... If it's Outlook, look for COM/Dispatch, with PyWin32 If it's Outlook-Express, search a MAPI module, like said Peter Hansen. @-salutations Michel Claveau From tjreedy at udel.edu Sat Aug 6 16:37:25 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 6 Aug 2005 16:37:25 -0400 Subject: Sample code to build rfc822 mail message building References: <20050806074530.919.qmail@web8404.mail.in.yahoo.com> Message-ID: "praba kar" wrote in message news:20050806074530.919.qmail at web8404.mail.in.yahoo.com... > I am new to python world. I have pasted my code > which I used it to build rfc822 format mails for When you start a completely new subject, you should start a new thread and not make your new-subject post a reply in an existing thread. This will be seen by people interested in complex numbers but not in mail messages (such as myself) and missed by people interested in mail formats who skip over a minor thread on a complex number function. If you don't get proper responsed, try reposting as a new thread. Terry J. Reedy From kay.schluehr at gmx.net Sun Aug 7 00:51:28 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 6 Aug 2005 21:51:28 -0700 Subject: Decline and fall of scripting languages ? References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> Message-ID: <1123390288.402485.171020@o13g2000cwo.googlegroups.com> Paul Rubin wrote: > Cliff Wells writes: > > It didn't say what they left PHP, Perl and Python for (if you are to > > even believe their findings). > > > > PHP has been losing programmers in droves... to Ruby on Rails, but I'm > > not sure how that is bad news for scripting-language fans. > > That's the second time in one or two days that I've heard Ruby on > Rails mentioned. Can anyone here post a paragraph or two description? > I sort of know what Ruby is, a very OOP-ified Perl-resemblant > language, that's also implemented only as an interpreter. I can't see > punting Python for it. Exacly. While Pythons main attitude is reducing clutter and redundant design while staying within an OO mindframe, Ruby reintroduces perlish clutter. Ruby was mentioned to be a more clean OO language than Python in times where Python didn't support inheritance from builtins. Nowadays anonymus blocks are the single most discriminative feature Ruby is praised for. Therefore Ruby seems to be more modern than Python to some people allthough it's design concept is reactionary - or "postmodern" what may be the same in post-postmodern times ;-) > Lately I'm interested in OCAML as a possible step up from Python. It > has bogosity of its own (much of it syntactic) but it has static > typing and a serious compiler, from what I understand. I don't think > I can grok it from just reading the online tutorial; I'm going to have > to code something in it, once I get a block of time available. Any > thoughts? The whole ML family ( including OCaml ) and languages like Haskell based on a Hindley-Milnor type system clearly make a difference. I would say that those languages are also cutting edge in language theory research. It should be definitely interesting to you. Since there is no single language implementation you might also find one that supports concepts you need most e.g. concurrency: http://cml.cs.uchicago.edu/ Regards, Kay From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 17 15:34:58 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 17 Aug 2005 21:34:58 +0200 Subject: Using for in one-liner In-Reply-To: <1124130122.840575.5650@g14g2000cwa.googlegroups.com> References: <3mbu82F15h18oU1@individual.net> <1124124590.563497.241560@g43g2000cwa.googlegroups.com> <4300CB9D.2020809@redlinepy.com> <1124126384.664929.313090@g43g2000cwa.googlegroups.com> <4300D3D1.6080909@redlinepy.com> <1124130122.840575.5650@g14g2000cwa.googlegroups.com> Message-ID: <3mhhr2F1734aqU1@individual.net> BranoZ wrote: > Paul Watson wrote: >> Using a '$' before the string works in the ksh that is part of FC4. >> However, it does not work on the pdksh that is in FC3 and Cygwin. It >> also does not work on AIX ksh. >> >> $ print $'now' >> $now > > In bash you can also use Ctrl-v followed by special character. > (I used to reset terminal by echo "c") > > Ctrl-v, Enter -> generate 0x0d to command-line > Crtl-v, Ctrl-m -> the same as above > Ctrl-v, Ctrl-j -> generate 0x0a (UNIX \n) > > So type: > python -c 'import sys; > then press Ctrl-v followed by Ctrl-j > and type the rest.. > > In vi it looks like ^@. At CLI it realy does a newline. > I guess, you can no longer call it an one-liner ;-) > > I'm not sure whether Ctrl-v is a bash feature. More probably > the tty driver. So, it may be worth tring it on bash-less UNIXes > (that deserve to extinct) You can as well use Enter directly on the command line, together with quotes. Reinhold From martin at v.loewis.de Fri Aug 26 04:12:15 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 26 Aug 2005 10:12:15 +0200 Subject: Setting the encoding in pysqlite2 In-Reply-To: <1125040131.767879.76840@o13g2000cwo.googlegroups.com> References: <1124957755.392563.197910@z14g2000cwz.googlegroups.com> <1125040131.767879.76840@o13g2000cwo.googlegroups.com> Message-ID: <430ecedf$0$13064$9b622d9e@news.freenet.de> Michele Simionato wrote: > Well, the issue is not how to input text in the database from Python > (it is enough to use literal unicode strings); > in my case the database has been generated from a text file containing > accented chars, using .import, > and it seems I cannot read it from Python because of the unicode error > :-( You should not do that. In SQLite 3, TEXT fields should always be UTF-8. That .import did not reject your data sounds like a bug in .import. So if you make your input data UTF-8, you should be able to fetch them easily, and receive Unicode strings. Regards, Martin From sheila at spamcop.net Sat Aug 13 01:46:54 2005 From: sheila at spamcop.net (Sheila King) Date: Sat, 13 Aug 2005 05:46:54 GMT Subject: socket setdefaulttimeout References: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> Message-ID: <8122246.VFEYWSAU@news.verizon.net> On 08/12/2005 22:37:22 Bryan Olson wrote: > Sheila King wrote: >> I'm doing DNS lookups [...] it is important to make sure that the socket >> doesn't just hang there waiting for a response. >> After a recent system upgrade to Python 2.4.1 (from 2.2.2) I thought I >> could take advantage of the setdefaulttimeout in the socket module, to >> limit the amount of time the sockets take for a lookup. >> As a test, I set the default timout ridiculously low. But it doesn't >> seem to be having any effect. > The timeout applies to network communication on that socket, but not to > calls such as socket.gethostbyname. The gethostbyname function actually > goes to the operating system, which can look up the name in a cache, or a > hosts file, or query DNS servers on sockets of its own. > Modern OS's generally have reasonably TCP/IP implementations, and the OS > will handle applying a reasonable timeout. Still gethostbyname and its > brethren can be a pain for single- threaded event-driven programs, because > they can block for significant time. > Under some older threading systems, any system call would block every > thread in the process, and gethostbyname was notorious for holding things > up. Some systems offer an asynchronous gethostbyname, but that doesn't > help users of Python's library. Some programmers would keep around a few > extra processes to handle their hosts lookups. Fortunately, threading > systems are now much better, and should only block the thread waiting for > gethostbyname. Thanks, Bryan. I'm not doing any threading. But we are running this script on incoming email as it arrives at the SMTP server, and scripts have a 16 second max time of execution. Generally they run in much less time. However, we have seen incidents where, due to issues with the DNS servers for the blacklists, that the script exceed it's max time to run and the process was killed by the OS. This results in the email being placed back into the mail queue for attempted re-delivery later. Of course, if this issue goes undetected, the mail can eventually be "returned to sender". There's no effective way to check from within the running filter script that the time is not exceeded if the gethostbyname blocks and doesn't return. :( As I said, normally this isn't a problem. But there have been a handful of incidents where it did cause issues briefly over a few days. I was hoping to address it. :/ Sounds like I'm out of luck. -- Sheila King http://www.thinkspot.net/sheila/ From lycka at carmen.se Tue Aug 16 05:10:48 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 16 Aug 2005 11:10:48 +0200 Subject: SOAP and XMLRPC In-Reply-To: References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Message-ID: phil hunt wrote: > I thought it was the whole point of XMLRPC that the server can be > written in one language and the client in another. Yes. > Am I wrong? No. That's what I said. The OP wanted to write a VB client, and I don't think this is the forum for questions about that. I can understand that he tried though. Every time I tried to find info about VB on the net, the discussions were on the "Hello World" level... From ml at dynkin.com Thu Aug 11 22:17:03 2005 From: ml at dynkin.com (George Yoshida) Date: Fri, 12 Aug 2005 11:17:03 +0900 Subject: Help sorting a list by file extension In-Reply-To: <42fbf3be.1215996460@news.oz.net> References: <42fbf3be.1215996460@news.oz.net> Message-ID: Bengt Richter wrote: >>>>[name for dec,name in sorted((int(nm.split('.')[1]),nm) for nm in namelist)] > > ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20'] Giving a key argument to sorted will make it simpler:: >>> sorted(namelist, key=lambda x:int(x.rsplit('.')[-1])) -- george From timothy at open-networks.net Tue Aug 2 01:10:23 2005 From: timothy at open-networks.net (Timothy Smith) Date: Tue, 02 Aug 2005 15:10:23 +1000 Subject: startfile problems Message-ID: <42EF003F.7080906@open-networks.net> hello i have a very odd issue with os.startfile() ok basicly my app works perfectly on every single other pc todate. i cannot recreate this issue on any system. so i've already ruled out any obvious coding issues, such as wrong file names etc. this issue only occurs on this one old pc. upon trying to os.startfile() a pdf document (that i create) i get the error - Windows error [erro2]"System cannot find the specified file" however when i go in to the program directory, the file is there, and i can open it. i have ruled out the following: the pdf viewer is working. the path and file name are correct the path and file name do not contain any spaces and what not. it's a windows xp system and i'm using python 2.3 i'm very curious as to what everyone thinks From sam at nuevageorgia.com Thu Aug 25 12:07:30 2005 From: sam at nuevageorgia.com (SamFeltus) Date: 25 Aug 2005 09:07:30 -0700 Subject: Experience regarding Python tutorials? In-Reply-To: <3n688aF2fp4U1@uni-berlin.de> References: <430de677$0$7618$ba624c82@nntp02.dk.telia.net> <3n688aF2fp4U1@uni-berlin.de> Message-ID: <1124986050.757959.307630@o13g2000cwo.googlegroups.com> Python is a very good place to start. However,Perl isn't a bad place to start either. Perl has a gazillion ways to express yourself. Perl is overly complicated (yet easy to get started with), so you are exposed to numerous ways to think. Perl gives you 8 million different sized and colored ropes to hang yourself with (google TMTOWTDI), so Perl will teach you to BE CAREFUL. The O'Reilly Perl books are excellent. From mensanator at aol.com Sun Aug 28 21:07:48 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 28 Aug 2005 18:07:48 -0700 Subject: Lossless Number Conversion In-Reply-To: References: Message-ID: <1125277668.616749.17090@o13g2000cwo.googlegroups.com> Chris Spencer wrote: > Is there any library for Python that implements a kind of universal > number object. Something that, if you divide two integers, generates a > ratio instead of a float, or if you take the square root of a negative, > generates a complex number instead of raising an exception? Lisp has > something like this, and it makes number crunching much more convenient. > > Chris The GMPY module has unlimited precision rationals: >>> from gmpy import * >>> r = mpq(1,1) # create the rational 1/1 >>> for i in range(2,50): r = r + mpq(1,i) # add the rational 1/i to the running sum print r 3/2 11/6 25/12 137/60 49/20 363/140 761/280 7129/2520 7381/2520 83711/27720 86021/27720 1145993/360360 1171733/360360 1195757/360360 2436559/720720 42142223/12252240 14274301/4084080 275295799/77597520 55835135/15519504 18858053/5173168 19093197/5173168 444316699/118982864 1347822955/356948592 34052522467/8923714800 34395742267/8923714800 312536252003/80313433200 315404588903/80313433200 9227046511387/2329089562800 9304682830147/2329089562800 290774257297357/72201776446800 586061125622639/144403552893600 So you can keep absolute precision all the way to the end of the calculation. And you can always convert it to a float by dividing the numerator by the denominator: >>> print mpf(r.numer())/mpf(r.denom()) 4.47920533832942505756047179296 From sp1d3rx at gmail.com Thu Aug 18 12:09:06 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 18 Aug 2005 09:09:06 -0700 Subject: Confused newbie needs help with "__init__() takes exactly 11 arguments (1 given)" In-Reply-To: <1124377112.427700.177790@g47g2000cwa.googlegroups.com> References: <1124377112.427700.177790@g47g2000cwa.googlegroups.com> Message-ID: <1124381346.014813.283710@g43g2000cwa.googlegroups.com> That's great, but it seems like a lot of work just to read in everything. Take a look at the sample that I did with the interpreter... First, X is a simulated input line... --- x = " param1,param2,param3,param4,param5,param6,param7,param8,param9,comments blah , blah, test" --- Ok, so just like your first example, with commas in the comments. Next, let's parse that into the variables and seperate on the commas... without using the CSV module.. --- param1, param2, param3, param4, param5, param6, param7, param8, param9, comments = x.split(',',9) --- Simply, this splits on the commas, up to 9 times. So, no need to fix your input text. Now, the output... --- f.write(param1 + " " + param2 + " " + param3 + " " + param4 + " " + param5 + " " + param6 + " " + param7 + " " + param8 + " " + param9 + " " + "\"" comments + "\"" + "\n") --- Writes the file, no commas except in the comments, and the comments are enclosed in quote marks. Also, the line ends in a CR+LF (depending on O/S). Is that something similar to what you were looking for? It doesnt look like your file is properly formatted for CSV, hence I suggest not using the CSV module. If you want to make your file CSV compatible, it should have quotation marks around the comments, as they could include commas. From tpearce at internode.on.net Mon Aug 22 07:16:01 2005 From: tpearce at internode.on.net (m7b52000) Date: Mon, 22 Aug 2005 20:46:01 +0930 Subject: passing arguments from scale widget to function In-Reply-To: References: <430828c4$1@duster.adelaide.on.net> Message-ID: <4309b3f2$1@duster.adelaide.on.net> Matt Hammond wrote: > On Sun, 21 Aug 2005 08:09:55 +0100, m7b52000 > wrote: > >> It is proving most difficult in Python. How do I pass the .get() >> values to my calculating function? Do I use the command option for >> each slider? e.g command = Calc(a.get()). Obviously not cos it >> doesn't work. > > > It should work if you wrap it as a lambda function. As it is, you're > assigning the > result of the Calc() function to the 'command' argument/parameter of > the slider widget. What you actually want is to assign just the function: > > command = lambda : Calc(a.get()) > >> I am not a real programmer and do not wish to get involved in classes >> and objects.... > > > If you're using Tcl/Tk you're already using them ... what do you think > your Slider widget is? :-) > > Hope this helps! > > regards > > > Matt Thanks, I get the following message when I use lambda as above: TypeError: () takes no arguments (1 given) any other thoughts :) Tony From grante at visi.com Wed Aug 31 09:42:25 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 31 Aug 2005 13:42:25 -0000 Subject: Sockets: code works locally but fails over LAN References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com> Message-ID: <11hbcu1guovme72@corp.supernews.com> On 2005-08-31, Peter Hansen wrote: > 2. I'm not at all sure that accessing the same socket object > simultaneously from two threads is safe. It's OK under Unix. Having one thread handle rx and a different one handle tx is a pretty widely used method. Don't know about Win32... -- Grant Edwards grante Yow! Someone in DAYTON, at Ohio is selling USED visi.com CARPETS to a SERBO-CROATIAN From mohammed at aims.ac.za Mon Aug 22 12:19:05 2005 From: mohammed at aims.ac.za (Mohammed Altaj) Date: Mon, 22 Aug 2005 18:19:05 +0200 Subject: split function Message-ID: <4309FAF9.4050400@aims.ac.za> Hi All I am reading data from file using readlines() to list , my question is how to deal with space between any two numbers , I mean , my data looks like 1 3 3 4 5 2 6 1 I tried to with my data as it, but i couldn't , so i removed the spaces 13 34 52 61 But when i deal with large number > 9 !!!! , i tried to use split function , but doesn't work , I can attach my code if its good idea to do ,, Thanks From saint.infidel at gmail.com Thu Aug 25 17:53:32 2005 From: saint.infidel at gmail.com (infidel) Date: 25 Aug 2005 14:53:32 -0700 Subject: a dummy python question In-Reply-To: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> References: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> Message-ID: <1125006812.641866.125150@g44g2000cwa.googlegroups.com> Learning Python wrote: > A example in learning Python by Mark Lutz and David Ascher > > about function scope > > example like this: > > >>def outer(x): > def inner(i): > print i, > if i: inner(i-1) > inner(x) > >>outer(3) > > Here supposely, it should report error, because the function inner > cannot see itself since inner is only in local namespace of outer. If that were so, Pythonistas could never write a recursive function! From reinout at cs.vu.nl Fri Aug 26 08:09:21 2005 From: reinout at cs.vu.nl (Reinout van Schouwen) Date: Fri, 26 Aug 2005 14:09:21 +0200 Subject: Should I move to Amsterdam? In-Reply-To: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> Message-ID: On Wed, 24 Aug 2005, Wade wrote: > Nice little series by Seth Stevenson for Americans daydreaming about > emigration. Somewhere, anywhere ... maybe Amsterdam? For a Python newsgroup, I'm surprised no one has mentioned yet that Guido van Rossum developed Python at the CWI in Amsterdam (called Stichting Mathematisch Centrum at the time). Type 'copyright' at the Python prompt some time. regards, -- Reinout van Schouwen *** student of Artifical Intelligence email: reinout at cs.vu.nl *** mobile phone: +31-6-44360778 www.vanschouwen.info *** help mee met GNOME vertalen: nl.gnome.org From notanlinesgirly2 at yahoo.com Wed Aug 17 17:04:39 2005 From: notanlinesgirly2 at yahoo.com (Lacy) Date: Wed, 17 Aug 2005 21:04:39 -0000 Subject: looking to GIVE my first oral favor Message-ID: im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me From renting at astron.nl Wed Aug 24 09:59:45 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 24 Aug 2005 15:59:45 +0200 Subject: Unix diff command under Window. Message-ID: There probably is some free version somewhere, maybe even as part of CygWin. I've used Araxis Merge on Windows. It used to be shareware. It's nice enough that I bought it. >>>"TonyHa" 08/24/05 3:50 pm >>> Hello, Does any one have using Python to write a Unix "diff" command for Window? Tony Ha. -- http://mail.python.org/mailman/listinfo/python-list From steve.horsley at gmail.com Sat Aug 27 13:33:33 2005 From: steve.horsley at gmail.com (Steve Horsley) Date: Sat, 27 Aug 2005 18:33:33 +0100 Subject: SocketServer and a Java applet listener In-Reply-To: <1124913592.821488.204350@g47g2000cwa.googlegroups.com> References: <1124913592.821488.204350@g47g2000cwa.googlegroups.com> Message-ID: google at phaedro.com wrote: > Dear newsgroup, > > I give up, I must be overseeing something terribly trivial, but I can't > get a simple (Java) applet to react to incoming (python) SocketServer > messages. > > Without boring you with the details of my code (on request available, > though), here is what I do : > > I have a TCPServer and BaseRequestHandler . > Connecting via telnet : everything goes OK. > > Connecting from Applet : > problem 1 (worked around it) : java has some 'propietary' UTF-8 format, > python's unicode doesn't seem to handle it correctly and I have to > strip the first two bytes/chars , then all goes OK . > Those 2 bytes are important! They are a string length indicator. Here are the docs that tell you that it puts a 2-byte length on the front: http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataOutputStream.html#writeUTF(java.lang.String) If you are ignoring these bytes, then how can you be sure you have received the whole string? Please don't tell me you "just hope" that the whole string will always arrive in a single read() call. There is no guarantee of that. TCP does NOT have message boundaries, and TCP packets can be both fragmented and coalesced. E.g. if you do: out.write('Steve was here") out.flush() out.write("Bilbo Baggins wasn't") out.flush() it is entirely legal for two successive read() calls to retrieve "steve was " and "hereBilbo Baggins wasn't". Although in practice, fragmentation won't normally happen until strings reach around 1500 bytes. writeUTF tries to fix the problem by telling the receive how much string to expect. > problem 2: > I have tried IMHO everything. > In the BaseRequestHandler.handle() method, I want to update a list of > clients in the server, i.e.: > > self.server.players[username] = self > > self := instance of the BaseRequestHandler, I only do this after > succesfull connect , i.e. first time socket. I assume (wrongfully?) > that I can now use the self.request socket for future transmissions to > the client. > > In the applet, I start a thread that listens to the socket by eternally > looping over: > String line = self.din.readUTF() > if (line == null) > break; > handle(line); > Probably the same problem. If you didn't send a 2 byte length indicator first, then java's readUTF() will have tried to interpret the first 2 bytes that you did actually send as the string length, and may well simply be waiting patiently for the rest to arrive. HTH Steve From http Wed Aug 31 12:37:34 2005 From: http (Paul Rubin) Date: 31 Aug 2005 09:37:34 -0700 Subject: can't start new thread References: <1125506166.505956.144570@f14g2000cwb.googlegroups.com> Message-ID: <7xirxmxdtd.fsf@ruckus.brouhaha.com> "jdonnell" writes: > This script has worked without a problem for months, but I did make > some changes recently. I don't see how those changes would cause > this error though. It's also on a VPS so it's possible that they > changed something in the OS. Does anyone have any suggestions about > possible causes of this error? Maybe some other VPS(s) under the host OS have spun enough processes or threads to make the host OS exhaust some limit. From bronger at physik.rwth-aachen.de Wed Aug 3 01:36:19 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Wed, 03 Aug 2005 07:36:19 +0200 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> Message-ID: <87d5ov8tv0.fsf@wilson.rwth-aachen.de> Hall?chen! Mike Meyer writes: > Torsten Bronger writes: > >> [...] >> >> Because such projects attract the greatest number of developers, >> many of them being amongst the most diligent developers, too. I >> expect this to have a positive influence of the language. > > You didn't answer the question about how you define agile > project. Please do so if you expect a comment on this. Projects with a high Sourceforge activity index. > [...] > >> Yes, this is what I meant with "legacy code". C and C++ are >> actually special-purpose. They are good for controlling a >> computer but not for implementing an idea. Their current >> vitality on almost all software areas arise from the fact that >> they had been extremely successful before Java, C#, and VB came >> into play. Invented today, they would be niche languages. > > This is patently absurd. C and C++ were born as general-purpose > languages. Changing the environment around them isn't going to > change that. In 1955 people would have told you that Fortran is general-purpose. It's not the case any more. > [...] > >>>> Legacy code is not a sign of success IMO because it implies a >>>> difficult future. >>> >>> So you're saying that Python, Perl, Linux, the various BSD >>> et. al. will have a difficult future? [...] >> >> No. All I said was that if a language's "success" relies almost >> exclusively on the heavy presence of legacy code, its future is >> difficult. I see this for C and C++ excluding VC++. > > Well, you lumped all C/C++ code a legacy code. No because ... > [...] > > You can't have it both ways. Either C/C++ is all legacy code, or > it's not. ... is wrong in my opinion. Why should this be? > [...] > > I think you need to come out from behind your Windows box for a > while. But you did read my headers? ;-) > There are *lots* of applications areas that don't need GUIs, > and don't run on Windows. This becomes a discussion about estimates we both don't know exactly, and weight differently, so I'll leave it here. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From news at lawshouse.org Mon Aug 29 10:03:23 2005 From: news at lawshouse.org (Henry Law) Date: Mon, 29 Aug 2005 15:03:23 +0100 Subject: Writing portable applications (Was: Jargons of Info Tech industry) References: <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> Message-ID: <6a56h1ltmkd860bmh0i6ial4c1fhm6fnaj@4ax.com> On Sat, 27 Aug 2005 14:35:05 -0400, Mike Meyer wrote: >Ulrich Hobelmann writes: >> Mike Meyer I wonder could you guys stop cross-posting this stuff to comp.lang.perl.misc? The person who started this thread - a well-known troll - saw fit to post it there, and now all your posts are going there too. -- Henry Law <>< Manchester, England From tony_ha2002 at yahoo.co.uk Wed Aug 24 09:50:04 2005 From: tony_ha2002 at yahoo.co.uk (TonyHa) Date: 24 Aug 2005 06:50:04 -0700 Subject: Unix diff command under Window. Message-ID: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> Hello, Does any one have using Python to write a Unix "diff" command for Window? Tony Ha. From irmen.NOSPAM at xs4all.nl Mon Aug 15 12:51:09 2005 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 15 Aug 2005 18:51:09 +0200 Subject: client server question In-Reply-To: References: <1123744304.897921.195450@g44g2000cwa.googlegroups.com> Message-ID: <4300c7ff$0$11065$e4fe514c@news.xs4all.nl> Robert Wierschke wrote: > John schrieb: > >> I have a simple script that runs a server where one client can connect. >> I would like to make it so that many clients can connect to one server >> on the same port. Where can I find how to do this? >> >> Thanks, >> --j >> > > use sockets. Or, if you have no interest at all in the gory details and problems of socket programming, have a look at Pyro (http://pyro.sourceforge.net). Pyro lets you invoke remote python objects as if they were just regular python objects. --Irmen From gnb at itga.com.au Tue Aug 23 02:56:30 2005 From: gnb at itga.com.au (Gregory Bond) Date: Tue, 23 Aug 2005 16:56:30 +1000 Subject: Eve from Adams' Ribs In-Reply-To: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> References: <1124771695.010789.87010@g49g2000cwa.googlegroups.com> Message-ID: <0bheed.c46.ln@lightning.itga.com.au> Godwin wrote: > But the funny fact is that i want this class to be dynamically > generated at run > time simply from a table name string. > The thing you are looking for is called an "object-relational mapper". try SQLObject http://sqlobject.org/ This is mainly intended to work the other way (i.e. describe the structure in Python and create tables from that), but it does support a "get the structure from a legacy table" mode that may be good enough (you may be in strife if your existing tables don't meet certain requirements, like having a unique integer key, or have odd column-naming schema etc). I don't think it supports Oracle (yet...) From bokr at oz.net Thu Aug 4 19:53:17 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 04 Aug 2005 23:53:17 GMT Subject: Metaclasses and class variables References: <3756d97505080406543aea76aa@mail.gmail.com> <42F2251E.4020701@rogers.com> Message-ID: <42f2a25a.605336077@news.oz.net> On Thu, 4 Aug 2005 17:53:28 +0200, Jan-Ole Esleben wrote: >Thanks! It's a bit icky, yes, but I've been so wrapped up in >complicated thinking that I didn't see this. It's actually quite an >OK solution (I need it because I have an internal representation for >method interfaces that needs to be saved somewhere without the user >having to worry about it, and without them having to set variables. >Method interfaces are class specific, and the only other thing I could >do would be to have a dictionary of classes somewhere, but as the >class itself uses its interface I can't see any really sensible way to >go about this differently). > >Ole > > >2005/8/4, Mike C. Fletcher : >> Jan-Ole Esleben wrote: >>=20 >> >Yes, that works, but it is unfortunately not an option (at least not a >> >good one). >> > >> >Is there no way to create a class variable that exists during >> >definition of the class? (I cannot imagine there isn't, since >> >technically it's possible and manually it can be done...) >> > >> >Ole >> > >> > >> The metaclass hook occurs *after* class definition, anything using a >> side-effect of a metaclass hook then, *must* occur after the execution >> of the metaclass hook. At the time you want to write classvar.append >> the "class" is only a namespace, so, if you really need this feature >> you'll need to look elsewhere for at least *part* of the solution. >>=20 >> A global "classvar" that, when appended to, caches values until your >> metaclass is called and transfers the cache to the class should *work*, >> but egads that's ugly compared to just classvar =3D [] . I guess what I'= >d >> ask is *why* is avoiding that single line so important. It could be >> there's a reasonable answer, but the amount of machinery required to >> avoid it is going to be significant. >>=20 >> class meta( type ): >> newClassVar =3D [] >> def __new__( cls, name, bases, dictionary ): >> dictionary[ 'classvar' ] =3D cls.newClassVar[:] >> del cls.newClassVar[:] >> return super( meta, cls ).__new__( cls, name, bases, dictionary ) >> __metaclass__ =3D meta >> classvar =3D meta.newClassVar >>=20 >> or something along those lines... >>=20 >> Um, ick, but HTH, >> Mike >>=20 >> -- What about using a closure variable instead of the global mentioned above? E.g., >>> def cfactory(): ... classvar = [] ... class TheClass(object): ... classvar.append(1) ... classvar.append(2) ... TheClass.classvar = classvar ... return TheClass ... >>> tc = cfactory() >>> tc >>> tc.classvar [1, 2] I'm wondering what the real problem is. If you are creating some kind of class variable that accumulates things related to methods, why can't the metaclass do the whole job after the methods have all been defined cleanly? OTOH, if not, have you considered that decorators execute a def-time of the decorated functions -- which for methods defined in class scope will be during class definition execution. E.g., you could make classvars accessible through a base class and pump into via decorators (note that you can decorate with Base.deco or bind it by itself as below) >>> class Base(object): ... classvar = [] ... @classmethod ... def deco(cls, f): ... cls.classvar.append((f.func_name, f.func_code.co_argcount)) ... >>> deco = Base.deco >>> class TheClass(Base): ... @deco ... def foo(): pass ... @Base.deco ... def bar(x, y): print 'two args:', x, y ... >>> TheClass.classvar [('foo', 0), ('bar', 2)] Incidentally, you can see that deco and classvar belong to the Base class, though accessible as instance and class attributes >>> tc = TheClass() >>> tc.classvar [('foo', 0), ('bar', 2)] >>> TheClass.mro() [, , ] >>> vars(tc) {} >>> vars(TheClass).keys() ['__module__', 'foo', 'bar', '__doc__'] >>> vars(Base).keys() ['__module__', 'deco', 'classvar', '__dict__', '__weakref__', '__doc__'] HTH. Add metaclasses and stir to taste ;-) Regards, Bengt Richter From matt.hammond at rd.bbc.co.uk Wed Aug 31 04:24:47 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Wed, 31 Aug 2005 09:24:47 +0100 Subject: Yielding a chain of values References: <4314bf65.177562962@news.oz.net> <3nk0e4F1snjcU2@individual.net> <4314e9fe.188467011@news.oz.net> <431553db.215568641@news.oz.net> Message-ID: > Well, maybe it's right both ways ;-) I.e., even though yield "is" now > an expression, it is valid to use it as an expression-statement which > evaluates the expression and discards the value. So I think you could > still use the currently illegal "yield in" token sequence to mean that > what follows is to be taken as an iterable whose full sequence is > to be yielded sequentially as if > > yield in iterable > > were sugar for > > for _ in iterable: yield _ "yield in" could make sense when thought of as an expression too. x = yield in iterable Would behave like a list comprehension. x would be assigned a list containing the results of the successive yields. Equivalent to: x = [ yield r for r in iterable ] regards Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From mail at tuxipuxi.org Fri Aug 12 09:36:07 2005 From: mail at tuxipuxi.org (Michael Goettsche) Date: Fri, 12 Aug 2005 15:36:07 +0200 Subject: Writing a small battleship game server in Python In-Reply-To: <42FB77E0.7000401@sweetapp.com> References: <200508111746.15668.mail@tuxipuxi.org> <42FB77E0.7000401@sweetapp.com> Message-ID: <200508121536.07425.mail@tuxipuxi.org> On Thursday 11 August 2005 18:08, Brian Quinlan wrote: > Michael Goettsche wrote: > > What would be a good, but still easy way to write such a server? > > You could use SimpleXMLRPCServer. A client call sequence could like this: Thanks for the example Brian. I wonder... is there a standard implementation for languages like Delphi and C++/Qt too? The server should work well with other clients. Thanks, Michael. From hongqn at gmail.com Fri Aug 12 13:43:06 2005 From: hongqn at gmail.com (Qiangning Hong) Date: Sat, 13 Aug 2005 01:43:06 +0800 Subject: How to build Python modules on windows? In-Reply-To: <42fcda84$1@news.fhg.de> References: <42fcda84$1@news.fhg.de> Message-ID: <42FCDFAA.3090107@gmail.com> ". <"@bag.python.org wrote: > Hi, > > how can I build python modules on windows? I tried to build numarray[0] > using Microsoft Visual C++ 2003 Toolkit, but got the following error: > > --- > error: Python was built with version 7.1 of Visual Studio, and > extensions need to be built with the same version of the compiler, but > it isn't installed. > --- Are you sure you have setup the environment variables before you build? Here is a reference: "Building Python Extensions with the MS Toolkit Compiler" (http://www.vrplumber.com/programming/mstoolkit/) [snip] -- Qiangning Hong I'm usually annoyed by IDEs because, for instance, they don't use VIM as an editor. Since I'm hooked to that, all IDEs I've used so far have failed to impress me. -- Sybren Stuvel @ c.l.python Get Firefox! From sp1d3rx at gmail.com Thu Aug 4 13:25:26 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 4 Aug 2005 10:25:26 -0700 Subject: listing users in Plone In-Reply-To: <1123164257.211224.66710@g14g2000cwa.googlegroups.com> References: <1123164257.211224.66710@g14g2000cwa.googlegroups.com> Message-ID: <1123176326.920163.20610@g43g2000cwa.googlegroups.com> Can't help you with #1 as I don't use Plone anymore. I prefer using plain Zope and building my site around that. There's not much that Plone adds for me, besides a skin. As for 2, I do have some experience doing that. First, create a ZSQL statement that does something like this: select * from database then, assuming you have called it 'query1' here's the ZPT you could put in that would use the results from your query (assuming your query returned columns named 'name' and 'salary').

John Doe
$500,000
P.S. This is the wrong group to post this question on. From stud0505 at yahoo.com Wed Aug 24 02:53:04 2005 From: stud0505 at yahoo.com (Layin'_Low) Date: 23 Aug 2005 23:53:04 -0700 Subject: FileIO problem Message-ID: <1124866383.975225.261840@o13g2000cwo.googlegroups.com> i'm havin a problem with this simple program. i need the output of this loop to be written to a file but i dont know how to do it!! this is what i have right now: gclas = raw_input("What is the class:") count = 0 while count != 1000: count = count + 1 print "Admin forceclass " , count , gclas i know the IO script. i tried calling it a function, but i got an error that says i cant call funtions for writing: gclas = raw_input("What is the class:") def Princlas(): count = 0 while count != 1000: count = count + 1 print "Admin forceclass " , count , gclas #asks for file name a = raw_input("What is new file name:") out_file = open(a,"w") #this is the input of text out_file.write(Princlas) out_file.close() i know i need to get it to a string but i dont know how?Any solution or help i s more that welcome From tow21 at cam.ac.uk Tue Aug 23 12:35:47 2005 From: tow21 at cam.ac.uk (Toby White) Date: Tue, 23 Aug 2005 17:35:47 +0100 Subject: Limited XML tidy Message-ID: I have a program which produces well-formed XML documents, but takes several hours if not days to do so. It would be useful to be able to take the incomplete output and manipulate it as XML. Clearly, however, the incomplete output will not be well- formed, so before being able to manipulate it I need to make it wellformed. This is essentially fairly simple. I know it's well-formed up to now - all I need to do is close unclosed tags. So, I 've made a short function that will do this: #!/usr/bin/python import sys import xml.sax tagStack = [] closingTags = "" class DodgyHandler(xml.sax.ContentHandler): def startElement(self, tag, attributes): tagStack.append(tag) def endElement(self, tag): tagStack.pop() class DodgyErrorHandler(xml.sax.ErrorHandler): def fatalError(self,exception): global closingTags tagStack.reverse() for tag in tagStack: closingTags += "" % tag return closingTags filename = sys.argv[1] p = xml.sax.make_parser() p.setContentHandler(DodgyHandler()) p.setErrorHandler(DodgyErrorHandler()) f = open(filename, mode='r') for line in f: print line, p.feed(line) p.close() print closingTags However - while this works for 90% of the cases I need, it fails in the case where my incomplete output stops in the middle of a tag (not to mention some other more arcane places I don't really care about). The problem is that when the sax handler raises an exception, I can't see how to find out why. What I want to do is for DodgyErrorHandler to do something different depending on where we are in the course of parsing. Is there anyway to get that information back from xml.sax (or indeed from any other sax handler?) Toby -- Dr. Toby White Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK Email: From carsten at uniqsys.com Thu Aug 25 11:11:00 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Thu, 25 Aug 2005 11:11:00 -0400 Subject: variable hell In-Reply-To: <1124982294.23716.51.camel@dot.uniqsys.com> References: <430dc538@127.0.0.1> <1124976866.259664.265280@g49g2000cwa.googlegroups.com> <430dd8e1@127.0.0.1> <1124982294.23716.51.camel@dot.uniqsys.com> Message-ID: <1124982660.23716.56.camel@dot.uniqsys.com> On Thu, 2005-08-25 at 11:04, I hastily wrote: > On Thu, 2005-08-25 at 10:43, Nx wrote: > > Thanks for the many replies > > > > here is an example for what it will be used for , in this case > > fixed at 31 fieldvalues: > > > > inputvalues=(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25, > > s26,s27,s28,s29,s30,s31) > > inputvalues = tuple(mylist) And actually, you probably don't have to do that, because the execute method should be able to handle a list just as well as a tuple. -Carsten. From erinhouston at gmail.com Thu Aug 18 16:24:21 2005 From: erinhouston at gmail.com (ina) Date: 18 Aug 2005 13:24:21 -0700 Subject: Put a url in a browsers address bar In-Reply-To: References: Message-ID: <1124396661.584176.229160@g47g2000cwa.googlegroups.com> Here is a start. http://www.ishpeck.net/?P=pytesting This is all stuff based on windos. Colin Gillespie wrote: > Dear All, > > I would like to place a url in my browsers address bar, then execute. > How can do this? > > e.g. > > def goToGoogle(): > url = "www.google.com" > b = openBrowser() > b.goToUrl(url) > return True > > Thanks for any help > > Colin From ex at pe.rl Sun Aug 21 00:15:31 2005 From: ex at pe.rl (ex at pe.rl) Date: Sat, 20 Aug 2005 21:15:31 -0700 Subject: Parallel port programming on windows XP / 2000 References: <1123937703.604211.296170@g14g2000cwa.googlegroups.com> Message-ID: Thank you... I finally got around to installing a proper newsreader, so that not every single one of my posts is a new thread. I know what I did wrong now. First, the line in the requirements about ""Java Communications" (JavaComm) extension for Java/Jython" seriously threw me off. Second, I somehow missed giveio_setup.exe. I did have giveio.sys, but I guess it wasn't installed or at least not properly. Anyway, now everything works... except of course the new thing that doesn't, but at least it has nothing to do with the parallel port itself. Interestingly enough, it's the 95/98 port that fails now, and the XP/2000 that works. The new problem may be something you're familiar with - the resolution of time.sleep(). On XP/2000 it's a millisecond, which is just about good enough; on 95/98 it's ten millisecond. I'll probably need to do something like run through a loop for a second or two, see how many iterations I can complete, then keep that as the basis for timing. Not really elegant, but I can't see a better way around it. From fabioz at esss.com.br Fri Aug 19 15:28:35 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Fri, 19 Aug 2005 16:28:35 -0300 Subject: [Jython-users] ANN: PyDev 0.9.7.99 released In-Reply-To: <42E6412A.4020905@esss.com.br> References: <42A720BD.5050701@esss.com.br> <42C175A5.5000206@esss.com.br> <42E6412A.4020905@esss.com.br> Message-ID: <31420118.1124480313964.JavaMail.SYSTEM@c1879626-a> Hi All, PyDev - Python IDE (Python Development Enviroment for Eclipse) version 0.9.7.99 has just been released. Check the homepage (http://pydev.sourceforge.net/) for more details. Details for Release: 0.9.7.99 OK, what's with the strange release version number?... Well, this version undergone lot's of changes, so, PyDev will be waiting on feedback about them... only after that will it become 0.9.8! Major highlights: ---------------- * PyDev has its first shot at Jython. you should be able to use many things already, meaning: all the common editor features and code completion. * The debugger is working. Others that are new and noteworthy: ------------------------------------ * Code completion has been improved for supporting wild imports and relative imports better (sometimes it had some problems). * There are hovers for the text and annotations (when you pass the mouse through an error it will show its description). * Block comment (Ctrl+4) now uses the size defined for the print margin. * New block-comment style added (Ctrl+Shift+4). * New icons were created. * wxPython completions now show. * Many other bug-fixes as usual. Note on Java 1.4 support: Currently Java 1.4 is not supported (only java 5.0), altough we will try to add support for java 1.4 before the 1.0 release. Special thanks --------------- This release would not be possible without help from: OctetString, for the financial support for making jython support possible! Aleks Totic, Scott Schlesier and Vitor Oba for the debugger patches! Eduardo A. Hoff, for the new logo and changes on the site layout! Cheers, Fabio -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ Jython-users mailing list Jython-users at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jython-users From aleaxit at gmail.com Thu Aug 18 17:40:05 2005 From: aleaxit at gmail.com (aleaxit at gmail.com) Date: 18 Aug 2005 14:40:05 -0700 Subject: up to date books? References: Message-ID: <1124401205.450291.176170@g44g2000cwa.googlegroups.com> John Salerno wrote: ... > Just one more quick question: I'm basically learning programming for > fun, and I'm concentrating on C# right now. Python seems interesting, > but I was wondering if I should even bother. Would it supplement C# in > any way, or can C# do everything Python can? C# and Python are both Turing-complete (net of limitations to finite amounts of storage, in the real world), so of course "they can do" exactly the same things as each other in some pretty strong sense -- so can machine language, Fortran, ... Exactly because of this, this is hardly ever a sensible question to ask. It clearly can be more _convenient and practical_ to "do some thing" in C# than machine language, because C# is a higher-level language than machine language, which increases your productivity (this applies to most tasks, but for a few things, such as some interrupt-response routines in embedded systems, machine language can instead be vastly more practical and productive). Similarly, Python is a higher-level language than C#, which further increases your productivity (and again this applies to most tasks, but for a few lower-level things C# may in fact be more practical and productive). Besides considerations connected to the language themselves, similar issues (pushing the same way) apply to their implementations -- Python vs C# as well as C# vs machine language. As far as I know, to deploy C# applications you need a dotNet runtime (or perhaps a Mono runtime, if you find it robust enough for your purposes); with machine language you'd be restricted to a particular family of CPUs (or emulators thereof, such as VirtualPC to emulate intel CPUs under MacOSX with PowerPC CPUs). Similarly, with Python you can deploy on the same runtimes as you can with C# (using the IronPython implementation, which compiles Python to Microsoft CLR intermediate-code) -- but alternatively you can deploy to JVMs (with the Jython implementation), to a variety of architectures and OSs using a Python-dedicated runtime/VM (with the classic, CPython implementation), to some Nokia cellphones (Series 60 ones, I believe) using the Python runtime which Nokia has developed and released, one day to the Parrot VM, etc, etc... in practice, therefore, Python pervades more niches than C#, and thus offers more practical deployment options, just like C# is more pervasive and deployable than machine language. However, I believe the language-level (and therefore programmer-productivity) issue will be even more important in most cases. Alex From caseyhHAMMER_TIME at istar.ca Wed Aug 10 22:19:00 2005 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Thu, 11 Aug 2005 02:19:00 GMT Subject: Creating Palm OS programs with python? References: Message-ID: Apparently there is a PVM (Python Virtual Machine) for the Palm OS, but it is several versions back! Jython, might be better, but it is also a few versions back! djanvk at gmail..com wrote: >QUick question: > >Is it possible to create a palm os program to use on a PDA with >python? > > >THanks -- Regards, Casey From harlinseritt at yahoo.com Wed Aug 10 07:31:47 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: 10 Aug 2005 04:31:47 -0700 Subject: Help with Regular Expressions In-Reply-To: <1123673219.653144.265270@f14g2000cwb.googlegroups.com> References: <1123657479.805511.309950@g47g2000cwa.googlegroups.com> <1123673219.653144.265270@f14g2000cwb.googlegroups.com> Message-ID: <1123673507.271664.146180@g49g2000cwa.googlegroups.com> Forgive another question here, but what is the 'r' for when used with expression: r'\w+...' ? From mwm at mired.org Thu Aug 18 22:47:28 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 18 Aug 2005 22:47:28 -0400 Subject: time.clock() problem under linux (precision=0.01s) References: <1124363238.556661.164270@g14g2000cwa.googlegroups.com> Message-ID: <86wtmid4n3.fsf@bhuda.mired.org> "Szabolcs Nagy" writes: > time.time seems much better solution, but python manual sais: "not all > systems provide time with a better precision than 1 second" > > Should i use time.clock or time.time to be more crossplatform? > Is time.time ok for windows? (time()-time() != 0.0) You should use the timeit module, which chooses the correct timer to use for the platform it's running on, as well as working around a number of other things that trip up people trying to benchmark code. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From renting at astron.nl Fri Aug 5 10:06:51 2005 From: renting at astron.nl (Adriaan Renting) Date: Fri, 05 Aug 2005 16:06:51 +0200 Subject: Filtering terminal commands on linux Message-ID: Thank you very much for you answer. We are using gear for a couple of reasons, the most improtant being that we use it in a production environment and it's the only package with commercial support under Linux that supports Dual Layer DVDs. (at least according to the person that made the decision to use it) We've had trouble in the past with cdrecord/dvdrecord. _I am_ using the batch mode, but still need to be able to parse the interactive output, as it will stop and try to communicate with the user, if it encounters a problem. It's batch mode isn't more sophisticated as "gear < batchfile". Adriaan Renting | Email: renting at astron.nl ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands | Web: http://www.astron.nl/~renting/ >>> "Lonnie Princehouse" 07/29/05 9:38 PM >>> >Firstly, there's probably a better way to do whatever you're >trying to >do w.r.t cd/dvd burning. I'm not familiar with gear, but its >webpage >lists "Batch file scripting capability" as a feature, which >suggests >that you might be able to do what you want without parsing >output >intended for humans. There are also a multitude of >command-line cd and >dvd utilities for Linux which might be better for scripting. > >That said, it shouldn't be too hard to craft a regular >expression that >matches ANSI control sequences. Using >http://www.dee.ufcg.edu.br/~rrbrandt/tools/ansi.html as a >reference, >here's how to do this for the first few control sequences... > >esc = '\x1B' >start_control_sequence = esc + '[' > >Pn = r'\d+' # Numeric parameter >Ps = '%s(;%s)*' % (Pn,Pn) # Selective parameter >PL = Pn >Pc = Pn > >control_sequences = [ > PL + ';' + Pc + '[Hf]', # Cursor position > Pn + '[ABCD]', # Cursor >up|down|forward|backward > 's', # Save cursor position > 'u', # Restore cursor position > '2J', # Erase display > 'K', # Erase line > Ps + 'm', # Set graphics mode > '=' + Pn + '[hl]', # Set|Reset mode > # ... etc >] > >match_ansi = re.compile(start_control_sequence + > '(' + '|'.join(control_sequences) + ')') > >def strip_ansi(text): > return match_ansi.sub('',text) > > >(note: code is untested.. may contain typos) -- http://mail.python.org/mailman/listinfo/python-list From jasondrew72 at gmail.com Mon Aug 1 14:02:08 2005 From: jasondrew72 at gmail.com (Jason Drew) Date: 1 Aug 2005 11:02:08 -0700 Subject: Hiding In-Reply-To: References: <1122659823.104154.135640@g43g2000cwa.googlegroups.com> <1122662993.207041.89630@f14g2000cwb.googlegroups.com> Message-ID: <1122919328.265250.296530@g49g2000cwa.googlegroups.com> Ah, good point, thanks. Must stop forgetting that "C:\file.txt" is bad. The whole open()/file() clairification is useful too. The Python docs for the file() constructor simply state that, "File objects ... can be created with the built-in constructor file() described in section 2.1, 'Built-in Functions.'" (http://python.org/doc/2.4.1/lib/bltin-file-objects.html) That's followed by a footnote that states, "file() is new in Python 2.2. The older built-in open() is an alias for file()." At first sight, that to me suggests that open() has been somewhat deprecated by file(). However, the description of many of the file methods on the same page refers to opening files using open(), e.g.: "mode: The I/O mode for the file. If the file was created using the open() built-in function, this will be the value of the mode parameter." It all becomes relatively clear in section 2.1, "Built-in Functions" where the entry for file() states, "The file() constructor is new in Python 2.2 and is an alias for open(). Both spellings are equivalent. The intent is for open() to continue to be preferred for use as a factory function which returns a new file object. The spelling, file is more suited to type testing (for example, writing 'isinstance(f, file)')." I guess that clears it up. Though perhaps the Python doc for the file() constructor should add that open() is the preferred general-purpose way to open a file or file-like object? Thanks again From kay.schluehr at gmx.net Wed Aug 31 10:13:26 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 Aug 2005 07:13:26 -0700 Subject: Infinity syntax. Re: Bug in string.find; was... In-Reply-To: <43156165.219034725@news.oz.net> References: <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> <43156165.219034725@news.oz.net> Message-ID: <1125497606.359002.131900@g14g2000cwa.googlegroups.com> Bengt Richter wrote: > How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ? > That would give a consitent interpretation of seq[-1] and no errors > for any value ;-) Cool, indexing becomes cyclic by default ;) But maybe it's better to define it explicitely: seq[!i] = seq[i%len(seq)] Well, I don't like the latter definition very much because it introduces special syntax for __getitem__. A better solution may be the introduction of new syntax and arithmetics for positive and negative infinite values. Sequencing has to be adapted to handle them. The semantics follows that creating of limits of divergent sequences: !0 = lim n n->infinity That enables consistent arithmetics: !0+k = lim n+k -> !0 n->infinity !0/k = lim n/k -> !0 for k>0, n->infinity -!0 for k<0 ZeroDevisionError for k==0 etc. In Python notation: >>> !0 !0 >>> !0+1 !0 >>> !0>n # if n is int True >>> !0/!0 Traceback (...) ... UndefinedValue >>> !0 - !0 Traceback (...) ... UndefinedValue >>> -!0 -!0 >>> range(9)[4:!0] == range(9)[4:] True >>> range(9)[4:-!0:-1] == range(5) True Life can be simpler with unbound limits. Kay From zarnovican at gmail.com Tue Aug 16 11:42:50 2005 From: zarnovican at gmail.com (BranoZ) Date: 16 Aug 2005 08:42:50 -0700 Subject: extending: new type instance Message-ID: <1124206969.965729.290240@g43g2000cwa.googlegroups.com> I'm writing my own (list-like) type in C. It is implementing a Sequence Protocol. In 'sq_slice' method I would like to return a new instance of my class/type. How do I create (and initialize) an instance of a given PyTypeObject MyType ? I have tried to provide (PyObject *)&MyType as 'class' argument to: PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw) It failed the PyClass_Check. I have also found a couple of PyObject_New functions which accept PyTypeObject as an argument. They look very low-level and obviously don't call __init__. Should I do it myself manualy ? BranoZ From no at spam Mon Aug 22 11:49:21 2005 From: no at spam (D H) Date: Mon, 22 Aug 2005 10:49:21 -0500 Subject: loop in python In-Reply-To: References: Message-ID: km wrote: > Hi all, > > Why is it that the implementation of empty loop so slow in python when compared to perl ? > > #i did this in python (v 1.5) > for x in xrange(1000): > print x > # this took 0.017 seconds > -------------------------- > #similar code in perl (v 5.6): > for $x (0..1000) > { > print $x; > } > # this took 0.005 seconds only !!! > > Is python runtime slow at all aspects when compared to perl ? > I really wonder what makes python slower than perl ? Yeah but the python version took 2.1 less seconds to type. Python runs as fast as Perl. From jforcier at strozllc.com Sun Aug 21 20:01:13 2005 From: jforcier at strozllc.com (Jeffrey E. Forcier) Date: 21 Aug 2005 17:01:13 -0700 Subject: Decorator and Metaclasses Documentation In-Reply-To: References: Message-ID: <1124668873.380249.119630@f14g2000cwb.googlegroups.com> Amusingly, I was just perusing these links earlier today. Go go Firefox history search! http://www.python.org/2.2/descrintro.html http://users.rcn.com/python/download/Descriptor.htm From fakeaddress at nowhere.org Wed Aug 10 20:00:32 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 11 Aug 2005 00:00:32 GMT Subject: wxPython and threads again In-Reply-To: References: <1123683323.056092.92800@o13g2000cwo.googlegroups.com> Message-ID: Peter Hansen wrote: > David E. Konerding DSD staff wrote: >> Further, calling wx from a thread other than the one running the >> event loop is deep voodoo and should typically be avoided. > > "Typically"? Let's just say "always" and maybe use the phrase "certain > to corrupt wx and crash the app" instead of "deep voodoo". :-) At least > that way the OP won't waste time experimenting... Come to think of it, wouldn't it be a good idea for a GUI toolkit to to do something like: import thread # ... def WhateverToolKitInitFunction(*args): global _thread_of_record _thread_of_record = thread.get_ident() # ... def check_thread(): if thread.get_ident() != _thread_of_record: raise RuntimeError('Attempt to update GUI from foreign thread.') And then begin each non-thread-safe function like: def SomeUpdateFunction(*args): check_thread() # ... [...] > Even simpler for some purposes is wx.CallAfter(), Ah, Nice. Same method under the hood, but hides the complexity. -- --Bryan From u.hobelmann at web.de Tue Aug 30 07:02:27 2005 From: u.hobelmann at web.de (Ulrich Hobelmann) Date: Tue, 30 Aug 2005 13:02:27 +0200 Subject: Writing portable applications In-Reply-To: <86r7cc9olv.fsf@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <86acj4w627.fsf@bhuda.mired.org> <3napq7Fl7hrU1@individual.net> <86acj3ut2e.fsf_-_@bhuda.mired.org> <3ndociF11gd3U1@individual.net> <86acj1y8mr.fsf@bhuda.mired.org> <3nfu55F19ui5U1@individual.net> <86r7cc9olv.fsf@bhuda.mired.org> Message-ID: <3nism4F1mljqU1@individual.net> Mike Meyer wrote: > If your web apps are well-written, any of them should work. As > previously stated, Sturgeon's law applies to the web, so chances are > good they aren't well-written. :) >> But as soon as some user of platform 54 tries your website, she'll >> encounter some weird behavior without even knowing why. And maybe so >> will you, especially if you don't have that platform there for >> testing. I don't understand how this web thing changes anything... > > The only difference is that the user of Platform 54 has a chance to > use your app. Sure, it may not work because that platforms bugs are > radically different from the bugs in the platforms you tested > on. Raising the possibility of your app working from "no way in hell" > to "maybe" is significant. Ok, there's a chance... >> With POSIX at least you have a real bug-report for the guy responsible >> for it. If a platform keeps being buggy, with no fixes coming, screw >> them. Every user will see that sooner or later, and these platforms >> die. Even Windows is quite stable/reliable after 10+ years NT! > > You do? All your porters reliably give you bug reports? Can I have > some? No, I mean, when you compile something on POSIX and it doesn't work, you have a bug to report. Of course many vendors might ignore them, and often don't send you any feedback at all (unfortunately), probably because contact between the company's programmer and you is considered bad for some reason (I'd consider it good support). > These don't answer the question. Maybe because I didn't explain it > fully. Do you have an example of an application that implements a > simple protocol along with a client and server where HTTP+HTML were > considered as an alternative, and rejected as "more difficult" than > the path actually chosen? No, because I don't know who considered HTTP+HTML before going the other way. HTTP certainly is used increasingly (for XML transfers, WebDAV, RSS, ...), because it's quite simple widely implemented. But as I said, there's RSS as a new standard, there's DAV and others. They don't use HTML, because custom protocols can be easy but have advantages. I guess it differs. Some applications make a lot of sense in a hypertext context; others don't. >> There's NNTP. There's RSS. There's Atom. The latter two emerged >> quite painlessly, even though you could maybe use some website for >> what they provide. But this way you have lots of clients for lots of >> platforms already. > > NNTP predates HTTP. Atom (and I assume RSS) uses HTTP as a transport, > so there's no new protocol invovled - just a new file format. Yes. I consider HTML a kind of protocol in that sense, though. It's a format, and it needs interpretation, too. >> Sure, but you can tell your customers that unfortunately their system >> vendor refuses to fix a bug and ask THEM to ask that vendor. Boy, >> will they consider another platform in the future, where bugs do get >> fixed ;) > > Yup. You and that platform vendor are no win the set of vendors that > don't fix bugs. Personally, I'd rather provide a workaround and keep > the customer. Short-term definitely. Long-term I'd try to migrate the customer (depending on how much influence I have in their IT context). >>> Not all platforms are POSIX. If you're ok limiting your application >>> to >>> a small subset of the total number of platforms available, then >>> there's no advantage to using web technologies. Some of us aren't >>> satisifed with that, though. >> Sure. You have to look where your users are. Chances are that with >> obscure systems they can't use most web-apps either. > > Right. Chances are they can only use well-written ones. If you write > those, your stuff will stand out for them. Very good point. You give me back my faith in web-apps ;) >> That's true, though I think the future of development lies in >> overcoming that program-code-as-text thing (NOT visual programming, >> just tool-based, structured). Smalltalk did it decades ago. > > Last time I looked at smalltalk, it still presented program code as > text. So I think you need to clarify what you mean. You have class and method browsers, while most Java and C code is still edited file-wise (though with options to hide methods except for their declaration header). I think it makes sense to ignore the file thing and just use browsers like that (kind of like having every C function in one file, but with the headers and visibility of functions managed by your IDE/build system, not by you by hand. >>> You don't have to guess - finding examples of XUL isn't hard at all. I >>> think XML gets used in a lot of places where it isn't appropriate. One >>> of the few places where it is appropriate is where you want a file >>> format that lots of independent implementations are going to be >>> reading. This could well be one of those times. >> Maybe, but for applications that aren't predominantly concerned about >> text, I'd really rather use a structured data type (like >> s-expressions), not text markup like XML. For hypertext, XHTML is >> fine, though, if a bit verbose. > > I'd rather use something which has a formal mechanism for defining > what legal documents are. XML provides DTDs. If you really want > S-expressions, we could use an SGML DTD that let you write them, and > get the best of both worlds. Well, sometimes, sure. But quite often I think people don't bother with DTDs anyway (and of course you could design a DTD format for sexps and write a validator; I'd even guess there exists at least one somewhere out there). Lots of customers will probably ask for XML, so that mostly the way to go. -- My ideal for the future is to develop a filesystem remote interface (a la Plan 9) and then have it implemented across the Internet as the standard rather than HTML. That would be ultimate cool. Ken Thompson From enleverlesO.OmcO at OmclaveauO.com Fri Aug 26 16:20:07 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Fri, 26 Aug 2005 22:20:07 +0200 Subject: Any projects to provide Javascript-style client-side browser accessvia Python? References: Message-ID: <430f79ae$0$27407$8fcfb975@news.wanadoo.fr> Hi ! >>> So anyone know if there are projects underway on this? Yes, I work on this way. But it's a long work, because I have few time... But there are certainly other projects. @-salutations Michel Claveau From sjmaster at gmail.com Sat Aug 20 15:48:26 2005 From: sjmaster at gmail.com (Steve M) Date: 20 Aug 2005 12:48:26 -0700 Subject: Binary Trees in Python In-Reply-To: References: Message-ID: <1124567306.363069.243310@o13g2000cwo.googlegroups.com> [diegueus9] Diego Andr?s Sanabria wrote: > Hello!!! > > I want know if python have binary trees and more? You might be interested that ZODB comes with some B-tree implementations. They can be used alone or you can persist them in the ZODB quite easily. http://www.zope.org/Wikis/ZODB/FrontPage From jeremy at emperorlinux.com Tue Aug 9 21:15:17 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Tue, 09 Aug 2005 21:15:17 -0400 Subject: Module Extension C/CPI Question Message-ID: <1123636517.6746.10.camel@localhost.localdomain> Just a quick question before I waste time doing something that will immediately be disregarded as unacceptable code... :) When using the C API and writing extension modules, how do you normally pass a structure up into the python module? For instance, if I have a structure: typedef struct Foo { int x; int y; int z; char xyz[100]; } Foo; Is there an "accepted" way of propagating this upstream? I was thinking one of these two: 1. Returning a enormous tuple of the struct's members using Py_BuildValue("(iiis)", f.x, f.y, f.z, f.xyz) which would later be converted to a similar object in Python for clients of my module to use. 2. Creating a PyObject and calling PyObject_SetAttrString(O, "x", Py_BuildValue("i", f.x)) for each member, finally returning a generic PyObject using the "O" flag in BuildValue. Option 1 I "know" is possible; 2 I haven't tried. The object is substantially larger and more complicated than what I used here as an example, so Option 2 would require a bit more work. However, I'd be more than glad to do it if the community sees it as being a cleaner solution. Or, perhaps, there's even a better way? I'm getting more and more experienced with the Python/C API, so I don't need a walk-through or anything. :) Just an experienced recommendation... From mvanaswegen at gmail.com Wed Aug 24 05:10:27 2005 From: mvanaswegen at gmail.com (vpr) Date: 24 Aug 2005 02:10:27 -0700 Subject: slip beta code released Message-ID: <1124874627.194019.282930@g47g2000cwa.googlegroups.com> Hi All Just released the code from my little excusion in socket coding with Python. I still need many pointers esp wrt. the way I hacked wx into the code. Comments welcomed. Quick start ----------- start up the service: slip.py -s all hosts running slip will be discovered, to see who else is around: slip.py -l debug view: slip.py -la to send files: slip.py c:\mp3\alphavi* bob to send a message slip.py -m bob "catch this" if you use windows you can add an explorer extention by creating a link to: slip.exe -sendto and adding it to your sendto directory. if you use explorer you can now "sendto" and a wx window will popup asking you which peer to send it to. http://prdownloads.sourceforge.net/slip-p2p/slip_beta_0.3.zip?download Regards Marinus comments ? mvanaswegen at gmail.com From peter at engcorp.com Tue Aug 16 09:31:11 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 16 Aug 2005 09:31:11 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: Antoon Pardon wrote: > Why has one made a difference in search policy for finding a > variable based on whether the variable is rebound or not > in the first place. Do you really not understand the reason, or do you simply disagree with it? It's a choice with rational thought behind it. Whether it's the best choice is a matter of opinion. -Peter From adsheehan at eircom.net Mon Aug 29 11:28:26 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 29 Aug 2005 08:28:26 -0700 Subject: GIL, threads and scheduling - performance cost Message-ID: <1125329306.425235.210840@f14g2000cwb.googlegroups.com> Hi all, Wondering if a GIL lock/unlock causes a re-schedule/contect swap when embedding Python in a multi-threaded C/C++ app on Unix ? If so, do I have any control or influence on this re-scheduling ? The app suffers from serious performance degradation (compared to pure c/C++) and high context switches that I suspect the GIL unlocking may be aggravating ? Thanks for any help. Alan From deets at web.de Wed Aug 17 13:51:10 2005 From: deets at web.de (Diez B. Roggisch) Date: 17 Aug 2005 10:51:10 -0700 Subject: Testing for presence of arguments In-Reply-To: <43036087$0$18639$14726298@news.sunsite.dk> References: <430353e1$0$18641$14726298@news.sunsite.dk> <1124293800.587084.302130@g43g2000cwa.googlegroups.com> <43036087$0$18639$14726298@news.sunsite.dk> Message-ID: <1124301070.837156.71040@g14g2000cwa.googlegroups.com> > I am writing some code for a measurement application (would have used > fortran 95 if a library had been available for linux-gpib, but python is a > lot friendlier than C without the irritating and utterly pointless braces) > where one of the input parameters for the GPIB command is optional, and > depending on whether it is specified at all, an entire sequence of commands > has to be sent to the GPIB bus plus some input parameters recalculated. > Further, the sequence of commands depends on the range of values of the > optional parameter. And some of these commands in turn have similar > optional arguments. I still don't see why default arguments like None won't do the trick. If The argument _can_ be some value (let's say an int) or None, you still could go for a default value like () or any other value from a different domain. > All in all, the above would have been a bunch of simple one-liners with a > simple if block if python had something like the fortran 95 present() > intrinsic, but I could not find it. Hence my query. Just because there is > no simple and direct way of doing something in a language does not mean > that the application that requires it has a design flaw. Certainly, but as certainly thinking in terms of one language while using another is prone to creating design flaws. So far you still haven't convinced me that default arguments don't work for you. To me it seems that your idiom of present() is modeld by python's if arg is None: whatever pretty mich. It might help if you show'd us what your code would like _if_ python had present() available. Then we can see what alternatives there are. > Unrelated question, how does one call a fortran 95 subroutine from python ? > I need really high speed of execution for that call (needed for each > measurement point, and is used to calculate some parameters for the > excitation for the next measurement point) and a scripting language would > not cut it. Didn't ever try that, but either do it in C, or if fortran code can be exposed as C lib, use that (ctypes is your friend). I'm not aware of a fortran binding - but I never tried to find one. Basically Python can interface with everything that can behave like C - which is the least common denominator I think, so there should be some way. Regards, Diez From mage at mage.hu Wed Aug 3 15:51:56 2005 From: mage at mage.hu (Mage) Date: Wed, 03 Aug 2005 21:51:56 +0200 Subject: pain In-Reply-To: References: Message-ID: <42F1205C.2000306@mage.hu> Michael Hoffman wrote: > >I would have used print sum(xrange(11)) myself. > This is why I love python and this list. I can't be as offtopic that you wouldn't be able to say something useful to me about python. Thank you. Mage From mwm at mired.org Tue Aug 9 22:50:18 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 9 Aug 2005 22:50:18 -0400 Subject: Recommendations for CVS systems In-Reply-To: <20050810021120.GA25296@alcyon.progiciels-bpi.ca> References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> <861x52lg10.fsf@bhuda.mired.org> <20050810021120.GA25296@alcyon.progiciels-bpi.ca> Message-ID: <17145.27498.774714.785031@bhuda.mired.org> In <20050810021120.GA25296 at alcyon.progiciels-bpi.ca>, Fran?ois Pinard typed: > [Mike Meyer] > > > [...] I generally wind up cursing at [subversion] at least once a day. > Would you accept elaborating a bit on the motivations of the cursing? > Your message says Perforce does nice things, one might fuzzily imply > that Subversion is bad or misbehaves on the same, but I do not read any > definite assertion against Subversion. Having Perforce better does not > necessarily makes Subversion bad. So my question. :-) Well, the only thing that subversion does that I'd call bad is leave turds in my development directory. I'm tired of having to tell commands to ignore .svn files. Of course, Perforce is the only source control system I know of that doesn't do this. Subversion doesn't deal as well with merges as perforce. I wouldn't say subversion is bad - but Perforce is better. In the one interfile branch I've done, subversion doesn't remember what deltas have already been applied to the branch, forcing me to work that out from the log every time I want to bring the branch up to date. I may have done the branch improperly, as I did it the first day I was using svn. But perforces branching model is file-based, so there's no way to do this wrong. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. From python at hope.cz Thu Aug 4 05:30:45 2005 From: python at hope.cz (Lad) Date: 4 Aug 2005 02:30:45 -0700 Subject: Administrative prohibition error when sending email In-Reply-To: <1123055906.120638.257680@g47g2000cwa.googlegroups.com> References: <1123055906.120638.257680@g47g2000cwa.googlegroups.com> Message-ID: <1123147845.092971.323070@g14g2000cwa.googlegroups.com> I solved the problem. The reason was uncomplete email message msg should be like this timezone = ' %+03d%02d' % (-time.timezone/3600, time.timezone%3600) MessageSubject="This is a subject" BodyMessage="This is a body" msg='From: '+fromaddr+' <'+fromaddr+'>\nTo: '+toaddrs+'<'+toaddrs+'>\nDate: '+ time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime(time.time()))+timezone+'\nSubject: '+MessageSubject+'\nReply-to: '+toaddrs+'\nX-Mailer: Microsoft Outlook Express 5.50.4133.2400\n\n'+BodyMessage From python at hope.cz Fri Aug 12 11:20:08 2005 From: python at hope.cz (Lad) Date: 12 Aug 2005 08:20:08 -0700 Subject: Where can be a problem? In-Reply-To: References: <1123827773.392501.155760@z14g2000cwz.googlegroups.com> <1123853944.966310.23340@g49g2000cwa.googlegroups.com> Message-ID: <1123860008.011665.85420@g47g2000cwa.googlegroups.com> Thank you Peter for help. The reason why it did not work was the fact that findall function required CRLF among lines From greg at puyo.cjb.net Mon Aug 22 05:26:44 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 22 Aug 2005 02:26:44 -0700 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <1124702804.589011.257970@o13g2000cwo.googlegroups.com> The 2nd option has real potential for me. Although the total amount of code is greater, it factors out some complexity away from the actual job, so that code is not obscured by unnecessary compexity. IMHO that's great practice. I like it! Thank you! The assurance that the code was clear was good too - that is also what I need to hear (decisively dismissing the quest for something shorter and punchier will make me happy as much as succeeding in it). I'll read all the other suggestions first though. From steve at holdenweb.com Wed Aug 17 06:01:42 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Aug 2005 11:01:42 +0100 Subject: Gadfly use (Newby) In-Reply-To: References: <1124190108.482249.33400@f14g2000cwb.googlegroups.com> Message-ID: Fredrik Lundh wrote: > "niko" wrote: > >>while using gadfly, got an error that i don't understand. >>Code is as follow : >> cursor = connection.cursor() >> cursor.execute('select id_m from mots where nom_m = "%s"' % nom_m) >> id_m = cursor.fetchall() >> >>Error message : >>File "C:\Python24\Lib\site-packages\gadfly\kjParser.py", line 567, in >>getmember >> (Token,skip) = self.LexDict.Token(self.String, self.Position) >> File "C:\Python24\Lib\site-packages\gadfly\kjParser.py", line 433, in >>Token >> raise LexTokenError, "Lexical token not found "+info >>gadfly.kjParser.LexTokenError: Lexical token not found near :: >>' where nom_m = '*'"Ancient s Pled' >> >>Stored value seems to interfere with somethong ? Am i wrong ? Did i >>missed something ? Thanks in advance for any help. > > > the "%" operator does the substitution *before* the execute method is > called. > > maybe you meant > > >> cursor.execute('select id_m from mots where nom_m = %s', nom_m) > > > ? > > > > > I suspect he actually meant cursor.execute("select id_m from mots where nom_m = '%s'" % nom_m) or perhaps cursor.execute("select id_m from mots where nom_m = %s", (nom_m, )) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sjmachin at lexicon.net Tue Aug 16 20:14:49 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 17 Aug 2005 10:14:49 +1000 Subject: List copying idiom was Re: [Python-Dev] implementation of copy standard lib In-Reply-To: References: <1124059680.11612.9.camel@localhost.localdomain> Message-ID: <43028179$1@news.eftel.com> Tom Anderson wrote: > > When you say [:], do you mean that you copy lists like this: > > l = someList() > m = [] > m[:] = l > > ? Why not m = L[:] instead of m = []; m[:] = L ??? > > That's what i've been doing. The other day, i realised that i could just > do: > > l = someList() > m = list(l) > > The same works for copying dicts. Whilst it's still not utterly obvious > that what this is about is making a copy, it's more obvious, cleaner, > shorter and probably faster than the slice assignment, which is really > kludgy (almost intercalorific, in fact - or even perlish!). From apardon at forel.vub.ac.be Tue Aug 23 08:06:05 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 Aug 2005 12:06:05 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> <430b0f50$0$10086$626a14ce@news.free.fr> Message-ID: Op 2005-08-23, rafi schreef : > Antoon Pardon wrote: > >> In that case you wouldn't return an empty sequence if you wanted >> a false value in a sequence context but would throw an exception. >> So this would be fine by me, I just don't understand how this >> would support the use of empty sequences as false. >> >> I also don't see how a read from a network connection returning >> either: >> >> a bytestring when data is available, >> '' when no data is available >> None when the connection was closed > > I do not get why returning '' when no data is available? If no data is > available then nothing is returned, the function hangs. (Which is the > cas for receive) Network connections can be configured to either block or return immediatly when no data is available. -- Antoon Pardon From rkern at ucsd.edu Mon Aug 1 05:39:42 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 01 Aug 2005 02:39:42 -0700 Subject: Operator Overloading In-Reply-To: <20050801051247.10135.qmail@webmail29.rediffmail.com> References: <20050801051247.10135.qmail@webmail29.rediffmail.com> Message-ID: Gurpreet Sachdeva wrote: > > Hi, > > Is there any provision in python which allows me to make my own operators? > > My problem is that I need to combine two dictonaries with their keys and > I don't want to use any of the existing operators like '+','-','*'. > So is there a way I can make '**' or '~' as my operators to add two > dictonaries? If not which all operators can I overoad? Both ** and ~ are existing operators (although ~ is unary, not binary). You cannot make new ones, but you can overload all of the available ones for new classes (not old ones like dicts). http://docs.python.org/ref/numeric-types.html With a beautiful hack, you can make your own general, pseudo-operators. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 -- 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 roccomoretti at hotpop.com Tue Aug 9 11:39:29 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Tue, 09 Aug 2005 10:39:29 -0500 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: Christopher Subich wrote: > Gregory Pi?ero wrote: > >> Hey guys, would someone mind giving me a quick rundown of how >> references work in Python when passing arguments into functions? The >> code below should highlight my specific confusion: This URL is always tossed out: http://starship.python.net/crew/mwh/hacks/objectthink.html > All arguments are passed by reference, but in Python equality rebinds > the name. Bingo >> Why does my list variable get changed for the rest of the program, but >> my boolean variable doesn't. What am I not understanding? Booleans are immutable, lists are mutable. You change (mutate) the same list, but you are referencing a different (immutable) Bool > In Python, "x = y" has a very definite meaning of "y is assigned to the > name of x." Change it to "the object referenced by y is assigned to the name of x", and you're closer to the truth. From mjekl at iol.pt Tue Aug 2 09:46:54 2005 From: mjekl at iol.pt (mjekl) Date: 2 Aug 2005 06:46:54 -0700 Subject: JBUS and Python which way Message-ID: <1122990414.662555.116450@g43g2000cwa.googlegroups.com> Hi, I'm a newbie without a technical background making some technology research for a company I work for. My aim is to have an idea of the alternatives technologies for accessing information produced by a machine with a JBUS interface (RS232) and how to access this information realtime in Python (connecting a PC locally via serial port). I'm aware of pyserial but I wonder if there is a library/module that takes care of accessing/interpreting JBUS protocol. I've searched for this without results. I also searched the net looking for some information so that I could have a birds-eye-view on this subject and got the impression that a possibility is to have the communication (JBUS protocol / buffering) managed by some hardware component. Is this so? Can some-one give me some pointers/resources on this subject. Would it still be possible to work with Python. Hope this makes any sense. All help appretiatted. Txs, Miguel From mekstran at scl.ameslab.gov Mon Aug 29 12:44:50 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Mon, 29 Aug 2005 11:44:50 -0500 Subject: python xml DOM? pulldom? SAX? In-Reply-To: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> References: <1125328624.021348.91610@o13g2000cwo.googlegroups.com> Message-ID: <20050829114450.3f7d95ee.mekstran@scl.ameslab.gov> On 29 Aug 2005 08:17:04 -0700 "jog" wrote: > I want to get text out of some nodes of a huge xml file (1,5 GB). The > architecture of the xml file is something like this > [structure snipped] > I want to combine the text out of page:title and page:revision:text > for every single page element. One by one I want to index these > combined texts (so for each page one index) > What is the most efficient API for that?: SAX ( I don?t thonk so) DOM > or pulldom? Definitely SAX IMHO, or xml.parsers.expat. For what you're doing, an event-driven interface is ideal. DOM parses the *entire* XML tree into memory at once, before you can do anything - highly inefficient for a large data set like this. I've never used pulldom, it might have potential, but from my (limited and flawed) understanding of it, I think it may also wind up loading most of the file into memory by the time you're done. SAX will not build any memory structures other than the ones you explicitly create (SAX is commonly used to build DOM trees). With SAX, you can just watch for any tags of interest (and perhaps some surrounding tags to provide context), extract the desired data, and all that very efficiently. It took me a bit to get the hang of SAX, but once I did, I haven't looked back. Event-driven parsing is a brilliant solution to this problem domain. > Or should I just use Xpath somehow. XPath usually requires a DOM tree on which it can operate. The Python XPath implementation (in PyXML) requires DOM objects. I see this as being a highly inefficient solution. Another potential solution, if the data file has extraneous information: run the source file through an XSLT transform that strips it down to only the data you need, and then apply SAX to parse it. - Michael From rkern at ucsd.edu Sat Aug 6 07:11:20 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 04:11:20 -0700 Subject: Installing/Using SWIG for python again In-Reply-To: <20050806110352.96861.qmail@web51508.mail.yahoo.com> References: <20050806110352.96861.qmail@web51508.mail.yahoo.com> Message-ID: Jerry He wrote: > Ok, I managed to get rid of the weird Tcl_Append, and > strlen error messages, but right now I'm left with > undefined references to what seems like Python-C API > objects. > > Does anyone know how to handle these undefined > references? Write a distutils setup.py script to do all of the compiling and linking. http://docs.python.org/dist/setup-script.html -- 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 notanlinesgirly2 at yahoo.com Fri Aug 19 17:12:19 2005 From: notanlinesgirly2 at yahoo.com (Lacy) Date: Fri, 19 Aug 2005 21:12:19 -0000 Subject: wanna stop by my homemade glory hole? Message-ID: my husband is installing an extra bathroom poolside. there is a perfect size hole (unless you have a huge cock) to stick your dick through into the adjoing room. come around the side of my house(perfect if you look like a repair man) enter into the unfisnished bathroom and I'll service you from the other side. you can leave when your done, no talking or small talk. i want to do this before the hole gets patched up. its been a huge fantasy of mine ever since I've seen a glory hole online. you can email me for a time convienient for you. im home all-day most days so my schedule is open. do you prefer a certain color of lipstick? check out my pic and email here under kallegirl26 www.no-strings-fun.net/kallegirl26 ready and waiting, me ;o) From andreas at kostyrka.org Sun Aug 14 17:11:21 2005 From: andreas at kostyrka.org (Andreas Kostyrka) Date: Sun, 14 Aug 2005 23:11:21 +0200 Subject: Parsing a log file In-Reply-To: <1124029906.297105.200680@o13g2000cwo.googlegroups.com> References: <1123966901.144060.288250@g47g2000cwa.googlegroups.com> <1124029906.297105.200680@o13g2000cwo.googlegroups.com> Message-ID: <1124053881.5321.0.camel@andi-lap> Completly untested: #!/usr/bin/env python import sys, datetime user = sys.argv[1] starttime = None for l in sys.stdin: flds = l.strip().split() datestr, timestr, prog, op, to, sname = flds month, day, year = [int(x) for x in datestr.split("-", 2)] hour, min, sec, ms = [int(x) for x in timestr.split(":")] timestamp = datetime.datetime(year, month, day, hour, min, sec) if op == 'CONNECTED': assert starttime is None starttime = timestamp elif op == 'DISCONNECTED': assert starttime is not None endtime = timestamp sql = "insert into data (start, end, user) value (%r, %r, %r);" print sql % (starttime, endtime, user) else: raise AssertationError("%r is not a valid line" % l) Am Sonntag, den 14.08.2005, 07:31 -0700 schrieb CG: > Thanks Andreas, > > In your first paragraph, you ask about incorrect input. I guess it is > possible, but without that information, my collection of the data is > useless, so I really don't know what I would do with that. > > As for the other stuff, I can hack the data in other ways, such as with > VBA and MSAccess, which I am more familiar with, but I am trying to > move to Linux and want to do it right the first time. I figure Perl is > the more common language for this kind of stuff, but I did want to try > to learn some Python while I am at it. I have started the tutorial, > but being a businessman, time is an issue, which, if I had an example > script that did a similar thing, I can learn by doing that (I am > looking for something similar now). > > I do live in a low-labor cost country, so I can hire someone to do it > for a small amount of money, but Python people are a little harder to > find. > > Thanks for the comments, > Clint > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Dies ist ein digital signierter Nachrichtenteil URL: From gsakkis at rutgers.edu Mon Aug 1 12:46:11 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 1 Aug 2005 09:46:11 -0700 Subject: Getting not derived members of a class References: Message-ID: <1122914771.387766.206260@g44g2000cwa.googlegroups.com> Franz Steinhaeusler wrote: > Is there any possibility to simply get out > the classes and baseclasses of a class? > > somfunc (y) => class A, B (where B is last). If you use "new-style" classes, i.e. classes inheriting from object, it is trivial: class X(object): pass class Y1(X): pass class Y2(X): pass class Z(Y1,Y2): pass >>> z = Z() >>> z.__class__.__mro__ (, , , , ) Old style classes don't have __mro__, so you have to write it yourself; in any case, writing old style classes in new code is discouraged. George From richard at nospam.here Sun Aug 21 06:33:03 2005 From: richard at nospam.here (Richard) Date: Sun, 21 Aug 2005 11:33:03 +0100 Subject: Embedding threaded Python in C Message-ID: <430859a8$0$17485$ed2e19e4@ptn-nntp-reader04.plus.net> I've tried embedding Python in a C app so that Threading is done in the Python side. In the simple example below, unless I uncomment the ALLOW_THREADS macros, the Python thread does nothing until the C for-loop finishes. My real-world example is a large C/Motif application - apart from scattering the ALLOW_THREADS macros everywhere (and what do you do while the Motif event loop is idling?), is there a better way to get the Python threads to run? I'm using Python-2.4 on Linux. ---------------------------------------------------------- /* app.c */ #include #include void run_worker(void) { PyObject *pmod; PyObject *pfunc; PyObject *pargs; PyObject *pres; pmod = PyImport_ImportModule("Manager"); pfunc = PyObject_GetAttrString(pmod, "run"); pargs = Py_BuildValue("()"); pres = PyEval_CallObject(pfunc, pargs); Py_DECREF(pres); Py_DECREF(pfunc); Py_DECREF(pargs); Py_DECREF(pmod); } int main(int argc, char **argv) { int i; Py_Initialize(); PyEval_InitThreads(); PySys_SetArgv(argc, argv); run_worker(); for (i=0; i<8; i++) { printf("%d main()\n", i); /*Py_BEGIN_ALLOW_THREADS*/ sleep(1); /*Py_END_ALLOW_THREADS*/ } Py_Finalize(); } ---------------------------------------------------------- # Manager.py import time from threading import Thread, currentThread class Worker(Thread): def run(self): for i in range(5): print "Worker.run() %d [%s]" % (i, currentThread().getName()) time.sleep(1) def run(): w = Worker() w.start() ---------------------------------------------------------- From jonny.longrigg at gmail.com Wed Aug 24 12:01:48 2005 From: jonny.longrigg at gmail.com (jonny.longrigg at gmail.com) Date: 24 Aug 2005 09:01:48 -0700 Subject: Default function arguments behaving badly References: <1124898044.569156.217700@g49g2000cwa.googlegroups.com> <430c9749$0$308$626a14ce@news.free.fr> Message-ID: <1124899308.578326.50100@g49g2000cwa.googlegroups.com> That works perfectly - Thanks! I'm always getting tripped up by the mutability of lists, I should really learn to look out for it more... From t.deconinck at gmail.com Thu Aug 11 06:35:02 2005 From: t.deconinck at gmail.com (Tom Deco) Date: 11 Aug 2005 03:35:02 -0700 Subject: Regular expression to match a # Message-ID: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> Hi, I'm trying to use a regular expression to match a string containing a # (basically i'm looking for #include ...) I don't seem to manage to write a regular expression that matches this. My (probably to naive) approach is: p = re.compile(r'\b#include\b) I also tried p = re.compile(r'\b\#include\b) in a futile attempt to use a backslash as escape character before the # None of the above return a match for a string like "#include ". I know a # is used for comments, hence my attempt to escape it... Any suggestion on how to get a regular expression to find a #? Thanks From tim.peters at gmail.com Tue Aug 30 19:41:50 2005 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 30 Aug 2005 19:41:50 -0400 Subject: Question about threading.Lock().aquire(waitflag) In-Reply-To: <1125444206.724537.154030@f14g2000cwb.googlegroups.com> References: <1125444206.724537.154030@f14g2000cwb.googlegroups.com> Message-ID: <1f7befae050830164156f42c88@mail.gmail.com> [ameyer2 at yahoo.com] > is treated as a boolean or as a number. > > Running on Windows, I get two different behaviors from > the following calls to acquire: > > aLock = threading.Lock() > ... > > # Thread 0 > # This one often succeeds > aLock.acquire(1) > ... > > # Thread 1 > # When this one would fail in a different thread > aLock.acquire(2) > > but the behaviors aren't what I would expect if waitflag > were a timeout value. It's a Windows bug, fixed a while ago but not yet in a released Python; here's the bug report: http://www.python.org/sf/1234979 2 _should_ have exactly the same effect as 1, but didn't on Windows. > If the argument to acquire is a true/false flag, the > behaviors for values of 1 and 2 ought to be the same. Right, that's the intent. > ... From nowayjose at noway.com Fri Aug 26 20:46:51 2005 From: nowayjose at noway.com (el chupacabra) Date: Sat, 27 Aug 2005 00:46:51 GMT Subject: Is there any module to play mp3 or wav format files? Message-ID: <%JOPe.6340$UE2.3907@tornado.socal.rr.com> Is there any module to play mp3 or wav format files? any sample code available somewhere? thanks, el chupacabra --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- From Tracy.Beck at Infineon.com Mon Aug 29 12:03:17 2005 From: Tracy.Beck at Infineon.com (T Beck) Date: 29 Aug 2005 09:03:17 -0700 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <1125064956.863140.32270@g14g2000cwa.googlegroups.com> Message-ID: <1125331397.416365.14460@g43g2000cwa.googlegroups.com> John Bokma wrote: > "T Beck" wrote: > > > [snip] > > alongside of it. The internet is a free-flowing evolving place... to > > try to protect one little segment like usenet from ever evolving is > > just ensuring it's slow death, IMHO. > > And if so, who cares? As long as people hang out on Usenet it will stay. > Does Usenet need al those extra gimmicks? To me, it would be nice if a > small set would be available. But need? No. > > The death of Usenet has been predicted for ages. And I see only more and > more groups, and maybe more and more people on it. > > As long as people who have to say something sensible keep using it, it > will stay. > I suppose I was (as many people on the internet have a bad habit of doing) being more caustic than was strictly necessary. I don't really forsee the death of usenet anytime soon, I just don't think the idea of it evolving is necessarily bad. I don't really have alot of vested interest one way or the other, to be honest, and I'm perfectly happy with the way it is. I just think it's a naive view to presume it never will change, because change is what the internet as a whole was built on. I think I'll calmly butt out now ^_^ -- T Beck From yoav_artzi at il.vio.com Sun Aug 21 03:19:49 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Sun, 21 Aug 2005 10:19:49 +0300 Subject: RE vs. SRE Message-ID: <430829de$1@news.bezeqint.net> What is the difference between the two? Which on is better to use and why? Thanks. From rkern at ucsd.edu Tue Aug 23 06:08:59 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 23 Aug 2005 03:08:59 -0700 Subject: Library and real path name In-Reply-To: <430af2d2$0$8495$5fc30a8@news.tiscali.it> References: <430af2d2$0$8495$5fc30a8@news.tiscali.it> Message-ID: Michele Petrazzo wrote: > I want to redistribute the library that I create. > I create a project, its setup.py that when launched copy all files into > the "site-packages/library" directory. And here it's all ok. > When I call my library with: > > import library > library.class() > > I want that my library know where are its real path > (site-packages/library/), because it has to load a data file present > into a subpackage directory (like site-package/library/data/file.dat), http://peak.telecommunity.com/DevCenter/PkgResources -- 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 fabioz at esss.com.br Tue Aug 30 06:50:04 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Tue, 30 Aug 2005 07:50:04 -0300 Subject: [Jython-users] Re: [Jython-dev] Parsing grammar for jython available (compatible with python 2.4) In-Reply-To: <311b5ce105082919592d4b0099@mail.gmail.com> References: <43130287.7030200@esss.com.br> <4dab5f7605082917112bbdf0a7@mail.gmail.com> <311b5ce105082919592d4b0099@mail.gmail.com> Message-ID: <431439DC.2010209@esss.com.br> Well, if you post your problems in the pydev bug-tracker, maybe those cases can be sorted out... (one area on where it is really difficult currently, is when you do code-completion and it is unable to parse your module... is this your case?) Cheers, Fabio could ildg wrote: > thanks. > pydev is very nice, I like it. > But sometimes the code completion will not work. > > On 8/30/05, *Frank Wierzbicki* > wrote: > > > The code, as well as the files for javacc and asdl (both were > changed) > are available in the pydev cvs at sourceforge, in the > org.python.pydev.parser module (the packages should be the > same jython > uses -- org.python.parser and org.python.parser.ast). > > The tests I used are available in the tests source folder > (org.python.pydev.parser.PyParserTest) > > Hey -- that's great! > Unfortunately we probably will not be able to integrate 2.4 > features in until after we get a 2.3 version stable... But I hope > you can remind us of this work (or I can remember it) when we do > get to that point. If you want to leave a strong reminder you > could submit your changes as a patch -- but I mean this as only > the gentlest of nudges since it will likely be quite a while > before we could really look at it. > > Thanks, > Frank > > > > -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From rkern at ucsd.edu Sat Aug 13 02:29:49 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 12 Aug 2005 23:29:49 -0700 Subject: Catching stderr output from graphical apps In-Reply-To: References: <1123697339.925135.161200@g47g2000cwa.googlegroups.com> <1123856626.852626.236030@g43g2000cwa.googlegroups.com> Message-ID: Christopher Subich wrote: > Bryan Olson wrote: > >>Thanks. >> >>Yeah, guess I was naive to test on Windows and expect that kind >>of process stuff to be portable. I'll be away from Linux for a >>week or so, so this will take me a while. >> >>Further bulletins as events warrant. > > If you can get a cross-platform solution, please re-annoucne it; this > sounds like a really neat module to have handy for graphical programs. Look at py.io[1]. It seems to have implemented a probably-cross-platform solution. Please check it out and let c.l.py and the py mailing list know if it works on Windows. [1] http://codespeak.net/py/current/doc/home.html -- 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 grante at visi.com Mon Aug 15 17:52:36 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 15 Aug 2005 21:52:36 -0000 Subject: GUI tookit for science and education References: Message-ID: <11g23l4mq5ftvcb@corp.supernews.com> On 2005-08-15, phil wrote: > >> >> Tkinter is the default GUI for Python, it runs on lots of platforms >> and often comes already installed (on Linux or Unix distributions). >> > > > I use Tkinter for a geometry course. I think it is fairly easy to > learn, much easier than say VB. VERY portable and pretty well > documented and very well supported on this list. > It doesn't have much math built in. For functions you have to > plot points. If you want to plot stuff, the gnuplot-py module is very easy to use. http://sourceforge.net/projects/gnuplot-py/ The one feature that I'd really like to add is the ability to plot a python function object. Currently you can plot a function specified by a string (e.g. "sin(x) * sin(x)**2"), or a sequence of data points. It would be nice to be able to pass an actual function. -- Grant Edwards grante Yow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, visi.com hubub, hubub, hubub. From bokr at oz.net Thu Aug 11 18:20:53 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 11 Aug 2005 22:20:53 GMT Subject: PEP 328, absolute/relative import References: <42fb9807.1192517609@news.oz.net> <67CdnaI0Bo4vAmbfRVn-1w@powergate.ca> Message-ID: <42fbc57b.1204153831@news.oz.net> On Thu, 11 Aug 2005 14:55:57 -0400, Peter Hansen wrote: >Bengt Richter wrote: >> Will/should an __init__.py in the current directory be required, >> to control what happens (and lessen the probability of accidental >> collision from a random working directory)? > >I don't think so. That would simply shift the possibility of mysterious >behaviour from the issue of colliding file names to the issue of whether >an __init__.py exists somewhere. Shouldn't one be allowed to treat >files in the current directory as regular Python scripts even if the >that directory contains an __init__.py so that it can be found as a >Python package *in other contexts*? > Hm. When you say "regular scripts," do you mean as in some_shell_prompt> python script.py or do you mean in an interactive session, as in >>> import script ? I think the first should be unaffected by __init__.py, but the second is slated to become an absolute import (IIUC) that will search the python path. Packages have to have __init__.py in order to be searched in dotted paths, so why shouldn't the current-working-directory-as-package-on-the-path also? IOW, the mysterious shadowing could only happen if you were mucking around in one of your path directories as cwd. An ordinary directory as cwd would not be searched first unless you gave it that priority with an __init__.py AND being there as cwd. You could do that for convenience without making it part of your normal path (except by being there as cwd, which you would only do for that project and desired shadowing effect). Then if you really wanted a one-shot override, in an un-marked-with-__init__.py directory, maybe >>> from . import script could possibly allow the cwd import without __init__.py since the cwd at interpreter startup is probably a reasonable interpretation of '.' in that case. ... just thinking out loud ;-) Regards, Bengt Richter From renting at astron.nl Wed Aug 17 11:19:16 2005 From: renting at astron.nl (Adriaan Renting) Date: Wed, 17 Aug 2005 17:19:16 +0200 Subject: GUI tookit for science and education Message-ID: Well, I don't think you want to write everything in HTML, but you can certainly have a program in Python/perl/PHP/ASP/java that outputs your user interface in HTML on one side, and maybe talks to Matlab or Root on the otherside to do the actual science/generate the images. I wouldn't advice Excel+VBA, unless it's the only thing you have. >>>"Thomas Bartkus" 08/17/05 4:50 pm >>> "Paul Rubin" wrote in message news:7xek8vsxua.fsf at ruckus.brouhaha.com... >Mateusz ?oskot writes: >>Thank you for any piece of advice in advance. > >Ask yourself why you want a GUI toolkit. Maybe you can write a web >application instead, and use a browser as the GUI. That's a lot >easier to write (just use html), and makes it trivial to run the >application and the browser on separate machines. Wow Paul! I just couldn't help zeroing on that comment. >a lot easier to write (just use html), I would have used adjectives like "clunky" and "limited" when talking about using an html in a browser app. Particularly if we are talking about high powered math/graphs as we often are in the science apps indicated in the original post. I would take MS Excel/VBA as the premier fat client prototyping tool/GUI toolkit for science & education. How would one go about replicating any of that in an HTML/browser app? How do we get to "easier to write"? >Ask yourself why you want a GUI toolkit. I just did. The answer is that I don't *think* you can do much of that with html. Then again - I was wrong once :-) -Tom From tjreedy at udel.edu Mon Aug 8 14:37:24 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 8 Aug 2005 14:37:24 -0400 Subject: Python framework References: <5bf3a41f05080809124ab203b0@mail.gmail.com> Message-ID: >what's the best python framework to create web applications? Let us try a different question: what is the best way to get help from a newsgroup? Step 1: do some research. Read throught the past postings still available on your newssource for threads on your topic. And/or, use Google's newsgroup archive and search facility to do the same. There have been lots of discussions of web application frameworks, some in the last couple of weeks. Step 2: ask a specific question that has an answer and whose answer would be useful to you. I think you could figure out the answer to the above: 'it depends'. It depends of you, your experience, and your specific task. Very helpful ;-) Terry J. Reedy From http Sun Aug 7 09:22:56 2005 From: http (Paul Rubin) Date: 07 Aug 2005 06:22:56 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> Message-ID: <7xacjtx4nj.fsf@ruckus.brouhaha.com> Peter Decker writes: > Hmmm..... Plonk. From peter at engcorp.com Thu Aug 11 14:57:58 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 11 Aug 2005 14:57:58 -0400 Subject: command line reports In-Reply-To: References: Message-ID: <67Cdnd00Bo62PWbfRVn-1w@powergate.ca> Darren Dale wrote: > Is there a module somewhere that intelligently deals with reports to the > command line? I would like to report the progress of some pretty lengthy > simulations, and currently I have the new reports written on a new line > rather rather than overwriting the previous report. You mean you want sys.stdout.write(report + '\r') instead of "print report" ? It's not really clear what you want. What's a "report" to you? -Peter From Mark.Sandler at gmail.com Wed Aug 31 22:15:36 2005 From: Mark.Sandler at gmail.com (Mark Sandler) Date: 31 Aug 2005 19:15:36 -0700 Subject: close/popen issues (bug?) Message-ID: <1125540936.791427.18970@g14g2000cwa.googlegroups.com> Hi, When i create a process using popen and then if i decide that i am not interested in keeping the process pipes anymore, and I forget the correspond variables [for example by exiting from function which called popen]. Then, if python tries to destroy pipes and get locked on pipe.close(), until the child process terminates... While this seem to follow specifications (close waits until pipes closes on the other end, and destructor calls close()), it seems like a rather weird behaviour to me: i can't release pipes until process terminates, essentially if i called popen from a function, i should either return pipes to the outer level, or should wait inside the function until the process terminates. So i was wondering if it is a bug or not? (quick search on bug reports didn't help) And if not, if there is an easy way around it...? This behaviour is consistent on both windows/linux machines. mark From tim.golden at viacom-outdoor.co.uk Thu Aug 18 08:03:47 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 18 Aug 2005 13:03:47 +0100 Subject: unsubscriptable object error Message-ID: <9A28C052FF32734DACB0A288A3533991044D21CC@vogbs009.gb.vo.local> [MCollins at seminolecountyfl.gov] > getting an unsubscriptable object error on an if else statement > db = MSSQL.connect(server,login,pwd,database) > c = db.cursor() > c.execute(mySQL) > rows = c.fetchone() > #determine recipient > if str(rows[3]) == str(rows[4]): > recipient = str(rows[0]) + " " + str(rows[1]) > else: > recipient = "test" > the above code works fine if rows[3] == rows[4]. it's when it doesn't equal that it gives the error:: > TypeError: unsubscriptable object > args = ('unsubscriptable object',) Hi, Matthew. Couple of points first: if it's possible, try to send emails in plain-text only, no HTML or Rich-Text. Makes life easier in some viewers. (And this list is gatewayed to news:comp.lang.python and to Google Groups). Also, try to screen dump the *actual* traceback, not your copy of it. Your example is self-contained so I imagine it can easily be run at the interpreter. (Which may be what you're doing). Finally, I suspect that your (slightly ill-named) "rows" is getting a None back from c.fetchone (). Consider the following example: import MSSQL # substitute your own connection info db = MSSQL.connect ("VODEV1", "", "", "EVODEV") c = db.cursor () c.execute ("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 1 = 2") # guaranteed no rows rows = c.fetchone () print rows # will display 'None' print rows[3], rows[4] # will display unsubscriptable object I realise that you say "the above code works find if rows[3] == rows[4]" but how do you know? If I've got the wrong end of the stick, can you publish a working snippet which can reproduce the error? 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 Tue Aug 23 06:31:03 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 12:31:03 +0200 Subject: loop in python References: <20050823065501.GA24558@mrna.tn.nic.in> Message-ID: Steve Holden wrote: > If you want a fast language, try Holden. I've just invented it. > Unfortunately it gets the answer to every problem wrong unless the > answer is 42, but boy it runs quickly. The code for the whole > interpreter (it's written in Python) follows: > > print 42 > > Why are you looking for a "fast language" without any regard for the > kind of problems you actually want (or need) to solve? isn't measuring speed by timing for-loops a 70's thing? I remember doing that back when I used Z80 BASIC machines (on a 3.58 MHz machine using floating point variables, each iteration took almost exactly 1 millisecond). I also remember that the compiler for my first custom language for that machine contained exactly one optimization: empty loops were replaced with plain assign- ments. everyone was mightly impressed. (for another view of Python's performance, see John Walker's floating point benchmarks: http://www.fourmilab.ch/fourmilog/archives/2005-08/000567.html from what I can tell, Python's the fastest interpreter in that test...) From greg at example.invalid Thu Aug 25 09:33:14 2005 From: greg at example.invalid (Greg Krohn) Date: Thu, 25 Aug 2005 13:33:14 GMT Subject: same menu point is activated In-Reply-To: <1124957306.899701.223010@g49g2000cwa.googlegroups.com> References: <1124957306.899701.223010@g49g2000cwa.googlegroups.com> Message-ID: OllieZ wrote: > Hi all > > Im trying to learn wxpython by some samples and Ive come across this. > After change EVT_MENU lines from > EVT_MENU(self, ID_OPEN, self.OnOpen) to > self.Bind(wx.EVT_MENU, self.OnOpen) It should be: self.Bind(wx.EVT_MENU, self.OnOpen, id=ID_OPEN) ^^^^^^^^^^ etc. -greg From grante at visi.com Thu Aug 18 14:06:33 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 18 Aug 2005 18:06:33 -0000 Subject: question about binary and serial info References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <1124386952.353027.93050@g47g2000cwa.googlegroups.com> Message-ID: <11g9jh97us7ct1e@corp.supernews.com> On 2005-08-18, nephish at xit.net wrote: >>>> import serial >>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1) >>>> a = ser.read(1) >>>> print a > ^ That's not a hex number. Hex numbers are composed of '0-9A-F' 0F48A is a hex number. ^ is not a hex number. >>>> ser.close() > >>>> type(a) > > >>>> int(a, 16) > Traceback (innermost last): > File "", line 1, in ? > ValueError: invalid literal for int(): ^ No big surprise there. We've already seen that a is bound to the string '^', and that isn't a hex number. > so i run it again the same way, only reading 4 bytes this time. It doesn't matter how many bytes you read. If what you're reading isn't a hex number, more of it still isn't a hex number. >>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1) >>>> a = ser.read(1) >>>> print a > ^A?? >>>> ser.close() > >>>> type(a) > > > > int(a, 16) > Traceback (innermost last): > File "", line 1, in ? > ValueError: invalid literal for int(): ^A?? Again, not a hex number. Hex numbers consist only of 0-9A-F. Hex numbers do not contain ^ ? or ?. > i dont understand what i am missing here. the string character > represents a hex character. No, it doesn't. "Hex" is a base-16 string representation consisting of the digits 0-9 and A-F[1]. The strings you're reading are clearing not hex, since they consist of characters other than 0-9 and A-F. You appear to be reading binary data of some sort. If you want to convert a string of 4 8-bit bytes (which is what you get when you do whatever.read(4)) integer, then you need to use the struct module. You're going to need to know whether the data are being transmitted least significant byte first or most significant byte first. http://www.python.org/doc/current/lib/module-struct.html If all you want is to convert a single character (what you get when you call whatever.read(1)), then all you need is the ord() builtin: http://www.python.org/doc/current/ref/types.html#l2h-51 [1] Unless you're got base-16 hardware (which you don't), then the native hardware representation is hex. -- Grant Edwards grante Yow! .. My pants just went at on a wild rampage through a visi.com Long Island Bowling Alley!! From njkirsch at gmail.com Wed Aug 24 15:46:44 2005 From: njkirsch at gmail.com (njkirsch at gmail.com) Date: 24 Aug 2005 12:46:44 -0700 Subject: PuLP and Mac OS X Message-ID: <1124912804.045308.75920@g43g2000cwa.googlegroups.com> Hello, I am working on a project that invovles the use of linear programming. The framework for the project has been written in Python. I recently came across PuLP http://www.jeannot.org/~js/code/index.en.html#PuLP , which creates output files to use with LP solvers. I was wondering if anyone has had experience in compiling PuLP on a machine running Mac OS X. Thanks, Nick From jonhewer at gmail.com Mon Aug 1 18:06:25 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Mon, 1 Aug 2005 23:06:25 +0100 Subject: Python IDE's In-Reply-To: References: <20050731205901.53A6E1E4005@bag.python.org> <1122915471.559698.231740@g43g2000cwa.googlegroups.com> Message-ID: I do use Vim a lot. I am currently using it for some PHP development i'm doing. I'm been using it so much recently that i keep pressing ESC and typing vi commands out of vi. But, if i use Vi, then whenever i want to test some code i have to open up python, import the necessary modules and run it - I like the idea of developing python in an IDE and just hitting a run button. Cheers Jon On 8/1/05, Caleb Hattingh wrote: > You know, for several years I was one of those people who simply ignored > posts like this about Vi/Vim because I happened to come across it once on > a sparc machine and thought it was ridiculous that I couldn't figure out > how to type a simple note. I thought that Vi (Vim) was some kind of > weird and ancient legacy program that just never caught up with the times. > > About 3 or 4 months ago, I had a truly large amount of ascii text editing > and formatting to do and in a plea for advice, I got the standard cliche > replies to try "Vim". Having nothing to lose, I gave it a shot. It took > only about two weeks before I was competent, but it was probably the > greatest time investment I have ever made. I now use Vim for any text > editing purpose, and especially python coding. > > No doubt, the majority of people who read your post will instantly ignore > it - but I know from personal experience that it would take a very special > IDE to compete with Vim for the manipulation of text (GUI design, of > course, is another story altogether). > > regards > Caleb > > > On Mon, 01 Aug 2005 18:57:51 +0200, projecktzero > wrote: > > > VIM or Emacs. I use VIM on Windows, Mac, and VMS. I'd consider it more > > of an editor than an IDE, but there are many IDE features available > > with plug ins. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From deets at nospam.web.de Sat Aug 20 11:39:59 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 20 Aug 2005 17:39:59 +0200 Subject: Version of TAR in tarfile module? TAR 1.14 or 1.15 port to Windows? In-Reply-To: <3mp0ouF17gb2qU1@individual.net> References: <3mnhu1F17b3j4U1@individual.net> <4306cf8d$0$15269$9b622d9e@news.freenet.de> <3mp0ouF17gb2qU1@individual.net> Message-ID: <3mp16gF17vuggU1@uni-berlin.de> Claudio Grondi wrote: > remember. I work in a Windows command shell > (DOS-box) and mount says: > j: on /cygdrive/j , but I don't know how to write > the entire path > "j:\o\archives\images\dump.tar", > so that the file can be found by tar.exe and > unpacked to "i:\images" . > tar.exe --extract --directory=tmp -f j:/o/archives/images/dump.tar > results in: > /usr/bin/tar: j\:/o/archives/images/dump.tar: Cannot open: Input/Output > error > telling > tar.exe --extract --directory=tmp -f /cygdrive/j/o/archives/images/dump.tar > doesn't work either. Try the cygpath-command like this: echo `cygpath c:\\some\\windows\\path` That should yield /cygdrive/c/some/windows/path Alternatively, do somethink like this mkdir -p /mnt/j mount j: /mnt/j Then /mnt/j should be the root for all files under j: HTH Diez From cjw at sympatico.ca Thu Aug 11 13:42:30 2005 From: cjw at sympatico.ca (Colin J. Williams) Date: Thu, 11 Aug 2005 13:42:30 -0400 Subject: "Ordered" dicts In-Reply-To: References: Message-ID: Delaney, Timothy (Tim) wrote: > Martin Miller wrote: > > >>To avoid continued reinvention of this wheel, I'd also vote to have >>this functionality be at least included in a standard module, if not >>built-in. > > > This has been discussed on python-dev (I proposed it actually). The > final consensus was that no such implementation would be included at > this time, as it's a pretty simple thing to implement, and there are > already several implementations in the Cookbook. > > My arguments included the fact that there were several implementations > in the Cookbook as an indication it should be included in the standard > library ... > > Thread starts here: > http://mail.python.org/pipermail/python-dev/2005-March/051915.html > > Tim Delaney I have a module "dictionaries.py" which might be of interest. The __doc__ says: ''' To provide the classes rDict (restricted dictionary), oDict (ordered according to time of entry) and sDict (sorted dictionary). oDict delivers keys or items in the order in which they were inserted. rDict has keys restricted to either those identified initially, or those added with newEntry. sDict delivers keys and items in sorted order. ''' It is available in the zip file (http://www3.sympatico.ca/cjw/PyMatrix/PyMatrix.zip) for the PyMatrix package. The zip file (176 KB) contains lots of irrelevant stuff. I would be glad to mail the dictionaries.py to anyone who is interested with the usual lack of warranty. Colin W. From deets at nospam.web.de Sat Aug 20 06:50:50 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 20 Aug 2005 12:50:50 +0200 Subject: Sandboxes In-Reply-To: References: Message-ID: <3mog8aF17j66oU1@uni-berlin.de> > Would this sufficient? Are there any drawbacks or giant gaping holes? > I'm anticipating that I'd also need to block 'exec' and 'eval' to > prevent an import from being obfuscated past the pre-parse. > > Or is this a hopeless cause? Yes. There have been numerous discussions about this, and there are so many different ways to overcome such imposed limitations - it won't work. > > Finally, either way, would anyone recommend a different script engine > that might be more suitable for what I'm trying to accomplish that I > might not have looked at. I don't need much; it needs to work with C#, > and be able to easily interact with 'published' interface. I'd also like > to leverage a "popular" language instead of something obscure. Maybe LUA? I only heard that it's well suited for such tasks. The overall question for me is: Why crippled acess at all? What do you fear your users could do that harms you or others? There are of coures valid reasons, I don't question that generally. E.g. applets and the like. So what is the actual usecase? Regards, Diez From spam.csubich+block at block.subich.spam.com Tue Aug 2 14:05:15 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 02 Aug 2005 14:05:15 -0400 Subject: 2-player game, client and server at localhost In-Reply-To: References: Message-ID: <%AOHe.6443$pp.1472@bignews1.bellsouth.net> Michael Rybak wrote: > CS> There's the key. How are you processing network input, specifically > CS> retrieving it from the socket? > > A "sock" class has a socket with 0.00001 timeout, and every time I > want anything, I call it's read_command() method until it returns > anything. read_command() and send_command() transfer user's actions in > special format so that it takes 10 bytes per transfer. So when you want player input, you explicitly halt the program until you receive it, inside a while loop? No wonder your programs aren't behaving well, then. Network processing Is Not Slow. Unless you're sending near the maximum capacity of your line, which you're obviously not[1], the slowness is architectural. [1] - The TCP packet contains at most 28 bytes of overhead, so combine that with 10 bytes of data and you're looking at 38 bytes/packet. A 33.6 modem can handle 4.2kB/sec, cut that in half for a safety margin for 2.1kB/sec. That will handle about 55 updates/second, which you shouldn't be reaching if you're "just sending updates when a player does something." Why are you messing with sockets directly, to begin with? It looks like you want an asynchronous socket interface, so that you don't explicitly loop and wait for data from the nyetwork for updates. In addition to making Julienne fries, Twisted is an excellent framework for asynchronous network IO. For a naive, non-threaded implementation, you'd schedule your update code as a timed event, and you'd define a Protocol for handling your network stuff. When you receive data, the protocl would update your application's state, and that would be picked up automagically the next time your update event ran. In a threaded implementation, you'd run your update code to a thread (DeferToThread), and your network code would post updates to a synchronous queue, read by your update code. From john at castleamber.com Fri Aug 26 08:42:56 2005 From: john at castleamber.com (John Bokma) Date: 26 Aug 2005 12:42:56 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8391F6ogbU1@individual.net> <3n8cn3Fb539U2@individual.net> Message-ID: usenet at isbd.co.uk wrote: > In comp.lang.perl.misc John Bokma wrote: >> usenet at isbd.co.uk wrote: >> >> > "NNTP and its applications" have evolved to provide a set of much more >> > sophisticated means of accessing and giving information than any forum >> > I've ever seen. >> >> Example(s). And do users need those sophisticated things? >> > Kill files there is a mod for that (at least for phpBB) > Selecting posts and threads based on a scoring system If there is no mod, one can be easily written. > A huge variety of different newsreaders allowing different users to > access the news in they way they want. Different browsers, stylesheets, themes. > I don't use all the possibilities (e.g. I don't use kill files) but I > do use a 'minority' text based newsreader because it is ideal for me. > I don't get the option of a text based forum reader - I doubt many > forums work with lynx. But have you tested it? You just blurb out random statements, based on gut feelings. Yes, phpBB works with lynx. And I doubt it's a rare exception. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From gelios at rbcmail.ru Wed Aug 10 07:35:22 2005 From: gelios at rbcmail.ru (Nodir Gulyamov) Date: Wed, 10 Aug 2005 15:35:22 +0400 Subject: MainThread blocks all others References: <42f9d4ef_2@news.isis.de> Message-ID: <42f9e68a_1@news.isis.de> Tried to rewrite using Event() just as experiment, but unfortunately MainThread will blocking all others. Code below: import threading class class1: def __init__(self): self.myEvent = threading.Event() result = doSomeJob() def increaseCounter(self): self.myEvent.set() doSomeJob(self): ##### BLOCKING HERE ### if not self.myEvent.isSet(): self.myEvent.wait() self.myEvent.clear() # ... continue... # this class subscribed to some observer which implements thread class monitor: def __init__(self, klass): #do some init self.c = klass def update(self): self.c.increaseCounter() if __name__ == "__main__": cl1 = class1() m = monitor(cl1) mo = MonitorObserver(m) Observer realized as described in Thinking in Python, Bruce Eckel http://mindview.net/Books/TIPython Does anybody have any idea? Any help will be appreciated. Thanks in advance to ALL! Best regards, /Gelios "Nodir Gulyamov" wrote in message news:42f9d4ef_2 at news.isis.de... > Hi Bryan, > Thanks for your reply. > I tried to test your solution, but it doesn't work, hence > threading.Semaphore object hasn't method to get value of semaphore. > I looked to source code of semaphore.py and find out that value is private > variable. > > Best regards, > /Gelios > > "Bryan Olson" wrote in message > news:fRaKe.3656$zr1.2646 at newssvr13.news.prodigy.com... >>I wrote: >> > Make self.counter a semaphore. Untested code: >> >> A little clean-up. Still untested: >> >> import threading >> >> class class1: >> def __init__(self): >> self.counter = threading.semaphore(0) >> result = self.doSomeJob() >> >> def increaseCounter(self): >> self.counter.release() >> >> def doSomeJob(self): >> # Busy-waiting sucks. >> # while counter != 1: >> # pass >> self.counter.acquire() >> # ... continue... >> >> >> -- >> --Bryan > > From bokr at oz.net Thu Aug 11 14:19:12 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 11 Aug 2005 18:19:12 GMT Subject: help in algorithm References: Message-ID: <42fb9533.1191793828@news.oz.net> On Wed, 10 Aug 2005 16:51:55 +0200, Paolino wrote: >I have a self organizing net which aim is clustering words. >Let's think the clustering is about their 2-grams set. >Words then are instances of this class. > >class clusterable(str): > def __abs__(self):# the set of q-grams (to be calculated only once) > return set([(self+self[0])[n:n+2] for n in range(len(self))]) > def __sub__(self,other): # the q-grams distance between 2 words > set1=abs(self) > set2=abs(other) > return len(set1|set2)-len(set1&set2) > >I'm looking for the medium of a set of words, as the word which >minimizes the sum of the distances from those words. > >Aka:sum([medium-word for word in words]) > > >Thanks for ideas, Paolino > Just wondering if this is a desired result: >>> clusterable('banana')-clusterable('bananana') 0 i.e., resulting from >>> abs(clusterable('banana'))-abs(clusterable('bananana')) set([]) >>> abs(clusterable('banana')) set(['na', 'ab', 'ba', 'an']) >>> abs(clusterable('bananana')) set(['na', 'ab', 'ba', 'an']) Regards, Bengt Richter From usenet.20.evilspam at spamgourmet.com Sun Aug 28 03:05:32 2005 From: usenet.20.evilspam at spamgourmet.com (Chris Spencer) Date: Sun, 28 Aug 2005 07:05:32 GMT Subject: Socket Troubles Message-ID: <0ndQe.259$DV.23@trndny07> I've written a simple class to manage P2P socket connections. However, whenever I try to receive data, the socket raises an exception with the error message (11, 'Resource temporarily unavailable'). My code's fairly straight-forward, with much of it right out of the Python docs, so I'm not sure what I'm doing wrong. You can see it all at http://deadbeefbabe.org/paste/1525/0 Any help is immensely appreciated. Thanks, Chris From fredrik at pythonware.com Wed Aug 31 06:42:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 12:42:07 +0200 Subject: Python doc problems example: gzip module References: <1125477977.072146.298670@g47g2000cwa.googlegroups.com> Message-ID: Peter Maas wrote: > Please feel free to insert this fucking example into the fucking docs. or use the fucking search engine. searching for "python example" and clicking the "I feel lucky" button tends to work quite well. e.g. http://www.google.com/search?q=python+gzip+example&btnI= From jdennett at acm.org Wed Aug 10 21:40:02 2005 From: jdennett at acm.org (James Dennett) Date: Wed, 10 Aug 2005 18:40:02 -0700 Subject: how to write a line in a text file In-Reply-To: References: <42E5B0F0.6020206@REMOVEMEcyber.com.au> <42E5ED91.10402@REMOVEMEcyber.com.au> Message-ID: Calvin Spealman wrote: > On 7/31/05, James Dennett wrote: > >>Peter Hansen wrote: >> >> >>>Steven D'Aprano wrote: >>> >>>Given that ZODB and PySQLite are simply Python extension modules, which >>>get bundled by your builder tool and are therefore installed >>>transparently along with your app by your installer, this is a total >>>non-issue at least with those packages. >>> >>>After all, it's not 1970 any more. ;-) >> >>Indeed; since 1970 we learned to prefer straightforward >>file formats where possible, reserving use of databases >>for structured data where the extra costs are justified. >> >>Sometime maybe databases will get better to the point >>that we don't need to distinguish so much between them >>and filesystems, but we're not there yet. Managing raw >>files, carefully, still has a place. >> >>-- James > > > Filesystems are a horrible way to organize information, and even worse > at structuring it. The mentality that there are any benefits of > low-overhead the outweigh the benefits of minimal database layers, > such as ZODB, BSD DB, and SQLite, is a large part of the reason we are > still stuck with such a mess. Those "extra costs" are so minimal, that > you wouldn't even notice them, if you hadn't convinced yourself of > their presense before performing or researching any realy benchmarks. > A simple RDBMS can be much easier to work with than any flat file > format, will likely be far faster in processing the data, and has the > benefit of years of coding making the code that actually reads and > writes your data as fast and stable as possible. Read again, and you'll note that I didn't say the costs were performance related (though in some, just some, situations the performance cost of using an RDBMS is a reason to avoid it, and in other cases an RDBMS will be faster than naive file access). The reasons for using other formats are things such as better interoperability, which extends to better future proofing, easier installations (in some situations -- note again that there are no hard and fast rules), and the fact that power users can edit the files by hand (more easily than they can tweak information in databases in many, but not all, cases). It can also (again, in some cases) be easier to port filesystem based storage between systems than to move database access code. Oh, and please don't assume that I make my decisions without measuring performance. If you store enough millions, or billions, of items, then performance is worth measuring. I've found situations where using various database engines made sense, I've found situations where flat files made more sense, and I've seen cases where either was used where the other might have been a better choice. -- James From whisper at oz.net Wed Aug 3 13:03:46 2005 From: whisper at oz.net (whisper at oz.net) Date: Wed, 03 Aug 2005 10:03:46 -0700 Subject: Secure email Message-ID: <42F0F8F2.7010908@oz.net> I need to write a .cgi that will take the content of an https GET or POST and send it securely as email to an Outlook client. I think that OpenSSL is somewhere in this, but I'm not even sure how to create the right certificate, how to use it to encrypt mail and how to install a certificate in Outlook (>= 2000). Code snippets and pointers to tutorials greatly appreciated. I've got a week to deploy this! Thanks! Dave LeBlanc Seattle, WA USA From jpopl at interia.pl Mon Aug 29 02:56:02 2005 From: jpopl at interia.pl (Jacek =?iso-8859-2?Q?Pop=B3awski?=) Date: Mon, 29 Aug 2005 06:56:02 +0000 (UTC) Subject: telnet.read_until() from telnetlib References: <1125075800.736986.28480@g43g2000cwa.googlegroups.com> Message-ID: my newsreader told me that sp1d3rx at gmail.com wrote: > Please post the minimum code necessary to duplicate the problem. It's impossible, because I am writting performance tests for big commercial project, I am trying to understand why they sometime fail. By definition of "read_until()" it should return expected data (if it doesn't wait timeout seconds). Anyway, I am trying to use "telnet.expect" now, thanks. -- Free Software - find interesting programs and change them NetHack - meet interesting creatures, kill them and eat their bodies Usenet - meet interesting people from all over the world and flame them Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net From lycka at carmen.se Mon Aug 22 04:09:03 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 22 Aug 2005 10:09:03 +0200 Subject: Sandboxes In-Reply-To: References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: 42 wrote: > Fair enough. I'm more or less ready to 'give up' on this fantasy of > python in a sandbox. I'll either use something else, or just accept the > risk. :) But is the scripting language interpreter the right place to put this? After all, any most languages would allow you to write something like an infinite loop, which might hog resources unless there is "something" outside the script that manages resources in such a way that this is not a problem. I've said this before: It's seems to me that this sandboxing should be done by the operating system. If the script runs in something like a chrooted environment, or with very restricted user permissions, it's difficult to do a lot of damage. E.g. if it runs as a user with no rights to execute, read or write files except those explicitly needed to get the scripts running, you're no worse off than if you allow the same user to log on to the machine with such limited ability. Right? Or have I missed something significant here? From siona at chiark.greenend.org.uk Tue Aug 2 09:15:41 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 02 Aug 2005 14:15:41 +0100 (BST) Subject: Dabo in 30 seconds? References: <200508010830.27322.ed@leafe.com> <1122901170.19618.296.camel@localhost.localdomain> Message-ID: James Stroud wrote: >Perhaps some of us are writing software with non-developer end-users in mind >and we kind of keep that mentality when evaluating modules our code uses. In the commercial environment I'm working in, non-developer end-users get a frozen executable. They don't know that there are eight packages not included in the standard library (including wxPython) in there, unless they go looking in the licences directory. They don't even have to install Python. Using a swarm of potentially awkward third-party modules and keeping things simple for the user are not incompatible. Of course, going back to Dabo there is the question of whether it has such a thing as a non-developer end-user. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From denis.kasak at gmail.com Thu Aug 25 10:20:14 2005 From: denis.kasak at gmail.com (Denis Kasak) Date: Thu, 25 Aug 2005 16:20:14 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <430D7366.C2126F6D@yahoo.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> Message-ID: CBFalconer wrote: > Mike Schilling wrote: >> "Mike Meyer" wrote in message >>> "Mike Schilling" writes: >>>> "l v" wrote in message >>>>> Xah Lee wrote: >>>>> >>>>>> (circa 1996), and email should be text only (anti-MIME, circa 1995), >>>>> >>>>> I think e-mail should be text only. I have both my email and >>>>> news readers set to display in plain text only. It prevents >>>>> the marketeers and spammers from obtaining feedback that my >>>>> email address is valid. A surprising amount of information >>>>> can be obtained from your computer by allowing HTML and all >>>>> of it's baggage when executing on your computer. Phishing >>>>> comes to my mind first and it works because people click the >>>>> link without looking to see where the link really takes them. >>>> >>>> A formatting-only subset of HTML would be useful for both e-mail >>>> and Usenet posts. >>> >>> Used to be people who wanted to send formatted text via email >>> would use rich text. It never really caught on. But given that >>> most of the people sending around formatted text are using >>> point-n-click GUIs to create the stuff, the main advantage of >>> HTML - that it's easy to write by hand - isn't needed. >> >> But the other advantage, that it's an existing and popular >> standard, remains. > > However, for both e-mail and news, it is totally useless. It also > interferes with the use of AsciiArt, while opening the recipient to > the dangers above. And HTML has the tendency to make e-mail and Usenet posts unnecessarily bigger, which will continue to be a bugger until broadband links become common enough. -- Denis From franz.steinhaeusler at gmx.at Thu Aug 11 07:09:08 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Thu, 11 Aug 2005 13:09:08 +0200 Subject: new python debugger References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> <1123740657.066728.39080@g43g2000cwa.googlegroups.com> Message-ID: On 10 Aug 2005 23:10:57 -0700, nir1408 at gmail.com wrote: Hello Nir, >Thanks for the compliments. > >I really believe Winpdb is not just another Python debugger, and that >it will be a real step forward in the quality of Python debuggers once >it matures. Yes, looks very promising ;) > >Also, don't worry about the .com url, it is a GPL debugger. > >Winpdb is still a BETA despite the version number which is 1.0.1 >so I will appreciate feedback on bugs, unexpected behavior, or >suggestions. >[...] Ok :) * Remember last opened files (in launch) * configurable shortcuts (I'm used to VC++ F10 step, F11 step into, Shift-F11 Step out). * As Neil suggested, Call Tips would be great (hovering over a variable). * A nice icon ;) * Ability to save Positions (Sash positions, if you drag the windows). * Possibility to close some windows (in my case, I would (most times) close "Console" and "Threads" or even better assign Shortcuts (example F4 => Toggle Threads window would be cool). * In VC++, there is also the possibility to Change a Variable with Shift-F9 (Quick Watch) and to change the program pointer with Ctrl-Shift 10. * bug: Open File (with browse it works); If I paste the filepath+name into the text field, it says "Error - File not found". I think: browse => "filename": the braces are important What do the letters in the margin mean? I saw: "L", "R" and "C". Cheers, -- Franz Steinhaeusler From kmcgann at cpi-search.com Mon Aug 29 09:42:11 2005 From: kmcgann at cpi-search.com (Kevin McGann) Date: Mon, 29 Aug 2005 09:42:11 -0400 Subject: NYC Opening Message-ID: <012b01c5ac9f$759d7c80$1300a8c0@asp0201> A major Investment Bank is searching for a strong Java or C++ developer that can build Pipes to Electronic Exchanges and ECNs. This is a new Internal Hedge Fund Business and they are looking for superb C++ or Java programmers that can enable them to go live in 1-2 months and begin trading. THIS IS AN OPPORTUNITY TO WORK IN THE BUSINESS UNIT OF A MAJOR TOP-TIERED BANK!!!!! Required Skills: -Expert Java or C++ -Extensive Multi-threading -OOA/OOD Must have Design Patterns Experience -Must have experience building Pipes/Connectivity Infrastructure/FIX -Linux, Unix, SQL/RDBMS Eventually this person will learn Stat/Arb business for Equities/FX and will get to learn about trading strategies and work closely with Quants/Prop Traders. THEY ARE LOCATED IN NEW YORK, THIS IS FULL-TIME ONLY, WILL NOT CONSIDER ANYONE FROM OUTSIDE THE US! THIS TEAM IS AN ELITE TEAM, YOU BETTER BE GOOD!!!! Also have numerous opportunities so if you program in C++ or Java send me an email or give me a call..... --------------------------------------------- Kevin M McGann Senior Technology Recruiter Continuity Partners Inc. (212) 624-9187 www.cpi-search.com kmcgann at cpi-search.com --------------------------------------------- From fakeaddress at nowhere.org Wed Aug 10 15:09:21 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 19:09:21 GMT Subject: Catching stderr output from graphical apps In-Reply-To: <1123697339.925135.161200@g47g2000cwa.googlegroups.com> References: <1123697339.925135.161200@g47g2000cwa.googlegroups.com> Message-ID: gry at ll.mit.edu wrote: > Python 2.3.3, Tkinter.__version__'$Revision: 1.177 $' > > Hmm, the error window pops up with appropriate title, but contains no > text. > I stuck an unbuffered write to a log file in ErrorPipe.write and got > only one line: Traceback (most recent call last):$ > > Any idea what's wrong? Darn. Are you on Windoze/Mac/Unix/, and what version? If you can spare the time, could you please try: import errorwindow import sys sys.stderr.write("Hello\nWorld.\n") x = 7 + nosuchvariable and tell me what happens? Thanks. -- --Bryan From http Sun Aug 21 01:37:13 2005 From: http (Paul Rubin) Date: 20 Aug 2005 22:37:13 -0700 Subject: urllib leaves sockets open? References: Message-ID: <7xek8nc0l2.fsf@ruckus.brouhaha.com> "Chris Tavares" writes: > Is this normal behavior for urllib? Is there a way to force that initial > socket closed earlier? Is there something else I need to do? I'd say open a sourceforge bug. There may be a way around it with the fancy opener methods of urllib2, but it's a bug if regular urllib opens a second socket without closing the first one. For http 1.1 it should be able to use just one socket anyway. From rspivak at nuxeo.com Fri Aug 12 01:22:13 2005 From: rspivak at nuxeo.com (Ruslan Spivak) Date: Fri, 12 Aug 2005 08:22:13 +0300 Subject: list to tuple References: <1123819543.351623.324870@f14g2000cwb.googlegroups.com> Message-ID: "zxo102" writes: > Hi, > I got several dynamic lists a1, b1, c1, .... from a python > application such as > a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, .... > > With python, I would like to reorganize them into a tuple like > > t1 = ((a1[0],b1[0],c1[0],...),(a1[1],b1[1],c1[1],...),...) > > Anybody knows how to do that. Thanks for your help. > t1 = tuple(zip(a1, b1, c1)) I don't know your requirements, so consider also izip from itertools. Ruslan From spam.csubich+block at block.subich.spam.com Fri Aug 12 17:02:24 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Fri, 12 Aug 2005 17:02:24 -0400 Subject: thread limit in python In-Reply-To: <1123859196.289006.200380@g44g2000cwa.googlegroups.com> References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> <9jTKe.85$k92.8@newssvr19.news.prodigy.com> <1123859196.289006.200380@g44g2000cwa.googlegroups.com> Message-ID: danieldsmith at gmail.com wrote: > i modified my C test program (included below) to explicitly set the > default thread stack size, and i'm still running into the same > problem. can you think of any other thing that would possibly be > limiting me? Hrm, you're on an A64, so that might very well mean you're dealing with 4MB pages. If each thread gets its own page of memory for stack space regardless of how small you've set it, then ~1k threads * 4MB ~= 4GB of virtual memory. From n.couturier at noos.fr Tue Aug 16 07:01:48 2005 From: n.couturier at noos.fr (niko) Date: 16 Aug 2005 04:01:48 -0700 Subject: Gadfly use (Newby) Message-ID: <1124190108.482249.33400@f14g2000cwb.googlegroups.com> Hello, while using gadfly, got an error that i don't understand. Code is as follow : cursor = connection.cursor() cursor.execute('select id_m from mots where nom_m = "%s"' % nom_m) id_m = cursor.fetchall() Error message : File "C:\Python24\Lib\site-packages\gadfly\kjParser.py", line 567, in getmember (Token,skip) = self.LexDict.Token(self.String, self.Position) File "C:\Python24\Lib\site-packages\gadfly\kjParser.py", line 433, in Token raise LexTokenError, "Lexical token not found "+info gadfly.kjParser.LexTokenError: Lexical token not found near :: ' where nom_m = '*'"Ancient s Pled' Stored value seems to interfere with somethong ? Am i wrong ? Did i missed something ? Thanks in advance for any help. From ampeloso at verizon.net Mon Aug 1 17:16:20 2005 From: ampeloso at verizon.net (None) Date: Mon, 01 Aug 2005 21:16:20 GMT Subject: Newer than a Newbe Message-ID: Hello, I am just starting to look into python.I have been prog with php for several years.My question is: Can/Is Python used as a web scripting language , and if so do many hosts support it? Thanks Mike From martin at v.loewis.de Tue Aug 23 17:39:35 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 23 Aug 2005 23:39:35 +0200 Subject: setlocale() in a module/extension library In-Reply-To: <873bp0pif9.fsf@mobile.repose.cx> References: <873bp0pif9.fsf@mobile.repose.cx> Message-ID: <430b9798$0$20386$9b622d9e@news.freenet.de> Damien Elmes wrote: > My question is this: it would be nice if every user of my library > didn't need to add the above two lines to their code. But on the other > hand, I'm unsure of the implications of modifying the locale from > within a module, and it doesn't seem very clean. Would calling > setlocale() from a library be a bad thing? If so, any alternative > recommendations would be greatly welcome. Because the locale is a process-wide setting, libraries have typically abstained from setting it. One of the most prominent problems is that setlocale is not thread-safe, so you need to do it before any threads are started. Another issue, of course, is that applications might break if the locale changes "in the middle" of some computation, as a side effect of using some library. Therefore, the C tradition is to indeed require applications to the the locale explicitly. Python follows that convention, and again exposes just the API, with no automatic setting of the locale (actually, there is some such setting during startup, but that is reverted before __main__ starts executing). IOW: feel free to invoke setlocale in your library. It will likely work in many cases, but may break in some. So you should atleast document that this is what your library does. Regards, Martin From jennifer_wild38 at yahoo.com Thu Aug 25 05:20:45 2005 From: jennifer_wild38 at yahoo.com (Jennifer) Date: Thu, 25 Aug 2005 09:20:45 -0000 Subject: wanna stop by my homemade glory hole? Message-ID: my husband is installing an extra bathroom poolside. there is a perfect size hole (unless you have a huge cock) to stick your dick through into the adjoing room. come around the side of my house(perfect if you look like a repair man) enter into the unfisnished bathroom and I'll service you from the other side. you can leave when your done, no talking or small talk. i want to do this before the hole gets patched up. its been a huge fantasy of mine ever since I've seen a glory hole online. you can email me for a time convienient for you. im home all-day most days so my schedule is open. do you prefer a certain color of lipstick? check out my pic and email here under kallegirl26 www.no-strings-fun.net/kallegirl26 ready and waiting, me ;o) From rebound1618 at yahoo.com Sun Aug 14 22:25:32 2005 From: rebound1618 at yahoo.com (Jerry He) Date: Sun, 14 Aug 2005 19:25:32 -0700 (PDT) Subject: distutils on Win32 using .NET Framework SDK Message-ID: <20050815022532.37810.qmail@web51503.mail.yahoo.com> Hi, I was trying to build a C++ extension on Win32 with distutils. The extension worked on Cygwin but when I tried it with the Win32-build python, it complained that I don't have .NET Framework SDK installed. But after I installed .NET Framework SDK 2.0, it still complains "error: The .NET Framework SDK needs to be installed before building extensions for Python." (I also did try restarting my computer) Does anyone know how to make the .NET Framework SDK visible to Python? thanks in advance, -Jerry __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From sigzero at gmail.com Sat Aug 13 17:15:41 2005 From: sigzero at gmail.com (sigzero at gmail.com) Date: 13 Aug 2005 14:15:41 -0700 Subject: Spaces and tabs again In-Reply-To: References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> Message-ID: <1123967741.407389.283930@g49g2000cwa.googlegroups.com> That is rediculous. If that happens...Python comes of my list of languages to use. Are they going to mandate 4 spaces as well? Robert From cito at online.de Tue Aug 2 15:26:28 2005 From: cito at online.de (Christoph Zwerschke) Date: Tue, 02 Aug 2005 21:26:28 +0200 Subject: Art of Unit Testing In-Reply-To: <87mzo0s25q.fsf@lucien.dreaming> References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: Bj?rn Lindstr?m wrote: >>Would it make sense to add "globaleSetup" and "globalTearDown" methods >>to the TestCase class? > In general that's not such a good idea. I completely agree and I think it makes a lot of sense that unittest calls setUp and tearDown for every single test. However, the fact that this is *generally* the best way doesn't exclude the fact that there are *exceptions* when it makes sense to setUp and tearDown not for every test, e.g. when it is absolutely sure that the fixture cannot be destroyed by the individual tests or when creating the fixture takes too much time. I already gave the example of creating database connections or even creating/importing whole databases. My question was, how do I handle these cases with the standard lib unittest? According to the "extreme programming" paradigm, testing should be done several times a day. So a requirement for extreme programm is that tests are fast enough. If the testing needs too much time, people are discouraged to test often. -- Christoph From sjmaster at gmail.com Wed Aug 17 11:31:31 2005 From: sjmaster at gmail.com (Steve M) Date: 17 Aug 2005 08:31:31 -0700 Subject: Iterparse and ElementTree confusion In-Reply-To: <1124269934.194818.51940@f14g2000cwb.googlegroups.com> References: <1124269934.194818.51940@f14g2000cwb.googlegroups.com> Message-ID: <1124292691.211252.30490@g14g2000cwa.googlegroups.com> "when i attempted [to load 150MB xml file] my PC goes to lala land, theres much HDD grinding followed by "windows runnign low on virtual memory" popup after 10-15mins. Then just more grinding...for an hour before i gave up" I have had great success using SAX to parse large XML files. If you use care your memory use will peak at a low number no matter how much XML you chew through. From db3l at fitlinxx.com Fri Aug 12 16:12:15 2005 From: db3l at fitlinxx.com (David Bolen) Date: 12 Aug 2005 16:12:15 -0400 Subject: Bug on Python2.3.4 [FreeBSD]? References: Message-ID: Uwe Mayer writes: > AFAICT there seems to be a bug on FreeBSD's Python 2.3.4 open function. The > documentation states: > > > Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' > > truncates the file). Append 'b' to the mode to open the file in binary > > mode, on systems that differentiate between binary and text files (else it > > is ignored). If the file cannot be opened, IOError is raised. > > Consider: > > $ cat test > lalala > > $ python2.3 > Python 2.3.4 (#2, Jan 4 2005, 04:42:43) > [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 > Type "help", "copyright", "credits" or "license" for more information. > >>> f = open('test', 'r+') > >>> f.read() > 'lalala\n' > >>> f.write('testing') > >>> f.close() > >>> > [1]+ Stopped python2.3 > $ cat test > lalala > > -> write did not work; ok Strange, I tried this with Python 2.3.3 and 2.3.5 on two FreeBSD 4.10 systems and it seemed to append to the file properly in both cases. Going back further, it also worked with Python 2.2.2 on a FreeBSD 4.7 system. I don't see happen to have a 2.3.4 installation, but can't see any changes to the source for the file object between 2.3.4 and 2.3.5, for example. ~> python Python 2.3.5 (#2, May 5 2005, 11:11:17) [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> f = open('test','r+') >>> f.read() 'lalala\n' >>> f.write('testing') >>> f.close() >>> ~> cat test lalala testing # no newline was present Which version of FreeBSD are you running? I thought it might be a dependency on needing to seek between reads and writes on a duplex stream (which is ANSI), but FreeBSD doesn't require that, at least back as far as a 4.7 system I have, and I assume much earlier than that. One dumb question - are you absolutely sure it wasn't appending? As written, there's no trailing newline on the file, so your final "cat test" would produce output where the "testing" was on the same line as your next command prompt, and can sometimes be missed visually. > Can anyone confirm that? Is there any other way of opening a file for > appending instead of a+? Well, if you really just want appending, I'd just use "a". It creates the file if necessary but always appends to the end. Of course, it's not set up for reading, but you wouldn't need that for appending. -- David From __peter__ at web.de Tue Aug 2 02:19:01 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2005 08:19:01 +0200 Subject: doctest bug with nested triple quotes References: <1122957696.085082.293440@o13g2000cwo.googlegroups.com> Message-ID: Michele Simionato wrote: > I am getting trouble with nested triple quoted strings in doctest. > For instance > > $ cat x.py > """ >>>> dummy = ''' > something > here > ''' > """ > import doctest; doctest.testmod() > > $ python x.py > > ********************************************************************** > File "x.py", line 2, in __main__ > Failed example: > dummy = ''' > Exception raised: > Traceback (most recent call last): > File "/usr/lib/python2.4/doctest.py", line 1243, in __run > compileflags, 1) in test.globs > File "", line 1 > dummy = ''' > ^ > SyntaxError: EOF while scanning triple-quoted string > ********************************************************************** > > Is this a know bug? Any workaround? Thanks for comments, I think it is your bug. All lines but the first must be prefixed with sys.PS2. Just add some dots to make it work: ''' >>> dummy = """ ... something ... here ... """ ''' import doctest; doctest.testmod() Peter From python at rcn.com Fri Aug 26 15:20:40 2005 From: python at rcn.com (Raymond Hettinger) Date: 26 Aug 2005 12:20:40 -0700 Subject: Why does min(A,B) behave different for lists and for classes? References: <3n95grFfp1fU2@individual.net> Message-ID: <1125084040.571865.154920@o13g2000cwo.googlegroups.com> Claudio Grondi wrote: > Is there any deeper reason I don't understand > explaining why does min(A,B) behave different > for classes than for lists? Yes, the sort order for lists is determined by their contents. With your example, the lists have identical contents, so min() returns the first minimum value encountered which is A for min(A,B) and B for min(B,A). For instances, the sort order is determined by custom __cmp__ or rich comparision methods. In the absence of those, the default ordering is determined by the object's id. In your example, the default is used and either object may be returned as the minimum depending on which object id is a higher number (that is an implementation and state dependent). Since the two objects have unique ids, min() will consistently find one to be lower than the other irrespective of argument order, if min(A,B) is A, then min(B,A) will also be A. The best way to develop your understanding here is view the object ids for the instances and experiment with the results of A References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> Message-ID: On Thu, 25 Aug 2005, Ulrich Hobelmann wrote: > CSS sheet. If things were that way, suddenly people *would* use Outlook No no no! Let's keep those Outhouse lusers away from Usenet. There's tto much top posting as it is! -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From EP at zomething.com Mon Aug 8 04:51:04 2005 From: EP at zomething.com (EP) Date: Mon, 8 Aug 2005 00:51:04 -0800 Subject: Python -- (just) a successful experiment? In-Reply-To: References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> Message-ID: <20050808005104.862503556.EP@zomething.com> Robert Kern wrote: > Which is exactly why I said at the beginning that people shouldn't > bother with this thread and should instead just get to work. > Robert, you are probably right, but I think how we get to work is important as well. What I posted was a little intellectually thin, but it would be nice to stir the collective energy toward some common (and useful) objectives. I think that something more than a superior language specification is required for a language to get a firm foothold in the IT world (and that is something I would personally like for Python.) It seems there are people very capable and willing to develop the good applications/tools/frameworks on top of Python, but too many of those projects do not gain critical mass; rather we have dozens of competing applications and frameworks that never blossom to their full potential. I'd love to see a little consensus on what "goodies" should be developed atop the language; what standards, principles, and API/hooks those goodies should provide; and then a collaborative effort to get there. Projects with a broader buy-in have a greater chance of achieving their potential. It does seem that perhaps some ground was gained with the WSGI effort. I understand Django [http://www.djangoproject.com/], a RoR alternative based on the WSGI spec, already has some buzz though "the cat got out of the bag a bit early" and Django is "not officially launched just yet." It makes sense to ask one's fellow developers and Python users what a new open source development should look and act like if one wants to develop something great. Open source code denotes sharing, but we should add teamwork and community involvement in the code as connotations if we want our open source to reach its potential. What are the top 5 developments, aside from specification and implementation details of the language itself, which Python still needs for greater success in the day to day IT world? EriPy pyDerson P.S. In terms of a more concrete suggestion, I propose the Python community form an intervention team who are ready to fly in and intercede any time a developer, whose brilliance has been expended in their heroic coding effort, goes to name their new module, package, or application with a "py" other than to the right of the dot. From benji at benjiyork.com Mon Aug 8 17:10:17 2005 From: benji at benjiyork.com (Benji York) Date: Mon, 08 Aug 2005 17:10:17 -0400 Subject: python for microcontrollers In-Reply-To: <42f7c8d4$1@news.orcon.net.nz> References: <42f7c8d4$1@news.orcon.net.nz> Message-ID: <42F7CA39.2050009@benjiyork.com> Evil Bastard wrote: > I'm currently tackling the problem of implementing a python to assembler > compiler for PIC 18Fxxx microcontrollers Perhaps porting Pyrex would be easier. Pyrex takes a python-like syntax (plus type information, etc.) and emits C, which is then compiled. -- Benji York From smitty_one_each at bigfoot.com Wed Aug 24 13:33:14 2005 From: smitty_one_each at bigfoot.com (Chris Smith) Date: Wed, 24 Aug 2005 13:33:14 -0400 Subject: Decorator and Metaclasses Documentation References: <1124692969.769378.36690@g43g2000cwa.googlegroups.com> Message-ID: <87wtmb6y05.fsf@bigfoot.com> >>>>> "Michele" == Michele Simionato writes: Michele> There are also my lectures at Oxford: Michele> http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_wondersofpython.zip Michele> Michele Simionato You really need to get O'Reilly to publish your stuff. -Chris From fakeaddress at nowhere.org Thu Aug 11 21:54:13 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 12 Aug 2005 01:54:13 GMT Subject: thread limit in python In-Reply-To: <1123787369.191604.237120@o13g2000cwo.googlegroups.com> References: <1123779143.910870.154760@g47g2000cwa.googlegroups.com> <1123786825.344176.93620@g14g2000cwa.googlegroups.com> <1123787369.191604.237120@o13g2000cwo.googlegroups.com> Message-ID: <9jTKe.85$k92.8@newssvr19.news.prodigy.com> danieldsmith at gmail.com wrote: > disregard the C example. wasn't checking the return code of > pthread_create. the C program breaks in the same place, when creating > the 1021st thread. So that's pretty good evidence that it's an OS limit, not a Python limit. The most likely problem is that the stack size is too large, so you're running out of virtual address space. -- --Bryan From aisaac0 at verizon.net Sun Aug 14 14:39:23 2005 From: aisaac0 at verizon.net (David Isaac) Date: Sun, 14 Aug 2005 18:39:23 GMT Subject: Permutation Generator References: Message-ID: "Casey Hawthorne" wrote in message news:s13vf1l9enq2el0kkpbikcmp3m9bvkaqav at 4ax.com... > It's hard to make "complete" permutation generators, Knuth has a whole > fascicle on it - "The Art of Computer Programming - Volume 4 Fascicle > 2 - Generating All Tuples and Permutations" - 2005 Can you elaborate a bit on what you mean? Given a list of unique elements, it is easy enough to produce a complete permutation generator in Python, in the sense that it yields every possible permuation. (See my previous post.) So you must mean something else? Cheers, Alan Isaac PS If the elements are not unique, that is easy enough to deal with too, as long as you say what you want the outcome to be. From nothingcanfulfill at gmail.com Thu Aug 18 21:08:37 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 18 Aug 2005 18:08:37 -0700 Subject: Module Name Conflicts In-Reply-To: <1124410215.293331.188720@g47g2000cwa.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> <1124408324.310617.198340@z14g2000cwz.googlegroups.com> <1124410215.293331.188720@g47g2000cwa.googlegroups.com> Message-ID: <1124413717.903542.131010@g44g2000cwa.googlegroups.com> I'm honestly not too sure how __import__ works, but I know you can provide a full path to it. Oh well, that was my best guess. I wish I could've been of more help. -Wes From noreply at gcgroup.net Fri Aug 12 11:35:37 2005 From: noreply at gcgroup.net (William Gill) Date: Fri, 12 Aug 2005 15:35:37 GMT Subject: problem extending tkSimpleDialog.Dialog Message-ID: I have created a widget that extends Frame() and contains labels, checkboxes, and entrys. I am trying to use tkSimpleDialog.Dialog to create a modal display of this widget, but am running into some (addressing) problems. My widget displays in the parent widget, not the tkSimpleDialog.Dialog? I hope this snippet is enough to help, as my actual code is really too hard to follow. class showtestWidget(tkSimpleDialog.Dialog): def body(self,master): Label(master,text="showPhoneNums").grid() testWidget(self).grid() class testWidget(Frame): def __init__(self, master): Frame.__init__(self) self.createWidgets() def createWidgets(self): Label(self,text="testWidget").grid() When the parent script instantiates showtestWidget() it should create a transient dialog containing a label with the text "showPhoneNums". It does, but the label containing the text "testWidget" is being created in the parent widget, not the dialog. It seems obvious to me that I'm addressing the wrong parent somehow, since the label (probably the testWidget) is being created, but in the wrong place. I tried changing testWidget(self).grid() to testWidget(master).grid(), just to see if that helped, but it made no difference. Can someone show me where I went wrong? Bill From sklass at pointcircle.com Thu Aug 4 11:50:55 2005 From: sklass at pointcircle.com (rh0dium) Date: 4 Aug 2005 08:50:55 -0700 Subject: Mass importing of a template based system.. Trouble with name substitutions In-Reply-To: References: <1123123110.255400.145060@g44g2000cwa.googlegroups.com> Message-ID: <1123170655.614433.219100@f14g2000cwb.googlegroups.com> Peter Otten wrote: > rh0dium wrote: > > > for mod in modules: > > a = mod.mod() > > a.run() > > Puzzle: If mod.mod did what you expect, what would a.run have to do to > maintain consistency? I thought that once a = example.example the class is then loaded. Since my framework defines a python file with a class named the same within it. So example1.py contains a class example1 and a module run example2.py contains a class example2 and a module run example3.py contains a class example3 and a module run Additional methods that must be present within the class include a run method. Since this was by definition I knew I needed to do a substitution - namely mod.mod ( which was intended to be translated to example1.example1 ). What you provided was very slick indeed. I no longer am dependant upon the naming to get the job done. Very nice - How does this work if some fool calls one class the same as the other. I'm assuming the last class will be loaded - not the first. > There would be no way to determine the name of the module bound to the mod > variable, but fortunately the Python developers foresaw your problem and > stashed it (the name) in the __name__ attribute. > Use getattr(obj, attrname) to look up an attribute whose name is not known > at compile time: OUTSTANDING!! Thanks so much! > > for mod in modules: > a = getattr(mod, mod.__name__)() > a.run() > > Peter From zen19725 at zen.co.uk Wed Aug 10 15:39:03 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 10 Aug 2005 20:39:03 +0100 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <1123697696.506898.66580@z14g2000cwz.googlegroups.com> Message-ID: On 10 Aug 2005 12:01:01 -0700, Qopit wrote: >> Why not just find out, by trying to compile it? :-) > >This will likely certify me as a python newbie, but... how do you mean? > How do you compile a .py file? At the command prompt: $ python yourfile.py This compiles it, then runs it. >If you mean to .pyc by doing an import on it, Indeed so. > that may work fine for >the simple example I typed up earlier, but that is easy to bypass by >slapping the offending line in a function. The sample below also >passes PyChecker with not even a warning: > >#---- >def tester(a,b,c): > print "bogus test function",a,b,c > >def try1(): > tester(1,2,3) >def try2(): > tester(1,2) #still no error here >#---- > >Do you mean something different? I've never used PyChecker myself, so can't comment on it. I've not personally had problems with the wrong number of argumnets to a function call -- they get caught at run-time and are easy enough to fix -- but I do sometimes get errors because a varialbe is the wrong time, e.g. a string when it should be an int. One problem I once encountered was wit this and I waasn't picking it up because my debugging code looked like this: if debug: print "v=%s" % (v,) Which of course prints the same output whether v is '2' or 2. For this reason I tend to debug print statements like this now: if debug: print "v=%s" % (v,) -- Email: zen19725 at zen dot co dot uk From rNOSPAMon at flownet.com Thu Aug 25 15:28:30 2005 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 25 Aug 2005 12:28:30 -0700 Subject: variable hell References: <430dc538@127.0.0.1> Message-ID: In article , Robert Kern wrote: > In the > bowels of my modules, I may not know what the contents are at code-time, Then how do you write your code? rg From ptmcg at austin.rr.com Tue Aug 16 14:33:48 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 16 Aug 2005 11:33:48 -0700 Subject: How can I exclude a word by using re? References: <430085e8$1@news.eftel.com> <1124165702.590364.107410@o13g2000cwo.googlegroups.com> <1124198308.584668.69390@g14g2000cwa.googlegroups.com> <1124198822.785871.143970@o13g2000cwo.googlegroups.com> Message-ID: <1124217228.600911.132070@z14g2000cwz.googlegroups.com> I just reviewed what the re "\s" signifies: whitespace. This is easy, pyparsing ignores all intervening whitespace by default. So mp3Entry simplfies to: mp3entry = valign + number.setResultsName("number"???) + tdEnd + \ tdStart + aStart + \ SkipTo(tdEnd).setResultsName("?n?ame") + tdEnd which leads me to another question - isn't there a closing in there somewhere, probably at the end of the name? If so, then you might be better off with: mp3entry = valign + number.setResultsName("number"???) + tdEnd + \ tdStart + aStart + \ SkipTo(aEnd).setResultsName("?n?ame") + aEnd + tdEnd -- Paul From cmedcoff at hotmail.com Tue Aug 2 13:05:00 2005 From: cmedcoff at hotmail.com (chuck) Date: 2 Aug 2005 10:05:00 -0700 Subject: pre subprocess help needed Message-ID: <1123002300.258761.316950@g44g2000cwa.googlegroups.com> I need to execute a command shell process obtain the return code and capture stdout from that shell process. I've done this with 2.4 using subprocess. How do I do it with 2.3? From kenneth.m.mcdonald at sbcglobal.net Thu Aug 25 17:19:03 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Thu, 25 Aug 2005 16:19:03 -0500 Subject: pre-PEP: Object-oriented file module Message-ID: I'd like to propose a new PEP [no, that isn't a redundant 'process' in there :-)--pre-PEP is a different process than PEP], for a standard library module that deals with files and file paths in an object oriented manner. I believe this module should be included as part of the standard Python distribution. Background ========== Some time ago, I wrote such a module for myself, and have found it extremely useful. Recently, I found a reference to a similar module, http://www.jorendorff.com/articles/python/path/ by Jeff Orendorff. There are of course differences--I think mine is more comprehensive but probably less stable--but the similarities in thought are striking. Both work by creating a class representing file paths, and then using that class to unify methods from shutil, os.path, and some builtin functions such as 'open' (and maybe some other stuff I can't remember). I haven't looked at Jeff's code yet, but for my own, a major enabler of the enhanced functionality has been the inclusion of generators in Python. This allows, for example, a method which yields all of the lines in a file and automatically closes that file after. The availability of attributes also makes certain things cleaner than was the case in previous versions of python. Fit With Python Philosophy ========================= One of the strengths of Python is that it is a highly object-oriented language, but this is not true when it comes to handling files. As far as python is concerned a file path is just a string, and there are a bunch of things you can do with it, but they all have to be done with function calls (not methods) since there is no concept of a file path object. Even worse, these functions are spread out across various modules, and often have cryptic names that hardly make it obvious what they do. Given that two different people concluded that such a module was desirable, and independently implemented modules that are actually very similar, I suspect there is an 'object-oriented mindset' to which this way of addressing files and file paths is natural. And that should be part of Python. Pragmatic Justification ================= I've been using my module for about a year and a half now. The ease- of-use and uniformity make a huge (I'm tempted to say 'vast') difference in dealing with files. I believe other users would experience an increase in efficiency when dealing with files ranging from 'significant' to 'very large' (in precise technical terms :-) ) Also, I think this type of API would be much easier for new users to learn and use. Examples ======== A few examples are in order. Again, these are from my own library, since I'm not too familiar with Jeff's. Also, this is stuff I'm just typing in right now as an illustration--there may be syntactic errors. (However, all of this functionality is present.) And these by no means represent the full functionality that is already defined. # define a new path object mydir = filepath("#&*$directory") # Note that special characters are automatically escaped # by filepath, as necessary for the current OS. If a character # is illegal in a file name no matter what (cannot be escaped), # an exception will be raised. # A file in that directory f = mydir / "some.txt" # Go through the lines in the file. When all lines are done, # the file will be closed automatically. If the file does not # actually exist, an appropriate exception will be raised. for line in f.iterlines(): ...do something... #The directory containing f is, of course, 'mydir' assert f.parent == mydir #Another path aPath = filepath(....) #In my module (not in Jeff's), a file path is considered # semantically as a sequence of directory names terminated # by the name of a file or directory. This makes it easy to # obtain the name of the file at the end of a path: theFile = aPath[-1] # or the directory leading to that file parentDir = aPath[0:-1] #of course, these two common indexes/slices are accessible through attributes theFile = aPath.basename parentDir = aPath.parent # A more powerful 'walk'-type method is included. Below, # the 'recursive' indicates that directories should be recursively # walked, and the 'preorder' indicates that directories should # be included in the iteration _before_ their contents are given. # There is also a 'postorder' argument, and both may be used to # yield directories both before and after their contents. aPath.iterfiles(recursive=True, preorder=True) # With the advent of the 'itertools' module in python, there is no # need to provide an argument taking a function that is applied # during the walk process, so in that sense, iterfiles is actually simpler than walk. #...and more. All of the various file capabilities available in Python are provided # in a unified package in this module. From john at castleamber.com Tue Aug 30 14:06:48 2005 From: john at castleamber.com (John Bokma) Date: 30 Aug 2005 18:06:48 GMT Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: Mark McIntyre wrote: >Its a complete mystery. Just as is the reason why you are x-posting >complete garbage to comp.lang.c... A similar mystery as in why Mark clueless n00b II McIntyre thinks it's a good idea to cross post to all other groups except comp.lang.c? Again: stop trolling in this thread. Let it go, it will die out in 1 or 2 days If you keep trolling, posting your ploinks, or witty comments, it will go on for days and days. Mark, as a C programmer you must at least have some idea of what logic means. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From python-url at phaseit.net Tue Aug 30 08:08:03 2005 From: python-url at phaseit.net ( Diez B. Roggisch ) Date: Tue, 30 Aug 2005 12:08:03 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 30) Message-ID: QOTW: "If I wanted to write five lines instead of one everywhere in a Python program, I'd use Java." -- Paul Rubin http://groups.google.com/group/comp.lang.python/msg/6fac4f3022acd1fa?hl=de& "i think less buggy code is not the main concern for all." -- km http://groups.google.com/group/comp.lang.python/msg/db5acbd68447ae33?hl=de& Bryan Olson discovers inconsistencies in the slice implementation that lead to a new slicing PEP and a lively discussion about string index semantics: http://groups.google.com/group/comp.lang.python/browse_frm/thread/402d770b6f503c27/66014427182265b9#66014427182265b9 Mark Dickinson finds strange runtime differences depending on the existence of dummy variables - the riddle is solved by Stelios Xanthakis who points out that min() can behave non-deterministically when the compared entities have no well-defined comparision sematics: http://groups.google.com/group/comp.lang.python/browse_frm/thread/2ff00f12499233e5/8b658bc804020f08#8b658bc804020f08 Russell E. Owen tries to get unique ids for bound methods - and discovers that id() can return the same value for two different bound methods. The solution is to keep a reference to the bound method, thus the id() won't be reused - which tkinters _register does: http://groups.google.com/group/comp.lang.python/browse_frm/thread/143a9000bdc9847e/5b2d07b8e5470583#5b2d07b8e5470583 Ramza Brown wants a small footprint python distro - and gets answers which shed light on the subject from varying perspectives: http://groups.google.com/group/comp.lang.python/browse_frm/thread/18e8f91c8e915c50/da5c5a740f7afe87#da5c5a740f7afe87 Diego Andr??s Sanabria wonders about the apparent lack of a binary tree data type in python: http://groups.google.com/group/comp.lang.python/browse_frm/thread/fb307dbdf7069b30/a0f94ea4a27ddb7c#a0f94ea4a27ddb7c sysfault wants enlightenment about decorators and metaclasses - and hopefully now has it: http://groups.google.com/group/comp.lang.python/browse_frm/thread/6bcb4d9ae934ac64/1060a20aaaf4b89a#1060a20aaaf4b89a Roland Hedberg wants to speed up his client/server implementation - and gets deep insight into the TCP/IP protocol stacks: http://groups.google.com/group/comp.lang.python/browse_frm/thread/507a711c61df7ad5/d6e871a24d8506a6#d6e871a24d8506a6 As often before, Jp Calderone eloquently illustrates the expressiveness Twisted affords those writing multitasking network servers: http://groups.google.com/group/comp.lang.python/browse_thread/thread/dce3370299af324e/ max(01)* needs help on piping commands in python: http://groups.google.com/group/comp.lang.python/browse_frm/thread/5cbe3126675ac0e0/1b3d6b36341e8cad#1b3d6b36341e8cad Pythoneers are nearly unanimous: when you need dynamic names for your variables ... you're probably doing something wrong. Python is plenty dynamic, though, so of course it's *possible*: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d9a99f17e0cad8f2/ Damien Elmes needs advice dealing with locales: http://groups.google.com/group/comp.lang.python/browse_frm/thread/8f44319aee701f71/ce6194ba78934818#ce6194ba78934818 KM compares apples with oranges - and gets told so: http://groups.google.com/group/comp.lang.python/browse_frm/thread/d1c6888eaec9930f/b444a3ec71e0e2b3#b444a3ec71e0e2b3 42 thinks he has new ideas about restricting python's execution - it turns out to be old news again, though: http://groups.google.com/group/comp.lang.python/browse_frm/thread/89e733d60380741b/4831ed5d84026549#4831ed5d84026549 ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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. del.icio.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/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 rkern at ucsd.edu Wed Aug 3 04:11:53 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 03 Aug 2005 01:11:53 -0700 Subject: distutils package_dir newbie In-Reply-To: <1123055950.708133.66580@g49g2000cwa.googlegroups.com> References: <1123055950.708133.66580@g49g2000cwa.googlegroups.com> Message-ID: peter wrote: > Hello all, > > I've have following problem > > the layout of my program is the following: > setup.py > project_dev/__init__.py > project_dev/someModule.py > > now I want to make a source-installer so python setup.py install will > give the following directory stucture: > > site-packages/project_user/__init__.py > site-packages/project_user/someModule.py > > notice the namechange from project_dev to project_user > > how do I achieve a namechange from project_dev to project_user??? > > I've tried several different versions of command package_dir options in > the setup function: > package_dir = {'project_user': 'project_dev'} > also package_dir = {'project_dev':'project_user'} > both without any success. (relatively unintuitive option this is) > > Can anybody give the correct way to achieve a directory-renaming when > creating an installer? Works just fine for me. from distutils.core import * setup(name='somePackage', packages = ['project_user'], # <- Are you sure you have this? package_dir = {'project_user': 'project_dev'}, ) -- 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 mwm at mired.org Thu Aug 4 00:53:28 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 04 Aug 2005 00:53:28 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> <868xzleztf.fsf@bhuda.mired.org> <87oe8gdbof.fsf@wilson.rwth-aachen.de> <86ek9betoz.fsf@bhuda.mired.org> <87d5ov8tv0.fsf@wilson.rwth-aachen.de> Message-ID: <86mzny1ewn.fsf@bhuda.mired.org> Torsten Bronger writes: > Hall??chen! > Mike Meyer writes: >> Torsten Bronger writes: >>> Because such projects attract the greatest number of developers, >>> many of them being amongst the most diligent developers, too. I >>> expect this to have a positive influence of the language. >> You didn't answer the question about how you define agile >> project. Please do so if you expect a comment on this. > Projects with a high Sourceforge activity index. That doesn't seem to match the common defintion of "agile" when it comes to programming. Then again, you have a habit of using words to mean whatever you want, without much reference to how they're used by the rest of the industry. >>> Yes, this is what I meant with "legacy code". C and C++ are >>> actually special-purpose. They are good for controlling a >>> computer but not for implementing an idea. Their current >>> vitality on almost all software areas arise from the fact that >>> they had been extremely successful before Java, C#, and VB came >>> into play. Invented today, they would be niche languages. >> This is patently absurd. C and C++ were born as general-purpose >> languages. Changing the environment around them isn't going to >> change that. > In 1955 people would have told you that Fortran is general-purpose. > It's not the case any more. Sorry, but you're wrong. FORTRAN is very much a general purpose language. Modern version don't resemble the version from 1955 very much, but that's true for most languages that are that old. >>>>> Legacy code is not a sign of success IMO because it implies a >>>>> difficult future. >>>> So you're saying that Python, Perl, Linux, the various BSD >>>> et. al. will have a difficult future? [...] >>> No. All I said was that if a language's "success" relies almost >>> exclusively on the heavy presence of legacy code, its future is >>> difficult. I see this for C and C++ excluding VC++. >> Well, you lumped all C/C++ code a legacy code. > No because ... Yes, you did do that. I objected to you doing that, because it isn't so. >> You can't have it both ways. Either C/C++ is all legacy code, or >> it's not. > ... is wrong in my opinion. Why should this be? Because any given proposition is either true or false. The truth may not be know (or even knowable), but the proposition is still either true or false. >> There are *lots* of applications areas that don't need GUIs, >> and don't run on Windows. > This becomes a discussion about estimates we both don't know > exactly, and weight differently, so I'll leave it here. No, it's not a discussion about estimates. The average household in a G8 country has more computers that don't run Windows - and in fact don't have GUIs at all - than otherwise. This is a fact of life. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From bdesth.quelquechose at free.quelquepart.fr Thu Aug 11 17:27:38 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 11 Aug 2005 23:27:38 +0200 Subject: Python interpreter error: unsupported operand type(s) for |: In-Reply-To: References: Message-ID: <42fbbb3e$0$22447$626a14ce@news.free.fr> yaffa a ?crit : > hey folks i get this error: Python interpreter error: unsupported > operand type(s) for |: > > when i run this line of code: > > for incident in bs('tr', {'bgcolor' : '#eeeeee'} | {'bgcolor' : > 'white'} ): > > any idea what i'm doing wrong here? yes: trying to do a bitwise or of two dict objects. > thanks You're welcome. From bokr at oz.net Mon Aug 8 20:14:25 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 09 Aug 2005 00:14:25 GMT Subject: PEP: Specialization Syntax References: <42f695f8.864310192@news.oz.net> <42f79137.928629067@news.oz.net> Message-ID: <42f7ef3b.952697616@news.oz.net> On Mon, 08 Aug 2005 16:18:50 -0400, Nicolas Fleury wrote: >Bengt Richter wrote: >> On Sun, 07 Aug 2005 21:41:33 -0400, Nicolas Fleury wrote: >>>I mean should angle brackets <> like in C++, or another operator, be >>>used instead? >> >> I am getting the feeling that your PEP is about a means to do something C++-like >> in python, not necessarily to enhance python ;-) IOW, it seems like you >> want the [] to do something like C++ in templates? > >Yes, exactly. Actually Guido also mentionned pointy brackets: >http://www.artima.com/weblogs/viewpost.jsp?thread=86641 > >> (BTW, I have nothing against giving python new capabilities (quite the reverse), >> but not by grafting limbs from other animals ;-) > >If I look at a very recent blog entry of Guido, it seems the idea is >still in the air: >http://www.artima.com/weblogs/viewpost.jsp?thread=92662 > >> Maybe you want hidden name-mangling of function defs according to arg types >> and corresponding dispatching of calls? I am afraid I am still not clear >> on the fundamental motivation for all this ;-) > >I wrote the PEP to see if was the only one that would benefit from >generic types *before* having optional static typing in the language. > >It seems I'm the only one;) > >According to blog entry 86641, Guido himself is prototyping with >__getitem__. However, I cannot do the same, because the framework I use >is much more complete and keyword arguments are a must. > Here is a decorator object to set up function call dispatch according to type. It only uses positional arguments, but could be fleshed out, I think. Not tested beyond what you see ;-) ----< typedispatcher.py >------------------------------------------------- # typedispatcher.py """ Provides a decorator to dispatch function calls according to arg types and signature. Example usage: foodisp = TypeDispatcher() # instance dedicated to foo variants @foodisp(a=int, b=str) def foo(a, b): assert type(a) is int and type(b) is str return (a,b) @foodisp(a=str, b=str) def foo(a, b): assert type(a) is str and type(b) is str return (a,b) """ class TypeDispatcher(object): def __init__(self): self.dispdict = {} def __call__(self, **kwtypes): self.kwtemp = kwtypes return self.dodeco def dodeco(self, f): if not hasattr(self, 'name'): self.name = f.func_name if f.func_name != self.name: raise ValueError('This TypeDispatcher instance decorates only functions named %r' % self.name) sig = tuple((self.kwtemp[argname] for argname in f.func_code.co_varnames[:f.func_code.co_argcount])) assert len(set([f.func_name]+list(f.func_name for f in self.dispdict.values()))) self.dispdict[sig] = f return self.docall def docall(self, *args): sig = tuple(map(type, args)) try: f = self.dispdict[sig] except KeyError: raise TypeError('no function %r with signature %r' % (self.name, sig)) return f(*args) def test(): try: foodisp = TypeDispatcher() @foodisp(a=int, b=str) def foo(a, b): assert type(a) is int and type(b) is str return 'foo(int, str):', (a,b) @foodisp(a=str, b=str) def foo(a, b): assert type(a) is str and type(b) is str return 'foo(str, str):', (a,b) @foodisp() def foo(): return 'foo()', () print foo(123, 'hello') print foo('hi','there') print foo() print foo(456, 789) except Exception, e: print 'Exception %s: %s' % (e.__class__.__name__, e) try: @foodisp() def bar(): pass except Exception, e: print 'Exception %s: %s' % (e.__class__.__name__, e) if __name__ == '__main__': test() -------------------------------------------------------------------------- Result: [17:12] C:\pywk\ut>py24 typedispatcher.py ('foo(int, str):', (123, 'hello')) ('foo(str, str):', ('hi', 'there')) ('foo()', ()) Exception TypeError: no function 'foo' with signature (, ) Exception ValueError: This TypeDispatcher instance decorates only functions named 'foo' Regards, Bengt Richter From me at privacy.net Wed Aug 17 11:41:26 2005 From: me at privacy.net (Dan Sommers) Date: Wed, 17 Aug 2005 11:41:26 -0400 Subject: Testing for presence of arguments References: <430353e1$0$18641$14726298@news.sunsite.dk> Message-ID: On Wed, 17 Aug 2005 11:13:03 -0400, Madhusudan Singh wrote: > I know how to set optional arguments in the function definition. Is > there an intrinsic function that determines if a certain argument was > actually passed ? Like the fortran 95 present() logical intrinsic ? def f(**kw): if kw.has_key('required_argument'): print "require_argument was present" else: print "require_argument was not present" > My required functionality depends on whether a certain argument is > specified at all. (Setting default values is *not* good enough.). You can very nearly achieve this with carefully planned default arguments. Put this into a module: class _SemiPrivateClass: pass def f(required_argument=_SemiPrivateClass): if required_argument == _SemiPrivateClass: print "required_argument was probably not present" else: print "required_argument was present" It's not impossible fool f, but an external module has to try very hard to do so. (All code untested.) Regards, Dan -- Dan Sommers From mathmom at gmail.com Sat Aug 13 00:44:27 2005 From: mathmom at gmail.com (Sheila King) Date: 12 Aug 2005 21:44:27 -0700 Subject: socket setdefaulttimeout Message-ID: <1123908267.500286.54150@g14g2000cwa.googlegroups.com> I'm doing DNS lookups on common spam blacklists (such as SpamCop..and others) in an email filtering script. Sometimes, because the DNS server that is resolving the looksup can go down, it is important to make sure that the socket doesn't just hang there waiting for a response. After a recent system upgrade to Python 2.4.1 (from 2.2.2) I thought I could take advantage of the setdefaulttimeout in the socket module, to limit the amount of time the sockets take for a lookup. As a test, I set the default timout ridiculously low. But it doesn't seem to be having any effect. The sockets will take several seconds to make the connection and complete the lookups, even though I've set the timeout to millionths of a second, which I thought would ensure a timeout (sample script below). Am I doing something wrong? Do I misunderstand something? Is what I want to do simply not possible? Thanks for any tips. Example code follows signature... -- Sheila King http://www.thinkspot.net/sheila/ #!/usr/local/bin/python2.4 import socket import sys from time import time, asctime, localtime socket.setdefaulttimeout(.00001) debugfile = "socketdebug.txt" def debug(data): timestamp = str(asctime(localtime(time()))) try: f = open(debugfile, 'a') f.write('\n*** %s ***\n' % timestamp) f.write('%s\n' % data) # 24-Dec-2003 -ctm- removed one linefeed f.close() except IOError: pass # do nothing if the file cannot be opened IPaddy = '220.108.204.114' if IPaddy: IPquads = IPaddy.split('.') IPquads.reverse() reverseIP = '.'.join(IPquads) bl_list = { 'bl.spamcop.net' : 'IP Address %s Rejected - see: http://spamcop.net/bl.shtml' % IPaddy, \ 'relays.ordb.org' : 'IP Address %s Rejected - see: http://ordb.org/' % IPaddy, \ 'list.dsbl.org' : 'IP Address %s Rejected - see: http://dsbl.org' % IPaddy} timing_done = 0 start_time = time() for host in bl_list.keys(): if host in bl_list.keys(): IPlookup = "%s.%s" % (reverseIP, host) try: debug(" IPlookup=%s=" % IPlookup) resolvesIP = socket.gethostbyname(IPlookup) debug(" resolvesIP=%s=" % resolvesIP) if resolvesIP.startswith('127.'): end_time = time() elapsed_time = end_time - start_time timing_done = 1 debug("Time elapsed for rDNS on bl_list: %f secs" % elapsed_time) debug("exiting--SPAM! id'd by %s" % host) print bl_list[host] sys.exit(0) except socket.gaierror: pass if not timing_done: end_time = time() elapsed_time = end_time - start_time debug("2nd try:Time elapsed for rDNS on bl_list: %f secs" % elapsed_time) From jitendran at productdossier.com Wed Aug 24 08:59:01 2005 From: jitendran at productdossier.com (jitya) Date: 24 Aug 2005 05:59:01 -0700 Subject: Inheritance problem ? In-Reply-To: References: <1124879676.525583.14390@g44g2000cwa.googlegroups.com> Message-ID: <1124888341.291306.209360@g44g2000cwa.googlegroups.com> The stuff on Descriptor.htm was really good . Thanks From twic at urchin.earth.li Mon Aug 22 03:50:35 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Mon, 22 Aug 2005 08:50:35 +0100 Subject: network programming In-Reply-To: References: Message-ID: On Sun, 21 Aug 2005, John Walton wrote: > Hello, everyone. I just began school, and they already assigned us > science fair. Since I'm in 8th grade, I get to do demonstrations for > our projects. I'm probably going to demonstrate Python's networking > capabilities by writing a simple instant messenger program. I only have > a few problems: > > 1. I know squat about Python network Programming > > 2. I know nothing about networks > > So if any of you know of a good Python Networking Tutorial or a website > with lots of information on networks and networking, please reply. > Thanks! There are two sides to this problem. The first is understanding networks in general, and the specific application protocols you're interested in. When i say 'understanding networks in general', don't panic - i don't mean you need to understand everything about how the internet works. In fact, you don't really need to understand *anything* about how the internet works, you just need to understand the interfaces it exposes to you. And, helpfully, that interface is pretty simple: a program can get a connection to another program, running on a different machine, which amounts ot a pipe for bytes - both ends can write bytes to the pipe when they feel like it, and those bytes become available for the other end to read. To open one of these connections, you need to know the hostname or IP address of the computer at the far end, and something called a 'port number', which is basically a way of identifying which program on that machine you want to talk to; if you want other programs to be able to open connections to your program, you have to pick a port number and ask the system to give you any connections that are made to it. That's pretty much it for the network fundamentals. There is more - datagram sockets, looking up IP addresses, doing funky things with sockets - but you can forget about that until you've mastered the basics. What you do need to understand beyond this, though, is about the application protocol you're using. The network just gives you a way to move streams of bytes; in order to actually do anything useful, you need an agreement between the programs at either end of the connection about what those bytes mean - that's an application protocol. It's basically a file format as applied to a network connection instead of a file. Each application protocol is completely different to every other one (well, there are a lot of similarities, but they're mostly different), so you'll need to read up on the one you want to use (or invent your own!) - the documentation is (almost always) in the form of a document unhelpfully called a Request For Comments, or RFC; the internet RFCs are published here: http://www.rfc-editor.org/ For example, here's the RFC for HTTP version 1.0: http://www.rfc-editor.org/rfc/rfc1945.txt RFCs can be pretty heavy going, but they are *the* definitive specifications, so they're worth reading. Once you're used to them, they're often easier to read than tutorials, i find. The second thing is understanding how to do network programming in python. There's a well-established API in C for network programming - the socket API - which comes from UNIX; python uses a fairly simple translation of this as its network API (look in the 'socket' package). The good thing about this is that this API is well-understood and well-documented. The bad thing is that it's a bit of a mess (compare and contrast to the API in Java if you don't believe me). There's detailed documentation for the socket module here: http://docs.python.org/lib/module-socket.html And a very quick tutorial here: http://www.amk.ca/python/howto/sockets/sockets.html What it comes down to, though, is that you can do: import socket s = socket.socket() target = ("www.python.org", 80) s.connect(target) s.send("GET / HTTP/1.0\r\n\r\n") reply = "" while True: line = s.recv(1000) if (line != ""): reply = reply + line else: break s.close() To create a connection, send some data, and then read some data. In this case, the code sends a very simple HTTP request. A slightly easier way to do this is using socket's makefile method - this gives you a file-like representation of the socket, so you can read and write data using the familiar file methods. To accept connections from other machines, do something like this: ss = socket.socket() ss.bind(('', 2323)) ss.listen(5) while True: s, addr = ss.accept() s.send("Hello!\r\n") s.close() tom -- Eat + Read + Learn = Word From tprimke at interia.pl Sat Aug 6 09:27:15 2005 From: tprimke at interia.pl (TPJ) Date: 6 Aug 2005 06:27:15 -0700 Subject: Some simple performace tests (long) Message-ID: <1123334835.548075.129430@z14g2000cwz.googlegroups.com> "The advantage of xrange() over range() is minimal (since xrange() still has to create the values when asked for them) except when a very large range is used on a memory-starved machine or when all of the range's elements are never used (such as when the loop is usually terminated with break)." - from Python Library Reference. I decided to measure the performance of range and xrange. I did it with the following functions: def rprint( n ): a = time.time() for i in range(n): print i print time.time() - a def xrprint( n ): a = time.time() for i in xrange(n): print i print time.time() - a def rpass( n ): a = time.time() for i in range(n): pass print time.time() - a def xrpass( n ): a = time.time() for i in xrange(n): pass print time.time() - a The results were as follows: n rprint xrprint 10^4 0.37 s 0.34 s <- (1) 10^5 4.26 s 4.25 s 10^6 42.57 s 42.57 s 10^7 431.94 s 438.32 s <- (2) n rpass xpass 10^4 0.0012 s 0.0011 s 10^5 0.0220 s 0.0139 s 10^6 0.1463 s 0.1298 s 10^7 1.4818 s 1.1807 s The values are the average times printed by tested functions. Conclusions: 1) According to (1) I could say that xrange might be somewhat faster than range with lower numbers of iterations. 2) According to (2) I could say that xrange might be slower than range with higher number of iterations. The test with pass is not so important as the test with print (because we usually do something inside of loops). So despite xpass has beaten rpass, I would say that range is not slower than xrange (especially for higher numbers of iterations). The final conclusion is : if you want speed, you should use xrange privided that there aren't many iterations. If you want less memory usage, you should use xrange. I've also made more tests. The code was as follows: ----------------------------- import array, random, time def test1( n, size ): a = time.time() for i in xrange(n): l = [] for i in xrange(size): l.append( random.randint( 1,10 ) ) e = sum(l) / float(size) # just for taking some time print time.time() - a def test2( n, size ): a = time.time() l = [] for i in xrange(n): del l[:] for i in xrange(size): l.append( random.randint( 1,10 ) ) e = sum(l) / float(size) print time.time() - a def test3( n, size ): a = time.time() l = range(size) for i in xrange(n): for i in xrange(size): l[i] = random.randint( 1,10 ) e = sum(l) / float(size) print time.time() - a def test4( n, size ): a = time.time() l = array.array( 'L', xrange(size) ) for i in xrange(n): for i in xrange(size): l[i] = random.randint( 1,10 ) e = sum(l) / float(size) print time.time() - a def test5( n, size ): a = time.time() ind1 = range(size) ind2 = range(size) for i in xrange(n): des1 = [] des2 = [] point = random.randint( 1, size-1 ) des1 = ind1[:point] + ind2[point:] des2 = ind2[:point] + ind1[point:] print time.time() - a def test6( n, size ): a = time.time() ind1 = range(size) ind2 = range(size) des1 = [] des2 = [] for i in xrange(n): del des1[:] del des2[:] point = random.randint( 1, size-1 ) des1 = ind1[:point] + ind2[point:] des2 = ind2[:point] + ind1[point:] print time.time() - a def test7( n, size ): a = time.time() ind1 = range(size) ind2 = range(size) des1 = range(size) des2 = range(size) for i in xrange(n): point = random.randint( 1, size-1 ) des1[:point] = ind1[:point] des1[point:] = ind2[point:] des2[:point] = ind2[:point] des2[point:] = ind1[point:] print time.time() - a def test8( n, size ): a = time.time() ind1 = array.array( 'L', xrange(size) ) ind2 = array.array( 'L', xrange(size) ) des1 = array.array( 'L', xrange(size) ) des2 = array.array( 'L', xrange(size) ) for i in xrange(n): point = random.randint( 1, size-1 ) des1[:point] = ind1[:point] des1[point:] = ind2[point:] des2[:point] = ind2[:point] des2[point:] = ind1[point:] print time.time() - a ----------------------------- And this is my session with Python 2.4.1: >>> for i in xrange(5): test.test1( 10000, 10 ) ... 2.27345108986 2.51863479614 2.49968791008 2.68024802208 2.28194379807 >>> for i in xrange(5): test.test2( 10000, 10 ) ... 2.54866194725 2.36415600777 2.71178197861 2.32558512688 2.71971893311 >>> for i in xrange(5): test.test3( 10000, 10 ) ... 2.29083013535 2.5563249588 2.32064318657 1.90063691139 2.30613899231 >>> for i in xrange(5): test.test4( 10000, 10 ) ... 2.55809211731 2.42571187019 2.59921813011 2.19631099701 2.16659498215 >>> for i in xrange(5): test.test5( 10000, 10 ) ... 0.318142175674 0.442049980164 0.367480039597 0.327154874802 0.322648048401 >>> for i in xrange(5): test.test6( 10000, 10 ) ... 0.356222867966 0.471677780151 0.332046031952 0.339803934097 0.48833990097 >>> for i in xrange(5): test.test7( 10000, 10 ) ... 0.467595815659 0.317886829376 0.311239004135 0.312664031982 0.49030995369 >>> for i in xrange(5): test.test8( 10000, 10 ) ... 0.499684095383 0.330184936523 0.332714080811 0.329524040222 0.50562787056 >>> for i in xrange(5): test.test5( 10000, 100 ) ... 0.387717962265 0.45348906517 0.507198095322 0.402877807617 0.526827096939 >>> for i in xrange(5): test.test6( 10000, 100 ) ... 0.525599002838 0.41659784317 0.443000078201 0.403271913528 0.591446876526 >>> for i in xrange(5): test.test7( 10000, 100 ) ... 0.399652957916 0.416820049286 0.400202035904 0.404708862305 0.57714009285 >>> for i in xrange(5): test.test8( 10000, 100 ) ... 0.357075929642 0.540817022324 0.378996133804 0.372053146362 0.554198980331 >>> for i in xrange(5): test.test5( 10000, 250 ) ... 0.630347967148 0.497437000275 0.687075138092 0.497366905212 0.935706853867 >>> for i in xrange(5): test.test6( 10000, 250 ) ... 0.493726015091 0.683156013489 0.512520074844 0.697488069534 0.746694803238 >>> for i in xrange(5): test.test7( 10000, 250 ) ... 0.519948005676 0.583598136902 0.624222993851 0.528346061707 0.948079824448 >>> for i in xrange(5): test.test8( 10000, 250 ) ... 0.553761005402 0.401547908783 0.389595985413 0.578064918518 0.394165039062 >>> for i in xrange(5): test.test1( 10000, 1000 ) ... 233.676990032 229.95272994 228.739851952 228.541095018 226.404256105 >>> for i in xrange(5): test.test2( 10000, 1000 ) ... 223.505224943 225.172422886 223.084803104 223.407966137 224.717788935 >>> for i in xrange(5): test.test3( 10000, 1000 ) ... 210.81110096 211.956163168 212.362264156 211.730306149 209.519776106 >>> for i in xrange(5): test.test4( 10000, 1000 ) ... 241.220864773 248.316150904 247.426213026 239.199230909 242.972666025 >>> for i in xrange(5): test.test5( 10000, 1000 ) ... 1.32021999359 1.29506993294 1.14080190659 1.50338101387 1.30436086655 >>> for i in xrange(5): test.test6( 10000, 1000 ) ... 1.28036403656 1.09035301208 1.07259607315 1.0751209259 1.07368779182 >>> for i in xrange(5): test.test7( 10000, 1000 ) ... 1.38129281998 1.36377501488 1.40786099434 1.35044002533 1.37256002426 >>> for i in xrange(5): test.test8( 10000, 1000 ) ... 0.524824142456 0.696274995804 0.544312000275 0.719218969345 0.77623295784 Tests with size equal to 10 were for testing a "small" size case. The sizes 100 and 250 are more adequate in my case. The size 1000 is a "big" size case. There are "random" tests (test1 ... test4) and "slice" tests (test5 ... test8). Conclusions: 1) Small size tests: there is no one winner of the random tests. The differences are rather small and might be accidental. There is also no winner of the slice tests. 2) Big size tests: as I expected, test3 is better than test2, and test 2 is better than test1. As I definitelly hadn't expected is the fact that test4 was the worst (shouldn't arrays be more efficient than lists?). So the winner of random tests is test3. And the winner in slicing is test8. I'm going to implement genetic algorothm, so I think that slicing tests are more important than random tests. And the final conclusion is I should use arrays instead of lists. I'm going also to write tests that use Numeric. From lycka at carmen.se Wed Aug 17 10:41:07 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 17 Aug 2005 16:41:07 +0200 Subject: random seed In-Reply-To: References: <1124215843.369517.197900@z14g2000cwz.googlegroups.com> <430244d1$0$14955$626a14ce@news.free.fr> <1124229800.788839.66510@o13g2000cwo.googlegroups.com> Message-ID: Robert Kern wrote: > random.seed(1234567890) > > is traditional and works just fine. > > Other favorites: > > 3141592653589793 > 2718281828459045 Nothing beats 42! (That was just an exclamation mark in the end, no factorial intended.) 371 is another nice number, since it's its own reverse in hex. If you liked 3141592653589793, you might also like 113355. :) From cliff at develix.com Mon Aug 1 04:17:57 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 01:17:57 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <7xu0iacfwq.fsf@ruckus.brouhaha.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <7xmzo25zmm.fsf@ruckus.brouhaha.com> <877jf6yzc3.fsf@wilson.rwth-aachen.de> <7xu0iacfwq.fsf@ruckus.brouhaha.com> Message-ID: <1122884277.19618.244.camel@localhost.localdomain> On Sun, 2005-07-31 at 23:47 -0700, Paul Rubin wrote: commentary about how Paul wants to both not install *anything* and if he does have to install something he must compile it from source because he shouldn't have had to do it in the first place therefore he needs to make it as difficult as possible and if something doesn't fit this bizarre pattern then it sucks and we should just use tkinter instead. I think you are one of a kind and that any suggestions you make about what should or shouldn't be standard in Python (i.e what would be of the most use to the largest number of people) are to be taken with an extremely large grain of salt. Nothing wrong with being unique, but you just need to realize that no one else in their right mind wants to do things your way and any attempts you make to get them to do so are doomed to failure at best and ridicule at worst. Regards, Cliff -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From zen19725 at zen.co.uk Mon Aug 15 14:41:45 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 15 Aug 2005 19:41:45 +0100 Subject: GUI tookit for science and education References: Message-ID: On Mon, 15 Aug 2005 04:59:29 +0200, Mateusz ?oskot wrote: >Hi, > >I'd like to ask some scientists or students >which GUI toolkit they would recommend >to develop scientific prototypes (for education and >testing some theories). >I think such toolkit should fill a bit different >needs and requirements: >- very simple to learn >- easy to install >- beautyfiers and advanced features are not required like OpenGL, >direct access to Windows GDI subsystem, beauty look and skinning >- multiplatform required Tkinter is the default GUI for Python, it runs on lots of platforms and often comes already installed (on Linux or Unix distributions). Is it "very simple to learn"? Well I suppose that depends on what you mean by "very simple". -- Email: zen19725 at zen dot co dot uk From leftwing17 at gmail.com Wed Aug 31 13:46:50 2005 From: leftwing17 at gmail.com (Adam Endicott) Date: 31 Aug 2005 10:46:50 -0700 Subject: aggdraw for PIL Message-ID: <1125510410.873991.285330@g47g2000cwa.googlegroups.com> Does anyone know anything about the aggdraw module for PIL? I think I would like to use it because I need to do some drawing with semi-transparent pen styles (I'm simulating using a highlighter). It seems to be working great, but I think I'm running into a memory leak that's noted in the documentation at http://effbot.org/zone/pythondoc-aggdraw.htm#aggdraw.Draw-class "Note: The Draw(im) form leaks memory in aggdraw 1.1b1 and earlier. Don't use this form in long-running program that creates multiple drawings. The memory leak has been fixed in release 1.1b2." Sounds good, except I can't find 1.1b2 anywhere. Is it not released yet? If so, does anyone know when it might be released? From maxm at mxm.dk Tue Aug 30 11:21:39 2005 From: maxm at mxm.dk (Max M) Date: Tue, 30 Aug 2005 17:21:39 +0200 Subject: ANN: PyDev 0.9.8 released In-Reply-To: References: <42A720BD.5050701@esss.com.br> <42C175A5.5000206@esss.com.br> <42E6412A.4020905@esss.com.br> <430632E3.9050403@esss.com.br> Message-ID: <4314793b$0$27314$edfadb0f@dread12.news.tele.dk> Fabio Zadrozny wrote: > Hi All, > > PyDev - Python IDE (Python Development Enviroment for Eclipse) version > 0.9.8 has just been released. I read this, and thought it was time to check out both Eclipse, end the pydev plugin. I got it all installed, along with a subversion plugin for eclipse, and it actually seems like a very sweet combo. I was afraid that a Java based editor would be sluggish. But it doesn't seem so. There are a few nice features too with a file navigator, refactoring, code folding and more. So I have decided to give it a try. But before commiting to it, I just wondered what experiences other users might have when using it for production. Being that my text editing environment is my bread and butter. Is it stable/effective etc? Anybody cares to share? -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From theller at python.net Wed Aug 24 10:57:35 2005 From: theller at python.net (Thomas Heller) Date: Wed, 24 Aug 2005 16:57:35 +0200 Subject: Unix diff command under Window. References: <1124891404.485434.105110@f14g2000cwb.googlegroups.com> Message-ID: <1x4j4c2o.fsf@python.net> "TonyHa" writes: > Hello, > > Does any one have using Python to write a Unix "diff" command for > Window? > > Tony Ha. Yes. There's a script in your Python distribution: Tools/scripts/diff.py See also the docs for the 'difflib' standard library module. I do not know whether the Tools directory is installed by default or not. Thomas From gregpinero at gmail.com Fri Aug 19 11:21:22 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 19 Aug 2005 11:21:22 -0400 Subject: Python jobs (was Re: Python for Webscripting (like PHP)) In-Reply-To: References: Message-ID: <312cfe2b0508190821715fb488@mail.gmail.com> I'd love Python work, just like everyone else here. On a related topic, what's the policy/etiquette of posting a resume on here, or mentioning what kind of work you're looking for? And what's the policy in general for most newsgroups and mailing lists? -Greg On 8/19/05, Steve Holden wrote: > > Aahz wrote: > > In article , > > Steve Holden wrote: > > > >>There's informal evidence that the Python secret is getting out. Sharpen > >>up your resumes, guys, you may not have to limit Python to home usage > >>soon :-) > > > > > > OTOH, the big sucking sound from Google and Yahoo (plus other places > > like Ironport) is making it more difficult to hire Python programmers in > > the Bay Area... > > Not to mention the large Python gravity field a few hundred miles South > emanating from Industrial Light and Magic. > > But don;t expect "Google and Yahoo suck" to be a popular compaint ;-) > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From cantabile.03 at wanadoo.fr Sun Aug 7 05:09:14 2005 From: cantabile.03 at wanadoo.fr (cantabile) Date: Sun, 07 Aug 2005 11:09:14 +0200 Subject: gettext again Message-ID: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> Hi, I'm failing to make it work but can't find out what's wrong. Here's what I do : ================ test.py import gettext gettext.install('') msg = _("Message without accented characters") print msg ================ Then I do : xgettext test.py mv message.po message pot msginit --> output message.fr_FR at euro I edit my fr_FR at euro with this text : msgid "This is a message without accented characters." msgstr "Message avec caract?res accentu?s : ????????a??" Then msgfmt fr_FR at euro Then python test.py shows "Message without accented characters" How come ? What's wrong with what I am doing ? Thanks for your help. From yux at sdf-eu.org Tue Aug 23 13:13:21 2005 From: yux at sdf-eu.org (Jonas Geiregat) Date: Tue, 23 Aug 2005 17:13:21 +0000 Subject: High Level FTP library In-Reply-To: <7NGOe.6737$Nb2.115820@news1.nokia.com> References: <7NGOe.6737$Nb2.115820@news1.nokia.com> Message-ID: <430b3cc2$0$10958$ba620e4c@news.skynet.be> Paulo Pinto wrote: > Hello, > > Is there any Python library similar to NET::FTP from Perl? > ftplib seems too lowlevel. > > I already found a few, but would like to get one that is > endorsed by the community. > > Thanks, > Paulo libftp sucks just look at how it's written such evil code! Not that I know of, write your own based on libftp good luck! From rtconner at gmail.com Mon Aug 1 16:51:12 2005 From: rtconner at gmail.com (Rob Conner) Date: 1 Aug 2005 13:51:12 -0700 Subject: inheriting from datetime Message-ID: <1122929471.966054.146010@g44g2000cwa.googlegroups.com> So this is simple, why can't I run the following code? I've tried many variances of this, but simply cannot inherit from datetime or datetime.datetime. I get this on line 3. TypeError: function takes at most 2 arguments (3 given) ******************************** import datetime _datetime = datetime.datetime class MyDateTime(_datetime): """ Identical to builtin datetime.datetime, except it accepts invalid dates and times as input. """ _valid = True def __init__(self, year, month, day, *args, **kw): try: _datetime.__init__(self, year, month, day, *args, **kw) except _datetime.ValueError: _valid = False self.year = year self.month = month self.day = day self.args = args self.kw = kw ******************************** From aahz at pythoncraft.com Wed Aug 10 22:56:52 2005 From: aahz at pythoncraft.com (Aahz) Date: 10 Aug 2005 19:56:52 -0700 Subject: PEP 328, absolute/relative import (was: Re: Bizarre error from help()) References: Message-ID: In article , Ben Finney wrote: > >So, under PEP 328 rules, the original poster's current-directory >module could only be imported (a) if the current directory was in >sys.path, or (b) if the code specified a relative import. The >accidental shadowing of the stdlib module could not happen. Normally the current directory *is* on sys.path, and the first thing, too: >>> sys.path ['', '/usr/local/lib/python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-netbsd2', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages'] -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From kimsj at mobile.snu.ac.kr Wed Aug 31 21:36:08 2005 From: kimsj at mobile.snu.ac.kr (James Sungjin Kim) Date: Thu, 01 Sep 2005 10:36:08 +0900 Subject: Considering moving from PowerBuilder to Python In-Reply-To: References: Message-ID: Norm Goertzen wrote: > I'm really only interested in programming for Windows XP. It is warned that the sequal is not directly related to the your question. However, hope that it helps your decision to move from the old stuff to the new stuff. The thing is that as you decideded to change your main programming language, why you don't turn to change your programming environment too. If you start to use Java, no more need to be dependent on one specific os. If you have any interest in my suggestion, please visit Jython (www.jython.org). Declrare that I have no relationship with the developement of Jython. -James Gold From http Sun Aug 14 23:06:21 2005 From: http (Paul Rubin) Date: 14 Aug 2005 20:06:21 -0700 Subject: GUI tookit for science and education References: Message-ID: <7xek8vsxua.fsf@ruckus.brouhaha.com> Mateusz ?oskot writes: > Thank you for any piece of advice in advance. Ask yourself why you want a GUI toolkit. Maybe you can write a web application instead, and use a browser as the GUI. That's a lot easier to write (just use html), and makes it trivial to run the application and the browser on separate machines. From paolo_veronelli at tiscali.it Tue Aug 9 11:19:34 2005 From: paolo_veronelli at tiscali.it (Paolino) Date: Tue, 09 Aug 2005 17:19:34 +0200 Subject: namespaces In-Reply-To: References: Message-ID: <42F8C986.9050202@tiscali.it> Peter Otten wrote: > Paolino wrote: > > >>Why descriptor mechanism doesn't apply to modules? > > > Because modules are instances of the module class and the descriptor has to > be defined in the class in order to work with the instance. E. g.: > > Got it,thanks. Then there is no way of having descriptors at module level,as 'module' class is not updatable. ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it From timr at probo.com Tue Aug 9 00:21:02 2005 From: timr at probo.com (Tim Roberts) Date: Mon, 08 Aug 2005 21:21:02 -0700 Subject: Chopping off spaces at both ends References: <42f63fac$0$18648$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > > I am a newbie to python and am using it to interface some of my lab >equipment. > > How does one get rid of spaces at both ends of a string ? A little like the >trim() intrinsic in fortran 95. > > One of my instruments is returning a string that has one or more blanks in >it, and that is complicating string matching tests in one of my functions. >>> a = ' abc ' >>> print a.strip() 'abc' -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From fredrik at pythonware.com Mon Aug 22 16:12:25 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 22:12:25 +0200 Subject: Sanitizing untrusted code for eval() References: Message-ID: Jim Washington wrote: > 4. List comprehensions might be troublesome, though it's not clear to me > how a DoS or exploit is possible with these. see item 1. > Or is eval() simply too evil? yes. however, running a tokenizer over the source string and rejecting any string that contains unknown tokens (i.e. anything that's not a literal, comma, colon, or square or curly bracket) before evaluation might be good enough. (you can use Python's standard tokenizer module, or rip out the relevant parts from it and use the RE engine directly) From http Mon Aug 1 16:38:21 2005 From: http (Paul Rubin) Date: 01 Aug 2005 13:38:21 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <7x1x5do2da.fsf@ruckus.brouhaha.com> Message-ID: <7xirypjsua.fsf@ruckus.brouhaha.com> Peter Decker writes: > We were discussing your 'enormous pain' installing wxPython. I find it > interesting that you selectively quoted part of one line of my post, Yes, the one line I quoted was the one that said most people have wxPython installed, which is a preposterous claim. The reason they don't have it installed is they don't have reason to go through the hassle of installing it, given (among other things) that tkinter is already there. If they don't want to go through that hassle, I don't see why I should want to go through it. As for installing from source, well, that's what I see the whole FOSS movement as being about. If I can't compile the source, why should I care about having it? And if I don't care about having it, what's the point of FOSS? Source that I can't compile is not much better than no source. From fphsml at gmail.com Thu Aug 25 14:59:50 2005 From: fphsml at gmail.com (James) Date: 25 Aug 2005 11:59:50 -0700 Subject: loop in python In-Reply-To: References: <1124964483.645753.190460@g47g2000cwa.googlegroups.com> Message-ID: <1124996390.000447.33320@o13g2000cwo.googlegroups.com> >> I don't want to offend you or anything, but doesn't the second sentence mean that someone DID do a speed comparison? I did provide Language Shootout link in the next paragraph of the post you referred to along with an obligatory caution about interpreting benchmarks. The Language Shootout is a general enough benchmark to cover all popular languages not just comparing between Perl/Python/Ruby/Tcl (which I said was pointless). So the statements are not in conflict. From mwm at mired.org Tue Aug 2 00:42:53 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 00:42:53 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> Message-ID: <861x5deype.fsf@bhuda.mired.org> zen19725 at zen.co.uk (phil hunt) writes: > In practise any Python GUI is going to contain code from otyher > languages since if it was coded all the way down in python it would > be too slow. Not necessarily. My window manger is Python all the way down - it uses the Python Xlib implementation - and is plenty fast. Of course, it doesn't do a lot of graphics work, even for a window manager. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From g.belyh at grsu.by Fri Aug 5 03:15:03 2005 From: g.belyh at grsu.by (Belyh G.P.) Date: Fri, 05 Aug 2005 10:15:03 +0300 Subject: installing python2.4.1 In-Reply-To: <1123187667.656812.275110@g49g2000cwa.googlegroups.com> References: <1123187667.656812.275110@g49g2000cwa.googlegroups.com> Message-ID: <42F311F7.5050705@grsu.by> Grig Gheorghiu wrote: >I had a similar problem when trying to compile Python 2.4.1 on AIX. The >configure script complained about not finding 'cc_r'. I simply did 'ln >-s /usr/bin/gcc /usr/bin/cc_r' and that solved my problem. You may >consider doing the same for cclplus. > >Grig > > > Thank for your letter. Advice has helped me, but not absolutely as I expected :). Now instead of a mistake installation process stoped and not responsed. So I shall use the old Python(2.1.3) while has not arrived yet our manager. Once again thank. From brakjoller at gmail.com Mon Aug 15 16:59:39 2005 From: brakjoller at gmail.com (Mathias Dahl) Date: 15 Aug 2005 22:59:39 +0200 Subject: Invoking GUI for app running in background with a keypress References: <1124130042.3819.37.camel@localhost.localdomain> Message-ID: Jeremy Moles writes: > If you want to get crazy you can poll() on one of the evdev nodes > (/dev/input/event*) and behave accordingly. I do this in a C application > we use to do the exact same thing you're talking about. > > Each successful read from the device returns a 16-byte input_event > struct (or similar, I'm going from memory here) that represents a key > action. > > A google search returned this: > > http://svn.navi.cx/misc/trunk/python/evdev/evdev.py Thanks for the pointer. That sounds crazy indeed! Maybe a bit too crazy (low-level) for me... :) I tested the code very briefly: $ python evdev.py /dev/input/event0 Traceback (most recent call last): File "evdev.py", line 549, in ? demo() File "evdev.py", line 35, in demo dev = Device(sys.argv[1]) File "evdev.py", line 91, in __init__ self.fd = os.open(filename, os.O_RDWR | os.O_NONBLOCK) OSError: [Errno 13] Permission denied: '/dev/input/event0' Loggin in (su:ing) as root solves that problem but I'm not sure I want to require the user being root to be able to run my program. Anyway, thanks again for the hint! /Mathias From richardlewis at fastmail.co.uk Fri Aug 26 06:43:18 2005 From: richardlewis at fastmail.co.uk (Richard Lewis) Date: Fri, 26 Aug 2005 11:43:18 +0100 Subject: DOM text In-Reply-To: <3n889kFb1liU1@uni-berlin.de> References: <3n889kFb1liU1@uni-berlin.de> Message-ID: <1125052998.4951.241536021@webmail.messagingengine.com> On Fri, 26 Aug 2005 12:13:10 +0200, "Diez B. Roggisch" said: > Richard Lewis wrote: > > > > I admit I haven't tried very much code yet, but I'm not sure how I'm > > going to handle situations like: the user wants to insert a link in the > > middle of a paragraph. How can I use the DOM to insert a node into the > > middle of some text? Am I right in thinking that the DOM will reference > > a whole text node but nothing smaller? > > You have to split the text-node, and add the two resulting noedes > together with the new link-node (or whatever node you want there, can be > a whole tree) in the correct order to the parent of the two node. If > unsure what that means, create two simple documents and parse these to > dom to see how that works. > Thanks. I was kind of worried it might be like that! I'm implementing a Cursor class now which keeps track of the current parent Element, text node and character position so that I can easily (I hope ;-) work out where the splitting and inserting needs to occur. Wish me luck!! Cheers, Richard From caseyhHAMMER_TIME at istar.ca Thu Aug 4 00:46:28 2005 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Thu, 04 Aug 2005 04:46:28 GMT Subject: Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name? Message-ID: <1773f1t9k90pakcjl7ita4ags006auck80@4ax.com> Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name? Like "iskeyword" determines if a word is a keyword! -- Regards, Casey From max at alcyone.com Fri Aug 12 03:27:36 2005 From: max at alcyone.com (Erik Max Francis) Date: Fri, 12 Aug 2005 00:27:36 -0700 Subject: Cheese shop (was Re: python2.4/site-packages) In-Reply-To: References: Message-ID: <7sadneieT7f10mHfRVn-gw@speakeasy.net> Michael Hoffman wrote: > I have but I've never heard of PyPI's name being changed? I can only > find an announcement on Slashdot? I came across the change a good while back in my Web referrals, not having heard of it except passively. PyPI was a simple, clear, unambiguous name; Cheese Shop is just a silly name for no purpose. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis We learn from history that we do not learn from history. -- Georg Friedrich Wilhelm Hegel From godoy at ieee.org Mon Aug 8 09:20:32 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 08 Aug 2005 10:20:32 -0300 Subject: Oreilly CodeZoo References: <1123252802.949384.94330@z14g2000cwz.googlegroups.com> <42f6f81c$0$8993$afc38c87@news.optusnet.com.au> Message-ID: <4q2ks2-lpi.ln1@strongwill.g2ctech> richard wrote: > We (PyPI / Cheese Shop developers) are talking to the CodeZoo people about > the relationship between the two systems. Things PyPI has: > > 1. python setup.py register > 2. python setup.py (sdist|bdist|bdist_egg|bdist_wininst|...) upload > 3. http://cheeseshop.python.org/ > 4. better categorisation (IMO) > 5. XML-RPC interface > 6. 852 packages registered Richard, Some feedback: With regards to 6, it would be interesting, though, to separate the classification using just the software name and not the version. For example http://cheeseshop.python.org/pypi?:action=browse&asdf=256 has four entries to ZODB3, in four different versions. This would decrease the amount of packages registered, but would allow a more realistic view of "packages" and not of "package versions", IMVHO. A subtree with version numbers could solve the problem of storing information for old versions when a new one is added. With regards to 4, I'd like to see the "Topic" category in the beginning of the page -- this is what most people search, I guess -- and not at the bottom of it. I'm usually looking for a software to do and not a software that is being planned, is in alpha - beta - production stage, etc. Also, there's a discrepancy on the amount of packages stored. The categorization page says there are 679 packages. The main page says there are 852. I believe the categorization page does what I suggested and disregard different versions of the same software. I think this (679) is the correct number. Ah! And an RSS feeder would be interesting, to know when there are new packages or when a package has been upgraded... ;-) Where's the "wishlist"? :-) I hope you see this as a constructive feedback from someone that has just screened the pages, getting to know it. Be seeing you, -- Jorge Godoy From fakeaddress at nowhere.org Wed Aug 24 11:03:02 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 24 Aug 2005 15:03:02 GMT Subject: Bug in slice type In-Reply-To: <1124612453.206314.39330@g43g2000cwa.googlegroups.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <1124612453.206314.39330@g43g2000cwa.googlegroups.com> Message-ID: Kay Schluehr wrote: > Steven Bethard wrote: >>"The slice of s from i to j with step k is defined as the sequence of >>items with index x = i + n*k such that 0 <= n < (j-i)/k." >> >>This seems to contradict list behavior though. >> range(10)[9:-1:-2] == [] > > > No, both is correct. But we don't have to interpret the second slice > argument m as the limit j of the above definition. Even if "we don't have to," it sure reads like we should. > For positive values > of m the identity > m==j holds. For negative values of m we have j = max(0,i+m). First, the definition from the doc is still ambiguous: Is the division in 0 <= n < (j-i)/k real division, or is it Python integer (truncating) division? It matters. Second, the rule Kay Schluehr states is wrong for either type of division. Look at: range(5)[4 : -6 : -2] Since Python is so programmer-friendly, I wrote some code to make the "look at" task easy: slice_definition = """" The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < (j-i)/k. """ Kay_Schluehr_rule = """ For positive values of m the identity m==j holds. For negative values of m we have j = max(0,i+m). """ def m_to_j(i, m): """ Compute slice_definition's 'j' according to Kay_Schluehr_rule when the slice of sequence is specified as, sequence[i : m : k]. """ if m > 0: j = m else: j = max(0, i + m) return j def extract_slice(sequence, i, m, k, div_type='i'): """ Apply the slice definition with Kay Schluehr's rule to find what the slice should be. Pass div_type of 'i' to use integer division, or 'f' for float (~real) division, in the slice_definition expression, (j-i)/k. """ j = m_to_j(i, m) result = [] n = 0 if div_type == 'i': end_bound = (j - i) / k else: assert div_type == 'f', "div_type must be 'i' or 'f'." end_bound = float(j - i) / k while n < end_bound: result.append(sequence[i + n * k]) n += 1 return result def show(sequence, i, m, k): """ Print what happens, both actually and according to stated rules. """ print "Checking: %s[%d : %d : %d]" % (sequence, i, m, k) print "actual :", sequence[i : m : k] print "Kay's rule, int division :", extract_slice(sequence, i, m, k) print "Kay's rule, real division:", extract_slice(sequence, i, m, k, 'f') print show(range(5), 4, -6, -2) -- --Bryan From mwm at mired.org Wed Aug 31 23:10:54 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 31 Aug 2005 23:10:54 -0400 Subject: Calling ftp commands from python References: <1125521382.972797.298740@g47g2000cwa.googlegroups.com> Message-ID: <86acix7a9t.fsf@bhuda.mired.org> "Thierry Lam" writes: > Is it possible to run an ftp command to connect to some remote computer > on the network. Yes, but why would you want to do taht? > For example, if I want to retrieve some data from > \\remcomputer\datafiles on the network and copy it to my local > computer, how do I do it in python on the Unix side? Start with "import ftplib". Use ftplib to read the file, and write it out wherever you want it - or don't, if the goal was to get the contents of the file into your Python program. The API is sorta ugly, but it works, and comes with Python. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From foo at bar.org Mon Aug 8 09:19:20 2005 From: foo at bar.org (stasz) Date: Mon, 08 Aug 2005 15:19:20 +0200 Subject: gettext again References: <42f5cfbb$0$25025$8fcfb975@news.wanadoo.fr> <42f66201$0$897$8fcfb975@news.wanadoo.fr> <42f6adc4$0$3113$8fcfb975@news.wanadoo.fr> Message-ID: On Mon, 08 Aug 2005 02:56:35 +0200, cantabile wrote: > stasz a ?crit : >> On Sun, 07 Aug 2005 21:33:21 +0200, cantabile wrote: >> >> >>>stasz a ?crit : >>> >>>>On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote: >>>> >>>> >>>> >>>>>Hi, >>>>>I'm failing to make it work but can't find out what's wrong. Here's what >>>>>I do : >>>> >>>>[....] >>>> >>>> >>>>>How come ? What's wrong with what I am doing ? >>>> >>>>Start with this little howto about gettext. >>>>http://childsplay.sourceforge.net/translate-howto.html >>>> >>>>And then do this in your test.py: >>>>http://www.python.org/doc/2.4.1/lib/node330.html >>>> >>>>You should read the part about gettext in the Python Library Reference >>>>it's really good :-) >>>> >>>>Good luck, >>>>Stas Z >>>> >>>> >>> >>>Well, I must be dumb, because I did exactly that and it still doesn't >>>work... >>> >>>BTW, I have no pygettext module. I asked here and somebody said it was >>>deprecated and now included in xgettext. >>>And I've read the Python doc about gettext about ten times, but it seems >>>quite outdated since it calls pygettext (as staded above)... >>> >>>I've read the info pages of gettext too (quite a long work). >> >> Ok, you should use xgettext to create a .po file from your test1.py. >> Translate that file and use msgfmt to compile it into a .mo file. >> Copy this .mo file to /usr/share/locale/fr/LC_MESSAGES/ >> >> >>>Here's my test1.py file again : >>> >>>=========================== >>>import gettext, os, locale >>> >>>locale.setlocale(locale.LC_ALL) >>>gettext.install('test1.py', '/usr/share/locale') >> >> test1.py is wrong, you must give the name of the .mo file. >> It must be: gettext.install('test1.mo', '/usr/share/locale') >> Assuming you have called the mo file like that. >> >> Stas Z >> >> > > Well, I did this exactly... and still no go. > > Is this sequence correct : > 1? xgettext test1.py > 2? mv messages.po messages.pot > 3? msginit > 4? Translate msgstr"" in fr_FR at euro.po file > 5? msgfmt -o test1.mo fr_FR at euro.po > 6? cp test1.mo /usr/share/locale/LC_MESSAGES > 7? python test1.py > > > This is what I did, without success. Must be bewitched :(( Your steps seems alright. Just a thought; you do start test1.py from a fr_FR at euro environment do you? I mean in a xterm do: export LANG=fr_FR at euro And then start test1.py from there. Stas From jstroud at mbi.ucla.edu Mon Aug 8 14:38:11 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 8 Aug 2005 11:38:11 -0700 Subject: OT: World's largest Python caught!:) In-Reply-To: <87EFF7FC7B6D46479AF451B4326EF876361599@newplymth.tegel.co.nz> References: <87EFF7FC7B6D46479AF451B4326EF876361599@newplymth.tegel.co.nz> Message-ID: <200508081138.11238.jstroud@mbi.ucla.edu> http://www.afghania.com/News-article-sid-4792-mode-thread.html 3rd hit in google with "world's largest python". The first two hits were your email below to the newsgroups. James On Sunday 07 August 2005 09:15 pm, Ashok Rajasingh wrote: > Hi > > > > Can I please get some information on this python? I saw a brief news > clip last year & am very keen to know more. > > > > Thanks > > Ashok Rajasingh > > 21 Cumberland street > > New Plymouth > > New Zealand > > +646 7575698 (home) > > 7599592 (work) > > > > > ###################################################################### > Attention: > The information contained in this message and or attachments is intended > only for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited. If you received this in error, please contact the sender and > delete the material from any system and destroy any copies. Please note > that the views or opinions expressed in this message may be those of the > individual and not necessarily those of Tegel Foods Ltd. > > This email was scanned and cleared by NetIQ MailMarshal. > ###################################################################### -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From greg at puyo.cjb.net Mon Aug 22 21:22:43 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 22 Aug 2005 18:22:43 -0700 Subject: while c = f.read(1) In-Reply-To: <863bp1q105.fsf@bhuda.mired.org> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <43057145.1837895163@news.oz.net> <1124702613.567210.239460@o13g2000cwo.googlegroups.com> <863bp1q105.fsf@bhuda.mired.org> Message-ID: <1124760163.853733.69150@g14g2000cwa.googlegroups.com> > On the other hand, if you've already planned another pass over the code, that might be the time to look into this. Exactly. And when I do that pass I will definitely try buffering the data 10 or 100 meg at a time before entring the 1 char-at-a-time loop, or using mmap to similar ends. From rkern at ucsd.edu Sun Aug 21 03:36:43 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 21 Aug 2005 00:36:43 -0700 Subject: subpackage import problem In-Reply-To: References: Message-ID: Eric Huss wrote: > I'm having a problem with packages within packages. Here's an example: > > foo/ > foo/__init__.py: empty file > foo/sub/__init__.py: > from foo.sub.B import B > foo/sub/A.py: > class A: > pass > foo/sub/B.py > import foo.sub.A > class B(foo.sub.A): > pass > > Trying to "import foo.sub" will result in this error: > >>>>import foo.sub > > Traceback (most recent call last): > File "", line 1, in ? > File "foo/sub/__init__.py", line 1, in ? > from foo.sub.B import B > File "foo/sub/B.py", line 3, in ? > class B(foo.sub.A): > AttributeError: 'module' object has no attribute 'sub' I imagine it has something to do with the timing of imports. Python is executing the contents of foo/sub/B.py while it's trying to create the module object foo.sub. You can get around it, though. Try this in foo/sub/B.py : from foo.sub.A import A class B(A): pass That works for me (Python 2.4.1, OS X). -- 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 http Wed Aug 24 01:57:16 2005 From: http (Paul Rubin) Date: 23 Aug 2005 22:57:16 -0700 Subject: shelve non-transparency Message-ID: <7x8xyrho77.fsf_-_@ruckus.brouhaha.com> class x: pass z = x() z.a = 'a' d = {'a': z} for i in range(5): print id(d['a']) prints the same id 5 times as you'd expect. d = shelve('filename') d['a'] = z for i in range(5): print id(d['a']) prints five different id's. So, for example, y = d['a'] y.x = 'x' fails to update the shelve. The reason is sort of understandable but I hadn't guessed it ahead of time (I'd actually forgotten that d wasn't a normal dict, which you're supposed to be able to do if abstraction works properly), and it caused a bug in my program that took a little while to figure out. I wonder if some fix is possible. From michaelparkin at gmail.com Tue Aug 2 06:43:30 2005 From: michaelparkin at gmail.com (michaelparkin at gmail.com) Date: 2 Aug 2005 03:43:30 -0700 Subject: HTTPSConnection & Password Message-ID: <1122979410.592297.239230@g43g2000cwa.googlegroups.com> Hi, I'm using httplib to create a mutually authenticated HTTPS connection with a server. I create the connection as follows: c = httplib.HTTPSConnection(uri, key_file = key, cert_file = cert) However, because I am using a private key I keep getting asked to enter the password to open that key every time I run the script. I've had a dig around and can't seem to find a way of specifying the password so that the user can supply it on the command line, or so I can script/fully automate these connections. The ideal scenario would be to be able to specify the password on the command line like in curl/pyCurl How can I set the password for the private key so it doesn't keep asking me for it? Appologies if I've missed something obvious here. Thanks, Michael. p.s. I need to use httplib (rather than pyCurl) as I need to be able to specify methods other than GET and POST in my requests to the server. From tjreedy at udel.edu Fri Aug 19 18:45:24 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Aug 2005 18:45:24 -0400 Subject: Python jobs (was Re: Python for Webscripting (like PHP)) References: <312cfe2b0508190821715fb488@mail.gmail.com> Message-ID: "Gregory Pi?ero" wrote in message news:312cfe2b0508190821715fb488 at mail.gmail.com... >I'd love Python work, just like everyone else here. On a related topic, >what's the >policy/etiquette of posting a resume on here, or mentioning >what kind of work >you're looking for? I would take absence of such postings, even though you can imagine *lots* of people have had the same idea, as an indication that it is against policy/etiquette. If 1 person does it, we could easily have 10 or 100 a day ;-). > And what's the policy in general for most newsgroups and mailing lists? For mainline newsgroups, such as the comp.*, commercial annoucements are generally counter-indicated unless the name (.marketplace) or charter say otherwise. Exceptions would be a low volume of things of direct and narrow interest. So I consider the rare job announcements posted here ok. The same for book announcements. In either case, such are positive news for what is still a minority, just becoming mainstream, language. Terry J. Reedy From jepler at unpythonic.net Thu Aug 4 19:15:37 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 4 Aug 2005 18:15:37 -0500 Subject: Parallel arithmetic? In-Reply-To: <42f298d6$1_5@alt.athenanews.com> References: <42f298d6$1_5@alt.athenanews.com> Message-ID: <20050804231537.GC19009@unpythonic.net> If you use numarray, you *can* write c = a-b >>> import numarray >>> a = numarray.array([1,2,3]) >>> b = numarray.array([5,0,2]) >>> c = a-b >>> c array([-4, 2, 1]) numarray is packaged separately from Python. http://www.stsci.edu/resources/software_hardware/numarray Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From peter at somewhere.com Wed Aug 31 09:49:51 2005 From: peter at somewhere.com (Peter Maas) Date: Wed, 31 Aug 2005 15:49:51 +0200 Subject: .pth files in working directory In-Reply-To: References: Message-ID: Michael Ekstrand schrieb: > If top/ is the working directory for your Python interpreter, the > problem is solved automatically. Python puts the current working > directory in the default search path. So, if you run IIS sets the the site path as working directory. So I would probably have to change wd at the beginnig of every module. Each module would read the top location from a .pth file in its directory. Yes that's possible. Thanks for your help. -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From fredrik at pythonware.com Mon Aug 22 07:53:46 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 13:53:46 +0200 Subject: Python for Webscripting (like PHP) References: Message-ID: Alessandro Bottoni wrote: > (Python has even been told to be used by Yahoo! and Google, among others, > but nobody was able to demonstrate this, so far) hint: http://mail.google.com/support/bin/answer.py?answer=6554 From http Mon Aug 1 02:47:17 2005 From: http (Paul Rubin) Date: 31 Jul 2005 23:47:17 -0700 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87vf2ryrk1.fsf@wilson.rwth-aachen.de> <7xvf2rync2.fsf@ruckus.brouhaha.com> <87r7dfymy1.fsf@wilson.rwth-aachen.de> <7xmzo25zmm.fsf@ruckus.brouhaha.com> <877jf6yzc3.fsf@wilson.rwth-aachen.de> Message-ID: <7xu0iacfwq.fsf@ruckus.brouhaha.com> Torsten Bronger writes: > > No it's not on Fedora, at least FC3. > > It may not be on a DVD but the RPMs are avaiable where Fedora should > look for them. > > > I had huge trouble trying to build it and gave up. > > It's perfectly okay if you are used to build everything yourself but > this is a quite untypical approach. I think my approach is in some sense completely typical: I don't want to install ANYTHING, EVER. I've described this before. I want to buy a new computer and have all the software I'll ever need already on the hard drive, and use it from that day forward. By the time the software is obsolete and I want new stuff, the hardware is also obsolete, so I buy another new computer and start over. This is the way most non-technical use their computers (Wintel boxes with MS Office pre-installed), but then I don't get Python or much other development stuff Buying a Macintosh would maybe accomplish the above for me better than wintel (i.e. it comes with dev stuff including Python), but somewhat less typically, I also want access to all the source code, so I run Linux on an x86 box. That means I approximate my zero-install desire by starting with an empty hard drive and plopping in the FC3 (or now FC4) DVD and clicking "install everything" just once at setup time. After that, if I absolutely have to install anything, I consider it an exceptional situation and so I want to compile from source, not unpack a binary. From fredrik at pythonware.com Tue Aug 23 00:41:42 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Aug 2005 06:41:42 +0200 Subject: Best way to 'touch' a file? References: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Message-ID: Peter Hansen wrote: > You've quoted selectively. He also said "Unix-style 'touch'", from > which one could quite legitimately infer nope. read his post again. From spiralx at gmail.com Fri Aug 26 05:42:04 2005 From: spiralx at gmail.com (James) Date: Fri, 26 Aug 2005 10:42:04 +0100 Subject: classes and list as parameter, whats wrong? In-Reply-To: <20050826093420.GC23815@hep.physik.uni-siegen.de> References: <20050826093420.GC23815@hep.physik.uni-siegen.de> Message-ID: <7ee3dcd80508260242717153fb@mail.gmail.com> No, the default paramter LL is only ever created once, not reinitialised every time the constructor is called - this is quite a common gotcha! You want to do something like: class cClass: """ Base class to handle playlists, i.e. the files, the name, etc. """ def __init__(self, LL=None): if LL == None: LL = [] self.list=LL def addFile(self,L): self.list.append(L) James On 8/26/05, Dirk Zimmermann wrote: > Hi! > > I have a problem in a program. And I don't understand what is going on. > I can code something, that the "error" doesn't occur anymore. But I > still don't know the reason and this is unsatisfactory: Did I understood > something wrong or is there a bug? To make it short, I boiled down the > program to the crucial part. It looks like this: > > ----------- START ------------ > #!/usr/bin/env python > > class cClass: > """ Base class to handle playlists, i.e. the files, the name, etc. """ > def __init__(self, LL=[]): > self.list=LL > def addFile(self,L): > self.list.append(L) > > def main(): > l1 = ['a','b','c'] > lNames=['n1','n2','n3'] > for name in lNames: > objC=cClass() > for each in l1: > objC.addFile(each) > print objC.list > del objC > > if __name__ == "__main__": > main() > ----------- END ---------------- > > If I start it, I get the following output: > > ['a', 'b', 'c'] > ['a', 'b', 'c', 'a', 'b', 'c'] > ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c'] > > > Why does this list grow? I thought, with every new instance the list LL > is set to []? > > How can bring light in this? > > > Best, > Dirk > > > -- > http://mail.python.org/mailman/listinfo/python-list > From adamtj at adamtj.org Sun Aug 28 19:29:22 2005 From: adamtj at adamtj.org (Adam Tomjack) Date: Sun, 28 Aug 2005 18:29:22 -0500 Subject: Question In-Reply-To: <1125270985.457418.17830@g44g2000cwa.googlegroups.com> References: <1125270985.457418.17830@g44g2000cwa.googlegroups.com> Message-ID: <431248D2.9070508@adamtj.org> Double clicking python.exe will give you the command line version. To run IDLE, click Start -> Programs -> Python 2.x -> IDLE. pythonw.exe is useful for running GUI scripts. In Windows there are two types of programs: command line and gui programs. python.exe is the command line version. Suppose you write a Tk or a wxWindows program with python and you save it to a file. You can still use python.exe to run that gui program, but it'll open an extra black window with nothing in it. That's what pythonw.exe is for. It can't give you a command line (which is why it disappears right away when you double click it), but it also doesn't open than extra window when you use it to run a gui application. Adam Beginner/Not Yet Programmer wrote: > I've never programmed before, so I thought I'd try and learn a bit by > using some Python tutorials. I started using the tutorial at > http://www.honors.montana.edu/~jjc/easytut/easytut/node3.html. It > mentioned different forms of Python, specifically Command Line and > IDLE. Being inexperienced, I'm not sure how to change from Command > Line to IDLE, and I'm not sure which one I'm in when I start up the > program. In my Python folder, the only applications I have are > python.exe and pythonw.exe. Pythonw.exe won't run. So, I run > python.exe, and I'm not sure whether it is IDLE, Command Line, or > neither. Also, I'm unsure of how to save programs, considering when I > run python.exe, it opens up a window which does not have the little bar > with the "File", "Edit", "View" and "Help" buttons on it. If you can > help me out at all, thank you. > From fakeaddress at nowhere.org Sat Aug 27 04:08:47 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 27 Aug 2005 08:08:47 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> Message-ID: Steve Holden wrote: > Bryan Olson wrote: >> [...] I see no good reason for the following >> to happily print 'y'. >> >> s = 'buggy' >> print s[s.find('w')] >> >> > Before using the result you always have to perform >> > a test to discriminate between the found and not found cases. So I >> don't >> > really see why this wart has put such a bug up your ass. >> >> The bug that got me was what a slice object reports as the >> 'stop' bound when the step is negative and the slice includes >> index 0. Took me hours to figure out why my code was failing. >> >> The double-meaning of -1, as both an exclusive stopping bound >> and an alias for the highest valid index, is just plain whacked. >> Unfortunately, as negative indexes are currently handled, there >> is no it-just-works value that slice could return. >> >> > If you want an exception from your code when 'w' isn't in the string you > should consider using index() rather than find. That misses the point. The code is a hypothetical example of what a novice or imperfect Pythoners might have to deal with. The exception isn't really wanted; it's just vastly superior to silently returning a nonsensical value. > Otherwise, whatever find() returns you will have to have an "if" in > there to handle the not-found case. > > This just sounds like whining to me. If you want to catch errors, use a > function that will raise an exception rather than relying on the > invalidity of the result. I suppose if you ignore the real problems and the proposed solution, it might sound a lot like whining. -- --Bryan From zwerschke at zuv.uni-heidelberg.de Wed Aug 3 12:14:06 2005 From: zwerschke at zuv.uni-heidelberg.de (Christoph Zwerschke) Date: Wed, 03 Aug 2005 18:14:06 +0200 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> <42efe1ec$0$3713$626a14ce@news.free.fr> <42efe330$0$3713$626a14ce@news.free.fr> Message-ID: >> - unittest is for *unit* testing (only) ;-) > Why would you say that? We've used it extensively for a wide ranging... That was actually only a quote from this thread that summarizes some of the answers I got: unittest has no support for "global" fixtures, because it is intended for unit testing, not for global tests. > What, and break all the code that currently does "import unittest"? Just insert the two words "punit as" between "import" and "unittest", and the code will run as before... -- Christoph From nospam at nospam.com Mon Aug 22 00:24:09 2005 From: nospam at nospam.com (42) Date: Mon, 22 Aug 2005 04:24:09 GMT Subject: Sandboxes References: <38SdnUU_VbGFkZTeRVn-qA@powergate.ca> Message-ID: In article <38SdnUU_VbGFkZTeRVn-qA at powergate.ca>, peter at engcorp.com says... > 42 wrote: > > Thoughts? Still gaping holes? > > Certainly. And rather than rehash them all here, I'm going to suggest > you check the comp.lang.python archives for any of the many past > discussions about this before you spend too much time thinking > (repeatedly) that you've nailed that one last hole only to have somebody > point out yet another way around it. > > -Peter > Fair enough. I'm more or less ready to 'give up' on this fantasy of python in a sandbox. I'll either use something else, or just accept the risk. :) But for what its worth, I *am* curious what sorts of holes persist. I did try googling the archives, but with no idea what I'm looking for -- python security brings up a mess of unrelated issues... Python in Apache, rexec/bastion stuff, xss, issues with infinite loops and many other 'security' issues that might be relevant to someone running python on a web server where you have to be concerned about DOS but not of any concern to me... and so on and so forth. Can you, or someone, at least give me a few keywords I should be looking for that will bring matches for the sorts of attachs you've hinted at? Mostly just to satisfy my curiousity. -regards, Dave From kbk at shore.net Mon Aug 22 14:37:54 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Mon, 22 Aug 2005 14:37:54 -0400 (EDT) Subject: Weekly Python Patch/Bug Summary Message-ID: <200508221837.j7MIbsHG031701@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 352 open ( +0) / 2898 closed ( +2) / 3250 total ( +2) Bugs : 926 open (+13) / 5177 closed (+15) / 6103 total (+28) RFE : 190 open ( -1) / 179 closed ( +1) / 369 total ( +0) New / Reopened Patches ______________________ fix smtplib when local host isn't resolvable in dns (2005-08-12) http://python.org/sf/1257988 opened by Arkadiusz Miskiewicz tarfile: fix for bug #1257255 (2005-08-17) http://python.org/sf/1262036 opened by Lars Gust?bel Patches Closed ______________ sha256 module (2004-04-14) http://python.org/sf/935454 closed by greg sha and md5 modules should use OpenSSL when possible (2005-02-12) http://python.org/sf/1121611 closed by greg New / Reopened Bugs ___________________ Significant memory leak with PyImport_ReloadModule (2005-08-11) http://python.org/sf/1256669 opened by Ben Held slice object uses -1 as exclusive end-bound (2005-08-11) http://python.org/sf/1256786 opened by Bryan G. Olson tarfile local name is local, should be abspath (2005-08-12) http://python.org/sf/1257255 opened by Martin Blais Encodings iso8859_1 and latin_1 are redundant (2005-08-12) http://python.org/sf/1257525 opened by liturgist Solaris 8 declares gethostname(). (2005-08-12) http://python.org/sf/1257687 opened by Hans Deragon error message incorrectly claims Visual C++ is required (2005-08-12) http://python.org/sf/1257728 opened by Zooko O'Whielacronx Make set.remove() behave more like Set.remove() (2005-08-12) CLOSED http://python.org/sf/1257731 opened by Raymond Hettinger tkapp read-only attributes (2005-08-12) http://python.org/sf/1257772 opened by peeb gen_send_ex: Assertion `f->f_back ! (2005-08-12) CLOSED http://python.org/sf/1257960 opened by Neil Schemenauer http auth documentation/implementation conflict (2005-08-13) http://python.org/sf/1258485 opened by Matthias Klose "it's" vs. "its" typo in Language Reference (2005-08-14) CLOSED http://python.org/sf/1258922 opened by Wolfgang Petzold Makefile ignores $CPPFLAGS (2005-08-14) http://python.org/sf/1258986 opened by Dirk Pirschel Tix CheckList 'radio' option cannot be changed (2005-08-14) http://python.org/sf/1259434 opened by Raymond Maple subprocess: more general (non-buffering) communication (2005-08-15) http://python.org/sf/1260171 opened by Ian Bicking __new__ is class method (2005-08-16) http://python.org/sf/1261229 opened by Mike Orr import dynamic library bug? (2005-08-16) http://python.org/sf/1261390 opened by broadwin Tutorial doesn't cover * and ** function calls (2005-08-16) http://python.org/sf/1261659 opened by Brett Cannon precompiled code and nameError. (2005-08-17) http://python.org/sf/1261714 opened by Vladimir Menshakov minidom.py alternate newl support is broken (2005-08-17) http://python.org/sf/1262320 opened by John Whitley fcntl.ioctl have a bit problem. (2005-08-18) http://python.org/sf/1262856 opened by Raise L. Sail typo on "SimpleXMLRPCServer Objects" (2005-08-18) CLOSED http://python.org/sf/1263086 opened by Chad Whitacre type() and isinstance() do not call __getattribute__ (2005-08-19) http://python.org/sf/1263635 opened by Per Vognsen IDLE on Mac (2005-08-18) http://python.org/sf/1263656 opened by Bruce Sherwood PyArg_ParseTupleAndKeywords doesn't handle I format correctl (2005-08-19) CLOSED http://python.org/sf/1264168 opened by John Finlay PEP 8 uses wrong raise syntax (2005-08-20) CLOSED http://python.org/sf/1264666 opened by Steven Bethard sequence slicing documentation incomplete (2005-08-20) http://python.org/sf/1265100 opened by Steven Bethard lexists() is not exported from os.path (2005-08-22) CLOSED http://python.org/sf/1266283 opened by Martin Blais Mistakes in decimal.Context.subtract documentation (2005-08-22) http://python.org/sf/1266296 opened by Jim Sizelove Bugs Closed ___________ smtplib and email.py (2005-08-03) http://python.org/sf/1251528 closed by rhettinger float('-inf') (2005-08-09) http://python.org/sf/1255395 closed by tjreedy Make set.remove() behave more like Set.remove() (2005-08-12) http://python.org/sf/1257731 closed by rhettinger gen_send_ex: Assertion `f->f_back ! (2005-08-12) http://python.org/sf/1257960 closed by pje IOError after normal write (2005-08-04) http://python.org/sf/1252149 closed by tim_one IOError after normal write (2005-08-04) http://python.org/sf/1252149 deleted by patrick_gerken "it's" vs. "its" typo in Language Reference (2005-08-14) http://python.org/sf/1258922 closed by birkenfeld hotshot.stats.load (2004-02-19) http://python.org/sf/900092 closed by bwarsaw typo on "SimpleXMLRPCServer Objects" (2005-08-18) http://python.org/sf/1263086 closed by doerwalter PyArg_ParseTupleAndKeywords doesn't handle I format correctl (2005-08-19) http://python.org/sf/1264168 closed by birkenfeld PEP 8 uses wrong raise syntax (2005-08-20) http://python.org/sf/1264666 closed by goodger list(obj) can swallow KeyboardInterrupt (2005-07-21) http://python.org/sf/1242657 closed by rhettinger container methods raise KeyError not IndexError (2005-08-01) http://python.org/sf/1249837 closed by rhettinger zip incorrectly and incompletely documented (2005-02-12) http://python.org/sf/1121416 closed by rhettinger bz2 RuntimeError when decompressing file (2005-04-27) http://python.org/sf/1191043 closed by birkenfeld lexists() is not exported from os.path (2005-08-22) http://python.org/sf/1266283 closed by birkenfeld RFE Closed __________ md5 and sha1 modules should use openssl implementation (2004-06-30) http://python.org/sf/983069 closed by greg From tomi.kyostila at gmail.com Wed Aug 3 05:36:33 2005 From: tomi.kyostila at gmail.com (=?ISO-8859-1?Q?Tomi_Ky=F6stil=E4?=) Date: Wed, 03 Aug 2005 12:36:33 +0300 Subject: Python Programming Contest: First results In-Reply-To: References: <1121838061.749455.44630@g14g2000cwa.googlegroups.com> <42DE18B2.903@sweetapp.com> <42EF352D.2060702@sweetapp.com> Message-ID: Brian Quinlan wrote: > Brian Quinlan wrote: > >> Tomi Ky?stil? wrote: >> >> Why don't I see my solution (__author__ = "dOb") in the results? I'm >> sure that you got it as you replied to my mail. > > > Your solution is now included. See: > http://www.sweetapp.com/pycontest/contest1/results.html > > Good job! > > Cheers, > Brian Thanks! :) Any idea when the next competition is coming? (it hasn't been quite weekly as you hoped, eh? ;) -- dOb From saint.infidel at gmail.com Tue Aug 9 12:00:42 2005 From: saint.infidel at gmail.com (infidel) Date: 9 Aug 2005 09:00:42 -0700 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: <1123603242.709888.24950@g44g2000cwa.googlegroups.com> > in Python equality rebinds the name Assignment (=) rebinds the name. Equality (==) is something else entirely. From nephish at xit.net Thu Aug 18 13:15:15 2005 From: nephish at xit.net (nephish at xit.net) Date: 18 Aug 2005 10:15:15 -0700 Subject: question about binary and serial info In-Reply-To: <11g9evhkjbanncb@corp.supernews.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> Message-ID: <1124385315.645206.285740@o13g2000cwo.googlegroups.com> i have an ascii string comming in the serial port and i need to convert it to something else, like an integer, or binary, or even a hex so i can use the bitwise comparison on it. thanks From hancock at anansispaceworks.com Fri Aug 26 22:27:58 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 26 Aug 2005 21:27:58 -0500 Subject: Language translation possible in python? In-Reply-To: References: <1124886682.990555.133180@g14g2000cwa.googlegroups.com> <003301c5a972$21bd30e0$5700a8c0@rmse> Message-ID: <200508262127.58517.hancock@anansispaceworks.com> On Friday 26 August 2005 04:15 pm, Terry Reedy wrote: > "Jon Monteleone" wrote in message > news:003301c5a972$21bd30e0$5700a8c0 at rmse... > >I have a program that currently displays all of its messages and > >instructions in only > > English. My boss wants me to change it all to Korean. Is there a python > > module that will > > automatically translate my English to Korean? > > You could write something that autosubmitted things to a translation site > like babelfish, Or just catenate all strings into one text and submit that. That would be silly, though. ;-) > There is a system (that I have not used) for internaionalizing code that > keeps messages to be translated in a separate resource file. Name excapes > me at the moment though. I think you are looking for gettext. Check out the gettext module in Python, and do a little googling for "I18N" / "Internationalization" and/or "L14N" / "Localization" . That will probably turn up some how-tos for dealing with po files, etc. If you really want to throw caution to the wind and trust an auto-translation site instead of just finding someone who speaks fluent Korean and enough English, then you *could* send each of the statements in the *po* file through the translator and collect the responses. But if your boss wants this; you can ask the question here; and you can understand your boss, then you must have *someone* in your organization who speaks both languages, surely? Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From petr at tpc.cz Tue Aug 30 06:18:26 2005 From: petr at tpc.cz (McBooCzech) Date: 30 Aug 2005 03:18:26 -0700 Subject: time.mktime problem Message-ID: <1125397106.854442.227120@g44g2000cwa.googlegroups.com> Hi, on Linux (Fedora FC4) and Python 2.4.1 I am trying to know the time delta in seconds between two times given in the HHMMSS format. My code looks like: import datetime, time ta1=(time.strptime('000001', '%H%M%S')) ta2=(time.strptime('230344', '%H%M%S')) t1=time.mktime(ta1) t2=time.mktime(ta2) print t1, t2 -2147483648.0 -2147483648.0 I just can not figure out, why the t1 and t2 are the same? Thanks for your comments Petr Jakes From hikenboots at gmail.com Tue Aug 23 17:12:00 2005 From: hikenboots at gmail.com (John F.) Date: 23 Aug 2005 14:12:00 -0700 Subject: Twisted Conch for emulating a terminal? Message-ID: <1124831520.619206.77220@g49g2000cwa.googlegroups.com> I'm trying to figure out how to emulate a terminal with twisted conch (I want to be able to send the client information with the 'write' command in freebsd). I have played with ssshsimpleclient.py on the twistedmatrix site and it works but I need to keep the connection open, not just execute a single command and exit. Can someone point me to some sample code or provide some advice? Thanks. From rohit at careernet.co.in Fri Aug 26 07:29:08 2005 From: rohit at careernet.co.in (Rohit, Careernet) Date: Fri, 26 Aug 2005 16:59:08 +0530 Subject: Opportunity in Open-Source Development Message-ID: <036001c5aa35$d37fbdc0$d40ba8c0@Rohit> Hi Madhu, I came across your reference on the net and wanted to get in touch with you regarding an interesting possibility in the open-source space. We are working with one of our client, which is starting its engineering operations in Bangalore. The focus is on building open source solutions. The challenge for open source software is to provide the chain of accountability that IT organizations require for mission-critical systems. Open source offers direct access to source code and the engineers who wrote it, but the availability and cost of accessing such expert support varies widely. Enterprise IT customers need on-demand support, up-to-date documentation, and extreme reliability. Our client offers integrated, validated, and certified open source stacks with ongoing maintenance and enterprise-class support services. It also offers open source interoperability testing and management tools. They value and honor the efforts of the open source community, and are proud to contribute by extending open source efforts and by productizing open source solutions. This makes open source even more reliable, easy, and safe to deploy. I would like to discuss this opportunity with you in detail. Please let me know if I can reach you on any number to discuss this. You can reach me at +91-9880731941 Looking forward to your response. Regards, Rohit +91-9880731941 Contact us: CareerNet at vsnl.com Visit us at www.careernet.co.in BANGALORE CareerNet Technologies Pvt. Ltd # 8, SBI Colony, 7th "A" Main 3rd Block, Koramangala ( On Sarjapur Road). Bangalore -- 560 034. Voice :+91-80-51991599 (Board Number) HYDERABAD Plot #60, Chikoti Gardens, Begumpet, Hyderabad. Voice: +91-40-55332825. +91-93464-86575. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bill.mill at gmail.com Thu Aug 4 15:56:47 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 4 Aug 2005 15:56:47 -0400 Subject: sample code for parsing html file to get contents of td fields In-Reply-To: <1123181678.144557.93100@g49g2000cwa.googlegroups.com> References: <1123181678.144557.93100@g49g2000cwa.googlegroups.com> Message-ID: <797fe3d405080412562ffce90c@mail.gmail.com> On 4 Aug 2005 11:54:38 -0700, yaffa wrote: > does anyone have sample code for parsting an html file to get contents > of a td field to write to a mysql db? even if you have everything but > the mysql db part ill take it. > Do you want something like this? In [1]: x = "something

something elsein a td(.*?)
' > print '

' > print 'Differences %s: %s' % (htypestr, lbl1) > if html: > ... I'd create two Formatter classes, one for HTML and one for text. It looks like, in your case, the HTML one should inherit from the text one. Something like: py> class TextFormatter(object): ... def print_differences(self, htypestr, lbll): ... print 'Differences %s: %s' % (htypestr, lbll) ... py> class HTMLFormatter(TextFormatter): ... def print_differences(self, htypestr, lbll): ... print '' ... print '' ... print '

' ... super(HTMLFormatter, self).print_differences(htypestr, lbll) ... print '

' ... py> formatter = TextFormatter() py> formatter.print_differences('test', 'one') Differences test: one py> formatter = HTMLFormatter() py> formatter.print_differences('test', 'one')

Differences test: one

Using this strategy, you would replace all your print statements with calls to a formatter object. Which formatter you use would be determined wherever you currently set 'html' to True or False. HTH, STeVe From sybrenUSE at YOURthirdtower.com.imagination Thu Aug 25 09:41:51 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Thu, 25 Aug 2005 15:41:51 +0200 Subject: variable hell References: <430dc538@127.0.0.1> Message-ID: Nx enlightened us with: > I am unpacking a list into variables, for some reason they need to > be unpacked into variable names like a0,a1,a2....upto aN whatever is > in the list. You're probably doing things the wrong way. What is your ultimate goal with this? There is probably a better way of doing it. In the mean time, look at eval(). Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From finite.automaton at gmail.com Thu Aug 4 19:07:41 2005 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 4 Aug 2005 16:07:41 -0700 Subject: Parallel arithmetic? References: <42f298d6$1_5@alt.athenanews.com> Message-ID: <1123196861.716743.222640@f14g2000cwb.googlegroups.com> There are many ways to do this. None of them avoids looping, technically, although you can easily avoid the "for" syntax. -- Simple but wastes some memory c = [i-j for i,j in zip(a,b)] -- Using itertools.izip (python 2.3) c = [i-j for i,j in itertools.izip(a,b) ] -- Generator expression (python 2.4) c = ( i-j for i,j in itertools.izip(a,b) ) From fabioz at esss.com.br Tue Aug 30 12:46:11 2005 From: fabioz at esss.com.br (Fabio Zadrozny) Date: Tue, 30 Aug 2005 13:46:11 -0300 Subject: ANN: PyDev 0.9.8 released In-Reply-To: <4314793b$0$27314$edfadb0f@dread12.news.tele.dk> References: <42A720BD.5050701@esss.com.br> <42C175A5.5000206@esss.com.br> <42E6412A.4020905@esss.com.br> <430632E3.9050403@esss.com.br> <4314793b$0$27314$edfadb0f@dread12.news.tele.dk> Message-ID: <43148D53.2060206@esss.com.br> Hi Max, I may be a little (or maybe a lot) biased for it (as I'm its maintainer), but as I do 'eat my own dogfood', I though I might share it with you... At my company, everybody that programs with python switched to pydev. Most people used 'highly customized' text-editors before pydev, as the company does not enforce one ambient for all... still, everybody changed to pydev, coming from vi, scintilla, komodo... and we have some really big projects (my current ambient has about 400 python modules, all managed in pydev). Also, there are no current bug reports for any instability in pydev. Well, anyway, I would like to know other opinions in pydev too... as I said, I might bee too biased towards it :-) Cheers, Fabio Max M wrote: >Fabio Zadrozny wrote: > > >>Hi All, >> >>PyDev - Python IDE (Python Development Enviroment for Eclipse) version >>0.9.8 has just been released. >> >> > > >I read this, and thought it was time to check out both Eclipse, end the >pydev plugin. > >I got it all installed, along with a subversion plugin for eclipse, and >it actually seems like a very sweet combo. > >I was afraid that a Java based editor would be sluggish. But it doesn't >seem so. > >There are a few nice features too with a file navigator, refactoring, >code folding and more. > >So I have decided to give it a try. But before commiting to it, I just >wondered what experiences other users might have when using it for >production. Being that my text editing environment is my bread and butter. > >Is it stable/effective etc? > >Anybody cares to share? > > > -- Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br PyDev - Python Development Enviroment for Eclipse pydev.sf.net pydev.blogspot.com From christoph.rackwitz at gmail.com Sun Aug 14 11:02:16 2005 From: christoph.rackwitz at gmail.com (Christoph Rackwitz) Date: 14 Aug 2005 08:02:16 -0700 Subject: How can I exclude a word by using re? References: Message-ID: <1124031736.367193.219920@g44g2000cwa.googlegroups.com> re.findall('(.*)hello|(.*)', 'hi, how are you. hello') re.findall('(.*)hello|(.*)', 'hi, how are you. ello') take a look at the outputs of these. From francois.perche at gmail.com Sat Aug 13 12:37:15 2005 From: francois.perche at gmail.com (perchef) Date: 13 Aug 2005 09:37:15 -0700 Subject: wx.MessageDialog displayed without components inside Message-ID: <1123951035.856439.173160@g44g2000cwa.googlegroups.com> Is there a reason why a wx.MessageDialog would be displayed without components inside ? this : md = wx.MessageDialog(None,'foo','bar',wx.YES_NO) result = md.ShowModal() md.Destroy() In my application, give me : http://img252.imageshack.us/my.php?image=messagedialog6nw.jpg This isn't a bug in wxPython because when I use the same code in pyshell I obtain the expected result. So, there must be a reason but I can't figure out why. Thanks. From spam.csubich+block at block.subich.spam.com Tue Aug 9 21:13:34 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 21:13:34 -0400 Subject: Does any one recognize this binary data storage format In-Reply-To: <11fijb6mu205l09@corp.supernews.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> <11fijb6mu205l09@corp.supernews.com> Message-ID: Grant Edwards wrote: > And I'll guarantee that the difference between 333-3333 and > 666-6666 has to be more than 1-bit. There's no way that can be > the correct data unless it's something like an index into a > different table or a pointer or something along those lines. Absolutely. I hadn't even taken a good look at those datapoints yet. The dataset that I'd like to see: 000-000-0001 000-000-0010 (etc) 000-000-0002 000-000-0004 000-000-0008 000-000-0016 (etc) I also wonder if the last 8-16 bits involves, at least in part, a count of the length of the phone number, or at least a flag to distinguish 7 from 10 digits. From sjmachin at lexicon.net Sun Aug 14 23:47:08 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Aug 2005 13:47:08 +1000 Subject: Spaces and tabs again In-Reply-To: <43000E8B.4030603@redlinepy.com> References: <1123927648.058674.213380@g44g2000cwa.googlegroups.com> <1123964301.854778.172680@g49g2000cwa.googlegroups.com> <6spsf1hr7i0ho9fa0ptauhst1s61jkig13@4ax.com> <43000262.7050209@redlinepy.com> <43000838@news.eftel.com> <43000E8B.4030603@redlinepy.com> Message-ID: <4300103b@news.eftel.com> Paul Watson wrote: > John Machin wrote: > >> Paul Watson wrote: >> >>> Dan Sommers wrote: >>> >>>> On Sun, 14 Aug 2005 01:04:04 GMT, >>>> Dennis Lee Bieber wrote: >>>> >>>> >>>>> On 13 Aug 2005 13:18:21 -0700, sigzero at gmail.com declaimed the >>>>> following >>>>> in comp.lang.python: >>>> >>>> >>>> >>>> >>>> >>>>>> Are you kidding? You are going to MANDATE spaces? >>>>>> >>>>> >>>>> After the backlash, Python 4.0 will ban leading spaces and require >>>>> tabs >>>> >>>> >>>> >>>> >>>> >>>> Why not petition the unicode people to include PYTHON INDENT and PYTHON >>>> DEDENT code points, and leave the display up to the text editors? ;-) >>>> >>>> Regards, >>>> Dan >>> >>> >>> >>> >>> The Unicode people will correctly point out that there is already a >>> Unicode codepoint assignment which can be used for this purpose. It >>> is even in the BMP portion of the C0 controls group. >>> >>> 0009 = HORIZONTAL TABULATION >> >> >> >> and how do you use this to get the DEDENT effect? Use something out of >> the bidirectional kit? E.g. RLO then tab then PDF ;-) > > > The use of one less HORIZONTAL TABULATION on a line in relation to the > number of HORIZONTAL TABULATION codepoints used by the pervious line > indicated "dedent" as you call it. :-) > > There are things about your suggestion that would be great! It would > require a language aware editing tool to be used. Like HTML was > intended, the rendering of the program source would be managed by the > tool. Everyone could choose the style in which they would like to > interact with the code. > > This is also the biggest problem. It would mean that a specialized > editor tool would be required. One could not just use a POTE (Plain Old > Text Editor). > > Using U+0009 HORIZONTAL TABULATION would provide both user selectable > rendering style as well as access through most existing tools. > > Of course, there is always 'expand' and 'unexpand' if you are really > desparate. OK Paul, you've convinced me. I look forward to your PEP "Mandated U+0009 HORIZONTAL TABULATION in Python source". Cheers, John From wojciech_mula at poczta.null.onet.pl.invalid Fri Aug 5 14:02:06 2005 From: wojciech_mula at poczta.null.onet.pl.invalid (Wojciech Mula) Date: Fri, 5 Aug 2005 18:02:06 +0000 (UTC) Subject: Suggestions for optimizing my code References: <1123263231.010703.88990@z14g2000cwz.googlegroups.com> Message-ID: drife wrote: > [...] > for row in range(len(Y)): > for col in range(0,row): In this case you should use 'xrange' instead 'range'. w. From mfaujour at yahoo.com Wed Aug 3 11:46:50 2005 From: mfaujour at yahoo.com (mfaujour) Date: Wed, 03 Aug 2005 15:46:50 -0000 Subject: socket and os.system Message-ID: I HAVE THIS PYTHON PROGRAMM: [test]$ cat socpb.py import BaseHTTPServer, SocketServer, os, socket, threading # the server initialisation server = SocketServer.TCPServer((socket.gethostname(), 8088),BaseHTTPServer.BaseHTTPRequestHandler) t=threading.Thread(target=server.serve_forever) t.setDaemon(1) t.start() # the command os.system("sleep 3600") [test]$ I LAUNCH IT: [test]$ python socpb.py [1]+ Stopped python socpb.py [test]$ bg [1]+ python socpb.py & I LOOK THE PORT IT USE --> OK: [test]$ netstat -taupe | grep 8088 tcp 0 0 test:8088 *:* LISTEN mik 32481 14092/python I KILL THE PYTHON PROGRAMM (OR IT STOP BY ANOTHER WAY): [test]$ kill 14092 [test]$ [1]+ Terminated python socpb.py I LOOK THE PORT --> NOK, I EXPECTED THAT THE PORT WAS FREED BUT SLEEP IS LISTENING AND IF I TRY TO LAUNCH MY PROGRAMM, IT FAIL: [test]$ netstat -taupe | grep 8088 tcp 0 0 test:8088 *:* LISTEN mik 32481 14094/sleep [test]$ python socpb.py Traceback (most recent call last): File "socpb.py", line 4, in ? server = SocketServer.TCPServer((socket.gethostname(), 8088),BaseHTTPServer.BaseHTTPRequestHandler) File "/usr/local/lib/python2.3/SocketServer.py", line 330, in __init__ self.server_bind() File "/usr/local/lib/python2.3/SocketServer.py", line 341, in server_bind self.socket.bind(self.server_address) File "", line 1, in bind socket.error: (98, 'Address already in use') IF I KILL THE SLEEP, ALL COME BACK FINE: [test]$ kill 14094 [test]$ netstat -taupe | grep 8088 [test]$ python socpb.py I HAVE SEARCHED ON THE WEB HOW TO LAUNCH THE SLEEP WHITHOUT IT GET THE PORT IN THE ENVIRONNEMENT BUT NOTHING... I HAVE A WORKAROUND BY USING rsh BUT I AM NOT VERY PLEASED WITH THAT. DOES SOMEONE HAS AN IDEA ? From http Fri Aug 12 15:56:41 2005 From: http (Paul Rubin) Date: 12 Aug 2005 12:56:41 -0700 Subject: Permutation Generator References: Message-ID: <7xr7cz3p52.fsf@ruckus.brouhaha.com> Talin writes: > I'm sure I am not the first person to do this, but I wanted to share > this: a generator which returns all permutations of a list: > > def permute( lst ): > if len( lst ) == 1: > yield lst > else: > head = lst[:1] > for x in permute( lst[1:] ): > yield head + x > yield x + head > return > > -- Talin Hmm: >>> for p in permute([1,2,3]): print p [1, 2, 3] [2, 3, 1] [1, 3, 2] [3, 2, 1] Oops. From gandalf at geochemsource.com Tue Aug 16 04:26:19 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Tue, 16 Aug 2005 10:26:19 +0200 Subject: zlib + Windows 32 service problem (ImportError) In-Reply-To: References: <43008D0D.4000509@geochemsource.com> Message-ID: <4301A32B.6070308@geochemsource.com> vincent wehren wrote: >"Laszlo Zsolt Nagy" schrieb im Newsbeitrag >news:mailman.3098.1124117300.10512.python-list at python.org... >| Sorry, I realized that the import zlib was not executed from my >| (working) service. >| So here is the question: why can't I use zlib from a win32 service? Is >| there any way to make it working? >| >| >------------- >| >Python could not import the service's module >| > File "T:\Python\Projects\NamedConnector\Service.py", line 17, in ? >| > from Processor import * >| > File "c:\Python\Projects\NamedConnector\Processor.py", line 35, in ? >| > from mess import MessageSocket >| > File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ? >| > import zlib >| >exceptions.ImportError: dynamic module does not define init function >| >(initzlib) >| >------------- >| >| >| >I had a similar problem where a zlib.dll that is *not a Python extension* is >in sys.path *before* zlib.pyd. Python will try to import this zlib.dll and >find the dll doesn't export a initzlib: >for more info see >http://mail.python.org/pipermail/python-list/2004-October/thread.html#248107 > > Thanks. I set my system environment variable 'PATH' to this: C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\GTK\2.0\bin Then I restarted my computer. It is still missing initzlib. :-( Please note that I can run the same program as an application, logged in as the same user. Les From daniel.dittmar at sap.corp Mon Aug 1 10:21:06 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Mon, 01 Aug 2005 16:21:06 +0200 Subject: Dabo in 30 seconds? In-Reply-To: References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> <200508010830.27322.ed@leafe.com> Message-ID: Cliff Wells wrote: > But then I'm willing to > actually work a little to get what I want. For other it seems they > won't be happy unless you drive to their house and install it for them To be fair to those slothes: some of them want to write software for a commercial setting where they have to install it on other peoples machines. So it isn't just getting it to work one one own's machine. Using a specifc Python library with external dependencies means also installing and *supporting* it on a possible large set of configurations. Daniel From tjreedy at udel.edu Sat Aug 27 03:59:08 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2005 03:59:08 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com><1124160882.554543.75730@g43g2000cwa.googlegroups.com><3ErPe.853$sV7.65@newssvr21.news.prodigy.com><7sJPe.573$MN5.131@newssvr25.news.prodigy.net><7xmzn41ofc.fsf@ruckus.brouhaha.com><878xyoe6m2.fsf@wilson.rwth-aachen.de> <7xslww10ur.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xslww10ur.fsf at ruckus.brouhaha.com... > Steve Holden writes: >> Of course. But onc you (sensibly) decide to use an "if" then there >> really isn't much difference between -1, None, () and sys.maxint as >> a sentinel value, is there? > > Of course there is. -1 is (under Python's perverse semantics) a valid > subscript. sys.maxint is an artifact of Python's fixed-size int > datatype, which is fading away under int/long unification, so it's > something that soon won't exist and shouldn't be used. None and () > are invalid subscripts so would be reasonable return values, unlike -1 > and sys.maxint. Of those, None is preferable to () because of its > semantic connotations. I agree here that None is importantly different from -1 for the reason stated. The use of -1 is, I am sure, a holdover from statically typed languages (C, in particular) that require all return values to be of the same type, even if the 'return value' is actually meant to indicat that there is no valid return value. Terry J. Reedy From florent.newsgroups at kynesthesy.org Wed Aug 3 05:44:17 2005 From: florent.newsgroups at kynesthesy.org (florent) Date: Wed, 03 Aug 2005 11:44:17 +0200 Subject: trying to parse non valid html documents with HTMLParser In-Reply-To: References: <42efc9ae$0$12924$636a15ce@news.free.fr> Message-ID: <42f091b8$0$3983$636a15ce@news.free.fr> > AFAIK not with HTMLParser or htmllib. You might try (if you haven't done > yet) htmllib and see, which parser is more forgiving. Thanks, I'll try htmllib. In other case, I found a solution. Feeding data to the HTMLParser by chunks extracted from the string using string.split("<"), will allow me to loose only one tag at a time when an exception is raised ! From godoy at ieee.org Mon Aug 1 08:39:09 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 01 Aug 2005 09:39:09 -0300 Subject: Dabo in 30 seconds? References: <7xr7de5zoe.fsf@ruckus.brouhaha.com> <200507311709.18243.jstroud@mbi.ucla.edu> Message-ID: <8ph1s2-rnn.ln1@strongwill.g2ctech> Ed Leafe wrote: > Should we have defensive code for every possible broken installation? We > use > a lot of the Python standard library modules, many dbapi-compliant > modules, and, of course, wxPython. If someone mis-installs one of the > pre-requisites, do you expect Dabo to catch that and present you with a > diagnostic message? I'm serious here: I want to know what people consider > acceptable for a software package that relies on other packages. If it doesn't interfere with my other custom options, catching unsatisfied requisites is interesting. But a helpful stack trace is enough for the developer. Just be sure to say that it was "this" or "that" requisite that generated the problem and that's it. Giving some references on how to fix the problem is a plus. But if you're going to check everything, you'll end up checking the whole system at each and every run -- because I might have added / removed packages since I installed Dabo -- what would give a big performance penalty. -- Jorge Godoy From fredrik at pythonware.com Tue Aug 30 07:48:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Aug 2005 13:48:10 +0200 Subject: variable hell References: <430debc5$0$25399$626a14ce@news.free.fr> <3n6ldtF2qhoU1@individual.net> <430e26c6$0$2092$626a14ce@news.free.fr> Message-ID: Steve Holden wrote: > Yes. A large part of learning a language is discovering the many idioms > that have already been established for doing certain things. These are a > kind of shorthand, established by long convention, that allow one to > avoid the "learning-by-use" curve. it's not obvious that the OP has found the pydiomatic way to solve his problem, though, given that most of this thread have been spent on playing with exec, and that Robert Kern's question from the be- ginning of this thread has still not been answered: "Again, why unpack them into separate variables when they are *already* in the form that you want to use them?" From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 31 04:13:10 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 31 Aug 2005 10:13:10 +0200 Subject: Bicycle Repair Man usability References: <1125439673.688666.264820@z14g2000cwz.googlegroups.com> Message-ID: Rex Eastbourne enlightened us with: > Are there any Bicycle Repair Man users here? I am. > I recently got PyDev for Eclipse, which comes with BRM. I use it from VIM. > I am disappointed with what I've seen, although I'm not sure if I'm > using its full functionality. Why would it need more functionality? > -Rename a function/variable > -Block of code --> method and a method call That seems nice to me. > -Get rid of extra variables by shifting them inline (e.g.: > a=1;b=2;c=a+b --> c=1+2) This is already excess functionality IMO. If you're programming like this and you want it to be replaced by 'c=1+2', you need to learn how to properly write software. No tool will help you in that. But hey, that's just my opinion. And I think it should be 'c=3' anyway ;-) Sometimes I use constructs as 'a, b = 1, 2' and 'c = a+b', but that's intensional. In such a case, 'a' and 'b' are settings that easily need to be edited, and 'c' is just a calculation on them. In such a case, I don't want to see 'c = 3' in my code. I use BRM if I need to rename a function or variable, and that's about it. I do the rest by hand faster than I can figure out how to use additional software. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From timothy at open-networks.net Tue Aug 2 18:35:33 2005 From: timothy at open-networks.net (Timothy Smith) Date: Wed, 03 Aug 2005 08:35:33 +1000 Subject: startfile problems In-Reply-To: References: Message-ID: <42EFF535.3080300@open-networks.net> Dennis Lee Bieber wrote: >On Tue, 02 Aug 2005 17:35:27 +1000, Timothy Smith > declaimed the following in comp.lang.python: > > > > >>it's iterally just >> >>PDFname = 'tmp.pdf' >>os.startfile(PDFname) >> >>thats the code. >> >> >> > No "import os"? > And the full traceback? > > > >>so obviously it contains no errnous characters. see my update btw. it >>actually DOES open the report, but throws up the exception as well. >> >> > > Must not have made it to my server yet, assuming it was posted >after my comment. > >import os > >PDFname = "test.pdf" >os.startfile(PDFname) > > No errors if I'm in the directory with the PDF when I execute >the program... > >E:\UserData\Dennis Lee Bieber\My Documents>script1.py > >E:\UserData\Dennis Lee Bieber\My Documents>python script1.py > >E:\UserData\Dennis Lee Bieber\My Documents> > > > > > yep the program is executed in the same dir as the pdf file. like i said it actually opens it, but throws up an exception as well. if i hadn't seen it with my own eyes i wouldn't believe it. From webmaster at sophos.com Thu Aug 25 12:24:33 2005 From: webmaster at sophos.com (webmaster at sophos.com) Date: Thu, 25 Aug 2005 11:24:33 -0500 (CDT) Subject: Protected message Message-ID: <200508251624.j7PGOV9h012845@il06exr03.mot.com> Your file is attached. From cbfalconer at yahoo.com Fri Aug 26 09:48:42 2005 From: cbfalconer at yahoo.com (CBFalconer) Date: Fri, 26 Aug 2005 13:48:42 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8391F6ogbU1@individual.net> Message-ID: <430EFFF1.404D2FFD@yahoo.com> usenet at isbd.co.uk wrote: > ... snip ... > > Same applies to most newsfeeds, depending on retention. If you > want to look a long way back in a thread, use Google Groups. Except for those anti-social zealots who use an X-noarchive header. -- "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 bob at passcal.nmt.edu Tue Aug 2 11:13:00 2005 From: bob at passcal.nmt.edu (Bob Greschke) Date: Tue, 2 Aug 2005 09:13:00 -0600 Subject: Tkinter, Menu(bar) font size References: Message-ID: Yeah. It works on a Sun and Linux, but not Windows. That stinks. We got a bunch of 1400x1050 display laptops in and now I have to run around changing a bunch of programs that looked fine on 1024x768 displays. Thanks! wrote in message news:mailman.2589.1122945053.10512.python-list at python.org... Tk tries to use the "native" menu control on Windows (and, I think, MacOS). One result seems to be that for the application's menu bar you can't change the font. Of course, Windows provides a way for users to select a uniform font for menu bars in all applications, in the Display control panel. Jeff From pydecker at gmail.com Sun Aug 7 08:42:52 2005 From: pydecker at gmail.com (Peter Decker) Date: Sun, 7 Aug 2005 08:42:52 -0400 Subject: Python -- (just) a successful experiment? In-Reply-To: <7xoe8a6q24.fsf@ruckus.brouhaha.com> References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> Message-ID: On 07 Aug 2005 02:42:43 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: > > I don't see why the things you talk about would have to be part of the > > main Python distribution. Ruby on Rails seems to do pretty well without > > being included with the core language. > > I haven't used Ruby on Rails but from the description I saw, its distro > includes everything needed, which I assume includes Ruby itself. Here you go again: making pronouncements without actually knowing what you are talking about. Just a few days ago you were trashing products like Dabo, because they use things that aren't in the standard distribution, and now you're approving of something like Rails because it has a Windows package that installs everything you need, including Ruby. Yet Dabo has had exactly the same thing for quite some time now on Windows: a standard Windows installer that gives you Python, wxPython, MySQLdb, kinterbasdb, etc., but you spent countless messages trashing Dabo and anyone who would consider using something like it, because it "wasn't in the standard distribution". > I have the impression that Zope is ungodly complex, and revolves around > a weird and nonstandard database instead of having an SQL interface. Wow, and I have the impression that you form opinions before you actually experience something. Isn't there a word for such a person? Hmmm..... -- # p.d. From fakeaddress at nowhere.org Wed Aug 10 01:37:01 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 10 Aug 2005 05:37:01 GMT Subject: Creating a virtual file system In-Reply-To: References: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> Message-ID: <1ogKe.1237$dk5.1053@newssvr21.news.prodigy.com> Jeff Schwab wrote: > I agree that you & I are probably discussing different things, but I > think this is exactly what the OP was seeking. He said: > > > I'm working on a project to implement a simple cross-platform file > > sharing protocol (using Python) that is similar to HTTP, and I > > have to write a GUI for Windows and Linux. > > Sure sounds like CIFS to me. > > > My question is: How do I implement a virtual partition that acts > > like a real file-system and is compleatly transparent to other > > programs? Should I make a virtual file allocation table for a > > FAT32 partition or simulate an NTFS? Or even further: How do I > > create a junction (or a hard link) to it in "My network places" or > > in "Entire Network"? > > CIFS is the canonical way to make resources show up in Network > Neighborhood. [...] Hmmm, you have a point. Looks like he has elements of both local file systems and networking protocols. To make his special filesystem transparent to MS-Windows programs is an installable- filesystem problem, which is what I was looking at. -- --Bryan From bokr at oz.net Tue Aug 2 13:18:21 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 02 Aug 2005 17:18:21 GMT Subject: Printing Docstrings Without Importing References: <1122746909.441941.226760@o13g2000cwo.googlegroups.com> <42ed90cf.273165611@news.oz.net> <1122904223.528701.55420@f14g2000cwb.googlegroups.com> Message-ID: <42efa671.409775095@news.oz.net> On 1 Aug 2005 06:50:23 -0700, "Fuzzyman" wrote: >This seems to scratch several people's itches. > >Care to develop/maintain it ? > Are you talking to me? ;-) (My news server is having some problem. I saw my post on google groups but my normal news client isn't seeing it.) Assuming you are talking to me, there's a bug, naturally, in trying to escape None as a doc string. It was twenty minutes of hacking and a half hour of trying to choose html colors, so there's not that much there ;-) But what did you have in mind? Javascript menu rollovers for popup docs of functions and classes and methods etc? Full help info access? Optional pdf output? That would take more than another hour, but I did fix the mentioned bug and put a table of clickable module names at the top with the file date stamps and paths so you can navigate down to the spcific module docstring output quickly if you have a lot of them. Of course, I think I'd put styling in the header rather than hack more raw html if I were to go another round. I'll post the latest once I can see my postings in context with my own newsreader again. Regards, Bengt Richter From enleverlesO.OmcO at OmclaveauO.com Tue Aug 16 19:12:10 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Wed, 17 Aug 2005 01:12:10 +0200 Subject: stopping a python windows service References: <1124230320.593335.288650@g44g2000cwa.googlegroups.com> Message-ID: <430272e4$0$916$8fcfb975@news.wanadoo.fr> Hi ! Use SC.exe (windows-XP) (with popen ?) For help : sc /? You can, also, try : qprocess /? tasklist /? taskkill /? etc. @-salutations Michel Claveau From nul at nul.be Fri Aug 12 12:02:36 2005 From: nul at nul.be (jan V) Date: Fri, 12 Aug 2005 16:02:36 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: > Xah is very well known as the resident troll in many NGs and his 'contributions' are less then useless. > > Best is to just ignore him. Did you know that some deranged people take sexual pleasure out of starting fires? Apparently some of the latest forest/bush fires in southern Europe were even started by firemen (with their pants down?). Maybe characters like Xah take some kind of sexual pleasure out of posting his kind of posts... the tought doesn't bear thinking, does it? From k33rni at gmail.com Tue Aug 23 10:34:15 2005 From: k33rni at gmail.com (k33rni at gmail.com) Date: 23 Aug 2005 07:34:15 -0700 Subject: yapsnmp port issues Message-ID: <1124807655.170230.144200@f14g2000cwb.googlegroups.com> Hello c.l.py, Does anyone else have experience with that? I'm somewhat stuck. The problem is basically the same as here: http://groups-beta.google.com/group/mailing.unix.net-snmp-users/browse_thread/thread/92fdea477a2f67ba/48924041d27b748b?tvc=2&q=yapsnmp+port#48924041d27b748b that is, I can't force a Session object to connect to any other port than 161. And, you may have anticipated it, the solution given in the referenced thread doesn't work, all I get is a socket.gaierror: Name or service not known. Any thoughts on that? I also suspect that I might have messed something during compilation, because it didn't go smooth at all. That, hovewer, will probably be irrelevant, since yapsnmp is just a SWIG-generated wrapper plus some higher-level interfaces. And everything seems right in the source code... From eurleif at ecritters.biz Fri Aug 26 17:49:41 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Fri, 26 Aug 2005 21:49:41 GMT Subject: Any projects to provide Javascript-style client-side browser access via Python? In-Reply-To: References: Message-ID: Kenneth McDonald wrote: > I'm curious about this because, quite aside their function as web > browsers, it is now possible to build some very useable interfaces > using browsers with HTML, CSS, and JavaScript. (The biggest problem is > still the lack of a decent text widget.) However, JavaScript isn't > really a good language for building complex applications, and it would > be very cool if there were some way to use Python to replace > client-side JavaScript, in order to gain access the DOM. You could try Livepage, which is a part of Nevow . It doesn't cut JavaScript completely out of the picture, but you could put all of your real code in Python and only use JavaScript as a simple layer to access the DOM. From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 31 07:23:03 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 31 Aug 2005 13:23:03 +0200 Subject: Yielding a chain of values In-Reply-To: References: <4314bf65.177562962@news.oz.net> <3nk0e4F1snjcU2@individual.net> <4314e9fe.188467011@news.oz.net> <431553db.215568641@news.oz.net> Message-ID: <3nli8nF23ge4U1@individual.net> Matt Hammond wrote: >> Well, maybe it's right both ways ;-) I.e., even though yield "is" now >> an expression, it is valid to use it as an expression-statement which >> evaluates the expression and discards the value. So I think you could >> still use the currently illegal "yield in" token sequence to mean that >> what follows is to be taken as an iterable whose full sequence is >> to be yielded sequentially as if >> >> yield in iterable >> >> were sugar for >> >> for _ in iterable: yield _ > > "yield in" could make sense when thought of as an expression too. > > x = yield in iterable > > Would behave like a list comprehension. x would be assigned a list > containing > the results of the successive yields. Equivalent to: > > x = [ yield r for r in iterable ] Which is quite different from x = (yield) in iterable which is currently (PEP 342) equivalent to _ = (yield) x = _ in iterable So, no further tinkering with yield, I'm afraid. Reinhold From peter at engcorp.com Wed Aug 24 17:39:11 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 24 Aug 2005 17:39:11 -0400 Subject: Sorta noob question - file vs. open? In-Reply-To: <6tmpg19aa138j4cv2s0k5j7ir1goercvb0@4ax.com> References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> <430b9cc0$1@nntp0.pdx.net> <6tmpg19aa138j4cv2s0k5j7ir1goercvb0@4ax.com> Message-ID: Peter A. Schott wrote: > Thanks to all who replied. If open is still preferred, I will > stick with that. FWIW, that's not an unqualified "preferred". To demonstrate by example, neither of the above is considered preferred, though they both work: outputFile = file('path.to.file') if isinstance(outputFile, open): ... whereas these _are_ preferred: outputFile = open('path.to.file') if isinstance(outputFile, file): ... -Peter From spam.csubich+block at block.subich.spam.com Wed Aug 3 11:29:23 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 03 Aug 2005 11:29:23 -0400 Subject: HELP:sorting list of outline numbers In-Reply-To: References: Message-ID: Felix Collins wrote: > Using Decorate, Sort , Undecorate... > > works like a charm. As a one-liner, you can also deconstruct and rebuild the outline numbers: new_outline = ['.'.join(v) for v in (sorted([k.split('.') for k in old_outline]))] From za at konto.pl Tue Aug 30 16:24:55 2005 From: za at konto.pl (Andrzej) Date: Tue, 30 Aug 2005 22:24:55 +0200 Subject: wxpython + ogl Message-ID: Hi! I'm writing a simple digital circuit simulator in order to familirise with (wx)python. I thought it would be an easy task with help from ogl lib. After a not so brief encounter with wx specs I've started to code but I just can't figure out how to get user-defined attachment points to work. I've tried to call SetAttachmentMode(True) for shapes that should be connected and then: dc = wx.ClientDC(self.canvas) # ->self.canvas = ogl.ShapeCanvas(self) self.canvas.PrepareDC(dc) shape1.MoveLineToNewAttachment(dc, line, x1, y1) But the line pops up in random place and is changing it's position only vertically when moving one of the shapes. I'm probably doing something terribly wrong and I'd appreciate any help to solve my little problem . Thanks in advance Andrzej From jforcier at strozllc.com Thu Aug 11 15:40:36 2005 From: jforcier at strozllc.com (Jeffrey E. Forcier) Date: 11 Aug 2005 12:40:36 -0700 Subject: epyDoc Questions References: Message-ID: <1123789236.709664.135120@g43g2000cwa.googlegroups.com> Neil Benn wrote: > 1. I want to document the attributes (instance and also class) of a > class and or module, I know the tags are there - where does they > go (before/after theclass decleration, top of the module, if > someone puts in the class doc but misses out the module stuff, how > will epydoc know that this is meant to be class and not module > (although someone doing this will probably get shouted at in a > code review!)? http://epydoc.sourceforge.net/fields.html You specify different tags for class, instance and module level attributes/variables using the respective tags @cvar, @ivar and @var. I believe you need to put @cvar and @ivar in the class' docstring, as follows: ## code ## class MyClass(): """ Stuff. @cvar varOne: the first var @cvar varTwo: the second var """ varOne = 1 varTwo = 2 [...] ## end code ## And @var should probably be used in the module's top level docstring in the same manner. > 2. In the argument to the tag for raises, how can I put a link > through to the exception? Not 100% sure on this one; I would imagine that Epydoc would automatically put those links in for you? Otherwise I don't believe L{} can be used in the field name, only in the field text/body paragraph. > 3. How would I go about marking up the property docs so that it knows > what the setter and getter methods are - it links through to the > methods but the docs arn't in there, they are in the fifth > argument to the property method (I can manually do this using > sections but is there a tag I can use?) Like a previous poster said, can you show us an example? I don't quite follow this one :) HTH, Jeff From spe.stani.be at gmail.com Fri Aug 12 22:00:59 2005 From: spe.stani.be at gmail.com (spe.stani.be at gmail.com) Date: 12 Aug 2005 19:00:59 -0700 Subject: new python debugger In-Reply-To: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> References: <1123584720.240642.295970@g47g2000cwa.googlegroups.com> Message-ID: <1123898459.747956.181100@g44g2000cwa.googlegroups.com> It will be integrated in the next release of SPE 0.7.5.b, as you can already see screenshots. For those who are impatient, check out the SVN. Stani http://pythonide.stani.be http://pythonide.stani.be/screenshots From exogen at gmail.com Mon Aug 1 18:06:05 2005 From: exogen at gmail.com (Brian Beck) Date: Mon, 01 Aug 2005 18:06:05 -0400 Subject: Path as a dictionary tree key? (was Re: PEP on path module for standard library) In-Reply-To: References: Message-ID: Ron Adam wrote: > This give a more general purpose for path objects. Working out ways to > retrieve path objects from a dictionary_tree also would be useful I > think. I think a Tree class would also be a useful addition as well. > > Any thoughts on this? I don't think this would be as useful as you think, for Path objects at least. Path objects represent *a* path, and building a tree as you have proposed involves storing much more information than necessary. For instance, if I have the path /A/B/X, a tree-structured object would logically also store the siblings of X and B (subpaths of B and A). -- Brian Beck Adventurer of the First Order From spammers-go-here at spam.invalid Sun Aug 14 12:41:11 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sun, 14 Aug 2005 12:41:11 -0400 Subject: Standalone applications ? References: <42feba84$0$18644$14726298@news.sunsite.dk> <42feca21$0$18650$14726298@news.sunsite.dk> <1124016548.909588.77090@g47g2000cwa.googlegroups.com> Message-ID: <42ff7411$0$18636$14726298@news.sunsite.dk> TPJ wrote: >> I should have added that my platform is Linux. > > In this case you shouldn't bother yourself with executables. Python is > available on any major distribution. > > My Python apps are available as pyc files for Linux (and for those > Windows users, who have Python installed) and as executables for Win > (for those Windows users, who have no Python installed). My python app uses a lot of modules, some custom developed by myself (and which I am not planning on releasing right now). Which is why I posed the question in the first place (that and curiosity). From donn at drizzle.com Sat Aug 20 12:00:57 2005 From: donn at drizzle.com (Donn Cave) Date: Sat, 20 Aug 2005 16:00:57 -0000 Subject: global interpreter lock References: <91nNe.620$zD3.198@newssvr29.news.prodigy.net> <86fyt5b93o.fsf@bhuda.mired.org> <7xvf2183mt.fsf@ruckus.brouhaha.com> Message-ID: <1124553656.678727@yasure> Quoth Paul Rubin : | Mike Meyer writes: |> The real problem is that the concurrency models available in currently |> popular languages are still at the "goto" stage of language |> development. Better models exist, have existed for decades, and are |> available in a variety of languages. | | But Python's threading system is designed to be like Java's, and | actual Java implementations seem to support concurrent threads just fine. I don't see a contradiction here. "goto" is "just fine", too -- you can write excellent programs with goto. 20 years of one very successful software engineering crusade against this feature have made it a household word for brokenness, but most current programming languages have more problems in that vein that pass without question. If you want to see progress, it's important to remember that goto was a workable, useful, powerful construct that worked fine in the right hands - and that wasn't enough. Anyway, to return to the subject, I believe if you follow this subthread back you will see that it has diverged a little from simply whether or how Python could support SMP. Mike, care to mention an example or two of the better models you had in mind there? Donn Cave, donn at drizzle.com From levicc00123 at gmail.com Sun Aug 28 17:35:07 2005 From: levicc00123 at gmail.com (levicc00123 at gmail.com) Date: 28 Aug 2005 14:35:07 -0700 Subject: using common lisp with python. Message-ID: <1125264907.656465.106900@g44g2000cwa.googlegroups.com> is there a way to embed common lisp programs in python? From peter at engcorp.com Fri Aug 5 18:10:49 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 05 Aug 2005 18:10:49 -0400 Subject: socket and os.system In-Reply-To: References: Message-ID: Donn Cave wrote: > Peter Hansen wrote: >>PLEASE learn to format your questions more appropriately! Your post is >>simply _awful_ to read. ... > > For heaven's sake, it wasn't that hard to read. My apologies to the original poster. I did find it very hard to read with the very brief time I put into reading posts which don't fit Usenet conventions. Upon rereading it now a third time I can parse it a little better, and my outburst does seem harsh. (Normally I quickly hit "k" on such posts and carry on, but the apparent SO_REUSEADDR symptom caught my eye milliseconds before I did so.) > The good thing is that he did provide example that clearly > illustrates the problem. > > Which is not really that he can't reuse the socket address. So I'm doubly wrong and apologize for not having tried hard enough to read it to avoid giving an unhelpful answer. -putting-ice-on-his-slapped-wrists-ly y'rs, Peter From icoba at yahoo.com Tue Aug 23 07:05:42 2005 From: icoba at yahoo.com (icoba at yahoo.com) Date: 23 Aug 2005 04:05:42 -0700 Subject: Import Error ('mutual inclusion of modules'?) In-Reply-To: References: <1124792581.450156.214960@g44g2000cwa.googlegroups.com> Message-ID: <1124795142.586721.7530@o13g2000cwo.googlegroups.com> Thanks, I had not found anything about it. But I had not search correctly. There is an entry in the FAQ about it: http://www.python.org/doc/faq/programming.html#how-can-i-have-modules-that-mutually-import-each-other I like the most the third way. I have also tried to move the import to the __init__ methos in B.py and it works. From see at signature.invalid Fri Aug 19 18:35:32 2005 From: see at signature.invalid (Nigel Rowe) Date: Sat, 20 Aug 2005 08:35:32 +1000 Subject: Database of non standard library modules... References: Message-ID: <11gcnlkt3q2bk53@news.supernews.com> Steve Holden wrote: > Robert Kern wrote: >> Jon Hewer wrote: >> >>>Is there an online database of non standard library modules for Python? >> >> >> http://cheeseshop.python.org/pypi >> > While cheeseshop might resonate with the Monty Python fans I have to say > I think the name sucks in terms of explaining what to expect. If I ask > someone where I can find a piece of code and the direct me to the cheese > shop, I might look for another language. > > regards > Steve To be fair, it's really the "Python Package Index", it just happens to be stored on a machine called cheeseshop. -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) swiftdsl (stop) com (stop) au From sjmachin at lexicon.net Thu Aug 11 18:30:58 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 12 Aug 2005 08:30:58 +1000 Subject: Regular expression to match a # In-Reply-To: <1123799252.257355.158320@f14g2000cwb.googlegroups.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> <42fbb9a9$1@news.eftel.com> <1123799252.257355.158320@f14g2000cwb.googlegroups.com> Message-ID: <42fbd1a1$1@news.eftel.com> Devan L wrote: > John Machin wrote: > >>Aahz wrote: >> >>>In article <42fb45d7$1 at news.eftel.com>, >>>John Machin wrote: >>> >>> >>>>Search for r'^something' can never be better/faster than match for >>>>r'something', and with a dopey implementation of search [which Python's >>>>re is NOT] it could be much worse. So please don't tell newbies to >>>>search for r'^something'. >>> >>> >>>You're somehow getting mixed up in thinking that "^" is some kind of >>>"not" operator -- it's the start of line anchor in this context. >> >>I can't imagine where you got that idea from. >> >>If I change "[which Python's re is NOT]" to "[Python's re's search() is >>not dopey]", does that help you? >> >>The point was made in a context where the OP appeared to be reading a >>line at a time and parsing it, and re.compile(r'something').match() >>would do the job; re.compile(r'^something').search() will do the job too >>-- BECAUSE ^ means start of line anchor -- but somewhat redundantly, and >>very inefficiently in the failing case with dopey implementations of >>search() (which apply match() at offsets 0, 1, 2, .....). > > > I don't see much difference. and I didn't expect that you would -- like I wrote above: "Python's re's search() is not dopey". From dmqatpobox.com Fri Aug 26 10:02:40 2005 From: dmqatpobox.com (David MacQuigg) Date: Fri, 26 Aug 2005 07:02:40 -0700 Subject: Fighting Spam with Python References: Message-ID: On Thu, 25 Aug 2005 13:22:53 -0400, Fran?ois Pinard wrote: >[David MacQuigg] > >> The key new features needed in a spam filter are the ability to >> extract the sender's identity (not that of the latest forwarder), and >> to factor into the spam score the reputation of that identity. > >This will only work if your system is immune to forgeries, while being >largely widespread. Stopping forgery is what the new authentication methods are all about. Getting these methods widely and effectively used is our big challenge, and one that I hope to accomplish with my efforts. There are a bunch of pieces that need to work together more smoothly. That's where Python comes in. There are some challenging constraints, like the system has to work without government regulation. I've got a first draft of a website for open-mail.org - temporarily at http://purl.net/macquigg/email/registry Suggestions are welcome. >> In the flow we envision, the spam filter is the final process, used >> only on the 5% that is hard to classify. 80% will get an immediate >> reject. 15% will get an immediate accept without filtering, because >> the sender is authenticated and has a good reputation. Eventually, >> all reputable senders will join the 15%, and the 5% will shrink to >> where we can ignore it. > >It's fun to read statistics about a vision! :-) The 80% is real. http://messagelabs.com/emailthreats As to how the remaining 20% will split, that's a guess, but one that I think is realistic. See http://www.spamhaus.org/effective_filtering.html for comparable numbers using only IP blacklists and spam filtering. The 5% still needing filtering will be those senders that don't offer any authentication or that authenticate with an identity that has not yet acquired a reputation. >> >You might find www.spambayes.org of interest, in several ways. > >Spambayes is surprisingly good as it already stands. I haven't used Spambayes, but my experience with Spamnix (an offshoot of Spam Assassin) is that statistical filters always have a few false rejects. In my case, that's about two per week. The solution to this problem is a reliable system allowing receivers to determine the identity and reputation of an unknown sender. Then we can safely ignore the spam. -- Dave From yoav_artzi at il.vio.com Thu Aug 25 11:21:35 2005 From: yoav_artzi at il.vio.com (Yoav) Date: Thu, 25 Aug 2005 18:21:35 +0300 Subject: RE Despair - help required In-Reply-To: References: <430d8883@news.bezeqint.net> <430dcea0$1@news.bezeqint.net> Message-ID: <430de0d4@news.bezeqint.net> Thank you all guys. It seems like the simpler the solution, the more I am happy about it. Sorry, for the simple question, I am quite new to this lang. Cheers. Robert Kern wrote: > Yoav wrote: > >>Don't think it will do much good. I need to get them from a file and >>extract the last folder in the path. For example: >>if I get "c:\dos\util" >>I want to extract the string "\util" > > > You mean like this: > > import os > os.path.sep + os.path.split(r"c:\dos\util")[-1] > From steve at holdenweb.com Thu Aug 25 00:05:18 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Aug 2005 00:05:18 -0400 Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> Message-ID: Bryan Olson wrote: > The doc for the find() method of string objects, which is > essentially the same as the string.find() function, states: > > find(sub[, start[, end]]) > Return the lowest index in the string where substring sub > is found, such that sub is contained in the range [start, > end). Optional arguments start and end are interpreted as > in slice notation. Return -1 if sub is not found. > > Consider: > > print 'Hello'.find('o') > > or: > > import string > print string.find('Hello', 'o') > > The substring 'o' is found in 'Hello' at the index -1, and at > the index 4, and it is not found at any other index. Both the > locations found are in the range [start, end), and obviously -1 > is less than 4, so according to the documentation, find() should > return -1. > > What the either of the above actually prints is: > > 4 > > which shows yet another bug resulting from Python's handling of > negative indexes. This one is clearly a documentation error, but > the real fix is to cure the wart so that Python's behavior is > consistent enough that we'll be able to describe it correctly. > > Do you just go round looking for trouble? As far as position reporting goes, it seems pretty clear that find() will always report positive index values. In a five-character string then -1 and 4 are effectively equivalent. What on earth makes you call this a bug? And what are you proposing that find() should return if the substring isn't found at all? please don't suggest it should raise an exception, as index() exists to provide that functionality. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jussij at zeusedit.com Tue Aug 9 20:02:18 2005 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: 9 Aug 2005 17:02:18 -0700 Subject: Recommendations for CVS systems References: <1123594076.419938.281440@g47g2000cwa.googlegroups.com> Message-ID: <1123630799.096018.41850@o13g2000cwo.googlegroups.com> > I was wondering if anyone could make recomendations/comments > about CVS systems Amoung other things the Zeus for Windows programmer's editor/IDE comes with integrated CVS support: http://www.zeusedit.com/features.html > Most of the developement is Python, but some C, Javascript, > HTML, etc. Zeus also has syntax highlighting and code folding for a dozen or so languages including Pyhton, C, Javascript and HTML. Note: Zeus is shareware and comes with a a 45 day fully functional trial period. Jussi Jumppanen From bdesth.quelquechose at free.quelquepart.fr Mon Aug 22 17:13:18 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 22 Aug 2005 23:13:18 +0200 Subject: loop in python In-Reply-To: References: <20050823065501.GA24558@mrna.tn.nic.in> Message-ID: <430a3825$0$17460$626a14ce@news.free.fr> km a ?crit : > Hi all, > > ya i am sorry i tried with an empty loop first and then one which emits a value as the snippet. I have tested it on my machine and now ... > > 1) perl (v 5.8) does the job in 0.005 seconds > 2) but python (v 2.4.1) is horribly slow its 0.61 seconds. > and using range() instead of xrange() in python snippet, it not better , it takes 0.57 seconds. just test it urself and see. > > what more do i need to accept python is slow when it comes to loops concept ? > #python -> python2.4.1: for i in xrange(100000): print i real 0m8.997s user 0m1.355s sys 0m0.483s /* C -> gcc -Wall -ansi -pedantic -O3 */ # include int main(void) { int i; for (i = 0; i < 100000; i++) printf("%d\n", i); return 0; } real 0m7.165s user 0m0.276s sys 0m0.430s Well... seems that Python is not *so* slow when compared to C on this one. But wait... Could it be possible that we're in fact merely benchmarking IO's ?-) lol... And what about this: # loops2.pl for $x (0..100000){} real 0m0.038s user 0m0.030s sys 0m0.002s # loops2.c int main(void) { int i; for (i = 0; i < 100000; i++); return 0; } real 0m0.002s user 0m0.001s sys 0m0.001s Oh my ! What more do you need to accept Perl is *so awfully slow*. If you want to keep on trolling on this, I suggest that you "benchmark" (lol) a Java, a PHP and a Ruby versions too... But I don't despair... Chances are that, one day, you understand that what is important is what you going on in the loop - not the loop itself. From stringy at gmail.com Tue Aug 2 06:47:02 2005 From: stringy at gmail.com (stringy) Date: 2 Aug 2005 03:47:02 -0700 Subject: C++, Swig, and pyMPI Message-ID: <1122979622.636448.200960@g47g2000cwa.googlegroups.com> I would like to be able to write a C++ function, to be wrapped into some python, to be able to communicate over pyMPI. As pyMPI is based on C++ I figure that this should be possible, although I'm not sure of where to start. I know the basics of swig and pyMPI, but not how I would do this. Does anyone know if this is possible and where to start? From kasteren at multiweb.nl Mon Aug 1 11:42:04 2005 From: kasteren at multiweb.nl (mrman) Date: Mon, 01 Aug 2005 11:42:04 -0400 Subject: problem using py2exe References: Message-ID: <4adc9a10d7c705d871a2ecf8abd88111@localhost.talkaboutprogramming.com> I ran into the same problem (although 2 years later :-P) I managed to fix it by copying the dll files and the snack.tcl file from the snacklib directory to my dist\tcl\tk8.4\ directory. Then editing the pkgIndex.tcl in the tk8.4 directory and adding the lines that are present in the pkgIndex.tcl that is in the snacklib directory. If no pkgIndex.tcl file is present in your tk8.4 dir, just copy the one from the snacklib dir just like you did the other files. Hope somebody still sees this as useful information From tiissa at nonfree.fr Sat Aug 6 08:37:05 2005 From: tiissa at nonfree.fr (tiissa) Date: Sat, 06 Aug 2005 14:37:05 +0200 Subject: why no arg, abs methods for comlex type? In-Reply-To: References: Message-ID: <42f4aef0$0$15019$626a14ce@news.free.fr> Daniel Sch?le wrote: >> Okay. Write a patch. Personally, I would prefer that it be a >> function in cmath rather than a method because then it could be made >> to work on integers and regular floats, too. > > Ok, but what semantic should angle/arg have, say for 3 respectively > for 3.0? > the same as for arg(3+0j)? As a potential user, that's what I would expect. See Dan Bishop's implementation (earlier in this thread). From walter at livinglogic.de Wed Aug 10 14:22:51 2005 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Wed, 10 Aug 2005 20:22:51 +0200 Subject: Syntax error after upgrading to Python 2.4 In-Reply-To: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> References: <1123260862.672051.282940@z14g2000cwz.googlegroups.com> Message-ID: <42FA45FB.6040607@livinglogic.de> frr at easyjob.net wrote: > Hi, > > After upgrading to 2.4 (from 2.3), I'm getting a weird syntax error: > > >>>>import themes > > Traceback (most recent call last): > File "", line 1, in ? > File "themes.py", line 564 > font = self.font.makeBlackAndWhite(), > additive = self.additive, > ^ > SyntaxError: invalid syntax > > The relevant code is: > > def makeBlackAndWhite( self ): > > return CharStyle( names = self.names, > basedOn = self.basedOn.makeBlackAndWhite(), > font = self.font.makeBlackAndWhite(), > additive = self.additive, > prefixText = self.prefixText ) > > This is a method in the CharStyle class which returns a new modified > instance of CharStyle. > > I'm using Windows XP and Python 2.4.1 > > Any ideas? O:-) This is probably related to http://www.python.org/sf/1163244. Do you have a PEP 263 encoding declaration in your file? Can you try Lib/codecs.py from current CVS? Bye, Walter D?rwald From paul at fxtech.com Thu Aug 25 17:55:48 2005 From: paul at fxtech.com (Paul Miller) Date: Thu, 25 Aug 2005 16:55:48 -0500 Subject: MacPython 2.2 on Mac OS X 10.3.8 - configurePython error Message-ID: I have a user who is is having trouble getting MacPython on his OS X 10.3.8 system. When he runs ConfigurePythonCarbon, he gets this error: [terminated] 'import site' failed; use -v for traceback traceback )most recent call last): File "Moes:SWdev:Jack:Python2.2:Mac:script:configurePython.py", line 11 , in ? Import error: No module named os I have had no trouble on my system (same version). What can cause this? -Paul From max2 at fisso.casa Mon Aug 22 06:08:02 2005 From: max2 at fisso.casa (max(01)*) Date: Mon, 22 Aug 2005 10:08:02 GMT Subject: regular expressions use Message-ID: <6uhOe.70629$2U1.3761846@news3.tin.it> hi everyone. i would like to do some uri-decoding, which means to translate patterns like "%2b/dhg-%3b %7E" into "+/dhg-; ~": in practice, if a sequence like "%2b" is found, it should be translated into one character whose hex ascii code is 2b. i did this: ... import re import sys modello = re.compile("%([0-9a-f][0-9a-f])", re.IGNORECASE) def funzione(corrispondenza): return chr(eval('0x' + corrispondenza.group(1))) for riga in sys.stdin: riga = modello.sub(funzione, riga) sys.stdout.write(riga) ... please comment it. can it be made easily or more compactly? i am a python regexp novice. bye max ps: i was trying to pythonate this kind of perl code: $riga =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/chr(hex($1))/ge; From rrr at ronadam.com Sun Aug 21 18:51:04 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 21 Aug 2005 22:51:04 GMT Subject: pythonXX.dll size: please split CJK codecs out In-Reply-To: <4308e632$0$31533$9b622d9e@news.freenet.de> References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <4308e632$0$31533$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: > Ron Adam wrote: > >>I would put the starting minimum boundary as: >> >> 1. "The minimum required to start the python interpreter with no >>additional required files." >> >>Currently python 2.4 (on windows) does not yet meet that guideline, so >>it seems some modules still need to be added while other modules, (I >>haven't checked which), are probably not needed to meet that guideline. > > > I'm not sure, either, but I *think* python24 won't load any .pyd file > on interactive startup. > > >>This could be extended to: >> >> 2. "The minimum required to run an agreed upon set of simple Python >>programs." >> >>I expect there may be a lot of differing opinions on just what those >>minimum Python programs should be. But that is where the PEP process >>comes in. > > > As I mentioned earlier, there also should be a negative list: modules > that depend on external libraries should not be incorporated into > python24.dll. This fits under the above, rule #1, of not needing additional files. Most notably, this rules out zlib.pyd, _bsddb.pyd, > and _ssl.pyd, all of which people may consider to be useful into these > simple programs. I would not consider those as being part of "simple" programs. But that's only an opinion and we need something more objective than opinion. Now that I think of it.. Rule 2 above should be... 2. "The minimum (modules) required to run an agreed upon set of "common simple" programs. Frequency of use is also an important consideration. Maybe there's a way to classify a programs complexity based on a set of attributes. So... program simplicity could consider: 1. Complete program is a single .py file. 2. Not larger than 'n' lines. (some reasonable limit) 3. Limited number of import statements. (less than 'n' modules imported) 4. Uses only stdio and/or basic file operations for input and output. (runs in interactive console or command line.) Then ranking the frequency of imported modules from this set of programs could give a good hint as to what might be included and those less frequently used that may be excluded. Setting a pythonxx.dll minimum file size goal could further help. For example if excluding modules result is less than the minimum goal, then a few extra more frequently used modules could be included as a bonus. This is obviously a "practical beats purity" exercise. ;-) Cheers, Ron > Regards, > Martin From chris at phaedsys.org Mon Aug 22 17:32:36 2005 From: chris at phaedsys.org (Chris Hills) Date: Mon, 22 Aug 2005 22:32:36 +0100 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> Message-ID: In article , jan V writes >> +-------------------+ .:\:\:/:/:. >> | PLEASE DO NOT | :.:\:\:/:/:.: >> | FEED THE TROLLS | :=.' - - '.=: >> | | '=(\ 9 9 /)=' >> | Thank you, | ( (_) ) >> | Management | /`-vvv-'\ >> +-------------------+ / \ >> | | @@@ / /|,,,,,|\ \ >> | | @@@ /_// /^\ \\_\ >> @x@@x@ | | |/ WW( ( ) )WW >> \||||/ | | \| __\,,\ /,,/__ >> \||/ | | | jgs (______Y______) >> /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ > >Please don't use ASCII art... not everyone uses a fixed-width font for his >newsreader............... I thought usenet specified fixed font. If you use something else don't complain. The Troll don't look pretty in fixed font either:-) -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris at phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ From luismgz at gmail.com Wed Aug 3 16:05:31 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 3 Aug 2005 13:05:31 -0700 Subject: Py: a very dangerous language References: <1122882607.594619.320980@g49g2000cwa.googlegroups.com> Message-ID: <1123099531.243492.4110@z14g2000cwz.googlegroups.com> Well, I have no problems going to bed. The problem is that while sleeping, I keep on coding in my head... Sometimes I reach the "A ha!" state, then I wake up, turn on the my pc and type the solution. I'm a little bit worried though... I don't even have erotic dreams anymore! From paul.sherwood at gmail.com Wed Aug 17 05:12:14 2005 From: paul.sherwood at gmail.com (paul.sherwood at gmail.com) Date: 17 Aug 2005 02:12:14 -0700 Subject: Iterparse and ElementTree confusion Message-ID: <1124269934.194818.51940@f14g2000cwb.googlegroups.com> Hi Im trying to parse a large(150MB) xml file in order to extract specific required records. import sys from elementtree.ElementTree import ElementTree root = ElementTree(file=big.xml') This works fine for smaller versions of the same xml file but...when i attempted the above my PC goes to lala land, theres much HDD grinding followed by "windows runnign low on virtual memory" popup after 10-15mins. Then just more grinding...for an hour before i gave up XML file format: . . . . . . 23172 Three Spot Rail Light Brushed Chrome 73520 . .etc Ok, i thought, surely theres a way to parse this thing in chucnks till i get to the element i require then I'll reuse the ElementTree goodness. I found Iterparse def parse_for_products(filename): for event, elem in iterparse(filename): if elem.tag == "Products": root = ElementTree(elem) print_all(root) else: elem.clear() My problem is that if i pass the 'elem' found by iterparse then try to print all attributes, children and tail text i only get elem.tag....elem.keys returns nothing as do all of the other previously useful elementtree methods. Am i right in thinking that you can pass an element into ElementTree? How might i manually iterate through ... grabbing everything? From nszabolcs at gmail.com Thu Aug 18 07:07:18 2005 From: nszabolcs at gmail.com (Szabolcs Nagy) Date: 18 Aug 2005 04:07:18 -0700 Subject: time.clock() problem under linux (precision=0.01s) Message-ID: <1124363238.556661.164270@g14g2000cwa.googlegroups.com> I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i tested timer functions capabilities with a short script: import time import os def test_timer_func(func): print 'min time-time: %.10f'%min(abs(func()-func()) for i in xrange(10**5)) print 'max time-time: %.10f'%max(abs(func()-func()) for i in xrange(10**5)) dt = 0.0 loopcount = 0 t = func() while dt==0.0: dt = func() - t loopcount += 1 print "min measurable loop time : %.10f"%dt print 'loopcount while dt==0 :',loopcount print '\n time.clock()' test_timer_func(time.clock) print '\n time.time()' test_timer_func(time.time) print '\n os.times()' ot = os.times test_timer_func(lambda:ot()[4]) My output is: time.clock() min time-time: 0.0000000000 max time-time: 0.0100000000 min measurable loop time : 0.0100000000 loopcount while dt==0 : 2703 time.time() min time-time: 0.0000019073 max time-time: 0.0000460148 min measurable loop time : 0.0000050068 loopcount while dt==0 : 1 os.times() min time-time: 0.0000000000 max time-time: 0.0100000007 min measurable loop time : 0.0099999998 loopcount while dt==0 : 2515 So the precision of time.clock is 0.01s under my ubuntu linux system, which means it's not suitable for benchmarking. (i want to benchmark the fps in my pygame+pyode program and it needs at least 0.001s precision) time.time seems much better solution, but python manual sais: "not all systems provide time with a better precision than 1 second" Should i use time.clock or time.time to be more crossplatform? Is time.time ok for windows? (time()-time() != 0.0) nszabolcs From rkern at ucsd.edu Sun Aug 7 00:48:34 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 06 Aug 2005 21:48:34 -0700 Subject: Decline and fall of scripting languages ? In-Reply-To: <7xpssqv0ln.fsf@ruckus.brouhaha.com> References: <1123323863.817060.117810@g47g2000cwa.googlegroups.com> <7xbr4ae8mx.fsf@ruckus.brouhaha.com> <7xpssqv0ln.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Joseph Garvin writes: > >>>That's the second time in one or two days that I've heard Ruby on >>>Rails mentioned. Can anyone here post a paragraph or two description? >>>I sort of know what Ruby is, a very OOP-ified Perl-resemblant >>>language, that's also implemented only as an interpreter. I can't see >>>punting Python for it. >> >>www.google.com > > Thanks but I wanted a more Pythonic point of view. google('"ruby on rails" python') Plenty of Pythonistas posting paragraphs pontificating on the Pythonic perspective. -- 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 jaydonnell at gmail.com Wed Aug 31 12:56:04 2005 From: jaydonnell at gmail.com (jdonnell) Date: 31 Aug 2005 09:56:04 -0700 Subject: can't start new thread References: <1125506166.505956.144570@f14g2000cwb.googlegroups.com> <7xirxmxdtd.fsf@ruckus.brouhaha.com> Message-ID: <1125507363.982202.11470@g47g2000cwa.googlegroups.com> >Maybe some other VPS(s) under the host OS have spun enough processes >or threads to make the host OS exhaust some limit. I'm not familiar with any hard limits in linux. Is there a config file with these settings? From steven.bethard at gmail.com Mon Aug 1 13:36:09 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 01 Aug 2005 11:36:09 -0600 Subject: multiple inheritance super() In-Reply-To: <1122788989.524732.40190@o13g2000cwo.googlegroups.com> References: <863bpzmz50.fsf@bhuda.mired.org> <1122548998.766210.101860@g47g2000cwa.googlegroups.com> <3ks3mrFvr5jkU1@individual.net> <1122653176.013770.106080@g49g2000cwa.googlegroups.com> <86br4ljnxs.fsf@bhuda.mired.org> <1122716129.428629.273960@g49g2000cwa.googlegroups.com> <86slxvh7qk.fsf@bhuda.mired.org> <1122788989.524732.40190@o13g2000cwo.googlegroups.com> Message-ID: Michele Simionato wrote: > I have found out that the more I use OOP, the less I > use inheritance" > > Just curious if others had a similar experience. Definitely. Though I think that's partly because I came from a Java background where it's a little more ingrained. Since Python relies heavily on duck-typing, a lot of cases where I would subclass in Java I don't in Python. In Python, I pretty much only create an inheritance hierarchy when I discover that two independent classes are sharing the same code. STeVe From jepler at unpythonic.net Mon Aug 1 21:06:59 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 1 Aug 2005 20:06:59 -0500 Subject: How to execute code when a module is imported ? In-Reply-To: <600d5b730508011705306de451@mail.gmail.com> References: <600d5b730508011705306de451@mail.gmail.com> Message-ID: <20050802010655.GB9303@unpythonic.net> Depending what you mean, it may be dirt simple: -- foo.py -- print "bar" -- end of foo.py -- When a module is first imported, all the statements in it are executed. "def" statements define functions, and "class" statements define clasess. But you can have any type of statement you like at the top level of a module. However, the module is only executed at the first import. On subsequent imports, nothing happens except that the name 'foo' gets assigned the existing foo module from sys.modules['foo']: >>> import foo bar >>> import foo >>> import foo If you really need to do something each time 'import foo' is executed, then you'll have more work to do. One thing to do is override builtins.__import__. Something like this (untested): class ArthasHook: def __init__(self): import __builtin__ self.old_import = __builtin__.__import__ __builtin__.__import__ = self.do_import def do_import(self, *args): m = self.old_import(*args) f = getattr(m, "__onimport__", None) if f: f() hook = ArthasHook() After ArthasHook is created, then each 'import' statement will call hook.do_import() That will look for a module-level function __onimport__, which will be called with no arguments if it exists. I don't recommend doing this. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From spam.csubich+block at block.subich.spam.com Wed Aug 3 21:15:29 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Wed, 03 Aug 2005 21:15:29 -0400 Subject: cut & paste text between tkinter widgets In-Reply-To: References: Message-ID: Apologies in advance to anyone who has this post mangled, I use a couple Unicode characters at the end and Thunderbird wants to use UTF8 for the message encoding. Unless it does something weird, this post should still be legible... but I'm not going to rely on that. :) William Gill wrote: >> 2) If you need to do any processing on the clipboard data, look at >> widget.selection_get [so named because of the way that X handles its >> clipboard] > > From my reading, w.selection_get will return the selected text in w, > and places it on the clipboard. I didn't see any way to get data from > the clipboard. Not exactly. The docs for selection_get say: """Return the contents of the current X selection. A keyword parameter selection specifies the name of the selection and defaults to PRIMARY. A keyword parameter displayof specifies a widget on the display to use.""" The "X selection" is another way of saying "clipboard," again because of the way that X manages the clipboard. In experimenting with this, I found a slight... fun issue involved in this. Selection_get is the correct method to call, but it doesn't quite work out of the box. >>> g.selection_get() Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\Lib\lib-tk\Tkinter.py", line 574, in selection_get return self.tk.call(('selection', 'get') + self._options(kw)) _tkinter.TclError: PRIMARY selection doesn't exist or form "STRING" not defined This poses a small problem. I'm not sure whether this is a Win32-related issue, or it's because the PRIMARY selection isn't fully configured. Regardless, even if it worked it still wouldn't be what we wanted; the selection we want is CLIPBOARD. See this code: >>> g.clipboard_clear() >>> g.clipboard_append('I just love the wonderful clipboard management functions of Tk!') >>> g.selection_get(selection='CLIPBOARD') 'I just love the wonderful clipboard management functions of Tk!' And then, copying some text from this compose window... >>> g.selection_get(selection='CLIPBOARD') 'And then, copying some text from this compose window...' In theory, the clipboard will support more than text. This support is nontrivial, which is code for saying that I have no idea how to get it to work. Also, despite ICCCM standards, it looks like this clipboard management on win32 works as-is with unicode data -- under Tkinter, it returns a unicode string. (? ? ? ? -- and good luck with -that- going through unmangled) From peter at engcorp.com Mon Aug 15 21:26:59 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 15 Aug 2005 21:26:59 -0400 Subject: __del__ pattern? In-Reply-To: References: <1124112670.590292.304480@g14g2000cwa.googlegroups.com> Message-ID: Tom Anderson wrote: > Only one socket can be bound to a given port at any time, so the second > instance of SpecialClass will get an exception from the bind call, and > will be stillborn. This is a bit of a crufty hack, though - you end up > with an open port on your machine for no good reason. If If you bind with self.sock.bind(('localhost', 4242)) instead, at least you don't have much of a security risk since the port won't be available for connections from outside the same machine. Using '' instead of 'localhost' means bind to *all* interfaces, not just the loopback one. -Peter From hancock at anansispaceworks.com Tue Aug 16 11:31:26 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 16 Aug 2005 10:31:26 -0500 Subject: Library vs Framework (was Dr. Dobb's Python-URL!) In-Reply-To: References: Message-ID: <200508161031.26507.hancock@anansispaceworks.com> On Tuesday 16 August 2005 08:46 am, Rocco Moretti wrote: > But I'm not sure if library vs. framework a fair comparison - the two > are doing different things. With a framework, you're not really writing > your own program, you're customizing someone else's. Sort of a vastly > more flexible version of command line options. Saying you can't reuse > code written for a framework is kind of like saying that it's difficult > to use an Apache config file with the Gimp. Yeah, well that's precisely the point. They *aren't* the same thing, and which one do you want to use? :-) Zope recently started going through some massive changes to make it more like a toolkit (which is the term I use instead of library here). Even if there must be a framework, a thin framework with good tools tends to be better than a complex framework, even if they can, in principle do the same job. This is really just another version of the Unix "small tools that do one thing well" philosophy. The operating system is the "framework" that ordinary programs run in -- and you must spend a fair amount of time learning to use the operating system, which is why it involves so much buy-in, and people are so religious about which one they use. That's a general property of frameworks. Utility programs are themselves a toolkit. You don't have to know all of them, you are free to use some and not others, and you may use tools from many different authors together. OTOH, a massive Microsoft-style application is a framework. Instead of scripting a bunch of LaTeX modules and scripts together to make a newsletter, you do it all in Word, and maybe write Visual Basic code to be interpreted by that framework. I'll probably get flamed just for mentioning this system, even though I'm not advocating it. ;-) Similarly, Zope has suffered because there is such a large learning curve, it's so complicated, most people don't really understand what it does -- essentially, *because it is a framework*. That's why, I think, the developers have been moving towards a more toolkit-oriented design with Zope 3. The "component architecture" is an attempt to do that, by component-izing all of the important functionality so that it can be used separately. All of this is also linked heavily with the open-source bazaar-style development model, too. A toolkit, with tools coming from many different sources is more like the natural output of the bazaar. A framework is a cathedral, so it needs a cathedral engineering approach in order to make it work. Where a framework shines is when you don't really want to program it much at all -- you just need a tweak here and there beyond what it already does. Gimp plugins are a great example of that. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From http Mon Aug 8 13:09:12 2005 From: http (Paul Rubin) Date: 08 Aug 2005 10:09:12 -0700 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <7xpsso3jih.fsf@ruckus.brouhaha.com> <1123507357.148189.27540@g47g2000cwa.googlegroups.com> Message-ID: <7xirygz77r.fsf@ruckus.brouhaha.com> "Kay Schluehr" writes: > > Having a good FFI is certainly an important feature but Python > > programs should first and foremost be Python programs. > > Python was originally created as an extension language for C. In some > sense it is an abstraction layer for C libs. I'd have to respond: that was then, this is now. As Python has gotten more powerful, that C extension feature has gotten less central. That is to say, the language is growing up, and unwillingness to recognize that is in some places stunting Python's growth. > Did you ever check out ctypes? I appreciate it very much. > > http://starship.python.net/crew/theller/ctypes/ I think I did see something about it before. I should check it out further. But mainly I want my Python programs to be Python programs, not wrappers for C programs. And frankly I'm more comfortable with something like SWIG, which turns the C functions into actual Python modules rather than exposing naked C functions to Python code (destroying Python's type safety). From siona at chiark.greenend.org.uk Thu Aug 25 05:55:13 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 25 Aug 2005 10:55:13 +0100 (BST) Subject: newbie question: convert a list to one string References: <1124959699.071708.239210@g14g2000cwa.googlegroups.com> Message-ID: wrote: >I'm searching for the fastest way to convert a list to one big string. The join() method of strings. The string instance in question being the separator you want, so: " ".join(test) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From donn at u.washington.edu Mon Aug 15 13:10:10 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 15 Aug 2005 10:10:10 -0700 Subject: Bug on Python2.3.4 [FreeBSD]? References: <1123906696.459433@yasure> Message-ID: In article , "Terry Reedy" wrote: ... > If there is a hole in the standard, 'innovation' is required. I hope this perspective is a rarity. When you exploit an opportunity to make something work differently while conforming to the existing standards, you're creating the kind of problem standards are there to prevent. In the end I don't care if my software works because someone followed the standards to the letter, or because someone took the trouble to follow existing practice whether it was codified in a standard or not, I just don't want it to work differently on one platform than on another. Holes in standards are at best an excuse for accidental deviations. In the present case, so far I see a strong Berkeley vs. everyone else pattern, so GNU C probably wasn't the culprit after all. Along with already documented FreeBSD, I find MacOS X, NetBSD 2 and Ultrix 4.2 position the read stream to EOF. Linux, AIX and DEC/OSF1 (or whatever it's called these days) position it to 0. Donn Cave, donn at u.washington.edu From grante at visi.com Thu Aug 18 13:30:05 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 18 Aug 2005 17:30:05 -0000 Subject: question about binary and serial info References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> Message-ID: <11g9hct6qkfsc28@corp.supernews.com> On 2005-08-18, nephish at xit.net wrote: > i have an ascii string comming in the serial port and i need to convert > it to something else, like an integer, or binary, or even a hex so i > can use the bitwise comparison on it. But what do you mean by "integer", "binary", and "hex"? Decimal, hex, and binary are all representations of integers. On your computer all integers are 2's compliment binary (we're going to ignore BCD for the moment). The only thing that can be "decimal" or "hex" are _string_ representations of integer values. If you want something upon which you can perform the bitwise boolean operations &, ^, |, then you most probably just want an integer object. To convert a string to an integer, use the int() builtin passing it the string an an optional base: >>> int("1234") 1234 >>> int("1234",10) 1234 >>> int("0x100",16) 256 >>> int("100",16) 256 >>> int("100",2) 4 Others have already shown you how to use the bitwise boolean operators. -- Grant Edwards grante Yow! Look DEEP into the at OPENINGS!! Do you see any visi.com ELVES or EDSELS... or a HIGHBALL??... From evenprimes at gmail.com Wed Aug 10 10:15:07 2005 From: evenprimes at gmail.com (Chris Cioffi) Date: Wed, 10 Aug 2005 10:15:07 -0400 Subject: "Ordered" dicts In-Reply-To: <8c7f10c605081006489f9ea3a@mail.gmail.com> References: <8c7f10c605081006489f9ea3a@mail.gmail.com> Message-ID: On 10/08/05, Simon Brunning wrote: > > On 8/10/05, Chris Cioffi wrote: > > I have lots of code that looks like: > > keys = mydict.keys() > > keys.sort() > > keys = sorted(mydict.keys()) While the sorted() built in addressed (yet another) community desire, I don't think this addresses the underlying expectation of getting dictionary keys in some order. It works, but it feel like a kludge to me. Chris -- "Obviously crime pays, or there'd be no crime." -- G. Gorden Liddy -------------- next part -------------- An HTML attachment was scrubbed... URL: From apardon at forel.vub.ac.be Tue Aug 30 06:07:06 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 30 Aug 2005 10:07:06 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-08-30, Terry Reedy schreef : > > "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message > news:7xy86k3r7n.fsf at ruckus.brouhaha.com... > >> Really it's x[-1]'s behavior that should go, not find/rfind. > > I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely > useful, especially when 'x' is an expression instead of a name. I don't think the ability to easily index sequences from the right is in dispute. Just the fact that negative numbers on their own provide this functionality. Because I sometimes find it usefull to have a sequence start and end at arbitrary indexes, I have written a table class. So I can have a table that is indexed from e.g. -4 to +6. So how am I supposed to easily get at that last value? -- Antoon Pardon From tjreedy at udel.edu Wed Aug 24 04:10:07 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Aug 2005 04:10:07 -0400 Subject: Anyone recognize this numeric storage format - similar to "float", but not quite References: <1124849085.656718.97720@g43g2000cwa.googlegroups.com> Message-ID: This appears to be a repost, perhaps not by the op but due to a glitch somewhere, of a question posted about a month ago and answered. wrote in message news:1124849085.656718.97720 at g43g2000cwa.googlegroups.com... > We are working on a project to decipher a record structure of an old > accounting system that originates from the late80's mid-90's. > We have come across a number format that appears to be a "float" but > doesn't match any of the more standard implementations. > so we are hoping this is a recognizable number storage format with an > identifiable name AND pre-built conversion method > similiar to the "struct" modules available in python. > > Here is what we have determined so far. > > Example Number: 1234567890 > > This get stored on disk as 8 bytes, resulting in the following HEX > characters; > 00 00 00 A4 05 2c 13 9f > > If we changed the order so that it is "little Endian" we get; > 9F 13 2c 05 A4 00 00 00 > > If the HEX is converted to binary it looks like; > 10011111 00010011 00101100 00000101 10100100 00000000 000000000 > 00000000 > > If the example number 1234567890 is converted to binary it looks like; > > 10010011 00101100 00000101 1010010 > > To extract the example number, you need to do the following; > 1) take the decimal value of the first byte and subtract 128 > 2) This tells you how many of the following bits to are significant and > must be read > 3) Once the remaining bits are read, reverse the first bit of that > group (ie if it is a 0 make it a 1) > 4) convert the result to decimal > ... and presto, the example number ! > > Using a fixed width font it is easy to see the match at the bit level; > > 10011111 00010011001011000000010110100100000000000000000000000000 > -------- 1001001100101100000001011010010 > > > If you are interested, the following are three other examples; > > Orig Hex: 00 00 00 60 92 96 72 A0 > Actual Value: 4069954144 > > Orig Hex: 00 00 80 22 A3 26 3C A1 > Actual Value: 6313297477 > > > So ... does anyone recognize this ?? > Is there a "built-in" conversion method in Python ?? > > Thanks in advance. > > -- > http://mail.python.org/mailman/listinfo/python-list > From benji at benjiyork.com Tue Aug 9 08:10:05 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 09 Aug 2005 08:10:05 -0400 Subject: Point and click GUI builder for Python In-Reply-To: <42f430ea$0$18643$14726298@news.sunsite.dk> References: <42f430ea$0$18643$14726298@news.sunsite.dk> Message-ID: <42F89D1D.7000306@benjiyork.com> Madhusudan Singh wrote: > Is there such a thing for python ? Like Qt Designer for instance ? I've had great success with wxDesigner (http://www.roebling.de/). It is a commercial product ($129 for a single license), but it does an exceptional job. -- Benji York From MCollins at seminolecountyfl.gov Thu Aug 18 14:53:52 2005 From: MCollins at seminolecountyfl.gov (MCollins at seminolecountyfl.gov) Date: Thu, 18 Aug 2005 14:53:52 -0400 Subject: determine variable type Message-ID: trying to determine a variable type, specifically that a variable is an integer. i tried using type(var) but that only seemed to produce a response in the command line. is there a built in python function to determine if a variable is an integer? --****Florida has a very broad Public Records Law. Virtually all written communications to or from State and Local Officials and employees are public records available to the public and media upon request. Seminole County policy does not differentiate between personal and business emails. E-mail sent on the County system will be considered public and will only be withheld from disclosure if deemed confidential pursuant to State Law.**** From peter at engcorp.com Sun Aug 28 08:12:57 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Aug 2005 08:12:57 -0400 Subject: Socket Troubles In-Reply-To: <0ndQe.259$DV.23@trndny07> References: <0ndQe.259$DV.23@trndny07> Message-ID: Chris Spencer wrote: > I've written a simple class to manage P2P socket connections. However, > whenever I try to receive data, the socket raises an exception with the > error message (11, 'Resource temporarily unavailable'). I would assume (without looking at your code) that this is equivalent to the Windows error "WSAEWOULDBLOCK" (10035) for which Microsoft's docs say this: Resource temporarily unavailable. This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established. Does that help? If not, at least provide information about what platform you're running on, and preferably post the code, if you can reduce it to only a few lines which still reproduces the problem. Many people don't like to spend time downloading code from who knows where and attempting to run it on their own machine, but could find the problem with a quick inspection of your code if posted here (but not if it's hundreds of lines!). -Peter From p at ulmcnett.com Wed Aug 31 12:05:56 2005 From: p at ulmcnett.com (Paul McNett) Date: Wed, 31 Aug 2005 09:05:56 -0700 Subject: ANN: Dabo 0.4.1 Message-ID: <4315D564.2070006@ulmcnett.com> We are happy to announce the release of Dabo 0.4.1, available for download from: http://dabodev.com/download Dabo is a framework for developing 3-tier database applications, and comes with database wrappers for MySQL, PostgreSQL, Firebird, and SQLite. It wraps the wxPython GUI toolkit, making it easier to use and more polymorphic, providing a nice property interface to the controls. In addition to the main dabo-0.4.1 package, there are also updated downloads for dabodemo-0.4.1 and daboide-0.2.1. There have been numerous improvements in Dabo over the past few weeks since 0.4, summarized here: Improved test framework for uiwx. Now you can run ui/uiwx/test.py and get almost all of the dabo controls in one form, and they are the same tests that you get when you run an individual control directly. Factored out the saving/restoring of user settings out of dApp into the separate dUserSettingProvider class, which can be subclassed or overridded by the developers. Added properties UserSettingProvider and UserSettingProviderClass to dApp. Dabo user settings are no longer saved to .userSettings.ini in the app directory, but are saved to the user's home directory (in ~.dabo/) or if on Windows, in /Application Data/Dabo/. Support for SQLite added. As of this moment, Dabo supports several major open-source database backends: MySQL, PostgreSQL, Firebird, and SQLite. Next on the list should be Oracle, Sybase, and MS-SQL. Started work implementing a Quick Report in the datanav library, which replaces the old HTML Print Preview. This uses the fledgling Dabo Report Writer to create a PDF rendition of the dataset. Added new property for all controls: StatusText. When set, and when the form has a status bar, that text will show in the form's status bar when the mouse enters the control. Expanded the dabo.ui.strToBmp() function to accept an optional scale factor or width/height values. If they are passed, the returned bitmap image is sized to those values. Added an optional parameter to the bizobj and cursor's getDataSet() method. If you send a list of field names, only those fields are returned. Fixed some lingering bugs in the dabo.ui.uiwx package and the datanav lib. dWizard works better now. Improved dGauge, dLine, dBox, dRadioBox, dListBox, dToolBar, and dSizers. Added simple decimal support to dTextBox. Work continues on dGrid, specifically dColumn is now better worked into the "Dabo Way". Added dabo.trace() function, that will drop you into pdb. dConnectInfo reworked to have better property names. Removed dependency on PIL and reportlab from Dabo. These are dependencies still, but only if you try to run a report. Added dabo.lib.StopWatch.StopWatch class, which is a light Python stopwatch with start(), stop(), reset() methods and Value property. This is a partial list. Both Ed and Paul have been very busy with Dabo since 0.4 a few weeks ago. Lots of bugfixes and enhancements were made, and we encourage everyone to upgrade. --------------- In addition, we'd like to note that the minesweeper game in dabodemo has been greatly improved, and also the addition of the card game of montana. The development of these games are helping us iron out user interface issues that otherwise may have gone unnoticed. The AppWizard in daboide/wizards has also been updated to produce even better generated applications, ones that give the developer a starting structure that is relatively easy to tweak, modify, and augment. -- Paul McNett http://paulmcnett.com http://dabodev.com From wezzy at despammed.com Sun Aug 28 08:35:19 2005 From: wezzy at despammed.com (Wezzy) Date: Sun, 28 Aug 2005 14:35:19 +0200 Subject: Modify a C++ instance from the embed python interpreter References: <1h1yl9h.1x14zs71pjw5fyN%wezzy@despammed.com> <3nboh6Fq4aqU1@uni-berlin.de> Message-ID: <1h207jg.1xp19ty1eqlq3sN%wezzy@despammed.com> Diez B. Roggisch wrote: > Wezzy wrote: > > Hi, is there a tool that automatically expose an object to python? i > > have an instance of a C++ (or ObjC) object and i want to pass it to the > > embed interpreter that runs inside my program. > > Python code have to call c++ method and register some callback. > > > > I know that swig helps when python creates c++ instance but i've the > > instance and i want to use it with python. > > That is the same case, wrt SWIG - the objects methods get accessed by > functions like > > int Object_foo(Object *s) { > return s->foo(); > } Can you post few line of code ? > So passing a exiting object reference to such a function will work. You > might also consider using SIP, it appears to me to be much more OO. > > Diez well i'll look to SIP but i prefer to use swig because it can interface C++ with other language such as ruby -- Ciao Fabio From zen19725 at zen.co.uk Wed Aug 3 10:15:09 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Wed, 3 Aug 2005 15:15:09 +0100 Subject: ANN: Kamaelia 0.2.0 released! References: <42ee6ee6$0$91540$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: On 03 Aug 2005 17:30:31 +0400, Sergei Organov wrote: >zen19725 at zen.co.uk (phil hunt) writes: >[...] >> Unix pipelines act on ascii files; > >No, they don't. Nitpicker. I would have thought it was perfectly obvious, in context, what I meant. -- Email: zen19725 at zen dot co dot uk From weekender_ny at yahoo.com Sun Aug 7 12:08:46 2005 From: weekender_ny at yahoo.com (John) Date: 7 Aug 2005 09:08:46 -0700 Subject: socket + file i/o question Message-ID: <1123430926.790390.195590@f14g2000cwb.googlegroups.com> I am sending a file on a tcp socket using the following code while 1: buf = os.read(fd, 4096) if not buf: break print total, len(buf) conn.send(buf) The recieving code looks like while 1: if recvbytes == filesize: print 'Transfer done. Size = %d' % recvbytes break buf = s.recv(4096) if not buf: print 'EOF received' raise Exception() print recvbytes, len(buf) os.write(fd, buf) recvbytes = recvbytes + len(buf) My problem is that the first time the client uploads a file to the server, the code works. But then when the server wants to download a file to the client, the same code breaks down! The problem seems to be the socket. The send part sends exactly the amount of data it reads from the file. But the recv part gets one more byte than the size of the file?? It seems to me that this extra one byte is coming inside the send/recv calls. Anyone has any comments on where this extra one byte is coming from? Thanks a lot for your help, --j From rafi at free.fr Tue Aug 2 17:18:35 2005 From: rafi at free.fr (rafi) Date: Tue, 02 Aug 2005 23:18:35 +0200 Subject: Art of Unit Testing In-Reply-To: <42efe1ec$0$3713$626a14ce@news.free.fr> References: <87mzo0s25q.fsf@lucien.dreaming> <42efe1ec$0$3713$626a14ce@news.free.fr> Message-ID: <42efe330$0$3713$626a14ce@news.free.fr> rafi wrote: > In order to unit test a function / method one should use mock objects, > otherwise you may not be sure that your code is faulty. 'should' may be too strong, 'may' may be better. In the meantime I found: http://python-mock.sourceforge.net/ my 2 cents -- rafi "Imagination is more important than knowledge." (Albert Einstein) From prabapython at yahoo.co.in Tue Aug 23 02:57:53 2005 From: prabapython at yahoo.co.in (praba kar) Date: Tue, 23 Aug 2005 07:57:53 +0100 (BST) Subject: Reg python nature. In-Reply-To: Message-ID: <20050823065753.38171.qmail@web8408.mail.in.yahoo.com> Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? regards Prabaha ____________________________________________________ Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html From tjreedy at udel.edu Sat Aug 13 08:29:56 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Aug 2005 08:29:56 -0400 Subject: Bug on Python2.3.4 [FreeBSD]? References: <1123906696.459433@yasure> Message-ID: "Donn Cave" wrote in message news:1123906696.459433 at yasure... > Quoth "Terry Reedy" : > | Standard C, by Plauger & Brodie says that 'a' plus whatever else means > all > | writes start at the current end-of-file. > > Of course, but the question was, where do reads start? For 'a+', that book, and perhaps the standard, does not specify where an *initial* read starts. It only says file position is set to end-of-file 'before each write' and that reads after a write (and vice versa) 'must' follow an intervening file-positioning call (fflush, fseek, fsetpos, rewind). > guess the GNU C library "innovated" on this point. If there is a hole in the standard, 'innovation' is required. Terry J. Reedy From aaron.ginn at gmail.com Tue Aug 30 15:26:42 2005 From: aaron.ginn at gmail.com (Angelic Devil) Date: 30 Aug 2005 12:26:42 -0700 Subject: File parser References: <1125368427.186511.149810@g47g2000cwa.googlegroups.com> Message-ID: "Rune Strand" writes: Thanks. This shows definate promise. I've already tailored it for what I need, and it appears to be working. -- "Society in every state is a blessing, but Government, even in its best state, is but a necessary evil; in its worst state, an intolerable one." -- Thomas Paine From tim.golden at viacom-outdoor.co.uk Mon Aug 15 11:39:35 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 15 Aug 2005 16:39:35 +0100 Subject: get a list of mounted filesystems under MacOSX Message-ID: <9A28C052FF32734DACB0A288A3533991044D21C1@vogbs009.gb.vo.local> [garabik-news-2005-05 at kassiopeia.juls.savba.sk] | And when we are at this, how to find out a list of mounted filesystems | under MS Windows? (yes, I know, there is a difference between cygwin | python and native port, and the term "mounted" is not used in | MS Windows | world much) WMI will do it under Win32. (Don't know about Cygwin). import wmi for d in wmi.WMI ().Win32_LogicalDisk (): print d.Caption, d.Description, d.ProviderName 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 haircut at gmail.com Wed Aug 31 21:08:04 2005 From: haircut at gmail.com (Adam Monsen) Date: 31 Aug 2005 18:08:04 -0700 Subject: time.strptime() for different languages In-Reply-To: References: <1125519061.261802.285840@o13g2000cwo.googlegroups.com> <1125522144.209140.266590@f14g2000cwb.googlegroups.com> Message-ID: <1125536884.953514.226790@o13g2000cwo.googlegroups.com> Strange, but I can't figure out how to switch back to the default locale. >>> import locale, datetime, time >>> locale.setlocale(locale.LC_ALL, 'nl_NL') 'nl_NL' >>> date = '10 augustus 2005 om 17:26' >>> time.strptime(date, "%d %B %Y om %H:%M") (2005, 8, 10, 17, 26, 0, 2, 222, -1) >>> locale.setlocale(locale.LC_ALL, '') 'en_US.UTF-8' >>> date = '10 August 2005 at 17:26' >>> time.strptime(date, "%d %B %Y at %H:%M") Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/_strptime.py", line 292, in strptime raise ValueError("time data did not match format: data=%s fmt=%s" % ValueError: time data did not match format: data=10 August 2005 at 17:26 fmt=%d %B %Y at %H:%M Also, locale.resetlocale() throws locale.Error (I saw some open bugs on this). Ugh! Is this stuff broken or is it just me? -- Adam Monsen http://adammonsen.com/ From nothingcanfulfill at gmail.com Tue Aug 9 15:02:32 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 9 Aug 2005 12:02:32 -0700 Subject: Import question Message-ID: <1123614152.482652.72900@g44g2000cwa.googlegroups.com> In file A, I have an instance of a class and then I import file B (import fileB as fb). In file B, I need to access file A's class instance. Is there anyway I can do this? (I hope that was descriptive enough :\) -Wes From tim.golden at viacom-outdoor.co.uk Tue Aug 23 03:30:45 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue, 23 Aug 2005 08:30:45 +0100 Subject: X-Platform method of remote execution of Windows programs Message-ID: <9A28C052FF32734DACB0A288A3533991044D21E2@vogbs009.gb.vo.local> [utabintarbo at gmail.com] | Well, I can do this using WMI thru VBScript for Windows-Windows | connections. What I would like is a method using python for both | Windows-Windows and Linux-Windows connections. I've looked at pyWMI | (http://tgolden.sc.sabren.com/python/wmi.html), and found it | unclear in it's dealings with remote boxes. A look at win32com netted me | a load of "Access Denied" errors. Well, assuming I understand the question, the wmi module won't help you if you're running on Linux, as it's just a thin wrapper around the pywin32 extensions which will only work on Windows. I remember hearing tell of a WBEM-on-Linux recently which might, I suppose, get you so far, but WMI uses the DCOM infrastructure to communicate cross-machine, so you'd have to factor that in somehow, too. That said, I'd like to know in what way the wmi is unclear about its dealing with remote boxes (if only to improve my documentation). Basically, rather than doing: import wmi c = wmi.WMI () you do: import wmi c = wmi.WMI ("name_of_other_box") and then carry on as before. I admit there are issues of security and so on, especially -- I gather -- on XP, where they've actually applied some of the security contexts that the WMI documentation talks about. But that's to do with WMI itself, and not to do with Python, afaict. Tim Golden ________________________________________________________________________ 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 caseyhHAMMER_TIME at istar.ca Sun Aug 14 14:27:00 2005 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Sun, 14 Aug 2005 18:27:00 GMT Subject: Permutation Generator References: Message-ID: It's hard to make "complete" permutation generators, Knuth has a whole fascicle on it - "The Art of Computer Programming - Volume 4 Fascicle 2 - Generating All Tuples and Permutations" - 2005 -- Regards, Casey From yxxxxlxxxxx at gmail.com Mon Aug 8 14:47:25 2005 From: yxxxxlxxxxx at gmail.com (yaffa) Date: 8 Aug 2005 11:47:25 -0700 Subject: sample script to write results of html scrape to mysql db? Message-ID: <1123526845.267249.312020@o13g2000cwo.googlegroups.com> does anyone have a sample script that writes results of html scraping to a mysql db? From jdhunter at ace.bsd.uchicago.edu Wed Aug 24 16:17:21 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 24 Aug 2005 15:17:21 -0500 Subject: use SciPy with Python 2.4.1? References: <1124895877.968739.323680@o13g2000cwo.googlegroups.com> Message-ID: <877jebjdim.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "Robert" == Robert Kern writes: Robert> beliavsky at aol.com wrote: >> Is SciPy usable with Python 2.4.1? At >> http://www.scipy.org/download/ it says that 2.3.3 is >> recommended, and I don't see a binary for 2.4.1. Robert> It is usable with Python 2.4.1 on Linux and OS X at Robert> least. IIRC, mingw-compiled extensions don't work with the Robert> standard Python 2.4.1 interpreter, which is, I believe, Robert> the largest holdup for Windows binaries for 2.4.1. I routinely compile matplotlib with mingw for 2.4 and haven't had any problems. If I recall correctly, a trivial patch for distutils is needed which is described at http://mail.python.org/pipermail/python-list/2004-December/254826.html JDH From bokr at oz.net Thu Aug 18 22:46:39 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 19 Aug 2005 02:46:39 GMT Subject: Module Name Conflicts References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: <430546d5.1827031121@news.oz.net> On Thu, 18 Aug 2005 16:46:42 -0700, Robert Kern wrote: >Dan Sommers wrote: > >> Assuming you can fiddle with sys.path at the right times, you can call >> an imported module anything you want: >> >> fix_sys_path_to_find_java_cmd_first() >> import cmd as java_cmd >> fix_sys_path_to_find_python_cmd_first() >> import cmd as python_cmd >> >> Obviously, then, 'cmd' does not reference either module; you'd have to >> use java_cmd and python_cmd as appropriate. > >That doesn't work. The first module is recorded as 'cmd' in sys.modules >and gets reused on the second import. > >[~]$ mkdir foo1 >[~]$ mkdir foo2 >[~]$ touch foo1/blah.py >[~]$ touch foo2/blah.py >[~]$ python >Python 2.4.1 (#2, Mar 31 2005, 00:05:10) >[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin >Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> sys.path.insert(0,'foo1') > >>> import blah as blah1 > >>> sys.path.insert(0,'foo2') > >>> import blah as blah2 > >>> sys.modules['blah'] > > >>> blah2.__file__ >'foo1/blah.py' > >>> > How about (untested) import new blah1 = new.module('blah') execfile('./foo1/blah.py', blah1.__dict__) blah2 = new.module('blah') execfile('./foo2/blah.py', blah2.__dict__) Of course, there is the issue of caching .pyc's and what to put in sys.path and sys.modules, but blah1 and blah2 ought to be usable, I think. Regards, Bengt Richter From sjmachin at lexicon.net Sun Aug 21 10:09:46 2005 From: sjmachin at lexicon.net (John Machin) Date: Mon, 22 Aug 2005 00:09:46 +1000 Subject: import __main__ where can i find a module called "__main__.py"? In-Reply-To: References: Message-ID: <43088b28$1@news.eftel.com> wen wrote: > and, in which case, the following case will happen: > if __name__!='__main__': > do_sth() > > any help would be appreciated. > > Sorry, but your question is rather difficult to interpret. For a start, you don't need/want to import __main__. On import, __name__ is set to the name of the module. When a source file is run as a script, there is no module, so __name__ is set to the dummy value "__main__". The module __main__ doesn't exist, and its source file __main__.py doesn't exist either (this side of the looking-glass). Below is a minimal example of the behaviour of __name__. C:\junk>type wenmain.py print "__name__:", __name__ C:\junk>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import wenmain __name__: wenmain >>> ^Z C:\junk>python wenmain.py __name__: __main__ Hope this helps, John From wouter at voti.nl Sun Aug 28 15:43:35 2005 From: wouter at voti.nl (Wouter van Ooijen www.voti.nl) Date: Sun, 28 Aug 2005 19:43:35 GMT Subject: python image thumbnail generator? References: Message-ID: <4312136f.86862341@news.xs4all.nl> >I'm thinking it would be nice and easy, if we could just upload a jpg into >a dir called "gallery/". When the client clicks the "gallery" link, a >cgi script could search the gallery/ dir, and create thumbnails of any >jpeg images that don't already have a thumbnail associated with them. The >script could then generate a page of clickable thumbnails. I dunno about the scripting aspect, but I use Python to generate my website, I already had the images (of the products I sell). I used PIL to generate thumbnails of the images. I think it took 2 or 3 lines of Python - that is: for me. PIL is of course a bit more. Wouter van Ooijen -- ------------------------------------ http://www.voti.nl Webshop for PICs and other electronics http://www.voti.nl/hvu Teacher electronics and informatics From eugene at boardkulture.com Sun Aug 7 10:07:26 2005 From: eugene at boardkulture.com (EuGeNe) Date: Sun, 07 Aug 2005 16:07:26 +0200 Subject: Grayson's Tkinter Programming Message-ID: Just noticed that it is now availabe as an ebook from Manning : http://www.manning.com/books/grayson I bought an edition on abebooks for a little fortune a few months ago ... From k04jg02 at kzoo.edu Sat Aug 6 01:44:07 2005 From: k04jg02 at kzoo.edu (Joseph Garvin) Date: Fri, 05 Aug 2005 23:44:07 -0600 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: <42F44E27.8000100@kzoo.edu> seberino at spawar.navy.mil wrote: >I've heard 2 people complain that word 'global' is confusing. > >Perhaps 'modulescope' or 'module' would be better? > >Am I the first peope to have thought of this and suggested it? > >Is this a candidate for Python 3000 yet? > >Chris > > > Hmm.. instead of 'global', how about 'outside' ? It seems a bit more intuitive to me because it suggests that you mean, "the variable defined outside this scope" or outside any nestedness. But then again it could be confused to mean "just one scope above this one" which isn't necessarily module scope (nested functions, etc.)... still, might be less confusing than 'global'. Another alternative to having to say "global var" would be to use some sort of indicator that you want the global with each usage, like, "global.var" or "outside.var" From gustavo.cordova at gmail.com Fri Aug 5 00:51:52 2005 From: gustavo.cordova at gmail.com (RangerElf) Date: 4 Aug 2005 21:51:52 -0700 Subject: Idiots guide to fonts with tKinter In-Reply-To: <1123146134.391156.258760@g43g2000cwa.googlegroups.com> References: <1123146134.391156.258760@g43g2000cwa.googlegroups.com> Message-ID: <1123217511.970078.117600@o13g2000cwo.googlegroups.com> Well, all text classes in Tkinter can take a " font=(...) " argument to specify the face with which to display, for example: from tkinter import * .... label = Label(root, font=("Helvetica", "bold", 13), ...) It's been a while since I've played with Tkinter, so I might be a little off on the exact syntax, but that's the main idea. It's really simple once you get the hang of it. Regarding the text editor: it's an excellent idea. By using Tkinter's text widget you can get a bit of milage easily; you'll have to define and use "tags" in order to organize your text styles, it'll make everything quite a bit easier. You can glean a bunch of info from Idle's sources. Good luck :-) -gus From andreas at kostyrka.org Mon Aug 29 03:21:02 2005 From: andreas at kostyrka.org (Andreas Kostyrka) Date: Mon, 29 Aug 2005 09:21:02 +0200 Subject: Lossless Number Conversion In-Reply-To: References: Message-ID: <1125300062.26038.4.camel@andi-lap> Am Sonntag, den 28.08.2005, 21:36 +0000 schrieb Chris Spencer: > Is there any library for Python that implements a kind of universal > number object. Something that, if you divide two integers, generates a > ratio instead of a float, or if you take the square root of a negative, > generates a complex number instead of raising an exception? Lisp has > something like this, and it makes number crunching much more convenient. Yes and no. There isn't general solution. But for example you want to allow complex number, just use cmath. Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Dies ist ein digital signierter Nachrichtenteil URL: From bj_666 at gmx.net Fri Aug 19 19:06:49 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sat, 20 Aug 2005 01:06:49 +0200 Subject: pickle.load not working? References: <1123884180.348659.247960@z14g2000cwz.googlegroups.com> <1124379754.569717.25810@f14g2000cwb.googlegroups.com> Message-ID: In <1124379754.569717.25810 at f14g2000cwb.googlegroups.com>, sp1d3rx at gmail.com wrote: > oh, well how do I make "derek" be an instance of 'chatuser' ? Spot the difference:: In [228]: class A: pass .228.: In [229]: a = A In [230]: repr(a) Out[230]: '' In [231]: b = A() In [232]: repr(b) Out[232]: '<__main__.A instance at 0x4075e52c>' Ciao, Marc 'BlackJack' Rintsch From eddie at holyrood.ed.ac.uk Fri Aug 26 11:23:32 2005 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Fri, 26 Aug 2005 15:23:32 +0000 (UTC) Subject: How to know if connection is active when using telnetlib? References: Message-ID: Wojciech Halicki-Piszko writes: >How to know if connection is active after telnetlib.Telnet.open(host,port)? If open() doesn't throw an exception then you should have a connection you can start reading/writing with. Unless you have some special meaning for 'active'? I'm just basing this on reading telnetlib.py. Eddie From zen19725 at zen.co.uk Mon Aug 15 16:56:56 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Mon, 15 Aug 2005 21:56:56 +0100 Subject: SOAP and XMLRPC References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> Message-ID: On Mon, 15 Aug 2005 20:04:55 +0200, Magnus Lycka wrote: >dcrespo wrote: >> Hi to all... >> Someone knows if is there possible to have a Python SOAP or XMLRPC >> server that works with VB? I would like you to include the examples >> clients and server programs. > >If you can write an XML-RPC client in VB, it will work with >XML-RPC servers written in any language. This is the wrong >forum to learn how to do that though. May I suggest that you >google for "visual basic xml-rpc client" I thought it was the whole point of XMLRPC that the server can be written in one language and the client in another. Am I wrong? -- Email: zen19725 at zen dot co dot uk From rkern at ucsd.edu Thu Aug 18 20:07:41 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 18 Aug 2005 17:07:41 -0700 Subject: Module Name Conflicts In-Reply-To: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> References: <1124406406.620743.242650@g44g2000cwa.googlegroups.com> Message-ID: torched_smurf at yahoo.com wrote: > I have a java program in a package called 'cmd'. This of course > conflicts with the builtin python package of the same name. The thing > is, I need to be able to import from both of these packages in the same > script. I can import either one first, but any future attempt to import > from cmd.* will look up the first cmd that was imported, so the second > package is essentially eclipsed. I've tried fiddling with sys.path and > sys.packageManager.searchPath, to no avail. To answer the obvious first > suggestion, no I can't rename the java package to 'Cmd' or anything > like that. Any ideas? Why not copy cmd.py into your package under a different name? -- 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 berlin.brown at gmail.com Fri Aug 26 17:31:18 2005 From: berlin.brown at gmail.com (Berlin Brown) Date: 26 Aug 2005 14:31:18 -0700 Subject: Python Light Revisted? In-Reply-To: References: <6Jydnde_uvYa8JreRVn-gw@comcast.com> Message-ID: <1125091878.533502.161300@z14g2000cwz.googlegroups.com> "Let's suppose I decided to take your bait and build a python-lite distribution (fyi, I'm not biting). " Of course not, that is the point, everybody is always right. What I want is the option to distribute something to light my users. I have done with java, lisp and other languages. But. I can't figure out the best approach for Python. And, with python being the only implementation, that is another story? I also don't want to use their messed up Python install that may or may not work. It is the microsoft registry issue, meaning; I don't like the concept of one source for screws up. If a user screws up their Python install, and I submit an application to them and now my application is screwed up, what can I do? Control is a good thing. I was considering something light, mainly for the application only, user clicks start and they are off. "What about compatibility? If someone installs the python-lite distro then downloads, let's say, Tailor, a version control converter. What are the chances that it will croak with an ImportError? Put another way, are you really willing to trade off a few megs of disk space against almost certain breakage at some point in the near future?" It wont get that complex. Python-lite is designed for each application. It is lite so you won't lose that much diskspace. "I can understand that distributions for some platforms (PalmOS, OS/2, Amiga, Jython) might contain fewer modules simply because not everything has been ported to them, but given the cost of disk space today I don't understand why a distribution for a mainstream platform should be hobbled. " I use jython works great, because I can distribute the light version. The only thing that has to work is java and I distribute the interpreter to all of my apps as the jython.jar library. From benji at benjiyork.com Wed Aug 17 11:50:05 2005 From: benji at benjiyork.com (Benji York) Date: Wed, 17 Aug 2005 11:50:05 -0400 Subject: Testing for presence of arguments In-Reply-To: <430353e1$0$18641$14726298@news.sunsite.dk> References: <430353e1$0$18641$14726298@news.sunsite.dk> Message-ID: <43035CAD.1060308@benjiyork.com> Madhusudan Singh wrote: > I know how to set optional arguments in the function definition. Is there an > intrinsic function that determines if a certain argument was actually > passed ? Like the fortran 95 present() logical intrinsic ? People generally use a value that isn't a valid option, often None. def my_func(a, b, c=None): if c is None: do something If None is a valid value, make one that isn't: unspecified = object() def my_func(a, b, c=unspecified): if c is unspecified: do something -- Benji York From chris2k01 at hotmail.com Sat Aug 27 14:58:40 2005 From: chris2k01 at hotmail.com (Chris Head) Date: Sat, 27 Aug 2005 18:58:40 GMT Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Bokma wrote: > Chris Head wrote: > > >>John Bokma wrote: >> >>>Chris Head wrote: > > > [HTML] > > >>>It can be made much faster. There will always be a delay since >>>messages have to be downloaded, but with a fast connection and a good >>>design, the delay will be very very small and the advantages are big. >> >>What advantages would those be (other than access from 'net cafes, but >>see below)? > > > And workplaces. Some people have more then one computer in the house. My > partner can check her email when I had her over the computer. When I > want to check my email when she is using it, I have to change the > session, fire up Thunderbird (which eats away 20M), and change the > session back. > > [ .. ] Hmm. That would just be a matter of preference. Personally I moved my Thunderbird profile into a shared directory and pointed everyone at it. Now only one login session can run Thunderbird at a time, but any login can see everyone's mailboxes. > > >>>Each has it's place. A bug in a thick client means each and everyone >>>has to be fixed. With a thin one, just one has to be fixed :-D. >> >>True. However, if people are annoyed by a Thunderbird bug, once it's >>fixed, most people will probably go and download the fix (the >>Thunderbird developers really only need to fix the bug once too). > > > Most people who use Thunderbird, yes. Different with OE, I am sure. With > a thin client *everybody*. True. As a programmer I don't usually think about the people who never download updates. The way I look at it, if somebody doesn't have the latest version, they shouldn't be complaining about a bug. I guess thin clients could be taken to mean you have a very light-weight auto-update system ;) > > >>>Depends on where your mailbox resides. Isn't there something called >>>MAPI? (I haven't used it myself, but I recall something like that). >> >>IMAP. It stores the messages on the server. Even so, it only has to >>transfer the messages, not the bloated UI. > > > But technically the UI (whether bloated or not) can be cached, and with > Ajax/Frames, etc. there is not really a need to refresh the entire page. > With smarter techniques (like automatically zipping pages), and > techniques like transmitting only deltas (Google experimented with this > some time ago) and better and faster rendering, the UI could be as fast > as a normal UI. > > Isn't the UI in Thunderbird and Firefox created using JavaScript and > XML? Isn't how future UIs are going to be made? I believe it is. I'm not sure if it's a good idea, but that's neither here nor there. > > >>I concede that Webmail >>might be just as fast when using a perfectly-designed >>Javascript/frames-driven interface. In the real world, Webmail isn't >>(unfortunately) that perfect. > > > Maybe because a lot of users aren't really heavy users. A nice example > (IMO) of a web client that works quite good: webmessenger ( > http://webmessenger.msn.com/ ). It has been some time since I used it > the last time, but if I recall correctly I hardly noticed that I was > chatting in a JavaScript pop up window. Haven't ever needed to use that program. > > >>As I said above regarding 'net cafes: >> >>If the Internet cafe has an e-mail client installed on their >>computers, you could use IMAP to access your messages. You'd have to >>do a bit more configuration than for Webmail, so it depends on the >>user I guess. Personally I doubt my ISP would like me saving a few >>hundred megs of e-mail on their server, while Thunderbird is quite >>happy to have 1504 messages in my Inbox on my local machine. If I had >>to use an Internet cafe, I would rather use IMAP than Webmail. > > > I rather have my email stored locally :-) But several webmail services > offer a form to download email. I've not seen a service that allows that. Sounds nice. > > >>>>Ergo, >>>>Thunderbird is faster as soon as the Internet gets congested. >>> >>>Ah, yeah, wasn't that predicted to happen in like 2001? >> >>Wasn't what predicted to happen? Congestion? It happens even today >>(maybe it's the Internet, maybe it's the server, whatever...). Hotmail >>is often pretty slow. > > > I read sometime ago that about 1/3 of traffic consists out of bittorrent > traffic... If the Internet gets congested, new techniques are needed, > like mod_gzip on every server, a way to transfer only deltas of webpages > if an update occured (like Google did some time ago). Better handling of > RSS (I have the impression that there is no "page has not been > modified" thing like with HTML, or at least I see quite some clients > fetch my feed every hour, again and again). > Eventually you reach the point where it's not bandwidth any more, it's server load. All these things like mod_gzip, deltas, and so on add server load. As to the point about "page not modified", it's not in the HTML spec, it's in the HTTP spec. RFC2616 (HTTP1.1) defines an "If-Modified-Since" header a client may send to the server indicating that it has a cached copy of the page at that date. If the page has not changed, the server should send HTTP 304 (not modified) with no content. For best results (due to clock mismatches etc), the client should set the If-Modified-Since header to the value of the Last-Modified header sent by the server when the page was first requested and cached. I think we can agree that in some cases, Webmail is better, and in others, clients are better. Much of this will be personal preference, and I would like to see ISPs offering both methods of accessing e-mail (as mine in fact does - POP3 and Webmail). Chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (MingW32) iD8DBQFDELff6ZGQ8LKA8nwRApxiAKDBU2R5KYAhp/4MJDoLlrbC5hWpLgCeNbnh YK2tCasrMOY3SaUV1gMtZdg= =N2wk -----END PGP SIGNATURE----- From grante at visi.com Tue Aug 23 23:46:32 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 24 Aug 2005 03:46:32 -0000 Subject: Logging all activity on a tty/pty? References: Message-ID: <11gnrco6e2v133@corp.supernews.com> On 2005-08-23, Dan Stromberg wrote: > > Is there a way, using python, to (voluntarily) log all activity in a > given shell, in a way that should work on pretty much all *ix's with a > port of python? Yes. Assuming the Unix implimentation has ptys. -- Grant Edwards grante Yow! Excuse me, but didn't at I tell you there's NO HOPE visi.com for the survival of OFFSET PRINTING? From bokr at oz.net Tue Aug 23 19:32:54 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 23 Aug 2005 23:32:54 GMT Subject: Best way to 'touch' a file? References: <38SdnUQ_VbE5kJTeRVn-qA@powergate.ca> Message-ID: <430bac85.2246279649@news.oz.net> On Tue, 23 Aug 2005 08:23:40 -0400, Peter Hansen wrote: >Fredrik Lundh wrote: >> Peter Hansen wrote: >> >>>You've quoted selectively. He also said "Unix-style 'touch'", from >>>which one could quite legitimately infer >> >> nope. read his post again. > >Sigh. You're being tiring, Fredrik: > >'''I'm looking for an easy way to perform a UNIX-style "touch", to >update the modification time of a file without actually modifying it.''' > >And if your point is that I spelled UNIX in mixed case, and change the >double quotation marks to single quotation marks, you really need to >take a break. > >If your point is that this statement *clearly and unambiguously* rejects >the create-if-missing feature as undesirable, then I can say only that >you are simply wrong. > OTOH, if I had to bet, I would bet that the part where it says, "... to update the modification time of a file..." indicates a pre-existing file. Otherwise it wouldn't be "updating," but just creating a first time-stamp along with the new file ;-) At least, that's what I imagine when I see those words. In your favor, I think the comma after '"touch"' tends to disconnect the purpose that follows, perhaps even from consciousness, reading quickly. What if the emphasis were changed? E.g., how would you have interpreted the same words rearranged as follows? '''I'm looking for an easy way to update the modification time of a file (to perform a UNIX-style "touch") without actually modifying it.''' Regards, Bengt Richter From steve at holdenweb.com Mon Aug 22 08:12:12 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Aug 2005 13:12:12 +0100 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon wrote: > Op 2005-08-19, Donn Cave schreef : > >>In article , >> Antoon Pardon wrote: >>... >> >>>But '', {}, [] and () are not nothing. They are empty containers. >> >>Oh come on, "empty" is all about nothing. > > > No it is not. There are situation where False or None should > be treated differently from an empty sequence. > > Empty can mean, "nothing yet" which should be treated > differently from "nothomg more". > > >>>And 0 is not nothing either it is a number. Suppose I have >>>a variable that is either None if I'm not registered and a >>>registration number if I am. In this case 0 should be treated >>>as any other number. >>> >>>Such possibilities, make me shy away from just using 'nothing' >>>as false and writing out my conditionals more explicitly. >> >>Sure, if your function's type is "None | int", then certainly >>you must explicitly check for None. > > > The fact is that python doesn't know which type a function is. > So why does python guess that zero should be treated as false. > Python doesn't guess. There are a range of values that will be treated, in a Boolean context (how perlish) as equivalent to False. If your function is capable of validly returning any of these values then your calls must be prepared to discriminate between (say) zero and False or None. If not, the calling experession in the "if" can be simpler. > >>That is not the case with >>fileobject read(), nor with many functions in Python that >>reasonably and ideally return a value of a type that may >>meaningfully test false. In this case, comparison (==) with >>the false value ('') is silly. > > > No is is not. The comparison with the specific false value > makes it easier for the reader of the code to find out what > to expect. I also find the use of '' as false in this context > wrong. A read can be used on all kind of objects including > a network connection. Returning '' on a network read would > be IMO the most natural answer to say, the network connection > is still open but no data is available for the moment. '' here > would mean "nothing yet" while '' is now made into "nothing more" > Yes, but you are restricting the programmer's range of expression if you promote this as a general rule. Sometimes it's important to discriminate between "", (), [] and None, sometimes there is no possiblity that confusion will arise. When there's no possibility of confusion you arae just picking nits (which I know your sense of intellectual tidiness encourages you to do ;-). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mhenry1384 at gmail.com Tue Aug 16 13:55:16 2005 From: mhenry1384 at gmail.com (mhenry1384) Date: 16 Aug 2005 10:55:16 -0700 Subject: get the return code when piping something to a python script? Message-ID: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> On WinXP, I am doing this nant.exe | python MyFilter.py This command always returns 0 (success) because MyFilter.py always succeeds. MyFilter.py looks like this while 1: line = sys.stdin.readline() if not line: break ... sys.stdout.write(line) sys.stdout.flush() How do I set the return code from MyFilter.py based on the return of nant.exe? Is this possible? I have googled around for an hour wihtout success. I understand that I could have MyFilter.py call "nant.exe", but for various reasons, that's not idea for my situation. From dr_tyson at hotmail.com Tue Aug 30 12:47:42 2005 From: dr_tyson at hotmail.com (dr_tyson at hotmail.com) Date: 30 Aug 2005 09:47:42 -0700 Subject: Embedding Matplotlib images into wxPython Message-ID: <1125420462.124637.113810@z14g2000cwz.googlegroups.com> I am trying to embed images into a wxPython app (created using Boa Constructor), but have not been able to do so. I know how to embed plots, but images seem to be a problem. I've tried using code analogous to the example given at the Matplotlib website to no avail. If anybody has been successful at this could you please post some sample code? That would be greatly appreciated. Thanks! Randy From bdesth.quelquechose at free.quelquepart.fr Sun Aug 21 18:32:47 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 22 Aug 2005 00:32:47 +0200 Subject: Further questions on dictionaries, namespaces, etc. In-Reply-To: References: Message-ID: <4308f935$0$17664$636a15ce@news.free.fr> Talin a ?crit : (snip) > 2) Is there an easy way to determine if a given object has a callable > method named "unify"? if callable(getattr(obj, 'unify', None)): # obj.unify exists and is callable Br From jeffrey.schwab at rcn.com Wed Aug 10 00:13:11 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Wed, 10 Aug 2005 00:13:11 -0400 Subject: Creating a virtual file system In-Reply-To: References: <1123285628.861289.107600@g44g2000cwa.googlegroups.com> Message-ID: Bryan Olson wrote: > Jeff Schwab wrote: > > You don't have to pay Microsoft to develop a Windows-compatible > > filesystem. See http://ubiqx.org/cifs/. > > That's a different usage of "filesystem" than what is at issue > here. I agree that you & I are probably discussing different things, but I think this is exactly what the OP was seeking. He said: > I'm working on a project to implement a simple cross-platform file > sharing protocol (using Python) that is similar to HTTP, and I > have to write a GUI for Windows and Linux. Sure sounds like CIFS to me. > My question is: How do I implement a virtual partition that acts > like a real file-system and is compleatly transparent to other > programs? Should I make a virtual file allocation table for a > FAT32 partition or simulate an NTFS? Or even further: How do I > create a junction (or a hard link) to it in "My network places" or > in "Entire Network"? CIFS is the canonical way to make resources show up in Network Neighborhood. The OP even said: > If there are tools that could help me but written in C or C++, > please let me know, I'll compile them to Python modules. Free, open source CIFS implementations already exist in C and Java. I'm guessing that to you (as to many of us) a filesystem is usually a way of mapping blocks on a device to parts of files, but I don't think that's what the OP actually wanted. From desparn at wtf.com Mon Aug 22 10:29:31 2005 From: desparn at wtf.com (Rick Wotnaz) Date: Mon, 22 Aug 2005 10:29:31 -0400 Subject: loop in python References: Message-ID: km wrote in news:mailman.3360.1124720412.10512.python-list at python.org: > Hi all, > > Why is it that the implementation of empty loop so slow in > python when compared to perl ? > > #i did this in python (v 1.5) > for x in xrange(1000): > print x > # this took 0.017 seconds > -------------------------- > #similar code in perl (v 5.6): > for $x (0..1000) > { > print $x; > } > # this took 0.005 seconds only !!! > > Is python runtime slow at all aspects when compared to perl ? > I really wonder what makes python slower than perl ? > Is there any proposal to make python faster in future versions ? > > curious to know all these ... > It appears that Python is not optimized for empty loops. -- rzed From max at alcyone.com Tue Aug 16 23:40:11 2005 From: max at alcyone.com (Erik Max Francis) Date: Tue, 16 Aug 2005 20:40:11 -0700 Subject: How to obtain GMT offset? In-Reply-To: <43023bdf.1627616969@news.oz.net> References: <43023bdf.1627616969@news.oz.net> Message-ID: Bengt Richter wrote: > > time.timezone gives you the timezone offset in minutes. > > ITYM seconds? I sure did. But at least minutes is a more entertaining answer. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis If you are afraid of loneliness, do not marry. -- Anton Chekhov From uval at rz.uni-karlsruhe.de Thu Aug 11 11:25:53 2005 From: uval at rz.uni-karlsruhe.de (Daniel Schüle) Date: Thu, 11 Aug 2005 17:25:53 +0200 Subject: len(sys.argv) in (3,4) Message-ID: Hello I wrote a simple module, which is also supposed to be used as standalone program after considering how to avoid multiple if's I came up with this idea if __name__ == "__main__": if len(sys.argv) not in (3,4): print "usage: prog arg1 argv2 [-x]" # etc ... while develeoping I had my interpeter running and reloaded module now since I am ready, I wanted to run it from cmd windows shell but it always prints "usage ..." I added print len(sys.arg) and it prints 1 though I am provinding more than 1 value C:\pool\vhd2h\python>vhd2h.py vhd.vhd vhd.h -o 1 usage: vhd2h.py vhdlFile hFile [-o] Someone got an idea what may be wrong? -- Daniel From dotpyFE at gmail.com Sat Aug 20 10:42:08 2005 From: dotpyFE at gmail.com (Lucas Raab) Date: Sat, 20 Aug 2005 14:42:08 GMT Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? In-Reply-To: References: Message-ID: <4jHNe.9077$ns.9030@newsread1.news.atl.earthlink.net> Miernik wrote: > On my Debian GNU/Linux system I have Python 2.3 installed in > /usr/lib/python2.3/ where most Python system files like > > /usr/lib/python2.3/gzip.py > /usr/lib/python2.3/gzip.pyc > /usr/lib/python2.3/gzip.pyo > > live, besides of course /usr/bin/python2.3 > > I noticed that all those files come in three "flavours": > *.py *.pyc *.pyo > > Is it possible that only one "flavour" of these files is needed, and I can > delete the remaining two, any my Python installation will still work? > > The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting > two "flavours" would save about 10 MB on my system, and that would help > me much as I am trying to fit my system on a 256 MB SD card, to make it > quiet (hard disks are noisy). > > Can I just do > cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc > for example, and everything will still work as before? > You can delete any two of the three and you shouldn't run into any problems. However, the .py files are the source code and .pyc and .pyo are compiled Python files. The .pyc and .pyo files will load faster because they are compiled. Also, if you keep the .py files and then execute them, .pyc files will be generated. In short, I would keep the .pyc files and delete the others. -- -------------------------- Lucas Raab lvraab"@"earthlink.net dotpyFE"@"gmail.com AIM: Phoenix11890 MSN: dotpyfe "@" gmail.com IRC: lvraab ICQ: 324767918 Yahoo: Phoenix11890 From pinard at iro.umontreal.ca Thu Aug 25 13:22:53 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Thu, 25 Aug 2005 13:22:53 -0400 Subject: Fighting Spam with Python In-Reply-To: References: Message-ID: <20050825172253.GA11954@phenix.progiciels-bpi.ca> [David MacQuigg] > The key new features needed in a spam filter are the ability to > extract the sender's identity (not that of the latest forwarder), and > to factor into the spam score the reputation of that identity. This will only work if your system is immune to forgeries, while being largely widespread. > In the flow we envision, the spam filter is the final process, used > only on the 5% that is hard to classify. 80% will get an immediate > reject. 15% will get an immediate accept without filtering, because > the sender is authenticated and has a good reputation. Eventually, > all reputable senders will join the 15%, and the 5% will shrink to > where we can ignore it. It's fun to read statistics about a vision! :-) > >You might find www.spambayes.org of interest, in several ways. Spambayes is surprisingly good as it already stands. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From jsaker at americanrelay.com Tue Aug 2 11:13:53 2005 From: jsaker at americanrelay.com (James Saker) Date: Tue, 2 Aug 2005 10:13:53 -0500 Subject: Class design for parser object Message-ID: <200508021013.54102.jsaker@americanrelay.com> I've been working on a Python class object for APRS (Automatic Position Reporting System - a digital mode used by amateur radio operators) and have been going through David Mertz's Text Processing in Python book to help in the construction of the parser component of the class. I was curious if there was a good reference on the most pythonic design of parsing objects. For instance, should one parse raw or formatted data upon initialization and return a boolean indicating success/failure, or require multiple steps to instantiate then parse and test? Are there generally found public methods in parsing objects that would serve as a good model? Thanks - Jamie From lonetwin at gmail.com Fri Aug 5 10:13:20 2005 From: lonetwin at gmail.com (Steve) Date: Fri, 5 Aug 2005 19:43:20 +0530 Subject: An editable buffer for the Python shell (similar to '\e' on sql prompts) Message-ID: <5a309bd305080507132e1cba43@mail.gmail.com> Hi, When working in the python command shell, I often end up writing more than 10+ lines of indented code before making a stupid typo. This got irritating enough for me to do something about it. So, here's an 'InteractiveConsole with an editable buffer'. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438813 Just thought some one else also would find this useful. Regards Steve From kenneth.m.mcdonald at sbcglobal.net Fri Aug 26 15:29:31 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Fri, 26 Aug 2005 14:29:31 -0500 Subject: Any projects to provide Javascript-style client-side browser access via Python? Message-ID: I'm curious about this because, quite aside their function as web browsers, it is now possible to build some very useable interfaces using browsers with HTML, CSS, and JavaScript. (The biggest problem is still the lack of a decent text widget.) However, JavaScript isn't really a good language for building complex applications, and it would be very cool if there were some way to use Python to replace client-side JavaScript, in order to gain access the DOM. So anyone know if there are projects underway on this? Thanks, Ken From mcfletch at rogers.com Wed Aug 10 12:31:29 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 10 Aug 2005 12:31:29 -0400 Subject: PyOpenGL In-Reply-To: <1123682107.891810.321960@o13g2000cwo.googlegroups.com> References: <1123682107.891810.321960@o13g2000cwo.googlegroups.com> Message-ID: <42FA2BE1.6060505@rogers.com> matt.walsh at gmail.com wrote: >Hey I'm a programmer looking to port some of my opengl ...although >limited into a python app I've made... I'd like to know where to find >any python/opengl source or a tutorial etc.. whatever I'd like to get a >series of points that represent a 3d slope presented to the user. > >Thanks >Matt > > That'd a fairly simple demo; you'll find a "big brother" of it in the "dots" demo with PyOpenGL (which is a particle system composed of dots (points)). OpenGLContext has a number of demos for displaying pointsets (dots), including the basic pointset test that just creates a set of 20 points or so. If what you mean is that you want to create a *mesh* from a point-set, then you need to add some more information, particularly you need a way to figure out the topological connections between points. If it's a regular x,y grid, you can readily construct the polygons, if not, you get into something a little more fuzzy. Good luck, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From jonhewer at gmail.com Fri Aug 26 06:49:34 2005 From: jonhewer at gmail.com (Jon Hewer) Date: Fri, 26 Aug 2005 11:49:34 +0100 Subject: ideas for university project ?? Message-ID: Hi I'm about to start my third, and final, year in computer science at cambridge uni, and i need to come up with an idea for a software project, but i'm really struggling for ideas, and i was wondering whether anyone here had any suggestions. I'd say i'm probably most experienced in Java, but I have started learning Python, and although i haven't got very far yet, I plan on doing some more in the next few weeks. Areas of interested include AI, distributed systems. Most of all i want something that is interesting, and actually useful (thats probably stating the obvious!) Cheers Jon From lycka at carmen.se Mon Aug 22 10:39:45 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 22 Aug 2005 16:39:45 +0200 Subject: while c = f.read(1) In-Reply-To: References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Antoon Pardon wrote: >>Python doesn't guess. There are a range of values that will be treated, >>in a Boolean context (how perlish) as equivalent to False. > > Yes it does. No it doesn't! > Python has no way to know what would be the most > usefull Boolean interpretation of these values in a particular > context. It's hardly the task of the interpreter to try to do that. > That it picks one out is guessing. No, it simply follows a well defined specification. See http://docs.python.org/ref/Booleans.html There is no guessing involved in that. > Lisp imterprets > an empty list as false, scheme interprets it as true. So > both seem usable interpretations. You might argue that *Guido* was guessing when he decided what the most useful behaviour of Python would be in this case, and there's probably some truth in that, just as there is some guesswork involved in most programming language design decisions, but that's another thing. That's not Python guessing, it's Guido using his excellent lanugage design skills. It seems most Python programmers agree that he "guessed" right here, as usual. (Perhaps you thought that "Python" was the name of the language designer. It's not. Python's design is led by Guido van Rossum, and the name Python comes from a (mostly) British comedy group.) You might also argue that this behaviour is counter to the Python dogma of "explicit is better than implicit". Python also allows you to get a float out of an expression such as "2*3.1" without forcing an explicit cast, as in "float(2)*3.1". You should note that the first Python tenet is "Beautiful is better than ugly" and that's probably what we have to blame here. There seems to be close to a consensus, that "if users:" is more beautiful than e.g. "if len(users) > 0:" or "if (len(users)==0)==False" or for that matter "if ((len(users)==0)==False)==True" or "if (((len(users)==0)==False)==True)==True" etc. What's true and false for Python, belongs to the few things you actually have to learn, and I can appreciate that it's annoying for a frequent schemer to remember that it's not the same in Python, but it seems that very few people argue with the way Python behaves in this respect. From peter at engcorp.com Wed Aug 24 17:48:00 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 24 Aug 2005 17:48:00 -0400 Subject: Exploring outlook using python In-Reply-To: <1124911125.270274.291090@g47g2000cwa.googlegroups.com> References: <1124911125.270274.291090@g47g2000cwa.googlegroups.com> Message-ID: Subir wrote: > I am new to this group. I am trying to build an application to see > all the contents of the outlook accounts (USING MAPI). Does anyone has > any information regarding this ? Did you try checking the list archives yet? Go to Google Groups (groups.google.com) and search in the comp.lang.python newsgroup for things like "outlook" or "mapi". I know there have been many past threads about similar questions, so you should start there. (I assume you've already tried to Google the web, since that should be anyone's first step before asking almost any question here.) -Peter From michael at stroeder.com Thu Aug 4 06:36:29 2005 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 04 Aug 2005 12:36:29 +0200 Subject: Secure email In-Reply-To: References: Message-ID: whisper at oz.net wrote: > I need to write a .cgi that will take the content of an https GET or > POST and send it securely as email to an Outlook client. > > I think that OpenSSL is somewhere in this, but I'm not even sure how to > create the right certificate, how to use it to encrypt mail and how to > install a certificate in Outlook (>= 2000). M2Crypto which wraps OpenSSL libs could be an option for sending S/MIME e-mails: http://sandbox.rulemaker.net/ngps/m2/ Ciao, Michael. From spam.csubich+block at block.subich.spam.com Tue Aug 9 11:19:45 2005 From: spam.csubich+block at block.subich.spam.com (Christopher Subich) Date: Tue, 09 Aug 2005 11:19:45 -0400 Subject: Passing arguments to function - (The fundamentals are confusing me) In-Reply-To: References: Message-ID: Gregory Pi?ero wrote: > Hey guys, would someone mind giving me a quick rundown of how > references work in Python when passing arguments into functions? The > code below should highlight my specific confusion: All arguments are passed by reference, but in Python equality rebinds the name. > > > > bool1=True > lst1=[1,2,3] > > def func1(arg1): arg1.append(4) In C++, pretending it had dynamic typing, this would be equivalent to: void func1( * arg1){ arg1->append(4); } > > def func2(arg1): arg1=False void func2 ( * arg2) { arg2 = &(False); > Why does my list variable get changed for the rest of the program, but > my boolean variable doesn't. What am I not understanding? In Python, "x = y" has a very definite meaning of "y is assigned to the name of x." This change does not affect whatever was in x to start with, and it certainly would not affect anything else which holds a reference to the object formerly known as x. In contrast, calling a function which mutates the object (like .append on lists, or assignment by lst[index]=something) actually changes the object itself, which is of course reflected by all other names that hold a reference to the object. From denis.kasak at gmail.com Fri Aug 26 09:48:01 2005 From: denis.kasak at gmail.com (Denis Kasak) Date: Fri, 26 Aug 2005 15:48:01 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <86wtmcm1j9.fsf@bhuda.mired.org> <6VaPe.422$MN5.100@newssvr25.news.prodigy.net> <430D7366.C2126F6D@yahoo.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n83eqF6ogbU2@individual.net> Message-ID: John Bokma wrote: > > so use Lynx :-) > > One forum I visit is about scorpions. And really, it talks a bit easier > about scorpions if you have an image to look at :-D. > > In short: Usenet = Usenet, and www = www. Why some people want to move > people from www to Usenet or vice versa is beyond me. If 80% of the current > Usenet users stop posting, Usenet is not going to die :-D Agreed. This is actually your first post with which content I agree totally. From your other posts I got the impression that you are one of those people that are trying to make Usenet and WWW more similar to one another. -- Denis From maxerickson at gmail.com Sun Aug 28 09:42:34 2005 From: maxerickson at gmail.com (Max Erickson) Date: Sun, 28 Aug 2005 13:42:34 -0000 Subject: Dynamic image creation for the web... References: Message-ID: Tompa wrote in news:mailman.86.1125225066.8229.python-list at python.org: > Hi, > > I would like to create images on the fly as a response to an http > request. I can do this with PIL like this (file create_gif.py): > from PIL import Image, ImageDraw > check out sparklines: http://bitworking.org/projects/sparklines/ It is a script very similar to what you want to do. The difference between your script and sparklines is mostly that it sends: print "Content-type: image/png" instead of: print 'Content-type: text/html' max From cam.ac.uk at mh391.invalid Fri Aug 12 03:15:37 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Fri, 12 Aug 2005 08:15:37 +0100 Subject: Cheese shop (was Re: python2.4/site-packages) In-Reply-To: References: Message-ID: Lucas Raab wrote: > Michael Hoffman wrote: >> http://www.python.org/pypi >> >> This used to be called the Python Package index but is now the Python >> Cheese Shop? Huh??? > > You've never heard the Cheese Shop Sketch by Monty Python?? I have but I've never heard of PyPI's name being changed? I can only find an announcement on Slashdot? -- Michael Hoffman P.S. Would you like another question mark for good measure??? From benji at benjiyork.com Tue Aug 30 18:15:03 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 30 Aug 2005 18:15:03 -0400 Subject: OpenSource documentation problems In-Reply-To: <200508301700.36140.hancock@anansispaceworks.com> References: <200508301700.36140.hancock@anansispaceworks.com> Message-ID: <4314DA67.6030101@benjiyork.com> Terry Hancock wrote: > OTOH, there are lots of poorly-documented third-party Python > modules (as in any language). Zope is a particularly nasty > example -- though I think I understand some of the reasons > behind that (rapidly changing API, poor interaction with doc > tools, etc). Are you referring to Zope 2 or 3 here? I ask because I consider the Zope 3 code (at least the parts written in the last couple years) to be some of the best (externally) documented code I've worked with. -- Benji York From __peter__ at web.de Mon Aug 8 03:28:03 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 08 Aug 2005 09:28:03 +0200 Subject: Python's CSV reader References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> <1123169310.391973.217860@o13g2000cwo.googlegroups.com> <1123467799.077938.60540@z14g2000cwz.googlegroups.com> Message-ID: Stephan wrote: > DictReader field names on the fly. Here is a rudimentary example of my > working code and the data it can parse. > > ------------------------------------- > John|Smith > Beef|Potatos|Dinner Roll|Ice Cream > Susan|Jones > Chicken|Peas|Biscuits|Cake > Roger|Miller > Pork|Salad|Muffin|Cookies > ------------------------------------- That sample data would have been valuable information in your original post. Here's what becomes of your code if you apply the "zip trick" from my first post (yes, I am sometimes stubborn): import itertools import csv HeaderFields = ["First Name", "Last Name"] DetailFields = ["Entree", "Side Dish", "Starch", "Desert"] instream = open("testdata.txt") heads = csv.DictReader(instream, HeaderFields, delimiter="|") details = csv.DictReader(instream, DetailFields, delimiter="|") for header, detail in itertools.izip(heads, details): print "Header (%d fields): %s" % (len(header), header) print "Detail (%d fields): %s" % (len(detail), detail) Peter From grante at visi.com Tue Aug 2 14:10:27 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 02 Aug 2005 18:10:27 -0000 Subject: py2exe windows apps path question References: <11ev0tcg9n2ndd@corp.supernews.com> Message-ID: <11evdoj8c4brd1b@corp.supernews.com> On 2005-08-02, vincent wehren wrote: > > "Grant Edwards" schrieb im Newsbeitrag > news:11ev0tcg9n2ndd at corp.supernews.com... >|I have several python apps (some wxPython, some plain text-mode >| stuff) that I distribute internally for installation on Win32 >| machines. They're bundled/installed using py2exe and inno >| setup. >| >| I followed what I think is the normal procedure of installing >| each app in its own directory under /Program >| Files//. >| >| The problem is that the apps only run if they're started with >| the install directory as the current working directory. >| Otherwise they can't find the .dll's they use from the install >| directory. > > AFAIK, Windows normally *does* search the directory where the executable > module for the current process lives in for dlls. What sort of dlls are > given you trouble? One's a "driver" for a CAN bus USB widget. The other failure that springs to mind is that gnuplot-py couldn't find something (could have been an .exe) that was in the app directory. -- Grant Edwards grante Yow! HUGH BEAUMONT died at in 1982!! visi.com From claudio.grondi at freenet.de Fri Aug 26 16:31:11 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Fri, 26 Aug 2005 20:31:11 -0000 Subject: Why does min(A,B) behave different for lists and for classes? Message-ID: <3n95grFfp1fU2@individual.net> Trying to understand the outcome of the recent thread (called later reference thread): "Speed quirk: redundant line gives six-fold speedup" I have put following piece of Python code together: class PythonObject_class: pass PythonObject_class_instanceA = PythonObject_class() PythonObject_class_instanceB = PythonObject_class() PythonObject_list_instanceA = [1] PythonObject_list_instanceB = [1] print "min(A,B) is A: " print "in case of classes as parameter: " + str(min(PythonObject_class_instanceA, PythonObject_class_instanceB) is PythonObject_class_instanceA) print "in case of lists as parameter: " + str(min(PythonObject_list_instanceA, PythonObject_list_instanceB) is PythonObject_list_instanceA) print "min(B,A) is A: " print "in case of classes as parameter: " + str(min(PythonObject_class_instanceB, PythonObject_class_instanceA) is PythonObject_class_instanceA) print "in case of lists as parameter: " + str(min(PythonObject_list_instanceB, PythonObject_list_instanceA) is PythonObject_list_instanceA) getting as output: min(A,B) is A: in case of classes as parameter: True in case of lists as parameter: True min(B,A) is A: in case of classes as parameter: True in case of lists as parameter: False Is there any deeper reason I don't understand explaining why does min(A,B) behave different for classes than for lists? It makes for me currently not much sense how it behaves for classes, because the result is according to the postings in the above mentioned reference thread nondeterministic. Claudio From stefan.rank at ofai.at Tue Aug 30 09:54:26 2005 From: stefan.rank at ofai.at (Stefan Rank) Date: Tue, 30 Aug 2005 15:54:26 +0200 Subject: regexps with unicode-aware characterclasses? Message-ID: <43146512.5000101@ofai.at> Hi all, in a python re pattern, how do I match all unicode uppercase characters (in a unicode string/in a utf-8 string)? I know that there is string.uppercase/.lowercase which are 'locale-aware', but I don't think there is a "all locales" locale. I know that there is a re.U switch that makes \w match all unicode word characters, but there are no subclasses of that ([[:upper:]] or preferably \u). Or is there a module/extension to get that? There is the module unicodedata, but it has no unicodedata.uppercase that would correspond to string.uppercase. re.compile('|'.join([x.encode('utf8') for x in unicode.uppercase])) or:: re.compile('(?u)[[:upper:]]') or:: re.compile('(?u)\u') for the latter two, to work on utf-8 strings, would I have to set the defaultencoding to utf-8? From greg at puyo.cjb.net Mon Aug 22 05:23:33 2005 From: greg at puyo.cjb.net (Greg McIntyre) Date: 22 Aug 2005 02:23:33 -0700 Subject: while c = f.read(1) In-Reply-To: <43057145.1837895163@news.oz.net> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <43057145.1837895163@news.oz.net> Message-ID: <1124702613.567210.239460@o13g2000cwo.googlegroups.com> Okay, the 1st option seems more complicated and the 2nd option, while simpler to my eye makes me worry about file descriptors, resource management and memory running out. My files are large, hence 1 character at a time, not f.read(). This is code from another employee and I'm just in the stages of going through it and doing a basic clean-up before I get on to a proper efficiency assessment, hence I don't want to change the way it works, just make it as short and lucid as I can. Your suggestion using the generator expression again seems more complex than the original. They're good suggestions though. Thank you! I'm just now catching up with everybody's comments. Some of them seem quite entriguing. From rkern at ucsd.edu Mon Aug 1 08:54:41 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 01 Aug 2005 05:54:41 -0700 Subject: Changing interpreter's deafult output/error streams In-Reply-To: References: Message-ID: Michael Hudson wrote: > "Ira" writes: > >>OK let me rephrase, >> >>the standard error stream (and if I'm not mistaken also the one that >>PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go >>ahead and write the following in python... > > Ah, OK, I think you're mistaken, and PyErr_Print prints to the C level > FILE* stderr (I agree my first post was confusing on this point, sorry > about that...). No, it doesn't. It grabs the appropriate object from sys.stderr. -- 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 jeffrey.schwab at rcn.com Thu Aug 11 09:23:55 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Thu, 11 Aug 2005 09:23:55 -0400 Subject: Regular expression to match a # In-Reply-To: <42fb45d7$1@news.eftel.com> References: <1123756502.593746.250640@g47g2000cwa.googlegroups.com> <42fb45d7$1@news.eftel.com> Message-ID: John Machin wrote: > Search for r'^something' can never be better/faster than match for > r'something', and with a dopey implementation of search [which Python's > re is NOT] it could be much worse. So please don't tell newbies to > search for r'^something'. How else would you match the beginning of a line in a multi-line string? From http Wed Aug 3 16:48:39 2005 From: http (Paul Rubin) Date: 03 Aug 2005 13:48:39 -0700 Subject: Secure email References: Message-ID: <7x8xzin3vc.fsf@ruckus.brouhaha.com> whisper at oz.net writes: > I need to write a .cgi that will take the content of an https GET or > POST and send it securely as email to an Outlook client. You're asking how to make S/MIME messages? This isn't really the right newsgroup. From kevin_little at comcast_net.com Tue Aug 30 22:28:51 2005 From: kevin_little at comcast_net.com (Kevin Little) Date: Tue, 30 Aug 2005 22:28:51 -0400 Subject: Adding bound methods dynamically... Message-ID: <4o4ah1h2r53gll81jinueaugpqi7rq7hsj@4ax.com> #!/usr/bin/env python ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or after the class was modified. I need this to work for both old ('classic') and new style classes, at both 2.3 and 2.4. I of course want to avoid side effects, and to make the solution as light-weight as possible. Question for the experts: Is the solution coded in AddBoundMethod() acceptable to the Pythonian Gods? :) It does seem to work -- tested at 2.3.5 (RH Linux) and 2.4.1 (WinXP) Is there a more pythonic way that's as straight forward? ''' def AddBoundMethod( cls, name, method ): ''' Dynamically add to the class 'cls' a bound method. Invoking this method instantly adds (or overwrites) the bound method identified by 'name' with the code contained in 'method', EVEN FOR PRE-EXISTING INSTANCES OF THE CLASS. The 'method' parameter should be a non-class function that has 'self' as its first parameter. ''' try: types except NameError: import types # # this is the crux of this example, short and sweet... # exec "%s.%s = types.MethodType( method, None, %s )" \ % ( cls.__name__, name, cls.__name__ ) # # The remainder (50x longer than the solution!) is test code... # # one new-style class... class NewStyleClass( object ): def __init__ ( self, objname ): print "Created a NewStyleClass, id %d, %s" % \ ( id( self ), objname ) self.objname = objname def ExistingMethod( self, msg ): print "Original ExistingMethod, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) # one 'classic' style class... class OldStyleClass: def __init__ ( self, objname ): print "Created a OldStyleClass, id %d, %s" % \ ( id( self ), objname ) self.objname = objname def ExistingMethod( self, msg ): print "Original ExistingMethod, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) # two non-class functions that *look* like bound methods in a class; # one returns a value, the other just outputs a string... def NeverInOriginalClass( self, msg ): return "Never in original class, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) def NewExistingMethod( self, msg ): print "REPLACED ExistingMethod, id %d, %s: '%s'" % \ ( id( self ), self.objname, msg ) # a test routine... def Test( cls ): print "--- %s ----------------------------------------------" % \ cls.__name__ print "type of class %s is '%s'" % ( cls.__name__, type( cls ) ) before_change = cls('instance created before change') print "type of object before_change is '%s'" % type(before_change) # 'A' shows that we start with an existing method.... before_change.ExistingMethod( 'A' ) print "*** Replacing bound method 'ExistingMethod'..." AddBoundMethod( cls, "ExistingMethod", NewExistingMethod ) after_change = cls( 'instance created AFTER change' ) print "type of after_change is '%s'" % type( after_change ) # 'B' and 'C' show we've replaced an existing method, both on # pre-existing instances and instances created after using # AddBoundMethod() before_change.ExistingMethod( 'B' ) after_change.ExistingMethod( 'C' ) print "*** Adding new bound method 'AddedMethod'..." AddBoundMethod( after_change.__class__, "AddedMethod", NeverInOriginalClass ) # 'D' and 'E' show we've added a brand new method, both on # pre-existing instances and instances created after using # AddBoundMethod() print "%s" % before_change.AddedMethod( 'D' ) print "%s" % after_change.AddedMethod( 'E' ) if __name__ == '__main__': Test( OldStyleClass ) Test( NewStyleClass ) From pink at odahoda.de Tue Aug 16 18:25:38 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 17 Aug 2005 00:25:38 +0200 Subject: stopping a python windows service References: <1124230320.593335.288650@g44g2000cwa.googlegroups.com> Message-ID: DK wrote: > i was able to successfully create a windows service using py2exe. it > polls a website periodically and logs it to a file. this is done using > a function that does an infinite loop with periodic "sleeps". > > my question is... > > what's the best way to stop this service gracefully? > > when try to stop it from the services applet from control panel, it > takes forever and then gives me an error. > > currently, the only way i am able to stop it is using the task manager > and killing the process. Windows services generally use two threads: one to do the work and one to listen for messages from the whatever-the-component-is-called-to-control-services. When the message thread received a 'stop' message, it should inform the worker thread to shut down, e.g. using threading.Event. So your worker should regularily check for the shutdown event, e.g.: while not shutdownEvent.isset(): pollWebsite() for i in xrange(1800): if shutdownEvent.isset(): break time.sleep(1) But if you get the 'stop' message while the worker thread is in pollWebsite() and the webserver is sloooow, you'll still have a significant delay... To avoid this, you would need a http client based on select() that allows you to check shutdownEvent.isset() at certain intervals - instead of urlopen which just blocks. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From nothingcanfulfill at gmail.com Thu Aug 18 19:49:24 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 18 Aug 2005 16:49:24 -0700 Subject: Traceback Questions Message-ID: <1124408964.797947.214270@f14g2000cwb.googlegroups.com> I'm just beginning with tracebacks, building off of what I see in asyncore's compact_traceback code, in order to hopefully store all the values from the location in which the exception occured. I'm actually trying to make this into a python bug report system for my current project, and am seeking advice on how to use sys.exc_info()[2] better (the traceback element) Does anyone have any advice on how I'd preform a traceback-based bugreport-like system? The more I work on this, the more I'm confusing myself. :\ -Wes This is the code from which I'm slowly figuring out the traceback stuff: import sys,pprint a,b = 1,0 def mth(a,b): moo = a/b try: mth(a,b) except: pass tb = sys.exc_info()[2] assert tb def sprint(o): pprint.pprint(dict([(x, getattr(o, x)) for x in dir(o) if x[:2]!='__']), indent=2) sprint(tb) sprint(tb.tb_frame) sprint(tb.tb_frame.f_code) From spammers-go-here at spam.invalid Wed Aug 17 13:56:28 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 17 Aug 2005 13:56:28 -0400 Subject: Testing for presence of arguments References: <430353e1$0$18641$14726298@news.sunsite.dk> <1124293800.587084.302130@g43g2000cwa.googlegroups.com> <43036087$0$18639$14726298@news.sunsite.dk> <1124301070.837156.71040@g14g2000cwa.googlegroups.com> Message-ID: <43037a2e$0$18637$14726298@news.sunsite.dk> Diez B. Roggisch wrote: > I still don't see why default arguments like None won't do the trick. > If The argument _can_ > be some value (let's say an int) or None, you still could go for a > default value like () or any other value > from a different domain. "None" works perfectly. Someone else on the thread suggested it. I did not know about the special intrinsic. >> Unrelated question, how does one call a fortran 95 subroutine from python >> ? I need really high speed of execution for that call (needed for each >> measurement point, and is used to calculate some parameters for the >> excitation for the next measurement point) and a scripting language would >> not cut it. > > Didn't ever try that, but either do it in C, or if fortran code can be > exposed as C lib, use that (ctypes is your friend). I'm not aware of a > fortran binding - but I never tried to find one. Basically Python can > interface with everything that can behave like C - which is the least > common denominator I think, so there should be some way. Hmm. Thanks for the pointers here. From kay.schluehr at gmx.net Tue Aug 9 00:45:46 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Aug 2005 21:45:46 -0700 Subject: python for microcontrollers References: <42f7c8d4$1@news.orcon.net.nz> Message-ID: <1123562745.993465.106610@g43g2000cwa.googlegroups.com> Hi Bastard, one of the main reasons PyPy gets funded by the EU was the promise to port Python to embedded systems ( but not necessarily very memory restricted ones ). The project seems to be in a state where the team tries to get rid of the CPython runtime alltogether and reaching some autonomy. The idea of providing a Forth backend would fit into the concept and would be great IMO. Maybe You should also have a look on the JavaCard platform specification for inspiration what is possible for an OO language on time and memory resticted platforms. http://java.sun.com/products/javacard/specs.html Since there are vendors that implemented the JVM on smartcards against SUNs spec and JavaCards are on the market ( not just research prototypes ) the approach has been proven successfull. For the matter of memory layout I would naively try to adapt the type inferencer ( annotator in PyPy slang ) and restrict Python to an even more smaller subset than RPython ( SmartJava does not even support strings. On the other hand the explicit casting to short and byte types is by no means braindead ). I currently don't have an idea for memory management and I'm not even sure about implicit or explicit finalization. Kay From martin at v.loewis.de Sun Aug 21 16:31:37 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 21 Aug 2005 22:31:37 +0200 Subject: Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out) In-Reply-To: References: <43082c5f$0$31577$9b622d9e@news.freenet.de> <8xWNe.24050$HM1.696102@twister1.libero.it> <430890f5$0$16648$9b622d9e@news.freenet.de> Message-ID: <4308e4a9$0$16592$9b622d9e@news.freenet.de> Giovanni Bajo wrote: > You seem to ignore the fact that scons can easily generate VS.NET projects. I'm not ignoring it - I'm not aware of it. And also, I don't quite believe it until I see it. > But there is no technical reason why it has to be so. I work on several > portable projects, and they use the same build process under both Windows and > Unix, while retaining full Visual Studio integration (I myself am a Visual > Studio user). Well, as long "F6" works... > Well, you came up with a maintenance problem: you told me that building more > external modules needs more effort. In a well-configured and fully-automated > build system, when you add a file you have to write its name only one time in a > project description file; if you want to build a dynamic library, you have to > add a single line. This would take care of both Windows and UNIX, both > compilation, packaging and installation. I very much doubt this is possible. For some modules, you also need to create autoconf fragments on Unix, for example, and you need might need to specify different libraries on different systems. Regards, Martin From haircut at gmail.com Wed Aug 31 23:39:44 2005 From: haircut at gmail.com (Adam Monsen) Date: 31 Aug 2005 20:39:44 -0700 Subject: time.strptime() for different languages In-Reply-To: <1125536884.953514.226790@o13g2000cwo.googlegroups.com> References: <1125519061.261802.285840@o13g2000cwo.googlegroups.com> <1125522144.209140.266590@f14g2000cwb.googlegroups.com> <1125536884.953514.226790@o13g2000cwo.googlegroups.com> Message-ID: <1125545984.087611.16570@g49g2000cwa.googlegroups.com> Figured this out. I thought I'd post my results in case it is helpful to someone else. ----------------------------------8<---------------------------------- import locale, time # save old locale old_loc = locale.getlocale(locale.LC_TIME) locale.setlocale(locale.LC_TIME, 'nl_NL') # seems to be the only way to avoid a ValueError from _strptime... # now that's a badly behaved module! import _strptime; reload(_strptime) # parse local date date = '10 augustus 2005 om 17:26' format = '%d %B %Y om %H:%M' dateTuple = time.strptime(date, format) # switch back to previous locale locale.setlocale(locale.LC_TIME, old_loc) ---------------------------------->8---------------------------------- If I try to do further date parsing in the same scope (with a different locale), it fails. Let me know if you have any ideas about why. -- Adam Monsen http://adammonsen.com/ From mwm at mired.org Fri Aug 19 23:10:43 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 19 Aug 2005 23:10:43 -0400 Subject: Save Binary data. References: <4305F38E.7020905@syscononline.com> Message-ID: <86br3tb8wc.fsf@bhuda.mired.org> Larry Bates writes: > Directories with large numbers of files was a problem in FAT16 and > FAT32 filesystems but not really a problem in NTFS or Linux (at > least that I've found). Depends on how you define "large" and what Linux file system you're using. Of course, if you open the directory in a GUI directory browser, you're probably going to be unhappy no matter what the underlying file system. The standard Unix solution to this is to break the files out into subdirectories. Create a subdirectory with the name being the first few letters of the file name, and then store the file in that subdirectory. Easy to do programmatically, it's still easy to find files "by hand", and you can make it as fine-grained as you want. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From timr at probo.com Mon Aug 1 01:42:58 2005 From: timr at probo.com (Tim Roberts) Date: Sun, 31 Jul 2005 22:42:58 -0700 Subject: rfc822 module bug? References: <20050730085418.2139.16534.XPN@orion.homeinvalid> Message-ID: <5ddre11dhqb6s8db3ne8ilop2ubrg7cs46@4ax.com> Nemesis wrote: > >Hi all, >I found that the function parsedate_tz of the rfc822 module has a bug >(or at least I think so). >I found a usenet article (message-id: <2714d.q75200 at myg.winews.net>) >that has this Date field: > >Date: Tue,26 Jul 2005 13:14:27 GMT +0200 > >It seems to be correct?, but parsedate_tz is not able to decode it, it >is confused by the absence of a space after the ",". Fascinating. I've written a lot of e-mail programs, and I would have bet real money that this was not legal by either RFC822 or 2822, but the BNF certainly supports your assertion that this is valid. RFC1036, which gives the format for Usenet articles, includes the space in its "suggested" date format. >? and looking at rfc822 par3.3 it should be correct: > >date-time = [ day-of-week "," ] date FWS time [CFWS] > >day-of-week = ([FWS] day-name) / obs-day-of-week > >day-name = "Mon" / "Tue" / "Wed" / "Thu" / > "Fri" / "Sat" / "Sun" > >date = day month year This is actually from RFC2822, but the point is the same. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From onurb at xiludom.gro Wed Aug 10 12:06:28 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 10 Aug 2005 18:06:28 +0200 Subject: Python supports LSP, does it? In-Reply-To: References: <86wtmuk0c5.fsf@bhuda.mired.org> Message-ID: <42fa2606$0$23692$636a15ce@news.free.fr> Roy Smith wrote: > Andy Leszczynski writes: > (snip) >>It's not a true statement. Nothing in the language enforces LSP. In >>fact, there's not even a [way?] when a function/method is invoked to make >>sure the type passed in is a subtype of the type you expect > > > Well, that's not entirely true. I could write: > > def func (self, obj): > assert (isinstance (obj, baseClass)) > > It's sort of un-pythonic, but the language certainly lets you do it if you > really want to. It doesn't inforce LSP anyway. class baseClass(object): def f(self): print "in %s f" % self return 42 class derivedClass(baseClass): f = "gotcha" class somethingElse(object) def f(self): return 42 def func1(obj): assert isinstance (obj, baseClass) obj.f() def func2(obj): assert(callable(getAttr(obj, f)) obj.f() b = baseClass() d = derivedClass() s = somethingElse() func1(b) # ok func1(d) # TypeError func1(s) # AssertionError func2(b) # ok func2(d) # AssertionError func2(s) # ok Clearly, somethingElse is a subtype of baseClass, when derivedClass is not. Don't confuse suclassing with subtyping. issinstance() let you check for subclassing, not for subtyping. The only language-level mechanism I know of that more or less inforce LSP is Eiffel's contracts. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From jennifer_wild38 at yahoo.com Thu Aug 11 00:43:44 2005 From: jennifer_wild38 at yahoo.com (Jennifer) Date: Thu, 11 Aug 2005 04:43:44 -0000 Subject: wanna stop by my homemade glory hole? Message-ID: my husband is installing an extra bathroom poolside. there is a perfect size hole (unless you have a huge cock) to stick your dick through into the adjoing room. come around the side of my house(perfect if you look like a repair man) enter into the unfisnished bathroom and I'll service you from the other side. you can leave when your done, no talking or small talk. i want to do this before the hole gets patched up. its been a huge fantasy of mine ever since I've seen a glory hole online. you can email me for a time convienient for you. im home all-day most days so my schedule is open. do you prefer a certain color of lipstick? check out my pic and email here under kallegirl26 www.no-strings-fun.net/kallegirl26 ready and waiting, me ;o) From rkern at ucsd.edu Thu Aug 4 00:17:01 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 03 Aug 2005 21:17:01 -0700 Subject: quetion about "+=" and "runtime" In-Reply-To: <1123128049.701735.249620@g49g2000cwa.googlegroups.com> References: <1123123359.768132.112990@g47g2000cwa.googlegroups.com> <1123128049.701735.249620@g49g2000cwa.googlegroups.com> Message-ID: gagaguy at gmail.com wrote: > 1.i have look " += " up,but i can't find it. http://docs.python.org/ref/augassign.html > is it ofthen used? Reasonably so. > 2.i saq a result like this in a web page: > > > $ time python permute2.py 56789 3 > Got 120 items. > Maximum at 87596 ,product 84000 > > real 0m0.057s > user 0m0.050s > sys 0m0.000s > > $ time python permute3.py 56789 3 > Got 120 items. > Maximum at 87596 ,product 84000 > > real 0m0.040s > user 0m0.030s > sys 0m0.010s > > i wanna know how to call out this As Terry said, look at the "time" module. Don't use the "time" program (a standard program on UNIX-like systems) unless you actually want to time the startup of the interpreter too rather than just the code itself. -- 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 johnjsal at NOSPAMgmail.com Thu Aug 18 16:10:48 2005 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Thu, 18 Aug 2005 20:10:48 GMT Subject: up to date books? In-Reply-To: <1124393604.278061.24100@g49g2000cwa.googlegroups.com> References: <1124393604.278061.24100@g49g2000cwa.googlegroups.com> Message-ID: Thanks. I understand that my question probably causes a lot of grief for some people. :) gene tani wrote: > well, it's not easy to find neutral comparisons of ruby and python, but > > > http://www.ruby-doc.org/RubyEyeForThePythonGuy.html > http://onestepback.org/index.cgi/Tech/Ruby/PythonAndRuby.rdoc > http://www.approximity.com/ruby/Comparison_rb_st_m_java.html > http://reflectivesurface.com/weblog/2004/12/19/why-rails > http://martinfowler.com/bliki/CollectionClosureMethod.html > > Also, Hal Fulton's "Ruby Way" book has a good "Python vs. ruby syntax" > appendix, if it's still in print > From robin at reportlab.com Mon Aug 15 10:25:35 2005 From: robin at reportlab.com (Robin Becker) Date: Mon, 15 Aug 2005 15:25:35 +0100 Subject: SOAP and XMLRPC In-Reply-To: <1124115078.926129.285880@f14g2000cwb.googlegroups.com> References: <1124112293.426299.9140@g47g2000cwa.googlegroups.com> <1124115078.926129.285880@f14g2000cwb.googlegroups.com> Message-ID: <4300A5DF.4080903@chamonix.reportlab.co.uk> dcrespo wrote: > Hi... Thanks for your answer, but can you give me his contact or tell > him to post here the answer I'm looking for? I'm needing it seriously. > Well I'm not a VB person so perhaps you need to ask on a VB list. Unfortunately the student has vanished into the real world. -- Robin Becker From aahz at pythoncraft.com Fri Aug 19 17:52:07 2005 From: aahz at pythoncraft.com (Aahz) Date: 19 Aug 2005 14:52:07 -0700 Subject: Python jobs (was Re: Python for Webscripting (like PHP)) References: Message-ID: In article , Erik Max Francis wrote: >Peter Decker wrote: >> >> Then start looking for telecommuting people. There are lots of us who >> can use work and have excellent telecommuting references, but who >> don't happen to live in a major metro area! > >And then there's some in the Bay Area who wouldn't mind telecommuting, >either ... :-) We do a *lot* of telecommuting. I'm working from home today, for example, because I needed to deal with the plumber. And we have two people in Seattle out of seven fulltime people. However, it's our experience that people are more productive when they show up at the office regularly -- the two Seattle people had lots of experience with our product before they worked independently, and the two of them do share an office. (They work across the street from Elliott Bay Books, the bastards.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The way to build large Python applications is to componentize and loosely-couple the hell out of everything. From fakeaddress at nowhere.org Wed Aug 24 09:42:11 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 24 Aug 2005 13:42:11 GMT Subject: Proposed PEP: New style indexing, was Re: Bug in slice type In-Reply-To: <1124612990.362407.87670@g43g2000cwa.googlegroups.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <1124612990.362407.87670@g43g2000cwa.googlegroups.com> Message-ID: Kay Schluehr wrote: > Bryan Olson wrote: > >>Steven Bethard wrote: >> > Well, I couldn't find where the general semantics of a negative stride >> > index are defined, but for sequences at least[1]: >> > >> > "The slice of s from i to j with step k is defined as the sequence of >> > items with index x = i + n*k such that 0 <= n < (j-i)/k." >> > >> > This seems to contradict list behavior though. [...] >> >>The conclusion is inescapable: Python's handling of negative >>subscripts is a wart. Indexing from the high end is too useful >>to give up, but it should be specified by the slicing/indexing >>operation, not by the value of the index expression. > > > It is a Python gotcha, but the identity X[-1] == X[len(X)-1] holds and > is very usefull IMO. No question index-from-the-far-end is useful, but I think special-casing some otherwise-out-of-bounds indexes is a mistake. Are there any cases in popular Python code where my proposal would not allow as elegant a solution? > If you want to slice to the bottom, take 0 as > bottom value. The docs have to be extended in this respect. I'm not sure what you mean. Slicing with a negative step and a stop value of zero will not reach the bottom (unless the sequence is empty). In general, Python uses inclusive beginning bounds and exclusive ending bounds. (The rule is frequently stated incorrectly as "inclusive lower bounds and exclusive upper bounds," which fails to consider negative increments.) -- --Bryan From rex.eastbourne at gmail.com Tue Aug 30 18:07:53 2005 From: rex.eastbourne at gmail.com (Rex Eastbourne) Date: 30 Aug 2005 15:07:53 -0700 Subject: Bicycle Repair Man usability Message-ID: <1125439673.688666.264820@z14g2000cwz.googlegroups.com> Are there any Bicycle Repair Man users here? I recently got PyDev for Eclipse, which comes with BRM. I am disappointed with what I've seen, although I'm not sure if I'm using its full functionality. According to PyDev's documentation, this is what one can do: -Rename a function/variable -Block of code --> method and a method call -Get rid of extra variables by shifting them inline (e.g.: a=1;b=2;c=a+b --> c=1+2) I'm not aware of anything else that can be done, as BRM's documentation is extremely thin. Is anyone else aware of other uses? It's a shame this project is not active; it seems like such a great idea. Rex From matt.hammond at rd.bbc.co.uk Thu Aug 11 04:18:11 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Thu, 11 Aug 2005 09:18:11 +0100 Subject: performance of recursive generator References: Message-ID: > Is it an inherent issue in the use of recursive generator? Is there any > compiler optimization possible? Hi, I could be misunderstanding it myself, but I think the short answer to your question is that its an inherent limitation. > def inorder(t): > if t: > for x in inorder(t.left): > yield x > yield t.label > for x in inorder(t.right): > yield x Using the generator you pass the tree node labels back up through each nested generator - therefore the deeper you are, obviously, the more yields it will take to pass the data back up. As you seem to have realised, you are, in effect traversing back up the tree from every node you visit, in order to deliver the data. > def inorder(t, foo): > if t: > inorder(t.left, foo): > foo(t.label) > inorder(t.right, foo): Inherently, by using callbacks you are shortcutting this - delivering direct. (I assume foo is a list you're building or something similar) Of course there might be some cunning alternative formulation, but I can't think of it :-) To optimise this away, I guess python would need to see this: > for x in inorder(t.left): > yield x And understand that you're just asking it to pass on all yields from a nested generator as if they were coming from this generator. Perhaps if there existed some kind of syntax to hint this to python it could optimise it away, eg: yield *inorder(t.left) ... but AFAIK there isn't :-( so I guess you'll have to avoid recursive generators for this app! Matt -- | Matt Hammond | R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK. From bokr at oz.net Fri Aug 19 17:42:47 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 19 Aug 2005 21:42:47 GMT Subject: How to get a unique id for bound methods? References: Message-ID: <430649fe.1893376731@news.oz.net> On Fri, 19 Aug 2005 13:29:19 -0700, "Russell E. Owen" wrote: >I have several situations in my code where I want a unique identifier >for a method of some object (I think this is called a bound method). I >want this id to be both unique to that method and also stable (so I can >regenerate it later if necessary). > >I thought the id function was the obvious choice, but it doesn't seem to >work. The id of two different methods of the same object seems to be the >same, and it may not be stable either. For instance: > The id function works, but you are applying it to transient objects, which is what bound methods are unless you cause them to persist one way or another. >class cls(object): > def __init__(self): > print id(self.meth1) > print id(self.meth2) > def meth1(self): > pass > def meth2(self): > pass > >c = cls() >3741536 >3741536 This means that self.meth1 only existed long enough to be passed to id, and when id was done with determining its id, self.meth1 was freed. Then self.meth2 was created, and happened to use a representation space with the same id as was used for self.meth1. If the two objects (bound methods here) existed at the same time, they would be guaranteed not to have the same id unless they were actually the same object. >print id(c.meth1) >3616240 >print id(c.meth2) >3616240 This happened to re-use a representation space with another id. > >I guess that just means bound methods aren't objects in their own right, >but it surprised me. No, they are objects in their own right. You were surprised by your [mis]interpretation of the above results ;-) > >The "hash" function looks promising -- it prints out consistent values >if I use it instead of "id" in the code above. Is it stable and unique? >The documentation talks about "objects" again, which given the behavior >of id makes me pretty nervous. > >Any advice would be much appreciated. > If you want a particular bound method to have a stable and persistent id, make it persist, e.g., >>> class cls(object): ... def __init__(self): ... print id(self.meth1) ... print id(self.meth2) ... def meth1(self): ... pass ... def meth2(self): ... pass ... >>> c = cls() 49219060 49219060 >>> print id(c.meth1) 49219020 >>> print id(c.meth2) 49219020 Ok, those were transient, now nail a couple of bound methods down: >>> cm1 = c.meth1 >>> cm2 = c.meth2 And you can look at their id's all you like: >>> print id(cm1) 49219020 >>> print id(cm2) 49219060 >>> print id(cm1) 49219020 >>> print id(cm2) 49219060 But every time you just evaluate the attribute expression c.meth1 or c.meth2 you will get a new transient bound method object, with a new id: >>> print id(c.meth1) 49219180 >>> print id(c.meth2) 49219180 But the ones we forced to persist by binding the expression values to cm1 and cm2 above still have the same ids as before: >>> print id(cm1) 49219020 >>> print id(cm2) 49219060 So the question would be, why do you (think you ;-) need ids for these bound methods as such? I.e., what is the "situation" in your code? Regards, Bengt Richter From apardon at forel.vub.ac.be Wed Aug 31 04:01:16 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Aug 2005 08:01:16 GMT Subject: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type References: <1124160882.554543.75730@g43g2000cwa.googlegroups.com> <3ErPe.853$sV7.65@newssvr21.news.prodigy.com> <7sJPe.573$MN5.131@newssvr25.news.prodigy.net> <7xy86k3r7n.fsf@ruckus.brouhaha.com> <4314b190.174021119@news.oz.net> <43156165.219034725@news.oz.net> Message-ID: Op 2005-08-31, Bengt Richter schreef : > On 31 Aug 2005 07:26:48 GMT, Antoon Pardon wrote: > >>Op 2005-08-30, Bengt Richter schreef : >>> On 30 Aug 2005 10:07:06 GMT, Antoon Pardon wrote: >>> >>>>Op 2005-08-30, Terry Reedy schreef : >>>>> >>>>> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message >>>>> news:7xy86k3r7n.fsf at ruckus.brouhaha.com... >>>>> >>>>>> Really it's x[-1]'s behavior that should go, not find/rfind. >>>>> >>>>> I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely >>>>> useful, especially when 'x' is an expression instead of a name. >>>> >>>>I don't think the ability to easily index sequences from the right is >>>>in dispute. Just the fact that negative numbers on their own provide >>>>this functionality. >>>> >>>>Because I sometimes find it usefull to have a sequence start and >>>>end at arbitrary indexes, I have written a table class. So I >>>>can have a table that is indexed from e.g. -4 to +6. So how am >>>>I supposed to easily get at that last value? >>> Give it a handy property? E.g., >>> >>> table.as_python_list[-1] >> >>Your missing the point, I probably didn't make it clear. >> >>It is not about the possibilty of doing such a thing. It is >>about python providing a frame for such things that work >>in general without the need of extra properties in 'special' >>cases. >> > How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ? > That would give a consitent interpretation of seq[-1] and no errors > for any value ;-) But the question was not about having a consistent interpretation for -1, but about an easy way to get the last value. But I like your idea. I just think there should be two differnt ways to index. maybe use braces in one case. seq{i} would be pure indexing, that throws exceptions if you are out of bound seq[i] would then be seq{i%len(seq)} -- Antoon Pardon From caseyhHAMMER_TIME at istar.ca Mon Aug 22 23:28:48 2005 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Tue, 23 Aug 2005 03:28:48 GMT Subject: up to date books? References: <1124761170.650704.181020@o13g2000cwo.googlegroups.com> Message-ID: Would you consider releasing an ebook in the mean time? aleaxit at gmail.com wrote: >Glad to hear that my efforts to cover some of 2.3's release features in >a mostly-2.2 book were appreciated. I'm probably going to do the same >thing for the 2nd edition of the Nutshell: wait until 2.5 alpha's out >so I can mention _its_ feechurz in a mostly-2.4 book... meaning the 2nd >ed of the Nutshell may be almost a year away... > > >Alex -- Regards, Casey From usenet at isbd.co.uk Fri Aug 26 07:25:24 2005 From: usenet at isbd.co.uk (usenet at isbd.co.uk) Date: 26 Aug 2005 11:25:24 GMT Subject: Usenet, HTML (was Re: Jargons of Info Tech industry) References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124990564.528106.205070@g44g2000cwa.googlegroups.com> <3n6kkjF4qppU1@individual.net> <3n6l5jF4t1cU1@individual.net> <3n8366F9vvsU1@individual.net> Message-ID: <3n8ch4Fb539U1@individual.net> In comp.lang.perl.misc John Bokma wrote: > > > > I'm talking about using the technology for communication, instead of > > reinventing the wheel with crappy web forums. > > What is exactly crappy about those forums? > They are slow They are inflexible They are slow They don't allow the user to choose how to view them, the interface is imposed on the user. They are slow They don't have killfiles or scoring They are slow -- Chris Green From mwm at mired.org Fri Aug 12 21:03:21 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 12 Aug 2005 21:03:21 -0400 Subject: Why is this? References: <42fc8eb4$0$38045$bed64819@news.gradwell.net> Message-ID: <86vf2a642u.fsf@bhuda.mired.org> Peter Mott writes: > If I use concatenation + instead of multiplication * then I get the > result that Jiri expected: > > >>> L = [[]] + [[]] > >>> L[1].append(1) > >>> L > [[], [1]] > > With * both elements are changed: > > >>> L = [[]] * 2 > >>> L[1].append(1) > >>> L > [[1], [1]] > > Alex Martelli says in his excellent Nutshell book that + is > concatenation and that "n*S is the concatenation of n copies of > S". But it seems not so. Surely, from a logical point of view, S + S > should be the same as S * 2? Only if you think lists are numbers. They aren't. The only real resemblance between the operators on lists and numbers is that the symbols got overloaded for both types. The operators on lists aren't commutative, aren't associative, and don't have inverses. Given that, the surprising thing is that S + S is the same as S * 2 as often as it is. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From peter at engcorp.com Wed Aug 3 14:43:15 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 03 Aug 2005 14:43:15 -0400 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> <42efe1ec$0$3713$626a14ce@news.free.fr> <42efe330$0$3713$626a14ce@news.free.fr> Message-ID: Christoph Zwerschke wrote: >>> - unittest is for *unit* testing (only) ;-) >> >> Why would you say that? We've used it extensively for a wide ranging... > > That was actually only a quote from this thread that summarizes some of > the answers I got: unittest has no support for "global" fixtures, > because it is intended for unit testing, not for global tests. Fair enough, as a quote, but it's still an inaccurate statement as I hoped I've made clear in the last several posts. The need to do "global" fixtures is most definitely not inherent in acceptance-type testing, so it's incorrect to say "unittest" is limited to unit testing. >> What, and break all the code that currently does "import unittest"? > > Just insert the two words "punit as" between "import" and "unittest", > and the code will run as before... No thanks. I have hundreds upon hundreds of test files and no desire to change them. Luckily there's roughly a zero chance of this actually happening, so no problem. :-) -Peter From bokr at oz.net Sat Aug 20 18:48:25 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 20 Aug 2005 22:48:25 GMT Subject: Well, another try Re: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124518424.490288.105620@o13g2000cwo.googlegroups.com> Message-ID: <4307a696.1982616211@news.oz.net> On 19 Aug 2005 23:13:44 -0700, "James" wrote: >> for data in iter(lambda:f.read(1024), ''): >> for c in data: > >What are the meanings of Commands 'iter' and 'lambda', respectively? I >do not want you to indicate merely the related help pages. Just your >ituitive and short explanations would be enough since I'm really newbie >to Python. > Would you please read the above, as if you were someone else? The above sounds to me like you think you're typing commands to an enhanced google, or worse, to an abused employee or servant. To say "I do not want you to ..." sounds so arrogantly presumptious that I'm sure if that "works" for you IRL, you must be living in a very pampered and sheltered environment. The downside of such environments is that if simple demanding "works" and you get things and services from people as if they were robots, you lose out on the thing that draws most of us, I think, to c.l.p and similar social spaces -- which is a feeling of shared consciousness and contact with other humans within a sphere common interests. You're welcome to try again ;-) (BTW, sorry if "James" doesn't mean English is your mother tongue, and I have misinterpreted your manner of expression. If so, this may still be a useful indication to you of how wording can determine response ;-) Regards, Bengt Richter From http Wed Aug 24 17:46:18 2005 From: http (Paul Rubin) Date: 24 Aug 2005 14:46:18 -0700 Subject: The ONLY thing that prevents me from using Python References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <8764tw8def.fsf@bigfoot.com> Message-ID: <7xvf1vgg9h.fsf@ruckus.brouhaha.com> Richie Hindle writes: > I can't speak for linode.org, but I have a Xen VPS from rimuhosting.com > and it's early days but so far I've been very impressed. It's $19/mo > (normally $20 but they kindly gave me a 5% Open Source Developer discount) Do you get enough resources in that minimal-cost configuration to run significant Python applications? From harlinseritt at yahoo.com Tue Aug 23 19:15:29 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: 23 Aug 2005 16:15:29 -0700 Subject: Machine Name Message-ID: <1124838929.732444.175410@g47g2000cwa.googlegroups.com> How does one get the machine name with Python that the actual script is running on? Obviously, one could parse the hosts file but I was wondering if there was a quick way to get it done? thanks, Harlin Seritt From kevino at tulane.edu Sat Aug 27 23:34:05 2005 From: kevino at tulane.edu (Kevin Ollivier) Date: Sat, 27 Aug 2005 20:34:05 -0700 Subject: Windows/win32all, unicode and long filenames Message-ID: Hi all, On Windows, it's very common to have a string of long directories in the pathname for files, like "C:\Documents and Settings\My Long User Name\My Documents\My Long Subdirectory Name\...". For a wxPython application I'm working on, this has actually caused me to run into what appears to be Python's pathname length limit for opening files. (247 chars on Win) Yes, I can hear people saying "yipes!" but this stuff does happen sometimes on Windows. :-) My first inclination was to use win32api.GetShortPathName(mypath), which worked fine until I had an unicode pathname with non-ascii characters in it. Those give me the 'oridnal not in range' errors performing an ascii encode, meaning that GetShortPathName doesn't handle unicode objects. The problem is that I'm working with Unicode filenames that contain characters that are not only non-ascii characters, but characters not in the current locale's character set as well. So I can't just 'down convert' from a unicode object to a string object in the current character set without corrupting the filename. Looking at the pyWin32 sources, it does look like only the ASCII version of this function exists, which suggests that for now this route is a dead-end. The only other solution I could think of is to call os.chdir(long_pathname) and open the file using a filename relative to long_pathname instead of an absolute path. But I was wondering if there was another solution, preferably one that doesn't require me to muck with the current directory, and I was also wondering if there was a simple way to get one or both of the above limitations removed. :-) Thanks in advance for any help, Kevin From tjreedy at udel.edu Thu Aug 4 01:53:15 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 4 Aug 2005 01:53:15 -0400 Subject: Art of Unit Testing References: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> <7xpssu8hzw.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xpssu8hzw.fsf at ruckus.brouhaha.com... > I knew there was some other one before unittest came along but I thought > unittest was supposed to replace the older stuff. I believe unittest was an alternative rather than replacement for doctest. > What's the preferred one, Pythonically speaking? py.test was written, apparently, by pypy folks to replace unittest for pypy testing. To me, it is more Pythonic in spirit, and I plan to try it for an upcoming TDD project. Terry J. Reedy From jbperez808 at yahoo.com Mon Aug 15 03:27:55 2005 From: jbperez808 at yahoo.com (jbperez808 at yahoo.com) Date: 15 Aug 2005 00:27:55 -0700 Subject: Wheel-reinvention with Python In-Reply-To: <87mzo4zsu4.fsf@wilson.rwth-aachen.de> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> Message-ID: <1124090875.292874.199610@o13g2000cwo.googlegroups.com> Torsten Bronger wrote: > I've been having a closer look at wxPython which is not Pythonic at > all and bad documented. Probably I'll use it nevertheless. Aye. Couldn't agree more. > PyGTK and PyQt may have their own advantages and disadvantages. I like PyGTK because the calls are C-based and not as confusing as C++-based ones. It looks pretty good too... just a bit slow, but that was about a year ago. Speed may have improved since. > However, in my opinion we don't need yet another binding so thin > that C or C++ is shining through, but a modern replacement for > Tkinter with its Pythonic way of thinking. You will want to take a look at Fredrik Lundh's Tkinter 3000 and Widget Construction Kit: http://www.effbot.org/downloads/ http://www.effbot.org/zone/wck.htm I believe it deserves to be much more well-known that it currently is. From albalmer at att.net Tue Aug 30 13:53:36 2005 From: albalmer at att.net (Alan Balmer) Date: Tue, 30 Aug 2005 10:53:36 -0700 Subject: Jargons of Info Tech industry References: <861x4fuqzg.fsf@bhuda.mired.org> <95e6h1p80g0jprm1d2rusrk5qktffp3mf1@4ax.com> <9at6h1p5k60qp6ikvfvrskfmmuubafok64@4ax.com> <4t47h15at19osfqbic87v4p39hp6jtn2nc@4ax.com> Message-ID: On Tue, 30 Aug 2005 11:30:19 GMT, axel at white-eagle.invalid.uk wrote: >In comp.lang.perl.misc John Bokma wrote: >> Alan Balmer wrote: > >>> On 29 Aug 2005 21:12:13 GMT, John Bokma wrote: > >>>>> Now, go away. And please, stay away. > >>>>Like I already said, it doesn't work that way. > >>> Goodbye, John. Filters set. > >> Saidly you didn't get the message. Moreover you think that the Usenet >> /needs/ a public ploink message. Get a clue. People like you add more noise >> to Usenet compared to a thread which runs a bit wide. > >Why do I think of a Dutch expression 'mieren neuker' with regards to >Balmer's posts? > Another obnoxious cross-poster identified. Thank you. -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From steve at holdenweb.com Tue Aug 23 20:03:10 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 23 Aug 2005 20:03:10 -0400 Subject: Sorta noob question - file vs. open? In-Reply-To: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> References: <6a8ng1pjusft9cegb1cb1pvs9gfdknav16@4ax.com> Message-ID: Peter A.Schott wrote: > Been reading the docs saying that file should replace open in our code, but this > doesn't seem to work: > > # Open file for writing, write something, close file > MyFile = file("MyFile.txt", "w") > MyFile.write("This is a test.") > MyFile.close() > > However, using: > MyFile = open("MyFile.txt", "w") > MyFile.write("This is a test.") > MyFile.close() > > I have no problems. > > I'm sure that I'm missing something here about using open vs file, but am not > sure what. Probably just mis-read something. If anyone can point me to what I > didn't quite get, I'd appreciate the information. > > Thanks. > > -Pete I can only assume you are using an older version of Python: $ python Python 2.4.1 (#1, May 27 2005, 18:02:40) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> open is file True >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sklass at pointcircle.com Thu Aug 25 14:48:48 2005 From: sklass at pointcircle.com (rh0dium) Date: 25 Aug 2005 11:48:48 -0700 Subject: Superclass files and order - oh my!! Questioning the experts!! In-Reply-To: <1124994489.853664.188260@f14g2000cwb.googlegroups.com> References: <1124994489.853664.188260@f14g2000cwb.googlegroups.com> Message-ID: <1124995728.382112.250500@g47g2000cwa.googlegroups.com> Slight correction.. rh0dium wrote: > Hi all, > > Still a newbie but making some headway. So I have a file structure > like this.. > > top/ > --modules/ > ----metrics.py > --metrix/ > ----uptime.py > > Now metrics.py is my superclass, and uptime.py inherits the superclass > metrics.py. > > So for arguments sake > > metrics.py > ---------------- > class metrics(): > def __init__(self, foo=bar): > self.foo=foo > def run(): > pass > ---------------- > > > uptime.py > ---------------- > class metrics(metrics): class uptime(metrics): > def run(): > print "hello" > > if __name__ == '__main__': > > if os.path.exists("../modules"): > print "importing modules" > sys.path.insert( 0, "../modules") > import metrics > else: > print "Unable to bring in main metric instance - path not correct" > sys.exit(1) > > ---------------- > > Now if simply try to run ./uptime.py it complains about not having the > metrics module? Huh but I brought it in? > > File "./uptime.py", line 19, in ? > class uptime(metrics): > NameError: name 'metrics' is not defined > > BUT... > > If I do this then it it imports.. ( NOTE the order is different.. ) > > uptime.py > ---------------- > if os.path.exists("../modules"): > print "importing modules" > sys.path.insert( 0, "../modules") > import metrics > else: > print "Unable to bring in main metric instance - path not correct" > sys.exit(1) > > class metrics(metrics): class uptime(metrics): > def run(): > print "hello" > > if __name__ == '__main__': > pass > > ---------------- > > But I get the next erorr: > Path exists > importing modules > Traceback (most recent call last): > File "./uptime.py", line 34, in ? > class uptime(metrics): > TypeError: Error when calling the metaclass bases > module.__init__() takes at most 2 arguments (3 given) > > So the question is.. > > Why is it not looking at the "if __name__ == '__main__':" statement > and starting there? I thought it was supposed to do that? Why can't > I just put a class statement in a file and if you put nothing (like if > __name__....) the class is just "registered" so later if (like > __main__) I use it then it's available. > > I want to not have to put that ugly code at the top but it seems as > though that's the only way? Someone must have figured this out and can > you explain why it workst this way? > > I must be missing something cause that's how modules work. How is this > different than a module? From k33rni at gmail.com Wed Aug 24 10:21:35 2005 From: k33rni at gmail.com (k33rni at gmail.com) Date: 24 Aug 2005 07:21:35 -0700 Subject: yapsnmp port issues References: <1124807655.170230.144200@f14g2000cwb.googlegroups.com> Message-ID: <1124893295.341934.59900@g44g2000cwa.googlegroups.com> Solved the problem all by myself. Patch (and rationale) available on sourceforge. From peter at engcorp.com Tue Aug 2 17:18:51 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 02 Aug 2005 17:18:51 -0400 Subject: Art of Unit Testing In-Reply-To: References: <87mzo0s25q.fsf@lucien.dreaming> Message-ID: Christoph Zwerschke wrote: > I completely agree and I think it makes a lot of sense that unittest > calls setUp and tearDown for every single test. However, the fact that > this is *generally* the best way doesn't exclude the fact that there are > *exceptions* when it makes sense to setUp and tearDown not for every > test, e.g. when it is absolutely sure that the fixture cannot be > destroyed by the individual tests or when creating the fixture takes too > much time. I already gave the example of creating database connections > or even creating/importing whole databases. My question was, how do I > handle these cases with the standard lib unittest? What's wrong with using Python's existing "global" support, and just having your test case setUp() call a global setup routine which checks whether that global setup work has already been done and, if not, does it once and sets a flag to say that it has now been done? I've done this easily in the few cases where I've wanted this behaviour. It doesn't seem complex enough to warrant adding to the standard unit test support. > According to the "extreme programming" paradigm, testing should be done > several times a day. So a requirement for extreme programm is that tests > are fast enough. If the testing needs too much time, people are > discouraged to test often. If you're going to quote XP rules of thumb, the tests should be independent and very fast, and if you have a setup code that is taking a long time, it's likely a "code smell" of some kind, and you should be fixing the design which prevents you writing these tests with minimal and quick setup. Are these really like "acceptance" tests? If they were unit tests, they should take only a few minutes to run, total, and you should be running them all *many* times a day, not twice. Still, if you're stuck, and really do need a lengthy setup to execute once as an optimization, it's not hard to do with globals. -Peter From phleum_nospam at chello.se Thu Aug 18 13:21:09 2005 From: phleum_nospam at chello.se (Carl) Date: Thu, 18 Aug 2005 19:21:09 +0200 Subject: Bitwise operations in Python? Message-ID: Dear friends, I am currently porting a fortran program to Python but am stuck on the intrinsic IBITS function. Does anyone know about a replacement function for IBITS in Python? Yours, Carl >>>>>>>>>>>>>>>> IBITS(I, POS, LEN) Extracts a sequence of bits. I must be of type integer. POS must be of type integer. It must be nonnegative and POS + LEN must be less than or equal to BIT_SIZE (I). LEN must be of type integer and nonnegative. Class Elemental function Result Type and Attributes Same as I. Result Value The result has the value of the sequence of LEN bits in I beginning at bit POS, right-adjusted and with all other bits zero. The bits are numbered from 0 to BIT_SIZE(I)-1, from right to left. Examples IBITS (14, 1, 3) has the value 7. From Scott.Daniels at Acm.Org Mon Aug 22 15:03:01 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Aug 2005 12:03:01 -0700 Subject: Reg Python Byte code In-Reply-To: References: <20050822101523.54728.qmail@web8402.mail.in.yahoo.com> Message-ID: <430a1575$1@nntp0.pdx.net> Warning: this post contains arcane knowledge. Steve Holden wrote: > praba kar wrote: >> Python 2.3 creates byte code with *.pyc >> extention. But Python 2.4 creates bytes code with >> *.pyo. Is there any difference between *.pyc >> and *.pyo?. >> > Yes. The .pyo files are optimized by removing certain features that > aren't essential to execution (things like doc strings). The -O option defines __debug__ to be False, and (as a side-effect) ignores assert statements in the code used. The -OO option does everything the -O option does, while also removing things like doc strings. Both -O and -OO produce .pyo files, so having made things with -OO, even using -O you will not see the doc strings in those modules. Here is a weird python program called opdemo.py to show these effects: Call it opdemo.py ================================== import sys def function(): '''doc strings kept''' try: assert 4 == 5 print '%s: assert skipped (__debug__ = %s)' % ( __name__, __debug__) except AssertError: print '%s: assert checked (__debug__ = %s)' % ( __name__, __debug__) docstring = function.__doc__ or 'No doc strings' print sys.version print '%s: __debug__ = %s; %s' % (__name__, __debug__, docstring) print __file__ function() if __name__ == '__main__': print '=============' import opdemo print opdemo.__name__, opdemo.docstring, opdemo.__file__ opdemo.function() ================================== Now that you have this, you can run: python opdemo.py and then python opdemo.py To see how you can tell if you are running post-compiled. If you run python -OO opdemo.py and then python -O opdemo.py You will see it looks like -O also removes docstrings. However if you delete opdemo.py and run python -O opdemo.py and then python -O opdemo.py You will see the docstrings are in fact there for -O. Of course, for all of this you will have to think a lot about exactly what code is being executed. A help to figuring this out is to remember that if you import a module you get a new and different copy of the module from the main program. --Scott David Daniels Scott.Daniels at Acm.Org From martin at v.loewis.de Fri Aug 19 02:07:31 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 19 Aug 2005 08:07:31 +0200 Subject: certificate-based authentication (Martin v. L?wis) In-Reply-To: References: Message-ID: <43057724$0$20134$9b622d9e@news.freenet.de> > I'm using Python version 2.2 - the SafeTransport class in it's xmlrpclib > doesn't have a 'get_host_info' method. Which version were you referring > to? I was looking at the HEAD revision in CVS. That feature was apparently released with Python 2.3. Still, httplib supports client certificates since Python 1.6, so you should be able to extend SafeTransport even in 2.2. Regards, Martin From mwh at python.net Mon Aug 15 11:52:09 2005 From: mwh at python.net (Michael Hudson) Date: Mon, 15 Aug 2005 15:52:09 GMT Subject: Python's Exception, and Capitalization References: <1123856890.712908.247920@o13g2000cwo.googlegroups.com> <1123858776.576754.318620@o13g2000cwo.googlegroups.com> Message-ID: "Ray" writes: > D H wrote: >> Yeah, the python standard library has been built by lots of different >> people. It wasn't designed by one entity using one standard like the >> java standard library or .NET/Mono class library. > > Um, OK, so is it customary in modern Python programs to follow Java > convention? then methods/functions should be written someMethod() or > myFunction()? > >> > 2. I'm quite baffled that you either have try/except, or try/finally. >> >> Apparently that will be fixed sometime: >> http://python.miscellaneousmirror.org/peps/pep-0341.html > > Ah, okay. I'm quite surprised to see the date--it was _that_ recent! :) > But currently, how have you--Python guys who code for a living--been > handling this case? I know that you can put another try inside a try, It's what I do, and I'm not bothered by it, TBH. Nested try's have an explicitness bonus. Cheers, mwh -- Anything that doesn't autonomously leave the fridge, or at the very least waves protest banners, will be eaten. -- Rik Steenwinkel, asr From gandalf at geochemsource.com Sat Aug 6 07:38:24 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Sat, 06 Aug 2005 13:38:24 +0200 Subject: How to use DrPython plugins Message-ID: <42F4A130.3010506@geochemsource.com> Hi All! I have DrPython installed. I see there are cool plugins but I cannot user them. For example, I installed the "CodeCompletion" and "CodeMark" plugins. I have enabled the "CodeCompletion" plugin by default. I assigned the shortcut CTRL+SPACE to :CodeCompletion "Toggle Code Completion". However, when I'm editing a file nothing happens. No matter if I hit CTRL+SPACE or not. I have the same problem with CodeMark too. I setup the shortcuts but nothing happens. What am I doing wrong? Thanks, Les From jepler at unpythonic.net Wed Aug 3 18:06:30 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 3 Aug 2005 17:06:30 -0500 Subject: cut & paste text between tkinter widgets In-Reply-To: References: Message-ID: <20050803220626.GA24660@unpythonic.net> Here's some code that gives a cut-copy-paste pop-up window on all Entry widgets in an application. This code is released into the public domain. Jeff Epler #------------------------------------------------------------------------ import Tkinter def make_menu(w): global the_menu the_menu = Tkinter.Menu(w, tearoff=0) the_menu.add_command(label="Cut") the_menu.add_command(label="Copy") the_menu.add_command(label="Paste") def show_menu(e): w = e.widget the_menu.entryconfigure("Cut", command=lambda: w.event_generate("<>")) the_menu.entryconfigure("Copy", command=lambda: w.event_generate("<>")) the_menu.entryconfigure("Paste", command=lambda: w.event_generate("<>")) the_menu.tk.call("tk_popup", the_menu, e.x_root, e.y_root) t = Tkinter.Tk() make_menu(t) e1 = Tkinter.Entry(); e1.pack() e2 = Tkinter.Entry(); e2.pack() e1.bind_class("Entry", "", show_menu) t.mainloop() #------------------------------------------------------------------------ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From simon.brunning at gmail.com Mon Aug 22 12:24:15 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Mon, 22 Aug 2005 17:24:15 +0100 Subject: Python for Webscripting (like PHP) In-Reply-To: <7xslx2kkuu.fsf@ruckus.brouhaha.com> References: <7xslx2kkuu.fsf@ruckus.brouhaha.com> Message-ID: <8c7f10c60508220924313e5ae6@mail.gmail.com> On 22 Aug 2005 09:16:41 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Fredrik Lundh" writes: > > > (Python has even been told to be used by Yahoo! and Google, among others, > > > but nobody was able to demonstrate this, so far) > > hint: > > http://mail.google.com/support/bin/answer.py?answer=6554 > > I don't see anything about Python at that url. Don't look at the page the URL returns - look at the URL itself. ;-) -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From grante at visi.com Tue Aug 9 20:42:14 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 10 Aug 2005 00:42:14 -0000 Subject: Does any one recognize this binary data storage format References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> <1123617422.783846.62590@g44g2000cwa.googlegroups.com> <11fi4piovsrgoe1@corp.supernews.com> <42f9187e$1@nntp0.pdx.net> <11fi98edg5mha3f@corp.supernews.com> Message-ID: <11fijb6mu205l09@corp.supernews.com> On 2005-08-09, Christopher Subich wrote: > Grant Edwards wrote: >> That would just be sick. I can't imagine anybody on an 8-bit >> CPU using FP for a phone number. > > Nobody on an 8-bit CPU would have a FPU, so I'll guarantee that this is > done using only 8 or 16-bit (probably 8) integer math. And I'll guarantee that the difference between 333-3333 and 666-6666 has to be more than 1-bit. There's no way that can be the correct data unless it's something like an index into a different table or a pointer or something along those lines. -- Grant Edwards grante Yow! ANN JILLIAN'S HAIR at makes LONI ANDERSON'S visi.com HAIR look like RICARDO MONTALBAN'S HAIR! From en.karpachov at ospaz.ru Sat Aug 20 00:42:06 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Sat, 20 Aug 2005 08:42:06 +0400 Subject: Well, another try Re: while c = f.read(1) In-Reply-To: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> Message-ID: <20050820084206.0f40701c.jk@ospaz.ru> On 18 Aug 2005 22:21:53 -0700 Greg McIntyre wrote: > f = open("blah.txt", "r") > while True: > c = f.read(1) > if c == '': break # EOF > # ... work on c > > Is some way to make this code more compact and simple? It's a bit > spaghetti. > > This is what I would ideally like: > > f = open("blah.txt", "r") > while c = f.read(1): > # ... work on c for data in iter(lambda:f.read(1024), ''): for c in data: # ... work on c -- jk From kpacka at inbox.ru Mon Aug 22 09:14:09 2005 From: kpacka at inbox.ru (Vadimir) Date: 22 Aug 2005 06:14:09 -0700 Subject: Problem with wxPython 2.6.1 In-Reply-To: References: Message-ID: <1124716449.663875.307090@f14g2000cwb.googlegroups.com> apt-get install alien apt-get install libgtk2.0-dev freeglut3-dev python2.3-dev wget http://voxel.dl.sourceforge.net/wxpython/wxPython2.6-2.6.1.0-1.src.rpm rpmbuild --rebuild --define 'pyver 2.3' wxPython2.6-2.6.1.0-1.src.rpm cd rpmdir alien *py2.3* dpkg -i *py2.3*.deb From apardon at forel.vub.ac.be Tue Aug 23 08:47:17 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 Aug 2005 12:47:17 GMT Subject: while c = f.read(1) References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124431651.152721@yasure> Message-ID: Op 2005-08-23, Sybren Stuvel schreef : > Antoon Pardon enlightened us with: >> The problem with interpreting empty as false is that empty just >> means no data now. But no data now can mean no data yet or it can >> mean no more data. The problem is not so much as having empty >> interpreted as false but that people don't seem to think about which >> false value would be more appropiate in particular circumstances. > > By no means can you take all possible future alterations in account. > You have to make assumptions somewhere. But having to write out a boolean expression fully, would force one to make his assumptions explicite. My impression is that people don't actually make assumptions but are happy to just throw a variable in a conditional context. They only begin to think about the assumptions this imply when things break. >> IMO reading '' from network connection is the most natural result >> when no data is ready and this should be treated differently from an >> EOF which would indicate the connection was closed. >> >> But how can you do this when somewhere else '' is used as an >> indication for an EOF. > > That's called "a protocol". If another protocol is used than the > software is written for, it'll break. This has nothing to do with > accepting something as False or True. Yes it has. That empty sequences are treated as false in a conditional context, influences what kind of protocols are used. >> And it is IMO this kind of comments that lead to '' being used as an >> EOF. > > And who cares if it is? In a blocking environment, it seems pretty > okay to me. Not all environments are blocking and it seems to be me it is better to use protocols that are are as much as possible independant from whether the environment is blocking or not. > A read() call could block, waiting for more data to > arrive. If there is none because the connection is down, for instance, > it could return ''. Of course, raising an exception would be better in > such a case, and it would also remove any ambiguity. > >> I have yet to see a mathematical work where 0, or any kind of empty >> sequence is treated as false. > > In that case, properly define your variables to hold either booleans > or numbers, and only test booleans in an "if var:" clause, and only > test numbers in an "if var != 0:" clause. > >> a bytestring when data is available, >> '' when no data is available >> None when the connection was closed > > Seems pretty nice to me. In such a case, one could do: > > data = network.read() > if data: > handleData(data) > > if data is None: > handleClosedConnection() > > I don't see a problem here. That is because you are looking at it too much in isolation. What if you have a function that among things handles bytes coming from a stream. Whether that stream is a regular file or a network connection may be irrelevant for the function, but if regular files return '' for EOF and other streams don't, you are in trouble. And IMO that '' is treated as false played its parts in deciding for it as indicating EOF. -- Antoon Pardon From fperez.net at gmail.com Wed Aug 3 13:38:11 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Wed, 03 Aug 2005 11:38:11 -0600 Subject: Dabo in 30 seconds? References: <200508010830.27322.ed@leafe.com> <200508011220.41469.ed@leafe.com> <42EFB4CF.5070205@ulmcnett.com> Message-ID: Paul McNett wrote: > I've done things like this in the past, in my own Visual Foxpro > framework. In that situation, I had enough control over the deployment > to also ship a small smtp client, and automatically email the error > without requiring any interaction at all. Clients were impressed when > I'd already have a fix for the problem before they even notified me of > the issue! Well, I thought about doing the same, which is easy since python already has smtplib built into the stdlib. I was just lazy and didn't do it. Though I would not implement it to send things silently without user acknowledgement. Since ipython is not installed by me on user machines (your situation was obviously different), I prefer to notify users of things about to be done first, in case they'd rather not have it 'call home'. But it would be a nice enhancement to add the option for auto-emailing in case of trouble. From pierre.barbier at cirad.fr Sat Aug 20 10:58:38 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Sat, 20 Aug 2005 16:58:38 +0200 Subject: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ? In-Reply-To: References: Message-ID: <4307446c$0$17386$626a14ce@news.free.fr> Miernik a ?crit : > On my Debian GNU/Linux system I have Python 2.3 installed in [...] > > I noticed that all those files come in three "flavours": > *.py *.pyc *.pyo > > Is it possible that only one "flavour" of these files is needed, and I can > delete the remaining two, any my Python installation will still work? Well, I would greatly discourage that ! First, if you erase the *.py, you won't be able to get detailed information on the traceback (like actual code causing throwing the exception) as only the filename/line is kept in the .pyc or .pyo. Then, if you erase the .pyo that means you don't want to use the optimized version of the modules (why not ... but it will be at the cost of performances). At last, if you keep only the .pyo you won't be able to run programs without the optimization. So let's summarize : 1 - you keep only .py files: everything will work but Python will have to recompile the modules everytime it's used first 2 - you keep only .pyc files: two problems: first you won't be able to launch Python with the "-O" option (i.e. optimize) because it will look for .py or .pyo files, then if any exception is thrown in one of the modules, you won't be able to use the very good pdb module with code information and all. 3 - you keep only .pyo files: similar to keeping only the .pyc files but you won't be able to launch Python without the "-O" ! > > The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting > two "flavours" would save about 10 MB on my system, and that would help > me much as I am trying to fit my system on a 256 MB SD card, to make it > quiet (hard disks are noisy). > > Can I just do > cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc > for example, and everything will still work as before? > Well, if you don't care about performances, the best to do is (using zsh ;) ): cd /usr/lib/python2.3 && rm -f **/*.py{o,c} Pierre From exarkun at divmod.com Tue Aug 16 11:57:54 2005 From: exarkun at divmod.com (Jp Calderone) Date: Tue, 16 Aug 2005 11:57:54 -0400 Subject: Creating a graphical interface on top of SSH. How? In-Reply-To: <1124201425.891035.281220@g44g2000cwa.googlegroups.com> Message-ID: <20050816155754.3914.115678388.divmod.quotient.4987@ohm> On 16 Aug 2005 07:10:25 -0700, "John F." wrote: >I want to write a client app in Python using wxWindows that connects to >my FreeBSD server via SSH (using my machine account credentials) and >runs a python or shell script when requested (by clicking a button for >instance). > >Can someone give me some advice on how to create a "graphical shell" >per se? tkconch might be interesting to look at. http://www.twistedmatrix.com/projects/conch/ From jarrod.roberson at gmail.com Fri Aug 5 15:10:12 2005 From: jarrod.roberson at gmail.com (fuzzylollipop) Date: 5 Aug 2005 12:10:12 -0700 Subject: The ONLY thing that prevents me from using Python In-Reply-To: <1123256939.119967.280500@z14g2000cwz.googlegroups.com> References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <1123256939.119967.280500@z14g2000cwz.googlegroups.com> Message-ID: <1123269012.654085.247950@g44g2000cwa.googlegroups.com> lazy newbie programmers, that is what the world needs more of for sure! From fphsml at gmail.com Fri Aug 26 09:34:03 2005 From: fphsml at gmail.com (James) Date: 26 Aug 2005 06:34:03 -0700 Subject: Integrate C source in a Python project In-Reply-To: References: Message-ID: <1125063243.748286.117800@g47g2000cwa.googlegroups.com> billiejoex wrote: > Hi all. > I was wondering if it ispossible to integrate C source in a python project. There is ofcourse Python/C API http://docs.python.org/api/api.html But you will probably be easier off with Pyrex or Swig. Good summary on when to use which http://www.rexx.com/~dkuhlman/python_201/python_201.html#SECTION006500000000000000000 James From prabapython at yahoo.co.in Wed Aug 31 00:42:54 2005 From: prabapython at yahoo.co.in (praba kar) Date: Wed, 31 Aug 2005 05:42:54 +0100 (BST) Subject: Python built email message doesn't support OutLook Express In-Reply-To: <1125317768.854518.134140@g44g2000cwa.googlegroups.com> Message-ID: <20050831044254.43443.qmail@web8403.mail.in.yahoo.com> --- "Diez B. Roggisch" wrote: > That is not what Sybren requested - we need the > message text. If you > send html, make sure your paragraphs are html > paragraphs (enclosed in >

-tags) and not pure whitespace, as html ignores > these. > I am sending text message as a paragraph __________________________________________________________ How much free photo storage do you get? Store your friends 'n family snaps for FREE with Yahoo! Photos http://in.photos.yahoo.com From nyamatongwe+thunder at gmail.com Tue Aug 16 20:04:15 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Wed, 17 Aug 2005 00:04:15 GMT Subject: Windows message pump problems In-Reply-To: References: Message-ID: <3avMe.873$FA3.106@news-server.bigpond.net.au> Cantankerous Old Git: > Problem 1: > If I have another thread call DestroyWindow after a delay, it gets an > error "permission denied". I really can't see why. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/destroywindow.asp """A thread cannot use DestroyWindow to destroy a window created by a different thread.""" Posting WM_CLOSE to the window will probably work. If not, then send an application defined message to the window and handle it by calling DestroyWindow. Neil From giampiero19601 at yahoo.it Tue Aug 2 15:41:42 2005 From: giampiero19601 at yahoo.it (giampiero mu) Date: 2 Aug 2005 12:41:42 -0700 Subject: finding sublist In-Reply-To: <1123003985.735221.119630@g44g2000cwa.googlegroups.com> References: <1122991014.595476.5740@g47g2000cwa.googlegroups.com> <1123003985.735221.119630@g44g2000cwa.googlegroups.com> Message-ID: <1123011702.830491.224500@g43g2000cwa.googlegroups.com> controlla("12345678") -> "12345678" thanks everyone. only a question. there is a way to advantage of binary sequences? From sjmachin at lexicon.net Thu Aug 18 19:18:44 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Aug 2005 09:18:44 +1000 Subject: how do i add a new path into sys.path? In-Reply-To: References: Message-ID: <43051754@news.eftel.com> wen wrote: > on my system(win2k server, python 2.3.5), > >>>>import sys >>>>print sys.path > > ['C:\\', 'C:\\WINNT\\system32\\python23.zip', > 'C:\\Python23\\lib\\site-packages\\Pythonwin', > 'C:\\Python23\\lib\\site-packages\\win32', > 'C:\\Python23\\lib\\site-packages\\win32\\lib', > 'C:\\Python23\\lib\\site-packages', 'C:\\Python23\\DLLs', > 'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win', > 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23', 'D:\\Program Files\\DeLano > Scientific\\PyMOL\\modules'] > > now, i wanna add "C:\Python23\Pmw\Pmw_1_2\lib" into sys.path, how? > > any help would be appreciated. > > with my kind regards, > Wen > > cat clpyaibot.log * sys.path is instance of . * "C:\Python23\Pmw\Pmw_1_2\lib" is a [non-raw, living dangerously] string. * does not compute, trying again under various failure modes ... * detected Shift key failure * interpreting "wanna" as "want to" * parsed chunk: """I want to add into """ * no such keyword: "add" * .add ... not found * .into ... not found * .addinto ... not found * checking plausible alternatives ... * .append() * .insert(, ) From usenet.filter at gmail.com Thu Aug 4 00:36:21 2005 From: usenet.filter at gmail.com (Stephan) Date: 3 Aug 2005 21:36:21 -0700 Subject: Python's CSV reader Message-ID: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> I'm fairly new to python and am working on parsing some delimited text files. I noticed that there's a nice CSV reading/writing module included in the libraries. My data files however, are odd in that they are composed of lines with alternating formats. (Essentially the rows are a header record and a corresponding detail record on the next line. Each line type has a different number of fields.) Can the CSV module be coerced to read two line formats at once or am I better off using read and split? Thanks for your insight, Stephan From titogarcia_borra_esto at gmail.com Wed Aug 10 12:20:48 2005 From: titogarcia_borra_esto at gmail.com (Tito) Date: Wed, 10 Aug 2005 18:20:48 +0200 Subject: What are modules really for? In-Reply-To: <42fa2189$0$4880$626a14ce@news.free.fr> References: <42F8CC8F.7020500@le.ac.uk> <1123602877.802803.281500@g14g2000cwa.googlegroups.com> <42F9BC7D.1050300@le.ac.uk> <42fa2189$0$4880$626a14ce@news.free.fr> Message-ID: > [1] 'aName' => public, '_aName' => protected, '__aName' => private I didn't know this one, as I am quite new to Python. Is it really general use? Regards, Tito From k.robert at gmx.de Mon Aug 29 04:13:55 2005 From: k.robert at gmx.de (Robert) Date: Mon, 29 Aug 2005 10:13:55 +0200 Subject: sslerror: (8, 'EOF occurred in violation of protocol') ??? Message-ID: On some connections only from some computers/network setups I get this error: Traceback (most recent call last): File "", line 1, in ? File "ClientCookie\_urllib2_support.pyo", line 524, in open File "ClientCookie\_urllib2_support.pyo", line 424, in http_response File "ClientCookie\_urllib2_support.pyo", line 541, in error File "urllib2.pyo", line 306, in _call_chain File "ClientCookie\_urllib2_support.pyo", line 185, in http_error_302 File "ClientCookie\_urllib2_support.pyo", line 518, in open File "urllib2.pyo", line 326, in open File "urllib2.pyo", line 306, in _call_chain File "ClientCookie\_urllib2_support.pyo", line 759, in https_open File "ClientCookie\_urllib2_support.pyo", line 608, in do_open File "httplib.pyo", line 712, in endheaders File "httplib.pyo", line 597, in _send_output File "httplib.pyo", line 564, in send File "httplib.pyo", line 985, in connect File "socket.pyo", line 73, in ssl sslerror: (8, 'EOF occurred in violation of protocol') The server is always the same and ok. but different client-OS/proxies/firewalls/routers are in use. What is the nature of this error? How is it possible that an EOF in ssl-connections (during connect?) occures? What can be done to handle/circumvent that problem? Robert From lycka at carmen.se Tue Aug 30 11:36:47 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 30 Aug 2005 17:36:47 +0200 Subject: micro-python - is it possible? In-Reply-To: <431440bb$1@news.orcon.net.nz> References: <431440bb$1@news.orcon.net.nz> Message-ID: Evil Bastard wrote: > Hi, > > Has anyone done any serious work on producing a subset of python's > language definition that would suit it to a tiny microcontroller > environment? Isn't pypy meant to support different backends with different requirements and constraints using the same basic language? From bob at passcal.nmt.edu Tue Aug 2 20:49:07 2005 From: bob at passcal.nmt.edu (Bob Greschke) Date: Tue, 2 Aug 2005 18:49:07 -0600 Subject: Setting a drive's volume label Message-ID: ...the name for a drive (hard or removable) that shows up when, for example, a USB flash drive is recognized by the system. I don't know if this shows up somewhere in Linux. Can this be set from Python? I guess it would be some MFC call in Windows (I don't know anything about doing that), and some ??? call in Linux? Could use both. Thanks! Bob From borges2003xx at yahoo.it Fri Aug 26 15:12:00 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 26 Aug 2005 12:12:00 -0700 Subject: minimalist regular expression In-Reply-To: <1125073552.716818.198610@g14g2000cwa.googlegroups.com> References: <1125001990.353470.266810@o13g2000cwo.googlegroups.com> <1125050745.833419.120910@o13g2000cwo.googlegroups.com> <1125073552.716818.198610@g14g2000cwa.googlegroups.com> Message-ID: <1125083520.397321.153100@g44g2000cwa.googlegroups.com> Whenever I ask a match in a string for(a{3,}b and match for (a{1,}, the first is implicit second: ab is implicit in a.*;automatically From dejan.wirusrodiger at ck.t-com.hr Tue Aug 9 14:42:34 2005 From: dejan.wirusrodiger at ck.t-com.hr (Dejan Rodiger) Date: Tue, 09 Aug 2005 20:42:34 +0200 Subject: Does any one recognize this binary data storage format In-Reply-To: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> References: <1123608554.533982.52870@g44g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com said the following on 9.08.2005 19:29: > We are working on a data file reader and extraction tool for an old > MS-DOS accounting system dating back to the mid 80's. Could you tell us what is the extension of those files? Could you post full 5-10 records (ASCII + HEX)? -- Dejan Rodiger - PGP ID 0xAC8722DC Delete wirus from e-mail address From eurleif at ecritters.biz Tue Aug 9 21:35:26 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Wed, 10 Aug 2005 01:35:26 GMT Subject: Retaining an object In-Reply-To: References: Message-ID: sysfault wrote: > I'm using os.popen() to open that program via the syntax: > os.popen('pidof var_name', 'r'), but as you know var_name is not > expanded within single quotes, os.popen('pidof %s' % var_name, 'r') From usenet.filter at gmail.com Thu Aug 4 11:28:30 2005 From: usenet.filter at gmail.com (Stephan) Date: 4 Aug 2005 08:28:30 -0700 Subject: Python's CSV reader References: <1123130181.767413.109340@z14g2000cwz.googlegroups.com> Message-ID: <1123169310.391973.217860@o13g2000cwo.googlegroups.com> Thank you all for these interesting examples and methods! Supposing I want to use DictReader to bring in the CSV lines and tie them to field names, (again, with alternating lines having different fields), should I use two two DictReaders as in Christopher's example or is there a better way? -- Stephan From calfdog at yahoo.com Thu Aug 25 15:39:33 2005 From: calfdog at yahoo.com (calfdog at yahoo.com) Date: 25 Aug 2005 12:39:33 -0700 Subject: New Arrival to Python In-Reply-To: References: <1BkPe.304848$5V4.169335@pd7tw3no> Message-ID: <1124998773.672599.269770@o13g2000cwo.googlegroups.com> I have been using Eclispe IDE with the PyDev plugin for Python Development. it allow you to set up projects. you can use PyAnt to build them. It works great for me. It's free an easy to use. Eclipse is at http://www.eclipse.org There is also Emacs with the python plugin Rob M. python project - http://pamie.sourceforge.net From tim.golden at viacom-outdoor.co.uk Fri Aug 19 10:09:47 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri, 19 Aug 2005 15:09:47 +0100 Subject: Adobe COM with Python Message-ID: <9A28C052FF32734DACB0A288A3533991044D21D7@vogbs009.gb.vo.local> [Andy W] | What i want to do is use, python COM to fireup Adobe and | print the pdf | file to a printer. If that's all you want to do, have a look at this: http://timgolden.me.uk/python/win32_how_do_i/print.html Or you could try for a Ghostscript solution. (Additionally, I seem to remember that the Acrobat COM object is really only designed to work in Internet Explorer. That was a version or so ago -- of both -- so I may be off beam). 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 benji at benjiyork.com Thu Aug 18 08:21:42 2005 From: benji at benjiyork.com (Benji York) Date: Thu, 18 Aug 2005 08:21:42 -0400 Subject: creating/modifying sparse files on linux In-Reply-To: References: <1124304819.090356.200280@f14g2000cwb.googlegroups.com> <1124314877.646737.266290@z14g2000cwz.googlegroups.com> Message-ID: <43047D56.6000907@benjiyork.com> Terry Reedy wrote: > megastring = 1000000*'a' # t < 1 sec on my machine >>(other than keep appending to a string until it reaches 1MB len)? > > You mean like (unexecuted) > s = '' > for i in xrange(1000000): s += 'a' #? > > This will allocate, copy, and deallocate 1000000 successively longer > temporary strings and is a noticeable O(n**2) operation. Not exactly. CPython 2.4 added an optimization of "+=" for strings. The for loop above takes about 1 second do execute on my machine. You are correct in that it will take *much* longer on 2.3. -- Benji York From berlin.brown at gmail.com Sat Aug 20 15:27:16 2005 From: berlin.brown at gmail.com (Ramza Brown) Date: Sat, 20 Aug 2005 15:27:16 -0400 Subject: Binary Trees in Python In-Reply-To: References: Message-ID: [diegueus9] Diego Andr?s Sanabria wrote: > Hello!!! > > I want know if python have binary trees and more? Yea, binary trees are more data structures as opposed to libraries: Here is one approach ( remove the 'java.lang' stuff) http://www.newspiritcompany.com/BinaryTreePyNew.html -- Ramza from Atlanta http://www.newspiritcompany.com From dr_tyson at hotmail.com Tue Aug 30 17:35:33 2005 From: dr_tyson at hotmail.com (dr_tyson at hotmail.com) Date: 30 Aug 2005 14:35:33 -0700 Subject: Embedding Matplotlib images into wxPython In-Reply-To: <1125420462.124637.113810@z14g2000cwz.googlegroups.com> References: <1125420462.124637.113810@z14g2000cwz.googlegroups.com> Message-ID: <1125437733.925985.104270@z14g2000cwz.googlegroups.com> Well, to answer my own question, the problem turned out to be that I was using the 'wx' backend and not the 'wxagg' one. Attempting to use the former typically resulted in a not implemented error upon the call to imshow. I was working from an older set of matplotlib example files which didn't include the dynamic image with wxagg demo. Thank goodness for those examples! No better way to learn how to implement code. From steve at holdenweb.com Sun Aug 21 18:53:28 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Aug 2005 23:53:28 +0100 Subject: question about binary and serial info In-Reply-To: <1124658915.090253.168700@g47g2000cwa.googlegroups.com> References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <43053b81$1@news.eftel.com> <11gag9de4vgbu33@corp.supernews.com> <1124658915.090253.168700@g47g2000cwa.googlegroups.com> Message-ID: nephish at xit.net wrote: > Sorry i am late getting back on this. > ord() is finally what is giving me what i wanted. > the vendor told me that what was comming in was an ascii string > representing hex characters. So i expected when i used the serial > module > that what i would be getting was something along the lines of 4A, 3D, > etc.. > but i got weird characters. So then (with the help of this very thread) > discovered that i am reading raw bytes. i am supposed to validate the > bytes as they come in because the message comes in four at a time. and > i validate each byte > like this > var = (validation number) > a = ser.read(1) > x = ord(a) > then to validate : x = (x & var) > > I am really sorry about the confusion. i am really new at this. > but i am getting what i am supposed to now. > > i dont have the details on the script, because it is at work. > but i will post it monday. > thanks for everything. > i would still be banging my head if not for this thread > Nice of you to provide some feedback, and great that your program in understanding the data. You'll find c.l.py can save you large amounts of time, and before you know it you'll be answering other people's questions. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mwm at mired.org Fri Aug 5 22:14:00 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 05 Aug 2005 22:14:00 -0400 Subject: The ONLY thing that prevents me from using Python References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> <1123256939.119967.280500@z14g2000cwz.googlegroups.com> <1123264238.812930.315720@g47g2000cwa.googlegroups.com> Message-ID: <86br4byfpz.fsf@bhuda.mired.org> "Paul McGuire" writes: > Once you find your service based on price/support/etc., send them an > e-mail asking for Python support. The worst they can say is "no, and > we never will," but just as likely they might respond "yes, it's > already there" or "yes, we can add that". The only way ISPs will find out that Python is popular is if potential customers tell them they need it. So if they say no, be *sure* and tell them you won't be using them because of that. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From cliff at develix.com Mon Aug 1 09:11:21 2005 From: cliff at develix.com (Cliff Wells) Date: Mon, 01 Aug 2005 06:11:21 -0700 Subject: Majordomo results: [UBCCS:VIRUS] Was: Returned mail: Data f In-Reply-To: <200508011304.j71D4S7l016303@pedigree.cs.ubc.ca> References: <200508011304.j71D4S7l016303@pedigree.cs.ubc.ca> Message-ID: <1122901882.19618.298.camel@localhost.localdomain> On Mon, 2005-08-01 at 06:04 -0700, Majordomo at cs.ubc.ca wrote: > **** Command 'nuisance' not recognized. Hm, seemed to work anyway. -- cliff at develix.com http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: From learningProgramming at gmail.com Thu Aug 25 18:23:59 2005 From: learningProgramming at gmail.com (Learning Python) Date: 25 Aug 2005 15:23:59 -0700 Subject: a dummy python question In-Reply-To: References: <1125005370.772096.5770@g14g2000cwa.googlegroups.com> <1125006812.641866.125150@g44g2000cwa.googlegroups.com> Message-ID: <1125008639.681838.275410@o13g2000cwo.googlegroups.com> Thanks all for replying. I finally know what's going on. From tkpmep at hotmail.com Tue Aug 23 18:07:55 2005 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: 23 Aug 2005 15:07:55 -0700 Subject: Reading just a few lines from a text file References: <1124833314.634409.317980@z14g2000cwz.googlegroups.com> <1124834076.521797.60180@z14g2000cwz.googlegroups.com> Message-ID: <1124834875.760223.131270@z14g2000cwz.googlegroups.com> Right now my code reads as follows: infile=file(FileName) for line in reversed(infile.readlines()): #Search from the bottom up if int(line.split()[0]) == MyDate: Data= float(line.split()[-1]) break infile.close() I have to read about 10,000 files, each with data. I'm looking to speed up each individual file open/close cycle. Thomas Philips From mwm at mired.org Thu Aug 4 01:10:32 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 04 Aug 2005 01:10:32 -0400 Subject: Standards not standard References: <86vf2oevxv.fsf@bhuda.mired.org> Message-ID: <86acjy1e47.fsf@bhuda.mired.org> Dark Cowherd writes: >> > I really think that the community needs a lot more of STANDARDS not >> > a STANDARD GUI >> >> Standards happen in one of two ways. Either an 800-lb gorrilla >> establishes them by fiat, or a group of people interested in having >> their code play well together hashes out something after they've all >> taken a crack at implementing it. The latter is slowly happening in >> the Python community. But it's a slow process. >> >> > -- > OK let me talk in specifics instead of abstractions. > > Lets take a GUI. Consider something like wxGlade or XRCed which > generates a XML resource file and then wxPython works from it. > > Suppose the python community works on defining a standard XML resource file. > > Then all wrappers for GUI libraries in Python can optionally support > this XML resource file. > > So if you are unfortunate enough to have to develop GUI applications > :-) you use the standard XML resource file and pick the wrapper and > the toolkit that you like. > > Then for some reason - you have to switch wrapper or toolkit - you > dont have a major crisis, you only have a minor crisis. ;-) > > Of course the wrappers and toolkits are free to provide additional > functionality which the developers using those toolkits may or may not > choose to use. > > I think this is what has happened with the DBAPI 2.0 for e.g. > kinterbasdb provides DBAPI 2.0 compliant methods for access to > firebird and also other non-standard methods. This is a GOOD THING and > my suggestion is that this GOOD THING must propogate into other areas > like GUI and the Web Toolkits. Good idea. Are you willing to write the standard, and at least one GUI toolkit implementation to show that it's workable? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From benji at zope.com Wed Aug 3 09:11:45 2005 From: benji at zope.com (Benji York) Date: Wed, 03 Aug 2005 09:11:45 -0400 Subject: Parallel port programming on windows XP/2000? In-Reply-To: References: Message-ID: <42F0C291.5060809@zope.com> Novice Experl wrote: > I'd like to write a simple application that interfaces with the parallel port Use pyParallel. You don't have to worry about the Java stuff unless you're using Jython. Just follow the instructions on the page (download, unarchive, python setup.py install). After that you have to understand how the parallel port works, but I'll assume you already do or can use the web to figure it out. -- Benji York From dmqatpobox.com Sat Aug 27 04:21:36 2005 From: dmqatpobox.com (David MacQuigg) Date: Sat, 27 Aug 2005 01:21:36 -0700 Subject: Newbie question: Sub-interpreters for CAD program References: <1124916493.902896.128340@g14g2000cwa.googlegroups.com> Message-ID: On 24 Aug 2005 13:48:13 -0700, "sonicSpammersGoToHellSmooth" wrote: >Hi all, > >I'm a newbie to Python, so I have a question about writing an >application that also has a scripting ability. I'm thinking of Eric3 >as an example. It's written in Python, but it also has an interpreter >window. The user doesn't have access (I don't think...) to all the >internal stuff that makes the IDE work. > >In my case I'd like to write a CAD program which allows the user to >write Python scripts, and to provide an API to do CAD stuff, manipulate >parameters, circuits, layouts, simulations, etc. The user should not >have access to the internals of the CAD program itself. The CAD >program is written primarily in Python, with possibly C++ extensions >for speed critical stuff. > >There is another posting currently asking about how many interpreters >are needed with how many thread states each. Since this is new to me, >can someone please explain how this sort of thing is "supposed" to >work, from a high level? > >I have a strong EE and hardware background (hence my need to write a >CAD program that doesn't piss me off), but not a CS background. Sounds like we have similar backgrounds and motivations. I have a project started along these lines, but I haven't had time to work on it for the last few months. http://www.ece.arizona.edu/~edatools/ Project page EDA Tools Projects: An Open-Source Platform for Front-End IC Design cdp_tut01-a1.zip cdp_tut01-a1.tar.gz The goal of this project is an easily-learned, universal, open-source, circuit design platform that will allow IC designers to use whatever tools they want for design entry, simulation, and display of results. The platform should provide a simple GUI, basic services such as storage of tool setups, and should define a simple, standard interface for each class of tool. Most of the work will be in documenting the design and construction of the platform, using a simple scripting language ( Python ) and GUI toolkit ( Qt ) so that others may easily follow the pattern and extend the platform to support new and more varied tools. ------ Take a look also at the MyHDL link from the main page. This is a similar effort for digital design. Mine is mostly analog. The discouraging thing about the EDA tools situation is that no matter how loudly design engineers complain about the poor quality of the proprietary tools they are using, there is very little interest in participating in an open-source project. They just can't see how it would ever do what their expensive tools do now. There is a similar lack of interest in the academic community. None of this is likely to lead to publications in scholarly journals. -- Dave From sybrenUSE at YOURthirdtower.com.imagination Fri Aug 26 07:05:15 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Fri, 26 Aug 2005 13:05:15 +0200 Subject: ideas for university project ?? References: Message-ID: Jon Hewer enlightened us with: > Areas of interested include AI, distributed systems. Most of all i > want something that is interesting, and actually useful (thats > probably stating the obvious!) You could help developing Dynamite (contact Dick van Albada from the University of Amsterdam for that), perhaps extend it to work with Python. It's a system to do process migration from node to node in a really nice way. Once a program is compiled with Dynamite, you can send it a signal and it'll write it's current state into a new ELF binary. You can then move that binary to another node in your distributed system, and execute it as any other executable. The program will continue to run from where it left off. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From steven.bethard at gmail.com Thu Aug 11 15:35:34 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 11 Aug 2005 13:35:34 -0600 Subject: Bug in slice type In-Reply-To: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> References: <2zoKe.2584$Z87.907@newssvr14.news.prodigy.com> Message-ID: Bryan Olson wrote: > > class BuggerAll: > > def __init__(self, somelist): > self.sequence = somelist[:] > > def __getitem__(self, key): > if isinstance(key, slice): > start, stop, step = key.indices(len(self.sequence)) > # print 'Slice says start, stop, step are:', start, > stop, step > return self.sequence[start : stop : step] > > > print range(10) [None : None : -2] > print BuggerAll(range(10))[None : None : -2] > > The above prints: > > [9, 7, 5, 3, 1] > [] > > Un-commenting the print statement in __getitem__ shows: > > Slice says start, stop, step are: 9 -1 -2 > > The slice object seems to think that -1 is a valid exclusive > bound, but when using it to actually slice, Python interprets > negative numbers as an offset from the high end of the sequence. > > Good start-stop-step values are (9, None, -2), or (9, -11, -2), > or (-1, -11, -2). The later two have the advantage of being > consistend with the documented behavior of returning three > integers. I suspect there's a reason that it's done this way, but I agree with you that this seems strange. Have you filed a bug report on Sourceforge? BTW, a simpler example of the same phenomenon is: py> range(10)[slice(None, None, -2)] [9, 7, 5, 3, 1] py> slice(None, None, -2).indices(10) (9, -1, -2) py> range(10)[9:-1:-2] [] STeVe From theller at python.net Thu Aug 4 09:46:58 2005 From: theller at python.net (Thomas Heller) Date: Thu, 04 Aug 2005 15:46:58 +0200 Subject: Metaclasses and class variables References: Message-ID: Jan-Ole Esleben writes: > Hi! > > I am new to this list, and maybe this is a stupid question, but I > can't seem to find _any_ kind of answer anywhere. > > What I want to do is the following: > I want to insert a class variable into a class upon definition and > actually use it during definition. > > Manually, that is possible, e.g.: > > class A: > classvar = [] > classvar.append(1) > classvar.append(2) > > I don't want to explicitly set the variable, though. My idea was to > write the following: > > class Meta(type): > def __new__(cls, name, bases, d): > d['classvar'] = [] > return type.__new__(cls, name, bases, d) > > class Test: > __metaclass__ = Meta > > classvar.append(1) > classvar.append(2) > > However, Python complains that the variable isn't defined; it can be > found in the class dictionary _after_ definition, though, and then it > can also be used. But where's the conceptual difference (to the manual > approach)? classvar is defined AFTER the class has been created. So, this should work: class Test: __metaclass__ = Meta Test.classvar.append(1) Thomas From newsuser at stacom-software.de Wed Aug 3 10:07:36 2005 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Wed, 03 Aug 2005 16:07:36 +0200 Subject: COM makepy problem Message-ID: Hello together, My system: ActivePython 2.4.1 Windows XP I write a COM Server in VC++ 6.0 using ATL. So far so good. While I develop I got sometimes strange behaviour with makepy utility. Today again. :-( What I do on the python (COM client) side. 1) Register COM server 2) Use COM makepy utility 3) Create com client object using win32com.client.Dispatch(...) The generated file in c:\python24\lib\site-packages\win32com\gen_py\{...}\I.py seem not work corectly. From the traceback, when i do myObj = win32com.client.Dispatch("") ---------------------------------------------- [...] __import__("win32com.gen_py." + dir_name + "." + child) File "c:\Python24\lib\site-packages\win32com\gen_py\D0BC1B38-B4AC-480A-86B0-81 DA572765CDx0x1x0\IDssInterface.py", line 125 IDssInterface_vtables_ = [dispatch_ = 1 ^ SyntaxError: invalid syntax file IDssInterface.py (starting at line 123) -------------------------------------------- [...] LCID = 0x0 IDssInterface_vtables_dispatch_ = 1 IDssInterface_vtables_ = [ [...] Now I change the file IDssInterface.py by hand to: -------------------------------------------------- [...] LCID = 0x0 IDssInterface_vtables_dispatch_ = 1 IDssInterface_vtables_ = [ [...] and everything works fine !!! Does anybody have a suggestion/idea/hint on that ??? Regards Alexander From kalyan.abbaraju at gmail.com Sun Aug 14 09:30:37 2005 From: kalyan.abbaraju at gmail.com (kalyan.abbaraju at gmail.com) Date: 14 Aug 2005 06:30:37 -0700 Subject: help with TixComboBox usage in python Message-ID: <1124026237.854748.235470@g43g2000cwa.googlegroups.com> Hi, I have to write a code in which based on a user selection in a combo box, pages in NoteBook should be automatically added or deleted. So, I have the following class. class myActionsDialog: def __init__ (self, top): self.ActionsWidget = dict() self.sd=None self.ActionsWidget['Label'] = Label (text="My Actions") top.configure(labelwidget=self.ActionsWidget['Label']) self.actionChoice=Tix.StringVar() self.ActionsWidget['Choice'] = Tix.ComboBox(top, label="Pre-defined Actions: ", dropdown=1, command=self.select_action, editable=1, variable=self.actionChoice, options='listbox.height 6 label.width 20 label.anchor e') self.ActionsWidget['Choice'].configure(command=self.select_action) self.ActionsWidget['Choice'].grid(row=1, column=0,sticky=NW) self.ActionsWidget['CustomAction']=Frame(top) self.ActionsWidget['CustomAction'].grid(row=2, column=0,sticky=NW+SE) self.ActionsWidget['CustomAction'].configure(borderwidth=1,highlightthickness=1, highlightcolor="blue", relief=GROOVE) self.ActionsWidget['NoteBook'] = Tix.NoteBook(self.ActionsWidget['CustomAction']) self.ActionsWidget['NoteBook'].grid(row=0, column=0,sticky=NW+SE) self.ActionsWidget['NoteBook'].configure(height=400, width=600) self.ActionsWidget['NBFrame'] = self.ActionsWidget['NoteBook'].subwidget_list["nbframe"] self.ActionsWidget['NBFrame'].configure(relief="raised", tabpadx="8") self.ANbook = self.ActionsWidget['NoteBook'] def add_Actions(self, toptions): """Usage: options = {'text':'Plain Text', 'html':'Plain Html'} add_Actions(options)""" print "add_Actions=", toptions for eachOpt in toptions: print eachOpt self.ActionsWidget['Choice'].insert(Tix.END, eachOpt) def add_page (self, name, text, mark): print "add_page=", name, text, mark self.ANbook.add(name, label=text, underline=mark, anchor="center") def delete_page (self, name): print "delete_page=", name self.ANbook.delete(name) def select_action(self,event): print "myActionsDialog::select_action=", self.actionChoice.get(), ";" print "select_action=", event, ";" if self.sd != None: print "Deleting the previous pages..." self.sd.del_pages() if self.actionChoice.get() == 'Send Events': print "Found Send Events" self.sd=mySendAlarmDialog(self) elif self.actionChoice.get() == 'Alarm Upload': print "Found Alarm Upload" print "Seems alarm Upload is found" self.sd=None But my problem is select_action is not executing when ever user changes his selection. my Current widget layout is something like this now. -------------------------------------------------- | pre-defined Actions: | --------------------------------------------------- | Tix.NoteBook | --------------------------------------------------- Tix.NoteBook pages should be changed dynamically based on the user selection in So, I have a doubt where this really works? or should I have to add a new buttion called "Update NoteBook" and whenever user clicks this button then the Notebook wiget changes. Question New UI: --------------------------------------------------------------------------- | pre-defined Actions: | Update NoteBook | --------------------------------------------------------------------------- | Tix.NoteBook | --------------------------------------------------------------------------- or please let me know if we have any better widgets to handle this behaviour. Thanks in advance Regards Kalyan From borges2003xx at yahoo.it Thu Aug 4 03:23:51 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 4 Aug 2005 00:23:51 -0700 Subject: substring and regular expression Message-ID: <1123140231.118099.4890@g43g2000cwa.googlegroups.com> i have read finding sublist http://groups.google.it/group/comp.lang.python/browse_thread/thread/50b09a0aca285256/5156ada81fc9358a?hl=it#5156ada81fc9358a the problem was in a string to find if we have two substring non overlapping of lenght al least 4 it was done by r=re.compile(r'(?P.{4,}).*(?P=seq)') my knowhow on re is null there is a way in re for ask if a substring is the reverse of the otherone? First seq is second seq in reverse order i appreciate all persons that can help me. excuse my ignorance From smitty_one_each at bigfoot.com Tue Aug 23 19:03:04 2005 From: smitty_one_each at bigfoot.com (Chris Smith) Date: Tue, 23 Aug 2005 19:03:04 -0400 Subject: The ONLY thing that prevents me from using Python References: <1123248107.576277.319410@g44g2000cwa.googlegroups.com> Message-ID: <8764tw8def.fsf@bigfoot.com> >>>>> "Kevin" == Kevin <816168 at gmail.com> writes: Kevin> I have been using java (jsp/servlets), vb/asp and perl for Kevin> a few years. Almost all my projects are web site Kevin> development related, and many of my clients' web sites are Kevin> hosted on those shared web hosting services. Kevin> The problem is that it's difficult to find hosting services Kevin> with Python installed and supported. And most hosting Kevin> companies are reluctant to install it for you because they Kevin> don't want to do the extra work(they would always say to Kevin> me, why don't you use php or java or asp or per?). I have Kevin> searched and found some companies that support Python. But Kevin> still there are far few choices than other options. Kevin> I am sure this issue has already been raised a billion Kevin> times. I just feel very frustrated on this. I want to learn Kevin> and use Python in my web projects. Kevin> One day in last December I decided to learn Python, because Kevin> of Bruce Eckel's recommendation on his web site (I started Kevin> java with his book). After writing a few scripts (each Kevin> with a hundred lines or less), I really liked Python, even Kevin> though at first to me, it has a very different style and Kevin> mindset from my accustomed java approach. I enjoyed the Kevin> experience and was ready to delve into the OO and other Kevin> aspect of Python. Kevin> But because of the hosting issue, I stopped and since then Kevin> have spent more time on php, and it seems that I would soon Kevin> become a full time PHPer now. Kevin> I really wish Python could be more widely available on web Kevin> server machines. This is just my own experience and I would Kevin> like to hear your comments. Not to be a shill, but I'd be interested in testimonials on http://linode.org/ I wonder if virtualization is the next killer app. Certainly blows the WTF my ISP? question away... -Chris From yux at sdf-eu.org Tue Aug 23 11:22:00 2005 From: yux at sdf-eu.org (Jonas Geiregat) Date: Tue, 23 Aug 2005 15:22:00 +0000 Subject: gtkmozembed in fedora core 3 In-Reply-To: <4TAOe.90515$vj.4835@pd7tw1no> References: <4TAOe.90515$vj.4835@pd7tw1no> Message-ID: <430b22ae$0$6564$ba620e4c@news.skynet.be> Martin DeMello wrote: > Could someone help me get gtkmozembed working under fc3? The only > available rpms need gnome-python2 >= 2.9 and fc3 ships with 2.6. I can't > find any fc3 rpms to upgrade gnome-python2 and I can't quite figure out > what I'd need to compile just to install gtkmozembed and the python > bindings (I need to deploy this at work, so I'm trying to make the > minimal possible change to a stock fc3 install). Upgrading to fc4 is > sadly not an option :-/ > > martin > If you can't find any rpm's there aren't any available. You need to compile mozilla with (I think) support for gtkmozembed but I guess that's done by default when you compile mozilla with ac_add_options --enable-default-toolkit=gtk2 in your mozconfig file. Check /usr/lib/mozilla for libgtkembedmoz.so if it's not there you'll have to rebuild your mozilla/firefox rpm , again I think, these are just some random tips .. Good luck! From nospam at nospam.nospam Sat Aug 13 14:54:49 2005 From: nospam at nospam.nospam (Steve Jorgensen) Date: Sat, 13 Aug 2005 11:54:49 -0700 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <7r0rf1p2ov2d6dpjqcomq5mn683962cc6f@4ax.com> Message-ID: On Sat, 13 Aug 2005 11:04:55 +0400, wrote: >On Fri, 12 Aug 2005 22:25:07 -0700 >Steve Jorgensen wrote: > >> Since Python does not use manifest typing, there's not much you can do about >> this, but typeless languages like this are great if you're using a process >> that finds the errors the compiler would otherwise find. I'm referring, of >> course, to Test Driven Development (TDD). >> >> If you do TDD, you won't miss compile-time checking much. In fact, the extra >> kruft that manifest typing requires is an annoying burden when doing TDD, so >> Python is a breath of fresh air in this regard. > >What test should one implement to catch that kind of errors like in OP >example? > >> On 10 Aug 2005 08:53:15 -0700, "Qopit" wrote: >> >> >#---- >> >def tester(a,b,c): >> > print "bogus test function",a,b,c >> >tester(1,2,3) #this runs fine >> >tester(1,2) #this obviously causes a run-time TypeError exception >> >#---- None - other tests you would write would fail if other code in your system is trying to call a procedure with the wrong number of parameters. From hancock at anansispaceworks.com Wed Aug 31 18:21:33 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 31 Aug 2005 17:21:33 -0500 Subject: What are new-style classes? In-Reply-To: <3nm6quF26e60U1@individual.net> References: <1125222465.061149.128650@g14g2000cwa.googlegroups.com> <3nm6quF26e60U1@individual.net> Message-ID: <200508311721.33176.hancock@anansispaceworks.com> On Wednesday 31 August 2005 12:14 pm, Reinhold Birkenfeld wrote: > Steve Holden wrote: > > Reinhold Birkenfeld wrote: > >>>>My comment mostly referred to "new-style classes must be declared as a subclass of > >>>>a new-style class", which is not true. > >>> > >>>Nonsense. > >> > >> Given the rest of your post, I assume that this isn't meant as it sounds. Remember, I'm > >> German, so please bear with my sense of humour. ;) Yes, it was tongue-in-cheek. However, there *was* some truth in what I said: Python *does* indicate implementation details with the "ignore the man behind the curtain" approach of marking them with "_" or "__". Yes, that is the only kind of encapsulation Python really gives you -- you have to play by the rules if you want those advantages, and one of the rules is to pretend you don't see those magic methods. Except when you really, really need to, of course. Also, we have to remember that this was a *newbie* question, so I gave a newbie-approved answer -- I told the "right" way to do it. And of course, there is something slightly comical about this. But you should expect that from a language named after a comedy troupe, shouldn't you? The fact that I did this because I didn't know about the other way is totally unimportant! :-P You are such a rude man for displaying your intellectual superiority like that. Fie! Actually, I was thinking seriously about trying to use the exact wording of Douglas Adams from "Hitchhiker's" (approx): "We have normality, therefore anything you still can't cope with is your own problem". But it didn't quite fit, and the other possible reference to the "Son of the Invisible Man" skit*, was just way too obscure. I doubt you've ever seen it. *I think this was in "Amazon Women on the Moon", though it may have been "Kentucky Fried Movie". Both are TV spoofs. And, yes, of course, I'm glad you posted about this detail, I learned something from it, which is why I read this list. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From nospam at here.com Mon Aug 15 09:47:21 2005 From: nospam at here.com (Matt Feinstein) Date: Mon, 15 Aug 2005 09:47:21 -0400 Subject: Gotchas in user-space matplotlib install? References: <626hf1lp7k492cbcq4o1mqhe3hnaqpbhf5@4ax.com> <87d5okurgh.fsf@peds-pc311.bsd.uchicago.edu> Message-ID: <5f51g1hm6ajl5v0qnrqu1635nldjbvqp2g@4ax.com> >If you do a --prefix=~/usr for all 'configure' and 'python setup.py >install' commands, and set your PATH, C_INCLUDE_PATH, >CPLUS_INCLUDE_PATH, LIBRARY_PATH, and LD_LIBRARY_PATH variables >accordingly, and set the MATPLOTLIBDATA environment variable to point >to ~/usr/share/matplotlib, it should work. > >When debugging your setup, you might want to run your test >matplotlib/pylab script with > > > python myscript.py --verbose-helpful > >OR > > > python myscript.py --verbose-debug > >to get extra information about where matplotlib is looking for things. For the record, I persuaded the sysadmin to install current levels of the tcl, tcl-devel, tk, and tk-devel libraries-- my argument was that you couldn't get a useful installation of Python without them. Since I used /usr/people/mrf/python24 for my home Python directory, there were a few tweaks needed to get the matplotlib installer to find stuff. To get access to the freetype and Numeric libraries and what-have-you, adding /usr/people/mrf/python24/lib/python2.4 and /usr/people/mrf/Numeric-23.8 to the basedir dictionary in setext.py seemed to work. In addition, I think I had to copy the Numeric include directory into an additional location. There was also a little fiddling with PYTHONPATH to insure that the installer found both numarray and Numeric. Didn't seem to need MATPLOTLIBDATA, but that would have been my next try. With a working version of Tcl/Tk, the need for other widget sets became somewhat academic. For GTK, Fedora Core 1 is apparently so far behind current levels of GTK that it is pointless to complain. Wx is still a possibility. All in all, not actually excruciating-- and now I have a working version of matplotlib! Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From pink at odahoda.de Sat Aug 13 16:18:35 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Sat, 13 Aug 2005 22:18:35 +0200 Subject: "Compile time" checking? References: <1123689195.840622.158870@z14g2000cwz.googlegroups.com> <7r0rf1p2ov2d6dpjqcomq5mn683962cc6f@4ax.com> Message-ID: en.karpachov at ospaz.ru wrote: > On Fri, 12 Aug 2005 22:25:07 -0700 > Steve Jorgensen wrote: > >> Since Python does not use manifest typing, there's not much you can do >> about this, but typeless languages like this are great if you're using a >> process >> that finds the errors the compiler would otherwise find. I'm referring, >> of course, to Test Driven Development (TDD). >> >> If you do TDD, you won't miss compile-time checking much. In fact, the >> extra kruft that manifest typing requires is an annoying burden when >> doing TDD, so Python is a breath of fresh air in this regard. > > What test should one implement to catch that kind of errors like in OP > example? A 'good' testsuite should run each line of the code at least once. There's more to do for a good code coverage, but that's the most basic requirement. So the faulty line will be executed by the testsuite and the runtime checking will raise an exception. Static typing is a very rudimentary type of code checking that is performed by the compiler with 100% code coverage. Such test won't tell you, if your code is actually doing what it is supposed to do (or anything sensible at all) and are mostly useless. If you think that code quality is important, you'll have to perform much more and more sophisticated tests. Such a testsuite is usually (I can't think of cases where it is not) a superset of static code checking - all type bugs are found be the testsuite even in the absence if static type checking. So you won't loose anything, if you drop static typing. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From fred.dixon at gmail.com Tue Aug 23 20:26:07 2005 From: fred.dixon at gmail.com (fred.dixon) Date: 23 Aug 2005 17:26:07 -0700 Subject: Lightweight Python distribute it in under 2MBs for Win32 In-Reply-To: <7tednYxNzPYfQJ7eRVn-iA@comcast.com> References: <1123888740.907184.38670@f14g2000cwb.googlegroups.com> <7tednYxNzPYfQJ7eRVn-iA@comcast.com> Message-ID: <1124843167.323608.247030@g47g2000cwa.googlegroups.com> long delay on reply due to pc death. i made a simple gui that picked paragraphs from a file with wxpython. using py2exe i bundled the program then packaged it with INNO install. it was 3megs. now its about 4 megs after a revision. I give you the source if you want. it uses python 241 and the latest wxpython From mwm at mired.org Tue Aug 2 00:18:52 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 02 Aug 2005 00:18:52 -0400 Subject: Wheel-reinvention with Python References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <42EA1B75.9040307@tiscali.it> <873bpxsivs.fsf_-_@wilson.rwth-aachen.de> <87mzo4zsu4.fsf@wilson.rwth-aachen.de> <86wtn7h8pl.fsf@bhuda.mired.org> <87ek9fr0c3.fsf@wilson.rwth-aachen.de> <86ack2hkol.fsf@bhuda.mired.org> <87mzo2zm9e.fsf@wilson.rwth-aachen.de> Message-ID: <868xzleztf.fsf@bhuda.mired.org> Torsten Bronger writes: > Hall??chen! > Mike Meyer writes: >> Torsten Bronger writes: >>> [...] >>> >>> None of us has talked about changing syntax. However, the >>> standard library is part of the language unless you're really >>> very petty. >> >> Or you use different Python implementations. There are four >> different Python implementations in the world. Not everything in >> the CPYthon standard library runs in all of them. Or are you going >> to claim that someone usin Jython isn't using Python because they >> can't use the full standard library? > > Well, in a way, they aren't using Python indeed. For example, most > Python books tell only partly the truth in this case. Well, in a way, you're right. On the other hand, Guido has always insisted that CPython is just an implementation, and not a definition. >>>>> This is not a sign of decadence, but a very good promotional >>>>> argument. >>>> But it's not required for the language to succeed. >>> Today it is (except for very special-purpose languages). >> To put this differently, it's required if you want to succeed as a >> language for the specific purpose of creating GUI >> applications. I'd agree to that. But there are *lots* of other >> application areas around, so limiting your definition of "success" >> to that one field is very short-sighted. > You have to take into account not only the number of application > areas, but also their respective importance. True. To you, GUI applications are very important. To me, they pretty much don't matter at all. > I'm interested in a language with a big community. This is my > definition of success. It has to do with the functionality I can > expect (more contributors can create more modules and documentation) > and with future-proofness. > > GUI applications seem to be the most attractive application type. > This is not only true for commercial programming. When I look at > the most agile projects on Sourceforge, almost all of them have a > GUI. Why restrict yourself to agile projects? For that matter, how do you decide if a project is agile or not? I won't argue that most of the projects on Sourceforge have GUIs - that's certainly true. I will argue that most of the projects are done in languages that aren't what you call GUI-aware. > Therefore, GUI-aware languages attract much larger user bases, and > so they cater my definition of being successful. Since you haven't stated what that definition is, I can't really say anything about this. If you're counting applications on sourceforge, the evidence doesn't support your conclusion. C and C++ are the most used languages by an order of magnitude, and neither of those has integral GUI support. >> [...] By which measure C is still immensely popular, because of >> the large number of older applications that are written in it that >> are available - Python being one such. > Legacy code is not a sign of success IMO because it implies a > difficult future. So you're saying that Python, Perl, Linux, the various BSD et. al. will have a difficult future? If you believe that about Python, then why are you here at all? >> [...] I'd say Python has succeeded as a web development language, >> and as a systems scripting language - and I've certainly missed >> some. > I don't think that Python should rely on these old strongholds. In > the biggest bookstore of our region, there is one book about Zope > but a whole bookself about PHP. And I've never used consciously a > Python system script in contrast to dozens of Perl scripts. Um - you should compare apples to apples. Zope is an application development framework, and doesn't really compete in the same space as PHP and Python. For that matter, as you note, PHP is a special-purpose language (for a very popular application area) whereas Python is general purpose language. As for system scripts, Python is the primary system scripting tool for a number of Linux distributions (gentoo and redhat come to mind), and if I understand correctly, it's also used pretty heavily in OS X. > In contrast to PHP or Perl, I consider Python a general-purpose > language. There is its future in my opinion. However, this area is > much tougher, and you need a good GUI approach there. I know a large number of people who'd argue with you implying that Perl isn't a general-purpose language. It's more successful than Python pretty much across teh board. >>>> [...] Could it be that that's what you really want - someone to >>>> distribute Python bundled with an enterprise-class GUI library >>>> and IDE? >>> >>> Well, a nice thing to have, but besides my point. >> >> Then you seem to have missed some of your own points. C++ >> succeeded without having a standard GUI library. You claimed that >> that success was because of a single distribution that included >> the things you are looking for. Why can't the same thing work for >> Python? > > I just didn't say that it couldn't work. But I don't think it'll > happen, that's all. Well, if you dismiss it out of hand, it certainly won't happen. Try asking ActiveState (they seem to be the major alternative distribution of CPython) to consider it, rather than trying to get it into the www.python.org distribution of CPython. Or maybe you could switch to Jython, and just use swing? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From rkern at ucsd.edu Mon Aug 22 21:53:24 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 22 Aug 2005 18:53:24 -0700 Subject: while c = f.read(1) In-Reply-To: <87fyt1mods.fsf@peds-pc311.bsd.uchicago.edu> References: <1124428913.678180.66980@o13g2000cwo.googlegroups.com> <1124702804.589011.257970@o13g2000cwo.googlegroups.com> <87fyt1mods.fsf@peds-pc311.bsd.uchicago.edu> Message-ID: John Hunter wrote: >>>>>>"Robert" == Robert Kern writes: > > Robert> Greg McIntyre wrote: > >> The 2nd option has real potential for me. Although the total > >> amount of code is greater, it factors out some complexity away > >> from the actual job, so that code is not obscured by > >> unnecessary compexity. IMHO that's great practice. > > Robert> Please quote the message you are replying to. We have no > Robert> idea what "the 2nd option" is. > > I think he means the second option you presented > > If you must read one character at a time, > > def reader(fileobj, blocksize=1): > """Return an iterator that reads blocks of a given size from a > file object until EOF. > ...snip > > With a decent threaded news/mail reader, the thread provides > sufficient context, no? Not taking into account the python-list gateway or GMane. I see his message threaded directly under his original one. And dammit, I'm vain enough that if people are complimenting my code, I want to be sure about it. ;-) -- 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 alessandro.bottoni at infinito.it Thu Aug 18 03:02:08 2005 From: alessandro.bottoni at infinito.it (Alessandro Bottoni) Date: Thu, 18 Aug 2005 07:02:08 GMT Subject: up to date books? References: Message-ID: John Salerno wrote: > hi all. are there any recommendations for an intro book to python that > is up-to-date for the latest version? I do not know how much up-to-date they are but I have to suggest you these books: - Learning Python By Mark Lutz and David Ascher published by O'Reilly Most likely the best introductory book on Python - Python Cookbook By Alex Martelli and David Ascher published by O'Reilly By far the most useful book on Python after your first week of real use of this language Also, the fundamental - Programming Python (the 2nd edition ONLY) By Mark Lutz published by O'Reilly Is very useful for understanding the most inner details of Python > would reading a book from a year or two ago cause me to miss much? No. Python did not changed too much since rel. 1.5. You can still use a book published in 2001 as a introductory book (as I do). The changes are exhaustively described both in the official documentation and in the very fine "what's new in..." articles written by Andrew Kuchlin for every new release (see www.python.org). CU ----------------------------------- Alessandro Bottoni From lbates at syscononline.com Fri Aug 12 10:10:05 2005 From: lbates at syscononline.com (Larry Bates) Date: Fri, 12 Aug 2005 09:10:05 -0500 Subject: Printing to printer In-Reply-To: References: Message-ID: <42FCADBD.4080801@syscononline.com> I adapted some code from David Boddie into a Python class to write directly to Linux print queues. I have used it in one project and it worked just fine. I've attached a copy for your use. You are free to use it as you wish, with no guarantees or warranties. Hope it helps. Larry Bates Steve M wrote: > Hello, > > I'm having problems sending information from a python > script to a printer. I was wondering if someone might send me > in the right direction. I wasn't able to find much by Google > > TIA > Steve -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: lprClass.py URL: From jack at performancedrivers.com Thu Aug 25 13:20:40 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Thu, 25 Aug 2005 13:20:40 -0400 Subject: Speed quirk: redundant line gives six-fold speedup In-Reply-To: References: Message-ID: <20050825172040.GB5991@performancedrivers.com> On Thu, Aug 25, 2005 at 04:44:24PM +0000, Mark Dickinson wrote: > I have a simple 192-line Python script that begins with the line: > > dummy0 = 47 > > The script runs in less than 2.5 seconds. The variable dummy0 is never > referenced again, directly or indirectly, by the rest of the script. > > Here's the surprise: if I remove or comment out this first line, the > script takes more than 15 seconds to run. So it appears that adding a > redundant line produces a spectacular six-fold increase in speed! > > (Actually, I had to add 29 dummy lines at the beginning of the code to > get the speed increase; if any one of these lines is removed the > running time reverts to around 15 seconds again.) > > Questions: > > (1) Can anyone else reproduce this behaviour, or is it just some quirk > of my setup? I get the same thing. > (2) Any possible explanations? Is there some optimization that kicks > in at a certain number of lines, or at a certain length of > bytecode? It seems to be related to the number of globals. I get the "fast" version with 30 to 120 globals and the "slow" version with less than 30 or more than 130. It actually gets even slower for higher numbers of globals. Here is a snippet to adjust the number of globals for (i) in range(100): globals()['dummy%d' % (i)] = 1 > (3) If (2), is there some way to force the optimization, so that I can > get the speed increase without having to add the extra lines? Yes, module level globals have bad lookup times compared to function local names. If you refactor your code to pass around the data currently at the global module level you should see times at least as fast as the current 'fast' one. That said, I'm very surprised that the lookup times jump around so much. Your code does bazillions of namespace lookups, so a small difference in lookup times is getting multiplied into some really big numbers. -jackdied From franz.steinhaeusler at gmx.at Mon Aug 1 12:00:42 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Mon, 01 Aug 2005 18:00:42 +0200 Subject: Getting not derived members of a class References: Message-ID: On Mon, 1 Aug 2005 10:24:53 -0500, Jeff Epler wrote: >On 'y', Python has no way of recording where '_a' and '_b' were set, so >you can't tell whether it comes from class 'a' or 'b'. > >You can find the attributes that are defined on 'b' only, though, by >using 'b.__dict__.keys()', or 'y.__class__.__dict__.__keys__()'. This >gives > ['__module__', 'who1', '__init__', '__doc__'] > >If you want to limit yourself to current versions of cpython (because the >bytecode used in cpython is only an implementation detail) and define a 'member >of class a' as one where a.__init__ has a statement like 'self.z = ...', you >can peer into the bytecodes. Something like this: > from dis import HAVE_ARGUMENT, opname > LOAD_FAST = chr(opname.index('LOAD_FAST')) > STORE_ATTR = chr(opname.index('STORE_ATTR')) > HAVE_ARGUMENT = chr(HAVE_ARGUMENT) > > def find(cls): > ns = cls.__dict__ > result = ns.keys() > init = ns.get('__init__', None) > if not init: return ns > f = ns['__init__'].func_code.co_code > n = ns['__init__'].func_code.co_names > i = 0 > while i < len(f) - 6: > if (f[i] == LOAD_FAST and f[i+1] == f[i+2] == '\0' > and f[i+3] == STORE_ATTR): > j = ord(f[i+4]) + 256 * ord(f[i+5]) > result.append(n[j]) > i += 6 > elif f[i] > HAVE_ARGUMENT: > i += 3 > else: > i += 1 > return result > >>>> import franz >>>> franz.find(y.__class__) >['__module__', 'who1', '__init__', '__doc__', '_b'] > >Jeff Hello Jeff, thank you for this desciption. Well, a little complicated, I must read/try this later, but it looks promising to get the "last derived class" members ;) Is there any possibility to simply get out the classes and baseclasses of a class? somfunc (y) => class A, B (where B is last). Ok you can prepare a class, but I need to use the existing wxPython classes. -- Franz Steinhaeusler From nothingcanfulfill at gmail.com Thu Aug 18 02:34:51 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 17 Aug 2005 23:34:51 -0700 Subject: Tkinter and gnuplot module In-Reply-To: References: Message-ID: <1124346891.146367.244790@z14g2000cwz.googlegroups.com> Because Tkinter is for GUI development on systems, and thereof, there is no plugin for browsers, I do not believe it to be possible to use Tkinter in a client's browser. If gnuplot.py allows you to save a plot to disk or get the plot's image file as a binary string, it should be possible to send a plot to a client's web browser. HTH, -Wes From thanos at sians.org Sat Aug 13 20:12:36 2005 From: thanos at sians.org (Thanos Tsouanas) Date: Sun, 14 Aug 2005 03:12:36 +0300 Subject: Changing data of xhtml document Message-ID: <20050814001236.GA16614@zermelo.sians.org> Hello list! I've got a unicode string which holds an xhtml website, begining with tag. Also, it writes the tag which I want to avoid at this stage. Are there any really easy solutions to this problem? Any modules that could be helpful for slight modification of such sgmlish files? The downside of SGMLParser is that I have to override all parser functions to actually leave everything intact instead of doing nothing and override characters(data) to print the altered data. Thanks in advance! -- Thanos Tsouanas .: My Music: http://www.thanostsouanas.com/ http://thanos.sians.org/ .: Sians Music: http://www.sians.org/ From steven.bethard at gmail.com Thu Aug 11 19:49:26 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 11 Aug 2005 17:49:26 -0600 Subject: performance of recursive generator In-Reply-To: References: <3uqdnVTPRY8yM2bfRVn-pQ@comcast.com> Message-ID: aurora wrote: > This test somehow water down the n^2 issue. The problem is in the depth > of recursion, in this case it is only log(n). It is probably more > interesting to test: > > def gen(n): > if n: > yield n > for i in gen(n-1): > yield i You should be able to do this yourself ;) but here's the results anyway: -------------------- test.py -------------------- def gen(n): if n: yield n for i in gen(n-1): yield i def gen_wrapper(n): return list(gen(n)) def nongen(n, func): if n: func(n) nongen(n-1, func) def nongen_wrapper(n): result = [] nongen(n, result.append) return result ------------------------------------------------- D:\steve>python -m timeit -s "import test" "test.gen_wrapper(10)" 10000 loops, best of 3: 22.3 usec per loop D:\steve>python -m timeit -s "import test" "test.nongen_wrapper(10)" 100000 loops, best of 3: 12 usec per loop D:\steve>python -m timeit -s "import test" "test.gen_wrapper(20)" 10000 loops, best of 3: 60.8 usec per loop D:\steve>python -m timeit -s "import test" "test.nongen_wrapper(20)" 10000 loops, best of 3: 20.9 usec per loop D:\steve>python -m timeit -s "import test" "test.gen_wrapper(100)" 1000 loops, best of 3: 1.01 msec per loop D:\steve>python -m timeit -s "import test" "test.nongen_wrapper(100)" 10000 loops, best of 3: 93.3 usec per loop It does appear that you get O(N**2)-ish behavior, but the difference isn't horribly noticeable at a depth of 10 or 20. How deep are your trees? I also have to mention that, for this kind of problem, it's silly to use any recursive solution, when there's a faster non-recursive solution: -------------------- test.py -------------------- ... def nonrecur(n): result = [] append = result.append while n: append(n) n -= 1 return result ------------------------------------------------- D:\steve>python -m timeit -s "import test" "test.nonrecur(10)" 100000 loops, best of 3: 6.26 usec per loop D:\steve>python -m timeit -s "import test" "test.nonrecur(100)" 10000 loops, best of 3: 37.9 usec per loop Sure, this only works on non-branching trees, but if that's what you're worried about, use the solution designed for it. ;) STeVe From fredrik at pythonware.com Wed Aug 17 08:06:41 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 17 Aug 2005 14:06:41 +0200 Subject: Iterparse and ElementTree confusion References: <1124269934.194818.51940@f14g2000cwb.googlegroups.com> Message-ID: paul.sherwood at gmail.com wrote: > def parse_for_products(filename): > > for event, elem in iterparse(filename): > if elem.tag == "Products": > root = ElementTree(elem) > print_all(root) > else: > elem.clear() > > My problem is that if i pass the 'elem' found by iterparse then try to > print all attributes, children and tail text i only get > elem.tag....elem.keys returns nothing as do all of the other previously > useful elementtree methods. > > Am i right in thinking that you can pass an element into ElementTree? > How might i manually iterate through ... grabbing > everything? by default, iterparse only returns "end" events, which means that the iterator will visit the Products children before you see the Products element itself. with the code above, this means that the children will be nuked before you get around to process the parent. depending on how much rubbish you have in the file, you can do for event, elem in iterparse(filename): if elem.tag == "Products": process(elem) elem.clear() or for event, elem in iterparse(filename): if elem.tag == "Products": process(elem) elem.clear() elif elem.tag in ("Rubbish1", "Rubbish2"): elem.clear() or inside = False for event, elem in iterparse(filename, events=("start", "end")): if event == "start": # we've seen the start tag for this element, but not # necessarily the end tag if elem.tag == "Products": inside = True else: # we've seen the end tag if elem.tag == "Products": process(elem) elem.clear() inside = False elif not inside: elem.clear() for more info, see http://effbot.org/zone/element-iterparse.htm From km at mrna.tn.nic.in Thu Aug 25 04:43:55 2005 From: km at mrna.tn.nic.in (km) Date: Thu, 25 Aug 2005 14:13:55 +0530 Subject: loop in python In-Reply-To: <430afc09$0$30445$636a15ce@news.free.fr> References: <20050823065501.GA24558@mrna.tn.nic.in> <430afc09$0$30445$636a15ce@news.free.fr> Message-ID: <20050825084355.GA4712@mrna.tn.nic.in> Hi all, > What you are "comparing" is either IO times (the "print loop" program), > where Perl beats C - which means that Perl's IO have been written at a > very low level instead of relying on the stdlib's IO - i'd like to know what aspects are really coded in very low level for python ? regards, KM From python at rcn.com Mon Aug 15 17:08:39 2005 From: python at rcn.com (Raymond Hettinger) Date: 15 Aug 2005 14:08:39 -0700 Subject: Py_DECREF Question: References: Message-ID: <1124140119.049632.75910@g47g2000cwa.googlegroups.com> [Jeremy Moles] > When I add an object created locally to a mapping or sequence (that will > be returned from a function into an running instance of the Python > interpreter), I need to call Py_DECREF on the object, right? It depends on the the function or macro, but usually the answer is Yes. The C API docs always tell you when a function or macro steals a reference. For instance, the docs for PyList_SET_ITEM specifically mention reference theft. If the docs don't say anything, then it means that the call does not affect the ref count of the function parameters. For instance, the docs for PyList_Append() do not say anything about ref counts: http://docs.python.org/api/listObjects.html This is easy to verify by looking at the source in Objects/listobject.c: int n = PyList_GET_SIZE(self); assert (v != NULL); if (n == INT_MAX) { PyErr_SetString(PyExc_OverflowError, "cannot add more objects to list"); return -1; } if (list_resize(self, n+1) == -1) return -1; Py_INCREF(v); PyList_SET_ITEM(self, n, v); return 0; The presence of the INCREF confirms that PyList_Append does not steal your reference. > Secondly, __and most importantly__, does anyone have any tools and/or > recommendations for detecting memory leaks when writing extension > modules in C? After about two days of coding with the C API, you just get good at reading the code and being able to track when you've added or consumed a reference. That desk checking takes care of 95% of the problems. For the remaining 5%, I run a test suite multiple times in the debug mode, do a gc.collect(), and print sys.gettotalrefcount() after each run. For an example, see the last few lines of Lib/test/test_set.py. If the counts become constant after the first couple of runs, it is a good bet that your extension doesn't leak. Of course, it helps if your test suite is thorough and exercises all code paths. > I'm mostly asking so I can cleanup any craziness in my code before I try > and release pyiw (the Python bindings for Wireless Networking in Linux). > I really want it to be as clean as possible before showing anyone > else. :) I'm sure your users will appreciate the devotion to quality. Raymond From jdhunter at ace.bsd.uchicago.edu Wed Aug 17 20:49:06 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 17 Aug 2005 19:49:06 -0500 Subject: GUI tookit for science and education References: <1124295749.592080.57410@o13g2000cwo.googlegroups.com> Message-ID: <87iry4ysql.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "James" == James Sungjin Kim writes: James> Michele Simionato wrote: >> My vote is for ipython + matplotlib. Very easy and very >> powerful. James> Is it really easier than to use MATLAB(TM)? Do you find matlab easy to use? What aspects are hard or easy? If you provide a little more context, it would be easier to answer your question. JDH From googlenews at tooper.org Thu Aug 11 13:03:04 2005 From: googlenews at tooper.org (googlenews at tooper.org) Date: 11 Aug 2005 10:03:04 -0700 Subject: Writing a small battleship game server in Python References: <200508111746.15668.mail@tuxipuxi.org> Message-ID: <1123779784.423243.25040@g43g2000cwa.googlegroups.com> Why not using directly SOAP ? A minimalistic 'Hello world' client looks like : from SOAPpy import SOAPProxy server= SOAPProxy("http://localhost:8080") print server.Hello("world") and the server side like : from SOAPpy import SOAPServer def Hello(name): print "Wishing "+name+" hello !" return "Hello "+name server= SOAPServer(("localhost",8080)) server.registerFunction(Hello) server.serve_forever() Difficult to make it simpler isn't it ? From k.robert at gmx.de Tue Aug 30 07:42:30 2005 From: k.robert at gmx.de (Robert) Date: Tue, 30 Aug 2005 13:42:30 +0200 Subject: sslerror: (8, 'EOF occurred in violation of protocol') ??? References: Message-ID: "Robert" schrieb im Newsbeitrag news:deug44$1jus$1 at ulysses.news.tiscali.de... > On some connections only from some computers/network setups I get this > error: > > Traceback (most recent call last): > File "", line 1, in ? > File "ClientCookie\_urllib2_support.pyo", line 524, in open > File "ClientCookie\_urllib2_support.pyo", line 424, in http_response > File "ClientCookie\_urllib2_support.pyo", line 541, in error > File "urllib2.pyo", line 306, in _call_chain > File "ClientCookie\_urllib2_support.pyo", line 185, in http_error_302 > File "ClientCookie\_urllib2_support.pyo", line 518, in open > File "urllib2.pyo", line 326, in open > File "urllib2.pyo", line 306, in _call_chain > File "ClientCookie\_urllib2_support.pyo", line 759, in https_open > File "ClientCookie\_urllib2_support.pyo", line 608, in do_open > File "httplib.pyo", line 712, in endheaders > File "httplib.pyo", line 597, in _send_output > File "httplib.pyo", line 564, in send > File "httplib.pyo", line 985, in connect > File "socket.pyo", line 73, in ssl > sslerror: (8, 'EOF occurred in violation of protocol') > In http://groups.google.de/group/comp.lang.python/msg/252b421a7d9ff037 Jp Calderone wrote: On 21 Jun 2005 08:39:02 -0700, Matthias Kluwe wrote: >> From: "Paul Rubin" "http://phr.cx"@NOSPAM.invalid >>> "Matthias Kluwe" writes: >>> After getting a @gmail.com address, I recognized I had to use TLS in my >>> python scripts using smtplib in order to get mail to the smtp.gmail.com >>> server. >>> [...] >>> The server accepts and delivers my messages, but the last command >>> raises >>> socket.sslerror: (8, 'EOF occurred in violation of protocol') >> [...] >> Have you verified that its your end that is broken, not gmail's, do other >> servers give the same response ? >No, I have not -- I should have, as I know now: Connecting, starttls, >login and sending mail works fine without the above mentioned error >using my previous mail provider. >Does that mean Gmail is in error here? I don't know... Most SSL servers and clients (primarily HTTP, but some SMTP as well) are broken in this regard: they do not properly negotiate TLS connection shutdown. This causes one end or the other to notice an SSL protocol error. Most of the time, the only thing left to do after the TLS connection shutdown is normal TCP connection shutdown, so the error doesn't lead to any problems (which is probably why so much software generates this problem). Of course, there's no way to *tell* if this is the case or not, at least programmatically. If you receive an OK response to your DATA, you probably don't need to worry, since you have gotten what you wanted out of the conversation. It's entirely possible that the fault here lies on gmail's end, but it is also possible that the fault is in your code or the standard library ssl support. Unless you want to dive into Python's OpenSSL bindings or start examining network traces of SSL traffic, you probably won't be able to figure out who's to blame in this particular case. The simplest thing to do is probably just capture and discard that particular error (again, assuming you are getting an OK resposne to your DATA command). In fact I saw the same problem with SSL-SMTP and Googles GMAIL. the sslerror can be ignored. But in my case here (HTTPS) the transaction story (redirected https-request) is not yet completed. I don't have the essential data communicated at the moment of the error. What can be done? Robert From no at spam Fri Aug 5 19:32:26 2005 From: no at spam (D H) Date: Fri, 05 Aug 2005 18:32:26 -0500 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: seberino at spawar.navy.mil wrote: > I've heard 2 people complain that word 'global' is confusing. > > Perhaps 'modulescope' or 'module' would be better? > > Am I the first peope to have thought of this and suggested it? > > Is this a candidate for Python 3000 yet? It is likely that more people would find module or modulescope confusing. Plus module has a different customary meaning already: import From pwatson at redlinepy.com Tue Aug 16 14:56:29 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Tue, 16 Aug 2005 13:56:29 -0500 Subject: get the return code when piping something to a python script? In-Reply-To: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> References: <1124214915.991836.316920@o13g2000cwo.googlegroups.com> Message-ID: <430236DD.5040208@redlinepy.com> mhenry1384 wrote: > On WinXP, I am doing this > > nant.exe | python MyFilter.py > > This command always returns 0 (success) because MyFilter.py always > succeeds. > > MyFilter.py looks like this > > while 1: > line = sys.stdin.readline() > if not line: > break > ... > sys.stdout.write(line) > sys.stdout.flush() > > How do I set the return code from MyFilter.py based on the return of > nant.exe? Is this possible? I have googled around for an hour wihtout > success. I understand that I could have MyFilter.py call "nant.exe", > but for various reasons, that's not idea for my situation. As you have heard, it may not be possible to get the exit code from a command line pipe. Of course, even if you could, this code does not yet set an exit code. sys.exit(exitcode) From Uwe.Lauth at cursor.de Wed Aug 31 02:00:20 2005 From: Uwe.Lauth at cursor.de (Uwe Lauth) Date: Wed, 31 Aug 2005 08:00:20 +0200 Subject: dynamicly updating an objects fields In-Reply-To: <1125465620.219693.187500@g47g2000cwa.googlegroups.com> References: <1125465620.219693.187500@g47g2000cwa.googlegroups.com> Message-ID: kyle.tk wrote: > I want to make a function that will work like this: > > def updateField(object, fieldName, newValue): > object.fieldName = newValue This function already exists in python. It is called settattr. Regards Uwe From peter at engcorp.com Sat Aug 6 13:26:55 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 06 Aug 2005 13:26:55 -0400 Subject: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?) In-Reply-To: References: <1123270841.195692.21470@g47g2000cwa.googlegroups.com> Message-ID: Paolino wrote: > seberino at spawar.navy.mil wrote: > def enclosing(): > var=[] > var[0]=2 > def enclosed(): > var[0]=4 > which is like saying python is not working > > It's ok to mark non locals,but why var=4 is not searched outside and > var[0]=4 yes? Because "var=4" rebinds the name "var", while "var[0]=4" does not. It's exactly the same issue with using "global", where you don't need it if you aren't rebinding the name. (Those who don't understand the difference between "rebinding a name" and "modifying an object" will need to figure out that distinction before they can participate much in a discussion about Python scopes, I think.) -Peter From bokr at oz.net Tue Aug 30 16:49:49 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 30 Aug 2005 20:49:49 GMT Subject: Precise timings ? References: <431498f4$0$18638$14726298@news.sunsite.dk> Message-ID: <4314c264.178329924@news.oz.net> On Tue, 30 Aug 2005 13:36:57 -0400, Madhusudan Singh wrote: >Hi > >I am using time.clock() to get the current time of the processor in seconds. >For my application, I need really high resolution but currently seem to be >limited to 0.01 second. Is there a way to specify the resolution (say 1-10 >microseconds) ? My processor is a 1.4 MHz Intel processor. Surely, it ^--G? >should be able to report times a few (or at least 10) microseconds apart. > windows or unix? time.time and time.clock seem to reverse roles as best-resolution time sources depending on which platform. If you have a pentium with a rdtsc instruction, you can write an extension module in c to get at it. In C on a 300mhz p2 I got down to 23ns minimum delta between calls, IIRC. But even then I was subject to the small probability of an interrupt during my timing loop, and there are many normally going on, so the longer the interval you are timing the greater the probability that an interrupt will occur within it (assuming random independence, which is also not necessarily true). This is why timing frameworks generally either average brute force or discard outlier timings and average, or return best-of. All these have different error properties, and depend on lots of stuff. I'm wondering whats your application is. Maybe you need a real-time OS? Regards, Bengt Richter From deets at web.de Wed Aug 17 11:50:00 2005 From: deets at web.de (Diez B. Roggisch) Date: 17 Aug 2005 08:50:00 -0700 Subject: Testing for presence of arguments In-Reply-To: <430353e1$0$18641$14726298@news.sunsite.dk> References: <430353e1$0$18641$14726298@news.sunsite.dk> Message-ID: <1124293800.587084.302130@g43g2000cwa.googlegroups.com> I don't have the details ready - but in the ASPN cookbook are recipes to e.g. figure insied a function f out how many results the caller of f expects - and act accordingly. This boils down to inspect the call-stack. So it ceratinly is possible. However, I'd say it is almost 100% a design flaw. Or can you give us a compelling reason why you need this behaviour? Diez From fred at adventistcare.org Thu Aug 18 13:01:56 2005 From: fred at adventistcare.org (Sells, Fred) Date: Thu, 18 Aug 2005 13:01:56 -0400 Subject: Coin-operated kiosk written in python -- need some help... Message-ID: <777056A4A8F1D21180EF0008C7DF75EE03317587@sunbelt.org> I've done a similar app, but it keeps a gui up awaiting a timeclock punch. You need to tackle this in phases: 1. what os and get the gui to start at bootup. 2. start a separate thread that reads/blocks on the coin. you need more specific questions to get better help -----Original Message----- From: Jon Monteleone [mailto:uomart at ihug.co.nz] Sent: Thursday, August 18, 2005 11:15 AM To: python-list at python.org Subject: Coin-operated kiosk written in python -- need some help... Greetings, I posted a few days back and didnt get much of a response, so I figured I would post again with more detail. I am running gnome under fedora core 4. I want a kid to be able to drop a quarter into a coin slot and get 15 minutes of time on an account that has "restricted" Internet access via the firefox web browser. We are experimenting with different ways to allow kids to safely surf the web during school hours while recovering some of the cost for bandwidth. I have written a python program that detects the coin drop and adds 15 minutes to a gui written in tkinter. The gui contains 2 buttons and the usage time. I need a way for my gui to display from machine bootup until shutdown and through multiple logins and logouts of the web browsing account. I am familiar with kiosk setups but I dont know how to code my python program to display its gui at the login screen and continue running through multiple sessions of users logging into and out of the internet acct. I thought making my kiosk program a daemon would work, but I cant get the gui to display at the login screen and then there is the problem of having the press of a button on my gui enter username and password information. Basically, I envision the following sequence of events... 1) Machine is turned on and boots up 2) My kiosk is started (maybe as a daemon) 3) The daemon uses Tkinter to display its gui with the buttons and time 4) User drops coins and time on gui is incremented 5) User presses the start button 6) My program logs the user into the Internet account 7) Secure firefox is started 8) My program starts counting down the time on the gui 9) When the time reaches 0, the user is logged out When the user presses stop on my gui, they are logged out The user can drop more coins at any time during the session to prolong the session 10) Timer resets to 0 awaiting the next customer to drop coins Any help on how to display my gui and log into an account using python would be much appreciated. Cheers -Jon -- http://mail.python.org/mailman/listinfo/python-list --------------------------------------------------------------------------- The information contained in this message may be privileged and / or confidential and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and deleting the material from any computer. --------------------------------------------------------------------------- From cam.ac.uk at mh391.invalid Sat Aug 20 06:23:20 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sat, 20 Aug 2005 11:23:20 +0100 Subject: Please Criticize My Code In-Reply-To: <1124530464.953087.134280@z14g2000cwz.googlegroups.com> References: <1124522306.461897.128960@g14g2000cwa.googlegroups.com> <1124530464.953087.134280@z14g2000cwz.googlegroups.com> Message-ID: Ray wrote: > Well... I'm always paranoid that I'm, you know, writing Java in Python > :) The biggest mistakes I see are wrapping everything in a class unnecessarily, or using accessor methods instead of properties (ugh, ugh, ugh!). CamelCasingYourVariableNames is annoyingToMe but that's really a stylistic choice. > Thanks for the examples! That last one took me a while to understand. I > like the way you approach it though (e.g.: going after clarity first > instead of shortness). I think that is the Pythonic way. In general, I find conciseness in code is not worth all that much in its own right. Although sometimes it can make things easier to understand, which is good. There is a common belief that concise code = fast code, and it is easy to demonstrate that this is false. See, for example, this essay: Also, if you haven't done so already, start up an interactive prompt and type "import this." Key to consider: Simple is better than complex. Complex is better than complicated. Sparse is better than dense. Readability counts. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Best regards, -- Michael Hoffman From tdelaney at avaya.com Wed Aug 3 17:59:31 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Thu, 4 Aug 2005 07:59:31 +1000 Subject: HELP:sorting list of outline numbers Message-ID: <2773CAC687FD5F4689F526998C7E4E5F0742A9@au3010avexu1.global.avaya.com> Scott David Daniels wrote: > Delaney, Timothy (Tim) wrote: >> Scott David Daniels wrote: >>> For 2.3: (using DSU -- Decorate, Sort, Undecorate) > ... >>> lst = ['1', '1.2', '1.12', '1.1', '3.1'] >>> decorated = [(numparts(txt), txt) for txt in lst] >>> decorated.sort() lst[:] = [txt for code, txt in decorated] >> >> Slightly better to do:: >> ... >> lst = ['1', '1.2', '1.12', '1.1', '3.1'] >> decorated = [(numparts(txt), i, txt) for i, txt in >> enumerate(lst)] decorated.sort() lst[:] = [txt[-1] for d >> in decorated] > > In the particular case given, I don't think it matters. True. > In general, however, I agree the latter is a better idea. Just > so someone hopping in here is clear about what is better, and > explicitly _not_ because I think Tim misunderstands the issue, Hey! I resent that! I misunderstand lots of things! > The latter version, in the case of a match on the "decorated" > version compares first the "key", and then, if the keys match, > it compares the position in the list. In no case does it actually > compare the original list elements. The 2.4 version (just using the > key= form of sort) does the same kind of thing; it avoids comparing > the element and only compares keys. The reason you care about this > is that is can be arbitrarily expensive to compare elements, or the > elements themselves may be "incomparable" (think of complex numbers). Yep - I really should have explained the reasoning better. I guess having been involved in the 2.4 sort discussions on python-dev, it kinda seems obvious to me why only comparing the key is an important feature. Tim Delaney From grig.gheorghiu at gmail.com Tue Aug 2 12:58:58 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 2 Aug 2005 09:58:58 -0700 Subject: Art of Unit Testing References: Message-ID: <1123001938.602349.164510@z14g2000cwz.googlegroups.com> The py.test module offers setup/teardown hooks at the method, class and module level. The scenario you're describing would be covered at the module level. See the py.test documentation for more details: Grig ==== http://agiletesting.blogspot.com From Nadie at san.rr.com Mon Aug 15 22:33:36 2005 From: Nadie at san.rr.com (Nadie) Date: Tue, 16 Aug 2005 02:33:36 GMT Subject: Reading portions of a wave file Message-ID: <4gcMe.1474$Q82.1316@tornado.socal.rr.com> Greeting list readers, I noticed that the wave read object has an *implementation dependent* setpos(pos) method. When reading audio files, it is useful to be able to set the position to a specific sample. While setpos(pos) may do this on certain implementations (haven't tried it), it would not be a reliable way to do it in a platform independent manner. Is anyone familiar with an alternative wave package that would let one arbitrarily access portions of a wave file? Clearly, one can read in up to the desired point, but when the file is very large, this becomes an inappropriate way of doing things. Thanks, Marie If you have a suggestion and prefer to send e-mail, please send it to "nospam" with the domain from the bogus address listed above. From grante at visi.com Thu Aug 18 22:17:17 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 19 Aug 2005 02:17:17 -0000 Subject: question about binary and serial info References: <1124333032.358284.174210@g44g2000cwa.googlegroups.com> <3p28g11c90qqbv72e76n4iujebqfmimt5p@4ax.com> <1124383018.080322.190510@g47g2000cwa.googlegroups.com> <11g9evhkjbanncb@corp.supernews.com> <1124385315.645206.285740@o13g2000cwo.googlegroups.com> <11g9hct6qkfsc28@corp.supernews.com> <43053b81$1@news.eftel.com> Message-ID: <11gag9de4vgbu33@corp.supernews.com> On 2005-08-19, John Machin wrote: > The OP is reading raw output from a serial port. He's already said he's > getting "funny ASCII characters". One gets the impression he thinks he > needs to do bit-twiddling on *each* byte. Looks like he needs ord(), or > (better) struct.unpack() Yes, I finally reached that conclusion. The OP kept insisting he was reading hex strings -- an impression given him by the device's vendor, apparently. -- Grant Edwards grante Yow! Jesuit priests are at DATING CAREER DIPLOMATS!! visi.com From petr at tpc.cz Tue Aug 23 07:53:09 2005 From: petr at tpc.cz (McBooCzech) Date: 23 Aug 2005 04:53:09 -0700 Subject: py-serial + CSV Message-ID: <1124797989.847787.68360@z14g2000cwz.googlegroups.com> Hi I am just trying to analyze (parse) data from the serial port (I have connected GPS receiver to the ttyS0, so I can read ASCII characters in the CSV form on the serial port 1). I am doing this just to understand how Python works (yes, you can call me Python/Linux newbie :) My environment is Fedora Core 4, Python 2.4.1 CSV alone (to read CSV data from the file) and py-serial alone (to read data from the serial port) are working flawlessly. Even I was trying to google through this group and through the Internet, I am not able to read (and parse) CSV data directly from the serial port. data from my serial port (using py-serial) I am getting this way: >>> import serial >>> s = serial.Serial(port=0,baudrate=4800, timeout=20) >>> s.readline() '$GPRMC,101236.331,A,5026.1018,N,01521.6653,E,0.0,328.1,230805,,*09\r\n' my next intention was to do something like this: import csv r = csv.reader(s.readline()) for currentline in r: if currentline[0] == '$GPRMC': print currentline[2] print currentline[4] but it does not work Thanks for your comments Petr Jakes From rafi at free.fr Mon Aug 15 12:06:43 2005 From: rafi at free.fr (rafi) Date: Mon, 15 Aug 2005 18:06:43 +0200 Subject: get a list of mounted filesystems under MacOSX In-Reply-To: References: Message-ID: <4300bd95$0$11586$636a15ce@news.free.fr> garabik-news-2005-05 at kassiopeia.juls.savba.sk wrote: > Hi all, > I am trying to port my (linux) program to MacOSX, and I need to get a > list of mounted filesystems. Under linux, it was easy, I was parsing > /etc/mtab (or /proc/mounts), this works also on some other unices. > But I have no idea how to do it on MacOSX, apart from calling "mount" as > an external program and parsing the output - but I prefer "cleaner" > solutions. Is there one? why not looking at the content of the /Volumes folder? my 2 cents -- rafi "Imagination is more important than knowledge." (Albert Einstein) From franz.steinhaeusler at gmx.at Mon Aug 1 12:08:51 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Mon, 01 Aug 2005 18:08:51 +0200 Subject: Getting not derived members of a class References: <1122907402.650512.213470@g47g2000cwa.googlegroups.com> <3l6v2gF115ttuU1@individual.net> Message-ID: On Mon, 01 Aug 2005 18:02:20 +0200, Reinhold Birkenfeld wrote: >Franz Steinhaeusler wrote: > >> The background: >> I want to create a code completition for an editor component. >> It should distinguish between inherited and non inherited members. >> Reason is, that on wxPython, most classes are derived from wxWindow. >> For example if I want Code completition for wx.Frame, >> I always get the 200 or so suggestions, >> whereby most times, I'm only interested in the possible completions of >> wx.Frame and maybe wx.TopLevelWindow. > >You can, of course, always search the base classes and subtract the two sets >(all members)-(members of baseclasses). For example: > >cls = wx.Frame > >set(dir(cls)) - reduce(set.union, [set(dir(base)) for base in cls.__bases__]) > >Reinhold Hello Reinhold, yes, cool, thank you very much! The optimum would be getting also the other base classes, with the members, but I think, it is asked to much. 'wx.Frame' ... => CreateStatusBar, ... 'wx.TopLevelWindow' ... => GetIcon, ... 'wx.Window' ... => ... 'wx.EvtHandler' => ... -- Franz Steinhaeusler From fumanchu at amor.org Tue Aug 23 20:54:00 2005 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 23 Aug 2005 17:54:00 -0700 Subject: Multiple (threaded?) connections to BaseHTTPServer Message-ID: <3A81C87DC164034AA4E2DDFE11D258E377282F@exchange.hqamor.amorhq.net> Adam Atlas wrote: > Is there any built-in way for BaseHTTPServer to handle multiple > connections at once, e.g. with threads? If not, can this existing > module be easily extended to do this, or will I have to do lower-level > socket things (and probably thus have to write my own HTTP code)? Do you *really* want to reinvent that wheel? ;) I'd suggest you start with a threaded HTTP server from one of Python's many web frameworks. Since I hack on CherryPy, I'll link you to its liberally-licensed PooledThreadServer: http://www.cherrypy.org/file/trunk/cherrypy/_cphttpserver.py Robert Brewer System Architect Amor Ministries fumanchu at amor.org From peter at engcorp.com Mon Aug 29 22:12:27 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 29 Aug 2005 22:12:27 -0400 Subject: new line In-Reply-To: References: Message-ID: Kuljo wrote: > Kuljo wrote: >>I'm so sorry to bore you with this trivial problem. Allthou: I have string >>having 0x0a as new line, but I should have \n instead. > I have found this in the meantime: >>>>nl="\\"+"n" Note: this is unnecessary. You could just do nl='\\n' instead, and you don't need the variable "nl" either, which by the way is confusingly named. Your variable "nl" is actually bound to the two character sequence \ followed by n instead of a "newline". Is that really what you wanted? >>>>text_new=replace(text_old, chr(10), nl) This use of replace() is deprecated. Use text_old.replace() instead. > It works. For some definitions of "works". This only works if you wanted the *single* character represented by '\x0a' to turn into the *two* characters backslash-followed-by-letter-n. The following you might find instructive: >>> old = 'some\x0atext' >>> old 'some\ntext' >>> print old some text >>> old.encode('string-escape') 'some\\ntext' >>> print old.encode('string-escape') some\ntext This will turn other control characters into their equivalent two-character escaped representation as well, such as \t and \r, as necessary. -Peter From whisper at oz.net Thu Aug 4 00:20:07 2005 From: whisper at oz.net (whisper at oz.net) Date: Wed, 03 Aug 2005 21:20:07 -0700 Subject: Secure email In-Reply-To: <7x8xzin3vc.fsf@ruckus.brouhaha.com> References: <7x8xzin3vc.fsf@ruckus.brouhaha.com> Message-ID: <42F19777.8060408@oz.net> Paul Rubin wrote: >whisper at oz.net writes: > > >>I need to write a .cgi that will take the content of an https GET or >>POST and send it securely as email to an Outlook client. >> >> > >You're asking how to make S/MIME messages? This isn't really the >right newsgroup. > > Well, perhaps it bears saying explicitly that I want to use python and python libraries to write the .cgi script. If there's a better newsgroup, would you please tell me? Dave LeBlanc Seattle, WA USA From bkhl at stp.lingfil.uu.se Sun Aug 7 10:02:49 2005 From: bkhl at stp.lingfil.uu.se (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) Date: Sun, 07 Aug 2005 16:02:49 +0200 Subject: Python -- (just) a successful experiment? References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> Message-ID: <87psspyhdi.fsf@lucien.dreaming> Paul Rubin writes: > That would imply that it included the Ruby language. Nothing stops the > Ruby on Rails packagers from making the Ruby on Rails distro a > superset of the Ruby distro, after all. So you agree with me then? That _was_ exactly my point, after all. Not that you read it. After all, you might have been replying to some completely different posting - who could know? > Peter Decker writes: > >> Wow, and I have the impression that you form opinions before you > >> actually experience something. Isn't there a word for such a person? > > Hmmm..... > > Plonk. Yeah, thanks, that's the word. -- Bj?rn Lindstr?m Student of computational linguistics, Uppsala University, Sweden From rdsteph at mac.com Thu Aug 11 09:48:13 2005 From: rdsteph at mac.com (rdsteph at mac.com) Date: 11 Aug 2005 06:48:13 -0700 Subject: Creating Palm OS programs with python? In-Reply-To: References: Message-ID: <1123768093.422246.32940@g14g2000cwa.googlegroups.com> Hello Peter, There are some links to Python on Palm web resources at my Python for Mobile Devices page. The only mobile device I have personnally run Python on is the Zaurus, which works great. I will try to post links to just the Python on Palm resources below, but these can all be found on my site as well as Pythonic links for Zaurus, Pocket PC, Nokia Series 60, iPod, iRiver, etc Palm

Python for Palm Operating System
2.3.2 from Argentina

Pippy, Python for the Palm PDA Platform

Python for the Palm OS
an old article but helpful for getting started

Pyrite
a comprehensive set of modules which allow access to Palm Computing platform devices and their data via Python. It includes APIs for transparent database access, records as Python objects, conduits, and plug-ins for extensability. Pyrite was formerly known as "PalmPython".

Palm Python Wiki


Peter Hansen wrote: > djanvk at gmail..com wrote: > > QUick question: > > > > Is it possible to create a palm os program to use on a PDA with > > python? > > Practically speaking, no. I did find it relatively easy to install and > learn enough of Plua to write a useful app for my old Palm V, however, > and Lua isn't so far from Python that you feel like you've travelled to > a foreign country to do it. > > -Peter From thomasbartkus at comcast.net Wed Aug 17 13:17:36 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Wed, 17 Aug 2005 12:17:36 -0500 Subject: Obfuscator for Python Code References: <1124298063.074422.252770@g14g2000cwa.googlegroups.com> Message-ID: "codecraig" wrote in message news:1124298063.074422.252770 at g14g2000cwa.googlegroups.com... > Is there any obfuscator out there that obfuscates the python code (byte > code i guess)??? Hmmhh! I know lots of obfuscators for VB, C, and Java. For these languages, it seems to be one of the more popular coding specialties. Certainly, I don't see much reason why one couldn't obfuscate Python code. It's just that coders with an aptitude for obfuscation don't seem to like the Python language very much. Perhaps if the "help wanted" ads contained more Python posting, the obfuscators might be tempted to flock to it :-) Thomas Bartkus From talin at acm.org Sun Aug 28 13:29:06 2005 From: talin at acm.org (Talin) Date: Sun, 28 Aug 2005 10:29:06 -0700 Subject: Yielding a chain of values Message-ID: <4311F462.4040006@acm.org> I'm finding that a lot of places within my code, I want to return the output of a generator from another generator. Currently the only method I know of to do this is to explicitly loop over the results from the inner generator, and yield each one: for x in inner(): yield x I was wondering if there was a more efficient and concise way to do this. And if there isn't, then what about extending the * syntax used for lists, i.e.: yield *inner() The * would indicate that you want to iterate through the given expression, and yield each value in turn. You could also use it on ordinary lists: yield *[1, 2, 3 ] Anyway, just an idle thought on a Sunday morning :) From kay.schluehr at gmx.net Tue Aug 9 02:10:22 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Aug 2005 23:10:22 -0700 Subject: Python -- (just) a successful experiment? In-Reply-To: References: <20050807005406.1217660123.whereU@now.com> <7xmznuxh61.fsf@ruckus.brouhaha.com> <87ll3eytx9.fsf@lucien.dreaming> <7xoe8a6q24.fsf@ruckus.brouhaha.com> <8764uiyqfq.fsf@lucien.dreaming> <7x64uhx4db.fsf@ruckus.brouhaha.com> <87psspyhdi.fsf@lucien.dreaming> <7xpsspq0re.fsf@ruckus.brouhaha.com> <7xhde1pyoy.fsf@ruckus.brouhaha.com> <42f78937.926582004@news.oz.net> <1123534185.140211.302750@o13g2000cwo.googlegroups.com> Message-ID: <1123567822.546673.93620@o13g2000cwo.googlegroups.com> EP wrote: > But sometimes a rugged individual can be even more rugged and more individual if said individual has the support of friends by which to vet ideas and, by absorbing counterpoint, to develop one's own thoughts even further. > > > And it is kind of nice when you have two teams drilling a mountain tunnel from opposite sides to have an effective way to line up efforts. EP, maybe you/we should try out the Meta-SIG or short MESIG which did not passed away because it was never born. http://www.python.org/sigs/ In the context of MESIG we can discuss the shape of PEEP and create your taskforce, blowing life into a new heroic genus - fame and prestige may be with them. Is K serious? Speaking seriously, a few years ago K read somewhere in the BDFLs memoirs that "fun" was once a part of Pythons culture originating from our great anchestors namely the commedians of Monty Python. Becoming sentimental about this and as a true and proud reactionary K always seemed to be a fundamentalist somehow. Not an excuse but an explanation. Kay From Andrey.Smirnov at Sun.COM Thu Aug 18 10:43:07 2005 From: Andrey.Smirnov at Sun.COM (Andrey Smirnov) Date: Thu, 18 Aug 2005 08:43:07 -0600 Subject: Strange email.Parser error? Message-ID: <43049E7B.7070700@Sun.COM> I am getting the following traceback after upgrading my app to Python 2.4.1. It's telling me that there is an error in Parser.py. It tells me that 'fp.read(8192)' is given 2 arguments, but it is clearly not true. Does anybody know what's going on here? Traceback (most recent call last): File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line 252, in work worker(e.linkval, info) File "/opt/etext/bin/etreceive", line 30, in worker result = decode.searchfile(f) File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line 43, in searchfile return Email(f) File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line 510, in __init__ self.child.append(Email(mf)) File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line 404, in __init__ msg = Parser().parse(f) File "/opt/etext/lib/python2.4/email/Parser.py", line 65, in parse data = fp.read(8192) TypeError: read() takes exactly 1 argument (2 given) Thanks, Andre. -- From sybrenUSE at YOURthirdtower.com.imagination Wed Aug 24 03:32:28 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 24 Aug 2005 09:32:28 +0200 Subject: how to deal with space between numbers References: Message-ID: Mohammed Altaj enlightened us with: > Thanks a lot for your valuable answer, i like the way you code , but > i would like to use my own, You don't learn to code properly if you always stick to your own stuff... > so if it is possible for you and if you have time, please could you > fix my code, so that i can do what i want. Learn from the answers you've been given. Read the documentation. Then you can incorporate them into your own program. You won't learn anything of you don't challenge yourself! Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 1 17:11:18 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 01 Aug 2005 23:11:18 +0200 Subject: Wheel-reinvention with Python In-Reply-To: <1122921964.869376.239020@g43g2000cwa.googlegroups.com> References: <1122577723.976528.61520@o13g2000cwo.googlegroups.com> <87wtn8qrdq.fsf@wilson.rwth-aachen.de> <1122829672.285541.45710@g43g2000cwa.googlegroups.com> <3l6ej1F10vf3eU1@individual.net> <1122921964.869376.239020@g43g2000cwa.googlegroups.com> Message-ID: <3l7hfmF11b0vaU1@individual.net> Kay Schluehr wrote: > Reinhold Birkenfeld wrote: > >> > In practise any Python GUI is going to contain code from otyher >> > languages since if it was coded all the way down in python it would >> > be too slow. >> >> Oh, I could imagine that a MFC-like wrapper around win32gui, or another >> one around Xlib wouldn't be slower that wxWidgets is today. >> >> Reinhold > > Hi Reinhold, > > did You have a look at 'venster'? > > http://venster.sourceforge.net/htdocs/index.html > > They even dropped win32gui and worked with ctypes and the Win32API > reducing the C-footprint. For frameworks like Dabo, AnyGUI, PyGUI etc. > this would be the right level to create an abstraction layer IMO. By > the way the demo applications of venster run stable and fast on WinXP. Ah! No, I didn't know this. I don't need it, either ;) but good to know it exists. Of course, doing such a thing for Xlib is more complicated because it doesn't know native widgets (okay, you can use Athena et al., but who wants them today...). Reinhold

a.text = text[2:6] # "link" goes inside a.tail = text[6:] # " and some" goes after p.insert(0, a) print tostring(p) # "